|
53 | 53 | /**
|
54 | 54 | * Action supporting project work management page.
|
55 | 55 | *
|
56 |
| - * |
57 | 56 | * <p>
|
58 | 57 | * Version 1.1 Change notes:
|
59 | 58 | * <ol>
|
60 | 59 | * <li>Added {@link #resourceManager} property.</li>
|
61 | 60 | * <li>Added {@link #resolveSubmitter(Submission)} method.</li>
|
62 | 61 | * </ol>
|
63 | 62 | * </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 |
66 | 78 | */
|
67 | 79 | public class ProjectWorkManagementAction extends BaseDirectStrutsAction implements FormAction<ProjectIdForm> {
|
68 | 80 |
|
@@ -129,6 +141,13 @@ public class ProjectWorkManagementAction extends BaseDirectStrutsAction implemen
|
129 | 141 | */
|
130 | 142 | private String demandWorkId;
|
131 | 143 |
|
| 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 | + |
132 | 151 | /**
|
133 | 152 | * <p>
|
134 | 153 | * Represents the MIME type retriever used to retrieve the MIME types.
|
@@ -378,6 +397,32 @@ public String getChallengesForWorkStepAndProject() {
|
378 | 397 | return SUCCESS;
|
379 | 398 | }
|
380 | 399 |
|
| 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 | + |
381 | 426 | /**
|
382 | 427 | * Helper method to build the phase result for the ajax response.
|
383 | 428 | *
|
@@ -749,7 +794,17 @@ public String pushSubmissions() {
|
749 | 794 |
|
750 | 795 | logger.info("Starting submission publishing...");
|
751 | 796 |
|
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)); |
753 | 808 |
|
754 | 809 | logger.info("Submissions published");
|
755 | 810 | //
|
@@ -1180,6 +1235,27 @@ public void setResourceManager(ResourceManager resourceManager) {
|
1180 | 1235 | this.resourceManager = resourceManager;
|
1181 | 1236 | }
|
1182 | 1237 |
|
| 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 | + |
1183 | 1259 | public static class SubmissionPresentationFilter implements FilenameFilter {
|
1184 | 1260 |
|
1185 | 1261 | /**
|
@@ -1221,4 +1297,89 @@ public boolean accept(File dir, String name) {
|
1221 | 1297 | return name.startsWith(this.filenamePrefix);
|
1222 | 1298 | }
|
1223 | 1299 | }
|
| 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 | + } |
1224 | 1385 | }
|
0 commit comments