13
13
import java .math .BigDecimal ;
14
14
import java .math .RoundingMode ;
15
15
import java .sql .SQLException ;
16
- import java .util .*;
16
+ import java .util .HashMap ;
17
+ import java .util .List ;
18
+ import java .util .Map ;
19
+ import java .util .Optional ;
17
20
18
21
import static com .google .common .collect .Lists .newArrayList ;
19
22
import static com .topcoder .onlinereview .component .util .CommonUtils .executeSqlWithParam ;
@@ -291,7 +294,7 @@ public class DefaultProjectPaymentCalculator implements ProjectPaymentCalculator
291
294
* </p>
292
295
*/
293
296
public static final String DEFAULT_CONFIG_NAMESPACE =
294
- "com.topcoder.management.payment.calculator.impl.DefaultProjectPaymentCalculator" ;
297
+ "com.topcoder.management.payment.calculator.impl.DefaultProjectPaymentCalculator" ;
295
298
296
299
/**
297
300
* <p>
@@ -463,18 +466,8 @@ public class DefaultProjectPaymentCalculator implements ProjectPaymentCalculator
463
466
* </p>
464
467
*/
465
468
private static final String GET_DEFAULT_PAYMENT_QUERY =
466
- "SELECT fixed_amount, base_coefficient, incremental_coefficient " + "FROM default_project_payment "
467
- + "WHERE project_category_id = ? and resource_role_id = ?" ;
468
-
469
- /**
470
- * <p>
471
- * The SQL query to retrieve metadata for a challenge to determine if it should skip payments calc
472
- * </p>
473
- */
474
- private static final String SKIP_PAYMENTS_FIELD = "skip_payments" ;
475
- private static final String SKIP_PAYMENTS_METADATA_TYPE_ID = "skip_OR_payment_calcs" ; // shared with challenge-api
476
- private static final String GET_METADATA_QUERY =
477
- "SELECT pi.value " + SKIP_PAYMENTS_FIELD + " FROM project_info pi WHERE pi.project_id=? AND pi.project_info_type_id='" + SKIP_PAYMENTS_METADATA_TYPE_ID + "'" ;
469
+ "SELECT fixed_amount, base_coefficient, incremental_coefficient " + "FROM default_project_payment "
470
+ + "WHERE project_category_id = ? and resource_role_id = ?" ;
478
471
479
472
/**
480
473
* <p>
@@ -483,50 +476,30 @@ public class DefaultProjectPaymentCalculator implements ProjectPaymentCalculator
483
476
* </p>
484
477
*/
485
478
private static final String GET_DEFAULT_PAYMENTS_QUERY =
486
- "SELECT dpp.resource_role_id, dpp.fixed_amount, dpp.base_coefficient, dpp.incremental_coefficient,"
487
- + "max(pr.prize_amount) as prize,"
488
- + "sum(case when s.submission_type_id = 1 then 1 else 0 end) as total_contest_submissions,"
489
- + "sum(case when s.submission_type_id = 1 and s.submission_status_id != 2 then 1 else 0 end) "
490
- + "as passed_contest_submissions,"
491
- + "sum(case when s.submission_type_id = 3 then 1 else 0 end) as total_checkpoint_submissions,"
492
- + "sum(case when s.submission_type_id = 3 and s.submission_status_id != 6 then 1 else 0 end) "
493
- + "as passed_checkpoint_submissions, "
494
- + "sum(case when s.submission_type_id = 1 and exists (select 1 from review r "
495
- + "where r.submission_id = s.submission_id and r.committed = 1) then 1 else 0 end) "
496
- + "as total_reviewed_contest_submissions "
497
- + "FROM default_project_payment dpp "
498
- + "INNER JOIN project p ON dpp.project_category_id = p.project_category_id and p.project_id=? "
499
- + "LEFT OUTER JOIN prize pr ON pr.project_id=p.project_id and pr.prize_type_id=15 and pr.place=1 "
500
- + "LEFT OUTER JOIN upload u ON u.project_id = p.project_id and u.upload_type_id = 1 "
501
- + "LEFT OUTER JOIN submission s ON s.submission_type_id in (1,3) and s.upload_id = u.upload_id "
502
- + "and s.submission_status_id in (1,2,3,4,6,7) "
503
- + "WHERE dpp.resource_role_id in (2,4,5,6,7,8,9,14,18,19,20,21) "
504
- + "GROUP BY dpp.resource_role_id, dpp.fixed_amount, dpp.base_coefficient, dpp.incremental_coefficient" ;
479
+ "SELECT dpp.resource_role_id, dpp.fixed_amount, dpp.base_coefficient, dpp.incremental_coefficient,"
480
+ + "max(pr.prize_amount) as prize,"
481
+ + "sum(case when s.submission_type_id = 1 then 1 else 0 end) as total_contest_submissions,"
482
+ + "sum(case when s.submission_type_id = 1 and s.submission_status_id != 2 then 1 else 0 end) "
483
+ + "as passed_contest_submissions,"
484
+ + "sum(case when s.submission_type_id = 3 then 1 else 0 end) as total_checkpoint_submissions,"
485
+ + "sum(case when s.submission_type_id = 3 and s.submission_status_id != 6 then 1 else 0 end) "
486
+ + "as passed_checkpoint_submissions, "
487
+ + "sum(case when s.submission_type_id = 1 and exists (select 1 from review r "
488
+ + "where r.submission_id = s.submission_id and r.committed = 1) then 1 else 0 end) "
489
+ + "as total_reviewed_contest_submissions "
490
+ + "FROM default_project_payment dpp "
491
+ + "INNER JOIN project p ON dpp.project_category_id = p.project_category_id and p.project_id=? "
492
+ + "LEFT OUTER JOIN prize pr ON pr.project_id=p.project_id and pr.prize_type_id=15 and pr.place=1 "
493
+ + "LEFT OUTER JOIN upload u ON u.project_id = p.project_id and u.upload_type_id = 1 "
494
+ + "LEFT OUTER JOIN submission s ON s.submission_type_id in (1,3) and s.upload_id = u.upload_id "
495
+ + "and s.submission_status_id in (1,2,3,4,6,7) "
496
+ + "WHERE dpp.resource_role_id in (2,4,5,6,7,8,9,14,18,19,20,21) "
497
+ + "GROUP BY dpp.resource_role_id, dpp.fixed_amount, dpp.base_coefficient, dpp.incremental_coefficient" ;
505
498
506
499
@ Autowired
507
500
@ Qualifier ("tcsJdbcTemplate" )
508
501
private JdbcTemplate jdbcTemplate ;
509
502
510
- /**
511
- * This contains a list of roles for which payment calculation should be skipped
512
- * when the skip payment flag is set by the self-service app.
513
- */
514
- private List <Long > reviewerRoles ;
515
-
516
- public DefaultProjectPaymentCalculator () {
517
- super ();
518
- // create list of reviewer roles
519
- reviewerRoles = new ArrayList <Long >();
520
- reviewerRoles .add (REVIEWER_RESOURCE_ROLE_ID );
521
- reviewerRoles .add (ACCURACY_REVIEWER_RESOURCE_ROLE_ID );
522
- reviewerRoles .add (FAILURE_REVIEWER_RESOURCE_ROLE_ID );
523
- reviewerRoles .add (STRESS_REVIEWER_RESOURCE_ROLE_ID );
524
- reviewerRoles .add (FINAL_REVIEWER_RESOURCE_ROLE_ID );
525
- reviewerRoles .add (SPECIFICATION_REVIEWER_RESOURCE_ROLE_ID );
526
- reviewerRoles .add (CHECKPOINT_REVIEWER_RESOURCE_ROLE_ID );
527
- reviewerRoles .add (ITERATIVE_REVIEWER_RESOURCE_ROLE_ID );
528
- }
529
-
530
503
/**
531
504
* <p>
532
505
* This method is a concrete implementation of the namesake method defined in the interface.
@@ -566,29 +539,33 @@ public DefaultProjectPaymentCalculator() {
566
539
* If any error occurred during the operation.
567
540
*/
568
541
public Map <Long , BigDecimal > getDefaultPayments (long projectId , List <Long > resourceRoleIDs )
569
- throws ProjectPaymentCalculatorException {
542
+ throws ProjectPaymentCalculatorException {
570
543
String signature = DEFAULT_CONFIG_NAMESPACE + "#getDefaultPayments(long, List<Long>)" ;
571
544
Helper .logEntrance (log , signature , new String [] {"projectId" , "resourceRoleIDs" },
572
- new Object [] {projectId , resourceRoleIDs });
545
+ new Object [] {projectId , resourceRoleIDs });
573
546
574
547
// arguments checking
575
- Helper .checkPositive (projectId , "projectId" );
576
- Helper .checkNotNullNorEmpty (resourceRoleIDs , "resourceRoleIDs" );
577
- Helper .checkNotNullElements (resourceRoleIDs , "resourceRoleIDs" );
548
+ try {
549
+ Helper .checkPositive (projectId , "projectId" );
550
+ Helper .checkNotNullNorEmpty (resourceRoleIDs , "resourceRoleIDs" );
551
+ Helper .checkNotNullElements (resourceRoleIDs , "resourceRoleIDs" );
552
+ } catch (IllegalArgumentException e ) {
553
+ throw Helper .logException (log , signature , e );
554
+ }
578
555
579
556
try {
580
- // get skip payments flag for project
581
- boolean skipPayments = isSkipPaymentsFlagPresentForProject (projectId );
582
- // Execute the query and get the result.
583
- List <Map <String , Object >> resultSet = executeSqlWithParam (jdbcTemplate , GET_DEFAULT_PAYMENTS_QUERY , newArrayList (projectId ));
557
+ // Execute the query and get the result.
558
+ List <Map <String , Object >> resultSet = executeSqlWithParam (jdbcTemplate , GET_DEFAULT_PAYMENTS_QUERY , newArrayList (projectId ));
559
+
584
560
Map <Long , BigDecimal > defaultPaymentsMap = new HashMap <Long , BigDecimal >();
561
+
585
562
// Iterate through the supported resource roles IDs and compute the default payment for each one of the
586
563
// requested resource role
587
564
for (Map <String , Object > row : resultSet ) {
588
565
long roleId = getLong (row , RESOURCE_ROLE_ID_COLUMN );
589
- if (resourceRoleIDs .contains (roleId ) && !( skipPayments && reviewerRoles . contains ( roleId )) ) {
566
+ if (resourceRoleIDs .contains (roleId )) {
590
567
BigDecimal fixedAmount =
591
- new BigDecimal (getDouble (row , FIXED_AMOUNT_COLUMN )).setScale (2 , RoundingMode .HALF_UP );
568
+ new BigDecimal (getDouble (row , FIXED_AMOUNT_COLUMN )).setScale (2 , RoundingMode .HALF_UP );
592
569
float baseCoefficient = ofNullable (getFloat (row , BASE_COEFFICIENT_COLUMN )).orElse (0F );
593
570
float incrementalCoefficient = ofNullable (getFloat (row , INCREMENTAL_COEFFICIENT_COLUMN )).orElse (0F );
594
571
float prize = ofNullable (getFloat (row , PRIZE_COLUMN )).orElse (0F );
@@ -598,42 +575,22 @@ public Map<Long, BigDecimal> getDefaultPayments(long projectId, List<Long> resou
598
575
599
576
// calculate the payment
600
577
BigDecimal augend =
601
- BigDecimal .valueOf ((baseCoefficient + incrementalCoefficient * submissionsCount ) * prize );
578
+ BigDecimal .valueOf ((baseCoefficient + incrementalCoefficient * submissionsCount ) * prize );
579
+
602
580
BigDecimal payment = fixedAmount .add (augend .setScale (2 , RoundingMode .HALF_UP ));
603
581
604
582
// put into the map
605
583
defaultPaymentsMap .put (roleId , payment );
606
584
}
607
585
}
586
+
608
587
Helper .logExit (log , signature , new Object [] {defaultPaymentsMap });
588
+
609
589
return defaultPaymentsMap ;
610
590
} catch (SQLException e ) {
611
591
throw Helper .logException (log , signature , new ProjectPaymentCalculatorException (
612
- "Fails to query project payments from database" , e ));
613
- }
614
- }
615
-
616
- /**
617
- * Queries the project attributes table for the payment skipped flag (challenge metadata in v5)
618
- *
619
- * @param projectId
620
- * @return true if payments are skipped, false, otherwise
621
- */
622
- private boolean isSkipPaymentsFlagPresentForProject (long projectId ) {
623
- List <Map <String , Object >> resultSet = executeSqlWithParam (jdbcTemplate , GET_METADATA_QUERY , newArrayList (projectId ));
624
- if (resultSet == null || resultSet .size () == 0 ) { return false ; }
625
- String skipPayments = resultSet .get (0 ).get (SKIP_PAYMENTS_FIELD ).toString ();
626
- if (skipPayments == null ) { return false ; }
627
- // assumed format
628
- if ("true" .equalsIgnoreCase (skipPayments .trim ())) { return true ; }
629
- // maybe not in assumed format, try to parseBool
630
- try {
631
- Boolean b = Boolean .parseBoolean (skipPayments );
632
- return b ;
633
- } catch (Throwable t ) {
634
- // don't care, return false;
592
+ "Fails to query project payments from database" , e ));
635
593
}
636
- return false ;
637
594
}
638
595
639
596
/**
@@ -676,11 +633,11 @@ private boolean isSkipPaymentsFlagPresentForProject(long projectId) {
676
633
* If any error occurred during the operation.
677
634
*/
678
635
public BigDecimal getDefaultPayment (long projectCategoryId , long resourceRoleId , BigDecimal prize ,
679
- int submissionsCount ) throws ProjectPaymentCalculatorException {
636
+ int submissionsCount ) throws ProjectPaymentCalculatorException {
680
637
String signature = DEFAULT_CONFIG_NAMESPACE + "#getDefaultPayment(long, long, BigDecimal, int)" ;
681
638
Helper .logEntrance (log , signature , new String [] {"projectCategoryId" , "resourceRoleId" ,
682
- PRIZE_COLUMN , "submissionsCount" },
683
- new Object [] {projectCategoryId , resourceRoleId , prize , submissionsCount });
639
+ PRIZE_COLUMN , "submissionsCount" },
640
+ new Object [] {projectCategoryId , resourceRoleId , prize , submissionsCount });
684
641
685
642
// arguments checking
686
643
try {
@@ -711,9 +668,9 @@ public BigDecimal getDefaultPayment(long projectCategoryId, long resourceRoleId,
711
668
712
669
BigDecimal scaledPrize = prize .setScale (2 , RoundingMode .HALF_UP );
713
670
BigDecimal multiplicandCoefficient =
714
- BigDecimal .valueOf (baseCoefficient + incrementalCoefficient * count );
671
+ BigDecimal .valueOf (baseCoefficient + incrementalCoefficient * count );
715
672
payment =
716
- fixedAmount .add (scaledPrize .multiply (multiplicandCoefficient )).setScale (2 , RoundingMode .HALF_UP );
673
+ fixedAmount .add (scaledPrize .multiply (multiplicandCoefficient )).setScale (2 , RoundingMode .HALF_UP );
717
674
}
718
675
Helper .logExit (log , signature , new Object [] {payment });
719
676
@@ -744,8 +701,8 @@ private static int getSubmissionsCount(Map<String, Object> resultSet, long resou
744
701
}
745
702
746
703
if (resourceRoleId == REVIEWER_RESOURCE_ROLE_ID || resourceRoleId == ACCURACY_REVIEWER_RESOURCE_ROLE_ID
747
- || resourceRoleId == FAILURE_REVIEWER_RESOURCE_ROLE_ID
748
- || resourceRoleId == STRESS_REVIEWER_RESOURCE_ROLE_ID ) {
704
+ || resourceRoleId == FAILURE_REVIEWER_RESOURCE_ROLE_ID
705
+ || resourceRoleId == STRESS_REVIEWER_RESOURCE_ROLE_ID ) {
749
706
submissionsCount = getInt (resultSet , "passed_contest_submissions" );
750
707
}
751
708
@@ -783,12 +740,12 @@ private static int getSubmissionsCount(Map<String, Object> resultSet, long resou
783
740
*/
784
741
private static boolean isSubmissionRequired (long resourceRoleId ) {
785
742
return (resourceRoleId == PRIMARY_SCREENER_RESOURCE_ROLE_ID || resourceRoleId == REVIEWER_RESOURCE_ROLE_ID
786
- || resourceRoleId == ACCURACY_REVIEWER_RESOURCE_ROLE_ID
787
- || resourceRoleId == FAILURE_REVIEWER_RESOURCE_ROLE_ID
788
- || resourceRoleId == STRESS_REVIEWER_RESOURCE_ROLE_ID
789
- || resourceRoleId == CHECKPOINT_SCREENER_RESOURCE_ROLE_ID
790
- || resourceRoleId == CHECKPOINT_REVIEWER_RESOURCE_ROLE_ID
791
- || resourceRoleId == ITERATIVE_REVIEWER_RESOURCE_ROLE_ID );
743
+ || resourceRoleId == ACCURACY_REVIEWER_RESOURCE_ROLE_ID
744
+ || resourceRoleId == FAILURE_REVIEWER_RESOURCE_ROLE_ID
745
+ || resourceRoleId == STRESS_REVIEWER_RESOURCE_ROLE_ID
746
+ || resourceRoleId == CHECKPOINT_SCREENER_RESOURCE_ROLE_ID
747
+ || resourceRoleId == CHECKPOINT_REVIEWER_RESOURCE_ROLE_ID
748
+ || resourceRoleId == ITERATIVE_REVIEWER_RESOURCE_ROLE_ID );
792
749
}
793
750
794
751
0 commit comments