());
}
+ softwareCompetition.getProjectHeader().setGroups(groupsList);
// remove the thurgood information if needed
if(softwareCompetition.getProjectHeader().getProperties().containsKey(THURGOOD_PLATFORM_KEY)) {
diff --git a/src/java/main/com/topcoder/direct/services/view/ajax/SoftwareCompetitionBeanProcessor.java b/src/java/main/com/topcoder/direct/services/view/ajax/SoftwareCompetitionBeanProcessor.java
index 1e6ab9eed..5b9fba888 100644
--- a/src/java/main/com/topcoder/direct/services/view/ajax/SoftwareCompetitionBeanProcessor.java
+++ b/src/java/main/com/topcoder/direct/services/view/ajax/SoftwareCompetitionBeanProcessor.java
@@ -319,6 +319,12 @@ public Object transform(Object object) {
}
}));
+ result.put("groupNames", CollectionUtils.collect(bean.getProjectHeader().getGroups(), new Transformer() {
+ public Object transform(Object object) {
+ return ((ProjectGroup) object).getName();
+ }
+ }));
+
// documentation
result.put("documentation", CollectionUtils.collect(assetDTO.getDocumentation(), new Transformer() {
public Object transform(Object object) {
diff --git a/src/java/main/com/topcoder/direct/services/view/util/DirectUtils.java b/src/java/main/com/topcoder/direct/services/view/util/DirectUtils.java
index 40cfb52dd..f6ca747fd 100644
--- a/src/java/main/com/topcoder/direct/services/view/util/DirectUtils.java
+++ b/src/java/main/com/topcoder/direct/services/view/util/DirectUtils.java
@@ -36,12 +36,7 @@
import com.topcoder.management.deliverable.Submission;
import com.topcoder.management.deliverable.Upload;
import com.topcoder.management.deliverable.persistence.UploadPersistenceException;
-import com.topcoder.management.project.CopilotContestExtraInfo;
-import com.topcoder.management.project.CopilotContestExtraInfoType;
-import com.topcoder.management.project.Prize;
-import com.topcoder.management.project.ProjectCopilotType;
-import com.topcoder.management.project.ProjectPropertyType;
-import com.topcoder.management.project.ProjectType;
+import com.topcoder.management.project.*;
import com.topcoder.management.resource.Resource;
import com.topcoder.management.resource.ResourceRole;
import com.topcoder.management.review.data.Comment;
@@ -954,6 +949,9 @@ public final class DirectUtils {
private static final String QUERY_GET_USERS_FROM_ID = "SELECT user_id, handle FROM user WHERE user_id in (";
+ private static final String QUERY_GET_SECURITY_GROUP_FROM_ID = "SELECT group_id, description FROM security_groups " +
+ " WHERE group_id in (";
+
/**
*
* Default Constructor.
@@ -3790,4 +3788,48 @@ public static Map> getUnAgreedProjectTermByUser(long proje
DatabaseUtils.close(con);
}
}
+
+ /**
+ * Get security Groups id and name from given projectGroup id
+ *
+ * @param projectGroups project group
+ * @return List of security group
+ * @throws Exception
+ */
+ public static List getGroupIdAndName(List projectGroups) throws Exception{
+ Connection con = null;
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ if (projectGroups == null || projectGroups.size() < 1){
+ return null;
+ }
+
+ try{
+ con = DatabaseUtils.getDatabaseConnection(DBMS.COMMON_OLTP_DATASOURCE_NAME);
+ StringBuilder sbQueryGids = new StringBuilder(QUERY_GET_SECURITY_GROUP_FROM_ID);
+ for (ProjectGroup pg : projectGroups){
+ sbQueryGids.append(" ?,");
+ }
+ sbQueryGids.setCharAt(sbQueryGids.length() - 1, ')');
+
+ ps = con.prepareStatement(sbQueryGids.toString());
+
+ for (int i = 0; i < projectGroups.size(); i++){
+ ps.setString(i + 1, String.valueOf(projectGroups.get(i).getId()));
+ }
+ rs = ps.executeQuery();
+ List result = new ArrayList();
+ while (rs.next()){
+ ProjectGroup pg = new ProjectGroup();
+ pg.setId(rs.getLong("group_id"));
+ pg.setName(rs.getString("description"));
+ result.add(pg);
+ }
+ return result;
+ }finally {
+ DatabaseUtils.close(rs);
+ DatabaseUtils.close(ps);
+ DatabaseUtils.close(con);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/web/scripts/launch/contestDetailSoftware.js b/src/web/scripts/launch/contestDetailSoftware.js
index de3ddcc0c..b9ec36b0c 100644
--- a/src/web/scripts/launch/contestDetailSoftware.js
+++ b/src/web/scripts/launch/contestDetailSoftware.js
@@ -207,14 +207,13 @@ $(document).ready(function(){
});
$(".cancel_text").click(function(){
+ groupCancel = true;
jQuery_1_11_1("#groups").magicSuggest().clear();
- if (mainWidget.softwareCompetition.groups.length > 0){
- jQuery_1_11_1("#groups").magicSuggest().setValue(mainWidget.softwareCompetition.groups);
- }
+ jQuery_1_11_1("#groups").magicSuggest().setValue(mainWidget.softwareCompetition.groups);
+ groupCancel = false;
+
jQuery_1_11_1("#preRegisterUsers").magicSuggest().clear();
- if (mainWidget.softwareCompetition.registrants.length > 0) {
- jQuery_1_11_1("#preRegisterUsers").magicSuggest().setValue(mainWidget.softwareCompetition.registrants);
- }
+ jQuery_1_11_1("#preRegisterUsers").magicSuggest().setValue(mainWidget.softwareCompetition.registrants);
populateTypeSection();
showTypeSectionDisplay();
});
@@ -875,6 +874,7 @@ function initContest(contestJson) {
}
mainWidget.softwareCompetition.groups = contestJson.groupIds;
+ mainWidget.softwareCompetition.groupNames = contestJson.groupNames;
var projectHeader = mainWidget.softwareCompetition.projectHeader;
projectHeader.tcDirectProjectId = contestJson.tcDirectProjectId;
@@ -1212,6 +1212,17 @@ function initContest(contestJson) {
}
$(".drHide").hide();
+
+ if (securityGroups.length < 1 && mainWidget.softwareCompetition.groups.length > 0) {
+ var allGroups = [];
+ $.each(mainWidget.softwareCompetition.groups, function(i, val){
+ allGroups.push({id: val, name: mainWidget.softwareCompetition.groupNames[i]});
+ });
+ jQuery_1_11_1("#groups").magicSuggest().setData(allGroups);
+ }
+
+ jQuery_1_11_1("#groups").magicSuggest().setValue(mainWidget.softwareCompetition.groups);
+
}
@@ -1270,8 +1281,6 @@ function populateTypeSection() {
$('#rProjectName').text(mainWidget.softwareCompetition.projectHeader.tcDirectProjectName);
}
- jQuery_1_11_1("#groups").magicSuggest().setValue(mainWidget.softwareCompetition.groups);
-
if (isF2F() || isDesignF2F()) {
var privateProject = p[TASK_FLAG];
var registrants = [];
@@ -1387,16 +1396,7 @@ function populateTypeSection() {
}
- var groupMap = {};
- $.each(securityGroups, function(i, val){
- groupMap[''+val.id]=val.name;
- });
- var selectedGroupName = [];
- $.each(mainWidget.softwareCompetition.groups, function(i, val){
- selectedGroupName.push(groupMap[val]);
- });
-
- $('#rswGroups').html(selectedGroupName.join(", "));
+ $('#rswGroups').html(mainWidget.softwareCompetition.groupNames.join(", "));
}
/**
@@ -1453,6 +1453,11 @@ function saveTypeSection() {
success: function (jsonResult) {
handleSaveAsDraftContestResult(jsonResult);
mainWidget.softwareCompetition.groups = jQuery_1_11_1("#groups").magicSuggest().getValue();
+ mainWidget.softwareCompetition.groupNames=[];
+ $.each(jQuery_1_11_1("#groups").magicSuggest().getSelection(), function(i, val){
+ mainWidget.softwareCompetition.groupNames.push(val.name);
+ })
+ mainWidget.softwareCompetition.registrants = jQuery_1_11_1("#preRegisterUsers").magicSuggest().getSelection().slice();
populateTypeSection();
populateRoundSection();
if (mainWidget.competitionType == "SOFTWARE") {
diff --git a/src/web/scripts/launch/main.js b/src/web/scripts/launch/main.js
index 4a230fb39..a4709bf80 100644
--- a/src/web/scripts/launch/main.js
+++ b/src/web/scripts/launch/main.js
@@ -203,6 +203,7 @@ var swDocuments = [];
var REPORTING_ID = "36";
var securityGroups = [];
+var groupCancel = false;
/**
* Configuration/General Set up
*/
@@ -232,9 +233,13 @@ $(document).ready(function() {
var ms_group = jQuery_1_11_1("#groups").magicSuggest({
placeholder: 'Type group name here',
allowFreeEntries: false,
- data: securityGroups
+ data: securityGroups,
+ disabled: securityGroups.length > 0 ? false : true
});
jQuery_1_11_1(ms_group).on('selectionchange', function(e,m){
+ if (groupCancel){
+ return;
+ }
if (this.getValue().length > 0 && jQuery_1_11_1("#preRegisterUsers").magicSuggest().getValue().length > 0){
displayWarning("#yesNoConfirmation", "Confirmation", "Changing group will remove all assigned members.\n" +
"Do you want to proceed?", "OK", function(){
From d49c967b8b756124d53873524a83aad776779bdd Mon Sep 17 00:00:00 2001
From: Deddy Syefria
Date: Thu, 12 Oct 2017 01:24:36 +0700
Subject: [PATCH 2/3] use group api to get groups
---
conf/web/WEB-INF/applicationContext.xml | 1 +
conf/web/WEB-INF/struts.xml | 5 ++
.../action/contest/launch/CommonAction.java | 86 +++++++++++++++++--
src/web/scripts/launch/main.js | 68 +++++++++------
token.properties.docker | 1 +
token.properties.example | 5 +-
6 files changed, 133 insertions(+), 33 deletions(-)
diff --git a/conf/web/WEB-INF/applicationContext.xml b/conf/web/WEB-INF/applicationContext.xml
index 5cd52d15a..53dd3fd32 100644
--- a/conf/web/WEB-INF/applicationContext.xml
+++ b/conf/web/WEB-INF/applicationContext.xml
@@ -356,6 +356,7 @@
+
+
+
+
+
+
diff --git a/src/java/main/com/topcoder/direct/services/view/action/contest/launch/CommonAction.java b/src/java/main/com/topcoder/direct/services/view/action/contest/launch/CommonAction.java
index 04056ac11..606fe4336 100644
--- a/src/java/main/com/topcoder/direct/services/view/action/contest/launch/CommonAction.java
+++ b/src/java/main/com/topcoder/direct/services/view/action/contest/launch/CommonAction.java
@@ -3,11 +3,8 @@
*/
package com.topcoder.direct.services.view.action.contest.launch;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.net.URI;
+import java.util.*;
import com.topcoder.clients.model.Project;
import com.topcoder.clients.model.ProjectContestFee;
@@ -29,11 +26,21 @@
import com.topcoder.direct.services.view.util.AuthorizationProvider;
import com.topcoder.direct.services.view.util.DataProvider;
import com.topcoder.direct.services.view.util.DirectUtils;
+import com.topcoder.direct.services.view.util.JwtTokenUpdater;
import com.topcoder.direct.services.view.util.challenge.CostCalculationService;
import com.topcoder.security.TCSubject;
import com.topcoder.service.facade.contest.ContestServiceException;
import com.topcoder.service.facade.project.DAOFault;
+import com.topcoder.util.log.Level;
import org.apache.commons.lang3.StringEscapeUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpHeaders;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
import com.topcoder.management.project.ProjectGroup;
@@ -130,6 +137,16 @@ public class CommonAction extends BaseContestFeeAction {
private long categoryId;
+ private String userGroupsApiEndpoint;
+
+ /**
+ * The jackson object mapping which is used to deserialize json return from API to domain model.
+ */
+ protected static final ObjectMapper objectMapper;
+ static {
+ objectMapper = new ObjectMapper();
+ }
+
/**
*
* Executes the action.
@@ -325,7 +342,6 @@ public String getContestConfigs() throws Exception {
configs.put("copilotFees", ConfigUtils.getCopilotFees());
configs.put("billingInfos", getBillingProjectInfos());
- configs.put("groups", getAllProjectGroups());
configs.put("platforms", getReferenceDataBean().getPlatforms());
configs.put("technologies", getReferenceDataBean().getTechnologies());
setResult(configs);
@@ -552,4 +568,62 @@ public long getCategoryId() {
public void setCategoryId(long categoryId) {
this.categoryId = categoryId;
}
+
+ /**
+ * Get Accessible security groups from group Api
+ *
+ * @return
+ */
+ public String getGroups() {
+ try {
+ TCSubject tcSubject = DirectUtils.getTCSubjectFromSession();
+ URIBuilder uri = new URIBuilder(userGroupsApiEndpoint);
+
+ if (!DirectUtils.isCockpitAdmin(tcSubject) && !DirectUtils.isTcStaff(tcSubject)) {
+ uri.setParameter("memberId", String.valueOf(tcSubject.getUserId()));
+ }
+
+ DefaultHttpClient httpClient = new DefaultHttpClient();
+
+ HttpGet getRequest = new HttpGet(uri.build());
+ getLogger().log(Level.INFO, "Getting Group with thi uri: " + uri.build().toString());
+
+ String v3Token = new JwtTokenUpdater().check().getToken();
+
+ getRequest.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + v3Token);
+
+ getRequest.addHeader(HttpHeaders.ACCEPT, "application/json");
+ HttpResponse httpResponse = httpClient.execute(getRequest);
+
+ HttpEntity entity = httpResponse.getEntity();
+
+ if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
+ throw new Exception("Unable to get groups from the API:" + httpResponse.getStatusLine().getReasonPhrase());
+ }
+
+ JsonNode result = objectMapper.readTree(entity.getContent());
+ JsonNode groups = result.path("result").path("content");
+ Set