11/*
2- * Copyright (C) 2004 - 2012 TopCoder Inc., All Rights Reserved.
2+ * Copyright (C) 2004 - 2017 TopCoder Inc., All Rights Reserved.
33 */
44package com .topcoder .web .ejb .pacts ;
55
126126 * method.</li>
127127 * </ol>
128128 * </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>
129135 *
130136 * <p>VERY IMPORTANT: remember to update serialVersionUID if needed.</p>
131137 *
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
134140 * @see PactsConstants
135141 */
136142public class PactsServicesBean extends BaseEJB implements PactsConstants {
@@ -1539,7 +1545,7 @@ public void saveUserPaymentMethod(long userId, long paymentMethodId) {
15391545 if (userId == 0 ) {
15401546 throw new IllegalArgumentException ("Invalid user ID" );
15411547 }
1542-
1548+
15431549 if (paymentMethodId <= 0 ) {
15441550 throw new IllegalArgumentException ("Invalid payment method ID." );
15451551 }
@@ -1608,7 +1614,7 @@ public void saveUserPayPalAccount(long userId, String payPalAccount) {
16081614 if (payPalAccount == null ) {
16091615 throw new IllegalArgumentException ("Invalid email address of the PayPal account" );
16101616 }
1611-
1617+
16121618 PreparedStatement insertPs = null , updatePs = null ;
16131619 Connection conn = null ;
16141620 try {
@@ -3203,7 +3209,7 @@ public Map findPayments(Map searchCriteria) throws SQLException {
32033209
32043210 StringBuffer whereClauses = new StringBuffer (300 );
32053211 whereClauses .append (" WHERE 1=1 " );
3206-
3212+
32073213 ArrayList objects = new ArrayList ();
32083214 Iterator i = searchCriteria .keySet ().iterator ();
32093215 try {
@@ -3759,7 +3765,7 @@ public double computePaymentNetAmount(int paymentTypeId, double grossAmount, lon
37593765
37603766 log .debug ("In computePaymentNetAmount" );
37613767 Connection c = null ;
3762-
3768+
37633769 try {
37643770 c = DBMS .getConnection (trxDataSource );
37653771
@@ -3813,7 +3819,7 @@ public double computePaymentNetAmount(int paymentTypeId, double grossAmount, lon
38133819 } else {
38143820 return grossAmount ;
38153821 }
3816-
3822+
38173823 // Round to lower pennie
38183824 BigDecimal bd = new BigDecimal (netAmount ).setScale (2 , RoundingMode .HALF_DOWN );
38193825 double roundedNetAmount = bd .doubleValue ();
@@ -5334,7 +5340,7 @@ public int generateRoundPayments(long roundId, boolean makeChanges, int paymentT
53345340 }
53355341
53365342 /**
5337-
5343+
53385344 * Generates all the payments for the people who won money for the given project (winners and
53395345 * and review board members).
53405346 * 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
53765382 getWinners .append (" ELSE ROUND(ri7.value) " );
53775383 getWinners .append (" END::float AS payment " );
53785384
5379- getWinners .append (" FROM tcs_catalog:project p " );
5385+ getWinners .append (" FROM tcs_catalog:project p " );
53805386 getWinners .append (" INNER JOIN tcs_catalog:project_category_lu pcl ON pcl.project_category_id = p.project_category_id " );
53815387 getWinners .append (" INNER JOIN tcs_catalog:resource r ON r.project_id = p.project_id AND r.resource_role_id = 1 " );
53825388 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
53985404 long resourceId = rsc .getLongItem (i , "resource_id" );
53995405 long projectCategoryId = rsc .getLongItem (i , "project_category_id" );
54005406 String submissionType = rsc .getStringItem (i , "submission_type" );
5401-
5407+
54025408 double penalty = penalties .get (coderId ) == null ? 0.0 : penalties .get (coderId );
54035409 double amount = rsc .getDoubleItem (i , "payment" )*(1.0 -penalty );
5404-
5410+
54055411 log .info ("Generating payment. Coder: " + coderId + " placed: " + placed + " amount: " + amount + " penalty: " + penalty + " resourceId: " + resourceId );
54065412 if (amount < 0.01 ) {
54075413 log .info ("Ignoring the payment because of zero or negative amount." );
@@ -5413,7 +5419,7 @@ public List generateComponentPayments(long projectId, long status, String client
54135419 if (projectCategoryId == 37 ) { // If Marathon Match
54145420 if (rsc .getItem (i , "mm_round_id" ).getResultData () == null ) {
54155421 log .info ("MM round ID is not set. Ignoring the payment." );
5416- continue ;
5422+ continue ;
54175423 }
54185424
54195425 long mmRoundId = rsc .getLongItem (i , "mm_round_id" );
@@ -5433,7 +5439,7 @@ public List generateComponentPayments(long projectId, long status, String client
54335439
54345440 // Calculate the due date for the 2nd installment.
54355441 // 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 ();
54375443 cal .add (Calendar .DATE , SECOND_INSTALLMENT_HOLD_PERIOD );
54385444
54395445 payment2 = fillPaymentData (payment2 );
@@ -5448,8 +5454,8 @@ public List generateComponentPayments(long projectId, long status, String client
54485454 } else if (submissionType .startsWith ("Checkpoint Submission" )) {
54495455 payments .add (new ContestCheckpointPayment (coderId , amount , client , projectId , placed ));
54505456 }
5451-
5452- resourceIds .add (new Long (resourceId ));
5457+
5458+ resourceIds .add (new Long (resourceId ));
54535459 } else {
54545460 log .info ("Payments for the coder " + coderId + " are skipped because he/she still has pending late deliverables." );
54555461 }
@@ -5494,7 +5500,7 @@ public List generateComponentPayments(long projectId, long status, String client
54945500 log .info ("Payments for the coder " + coderId + " are skipped because he/she still has pending late deliverables." );
54955501 continue ;
54965502 }
5497-
5503+
54985504 String paymentType = rsc .getStringItem (i , "payment_type" );
54995505 double penalty = penalties .get (coderId ) == null ? 0.0 : penalties .get (coderId );
55005506 double amount = rsc .getDoubleItem (i , "paid" );
@@ -5505,7 +5511,7 @@ public List generateComponentPayments(long projectId, long status, String client
55055511
55065512 ComponentProjectReferencePayment p = null ;
55075513 int projectType = getProjectType (projectId );
5508-
5514+
55095515 if (paymentType .startsWith ("Copilot Payment" )) {
55105516 // The penalties are not applied to the copilot payments
55115517 p = new CopilotPayment (coderId , amount , client , projectId );
@@ -5537,8 +5543,8 @@ public List generateComponentPayments(long projectId, long status, String client
55375543 return payments ;
55385544 }
55395545
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.
55425548 */
55435549 private static Date max (Date d1 , Date d2 ) {
55445550 if (d1 == null && d2 == null ) {
@@ -5559,7 +5565,7 @@ private static Date max(Date d1, Date d2) {
55595565 * is still in the 24 hours window since the moment of creation (which means the late member can still explain it).
55605566 *
55615567 * @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.
55635569 * @throws SQLException If there was some error retrieving the data.
55645570 */
55655571 private List <Long > getPendingUserIds (long projectId ) throws SQLException {
@@ -5569,9 +5575,9 @@ private List<Long> getPendingUserIds(long projectId) throws SQLException {
55695575 query .append (" ld.resource_id = r.resource_id and r.project_id = " + projectId + " and " );
55705576 query .append (" r.resource_id = ri.resource_id and ri.resource_info_type_id = 1 and " );
55715577 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
55735579 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+
55755581 List <Long > userIds = new ArrayList <Long >();
55765582 ResultSetContainer rsc = runSelectQuery (query .toString ());
55775583 for (int i = 0 ; i < rsc .size (); i ++) {
@@ -5598,19 +5604,19 @@ private Map<Long,Double> getPaymentPenalties(long projectId) throws SQLException
55985604 query .append (" r.project_id=" + projectId + " and r.resource_id=ld.resource_id and r.resource_id=ri.resource_id and " );
55995605 query .append (" ri.resource_info_type_id=1 and ld.forgive_ind=0 " );
56005606 query .append (" group by 1 " );
5601-
5607+
56025608 Map <Long ,Double > penalties = new HashMap <Long ,Double >();
56035609 ResultSetContainer rsc = runSelectQuery (query .toString ());
56045610 for (int i = 0 ; i < rsc .size (); i ++) {
56055611 long userId = rsc .getLongItem (i , "user_id" );
56065612 long delay = rsc .getLongItem (i , "total_delay" );
56075613 long rejectedFinalFixes = rsc .getLongItem (i , "rejected_final_fixes" );
5608-
5614+
56095615 long paymentPenaltyPercentage = (delay >0 ? 5 : 0 ) + (delay /3600 ) + rejectedFinalFixes * 5 ;
56105616 if (paymentPenaltyPercentage > 50 ) {
56115617 paymentPenaltyPercentage = 50 ;
56125618 }
5613-
5619+
56145620 penalties .put (userId , (double )paymentPenaltyPercentage /100.0 );
56155621 }
56165622 return penalties ;
@@ -6513,7 +6519,7 @@ private int getProjectType(long projectId) throws SQLException {
65136519 }
65146520
65156521 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, " +
65176523 " tcs_catalog:project p WHERE p.project_category_id=pcl.project_category_id and p.project_id=" + projectId );
65186524
65196525 if (rsc .size () == 0 ) {
@@ -6748,12 +6754,12 @@ public List findCoderPayments(long coderId, int paymentTypeId, long referenceId)
67486754 searchCriteria .put (PAYMENT_REFERENCE_ID , String .valueOf (referenceId ));
67496755 return findCoderPayments (searchCriteria );
67506756 }
6751-
6757+
67526758 /**
67536759 * Find a Jira payment by its issue key.
67546760 * @param jiraIssueKey the issue key.
67556761 * @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
67576763 * @throws Exception if there is an error
67586764 * @throws InvalidStatusException if there is an error
67596765 */
@@ -7075,6 +7081,32 @@ public ResultSetContainer getContestsInfo(long eid) throws SQLException {
70757081
70767082 }
70777083
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+
70787110 class AlgorithmContestPaymentDataRetriever extends AlgorithmContestPayment {
70797111 private final String roundName ;
70807112 private final Date dueDate ;
0 commit comments