Skip to content

Commit ba846d2

Browse files
Merge pull request #154 from topcoder-platform/migrate-v5-groups
[Online Review] Migrate to use V5 Groups API instead of V3
2 parents e3060f2 + e67bc1e commit ba846d2

File tree

5 files changed

+22
-112
lines changed

5 files changed

+22
-112
lines changed

conf/OnlineReview.xml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5231,12 +5231,8 @@
52315231
<Property name="topcoder_api_base_url">
52325232
<Value>@topcoder_api_base_url@</Value>
52335233
</Property>
5234-
5235-
<Property name="user_group_membership_url">
5236-
<Value>@topcoder_api_base_url_v3@/groups?memberId=%s&amp;membershipType=User</Value>
5237-
</Property>
5238-
<Property name="parent_groups_url">
5239-
<Value>@topcoder_api_base_url_v3@/groups/%s/getParentGroup?oneLevel=false</Value>
5234+
<Property name="user_group_membership_url_v5">
5235+
<Value>@topcoder_api_base_url_v5@/groups/memberGroups/%s</Value>
52405236
</Property>
52415237
<Property name="v3jwt_cookie_name">
52425238
<Value>v3jwt</Value>

src/main/java/com/cronos/onlinereview/actions/project/SaveProjectAction.java

Lines changed: 9 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,107 +1401,40 @@ private Date parseDatetimeFormProperties(int propertyIndex, String dateProperty,
14011401
/**
14021402
* Get groups for the login user
14031403
*
1404-
* @param request the request to use
14051404
* @param userId the user id to use
14061405
* @throws BaseException if any error occurs
14071406
* @return the Set<Long> result contains the group ids
14081407
*/
14091408
private Set<Long> getGroups(long userId) throws BaseException {
14101409
try {
14111410
DefaultHttpClient httpClient = new DefaultHttpClient();
1412-
String groupEndPoint = String.format(ConfigHelper.getUserGroupMembershipUrl(), userId);
1413-
HttpGet getRequest = new HttpGet(groupEndPoint);
1414-
1415-
String v3Token = new JwtTokenUpdater().check().getToken();
1411+
String groupV5EndPoint = String.format(ConfigHelper.getUserGroupMembershipUrlV5(), userId);
1412+
HttpGet getRequest = new HttpGet(groupV5EndPoint);
14161413

1417-
getRequest.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + v3Token);
1414+
String m2mToken = ConfigHelper.getEventBusAuthToken();
1415+
getRequest.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + m2mToken);
14181416

14191417
getRequest.addHeader(HttpHeaders.ACCEPT, "application/json");
14201418
HttpResponse httpResponse = httpClient.execute(getRequest);
14211419

14221420
HttpEntity entity = httpResponse.getEntity();
14231421

14241422
if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
1425-
throw new BaseException("Unable to get groups from the API:" + httpResponse.getStatusLine().getReasonPhrase());
1423+
throw new BaseException("Unable to get v5 groups from the API:" + httpResponse.getStatusLine().getReasonPhrase());
14261424
}
14271425

1428-
JsonNode result = objectMapper.readTree(entity.getContent());
1429-
1430-
JsonNode groups = result.path("result").path("content");
1426+
JsonNode groups = objectMapper.readTree(entity.getContent());
14311427
Set<Long> groupIds = new HashSet<Long>();
14321428
for (JsonNode group : groups) {
1433-
groupIds.add(group.path("id").asLong());
1429+
groupIds.add(group.asLong());
14341430
}
1435-
1436-
Set<Long> allGroupIds = new HashSet<Long>(groupIds);
1437-
for (Long groupId : groupIds) {
1438-
allGroupIds.addAll(getParentGroups(groupId));
1439-
}
1440-
1441-
return allGroupIds;
1431+
System.out.println("getGroups Results:" + groupIds);
1432+
return groupIds;
14421433
} catch (Exception exp) {
14431434
throw new BaseException(exp.getMessage(), exp);
14441435
}
14451436
}
14461437

1447-
/**
1448-
* Get parent groups for the given group id
1449-
*
1450-
* @param request the request to use
1451-
* @param groupId the user id to use
1452-
* @throws BaseException if any error occurs
1453-
* @return the Set<Long> result contains the group ids
1454-
*/
1455-
private Set<Long> getParentGroups(long groupId) throws BaseException {
1456-
try {
1457-
DefaultHttpClient httpClient = new DefaultHttpClient();
1458-
String parentGroupsEndPoint = String.format(ConfigHelper.getParentGroupsUrl(), groupId);
1459-
HttpGet getRequest = new HttpGet(parentGroupsEndPoint);
1460-
1461-
String v3Token = new JwtTokenUpdater().check().getToken();
1462-
1463-
getRequest.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + v3Token);
1464-
1465-
getRequest.addHeader(HttpHeaders.ACCEPT, "application/json");
1466-
HttpResponse httpResponse = httpClient.execute(getRequest);
1467-
1468-
HttpEntity entity = httpResponse.getEntity();
1469-
1470-
if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
1471-
throw new BaseException("Unable to get groups from the API:" + httpResponse.getStatusLine().getReasonPhrase());
1472-
}
1473-
1474-
JsonNode result = objectMapper.readTree(entity.getContent());
1475-
1476-
JsonNode groupNode = result.path("result").path("content");
1477-
Set<Long> groupIds = parseGroup(groupNode);
1478-
1479-
return groupIds;
1480-
} catch (Exception exp) {
1481-
throw new BaseException(exp.getMessage(), exp);
1482-
}
1483-
}
1484-
1485-
/**
1486-
* Parse the group from the JSON node
1487-
* @param groupNode the JSON node
1488-
* @return the group
1489-
*/
1490-
private Set<Long> parseGroup(JsonNode groupNode) {
1491-
Set<Long> parentGroupIds = new HashSet<Long>();
1492-
Long parentGroupId = groupNode.path("id").asLong();
1493-
if (parentGroupId != 0) {
1494-
// exclude null node
1495-
parentGroupIds.add(groupNode.path("id").asLong());
1496-
}
1497-
1498-
if (groupNode.has("parentGroup")) {
1499-
parentGroupIds.addAll(parseGroup(groupNode.path("parentGroup")));
1500-
}
1501-
1502-
return parentGroupIds;
1503-
}
1504-
15051438
/**
15061439
* Check group permission
15071440
*

src/main/java/com/cronos/onlinereview/util/ConfigHelper.java

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -580,14 +580,9 @@ public class ConfigHelper {
580580
private static final String V3_JWT_COOKIE_NAME = "v3jwt_cookie_name";
581581

582582
/**
583-
* <p>A <code>String</code> providing the name for user group memeber ship url property.</p>
583+
* <p>A <code>String</code> providing the name for user group member ship v5 url property.</p>
584584
*/
585-
private static final String USER_GROUP_MEMBERSHIP_URL = "user_group_membership_url";
586-
587-
/**
588-
* <p>A <code>String</code> providing the name for parent groups url property.</p>
589-
*/
590-
private static final String PARENT_GROUPS_URL = "parent_groups_url";
585+
private static final String USER_GROUP_MEMBERSHIP_URL_V5 = "user_group_membership_url_v5";
591586

592587
/**
593588
* <p>A <code>String</code> providing the name for v2 jwt cookie name property.</p>
@@ -962,15 +957,9 @@ public class ConfigHelper {
962957
private static String thurgoodPassword;
963958

964959
/**
965-
* <p>Represents the userGroupMembershipUrl.</p>
966-
*/
967-
private static String userGroupMembershipUrl;
968-
969-
/**
970-
* <p>Represents the parentGroupsUrl.</p>
960+
* <p>Represents the userGroupMembershipUrlV5.</p>
971961
*/
972-
private static String parentGroupsUrl;
973-
962+
private static String userGroupMembershipUrlV5;
974963
/**
975964
* <p>Represents the v3jwtCookieBame.</p>
976965
*/
@@ -1671,8 +1660,7 @@ public class ConfigHelper {
16711660
thurgoodPassword = value;
16721661
}
16731662

1674-
userGroupMembershipUrl = cfgMgr.getString(ONLINE_REVIEW_CFG_NS, USER_GROUP_MEMBERSHIP_URL);
1675-
parentGroupsUrl = cfgMgr.getString(ONLINE_REVIEW_CFG_NS, PARENT_GROUPS_URL);
1663+
userGroupMembershipUrlV5 = cfgMgr.getString(ONLINE_REVIEW_CFG_NS, USER_GROUP_MEMBERSHIP_URL_V5);
16761664
v3jwtCookieName = cfgMgr.getString(ONLINE_REVIEW_CFG_NS, V3_JWT_COOKIE_NAME);
16771665
v2jwtCookieName = cfgMgr.getString(ONLINE_REVIEW_CFG_NS, V2_JWT_COOKIE_NAME);
16781666
ssoDomainForV3jwtCookie = cfgMgr.getString(ONLINE_REVIEW_CFG_NS, SSO_DOMAIN_FOR_V3_JWT_COOKIE);
@@ -2536,21 +2524,12 @@ public static String getThurgoodPassword() {
25362524
}
25372525

25382526
/**
2539-
* Get user group membership url
2540-
*
2541-
* @return the userGroupMembershipUrl
2542-
*/
2543-
public static String getUserGroupMembershipUrl() {
2544-
return userGroupMembershipUrl;
2545-
}
2546-
2547-
/**
2548-
* Get parent groups url
2527+
* Get user group membership v5 url
25492528
*
2550-
* @return the parent groups url
2529+
* @return the userGroupMembershipUrlV5
25512530
*/
2552-
public static String getParentGroupsUrl() {
2553-
return parentGroupsUrl;
2531+
public static String getUserGroupMembershipUrlV5() {
2532+
return userGroupMembershipUrlV5;
25542533
}
25552534

25562535
/**

token.properties.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ thurgood.username=Thurgood
154154
thurgood.password=password
155155
topcoder_api_base_url=http://api.topcoder.com/v2/develop/challenges
156156
topcoder_api_base_url_v3=http://api.topcoder.com/v3/challenges
157+
topcoder_api_base_url_v5=https://api.topcoder.com/v5
157158
amazon_sns_arn=
158159
amazonSNSAccessKey=
159160
amazonSNSSecretKey=

token.properties.local

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ thurgood.username=Thurgood
160160
thurgood.password=password
161161
topcoder_api_base_url=http://api.topcoder-dev.com/v2/develop/challenges
162162
topcoder_api_base_url_v3=http://api.topcoder-dev.com/v3/challenges
163+
topcoder_api_base_url_v5=https://api.topcoder-dev.com/v5
163164
amazon_sns_arn=arn:aws:sns:us-east-1:766830814403:community-challenge-create
164165
amazonSNSAccessKey=AKIAIZNXS3HERHTLVQKA
165166
amazonSNSSecretKey=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

0 commit comments

Comments
 (0)