862
862
* <li>Add {@link #cancelSoftwareContestByUser(TCSubject, long)}</li>
863
863
* </ul>
864
864
*
865
+ * Version 3.6 (TOPCODER DIRECT - FIXES FOR CLOSE PRIVATE CHALLENGE IMMEDIATELY)
866
+ * <ul>
867
+ * <li>Refactor {@link #createReviewerResource(long, long, long, boolean, boolean)}</li>
868
+ * <li>Fix {@link #closeSoftwareContest(TCSubject, long, long)} to work with auto pilot</li>
869
+ * </ul>
865
870
* @author snow01, pulky, murphydog, waits, BeBetter, hohosky, isv, tangzx, GreatKevin, lmmortal, minhu, GreatKevin, tangzx
866
871
* @author isv, GreatKevin, Veve, deedee, TCSCODER, TCSASSEMBLER
867
- * @version 3.5
872
+ * @version 3.6
868
873
*/
869
874
@ Stateless
870
875
@ TransactionManagement (TransactionManagementType .CONTAINER )
@@ -963,6 +968,18 @@ public class ContestServiceFacadeBean implements ContestServiceFacadeLocal, Cont
963
968
*/
964
969
private static final String RESOURCE_INFO_PAYMENT_NA = "N/A" ;
965
970
971
+ /**
972
+ * Resource info attribute for Manual payment
973
+ * @since 3.6
974
+ */
975
+ private static final String RESOURCE_INFO_MANUAL_PAYMENT = "Manual Payments" ;
976
+
977
+ /**
978
+ * Scorecard ID attibute
979
+ * @since 3.6
980
+ */
981
+ private static final String SCORECARD_ID_ATTRIBUTE = "Scorecard ID" ;
982
+
966
983
/**
967
984
* Email file template source key that is used by email generator.
968
985
*/
@@ -1011,6 +1028,13 @@ public class ContestServiceFacadeBean implements ContestServiceFacadeLocal, Cont
1011
1028
*/
1012
1029
private static final String ADMIN_ROLE = "Cockpit Administrator" ;
1013
1030
1031
+ /**
1032
+ * Private constant specifying project registration phase name.
1033
+ *
1034
+ * @since 3.6
1035
+ */
1036
+ private static final String PROJECT_REGISTRATION_PHASE_NAME = "Registration" ;
1037
+
1014
1038
/**
1015
1039
* Private constant specifying project submission phase name.
1016
1040
*
@@ -4098,13 +4122,35 @@ private com.topcoder.management.resource.Resource createIterativeReviewerResourc
4098
4122
* @throws UserServiceException if error when getting resource handle.
4099
4123
* @since 2.5
4100
4124
*/
4101
- private com .topcoder .management .resource .Resource createReviewerResource (long userId , long contestId , long phaseId , boolean hasPayment ) throws UserServiceException {
4125
+ private com .topcoder .management .resource .Resource createReviewerResource (long userId , long contestId , long phaseId ,
4126
+ boolean hasPayment ) throws UserServiceException {
4127
+ return createReviewerResource (userId , contestId , phaseId , hasPayment , false );
4128
+ }
4129
+
4130
+ /**
4131
+ * Creates a Reviewer Resource to add to the contest
4132
+ *
4133
+ * @param userId the user id
4134
+ * @param contestId the contest id.
4135
+ * @param phaseId the phase the resource adds to, 0 for not add
4136
+ * @param hasPayment whether this resource should be paid.
4137
+ * @param iterativeReviewer whether this iterative review
4138
+ * @return the created Reviewer resource to add.
4139
+ * @throws UserServiceException if error when getting resource handle.
4140
+ * @since 3.6
4141
+ */
4142
+ private com .topcoder .management .resource .Resource createReviewerResource (long userId , long contestId , long phaseId ,
4143
+ boolean hasPayment , boolean iterativeReviewer ) throws UserServiceException {
4102
4144
com .topcoder .management .resource .Resource resource = new com .topcoder .management .resource .Resource ();
4103
4145
// unset id
4104
4146
resource .setId (-1 );
4105
4147
4106
4148
// set resource to reviewer
4107
- resource .setResourceRole (new ResourceRole (ResourceRole .RESOURCE_ROLE_REVIEWER_ID ));
4149
+ if (iterativeReviewer ){
4150
+ resource .setResourceRole (new ResourceRole (ResourceRole .RESOURCE_ROLE_ITERATIVE_REVIEWER_ID ));
4151
+ }else {
4152
+ resource .setResourceRole (new ResourceRole (ResourceRole .RESOURCE_ROLE_REVIEWER_ID ));
4153
+ }
4108
4154
4109
4155
resource .setProperty (RESOURCE_INFO_HANDLE , userService .getUserHandle (userId ));
4110
4156
resource .setProperty (RESOURCE_INFO_EXTERNAL_REFERENCE_ID , String .valueOf (userId ));
@@ -4121,6 +4167,7 @@ private com.topcoder.management.resource.Resource createReviewerResource(long us
4121
4167
if (!hasPayment ) {
4122
4168
resource .setProperty (RESOURCE_INFO_PAYMENT_STATUS , RESOURCE_INFO_PAYMENT_STATUS_NA );
4123
4169
resource .setProperty (RESOURCE_INFO_PAYMENT , RESOURCE_INFO_PAYMENT_NA );
4170
+ resource .setProperty (RESOURCE_INFO_MANUAL_PAYMENT , "true" );
4124
4171
}
4125
4172
4126
4173
// set registration date to now
@@ -9083,28 +9130,45 @@ public void closeSoftwareContest(TCSubject tcSubject, long projectId, long winne
9083
9130
9084
9131
//close submission and review phase
9085
9132
com .topcoder .project .phases .Phase submissionPhase = null ;
9133
+ com .topcoder .project .phases .Phase reviewPhase = null ;
9086
9134
for (com .topcoder .project .phases .Phase phase : phases ) {
9087
- if (PROJECT_SUBMISSION_PHASE_NAME .equals (phase .getPhaseType ().getName ()) ||
9088
- PROJECT_ITERATIVE_REVIEW_PHASE_NAME .equals (phase .getPhaseType ().getName ()) ||
9089
- PROJECT_REVIEW_PHASE_NAME .equals (phase .getPhaseType ().getName ())) {
9090
- Date scheduleStartDate = phase .getScheduledStartDate ();
9135
+ if (PROJECT_REGISTRATION_PHASE_NAME .equals (phase .getPhaseType ().getName ()) ||
9136
+ PROJECT_SUBMISSION_PHASE_NAME .equals (phase .getPhaseType ().getName ()) ||
9137
+ PROJECT_REVIEW_PHASE_NAME .equals (phase .getPhaseType ().getName ()) ||
9138
+ PROJECT_ITERATIVE_REVIEW_PHASE_NAME . equals ( phase .getPhaseType (). getName ())) {
9091
9139
Date currentDate = new Date ();
9092
- Date actualStartDate = null ;
9093
- long length = 0L ;
9094
- if (currentDate .before (scheduleStartDate )){
9095
- //set length to 5 minutes
9096
- length = 5 * MINUTE_IN_MILIS ;
9097
- actualStartDate = new Date (currentDate .getTime () - length );
9098
- } else {
9099
- actualStartDate = scheduleStartDate ;
9100
- length = currentDate .getTime () - scheduleStartDate .getTime ();
9101
- }
9102
- phase .setActualStartDate (actualStartDate );
9103
- phase .setActualEndDate (currentDate );
9104
- phase .setLength (length );
9105
- phase .setPhaseStatus (PhaseStatus .CLOSED );
9140
+ //length 1 hour
9141
+ long length = 60 * MINUTE_IN_MILIS ;
9142
+ //submision start 3h before
9143
+ Date regStartDate = new Date (currentDate .getTime () - 180 * MINUTE_IN_MILIS );
9144
+ //submision start 2h before
9145
+ Date submissionStartDate = new Date (currentDate .getTime () - 120 * MINUTE_IN_MILIS );
9146
+ //submission end / review start 1h before
9147
+ Date submissionEndDate = new Date (currentDate .getTime () - 60 * MINUTE_IN_MILIS );
9148
+
9106
9149
if (PROJECT_SUBMISSION_PHASE_NAME .equals (phase .getPhaseType ().getName ())) {
9150
+ phase .setScheduledStartDate (submissionStartDate );
9151
+ phase .setActualStartDate (submissionStartDate );
9152
+ phase .setScheduledEndDate (submissionEndDate );
9153
+ phase .setActualEndDate (submissionEndDate );
9154
+ phase .setLength (length );
9155
+ phase .setPhaseStatus (PhaseStatus .CLOSED );
9107
9156
submissionPhase = phase ;
9157
+ } else if (PROJECT_REGISTRATION_PHASE_NAME .equals (phase .getPhaseType ().getName ())) {
9158
+ phase .setScheduledStartDate (regStartDate );
9159
+ phase .setFixedStartDate (regStartDate );
9160
+ phase .setActualStartDate (regStartDate );
9161
+ phase .setScheduledEndDate (submissionEndDate );
9162
+ phase .setActualEndDate (submissionEndDate );
9163
+ phase .setLength (2 * length );
9164
+ phase .setPhaseStatus (PhaseStatus .CLOSED );
9165
+ } else {
9166
+ phase .setScheduledStartDate (submissionEndDate );
9167
+ phase .setActualStartDate (submissionEndDate );
9168
+ phase .setScheduledEndDate (currentDate );
9169
+ phase .setLength (length );
9170
+ phase .setPhaseStatus (PhaseStatus .OPEN );
9171
+ reviewPhase = phase ;
9108
9172
}
9109
9173
}
9110
9174
}
@@ -9115,14 +9179,37 @@ public void closeSoftwareContest(TCSubject tcSubject, long projectId, long winne
9115
9179
Submission submission = uploadManager .getSubmission (submissionId );
9116
9180
submission .setInitialScore (100.0 );
9117
9181
submission .setFinalScore (100.0 );
9182
+ submission .setPlacement (1L );
9183
+ submission .setPrize (contest .getPrizes ().get (0 ));
9118
9184
uploadManager .updateSubmission (submission , String .valueOf (tcSubject .getUserId ()));
9119
9185
9186
+ //create reviewer, remove if there is
9187
+ com .topcoder .management .resource .Resource [] reviewers = this .projectServices .searchResources (contest .getId (),
9188
+ ResourceRole .RESOURCE_ROLE_ITERATIVE_REVIEWER_ID );
9189
+ for (com .topcoder .management .resource .Resource r : reviewers ) {
9190
+ this .projectServices .removeResource (r , String .valueOf (tcSubject .getUserId ()));
9191
+ }
9192
+ com .topcoder .management .resource .Resource reviewer = createReviewerResource (winnerId , contest .getId (),
9193
+ reviewPhase .getId (), false , ProjectCategory .FIRST2FINISH .getName ().equals (contest .getProjectCategory ().getName ()));
9194
+
9195
+ reviewer = projectServices .updateResource (reviewer , String .valueOf (tcSubject .getUserId ()));
9196
+
9197
+ //create review
9198
+ Scorecard scorecard = projectServices .getScorecard (Long .parseLong ((String ) reviewPhase .getAttribute (SCORECARD_ID_ATTRIBUTE )));
9199
+ createReview (reviewer , submissionId , 1 , scorecard , reviewPhase .getId ());
9200
+
9120
9201
Upload upload = submission .getUpload ();
9121
9202
upload .setProjectPhase (submissionPhase .getId ());
9122
9203
uploadManager .updateUpload (upload , String .valueOf (tcSubject .getUserId ()));
9123
9204
} catch (IOException e ) {
9124
9205
logger .error ("Failed to create submission file" );
9125
9206
throw new ContestServiceException ("Failed to create submission file" , e );
9207
+ } catch (UserServiceException e ) {
9208
+ logger .error ("User not found: " + String .valueOf (winnerId ));
9209
+ throw new ContestServiceException ("User not found: " + String .valueOf (winnerId ), e );
9210
+ } catch (ReviewManagementException e ) {
9211
+ logger .error ("Failed to create review" );
9212
+ throw new ContestServiceException ("Failed to create review" , e );
9126
9213
} catch (ProjectServicesException e ) {
9127
9214
logger .error ("Failed to update phase" );
9128
9215
throw new ContestServiceException ("Failed to update phase" , e );
0 commit comments