Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

add payment method for wipro #10

Merged
merged 1 commit into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions resources/taglib/tc-webtags.tld
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>disabled</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>

<tag>
Expand Down
19 changes: 18 additions & 1 deletion src/main/com/topcoder/web/common/model/PaymentMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@
/**
* A class to hold Payment Method data.
*
* @author VolodymyrK
* <p>
* Version 1.1 (Topcoder - Add New Payment Provider) Change notes:
* <ol>
* <li>Added eligible attribute to determinate whether the payment method is allowed or not.</li>
* </ol>
* </p>
*
* @author VolodymyrK, TCSCODER
* @version 1.1
*/
public class PaymentMethod extends Base {

private Long id;
private String name;
private boolean eligible = true;

public PaymentMethod() {
}
Expand All @@ -30,4 +39,12 @@ public void setName(String name) {
this.name = name;
}

public boolean isEligible() {
return eligible;
}

public void setEligible(boolean eligible) {
this.eligible = eligible;
}

}
14 changes: 14 additions & 0 deletions src/main/com/topcoder/web/common/tag/RadioButtonTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
* User: dok
* Date: Jan 3, 2005
* Time: 5:53:26 PM
*
* Version 1.1 (Topcoder - Add New Payment Provider) 08/08/2017
* - Add "disabled" attribute
*
* @author dok, TCSCODER
* @version 1.1
*/
public class RadioButtonTag extends BaseTag {
private String value = null;
private String selected = null;
private String onClick = null;
private String disabled = null;

public int doStartTag() {
StringBuffer ret = new StringBuffer();
Expand All @@ -25,6 +32,9 @@ public int doStartTag() {
}
if (onClick != null)
ret.append("onClick=\"").append(onClick).append("\" ");
if (disabled != null) {
ret.append("disabled ");
}
ret.append("/>");
pageContext.getOut().print(ret.toString());
} catch (java.io.IOException ioe) {
Expand All @@ -48,6 +58,10 @@ public void setOnClick(String onClick) {
this.onClick = onClick;
}

public void setDisabled(String disabled) {
this.disabled = disabled;
}

protected void init() {
this.value = null;
this.selected = null;
Expand Down
18 changes: 13 additions & 5 deletions src/main/com/topcoder/web/ejb/pacts/Constants.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2004 - 2012 TopCoder Inc., All Rights Reserved.
* Copyright (C) 2004 - 2017 TopCoder Inc., All Rights Reserved.
*/
package com.topcoder.web.ejb.pacts;

Expand Down Expand Up @@ -75,7 +75,7 @@
* <ol>
* <li>Added common payment types for all tracks. No more separate payments for architecture, assembly, components etc.</li>
* </ol>
* </p>
* </p>
*
* <p>
* Version 1.10 (Member Payments Automation Assembly 1.0) Change notes:
Expand All @@ -84,8 +84,15 @@
* </ol>
* </p>
*
* @author pulky, VolodymyrK, isv
* @version 1.10
* <p>
* Version 1.11 (Topcoder - Add New Payment Provider) Change notes:
* <ol>
* <li>Added {@link WIPRO_PAYROLL_PAYMENT_METHOD_ID} constant.</li>
* </ol>
* </p>
*
* @author pulky, VolodymyrK, isv, TCSCODER
* @version 1.11
*/
public interface Constants {

Expand Down Expand Up @@ -271,10 +278,11 @@ public interface Constants {
public static final long NOT_SET_PAYMENT_METHOD_ID = 1;
public static final long PAYPAL_PAYMENT_METHOD_ID = 2;
public static final long PAYONEER_PAYMENT_METHOD_ID = 5;
public static final long WIPRO_PAYROLL_PAYMENT_METHOD_ID = 7;

/**
* <p>A <code>long</code> providing the ID of <code>Western Union</code> payment method.</p>
*
*
* @since 1.10
*/
public static final long WESTERN_UNION_PAYMENT_METHOD_ID = 6;
Expand Down
90 changes: 61 additions & 29 deletions src/main/com/topcoder/web/ejb/pacts/PactsServicesBean.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2004 - 2012 TopCoder Inc., All Rights Reserved.
* Copyright (C) 2004 - 2017 TopCoder Inc., All Rights Reserved.
*/
package com.topcoder.web.ejb.pacts;

Expand Down Expand Up @@ -126,11 +126,17 @@
* method.</li>
* </ol>
* </p>
* <p>
* Version 1.8 (Topcoder - Add New Payment Provider) Change notes:
* <ol>
* <li>Added {@link #hasWiproSSOAccount(long)} method.</li>
* </ol>
* </p>
*
* <p>VERY IMPORTANT: remember to update serialVersionUID if needed.</p>
*
* @author Dave Pecora, pulky, isv, Vitta, Blues, FireIce
* @version 1.7
* @author Dave Pecora, pulky, isv, Vitta, Blues, FireIce, TCSCODER
* @version 1.8
* @see PactsConstants
*/
public class PactsServicesBean extends BaseEJB implements PactsConstants {
Expand Down Expand Up @@ -1539,7 +1545,7 @@ public void saveUserPaymentMethod(long userId, long paymentMethodId) {
if (userId == 0) {
throw new IllegalArgumentException("Invalid user ID");
}

if (paymentMethodId <= 0) {
throw new IllegalArgumentException("Invalid payment method ID.");
}
Expand Down Expand Up @@ -1608,7 +1614,7 @@ public void saveUserPayPalAccount(long userId, String payPalAccount) {
if (payPalAccount == null) {
throw new IllegalArgumentException("Invalid email address of the PayPal account");
}

PreparedStatement insertPs = null, updatePs = null;
Connection conn = null;
try {
Expand Down Expand Up @@ -3203,7 +3209,7 @@ public Map findPayments(Map searchCriteria) throws SQLException {

StringBuffer whereClauses = new StringBuffer(300);
whereClauses.append(" WHERE 1=1 ");

ArrayList objects = new ArrayList();
Iterator i = searchCriteria.keySet().iterator();
try {
Expand Down Expand Up @@ -3759,7 +3765,7 @@ public double computePaymentNetAmount(int paymentTypeId, double grossAmount, lon

log.debug("In computePaymentNetAmount");
Connection c = null;

try {
c = DBMS.getConnection(trxDataSource);

Expand Down Expand Up @@ -3813,7 +3819,7 @@ public double computePaymentNetAmount(int paymentTypeId, double grossAmount, lon
} else {
return grossAmount;
}

// Round to lower pennie
BigDecimal bd = new BigDecimal(netAmount).setScale(2, RoundingMode.HALF_DOWN);
double roundedNetAmount = bd.doubleValue();
Expand Down Expand Up @@ -5334,7 +5340,7 @@ public int generateRoundPayments(long roundId, boolean makeChanges, int paymentT
}

/**

* Generates all the payments for the people who won money for the given project (winners and
* and review board members).
* It doesn't insert the payments in the DB, just generates and returns them.
Expand Down Expand Up @@ -5376,7 +5382,7 @@ public List generateComponentPayments(long projectId, long status, String client
getWinners.append(" ELSE ROUND(ri7.value) ");
getWinners.append(" END::float AS payment ");

getWinners.append(" FROM tcs_catalog:project p ");
getWinners.append(" FROM tcs_catalog:project p ");
getWinners.append(" INNER JOIN tcs_catalog:project_category_lu pcl ON pcl.project_category_id = p.project_category_id ");
getWinners.append(" INNER JOIN tcs_catalog:resource r ON r.project_id = p.project_id AND r.resource_role_id = 1 ");
getWinners.append(" INNER JOIN tcs_catalog:resource_info ri1 ON r.resource_id = ri1.resource_id AND ri1.resource_info_type_id = 1 ");
Expand All @@ -5398,10 +5404,10 @@ public List generateComponentPayments(long projectId, long status, String client
long resourceId = rsc.getLongItem(i, "resource_id");
long projectCategoryId = rsc.getLongItem(i, "project_category_id");
String submissionType = rsc.getStringItem(i, "submission_type");

double penalty = penalties.get(coderId) == null ? 0.0 : penalties.get(coderId);
double amount = rsc.getDoubleItem(i, "payment")*(1.0-penalty);

log.info("Generating payment. Coder: " + coderId + " placed: " + placed + " amount: " + amount + " penalty: " + penalty + " resourceId: " + resourceId);
if (amount < 0.01) {
log.info("Ignoring the payment because of zero or negative amount.");
Expand All @@ -5413,7 +5419,7 @@ public List generateComponentPayments(long projectId, long status, String client
if (projectCategoryId == 37) { // If Marathon Match
if (rsc.getItem(i, "mm_round_id").getResultData() == null) {
log.info("MM round ID is not set. Ignoring the payment.");
continue;
continue;
}

long mmRoundId = rsc.getLongItem(i, "mm_round_id");
Expand All @@ -5433,7 +5439,7 @@ public List generateComponentPayments(long projectId, long status, String client

// Calculate the due date for the 2nd installment.
// It should be max(general due date assigned by the system, SECOND_INSTALLMENT_HOLD_PERIOD days from now).
Calendar cal = Calendar.getInstance();
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, SECOND_INSTALLMENT_HOLD_PERIOD);

payment2 = fillPaymentData(payment2);
Expand All @@ -5448,8 +5454,8 @@ public List generateComponentPayments(long projectId, long status, String client
} else if (submissionType.startsWith("Checkpoint Submission")) {
payments.add(new ContestCheckpointPayment(coderId, amount, client, projectId, placed));
}
resourceIds.add(new Long(resourceId));

resourceIds.add(new Long(resourceId));
} else {
log.info("Payments for the coder " + coderId + " are skipped because he/she still has pending late deliverables.");
}
Expand Down Expand Up @@ -5494,7 +5500,7 @@ public List generateComponentPayments(long projectId, long status, String client
log.info("Payments for the coder " + coderId + " are skipped because he/she still has pending late deliverables.");
continue;
}

String paymentType = rsc.getStringItem(i, "payment_type");
double penalty = penalties.get(coderId) == null ? 0.0 : penalties.get(coderId);
double amount = rsc.getDoubleItem(i, "paid");
Expand All @@ -5505,7 +5511,7 @@ public List generateComponentPayments(long projectId, long status, String client

ComponentProjectReferencePayment p = null;
int projectType = getProjectType(projectId);

if (paymentType.startsWith("Copilot Payment")) {
// The penalties are not applied to the copilot payments
p = new CopilotPayment(coderId, amount, client, projectId);
Expand Down Expand Up @@ -5537,8 +5543,8 @@ public List generateComponentPayments(long projectId, long status, String client
return payments;
}

/**
* Returns the maximum of two dates. A null date is considered to be less than any non-null date.
/**
* Returns the maximum of two dates. A null date is considered to be less than any non-null date.
*/
private static Date max(Date d1, Date d2) {
if (d1 == null && d2 == null) {
Expand All @@ -5559,7 +5565,7 @@ private static Date max(Date d1, Date d2) {
* is still in the 24 hours window since the moment of creation (which means the late member can still explain it).
*
* @param projectId The ID of the project
* @return List of user IDs who have pending late deliverables for this project.
* @return List of user IDs who have pending late deliverables for this project.
* @throws SQLException If there was some error retrieving the data.
*/
private List<Long> getPendingUserIds(long projectId) throws SQLException {
Expand All @@ -5569,9 +5575,9 @@ private List<Long> getPendingUserIds(long projectId) throws SQLException {
query.append(" ld.resource_id = r.resource_id and r.project_id = " + projectId + " and ");
query.append(" r.resource_id = ri.resource_id and ri.resource_info_type_id = 1 and ");
query.append(" ld.forgive_ind=0 and ");
query.append(" ((ld.explanation is not null and ld.response is null) "); // if the explained record is waiting for the response
query.append(" ((ld.explanation is not null and ld.response is null) "); // if the explained record is waiting for the response
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)

List<Long> userIds = new ArrayList<Long>();
ResultSetContainer rsc = runSelectQuery(query.toString());
for (int i = 0; i < rsc.size(); i++) {
Expand All @@ -5598,19 +5604,19 @@ private Map<Long,Double> getPaymentPenalties(long projectId) throws SQLException
query.append(" r.project_id=" + projectId + " and r.resource_id=ld.resource_id and r.resource_id=ri.resource_id and ");
query.append(" ri.resource_info_type_id=1 and ld.forgive_ind=0 ");
query.append(" group by 1 ");

Map<Long,Double> penalties = new HashMap<Long,Double>();
ResultSetContainer rsc = runSelectQuery(query.toString());
for (int i = 0; i < rsc.size(); i++) {
long userId = rsc.getLongItem(i, "user_id");
long delay = rsc.getLongItem(i, "total_delay");
long rejectedFinalFixes = rsc.getLongItem(i, "rejected_final_fixes");

long paymentPenaltyPercentage = (delay>0 ? 5 : 0) + (delay/3600) + rejectedFinalFixes * 5;
if (paymentPenaltyPercentage > 50) {
paymentPenaltyPercentage = 50;
}

penalties.put(userId, (double)paymentPenaltyPercentage/100.0);
}
return penalties;
Expand Down Expand Up @@ -6513,7 +6519,7 @@ private int getProjectType(long projectId) throws SQLException {
}

private boolean isStudioProject(long projectId) throws SQLException {
ResultSetContainer rsc = runSelectQuery("SELECT pcl.project_type_id FROM tcs_catalog:project_category_lu pcl, " +
ResultSetContainer rsc = runSelectQuery("SELECT pcl.project_type_id FROM tcs_catalog:project_category_lu pcl, " +
" tcs_catalog:project p WHERE p.project_category_id=pcl.project_category_id and p.project_id=" + projectId);

if (rsc.size() == 0) {
Expand Down Expand Up @@ -6748,12 +6754,12 @@ public List findCoderPayments(long coderId, int paymentTypeId, long referenceId)
searchCriteria.put(PAYMENT_REFERENCE_ID, String.valueOf(referenceId));
return findCoderPayments(searchCriteria);
}

/**
* Find a Jira payment by its issue key.
* @param jiraIssueKey the issue key.
* @return the Jira payments for the given issue, or empty if not found
* @throws RemoteException if there is an error
* @throws RemoteException if there is an error
* @throws Exception if there is an error
* @throws InvalidStatusException if there is an error
*/
Expand Down Expand Up @@ -7075,6 +7081,32 @@ public ResultSetContainer getContestsInfo(long eid) throws SQLException {

}

/**
* Returns true if the specified user is a Wipro SSO user.
*
* @param userId The user ID to check.
* @return Whether the user is a Wipro SSO user.
* @throws SQLException If there is some problem querying the database
*/
public boolean hasWiproSSOAccount(long userId) throws SQLException {
StringBuffer query = new StringBuffer(300);
query.append("SELECT COUNT(*) FROM user u ");
query.append(" JOIN user_sso_login su ON su.user_id = u.user_id ");
query.append(" JOIN sso_login_provider sp ON sp.sso_login_provider_id = su.provider_id AND sp.name = 'wipro-adfs' ");
query.append("WHERE u.user_id = " + userId);

Connection c = null;
boolean ret = false;
try {
c = DBMS.getConnection(DBMS.COMMON_OLTP_DATASOURCE_NAME);
ResultSetContainer rsc = runSelectQuery(c, query.toString());
ret = Integer.parseInt(rsc.getItem(0, 0).toString()) > 0;
} finally {
close(c);
}
return ret;
}

class AlgorithmContestPaymentDataRetriever extends AlgorithmContestPayment {
private final String roundName;
private final Date dueDate;
Expand Down
Loading