1
1
/*
2
- * Copyright (C) 2004 - 2012 TopCoder Inc., All Rights Reserved.
2
+ * Copyright (C) 2004 - 2017 TopCoder Inc., All Rights Reserved.
3
3
*/
4
4
package com .topcoder .web .ejb .pacts ;
5
5
126
126
* method.</li>
127
127
* </ol>
128
128
* </p>
129
+ * <p>
130
+ * Version 1.8 (Topcoder - Add New Payment Provider) Change notes:
131
+ * <ol>
132
+ * <li>Added {@link #hasWiproSSOAccount(long)} method.</li>
133
+ * </ol>
134
+ * </p>
129
135
*
130
136
* <p>VERY IMPORTANT: remember to update serialVersionUID if needed.</p>
131
137
*
132
- * @author Dave Pecora, pulky, isv, Vitta, Blues, FireIce
133
- * @version 1.7
138
+ * @author Dave Pecora, pulky, isv, Vitta, Blues, FireIce, TCSCODER
139
+ * @version 1.8
134
140
* @see PactsConstants
135
141
*/
136
142
public class PactsServicesBean extends BaseEJB implements PactsConstants {
@@ -1539,7 +1545,7 @@ public void saveUserPaymentMethod(long userId, long paymentMethodId) {
1539
1545
if (userId == 0 ) {
1540
1546
throw new IllegalArgumentException ("Invalid user ID" );
1541
1547
}
1542
-
1548
+
1543
1549
if (paymentMethodId <= 0 ) {
1544
1550
throw new IllegalArgumentException ("Invalid payment method ID." );
1545
1551
}
@@ -1608,7 +1614,7 @@ public void saveUserPayPalAccount(long userId, String payPalAccount) {
1608
1614
if (payPalAccount == null ) {
1609
1615
throw new IllegalArgumentException ("Invalid email address of the PayPal account" );
1610
1616
}
1611
-
1617
+
1612
1618
PreparedStatement insertPs = null , updatePs = null ;
1613
1619
Connection conn = null ;
1614
1620
try {
@@ -3203,7 +3209,7 @@ public Map findPayments(Map searchCriteria) throws SQLException {
3203
3209
3204
3210
StringBuffer whereClauses = new StringBuffer (300 );
3205
3211
whereClauses .append (" WHERE 1=1 " );
3206
-
3212
+
3207
3213
ArrayList objects = new ArrayList ();
3208
3214
Iterator i = searchCriteria .keySet ().iterator ();
3209
3215
try {
@@ -3759,7 +3765,7 @@ public double computePaymentNetAmount(int paymentTypeId, double grossAmount, lon
3759
3765
3760
3766
log .debug ("In computePaymentNetAmount" );
3761
3767
Connection c = null ;
3762
-
3768
+
3763
3769
try {
3764
3770
c = DBMS .getConnection (trxDataSource );
3765
3771
@@ -3813,7 +3819,7 @@ public double computePaymentNetAmount(int paymentTypeId, double grossAmount, lon
3813
3819
} else {
3814
3820
return grossAmount ;
3815
3821
}
3816
-
3822
+
3817
3823
// Round to lower pennie
3818
3824
BigDecimal bd = new BigDecimal (netAmount ).setScale (2 , RoundingMode .HALF_DOWN );
3819
3825
double roundedNetAmount = bd .doubleValue ();
@@ -5334,7 +5340,7 @@ public int generateRoundPayments(long roundId, boolean makeChanges, int paymentT
5334
5340
}
5335
5341
5336
5342
/**
5337
-
5343
+
5338
5344
* Generates all the payments for the people who won money for the given project (winners and
5339
5345
* and review board members).
5340
5346
* It doesn't insert the payments in the DB, just generates and returns them.
@@ -5376,7 +5382,7 @@ public List generateComponentPayments(long projectId, long status, String client
5376
5382
getWinners .append (" ELSE ROUND(ri7.value) " );
5377
5383
getWinners .append (" END::float AS payment " );
5378
5384
5379
- getWinners .append (" FROM tcs_catalog:project p " );
5385
+ getWinners .append (" FROM tcs_catalog:project p " );
5380
5386
getWinners .append (" INNER JOIN tcs_catalog:project_category_lu pcl ON pcl.project_category_id = p.project_category_id " );
5381
5387
getWinners .append (" INNER JOIN tcs_catalog:resource r ON r.project_id = p.project_id AND r.resource_role_id = 1 " );
5382
5388
getWinners .append (" INNER JOIN tcs_catalog:resource_info ri1 ON r.resource_id = ri1.resource_id AND ri1.resource_info_type_id = 1 " );
@@ -5398,10 +5404,10 @@ public List generateComponentPayments(long projectId, long status, String client
5398
5404
long resourceId = rsc .getLongItem (i , "resource_id" );
5399
5405
long projectCategoryId = rsc .getLongItem (i , "project_category_id" );
5400
5406
String submissionType = rsc .getStringItem (i , "submission_type" );
5401
-
5407
+
5402
5408
double penalty = penalties .get (coderId ) == null ? 0.0 : penalties .get (coderId );
5403
5409
double amount = rsc .getDoubleItem (i , "payment" )*(1.0 -penalty );
5404
-
5410
+
5405
5411
log .info ("Generating payment. Coder: " + coderId + " placed: " + placed + " amount: " + amount + " penalty: " + penalty + " resourceId: " + resourceId );
5406
5412
if (amount < 0.01 ) {
5407
5413
log .info ("Ignoring the payment because of zero or negative amount." );
@@ -5413,7 +5419,7 @@ public List generateComponentPayments(long projectId, long status, String client
5413
5419
if (projectCategoryId == 37 ) { // If Marathon Match
5414
5420
if (rsc .getItem (i , "mm_round_id" ).getResultData () == null ) {
5415
5421
log .info ("MM round ID is not set. Ignoring the payment." );
5416
- continue ;
5422
+ continue ;
5417
5423
}
5418
5424
5419
5425
long mmRoundId = rsc .getLongItem (i , "mm_round_id" );
@@ -5433,7 +5439,7 @@ public List generateComponentPayments(long projectId, long status, String client
5433
5439
5434
5440
// Calculate the due date for the 2nd installment.
5435
5441
// It should be max(general due date assigned by the system, SECOND_INSTALLMENT_HOLD_PERIOD days from now).
5436
- Calendar cal = Calendar .getInstance ();
5442
+ Calendar cal = Calendar .getInstance ();
5437
5443
cal .add (Calendar .DATE , SECOND_INSTALLMENT_HOLD_PERIOD );
5438
5444
5439
5445
payment2 = fillPaymentData (payment2 );
@@ -5448,8 +5454,8 @@ public List generateComponentPayments(long projectId, long status, String client
5448
5454
} else if (submissionType .startsWith ("Checkpoint Submission" )) {
5449
5455
payments .add (new ContestCheckpointPayment (coderId , amount , client , projectId , placed ));
5450
5456
}
5451
-
5452
- resourceIds .add (new Long (resourceId ));
5457
+
5458
+ resourceIds .add (new Long (resourceId ));
5453
5459
} else {
5454
5460
log .info ("Payments for the coder " + coderId + " are skipped because he/she still has pending late deliverables." );
5455
5461
}
@@ -5494,7 +5500,7 @@ public List generateComponentPayments(long projectId, long status, String client
5494
5500
log .info ("Payments for the coder " + coderId + " are skipped because he/she still has pending late deliverables." );
5495
5501
continue ;
5496
5502
}
5497
-
5503
+
5498
5504
String paymentType = rsc .getStringItem (i , "payment_type" );
5499
5505
double penalty = penalties .get (coderId ) == null ? 0.0 : penalties .get (coderId );
5500
5506
double amount = rsc .getDoubleItem (i , "paid" );
@@ -5505,7 +5511,7 @@ public List generateComponentPayments(long projectId, long status, String client
5505
5511
5506
5512
ComponentProjectReferencePayment p = null ;
5507
5513
int projectType = getProjectType (projectId );
5508
-
5514
+
5509
5515
if (paymentType .startsWith ("Copilot Payment" )) {
5510
5516
// The penalties are not applied to the copilot payments
5511
5517
p = new CopilotPayment (coderId , amount , client , projectId );
@@ -5537,8 +5543,8 @@ public List generateComponentPayments(long projectId, long status, String client
5537
5543
return payments ;
5538
5544
}
5539
5545
5540
- /**
5541
- * Returns the maximum of two dates. A null date is considered to be less than any non-null date.
5546
+ /**
5547
+ * Returns the maximum of two dates. A null date is considered to be less than any non-null date.
5542
5548
*/
5543
5549
private static Date max (Date d1 , Date d2 ) {
5544
5550
if (d1 == null && d2 == null ) {
@@ -5559,7 +5565,7 @@ private static Date max(Date d1, Date d2) {
5559
5565
* is still in the 24 hours window since the moment of creation (which means the late member can still explain it).
5560
5566
*
5561
5567
* @param projectId The ID of the project
5562
- * @return List of user IDs who have pending late deliverables for this project.
5568
+ * @return List of user IDs who have pending late deliverables for this project.
5563
5569
* @throws SQLException If there was some error retrieving the data.
5564
5570
*/
5565
5571
private List <Long > getPendingUserIds (long projectId ) throws SQLException {
@@ -5569,9 +5575,9 @@ private List<Long> getPendingUserIds(long projectId) throws SQLException {
5569
5575
query .append (" ld.resource_id = r.resource_id and r.project_id = " + projectId + " and " );
5570
5576
query .append (" r.resource_id = ri.resource_id and ri.resource_info_type_id = 1 and " );
5571
5577
query .append (" ld.forgive_ind=0 and " );
5572
- query .append (" ((ld.explanation is not null and ld.response is null) " ); // if the explained record is waiting for the response
5578
+ query .append (" ((ld.explanation is not null and ld.response is null) " ); // if the explained record is waiting for the response
5573
5579
query .append (" or (ld.explanation is null and ld.create_date>current-24 units hour)) " ); // or if the late member still has time to explain (24 hours)
5574
-
5580
+
5575
5581
List <Long > userIds = new ArrayList <Long >();
5576
5582
ResultSetContainer rsc = runSelectQuery (query .toString ());
5577
5583
for (int i = 0 ; i < rsc .size (); i ++) {
@@ -5598,19 +5604,19 @@ private Map<Long,Double> getPaymentPenalties(long projectId) throws SQLException
5598
5604
query .append (" r.project_id=" + projectId + " and r.resource_id=ld.resource_id and r.resource_id=ri.resource_id and " );
5599
5605
query .append (" ri.resource_info_type_id=1 and ld.forgive_ind=0 " );
5600
5606
query .append (" group by 1 " );
5601
-
5607
+
5602
5608
Map <Long ,Double > penalties = new HashMap <Long ,Double >();
5603
5609
ResultSetContainer rsc = runSelectQuery (query .toString ());
5604
5610
for (int i = 0 ; i < rsc .size (); i ++) {
5605
5611
long userId = rsc .getLongItem (i , "user_id" );
5606
5612
long delay = rsc .getLongItem (i , "total_delay" );
5607
5613
long rejectedFinalFixes = rsc .getLongItem (i , "rejected_final_fixes" );
5608
-
5614
+
5609
5615
long paymentPenaltyPercentage = (delay >0 ? 5 : 0 ) + (delay /3600 ) + rejectedFinalFixes * 5 ;
5610
5616
if (paymentPenaltyPercentage > 50 ) {
5611
5617
paymentPenaltyPercentage = 50 ;
5612
5618
}
5613
-
5619
+
5614
5620
penalties .put (userId , (double )paymentPenaltyPercentage /100.0 );
5615
5621
}
5616
5622
return penalties ;
@@ -6513,7 +6519,7 @@ private int getProjectType(long projectId) throws SQLException {
6513
6519
}
6514
6520
6515
6521
private boolean isStudioProject (long projectId ) throws SQLException {
6516
- ResultSetContainer rsc = runSelectQuery ("SELECT pcl.project_type_id FROM tcs_catalog:project_category_lu pcl, " +
6522
+ ResultSetContainer rsc = runSelectQuery ("SELECT pcl.project_type_id FROM tcs_catalog:project_category_lu pcl, " +
6517
6523
" tcs_catalog:project p WHERE p.project_category_id=pcl.project_category_id and p.project_id=" + projectId );
6518
6524
6519
6525
if (rsc .size () == 0 ) {
@@ -6748,12 +6754,12 @@ public List findCoderPayments(long coderId, int paymentTypeId, long referenceId)
6748
6754
searchCriteria .put (PAYMENT_REFERENCE_ID , String .valueOf (referenceId ));
6749
6755
return findCoderPayments (searchCriteria );
6750
6756
}
6751
-
6757
+
6752
6758
/**
6753
6759
* Find a Jira payment by its issue key.
6754
6760
* @param jiraIssueKey the issue key.
6755
6761
* @return the Jira payments for the given issue, or empty if not found
6756
- * @throws RemoteException if there is an error
6762
+ * @throws RemoteException if there is an error
6757
6763
* @throws Exception if there is an error
6758
6764
* @throws InvalidStatusException if there is an error
6759
6765
*/
@@ -7075,6 +7081,32 @@ public ResultSetContainer getContestsInfo(long eid) throws SQLException {
7075
7081
7076
7082
}
7077
7083
7084
+ /**
7085
+ * Returns true if the specified user is a Wipro SSO user.
7086
+ *
7087
+ * @param userId The user ID to check.
7088
+ * @return Whether the user is a Wipro SSO user.
7089
+ * @throws SQLException If there is some problem querying the database
7090
+ */
7091
+ public boolean hasWiproSSOAccount (long userId ) throws SQLException {
7092
+ StringBuffer query = new StringBuffer (300 );
7093
+ query .append ("SELECT COUNT(*) FROM user u " );
7094
+ query .append (" JOIN user_sso_login su ON su.user_id = u.user_id " );
7095
+ query .append (" JOIN sso_login_provider sp ON sp.sso_login_provider_id = su.provider_id AND sp.name = 'wipro-adfs' " );
7096
+ query .append ("WHERE u.user_id = " + userId );
7097
+
7098
+ Connection c = null ;
7099
+ boolean ret = false ;
7100
+ try {
7101
+ c = DBMS .getConnection (DBMS .COMMON_OLTP_DATASOURCE_NAME );
7102
+ ResultSetContainer rsc = runSelectQuery (c , query .toString ());
7103
+ ret = Integer .parseInt (rsc .getItem (0 , 0 ).toString ()) > 0 ;
7104
+ } finally {
7105
+ close (c );
7106
+ }
7107
+ return ret ;
7108
+ }
7109
+
7078
7110
class AlgorithmContestPaymentDataRetriever extends AlgorithmContestPayment {
7079
7111
private final String roundName ;
7080
7112
private final Date dueDate ;
0 commit comments