Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit dc05048

Browse files
authored
Merge pull request #329 from appirio-tech/dev
Group selection based on user's groups
2 parents 6145fc8 + c0c5164 commit dc05048

18 files changed

+411
-159
lines changed

conf/web/WEB-INF/applicationContext.xml

+4-1
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@
356356
<property name="loggerName" value="com.topcoder.accounting.fees.view.actions.ContestFeesHomeAction"/>
357357
<property name="contestFeeService" ref="contestFeeService"/>
358358
<property name="contestFeePercentageService" ref="contestFeePercentageService"/>
359+
<property name="userGroupsApiEndpoint" value="@userGroupsApiEndpoint@"/>
360+
<property name="jwtTokenUpdater" ref="jwtTokenUpdater" />
359361
</bean>
360362

361363
<bean id="projectAction" class="com.topcoder.direct.services.view.action.contest.launch.ProjectAction"
@@ -424,6 +426,7 @@
424426
<bean id="saveDraftContestAction"
425427
class="com.topcoder.direct.services.view.action.contest.launch.SaveDraftContestAction"
426428
parent="contestAction" scope="prototype">
429+
<property name="userGroupsApiEndpoint" value="@userGroupsApiEndpoint@"/>
427430
</bean>
428431

429432
<bean id="documentUploadAction" class="com.topcoder.direct.services.view.action.contest.launch.DocumentUploadAction"
@@ -1609,7 +1612,7 @@
16091612
<property name="groupApiEndpoint" value="@groupMemberApiUrl@"/>
16101613
<property name="jwtTokenUpdater" ref="jwtTokenUpdater"/>
16111614
</bean>
1612-
<bean id="jwtTokenUpdater" class="com.topcoder.direct.services.view.util.JwtTokenUpdater">
1615+
<bean id="jwtTokenUpdater" class="com.topcoder.direct.services.view.util.JwtTokenUpdater" scope="prototype">
16131616
<property name="ssoLoginUrl" value="@ssoLoginUrl@"/>
16141617
<property name="authorizationURL" value="@authorizationUrl@"/>
16151618
</bean>

conf/web/WEB-INF/struts.xml

+5
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,11 @@
16611661
<result name="error" type="json"/>
16621662
</action>
16631663

1664+
<action name="getGroups" method="getGroups" class="commonAction">
1665+
<result name="success" type="json"/>
1666+
<result name="error" type="json"/>
1667+
</action>
1668+
16641669
<action name="documentUpload" class="documentUploadAction">
16651670
<result name="success" type="json"/>
16661671
<result name="error" type="json"/>

services/contest_service_facade/src/java/main/com/topcoder/service/facade/contest/ContestServiceFacade.java

+12
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import com.topcoder.project.service.ScorecardReviewData;
3232
import com.topcoder.search.builder.SearchBuilderException;
3333
import com.topcoder.security.TCSubject;
34+
import com.topcoder.service.contest.eligibility.ContestEligibility;
35+
import com.topcoder.service.contest.eligibility.dao.ContestEligibilityPersistenceException;
3436
import com.topcoder.service.facade.contest.notification.ProjectNotification;
3537
import com.topcoder.service.payment.CreditCardPaymentData;
3638
import com.topcoder.service.payment.TCPurhcaseOrderPaymentData;
@@ -1666,4 +1668,14 @@ Set<Long> updatePreRegister(TCSubject tcSubject, SoftwareCompetition contest,
16661668
* @since 1.8.6
16671669
*/
16681670
public ProjectGroup[] getAllProjectGroups(TCSubject tcSubject) throws ContestServiceException;
1671+
1672+
/**
1673+
* Get group for a contest
1674+
*
1675+
* @param contestId contestId
1676+
* @param isStudio false
1677+
* @return
1678+
* @throws ContestServiceException
1679+
*/
1680+
public List<ProjectGroup> getGroupForContest(long contestId, boolean isStudio) throws ContestServiceException;
16691681
}

services/contest_service_facade/src/java/main/com/topcoder/service/facade/contest/ejb/ContestServiceFacadeBean.java

+22
Original file line numberDiff line numberDiff line change
@@ -9592,4 +9592,26 @@ private ProjectPayment addManualCopilotPayment(com.topcoder.management.resource.
95929592
newPayment.setResourceId(copilotResource.getId());
95939593
return projectPaymentManager.create(newPayment, String.valueOf(tcSubject.getUserId()));
95949594
}
9595+
9596+
/**
9597+
* Get group for a contest
9598+
*
9599+
* @param contestId contestId
9600+
* @param isStudio false
9601+
* @return
9602+
* @throws ContestServiceException
9603+
*/
9604+
public List<ProjectGroup> getGroupForContest(long contestId, boolean isStudio) throws ContestServiceException {
9605+
try {
9606+
List<ContestEligibility> ces = contestEligibilityManager.getContestEligibility(contestId, isStudio);
9607+
List<ProjectGroup> groupList = new ArrayList<ProjectGroup>();
9608+
for (ContestEligibility ce : ces) {
9609+
groupList.add(new ProjectGroup(((GroupContestEligibility) ce).getGroupId(), ""));
9610+
}
9611+
return groupList;
9612+
} catch (ContestEligibilityPersistenceException ce) {
9613+
logger.error("Failed to get security group for challenge id:" + contestId);
9614+
throw new ContestServiceException("Failed to get security group for challenge id:" + contestId);
9615+
}
9616+
}
95959617
}

src/java/main/com/topcoder/direct/services/view/action/contest/launch/CommonAction.java

+46-12
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,10 @@
33
*/
44
package com.topcoder.direct.services.view.action.contest.launch;
55

6-
import java.util.ArrayList;
7-
import java.util.Arrays;
8-
import java.util.HashMap;
9-
import java.util.List;
10-
import java.util.Map;
11-
126
import com.topcoder.clients.model.Project;
137
import com.topcoder.clients.model.ProjectContestFee;
148
import com.topcoder.clients.model.ProjectContestFeePercentage;
15-
import com.topcoder.direct.services.configs.AlgorithmSubtypeContestFee;
169
import com.topcoder.direct.services.configs.ConfigUtils;
17-
import com.topcoder.direct.services.configs.ContestFee;
18-
import com.topcoder.direct.services.configs.StudioSubtypeContestFee;
1910
import com.topcoder.direct.services.project.metadata.entities.dao.DirectProjectAccess;
2011
import com.topcoder.direct.services.project.milestone.model.Milestone;
2112
import com.topcoder.direct.services.project.milestone.model.MilestoneStatus;
@@ -24,18 +15,21 @@
2415
import com.topcoder.direct.services.view.dto.IdNamePair;
2516
import com.topcoder.direct.services.view.dto.contest.ContestCopilotDTO;
2617
import com.topcoder.direct.services.view.dto.contest.ProblemDTO;
27-
import com.topcoder.direct.services.view.dto.contest.TypedContestBriefDTO;
2818
import com.topcoder.direct.services.view.dto.contest.ReviewScorecardDTO;
19+
import com.topcoder.direct.services.view.dto.contest.TypedContestBriefDTO;
2920
import com.topcoder.direct.services.view.util.AuthorizationProvider;
3021
import com.topcoder.direct.services.view.util.DataProvider;
3122
import com.topcoder.direct.services.view.util.DirectUtils;
23+
import com.topcoder.direct.services.view.util.JwtTokenUpdater;
3224
import com.topcoder.direct.services.view.util.challenge.CostCalculationService;
25+
import com.topcoder.management.project.ProjectGroup;
3326
import com.topcoder.security.TCSubject;
3427
import com.topcoder.service.facade.contest.ContestServiceException;
3528
import com.topcoder.service.facade.project.DAOFault;
3629
import org.apache.commons.lang3.StringEscapeUtils;
3730
import org.codehaus.jackson.map.ObjectMapper;
38-
import com.topcoder.management.project.ProjectGroup;
31+
32+
import java.util.*;
3933

4034
/**
4135
* <p>
@@ -130,6 +124,13 @@ public class CommonAction extends BaseContestFeeAction {
130124

131125
private long categoryId;
132126

127+
/**
128+
* Endpoint to group of a user
129+
*/
130+
private String userGroupsApiEndpoint;
131+
132+
private JwtTokenUpdater jwtTokenUpdater;
133+
133134
/**
134135
* <p>
135136
* Executes the action.
@@ -325,7 +326,6 @@ public String getContestConfigs() throws Exception {
325326

326327
configs.put("copilotFees", ConfigUtils.getCopilotFees());
327328
configs.put("billingInfos", getBillingProjectInfos());
328-
configs.put("groups", getAllProjectGroups());
329329
configs.put("platforms", getReferenceDataBean().getPlatforms());
330330
configs.put("technologies", getReferenceDataBean().getTechnologies());
331331
setResult(configs);
@@ -552,4 +552,38 @@ public long getCategoryId() {
552552
public void setCategoryId(long categoryId) {
553553
this.categoryId = categoryId;
554554
}
555+
556+
/**
557+
* Get Accessible security groups from group Api
558+
*
559+
* @return
560+
*/
561+
public String getGroups() {
562+
try {
563+
TCSubject tcSubject = DirectUtils.getTCSubjectFromSession();
564+
Set<ProjectGroup> projectGroups = DirectUtils.getGroups(tcSubject, jwtTokenUpdater, userGroupsApiEndpoint);
565+
setResult(projectGroups);
566+
} catch (Throwable e) {
567+
if (getModel() != null) {
568+
setResult(e);
569+
}
570+
}
571+
return SUCCESS;
572+
}
573+
574+
public String getUserGroupsApiEndpoint() {
575+
return userGroupsApiEndpoint;
576+
}
577+
578+
public void setUserGroupsApiEndpoint(String userGroupsApiEndpoint) {
579+
this.userGroupsApiEndpoint = userGroupsApiEndpoint;
580+
}
581+
582+
public JwtTokenUpdater getJwtTokenUpdater() {
583+
return jwtTokenUpdater;
584+
}
585+
586+
public void setJwtTokenUpdater(JwtTokenUpdater jwtTokenUpdater) {
587+
this.jwtTokenUpdater = jwtTokenUpdater;
588+
}
555589
}

src/java/main/com/topcoder/direct/services/view/action/contest/launch/GetContestAction.java

+19-13
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.topcoder.direct.services.view.util.SessionData;
2525
import com.topcoder.management.deliverable.Submission;
2626
import com.topcoder.management.project.Prize;
27+
import com.topcoder.management.project.ProjectGroup;
2728
import com.topcoder.management.resource.Resource;
2829
import com.topcoder.management.resource.ResourceRole;
2930
import com.topcoder.security.TCSubject;
@@ -342,11 +343,11 @@ public class GetContestAction extends ContestAction {
342343
private boolean admin;
343344

344345
/**
345-
* The registration end date.
346-
*/
347-
private String regEndDate;
348-
349-
/**
346+
* The registration end date.
347+
*/
348+
private String regEndDate;
349+
350+
/**
350351
* The submission end date.
351352
* @since 1.5
352353
*/
@@ -452,11 +453,16 @@ protected void executeAction() throws Exception {
452453
if (DirectUtils.isStudio(softwareCompetition)) {
453454
softwareCompetition.setType(CompetionType.STUDIO);
454455
}
456+
softwareCompetition.getProjectHeader().setGroups(DirectUtils.getGroupIdAndName(
457+
softwareCompetition.getProjectHeader().getGroups()));
458+
455459
setResult(softwareCompetition);
456-
regEndDate = DirectUtils.getDateString(DirectUtils.getRegistrationEndDate(softwareCompetition));
460+
regEndDate = DirectUtils.getDateString(DirectUtils.getRegistrationEndDate(softwareCompetition));
457461
subEndDate = DirectUtils.getDateString(DirectUtils.getSubmissionEndDate(softwareCompetition));
458462
contestEndDate = DirectUtils.getDateString(DirectUtils.getEndDate(softwareCompetition));
459463

464+
465+
460466
// depends on the type :
461467
// 1. if contest, store softwareCompetition in session
462468
// 2. if json data for contest, stops here since we are getting it
@@ -955,13 +961,13 @@ public void setType(TYPE type) {
955961
this.type = type;
956962
}
957963

958-
/**
959-
* Gets the registration end date.
960-
*/
961-
public String getRegEndDate() {
962-
return regEndDate;
963-
}
964-
964+
/**
965+
* Gets the registration end date.
966+
*/
967+
public String getRegEndDate() {
968+
return regEndDate;
969+
}
970+
965971
/**
966972
* Gets the submission end date.
967973
* @since 1.5

src/java/main/com/topcoder/direct/services/view/action/contest/launch/GetGroupMemberAction.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ private Set<Long> getGroupMembers() throws Exception{
153153
if (!gidProcessed.contains(gid)) {
154154
logger.info("processing gid: " + gid);
155155
RestResult<GroupMember> result = getGroupMemberByGid(gid);
156+
if (result == null) {
157+
continue;
158+
}
156159
for (GroupMember gm : result.getContent()) {
157160
if (gm.isGroup()) {
158161
if (!gids.contains(gm.getMemberId())) {
@@ -199,7 +202,8 @@ private RestResult<GroupMember> getGroupMemberByGid(Long gid) throws Exception {
199202
HttpEntity entity = response.getEntity();
200203

201204
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
202-
throw new Exception("Failed to get Group Member for " + gid + " - " + response.getStatusLine().toString());
205+
logger.error("Failed to get Group Member for " + gid + " - " + response.getStatusLine().toString());
206+
return null;
203207
}
204208

205209
jsonNode = objectMapper.readTree(entity.getContent());

src/java/main/com/topcoder/direct/services/view/action/contest/launch/SaveDraftContestAction.java

+29-13
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,17 @@ public class SaveDraftContestAction extends ContestAction {
506506
*/
507507
private static final long APPIRIO_MANAGER_METADATA_KEY_ID = 15L;
508508

509+
/**
510+
* Private constant specifying administrator role.
511+
*/
512+
private static final String ADMIN_ROLE = "Cockpit Administrator";
513+
514+
/**
515+
* Private constant specifying administrator role.
516+
*/
517+
private static final String TC_STAFF_ROLE = "TC Staff";
518+
519+
509520
/**
510521
* </p>
511522
*
@@ -731,6 +742,11 @@ public class SaveDraftContestAction extends ContestAction {
731742
*/
732743
private Double customCopilotFee;
733744

745+
/**
746+
* Endpoint to group of a user
747+
*/
748+
private String userGroupsApiEndpoint;
749+
734750
/**
735751
* <p>
736752
* Creates a <code>SaveDraftContestAction</code> instance.
@@ -1055,24 +1071,16 @@ public boolean evaluate(Object object) {
10551071
populateSoftwareCompetition(softwareCompetition);
10561072
}
10571073

1058-
//set groups
1074+
//do backend validation for groups here
1075+
List<ProjectGroup> projectGroups = new ArrayList<ProjectGroup>();
10591076
if (groups != null && groups.size() > 0) {
1060-
List<ProjectGroup> groupsList = new ArrayList<ProjectGroup>();
1061-
// get the TCSubject from session
1062-
ProjectGroup[] allProjectGroups = getContestServiceFacade().getAllProjectGroups(DirectStrutsActionsHelper.getTCSubjectFromSession());
10631077
for (String groupId : groups) {
1064-
for (ProjectGroup projectGroup : allProjectGroups) {
1065-
if (Long.valueOf(groupId).equals(projectGroup.getId())) {
1066-
groupsList.add(projectGroup);
1067-
}
1068-
}
1069-
1078+
projectGroups.add(new ProjectGroup(Long.valueOf(groupId), ""));
10701079
}
1071-
softwareCompetition.getProjectHeader().setGroups(groupsList);
1072-
} else {
1073-
softwareCompetition.getProjectHeader().setGroups(new ArrayList<ProjectGroup>());
10741080
}
10751081

1082+
softwareCompetition.getProjectHeader().setGroups(projectGroups);
1083+
10761084
// remove the thurgood information if needed
10771085
if(softwareCompetition.getProjectHeader().getProperties().containsKey(THURGOOD_PLATFORM_KEY)) {
10781086
if(softwareCompetition.getProjectHeader().getProperties().get(THURGOOD_PLATFORM_KEY) == null
@@ -2552,6 +2560,14 @@ public void setPreRegisterUsers(String preRegisterUsers) {
25522560
this.preRegisterUsers = preRegisterUsers;
25532561
}
25542562

2563+
public String getUserGroupsApiEndpoint() {
2564+
return userGroupsApiEndpoint;
2565+
}
2566+
2567+
public void setUserGroupsApiEndpoint(String userGroupsApiEndpoint) {
2568+
this.userGroupsApiEndpoint = userGroupsApiEndpoint;
2569+
}
2570+
25552571
/**
25562572
* Pre-Register users to a given project
25572573
*

src/java/main/com/topcoder/direct/services/view/action/my/MyChallengesAction.java

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.topcoder.direct.services.view.dto.my.Challenge;
88
import com.topcoder.direct.services.view.dto.my.RestResult;
99
import com.topcoder.direct.services.view.exception.JwtAuthenticationException;
10-
import com.topcoder.direct.services.view.util.JwtTokenUpdater;
1110
import org.codehaus.jackson.JsonNode;
1211

1312
import java.text.DateFormat;

src/java/main/com/topcoder/direct/services/view/ajax/SoftwareCompetitionBeanProcessor.java

+6
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ public Object transform(Object object) {
319319
}
320320
}));
321321

322+
result.put("groupNames", CollectionUtils.collect(bean.getProjectHeader().getGroups(), new Transformer() {
323+
public Object transform(Object object) {
324+
return ((ProjectGroup) object).getName();
325+
}
326+
}));
327+
322328
// documentation
323329
result.put("documentation", CollectionUtils.collect(assetDTO.getDocumentation(), new Transformer() {
324330
public Object transform(Object object) {

src/java/main/com/topcoder/direct/services/view/exception/JwtAuthenticationException.java

+4
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ public class JwtAuthenticationException extends BaseException {
66
public JwtAuthenticationException(String message) {
77
super(message);
88
}
9+
10+
public JwtAuthenticationException(String message, Throwable cause) {
11+
super(message, cause);
12+
}
913
}

0 commit comments

Comments
 (0)