862862 * <li>Add {@link #cancelSoftwareContestByUser(TCSubject, long)}</li>
863863 * </ul>
864864 *
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>
865870 * @author snow01, pulky, murphydog, waits, BeBetter, hohosky, isv, tangzx, GreatKevin, lmmortal, minhu, GreatKevin, tangzx
866871 * @author isv, GreatKevin, Veve, deedee, TCSCODER, TCSASSEMBLER
867- * @version 3.5
872+ * @version 3.6
868873 */
869874@ Stateless
870875@ TransactionManagement (TransactionManagementType .CONTAINER )
@@ -963,6 +968,18 @@ public class ContestServiceFacadeBean implements ContestServiceFacadeLocal, Cont
963968 */
964969 private static final String RESOURCE_INFO_PAYMENT_NA = "N/A" ;
965970
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+
966983 /**
967984 * Email file template source key that is used by email generator.
968985 */
@@ -1011,6 +1028,13 @@ public class ContestServiceFacadeBean implements ContestServiceFacadeLocal, Cont
10111028 */
10121029 private static final String ADMIN_ROLE = "Cockpit Administrator" ;
10131030
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+
10141038 /**
10151039 * Private constant specifying project submission phase name.
10161040 *
@@ -4098,13 +4122,35 @@ private com.topcoder.management.resource.Resource createIterativeReviewerResourc
40984122 * @throws UserServiceException if error when getting resource handle.
40994123 * @since 2.5
41004124 */
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 {
41024144 com .topcoder .management .resource .Resource resource = new com .topcoder .management .resource .Resource ();
41034145 // unset id
41044146 resource .setId (-1 );
41054147
41064148 // 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+ }
41084154
41094155 resource .setProperty (RESOURCE_INFO_HANDLE , userService .getUserHandle (userId ));
41104156 resource .setProperty (RESOURCE_INFO_EXTERNAL_REFERENCE_ID , String .valueOf (userId ));
@@ -4121,6 +4167,7 @@ private com.topcoder.management.resource.Resource createReviewerResource(long us
41214167 if (!hasPayment ) {
41224168 resource .setProperty (RESOURCE_INFO_PAYMENT_STATUS , RESOURCE_INFO_PAYMENT_STATUS_NA );
41234169 resource .setProperty (RESOURCE_INFO_PAYMENT , RESOURCE_INFO_PAYMENT_NA );
4170+ resource .setProperty (RESOURCE_INFO_MANUAL_PAYMENT , "true" );
41244171 }
41254172
41264173 // set registration date to now
@@ -9083,28 +9130,45 @@ public void closeSoftwareContest(TCSubject tcSubject, long projectId, long winne
90839130
90849131 //close submission and review phase
90859132 com .topcoder .project .phases .Phase submissionPhase = null ;
9133+ com .topcoder .project .phases .Phase reviewPhase = null ;
90869134 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 ())) {
90919139 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+
91069149 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 );
91079156 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 ;
91089172 }
91099173 }
91109174 }
@@ -9115,14 +9179,37 @@ public void closeSoftwareContest(TCSubject tcSubject, long projectId, long winne
91159179 Submission submission = uploadManager .getSubmission (submissionId );
91169180 submission .setInitialScore (100.0 );
91179181 submission .setFinalScore (100.0 );
9182+ submission .setPlacement (1L );
9183+ submission .setPrize (contest .getPrizes ().get (0 ));
91189184 uploadManager .updateSubmission (submission , String .valueOf (tcSubject .getUserId ()));
91199185
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+
91209201 Upload upload = submission .getUpload ();
91219202 upload .setProjectPhase (submissionPhase .getId ());
91229203 uploadManager .updateUpload (upload , String .valueOf (tcSubject .getUserId ()));
91239204 } catch (IOException e ) {
91249205 logger .error ("Failed to create submission file" );
91259206 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 );
91269213 } catch (ProjectServicesException e ) {
91279214 logger .error ("Failed to update phase" );
91289215 throw new ContestServiceException ("Failed to update phase" , e );
0 commit comments