Skip to content

Commit 2f47cba

Browse files
authored
Merge pull request #256 from topcoder-platform/dev-maven
Add manual sync
2 parents 919b10a + 00ac22b commit 2f47cba

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed

conf/WEB-INF/actions.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,9 @@ http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
664664
<bean id="viewScorecardAction" class="com.cronos.onlinereview.actions.projectreview.ViewScorecardAction" parent="baseViewOrExportGenericReviewAction" scope="request">
665665
</bean>
666666

667+
<bean id="syncProjectAction" class="com.cronos.onlinereview.actions.project.SyncProjectAction" parent="baseProjectAction" scope="request">
668+
</bean>
669+
667670
<!-- Struts1MappingAction action -->
668671
<bean id="struts1MappingAction" class="com.cronos.onlinereview.actions.Struts1MappingAction" scope="request">
669672
</bean>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (C) 2013-2014 TopCoder Inc., All Rights Reserved.
3+
*/
4+
package com.cronos.onlinereview.actions.project;
5+
6+
import java.util.ArrayList;
7+
import java.util.Arrays;
8+
import java.util.List;
9+
10+
import org.apache.http.HttpHeaders;
11+
12+
import com.auth0.jwt.interfaces.Claim;
13+
import com.auth0.jwt.interfaces.DecodedJWT;
14+
import com.cronos.onlinereview.util.AuthorizationHelper;
15+
import com.topcoder.onlinereview.component.exception.BaseException;
16+
import com.topcoder.onlinereview.component.grpcclient.GrpcHelper;
17+
18+
/**
19+
* This class is the struts action class which is used for listing all projects.
20+
* <p>
21+
* Struts 2 Action objects are instantiated for each request, so there are no
22+
* thread-safety issues.
23+
* </p>
24+
*
25+
* @author TCSASSEMBLER
26+
* @version 2.0
27+
*/
28+
public class SyncProjectAction extends BaseProjectAction {
29+
30+
/**
31+
* Default constructor.
32+
*/
33+
public SyncProjectAction() {
34+
}
35+
36+
public String execute() throws BaseException {
37+
String projectId = request.getParameter("projectId");
38+
String tables = request.getParameter("tables");
39+
List<String> tableNames = new ArrayList<>();
40+
if (tables != null && !tables.isEmpty()) {
41+
tableNames = Arrays.asList(tables.split(","));
42+
}
43+
if (projectId.isEmpty() || tableNames.isEmpty()) {
44+
return NONE;
45+
}
46+
47+
String authHeader = request.getHeader(HttpHeaders.AUTHORIZATION);
48+
if (authHeader == null || authHeader.isEmpty()) {
49+
return NONE;
50+
}
51+
String[] headerParts = authHeader.split(" ");
52+
if (headerParts.length < 2) {
53+
return NONE;
54+
}
55+
String token = headerParts[1];
56+
57+
DecodedJWT jwt;
58+
try {
59+
jwt = AuthorizationHelper.validateJWTToken(token);
60+
} catch (Exception e) {
61+
return NONE;
62+
}
63+
boolean hasAccess = false;
64+
for (String claimName : jwt.getClaims().keySet()) {
65+
if (claimName.endsWith("/roles")) {
66+
Claim claim = jwt.getClaim(claimName);
67+
for (String role : claim.asArray(String.class)) {
68+
if (role.equals("administrator")) {
69+
hasAccess = true;
70+
}
71+
}
72+
}
73+
}
74+
if (!hasAccess) {
75+
return NONE;
76+
}
77+
78+
GrpcHelper.getSyncServiceRpc().manualSync(Long.valueOf(projectId), tableNames);
79+
return NONE;
80+
}
81+
}

src/main/resources/struts.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,9 @@
519519
<action name="eventBusHandleAppealAction" class="eventBusHandleAppealAction">
520520
</action>
521521

522+
<action name="SyncProject" class="syncProjectAction">
523+
</action>
524+
522525
<!-- Redirect for old-style Struts1 requests -->
523526
<action name="*.do" class="struts1MappingAction">
524527
<result name="dynamic" type="redirect">${url}</result>

web/jsp/syncResult.jsp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<%--
2+
- Author: TCSASSEMBLER
3+
- Version: 2.0
4+
- Copyright: Copyright (C) 2005 - 2014 TopCoder Inc., All Rights Reserved.
5+
-
6+
- Description: The login page for the online review application.
7+
--%>
8+
<%@ page contentType="text/html;charset=UTF-8" %>
9+
<%@ page language="java" isELIgnored="false" %>
10+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
11+
<%@ taglib prefix="s" uri="/struts-tags" %>
12+
<%@ taglib prefix="or" uri="/or-tags" %>
13+
<%@ taglib prefix="orfn" uri="/tags/or-functions" %>
14+
<%@ page import="com.topcoder.onlinereview.component.webcommon.ApplicationServer" %>
15+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
16+
<html>
17+
18+
<head>
19+
</head>
20+
<body>
21+
22+
<body>
23+
24+
</body>
25+
</html>

0 commit comments

Comments
 (0)