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

Commit c37e6ff

Browse files
authored
Merge pull request #321 from deedee/update_group_challenge
update_group_challenge
2 parents 11df8c9 + 5c14a93 commit c37e6ff

File tree

14 files changed

+360
-122
lines changed

14 files changed

+360
-122
lines changed

conf/web/WEB-INF/applicationContext.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@
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@"/>
359360
</bean>
360361

361362
<bean id="projectAction" class="com.topcoder.direct.services.view.action.contest.launch.ProjectAction"
@@ -424,6 +425,7 @@
424425
<bean id="saveDraftContestAction"
425426
class="com.topcoder.direct.services.view.action.contest.launch.SaveDraftContestAction"
426427
parent="contestAction" scope="prototype">
428+
<property name="userGroupsApiEndpoint" value="@userGroupsApiEndpoint@"/>
427429
</bean>
428430

429431
<bean id="documentUploadAction" class="com.topcoder.direct.services.view.action.contest.launch.DocumentUploadAction"

conf/web/WEB-INF/struts.xml

Lines changed: 5 additions & 0 deletions
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

Lines changed: 12 additions & 0 deletions
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

Lines changed: 22 additions & 0 deletions
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

Lines changed: 35 additions & 12 deletions
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,20 @@
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;
3223
import com.topcoder.direct.services.view.util.challenge.CostCalculationService;
24+
import com.topcoder.management.project.ProjectGroup;
3325
import com.topcoder.security.TCSubject;
3426
import com.topcoder.service.facade.contest.ContestServiceException;
3527
import com.topcoder.service.facade.project.DAOFault;
3628
import org.apache.commons.lang3.StringEscapeUtils;
3729
import org.codehaus.jackson.map.ObjectMapper;
38-
import com.topcoder.management.project.ProjectGroup;
30+
31+
import java.util.*;
3932

4033
/**
4134
* <p>
@@ -130,6 +123,11 @@ public class CommonAction extends BaseContestFeeAction {
130123

131124
private long categoryId;
132125

126+
/**
127+
* Endpoint to group of a user
128+
*/
129+
private String userGroupsApiEndpoint;
130+
133131
/**
134132
* <p>
135133
* Executes the action.
@@ -325,7 +323,6 @@ public String getContestConfigs() throws Exception {
325323

326324
configs.put("copilotFees", ConfigUtils.getCopilotFees());
327325
configs.put("billingInfos", getBillingProjectInfos());
328-
configs.put("groups", getAllProjectGroups());
329326
configs.put("platforms", getReferenceDataBean().getPlatforms());
330327
configs.put("technologies", getReferenceDataBean().getTechnologies());
331328
setResult(configs);
@@ -552,4 +549,30 @@ public long getCategoryId() {
552549
public void setCategoryId(long categoryId) {
553550
this.categoryId = categoryId;
554551
}
552+
553+
/**
554+
* Get Accessible security groups from group Api
555+
*
556+
* @return
557+
*/
558+
public String getGroups() {
559+
try {
560+
TCSubject tcSubject = DirectUtils.getTCSubjectFromSession();
561+
Set<ProjectGroup> projectGroups = DirectUtils.getGroups(tcSubject, userGroupsApiEndpoint);
562+
setResult(projectGroups);
563+
} catch (Throwable e) {
564+
if (getModel() != null) {
565+
setResult(e);
566+
}
567+
}
568+
return SUCCESS;
569+
}
570+
571+
public String getUserGroupsApiEndpoint() {
572+
return userGroupsApiEndpoint;
573+
}
574+
575+
public void setUserGroupsApiEndpoint(String userGroupsApiEndpoint) {
576+
this.userGroupsApiEndpoint = userGroupsApiEndpoint;
577+
}
555578
}

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

Lines changed: 19 additions & 13 deletions
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/SaveDraftContestAction.java

Lines changed: 29 additions & 13 deletions
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/ajax/SoftwareCompetitionBeanProcessor.java

Lines changed: 6 additions & 0 deletions
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) {

0 commit comments

Comments
 (0)