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

Commit e08df3e

Browse files
committed
Merge pull request #128 from isvisv/dev
TOPCODER DIRECT - ASP INTEGRATION WORK MANAGEMENT IMPROVEMENT code
2 parents 73ff0e4 + 85ff0d1 commit e08df3e

File tree

6 files changed

+432
-26
lines changed

6 files changed

+432
-26
lines changed

conf/web/WEB-INF/struts.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,12 @@
789789
<result name="error" type="json"/>
790790
</action>
791791

792+
<action name="getSubmissionPushStatus" method="getSubmissionPushStatus" class="projectWorkManagementAction">
793+
<interceptor-ref name="securedProjectPreProcessorStack"/>
794+
<result name="success" type="json"/>
795+
<result name="error" type="json"/>
796+
</action>
797+
792798
<action name="getWorkStepChallenges" method="getChallengesForWorkStepAndProject" class="projectWorkManagementAction">
793799
<interceptor-ref name="securedProjectPreProcessorStack"/>
794800
<result name="success" type="json"/>

src/java/main/com/topcoder/direct/services/view/action/project/ProjectWorkManagementAction.java

Lines changed: 165 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,28 @@
5353
/**
5454
* Action supporting project work management page.
5555
*
56-
*
5756
* <p>
5857
* Version 1.1 Change notes:
5958
* <ol>
6059
* <li>Added {@link #resourceManager} property.</li>
6160
* <li>Added {@link #resolveSubmitter(Submission)} method.</li>
6261
* </ol>
6362
* </p>
64-
* @author isv, TCSASSEMBLER
65-
* @version 1.1
63+
*
64+
* <p>
65+
* Version 1.2 (TOPCODER DIRECT - ASP INTEGRATION WORK MANAGEMENT IMPROVEMENT) Change notes:
66+
* <ol>
67+
* <li>Temporarily switched {@link ASPClient} into <code>demo</code> mode just for sake of testing/reviewing this
68+
* submission.</li>
69+
* <li>Added {@link SubmissionPusher} class.</li>
70+
* <li>Added {@link #pushId} property.</li>
71+
* <li>Added {@link #getSubmissionPushStatus()} method.</li>
72+
* <li>Moved the code pushing the submissions to separate thread.</li>
73+
* </ol>
74+
* </p>
75+
*
76+
* @author isv
77+
* @version 1.2
6678
*/
6779
public class ProjectWorkManagementAction extends BaseDirectStrutsAction implements FormAction<ProjectIdForm> {
6880

@@ -129,6 +141,13 @@ public class ProjectWorkManagementAction extends BaseDirectStrutsAction implemen
129141
*/
130142
private String demandWorkId;
131143

144+
/**
145+
* <p>A <code>long</code> providing the value for pushId property.</p>
146+
*
147+
* @since 1.2
148+
*/
149+
private long pushId;
150+
132151
/**
133152
* <p>
134153
* Represents the MIME type retriever used to retrieve the MIME types.
@@ -378,6 +397,32 @@ public String getChallengesForWorkStepAndProject() {
378397
return SUCCESS;
379398
}
380399

400+
/**
401+
* <p>Gets the current status for requested submission's push.</p>
402+
*
403+
* @return {@link #SUCCESS} always.
404+
* @since 1.2
405+
*/
406+
public String getSubmissionPushStatus() {
407+
try {
408+
checkPermission();
409+
410+
String submissionPushStatus = DirectUtils.getSubmissionPushStatus(getPushId());
411+
412+
Map<String, String> result = new HashMap<String, String>();
413+
result.put("pushStatus", submissionPushStatus);
414+
415+
setResult(result);
416+
} catch (Throwable e) {
417+
logger.error("Unable to get submission's push status", e);
418+
if (getModel() != null) {
419+
setResult(e);
420+
}
421+
}
422+
423+
return SUCCESS;
424+
}
425+
381426
/**
382427
* Helper method to build the phase result for the ajax response.
383428
*
@@ -749,7 +794,17 @@ public String pushSubmissions() {
749794

750795
logger.info("Starting submission publishing...");
751796

752-
aspClient.publishSubmissionsToWorkStep(workStep, submissionsToPush);
797+
// Start a separate thread for pushing the submissions
798+
long userId = getCurrentUser().getUserId();
799+
long pushId = DirectUtils.insertSubmissionPushStatus(getFormData().getProjectId(), userId);
800+
if (pushId == 0) {
801+
throw new Exception("Could not create new record for submission's push status");
802+
}
803+
SubmissionPusher submissionPusher = new SubmissionPusher(aspClient, workStep, submissionsToPush, userId,
804+
pushId);
805+
Thread submissionPusherThread = new Thread(submissionPusher);
806+
submissionPusherThread.start();
807+
result.put("pushId", String.valueOf(pushId));
753808

754809
logger.info("Submissions published");
755810
//
@@ -1180,6 +1235,27 @@ public void setResourceManager(ResourceManager resourceManager) {
11801235
this.resourceManager = resourceManager;
11811236
}
11821237

1238+
1239+
/**
1240+
* <p>Gets the pushId property.</p>
1241+
*
1242+
* @return a <code>long</code> providing the value for pushId property.
1243+
* @since 1.2
1244+
*/
1245+
public long getPushId() {
1246+
return this.pushId;
1247+
}
1248+
1249+
/**
1250+
* <p>Sets the pushId property.</p>
1251+
*
1252+
* @param pushId a <code>long</code> providing the value for pushId property.
1253+
* @since 1.2
1254+
*/
1255+
public void setPushId(long pushId) {
1256+
this.pushId = pushId;
1257+
}
1258+
11831259
public static class SubmissionPresentationFilter implements FilenameFilter {
11841260

11851261
/**
@@ -1221,4 +1297,89 @@ public boolean accept(File dir, String name) {
12211297
return name.startsWith(this.filenamePrefix);
12221298
}
12231299
}
1300+
1301+
/**
1302+
* <p>A separate thread to be used for pushing the submissions to <code>TopCoder Connect</code> system.</p>
1303+
*
1304+
* @author TCSCODER
1305+
* @version 1.0
1306+
* @since 1.1 (TOPCODER DIRECT - ASP INTEGRATION WORK MANAGEMENT IMPROVEMENT)
1307+
*/
1308+
private static class SubmissionPusher implements Runnable {
1309+
1310+
/**
1311+
* <p>Logger for this class.</p>
1312+
*/
1313+
private static final Logger logger = Logger.getLogger(SubmissionPusher.class);
1314+
1315+
/**
1316+
* <p>An <code>ASPClient</code> providing interface to TopCoder Connect system.</p>
1317+
*/
1318+
private ASPClient aspClient;
1319+
1320+
/**
1321+
* <p>A <code>WorkStep</code> specifying the work step the submissions correspond to.</p>
1322+
*/
1323+
private WorkStep workStep;
1324+
1325+
/**
1326+
* <p>A <code>List</code> of submissions to push to TopCoder Connect.</p>
1327+
*/
1328+
private List<List<com.appirio.client.asp.api.Submission>> submissionsToPush;
1329+
1330+
/**
1331+
* <p>A <code>Long</code> providing the ID for submission push status.</p>
1332+
*/
1333+
private long pushId;
1334+
1335+
/**
1336+
* <p>A <code>Long</code> providing the ID for user pushing the submission.</p>
1337+
*/
1338+
private long userId;
1339+
1340+
/**
1341+
* <p>Constructs new <code>SubmissionPusher</code> instance with specified ASP client.</p>
1342+
*
1343+
* @param aspClient an <code>ASPClient</code> providing interface to TopCoder Connect system.
1344+
* @param workStep a <code>WorkStep</code> specifying the work step the submissions correspond to.
1345+
* @param submissionsToPush a <code>List</code> of submissions to push to TopCoder Connect.
1346+
* @param userId a <code>long</code> providing the ID for user pushing the submission.
1347+
* @param pushId a <code>long</code> providing the ID for submission push status.
1348+
*/
1349+
private SubmissionPusher(ASPClient aspClient, WorkStep workStep,
1350+
List<List<com.appirio.client.asp.api.Submission>> submissionsToPush,
1351+
long userId, long pushId) {
1352+
this.aspClient = aspClient;
1353+
this.workStep = workStep;
1354+
this.submissionsToPush = submissionsToPush;
1355+
this.userId = userId;
1356+
this.pushId = pushId;
1357+
}
1358+
1359+
/**
1360+
* <p>Pushes intended submissions to <code>TopCoder Connect</code> system via <code>ASP Client</code>.</p>
1361+
*/
1362+
public void run() {
1363+
logger.info("Starting to push the submissions to TopCoder Connect. Push ID: " + this.pushId);
1364+
1365+
boolean success = false;
1366+
try {
1367+
this.aspClient.publishSubmissionsToWorkStep(this.workStep, this.submissionsToPush);
1368+
success = true;
1369+
logger.info("Pushed submissions to TopCoder Connect. Push ID: " + this.pushId);
1370+
} catch (Exception e) {
1371+
logger.error("Failed to push submissions for push ID: " + this.pushId, e);
1372+
}
1373+
1374+
try {
1375+
if (success) {
1376+
DirectUtils.updateSubmissionPushStatus(this.pushId, this.userId, "SUCCESS");
1377+
} else {
1378+
DirectUtils.updateSubmissionPushStatus(this.pushId, this.userId, "FAIL");
1379+
}
1380+
} catch (Exception e) {
1381+
logger.error("Failed to update submission's push status for push ID: " + this.pushId, e);
1382+
}
1383+
}
1384+
}
12241385
}

0 commit comments

Comments
 (0)