com.etcc.csc.dao.OraclePaymentDAO.java Source code

Java tutorial

Introduction

Here is the source code for com.etcc.csc.dao.OraclePaymentDAO.java

Source

package com.etcc.csc.dao;

import java.math.BigDecimal;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;

import org.apache.commons.lang.ArrayUtils;

import com.etcc.csc.common.DateUtil;
import com.etcc.csc.common.ErrorMessageDTO;
import com.etcc.csc.common.EtccErrorMessageException;
import com.etcc.csc.common.EtccException;
import com.etcc.csc.common.EtccSecurityException;
import com.etcc.csc.common.Logger;
import com.etcc.csc.common.Util;
import com.etcc.csc.datatype.Invoice;
import com.etcc.csc.datatype.MonthlyStatement;
import com.etcc.csc.datatype.OLC_PAYMENT_INFO_RECBean;
import com.etcc.csc.datatype.OlcUninvoicedViolsRec;
import com.etcc.csc.datatype.OlcUninvoicedViolsRecBean;
import com.etcc.csc.datatype.OlcVpsInvoicesRec;
import com.etcc.csc.datatype.OlcVpsInvoicesRecBean;
import com.etcc.csc.datatype.PaymentDetail;
import com.etcc.csc.datatype.PaymentDetailUtil;
import com.etcc.csc.datatype.PaymentResponse;
import com.etcc.csc.datatype.Violation;
import com.etcc.csc.dto.LicensePlateDTO;
import com.etcc.csc.dto.PaymentResultDTO;
import com.etcc.csc.dto.TagDTO;
import com.etcc.csc.oracleerrortest.dao.ErrorMsgRec;
import com.etcc.csc.plsql.OLCSC_ACCT_MGMT;
import com.etcc.csc.plsql.OLCSC_INV;
import com.etcc.csc.plsql.OLCSC_PARAM;
import com.etcc.csc.plsql.OLCSC_PAYMENT;
import com.etcc.csc.plsql.OLCSC_REP;
import com.etcc.csc.plsql.OLCSC_VTOLL;
import com.etcc.csc.plsql.OLC_ACCOUNT_TAG_ARR;
import com.etcc.csc.plsql.OLC_ACCOUNT_TAG_REC;
import com.etcc.csc.plsql.OLC_ERROR_MSG_ARR;
import com.etcc.csc.plsql.OLC_ERROR_MSG_REC;
import com.etcc.csc.plsql.OLC_PAYMENT_INFO_REC;
import com.etcc.csc.plsql.OLC_ST_INVOICES_ARR;
import com.etcc.csc.plsql.OLC_ST_PAYMENT_RCPT_REC;
import com.etcc.csc.plsql.OLC_ST_PMT_INV_REC;
import com.etcc.csc.plsql.OLC_UNINVOICED_VIOLS_ARR;
import com.etcc.csc.plsql.OLC_UNINVOICED_VIOLS_REC;
import com.etcc.csc.plsql.OLC_VPS_INVOICES_ARR;
import com.etcc.csc.plsql.OLC_VPS_INVOICES_REC;
import com.etcc.csc.plsql.OLC_VPS_INV_FEE_PMT_ARR;
import com.etcc.csc.plsql.OLC_VPS_INV_PMT_ARR;
import com.etcc.csc.plsql.OLC_VPS_UNINV_FEE_PMT_ARR;
import com.etcc.csc.plsql.OLC_VPS_UNINV_PMT_ARR;
import com.etcc.csc.plsql.T_LIC_PLATE_REC;
import com.etcc.csc.plsql.T_VIOLATOR_LPS_ARR;

public class OraclePaymentDAO extends PaymentDAO {
    private Logger logger = Logger.getLogger(OraclePaymentDAO.class);

    public PaymentDetail getPaymentDetail(String dbSessionId, String ipAddress, String loginId, long docId,
            String docType, String licPlate, String licState, BigDecimal transactionId)
            throws EtccErrorMessageException, Exception {
        PaymentDetail paymentDetail = null;
        try {
            setConnection(Util.getDbConnection());
            OLC_ACCOUNT_TAG_ARR[] P_ACCOUNT_TAG_ARR = new OLC_ACCOUNT_TAG_ARR[] { new OLC_ACCOUNT_TAG_ARR() };
            String[] P_FORCE_PMT = new String[] { "" };
            BigDecimal[] P_PMT_AMT = new BigDecimal[] { new BigDecimal(0) };
            BigDecimal[] P_DEP_AMT = new BigDecimal[] { new BigDecimal(0) };
            BigDecimal[] P_RTL_TRXN_ID = new BigDecimal[] { transactionId };

            OLC_VPS_INVOICES_ARR[] O_VPS_INVOICES_ARR = new OLC_VPS_INVOICES_ARR[] { new OLC_VPS_INVOICES_ARR() };
            OLC_UNINVOICED_VIOLS_ARR[] O_UNINVOICED_VIOLS_ARR = new OLC_UNINVOICED_VIOLS_ARR[] {
                    new OLC_UNINVOICED_VIOLS_ARR() };
            OLC_ERROR_MSG_ARR[] O_ERROR_MSG_ARR = new OLC_ERROR_MSG_ARR[] { new OLC_ERROR_MSG_ARR() };

            int result = new OLCSC_INV(conn).GET_PMT_INFO(dbSessionId, ipAddress, loginId, new BigDecimal(docId),
                    docType, licPlate, licState, P_ACCOUNT_TAG_ARR, P_FORCE_PMT, P_PMT_AMT, P_DEP_AMT,
                    P_RTL_TRXN_ID, O_VPS_INVOICES_ARR, O_UNINVOICED_VIOLS_ARR, O_ERROR_MSG_ARR, true).intValue();

            if (result == 1) {
                paymentDetail = new PaymentDetail();

                if (P_ACCOUNT_TAG_ARR[0] != null && !ArrayUtils.isEmpty(P_ACCOUNT_TAG_ARR[0].getArray())) {
                    OLC_ACCOUNT_TAG_REC[] accountTagRecs = P_ACCOUNT_TAG_ARR[0].getArray();
                    TagDTO[] tags = new TagDTO[accountTagRecs.length];
                    for (int i = 0; i < accountTagRecs.length; i++) {
                        tags[i] = new TagDTO();
                        tags[i].setLicPlate(accountTagRecs[i].getLIC_PLATE());
                        tags[i].setLicState(accountTagRecs[i].getLIC_STATE());
                        tags[i].setVehicleYear(accountTagRecs[i].getVEHICLE_YEAR());
                        tags[i].setVehicleColor(accountTagRecs[i].getVEHICLE_COLOR());
                        tags[i].setVehicleMake(accountTagRecs[i].getVEHICLE_MAKE());
                        tags[i].setVehicleModel(accountTagRecs[i].getVEHICLE_MODEL());
                    }
                    paymentDetail.setTags(tags);
                }

                if (!ArrayUtils.isEmpty(P_FORCE_PMT)) {
                    paymentDetail.setForcePayment(P_FORCE_PMT[0]);
                }

                if (!ArrayUtils.isEmpty(P_PMT_AMT)) {
                    paymentDetail.setTagAmount(P_PMT_AMT[0]);
                }

                if (!ArrayUtils.isEmpty(P_DEP_AMT)) {
                    paymentDetail.setDepAmount(P_DEP_AMT[0]);
                }

                if (!ArrayUtils.isEmpty(P_RTL_TRXN_ID)) {
                    paymentDetail.setTransactionId(P_RTL_TRXN_ID[0]);
                }

                if (O_VPS_INVOICES_ARR[0] != null && !ArrayUtils.isEmpty(O_VPS_INVOICES_ARR[0].getArray())) {
                    OLC_VPS_INVOICES_REC[] vpsInvoicesRecs = O_VPS_INVOICES_ARR[0].getArray();
                    Invoice[] invoices = new Invoice[vpsInvoicesRecs.length];
                    for (int i = 0; i < vpsInvoicesRecs.length; i++) {
                        invoices[i] = PaymentDetailUtil.convertToInvoice(vpsInvoicesRecs[i]);
                    }
                    paymentDetail.setInvoices(invoices);
                }

                if (O_UNINVOICED_VIOLS_ARR[0] != null
                        && !ArrayUtils.isEmpty(O_UNINVOICED_VIOLS_ARR[0].getArray())) {
                    OLC_UNINVOICED_VIOLS_REC[] uninvoicedViolsRecs = O_UNINVOICED_VIOLS_ARR[0].getArray();
                    Violation[] violations = new Violation[uninvoicedViolsRecs.length];
                    for (int i = 0; i < uninvoicedViolsRecs.length; i++) {
                        violations[i] = PaymentDetailUtil.convertToViolation(uninvoicedViolsRecs[i]);
                    }
                    paymentDetail.setViolations(violations);
                }
                System.out.println(paymentDetail.toString());
            } else {

                throw new EtccException("PaymentWS::getPaymentDetail fatal error");
            }
        } finally {
            closeConnection();
        }
        return paymentDetail;
    }

    public boolean veaAutoComments(long docId, String docType, String sessionId, String ipAddress, String userId,
            String veaName, OlcVpsInvoicesRecBean[] invoices) throws EtccException {

        try {
            setConnection(Util.getDbConnection());
            cstmt = conn.prepareCall("{? = call OLCSC_VPS_COMMENTS.vea_auto_comments(?,?,?,?,?,?,?,?)}");

            Map typeMap = new HashMap();
            typeMap.put("TAG_OWNER.OLC_VPS_INVOICES_REC", OlcVpsInvoicesRec.class);
            typeMap.put("TAG_OWNER.OLC_ERROR_MSG_REC", ErrorMsgRec.class);
            conn.setTypeMap(typeMap);

            cstmt.registerOutParameter(1, Types.SMALLINT);
            cstmt.setLong(2, docId);
            cstmt.setString(3, docType);
            cstmt.setString(4, sessionId); //session id
            cstmt.setString(5, ipAddress);
            cstmt.setString(6, userId);
            cstmt.setString(7, veaName);

            ArrayDescriptor arraydesc = ArrayDescriptor.createDescriptor("TAG_OWNER.OLC_VPS_INVOICES_ARR", conn);
            ARRAY array = new ARRAY(arraydesc, conn, convertToOracleInvoices(invoices));
            cstmt.setArray(8, array);

            cstmt.registerOutParameter(9, Types.ARRAY, "TAG_OWNER.OLC_ERROR_MSG_ARR");

            cstmt.execute();

            byte success = cstmt.getByte(1);

            if (success == 0) {
                Collection errors = Util.convertErrorMsgs(cstmt.getArray(9));
                Iterator iter = errors.iterator();
                while (iter.hasNext()) {
                    ErrorMessageDTO errorDTO = (ErrorMessageDTO) iter.next();
                    logger.info("error occured in veaAutoComments:" + errorDTO.getMessage());
                }
                return false;
            }

            return true;

        } catch (SQLException ex) {
            throw new EtccException();
        } finally {
            closeConnection();
        }
    }

    public boolean autoComments(long docId, String docType, String sessionId, String ipAddress, String userId,
            long paymentId, String payerName, double payAmt, String failedFlag, OlcVpsInvoicesRecBean[] invoices,
            OlcUninvoicedViolsRecBean[] uninvoiced) throws EtccException {
        try {
            setConnection(Util.getDbConnection());
            cstmt = conn.prepareCall("{? = call OLCSC_VPS_COMMENTS.auto_comments(?,?,?,?,?,?,?,?,?,?,?,?)}");

            Map typeMap = new HashMap();
            typeMap.put("TAG_OWNER.OLC_VPS_INVOICES_REC", OlcVpsInvoicesRec.class);
            typeMap.put("TAG_OWNER.OLC_UNINVOICED_VIOLS_REC", OlcUninvoicedViolsRec.class);
            typeMap.put("TAG_OWNER.OLC_ERROR_MSG_REC", ErrorMsgRec.class);
            conn.setTypeMap(typeMap);

            cstmt.registerOutParameter(1, Types.SMALLINT);
            cstmt.setLong(2, docId);
            cstmt.setString(3, docType);
            cstmt.setString(4, sessionId); //session id
            cstmt.setString(5, ipAddress);
            cstmt.setString(6, userId);
            cstmt.setLong(7, paymentId); //payment id
            cstmt.setString(8, payerName);
            cstmt.setDouble(9, payAmt);
            cstmt.setString(10, failedFlag); //

            ArrayDescriptor arraydesc = ArrayDescriptor.createDescriptor("TAG_OWNER.OLC_VPS_INVOICES_ARR", conn);
            ARRAY array = new ARRAY(arraydesc, conn, convertToOracleInvoices(invoices));
            cstmt.setArray(11, array);

            ArrayDescriptor arraydesc1 = ArrayDescriptor.createDescriptor("TAG_OWNER.OLC_UNINVOICED_VIOLS_ARR",
                    conn);
            ARRAY array1 = new ARRAY(arraydesc1, conn, convertToOracleUninvoiced(uninvoiced));
            cstmt.setArray(12, array1);

            cstmt.registerOutParameter(13, Types.ARRAY, "TAG_OWNER.OLC_ERROR_MSG_ARR");

            cstmt.execute();

            byte success = cstmt.getByte(1);

            if (success == 0) {
                Collection errors = Util.convertErrorMsgs(cstmt.getArray(9));
                Iterator iter = errors.iterator();
                while (iter.hasNext()) {
                    ErrorMessageDTO errorDTO = (ErrorMessageDTO) iter.next();
                    logger.info("error occured in autoComments:" + errorDTO.getMessage());
                }
                return false;
            }

            return true;

        } catch (SQLException ex) {
            throw new EtccException();
        } finally {
            closeConnection();
        }
    }

    private OlcVpsInvoicesRec[] convertToOracleInvoices(OlcVpsInvoicesRecBean[] invoices) throws SQLException {
        if (invoices != null && invoices.length > 0) {
            OlcVpsInvoicesRec[] result = new OlcVpsInvoicesRec[invoices.length];
            for (int i = 0; i < invoices.length; i++) {
                result[i] = new OlcVpsInvoicesRec();
                result[i].setCurrDueDate(DateUtil.calendarToTimestamp(invoices[i].getCurrDueDate()));
                result[i].setFirstName(invoices[i].getFirstName());
                result[i].setInvoiceAmount(invoices[i].getInvoiceAmount());
                result[i].setInvoiceDate(DateUtil.calendarToTimestamp(invoices[i].getInvoiceDate()));
                result[i].setInvoiceId(invoices[i].getInvoiceId());
                result[i].setLastName(invoices[i].getLastName());
                result[i].setLicPlateNbr(invoices[i].getLicPlateNbr());
                result[i].setLicState(invoices[i].getLicState());
                result[i].setOnlineFee(invoices[i].getOnlineFee());
                result[i].setVeaAmount(invoices[i].getVeaAmount());
                //                result[i].setViolations();
                result[i].setViolatorId(invoices[i].getViolatorId());
            }
            return result;
        }

        return null;
    }

    public PaymentResponse combinedPayment(long docId, String docType, String dbSessionId, String ipAddress,
            String loginId, BigDecimal transactionId, BigDecimal tagAmount, BigDecimal totalAmount, String dlState,
            String dlNumber, String email, boolean updatePmtInfo, String cardCode, String paymentType,
            String cardNumber, String expireMonth, String expireYear, String nameOnCard, String address,
            String address2, String city, String state, String zipCode, String plus4, String cardSecurityCode,
            Invoice[] invoices, Violation[] violations, boolean veaAccepted)
            throws EtccErrorMessageException, Exception {
        PaymentResponse paymentResponse = null;
        try {

            setConnection(Util.getDbConnection());
            BigDecimal acctId = null;
            if ("AC".equals(docType)) {
                acctId = new BigDecimal(docId);
            }

            OLC_PAYMENT_INFO_REC olcPaymentInfoRec = new OLC_PAYMENT_INFO_REC();
            olcPaymentInfoRec.setPMT_TYPE(paymentType);
            olcPaymentInfoRec.setCARD_CODE(cardCode);
            olcPaymentInfoRec.setCARD_SEC_CODE(cardSecurityCode);
            olcPaymentInfoRec.setCARD_NBR(cardNumber);
            olcPaymentInfoRec.setCARD_EXPIRES(DateUtil.monthYearToTimestamp(expireMonth + "/" + expireYear));
            olcPaymentInfoRec.setNAME_ON_CARD(nameOnCard);
            olcPaymentInfoRec.setADDRESS1(address);
            olcPaymentInfoRec.setADDRESS2(address2);
            olcPaymentInfoRec.setCITY(city);
            olcPaymentInfoRec.setSTATE(state);
            olcPaymentInfoRec.setZIP_CODE(zipCode);
            olcPaymentInfoRec.setPLUS4(plus4);

            OLC_VPS_INV_PMT_ARR P_INV_PMT_ARR = new OLC_VPS_INV_PMT_ARR();
            OLC_VPS_INV_FEE_PMT_ARR P_INV_FEE_PMT_ARR = new OLC_VPS_INV_FEE_PMT_ARR();
            OLC_VPS_UNINV_PMT_ARR P_UNINV_VIOL_PMT_ARR = new OLC_VPS_UNINV_PMT_ARR();
            OLC_VPS_UNINV_FEE_PMT_ARR P_UNINV_FEE_PMT_ARR = new OLC_VPS_UNINV_FEE_PMT_ARR();

            P_INV_PMT_ARR.setArray(PaymentDetailUtil.invoicesToOLC_VPS_INV_PMT_RECs(invoices, veaAccepted));
            P_INV_FEE_PMT_ARR.setArray(PaymentDetailUtil.invoicesToOLC_VPS_INV_FEE_PMT_RECs(invoices, veaAccepted));
            P_UNINV_VIOL_PMT_ARR.setArray(PaymentDetailUtil.violationsToOLC_VPS_UNINV_PMT_RECs(violations));
            P_UNINV_FEE_PMT_ARR.setArray(PaymentDetailUtil.violationsToOLC_VPS_UNINV_FEE_PMT_RECs(violations));

            String[] P_POSTING_STATUS = new String[] { "" };
            BigDecimal[] P_PAYMENT_ID = new BigDecimal[] { new BigDecimal(0) };
            OLC_ERROR_MSG_ARR[] O_ERROR_MSG_ARR = new OLC_ERROR_MSG_ARR[] { new OLC_ERROR_MSG_ARR() };

            logger.debug("OraclePaymentDAO.java::::combinedPayment::: docType:" + docType + ":dbSessionId:"
                    + dbSessionId + ":ipAddress:" + ipAddress + ":loginId:" + loginId + ":transactionId:"
                    + transactionId + ":acctId:" + acctId + ":tagAmount:" + tagAmount + ":totalAmount:"
                    + totalAmount + ":olcPaymentInfoRec.getNAME_ON_CARD():" + olcPaymentInfoRec.getNAME_ON_CARD()
                    + ":olcPaymentInfoRec.getADDRESS1():" + olcPaymentInfoRec.getADDRESS1()
                    + ":olcPaymentInfoRec.getADDRESS2():" + olcPaymentInfoRec.getADDRESS2()
                    + ":olcPaymentInfoRec.getCITY():" + olcPaymentInfoRec.getCITY()
                    + ":olcPaymentInfoRec.getSTATE():" + olcPaymentInfoRec.getSTATE()
                    + ":olcPaymentInfoRec.getZIP_CODE():" + olcPaymentInfoRec.getZIP_CODE() + ":dlState:" + dlState
                    + ":dlNumber:" + dlNumber + ":email:" + email + ":updatePmtInfo:" + updatePmtInfo + ":docId:"
                    + docId);

            int result = new OLCSC_PAYMENT(conn)
                    .MAKE_PAYMENT(new BigDecimal(docId), docType, dbSessionId, ipAddress, loginId, transactionId,
                            acctId, tagAmount, totalAmount, P_INV_PMT_ARR, P_INV_FEE_PMT_ARR, P_UNINV_VIOL_PMT_ARR,
                            P_UNINV_FEE_PMT_ARR, olcPaymentInfoRec, dlState, dlNumber, email, true,
                            updatePmtInfo ? "Y" : "N", P_POSTING_STATUS, P_PAYMENT_ID, O_ERROR_MSG_ARR)
                    .intValue();

            if (result == 1) {
                if (!ArrayUtils.isEmpty(P_POSTING_STATUS) && !ArrayUtils.isEmpty(P_PAYMENT_ID)) {
                    paymentResponse = new PaymentResponse();
                    paymentResponse.setPostingStatus(P_POSTING_STATUS[0].trim());
                    paymentResponse.setPaymentId(P_PAYMENT_ID[0]);
                }
            } else {
                if (O_ERROR_MSG_ARR[0] != null && O_ERROR_MSG_ARR[0].getArray() != null
                        && O_ERROR_MSG_ARR[0].getArray().length > 0) {
                    OLC_ERROR_MSG_REC[] errorMsgRecs = O_ERROR_MSG_ARR[0].getArray();
                    EtccErrorMessageException em = new EtccErrorMessageException(
                            "PaymentWS::combinedPayment error message");
                    for (int i = 0; i < errorMsgRecs.length; i++) {
                        em.addRecoverable(errorMsgRecs[i].getERROR_MSG());
                    }

                    // Procedure to capture more logs
                    logger.debug(
                            "Exception Occured in OraclePaymentDAO.java::combinedPayment.  More information : ");
                    int tmpindex = 0;
                    String tmperror = "";
                    while (O_ERROR_MSG_ARR.length > tmpindex) {
                        if (O_ERROR_MSG_ARR[tmpindex].getArray() == null)
                            break;

                        OLC_ERROR_MSG_REC[] moreErrorMsgRecs = O_ERROR_MSG_ARR[tmpindex].getArray();
                        for (int i = 0; (i < moreErrorMsgRecs.length) && (i < 10); i++) {
                            tmperror = tmperror + "\n" + (moreErrorMsgRecs[i].getERROR_MSG());
                        }
                        tmpindex++;
                        if (tmpindex > 10)
                            break;
                    }
                    logger.debug(tmperror);

                    throw em;
                } else {
                    logger.debug("PaymentWS::combinedPayment fatal error");

                    throw new EtccException("PaymentWS::combinedPayment fatal error");
                }
            }
        } finally {
            closeConnection();
        }
        return paymentResponse;
    }

    public PaymentResponse monthlyStatementPayment(String dbSessionId, String ipAddress, String loginId, Long docId,
            String docType, String statementId, BigDecimal transactionId, BigDecimal tagstoreAmt,
            BigDecimal totalAmount, MonthlyStatement monthlyStatement, String dlState, String dlNumber,
            String email, boolean updatePmtInfo, String cardCode, String paymentType, String cardNumber,
            String expireMonth, String expireYear, String nameOnCard, String address, String address2, String city,
            String state, String zipCode, String plus4, String cardSecurityCode, Invoice[] invoices,
            Violation[] uninvoiceViols) throws EtccErrorMessageException, Exception {
        PaymentResponse paymentResponse = null;
        try {
            setConnection(Util.getDbConnection());

            OLC_PAYMENT_INFO_REC olcPaymentInfoRec = new OLC_PAYMENT_INFO_REC();
            olcPaymentInfoRec.setPMT_TYPE(paymentType);
            olcPaymentInfoRec.setCARD_CODE(cardCode);
            olcPaymentInfoRec.setCARD_SEC_CODE(cardSecurityCode);
            olcPaymentInfoRec.setCARD_NBR(cardNumber);
            olcPaymentInfoRec.setCARD_EXPIRES(DateUtil.monthYearToTimestamp(expireMonth + "/" + expireYear));
            olcPaymentInfoRec.setNAME_ON_CARD(nameOnCard);
            olcPaymentInfoRec.setADDRESS1(address);
            olcPaymentInfoRec.setADDRESS2(address2);
            olcPaymentInfoRec.setCITY(city);
            olcPaymentInfoRec.setSTATE(state);
            olcPaymentInfoRec.setZIP_CODE(zipCode);
            olcPaymentInfoRec.setPLUS4(plus4);

            OLC_ST_PMT_INV_REC olcSTPmtInvRec = new OLC_ST_PMT_INV_REC();
            olcSTPmtInvRec.setSTATEMENT_ID(new BigDecimal(statementId));
            olcSTPmtInvRec.setACCOUNT_ID(BigDecimal.ZERO);
            OLC_ST_INVOICES_ARR P_OLC_ST_INVOICES_ARR = new OLC_ST_INVOICES_ARR();
            P_OLC_ST_INVOICES_ARR.setArray(PaymentDetailUtil.invoicesToOLC_ST_INVOICES_RECs(invoices));
            olcSTPmtInvRec.setINVOICES(P_OLC_ST_INVOICES_ARR);

            OLC_UNINVOICED_VIOLS_ARR P_OLC_UNINVOICED_VIOLS_ARR = new OLC_UNINVOICED_VIOLS_ARR();
            OLC_VPS_UNINV_PMT_ARR P_UNINV_VIOL_PMT_ARR = new OLC_VPS_UNINV_PMT_ARR();
            OLC_VPS_UNINV_FEE_PMT_ARR P_UNINV_FEE_PMT_ARR = new OLC_VPS_UNINV_FEE_PMT_ARR();

            P_OLC_UNINVOICED_VIOLS_ARR
                    .setArray(PaymentDetailUtil.violationsToOLC_UNINVOICED_VIOLS_RECs(uninvoiceViols));
            P_UNINV_VIOL_PMT_ARR.setArray(PaymentDetailUtil.violationsToOLC_VPS_UNINV_PMT_RECs(uninvoiceViols));
            P_UNINV_FEE_PMT_ARR.setArray(PaymentDetailUtil.violationsToOLC_VPS_UNINV_FEE_PMT_RECs(uninvoiceViols));

            olcSTPmtInvRec.setUNINVOICED_VIOLS(P_OLC_UNINVOICED_VIOLS_ARR);
            olcSTPmtInvRec.setUNINVOICED_VIOL_PMTS(P_UNINV_VIOL_PMT_ARR);
            olcSTPmtInvRec.setUNINVOICED_FEE_PMTS(P_UNINV_FEE_PMT_ARR);

            OLC_ST_PMT_INV_REC[] olcSTPmtInvRecArray = new OLC_ST_PMT_INV_REC[1];
            olcSTPmtInvRecArray[0] = olcSTPmtInvRec;

            String[] P_POSTING_STATUS = new String[] { "" };
            //   BigDecimal[] P_PAYMENT_ID = new BigDecimal[] { new BigDecimal(0) };
            OLC_ERROR_MSG_ARR[] O_ERROR_MSG_ARR = new OLC_ERROR_MSG_ARR[] { new OLC_ERROR_MSG_ARR() };

            int result = new OLCSC_INV(conn).MAKE_STATEMENT_PAYMENT(dbSessionId, ipAddress, loginId,
                    new BigDecimal(docId), docType, new BigDecimal(statementId), transactionId, tagstoreAmt,
                    totalAmount, olcSTPmtInvRecArray, olcPaymentInfoRec, email, updatePmtInfo ? "Y" : "N",
                    P_POSTING_STATUS, O_ERROR_MSG_ARR, true).intValue();

            if (result == 1) {
                if (!ArrayUtils.isEmpty(P_POSTING_STATUS)) {
                    paymentResponse = new PaymentResponse();
                    paymentResponse.setPostingStatus(P_POSTING_STATUS[0].trim());
                }
                System.out.println("PAYMENT_RECEIPTS  :" + olcSTPmtInvRecArray[0].getPAYMENT_RECEIPTS());

                if (olcSTPmtInvRecArray[0].getPAYMENT_RECEIPTS() != null) {

                    paymentResponse = new PaymentResponse();
                    paymentResponse.setPostingStatus(P_POSTING_STATUS[0].trim());
                    OLC_ST_PAYMENT_RCPT_REC[] OLC_ST_PAYMENT_RCPT_RECs = olcSTPmtInvRecArray[0]
                            .getPAYMENT_RECEIPTS().getArray();
                    List<PaymentResultDTO> paymentResultDTOs = new ArrayList<PaymentResultDTO>();
                    for (int i = 0; i < OLC_ST_PAYMENT_RCPT_RECs.length; i++) {
                        logger.info("Payment Receipt Id " + OLC_ST_PAYMENT_RCPT_RECs[i].getPAYMENT_RECEIPT_ID()); //RTalreja 02/16/2015 Ticket:RITE2128P1 Receipt
                        logger.info("OLC_Payment_id " + OLC_ST_PAYMENT_RCPT_RECs[i].getOL_PMT_ID());
                        PaymentResultDTO paymentResultDTO = new PaymentResultDTO();
                        paymentResultDTO.setPaymentId(OLC_ST_PAYMENT_RCPT_RECs[i].getPAYMENT_RECEIPT_ID());
                        paymentResultDTO.setOlPaymentId(OLC_ST_PAYMENT_RCPT_RECs[i].getOL_PMT_ID()); //RTalreja 02/16/2015 Ticket:RITE2128P1 Receipt
                        paymentResultDTO.setInvoiceType(OLC_ST_PAYMENT_RCPT_RECs[i].getINVOICE_TYPE());
                        paymentResultDTOs.add(paymentResultDTO);
                    }
                    paymentResponse.setPaymentResultDTOs(paymentResultDTOs);
                }
            } else {
                if (O_ERROR_MSG_ARR[0] != null && O_ERROR_MSG_ARR[0].getArray() != null
                        && O_ERROR_MSG_ARR[0].getArray().length > 0) {
                    OLC_ERROR_MSG_REC[] errorMsgRecs = O_ERROR_MSG_ARR[0].getArray();
                    EtccErrorMessageException em = new EtccErrorMessageException(
                            "PaymentWS::combinedPayment error message");
                    for (int i = 0; i < errorMsgRecs.length; i++) {
                        em.addRecoverable(errorMsgRecs[i].getERROR_MSG());
                    }
                    throw em;
                } else {
                    throw new EtccException("PaymentWS::combinedPayment fatal error");
                }
            }
        } finally {
            closeConnection();
        }
        return paymentResponse;
    }

    private OlcUninvoicedViolsRec[] convertToOracleUninvoiced(OlcUninvoicedViolsRecBean[] uninvoiced)
            throws SQLException {
        if (uninvoiced != null && uninvoiced.length > 0) {
            OlcUninvoicedViolsRec[] result = new OlcUninvoicedViolsRec[uninvoiced.length];
            for (int i = 0; i < uninvoiced.length; i++) {
                result[i] = new OlcUninvoicedViolsRec();
                result[i].setAviAmt(uninvoiced[i].getAviAmt());
                result[i].setCashAmt(uninvoiced[i].getCashAmt());
                result[i].setStatus(uninvoiced[i].getStatus());
                result[i].setViolationDateTime(DateUtil.calendarToTimestamp(uninvoiced[i].getViolationDateTime()));
                result[i].setViolationId(uninvoiced[i].getViolationId());
                result[i].setViolationLocation(uninvoiced[i].getViolationLocation());
                result[i].setViolatorId(uninvoiced[i].getViolatorId());
                result[i].setFullLocationName(uninvoiced[i].getFullLocationName());
                result[i].setLicPlate(uninvoiced[i].getLicPlate());
                result[i].setLicState(uninvoiced[i].getLicState());
                result[i].setOnlineFee(uninvoiced[i].getOnlineFee());
            }

            return result;
        }
        return null;
    }

    public boolean veaExists(BigDecimal docId, String docType, String dbSessionId, String ipAddress, String loginId,
            String licPlate, String licState) throws Exception {

        try {

            setConnection(Util.getDbConnection());
            BigDecimal[] O_VEA_EXIST = new BigDecimal[] { new BigDecimal(0) };
            OLC_ERROR_MSG_ARR[] O_ERROR_MSG_ARR = new OLC_ERROR_MSG_ARR[] { new OLC_ERROR_MSG_ARR() };
            OLCSC_ACCT_MGMT pkg = new OLCSC_ACCT_MGMT(conn);

            int result = pkg.VEA_EXIST_INFO(docId.toPlainString(), docType, dbSessionId, ipAddress, loginId,
                    licPlate, licState, O_VEA_EXIST, O_ERROR_MSG_ARR).intValue();

            if (result == 1) {
                if (!ArrayUtils.isEmpty(O_VEA_EXIST)) {
                    return O_VEA_EXIST[0].intValue() == 1;
                }
            }
            throw new EtccException("PaymentWS::veaExists fatal error");
        } finally {
            closeConnection();
        }
    }

    public OLC_PAYMENT_INFO_RECBean getPaymentInfo(BigDecimal docId, String docType, String dbSessionId,
            String ipAddress, String loginId) throws EtccErrorMessageException, Exception {
        OLC_PAYMENT_INFO_RECBean olcPaymentInfoRecBean = null;
        try {

            setConnection(Util.getDbConnection());
            OLC_PAYMENT_INFO_REC[] O_PAYMENT_INFO_REC = new OLC_PAYMENT_INFO_REC[] { new OLC_PAYMENT_INFO_REC() };
            OLC_ERROR_MSG_ARR[] O_ERROR_MSG_ARR = new OLC_ERROR_MSG_ARR[] { new OLC_ERROR_MSG_ARR() };

            OLCSC_ACCT_MGMT plsql = new OLCSC_ACCT_MGMT(conn);

            int result = plsql.GET_PAYMENT_INFO(docId.toPlainString(), docType, dbSessionId, ipAddress, loginId,
                    O_PAYMENT_INFO_REC, O_ERROR_MSG_ARR).intValue();

            if (result == 1) {
                if (!ArrayUtils.isEmpty(O_PAYMENT_INFO_REC)) {
                    olcPaymentInfoRecBean = new OLC_PAYMENT_INFO_RECBean(O_PAYMENT_INFO_REC[0]);
                }
            } else {
                if (O_ERROR_MSG_ARR[0] != null && O_ERROR_MSG_ARR[0].getArray() != null
                        && O_ERROR_MSG_ARR[0].getArray().length > 0) {
                    OLC_ERROR_MSG_REC[] errorMsgRecs = O_ERROR_MSG_ARR[0].getArray();
                    EtccErrorMessageException em = new EtccErrorMessageException(
                            "PaymentWS::getPaymentInfo error message");
                    for (int i = 0; i < errorMsgRecs.length; i++) {
                        em.addRecoverable(errorMsgRecs[i].getERROR_MSG());
                    }
                    throw em;
                } else {
                    throw new EtccException("PaymentWS::getPaymentInfo fatal error");
                }
            }
        } finally {
            closeConnection();
        }
        return olcPaymentInfoRecBean;
    }

    public boolean postViolations(BigDecimal docId, String docType, String dbSessionId, String ipAddress,
            String loginId, Violation[] violations) throws EtccErrorMessageException, Exception {
        boolean success = false;
        try {

            setConnection(Util.getDbConnection());
            OLC_ERROR_MSG_ARR[] O_ERROR_MSG_ARR = new OLC_ERROR_MSG_ARR[] { new OLC_ERROR_MSG_ARR() };

            OLC_UNINVOICED_VIOLS_ARR UNINVOICED_VIOLS_ARR = new OLC_UNINVOICED_VIOLS_ARR();
            UNINVOICED_VIOLS_ARR.setArray(PaymentDetailUtil.convertToOLC_UNINVOICED_VIOLS_RECs(violations));
            OLC_UNINVOICED_VIOLS_ARR[] P_UNINVOICED_VIOLS = new OLC_UNINVOICED_VIOLS_ARR[] { UNINVOICED_VIOLS_ARR };
            OLCSC_VTOLL plsql = new OLCSC_VTOLL(conn);

            int result = plsql.PAY_UNINVOICED_VIOLS(P_UNINVOICED_VIOLS, dbSessionId, ipAddress, loginId, docId, "Y",
                    O_ERROR_MSG_ARR).intValue();

            if (result == 1) {
                success = true;
            } else {
                if (O_ERROR_MSG_ARR[0] != null && O_ERROR_MSG_ARR[0].getArray() != null
                        && O_ERROR_MSG_ARR[0].getArray().length > 0) {
                    OLC_ERROR_MSG_REC[] errorMsgRecs = O_ERROR_MSG_ARR[0].getArray();
                    EtccErrorMessageException em = new EtccErrorMessageException("postViolations error message");
                    for (int i = 0; i < errorMsgRecs.length; i++) {
                        em.addRecoverable(errorMsgRecs[i].getERROR_MSG());
                    }
                    throw em;
                } else {
                    throw new EtccException("postViolations fatal error");
                }
            }
        } finally {
            closeConnection();
        }
        return success;
    }

    public String getPaymentReceipt(BigDecimal docId, String docType, String dbSessionId, String ipAddress,
            String loginId, BigDecimal paymentId, String reportFormat) throws EtccErrorMessageException, Exception {
        String reportUrl = null;

        try {

            setConnection(Util.getDbConnection());
            String[] O_REPORT_URL = new String[] { "" };
            OLC_ERROR_MSG_ARR[] O_ERROR_MSG_ARR = new OLC_ERROR_MSG_ARR[] { new OLC_ERROR_MSG_ARR() };

            int result = new OLCSC_REP(conn).ONLINE_RECEIPT_RPT(reportFormat, docId, docType, paymentId,
                    dbSessionId, ipAddress, loginId, O_REPORT_URL, O_ERROR_MSG_ARR).intValue();
            if (result == 1) {
                if (!ArrayUtils.isEmpty(O_REPORT_URL)) {
                    reportUrl = O_REPORT_URL[0].trim();
                }
            } else {
                if (O_ERROR_MSG_ARR[0] != null && O_ERROR_MSG_ARR[0].getArray() != null
                        && O_ERROR_MSG_ARR[0].getArray().length > 0) {
                    OLC_ERROR_MSG_REC[] errorMsgRecs = O_ERROR_MSG_ARR[0].getArray();
                    EtccErrorMessageException em = new EtccErrorMessageException("postViolations error message");
                    for (int i = 0; i < errorMsgRecs.length; i++) {
                        em.addRecoverable(errorMsgRecs[i].getERROR_MSG());
                    }
                    throw em;
                } else {
                    throw new EtccException("postViolations fatal error");
                }
            }
        } finally {
            closeConnection();
        }
        return reportUrl;
    }

    public BigDecimal getPaymentLimit() throws Exception {
        try {

            setConnection(Util.getDbConnection());
            return new OLCSC_PARAM(conn).GET_OL_PAYMENT_LIMIT(new OLC_ERROR_MSG_ARR[] { new OLC_ERROR_MSG_ARR() });
        } finally {
            closeConnection();
        }
    }

    public boolean updateSessionId(BigDecimal docId, String docType, String dbSessionId, String ipAddress,
            String loginId, String paymentId) throws EtccErrorMessageException, Exception {
        boolean success = false;
        try {

            setConnection(Util.getDbConnection());
            OLC_ERROR_MSG_ARR[] O_ERROR_MSG_ARR = new OLC_ERROR_MSG_ARR[] { new OLC_ERROR_MSG_ARR() };
            BigDecimal pmtId = (paymentId == null) ? null : new BigDecimal(paymentId);
            int result = new OLCSC_PAYMENT(conn).UPDATE_SESSION_ID(docId, docType, dbSessionId, ipAddress, loginId,
                    true, pmtId, O_ERROR_MSG_ARR).intValue();

            if (result == 1) {
                success = true;
            } else {
                if (O_ERROR_MSG_ARR[0] != null && O_ERROR_MSG_ARR[0].getArray() != null
                        && O_ERROR_MSG_ARR[0].getArray().length > 0) {
                    OLC_ERROR_MSG_REC[] errorMsgRecs = O_ERROR_MSG_ARR[0].getArray();
                    EtccErrorMessageException em = new EtccErrorMessageException("updateSessionId error message");
                    for (int i = 0; i < errorMsgRecs.length; i++) {
                        em.addRecoverable(errorMsgRecs[i].getERROR_MSG());
                    }
                    throw em;
                } else {
                    throw new EtccException("update session Id error");
                }
            }
        } finally {
            closeConnection();
        }
        return success;
    }

    public long hasVBInvoices(String licPlate, String licState, BigDecimal inv_id, BigDecimal violator_id)
            throws EtccErrorMessageException, Exception {

        long result = 0;
        try {
            setConnection(Util.getDbConnection());

            cstmt = conn.prepareCall("{? = call olcsc_VB_inv.has_invoices(?,?,?,?)}");

            cstmt.registerOutParameter(1, Types.VARCHAR);
            cstmt.setString(2, licPlate);
            cstmt.setString(3, licState);
            cstmt.setBigDecimal(4, inv_id);
            cstmt.registerOutParameter(4, Types.NUMERIC);
            cstmt.setBigDecimal(5, violator_id);
            cstmt.execute();

            String violationExists = cstmt.getString(1);
            logger.info("the violation exist value is " + violationExists);
            if (violationExists.equals("Y")) {
                result = cstmt.getLong(4);

            }
            logger.info("the result value is " + result);
        } catch (Throwable t) {
            throw new EtccException("Error running hasVBInvoices: " + t, t);
        } finally {
            closeConnection();
        }

        return result;

    }

    /**
     * No payment Checkout: check out the retail transaction passed to this 
     * method. Make sure this method is called only when there is no payment
     * expected.
     * 
     * @param accountId
     * @param dbSessionId
     * @param ipAddress
     * @param loginId
     * @param retailTransId
     * @return
     * @throws EtccException
     * @throws Exception
     */
    public boolean noPaymentCheckout(long accountId, String dbSessionId, String ipAddress, String loginId,
            long retailTransId) throws EtccException, Exception {
        boolean success = false;
        try {
            setConnection(Util.getDbConnection());

            /*
              FUNCTION no_payment_checkout(p_acct_id        IN accounts.acct_id%TYPE,
                            p_session_id    IN VARCHAR2,
                            p_ip_address    IN VARCHAR2,
                            p_user_id       IN VARCHAR2,
                            p_rtl_trxn_id   IN NUMBER,
                            o_error_msg_arr OUT olc_error_msg_arr,
                            p_called_from_ui      boolean default TRUE)
              RETURN NUMBER
             */

            setConnection(Util.getDbConnection());

            Map typeMap = new HashMap();
            typeMap.put("TAG_OWNER.OLC_ERROR_MSG_REC", ErrorMsgRec.class);
            conn.setTypeMap(typeMap);

            cstmt = conn.prepareCall("{? = call OLCSC_ACCT_MGMT.NO_PAYMENT_CHECKOUT(?,?,?,?,?,?)}");

            cstmt.registerOutParameter(1, Types.SMALLINT);
            cstmt.setLong(2, accountId);
            cstmt.setString(3, dbSessionId);
            cstmt.setString(4, ipAddress);
            cstmt.setString(5, loginId);
            cstmt.setLong(6, retailTransId);
            cstmt.registerOutParameter(7, Types.ARRAY, "TAG_OWNER.OLC_ERROR_MSG_ARR");
            cstmt.execute();
            int result = cstmt.getInt(1);
            if (result == -1) {
                logger.info("security exception: activateTag");
                throw new EtccSecurityException("security exception in activateTag");
            } else if (result == 1) {
                success = true;
            } else {
                Collection errors = Util.convertErrorMsgs(cstmt.getArray(7));
                Iterator iter = errors.iterator();
                while (iter.hasNext()) {
                    ErrorMessageDTO errorDTO = (ErrorMessageDTO) iter.next();
                    logger.error("Error occured in noPaymentCheckout:" + errorDTO.getMessage());
                }
            }
            logger.info("No payment checkout, Success? " + success);
        } catch (Throwable t) {
            throw new EtccException("Error running noPaymentCheckout: ", t);
        } finally {
            closeConnection();
        }
        return success;
    }

    public List<LicensePlateDTO> getAccountLicPlates(long accountId) throws EtccException, Exception {
        List<LicensePlateDTO> licensePlateDTOList = new ArrayList<LicensePlateDTO>();
        try {
            T_VIOLATOR_LPS_ARR[] licPlateArray = new T_VIOLATOR_LPS_ARR[] { new T_VIOLATOR_LPS_ARR() };
            setConnection(Util.getDbConnection());

            int result = new OLCSC_ACCT_MGMT(conn).GET_ACCOUNT_PLATES(new BigDecimal(accountId), licPlateArray)
                    .intValue();
            if (result == 1) {
                if (licPlateArray != null && licPlateArray.length > 0) {
                    T_LIC_PLATE_REC[] P_LIC_PLATE_REC_ARRAY = licPlateArray[0].getArray();
                    if (P_LIC_PLATE_REC_ARRAY.length > 0) {
                        for (int i = 0; i < P_LIC_PLATE_REC_ARRAY.length; i++) {
                            LicensePlateDTO licensePlateDTO = new LicensePlateDTO();
                            licensePlateDTO.setLicPlateNumber(P_LIC_PLATE_REC_ARRAY[i].getLIC_PLATE());
                            licensePlateDTO.setLicPlateState(P_LIC_PLATE_REC_ARRAY[i].getLIC_STATE());
                            licensePlateDTO.setViolatorId(P_LIC_PLATE_REC_ARRAY[i].getVIOLATOR_ID());
                            licensePlateDTO
                                    .setStartDate(timestampToCalendar(P_LIC_PLATE_REC_ARRAY[i].getSTARTDATE()));
                            licensePlateDTO.setEndDate(timestampToCalendar(P_LIC_PLATE_REC_ARRAY[i].getENDDATE()));
                            licensePlateDTOList.add(licensePlateDTO);
                        }
                    }
                }
            }
        } finally {
            closeConnection();
        }
        return licensePlateDTOList;
    }

    private Calendar timestampToCalendar(Timestamp timestamp) {
        if (timestamp == null) {
            return null;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(timestamp.getTime()));
        return calendar;
    }

    public String getMonthlyStatementPaymentReceipt(BigDecimal docId, String docType, String dbSessionId,
            String ipAddress, String loginId, BigDecimal paymentId, String reportFormat)
            throws EtccErrorMessageException, Exception {
        String reportUrl = null;

        try {

            setConnection(Util.getDbConnection());
            String[] O_REPORT_URL = new String[] { "" };
            OLC_ERROR_MSG_ARR[] O_ERROR_MSG_ARR = new OLC_ERROR_MSG_ARR[] { new OLC_ERROR_MSG_ARR() };

            int result = new OLCSC_INV(conn).GET_MONTHLY_STATEMENT_RCPT_RPT(reportFormat, docId, docType, paymentId,
                    dbSessionId, ipAddress, loginId, O_REPORT_URL, O_ERROR_MSG_ARR).intValue();
            if (result == 1) {
                if (!ArrayUtils.isEmpty(O_REPORT_URL)) {
                    reportUrl = O_REPORT_URL[0].trim();
                }
            } else {
                if (O_ERROR_MSG_ARR[0] != null && O_ERROR_MSG_ARR[0].getArray() != null
                        && O_ERROR_MSG_ARR[0].getArray().length > 0) {
                    OLC_ERROR_MSG_REC[] errorMsgRecs = O_ERROR_MSG_ARR[0].getArray();
                    EtccErrorMessageException em = new EtccErrorMessageException("postViolations error message");
                    for (int i = 0; i < errorMsgRecs.length; i++) {
                        em.addRecoverable(errorMsgRecs[i].getERROR_MSG());
                    }
                    throw em;
                } else {
                    throw new EtccException("postViolations fatal error");
                }
            }
        } finally {
            closeConnection();
        }
        return reportUrl;
    }

    public boolean statementDataAvailable(String dbSessionId, String ipAddress, String loginId, String ipAddress1,
            BigDecimal docId, String docType, BigDecimal statementId, BigDecimal invoiceId, BigDecimal accountId,
            String licPlate, String licPlateState) {
        try {

            setConnection(Util.getDbConnection());
            OLC_ERROR_MSG_ARR[] O_ERROR_MSG_ARR = new OLC_ERROR_MSG_ARR[] { new OLC_ERROR_MSG_ARR() };
            BigDecimal result = new OLCSC_INV(conn).STATEMENT_DATA_AVAILABLE(dbSessionId, ipAddress, loginId, docId,
                    docType, statementId, invoiceId, accountId, licPlate, licPlateState, O_ERROR_MSG_ARR);
            System.out.println(result.intValue() == 1);
            return (result.intValue() == 1);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            closeConnection();
        }
        return false;
    }
}