• Post Reply Bookmark Topic Watch Topic
  • New Topic

Check Account duplication/reordering  RSS feed

 
misty angel
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to override the base class as follows and implement the same after increasing the number of accounts to 10.
Please help me write the code for the same

Thanks

package Account;

import javax.servlet.http.*;
import java.util.*;



public class accounCheck {


public accounCheck() {
this.setDirectory("/acctdata/");
}



/***************Purpose: To re-order the priorties when accounts are deleted. Exisitin code is for 3 accounts its to be
made for 10 accounts. *******************/



protected void reorderAccount(UserRequestParameters reqParams, HttpServletRequest request) {

int numberOfAccounts = 0;
try {
numberOfAccounts = Integer.parseInt(request.getParameter("NO_ACCTS"));
} catch (NumberFormatException e) {

}

// if all of the accounts are being deleted then don't bother shifting anyting
boolean deleteAll = ((StringUtil.ns(reqParams.get("AccountValues_0")).equals("Delete") || StringUtil.ns(reqParams.get("AccountValues_0")).equals("-Select-"))
&& (StringUtil.ns(reqParams.get("AccountValues_1")).equals("Delete") || StringUtil.ns(reqParams.get("AccountValues_1")).equals("-Select-"))
&& (StringUtil.ns(reqParams.get("AccountValues_2")).equals("Delete") || StringUtil.ns(reqParams.get("AccountValues_2")).equals("-Select-")));

if (!deleteAll) {

// processing for three accounts
if (numberOfAccounts == 3) {
int doubleShift = 0;
for (int i = 2; i > -1; i--) {
if (reqParams.get("AccountValues_" + i) != null && reqParams.get("AccountValues_" + i).trim().equals("Delete")) {
// Single Down Shift (3 to 2 or 2 to 1)
reqParams.put("PriorityValues_" + (i + 1), String.valueOf(i+1));
doubleShift ++;
}
}

if (doubleShift == 2) {
// Down Shift (3 to 1);
reqParams.put("PriorityValues_2" , String.valueOf(1));
} else if (reqParams.get("AccountValues_0" ) != null && reqParams.get("AccountValues_0").trim().equals("Delete")) {
// Down Shift 3 to 2 if 1 is deleted
if (reqParams.get("AccountValues_2" ) != null) {
reqParams.put("PriorityValues_2", String.valueOf(2));
}
}
} else if (numberOfAccounts == 2) {
if (reqParams.get("AccountValues_0") != null && reqParams.get("AccountValues_0").trim().equals("Delete")) {
// Single Down Shift (2 to 1)
reqParams.put("PriorityValues_1", String.valueOf(1));
}
}
}
}


/****************** Purpose: To make sure that the account numbers are not Duplicated ******************/


protected void checkForDuplicateAccounts(UserRequestParameters reqParams, Vector errors) {
String acct0 = StringUtil.ns(reqParams.get("accountNbr_0").trim());
String acct1 = StringUtil.ns(reqParams.get("accountNbr_1").trim());
String acct2 = StringUtil.ns(reqParams.get("accountNbr_2").trim());

String acct0Type = StringUtil.ns(reqParams.get("AccountValues_0").trim());
String acct1Type = StringUtil.ns(reqParams.get("AccountValues_1").trim());
String acct2Type = StringUtil.ns(reqParams.get("AccountValues_2").trim());

String acct0Rout = StringUtil.ns(reqParams.get("transferNbr_0").trim());
String acct1Rout = StringUtil.ns(reqParams.get("transferNbr_1").trim());
String acct2Rout = StringUtil.ns(reqParams.get("transferNbr_2").trim());

boolean validRow0 = (!acct0.equals("") && !acct0Type.equals("-Select-") && !acct0Type.equals("Delete") && !acct0Type.equals("") && !acct0Rout.equals(""));
boolean validRow1 = (!acct1.equals("") && !acct1Type.equals("-Select-") && !acct1Type.equals("Delete") && !acct1Type.equals("") && !acct1Rout.equals(""));
boolean validRow2 = (!acct2.equals("") && !acct2Type.equals("-Select-") && !acct2Type.equals("Delete") && !acct2Type.equals("") && !acct2Rout.equals(""));

// compare 0 and 1
if (validRow0 && validRow1) {
if (acct0Rout.equals(acct1Rout)) {
if (acct0Type.equals(acct1Type)) {
if (acct0.equals(acct1)) {
errors.add(new ErrorListItem(msgDuplicateAccount));
return;
}
}
}
}
// compare 0 and 2
if (validRow0 && validRow2) {
if (acct0Rout.equals(acct2Rout)) {
if (acct0Type.equals(acct2Type)) {
if (acct0.equals(acct2)) {
errors.add(new ErrorListItem(msgDuplicateAccount));
return;
}
}
}
}
// compare 1 and 2
if (validRow1 && validRow2) {
if (acct1Rout.equals(acct2Rout)) {
if (acct1Type.equals(acct2Type)) {
if (acct1.equals(acct2)) {
errors.add(new ErrorListItem(msgDuplicateAccount));
return;
}
}
}
}
}

/********************** Purpose: To figure out the number of accounts and Note error message display ***********/


protected boolean isNoteErrorRequired(UserRequestParameters reqParams, Customer customer) {
boolean error = false;
Vector accounts = new Vector();
try {
accounts = customer.getItemsRented();
} catch (Exception e) {
ErrorLog.log(e, customer, "customer.getItemsRented() thru an exception");
}

int numberOfAccounts = accounts.size();


if (numberOfAccounts > 0 && StringUtil.ns(reqParams.get("balanceAmmount")).equals("4")) {
numberOfAccounts--;
}


// check the number of accounts
if (!StringUtil.ns(reqParams.get("AccountValues_" + (numberOfAccounts))).equals("Delete") &&
!StringUtil.ns(reqParams.get("AccountValues_" + (numberOfAccounts))).equals("-Select-") &&
!StringUtil.ns(reqParams.get("AccountValues_" + (numberOfAccounts))).trim().equals("")) {
// an extra row has been added
return true;
}

if (numberOfAccounts == 0) {
for (int i = 0; i < 3; i++) {
if (StringUtil.ns(reqParams.get("AccountValues_" + i)).equals("R") || StringUtil.ns(reqParams.get("AccountValues_" + i)).equals("P")) {
return true;
}
}
}

for (int i = 0; i < accounts.size(); i++) {


// Check for differences
if (!StringUtil.ns(((ItemsRented)accounts.elementAt(i)).getAccountNbr()).equals(StringUtil.ns(reqParams.get("accountNbr_" + i)))) {
return true;
}
if (StringUtil.ns(reqParams.get("AccountValues_" + i)).equals("R") || StringUtil.ns(reqParams.get("AccountValues_" + i)).equals("P")) {
if (!StringUtil.ns(((ItemsRented)accounts.elementAt(i)).getType()).equals(StringUtil.ns(reqParams.get("AccountValues_" + i)))) {
return true;
}
}
if (!StringUtil.ns(((ItemsRented)accounts.elementAt(i)).getRegistrationNumber()).equals(StringUtil.ns(reqParams.get("transferNbr_" + i)))) {
return true;
}
}
return error;
}


/************ To make sure that the priority numbers are all in order.
* This returns a boolean which tells the calling clients that
* the row that has excess checked also has the lowest priority so the calling method
* will know to display the origional data.
*/
protected boolean checkPriorityNumbers(Customer Customer, Vector items, Vector errors) {

boolean[] p = new boolean[items.size()];
boolean returnFlag = true;
// Check to make sure the priorities are in order
for (int i = 0; i < items.size(); i++){
if (((ItemsRentedCs)items.elementAt(i)).getPriority() == 1) {
if(p[0] == true) {
errors.add(new ErrorListItem(msgPriorityUnique));
break;
} else {
p[0] = true;
}
}
if (((ItemsRentedCs)items.elementAt(i)).getPriority() == 2) {
if(p[1] == true) {
errors.add(new ErrorListItem(msgPriorityUnique));
break;
} else {
p[1] = true;
}
}
if (((ItemsRentedCs)items.elementAt(i)).getPriority() == 3) {
if(p[2] == true) {
errors.add(new ErrorListItem(msgPriorityUnique));
break;
} else {
p[2] = true;
}
}
}

// Make sure that the row that has excess checked also has the lowest priority
for (int i = 0; i < items.size(); i++){
if (((ItemsRented)items.elementAt(i)).isExcessAllowed()) {
if (((ItemsRentedCs)items.elementAt(i)).getPriority() != items.size()) {
errors.add(new ErrorListItem(msgFNDLowPriority));
returnFlag = false;
}
// The full net deposit cannot have a balance in the Deposit Amount field
if (((ItemsRented)items.elementAt(i)).getDepositAmount() != 0) {
errors.add(new ErrorListItem(msgItemRentedAmt));
}
}
}
return returnFlag;
}
/**
* Purpose: To return a vector of the valid rows */

protected Vector getValidItemRowNums(UserRequestParameters reqParams, HttpServletRequest request, Vector errors) {
Vector validItemRowNum = new Vector();
int errorCount = 0;
Vector tmpErrors = new Vector();
// Flags to tell when a certain type of error has been reported (don't want to report the same error 2x)
// These are implemented as counters so that when errors are added for an acount row that is empty
// The specifice error counter can be decremented
int accountTypeErrorCount = 0;
int priorityErrorCount = 0;
int transferNumberErrorCount = 0;
int accountNumberErrorCount = 0;
int accountAmountErrorCount = 0;

for (int i = 0; i < 3; i++) {
// Reset the error counter and tmpErrors vector
errorCount = 0;
tmpErrors.clear();

// gather initial errors
if (reqParams.get("AccountValues_" + i).equals("Delete")) {
// The user selected the row for deletion, so just don't include it
// and don't display any error messages for it
// JUST SKIP IT!
} else {
// Validate the data in the row.
// Check the account type
if (reqParams.get("AccountValues_" + i).equals("-Select-")) {
if (accountTypeErrorCount == 0) tmpErrors.add(new ErrorListItem(msgAcctTypeReq));
errorCount++;
accountTypeErrorCount++;
}


// Check the priority
if (reqParams.get("PriorityValues_" + i).equals("-Select-")) {
if (priorityErrorCount == 0) tmpErrors.add(new ErrorListItem(msgPriorityNumReq));
errorCount++;
priorityErrorCount++;
}


// Check the transfer number
// the following line is commented out because we now have database registration number validation in
// the saveItemsRented() method
// if (reqParams.get("transferNbr_" + i) == null || !isRegistrationNumberValid(reqParams.get("transferNbr_" + i))) {
if (reqParams.get("transferNbr_" + i) == null || reqParams.get("transferNbr_" + i).trim().length() < 1) {
if (transferNumberErrorCount == 0) tmpErrors.add(new ErrorListItem(msgStoreRegistrationNbrReq));
errorCount++;
transferNumberErrorCount++;
}

// Check the account number
if (reqParams.get("accountNbr_" + i) == null || reqParams.get("accountNbr_" + i).trim().length() < 1) {
if (accountNumberErrorCount == 0) tmpErrors.add(new ErrorListItem(msgAcctNbrReq));
errorCount++;
accountNumberErrorCount++;
}

// Check the amount
try {
String itemNbr = reqParams.get("itemNbr_" + i);
itemNbr = StringUtil.removeNonDecimalChars(itemNbr).trim();
if (itemNbr == null || itemNbr.length() == 0) {
itemNbr = "0";
}

if (Double.parseDouble(itemNbr) <= 0) {
// OK for no amount if full net deposit is checked.
if (reqParams.get("remainingPay") != null) {
if (new Integer(Integer.parseInt(reqParams.get("remainingPay"))).intValue() != (i+1)) {
if (accountAmountErrorCount == 0) tmpErrors.add(new ErrorListItem(msgDepAmtReq));
errorCount++;
accountAmountErrorCount++;
}
}
} else if (Double.parseDouble(itemNbr) > 99999999.99) {
if (accountAmountErrorCount == 0) tmpErrors.add(new ErrorListItem(msgDepMaxAmt));
errorCount++;
accountAmountErrorCount++;
}
} // Get the parse exception
catch (Exception e) {
ErrorLog.log("Parse exception for the deposit in getValidItemsRowNums", ErrorLog.ABORTED_TRANSACTION, e);
}

// If there was an error in EVERY field and the error
// count is all of the fields but one, there's NO WAY it's valid
// so don't include it in the count
if (errorCount == ITEM_RENTED_FIELD_COUNT || (reqParams.get("balanceAmmount") == null && errorCount == (ITEM_RENTED_FIELD_COUNT - 1))) {
// decrement the error counters
accountTypeErrorCount--;
priorityErrorCount--;
transferNumberErrorCount--;
accountNumberErrorCount--;
accountAmountErrorCount--;
} else {
validDepositRowNum.add(Integer.toString(i));
errors.addAll(tmpErrors);
}
}
}
return validDepositRowNum;
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!