com.intuit.it.billing.data.BillingFileReader.java Source code

Java tutorial

Introduction

Here is the source code for com.intuit.it.billing.data.BillingFileReader.java

Source

package com.intuit.it.billing.data;

import java.io.BufferedReader;
import java.io.FileReader;
import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

import org.springframework.stereotype.Repository;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import com.intuit.it.billing.model.Allocation;
import com.intuit.it.billing.model.Customer;
import com.intuit.it.billing.model.LineItem;
import com.intuit.it.billing.model.PaymentInfoCC;
import com.intuit.it.billing.model.PaymentInfoCheck;
import com.intuit.it.billing.model.PaymentInfoEFT;
import com.intuit.it.billing.util.JSONException;

//@Repository("billingDAO")
public class BillingFileReader implements BillingDAO {

    String directory = "/home/bitnami/data/";

    /**
      * @section dao_section class BillingDAOImpl
     * getAllocation
     * 
     * To be used in a caching method where we are pulling all of the allocations at once.  The way we can do this
     * is to merge a date range based set of billing history records with a date range set of allocations.
     * <p/>
     * <p/>
     * <b>DATABASE PROCEDURE:</b>
     *  
     * @code
     *     FUNCTION fn_get_item_allocations(
     *           item_no IN VARCHAR2 )
     *        RETURN ref_cursor;
     * @endcode
     * <p/>
     * <b>DATABASE RESULT SET:</b>
     * <ul>
     *    <li>ALLOCATION_DATE,</li>
     *    <li>ALLOCATION_T, </li>
     *    <li>ALLOCATION_AMT,</li>
     *    <li>AR_ITEM_NO, </li>
     *    <li>BILL_ITEM_NO, </li>
     *    <li>ITEM_DESCRIPTION, </li>
     *    <li>ITEM_CODE,</li> 
     *    <li>AR_ITEM_DATE, </li>
     *    <li>BILL_ITEM_DATE </li>
     *    <li>LICENSE</li>
     *  </ul>
     *  
     * @param customer  :  The Customer.accountNo account number of the customer who's allocations we need
     * @param startDate : The starting date of the allocation - to be merged with a billing history record set
     * @param endDate  :  The ending date of the allocation - to be merged with a billing history record set
     * 
     * @return A list of Allocation objects. 
     * @throws JSONException 
     * 
     * 
     * 
     */
    @Override
    public List<Allocation> getAllocation(String itemNo) throws JSONException {

        List<Allocation> allocs = new ArrayList<Allocation>();

        try {
            //csv file containing data
            String strFile = directory + "a_" + itemNo + ".csv";
            DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy h:mm");

            //create BufferedReader to read csv file
            BufferedReader br = new BufferedReader(new FileReader(strFile));
            String strLine = "";
            int lineNumber = 0, tokenNumber = 0;

            //read comma separated file line by line
            while ((strLine = br.readLine()) != null) {

                if (strLine.startsWith("$")) {
                    continue;
                }

                lineNumber++;

                tokenNumber = 0;

                //break comma separated line using ","
                String[] splitted = strLine.split(",");

                Allocation l = new Allocation();

                l.setLicense(splitted[tokenNumber]);
                tokenNumber++;
                l.setAllocationDate(formatter.parse(splitted[tokenNumber]));
                tokenNumber++;
                l.setAllocationAmount(new BigDecimal(splitted[tokenNumber]));
                tokenNumber++;
                l.setAllocatedFromItem(splitted[tokenNumber]);
                l.setAllocatedToItem(splitted[tokenNumber]);
                l.setItemDescription(splitted[tokenNumber]);
                l.setItemCode(splitted[tokenNumber]);
                allocs.add(l);

            }

            br.close();

        } catch (Exception e) {
            System.out.println("Exception while reading csv file:  " + e);
            throw JSONException.noDataFound("Bad file read " + e.getMessage());

        }

        if (allocs == null || allocs.isEmpty()) {
            throw JSONException.noDataFound("Null set returned - no data found");
        }

        return allocs;
    }

    /**
     * getAllocationsList
     * 
     * To be used in a caching method where we are pulling all of the allocations at once.  The way we can do this
     * is to merge a date range based set of billing history records with a date range set of allocations.
     * <p/>
     * <p/>
     * <b>DATABASE PROCEDURE:</b>
     *  
     * @code
     *     FUNCTION fn_get_allocations(
     *           customer IN VARCHAR2,
     *           start_date IN DATE,
     *           end_date   IN DATE )
     *        RETURN ref_cursor;
     * @endcode
     * <p/>
     * <b>DATABASE RESULT SET:</b>
     * <ul>
     *    <li>ALLOCATION_DATE,</li>
     *    <li>ALLOCATION_T, </li>
     *    <li>ALLOCATION_AMT,</li>
     *    <li>AR_ITEM_NO, </li>
     *    <li>BILL_ITEM_NO, </li>
     *    <li>ITEM_DESCRIPTION, </li>
     *    <li>ITEM_CODE,</li> 
     *    <li>AR_ITEM_DATE, </li>
     *    <li>BILL_ITEM_DATE </li>
     *    <li>LICENSE</li>
     *  </ul>
     *  
     * @param customer  :  The Customer.accountNo account number of the customer who's allocations we need
     * @param startDate : The starting date of the allocation - to be merged with a billing history record set
     * @param endDate  :  The ending date of the allocation - to be merged with a billing history record set
     * 
     * @return A list of Allocation objects. 
     * 
     */
    @Override
    public List<Allocation> getAllocationsList(String customer, Date startDate, Date endDate) throws JSONException {

        List<Allocation> allocs = new ArrayList<Allocation>();

        try {
            //csv file containing data
            String strFile = directory + "ac_" + customer + ".csv";
            DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy h:mm");

            //create BufferedReader to read csv file
            BufferedReader br = new BufferedReader(new FileReader(strFile));
            String strLine = "";
            int lineNumber = 0, tokenNumber = 0;

            //read comma separated file line by line
            while ((strLine = br.readLine()) != null) {

                if (strLine.startsWith("$")) {
                    continue;
                }

                lineNumber++;

                tokenNumber = 0;

                //break comma separated line using ","
                String[] splitted = strLine.split(",");

                Allocation l = new Allocation();

                l.setLicense(splitted[tokenNumber]);
                tokenNumber++;
                l.setAllocationDate(formatter.parse(splitted[tokenNumber]));
                tokenNumber++;

                Date d = l.getAllocationDate();
                if (d != null && d.after(formatter.parse("01/01/1990 00:00"))
                        && startDate.after(formatter.parse("01/01/1990 00:00"))
                        && endDate.after(formatter.parse("01/01/1990 00:00"))) {
                    if (d.before(startDate) || d.after(endDate)) {
                        lineNumber--;
                        continue;
                    }
                }

                l.setAllocationAmount(new BigDecimal(splitted[tokenNumber]));
                tokenNumber++;
                l.setAllocatedFromItem(splitted[tokenNumber]);
                tokenNumber++;
                l.setAllocatedToItem(splitted[tokenNumber]);
                tokenNumber++;
                l.setItemDescription(splitted[tokenNumber]);
                tokenNumber++;
                l.setItemCode(splitted[tokenNumber]);
                tokenNumber++;
                allocs.add(l);
            }

            br.close();

        } catch (Exception e) {
            System.out.println("Exception while reading csv file:  " + e);
            throw JSONException.noDataFound("Bad file read " + e.getMessage());

        }

        if (allocs == null || allocs.isEmpty()) {
            throw JSONException.noDataFound("Null set returned - no data found");
        }

        return allocs;
    }

    /**
     * getBillingHistory is to be used to get  get the billing history of a given customer.
     * <p/>
     * <p/>
     * <b>DATABASE PROCEDURE:</b>
     *  
     * @code
     *  FUNCTION fn_get_history(
     *    customer   IN VARCHAR2,
     *    start_date IN DATE,
     *    end_date   IN DATE,
     *    page       IN INTEGER,
     *    records    IN INTEGER )
     *  RETURN ref_cursor;
     *  @endcode
     * <p/>
     * <b>DATABASE RESULT SET:</b>
     * <ul>
     *    <li>ITEM_ID,</li>
     *    <li>BILL_ITEM_NO,</li>
     *    <li>AR_ACCOUNT_NO,</li>
     *    <li>ACCOUNT_NO,</li>
     *    <li>ORDER_NO,</li>
     *    <li>ORDER_LINE_NO,</li>
     *    <li>EVENT_TYPE,</li>
     *    <li>CHARGE_TYPE,</li>
     *    <li> CURRENCY,</li>
     *    <li>CREATED_DATE,</li>
     *    <li>BILL_DATE,</li>
     *    <li>DUE_DATE,</li>
     *    <li>STATUS,</li>
     *    <li>REASON_CODE,</li>
     *    <li>ITEM_TOTAL,</li>
     *    <li>ITEM_DUE,</li>
     *    <li>ITEM_DISPUTED,</li>
     *    <li>ITEM_BASE,</li>
     *    <li>ITEM_TAX,</li>
     *    <li>ITEM_DESCRIPTION,</li>
     *    <li>ITEM_CODE,</li>
     *    <li>LICENSE,</li>
     *    <li>PAY_TYPE,</li>
     *    <li>PAY_DESCR,</li>
     *    <li>PAY_ACCT_TYPE,
     *    <li>PAY_PSON,</li>
     *    <li>QUANTITY </li>
     *  </ul>
     *  
     * @param customer  :  The Customer.accountNo of the customer we want history for
     * @param startDate : The starting date of the allocation - to be merged with a billing history record set
     * @param endDate   :  The ending date of the allocation - to be merged with a billing history record set
     * @param skip      :  Starting record for server side paging
     * @param pageSize  :  How many records to retrieve 
     * 
     * @return A list of LineItem objects in reverse date order sort
     */
    @Override
    public List<LineItem> getBillingHistory(String cust, Date startDate, Date endDate, Integer startPage,
            Integer pageSize) throws JSONException {

        List<LineItem> history = new ArrayList<LineItem>();

        try {
            //csv file containing data
            String strFile = directory + "h_" + cust + ".csv";
            DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy h:mm");

            //create BufferedReader to read csv file
            BufferedReader br = new BufferedReader(new FileReader(strFile));
            String strLine = "";
            int lineNumber = 0, tokenNumber = 0;

            //read comma separated file line by line
            while ((strLine = br.readLine()) != null) {

                if (strLine.startsWith("$")) {
                    continue;
                }

                lineNumber++;

                if (startPage >= 1 && lineNumber < startPage) {
                    continue;
                }

                if (startPage >= 1 && lineNumber >= startPage + pageSize) {
                    break;
                }

                //break comma separated line using ","
                String[] splitted = strLine.split(",");
                tokenNumber = 0;

                LineItem l = new LineItem();

                l.setRowId(Integer.parseInt(splitted[tokenNumber]));
                tokenNumber++;
                l.setItemID(splitted[tokenNumber]);
                tokenNumber++;
                l.setBillItemNo(splitted[tokenNumber]);
                tokenNumber++;
                l.setBillTo(splitted[tokenNumber]);
                tokenNumber++;
                tokenNumber++; // account

                l.setOrderLine(splitted[tokenNumber]);
                tokenNumber++;
                l.setOrderNo(splitted[tokenNumber]);
                tokenNumber++;
                l.setEventType(splitted[tokenNumber]);
                tokenNumber++;
                l.setChargeType(splitted[tokenNumber]);
                tokenNumber++;
                l.setCurrency(splitted[tokenNumber]);
                tokenNumber++;
                l.setCreatedDate(formatter.parse(splitted[tokenNumber]));
                tokenNumber++;

                Date d = l.getCreatedDate();
                if (d != null && startDate.after(formatter.parse("01/01/1990 00:00"))
                        && endDate.after(formatter.parse("01/01/1990 00:00"))) {
                    if (d.before(startDate) || d.after(endDate)) {
                        lineNumber--;
                        continue;
                    }
                }

                l.setBillDate(formatter.parse(splitted[tokenNumber]));
                tokenNumber++;
                l.setDueDate(formatter.parse(splitted[tokenNumber]));
                tokenNumber++;
                l.setStatus(Integer.parseInt(splitted[tokenNumber]));
                tokenNumber++;
                l.setReasonCode(splitted[tokenNumber]);
                tokenNumber++;
                l.setItemTotal(new BigDecimal(splitted[tokenNumber]));
                tokenNumber++;
                l.setItemDue(new BigDecimal(splitted[tokenNumber]));
                tokenNumber++;
                l.setItemDisputed(new BigDecimal(splitted[tokenNumber]));
                tokenNumber++;
                l.setBaseAmount(new BigDecimal(splitted[tokenNumber]));
                tokenNumber++;
                l.setTaxAmount(new BigDecimal(splitted[tokenNumber]));
                tokenNumber++;
                l.setItemDescription(splitted[tokenNumber]);
                tokenNumber++;
                l.setItemCode(splitted[tokenNumber]);
                tokenNumber++;
                l.setLicense(splitted[tokenNumber]);
                tokenNumber++;
                l.setPayType(splitted[tokenNumber]);
                tokenNumber++;
                l.setPayDescription(splitted[tokenNumber]);
                tokenNumber++;
                l.setPayAccountType(splitted[tokenNumber]);
                tokenNumber++;
                l.setpSON(splitted[tokenNumber]);
                tokenNumber++;
                l.setQuantity(Integer.parseInt(splitted[tokenNumber]));
                tokenNumber++;
                history.add(l);

            }

            br.close();

        } catch (Exception e) {
            System.out.println("Exception while reading csv file:  " + e);
            throw JSONException.noDataFound("Bad file read " + e.getMessage());

        }

        if (history == null || history.isEmpty()) {
            throw JSONException.noDataFound("Null set returned - no data found");
        }

        return history;
    }

    /**
     * getCustomerInfo
     * <p/>
     * <p/>
     * <b>DATABASE PROCEDURE:</b>
     *  
     * @code
     *  FUNCTION fn_get_customer
     *  (
     *    customer     IN VARCHAR2,
     *    bill_item_no IN VARCHAR2,
     *    order_no     IN VARCHAR2,
     *    pson         IN VARCHAR2
     *  )
     *  RETURN ref_cursor;
     * @endcode
     * <p/>
     * <b>DATABASE RESULT SET:</b>
     * <ul>
     *    <li>ACCOUNT_NO,</li>
     *    <li>FIRST_NAME,</li>
     *    <li>LAST_NAME,</li>
     *    <li>COMPANY,</li>
     *    <li>PHONE,</li>
     *    <li>ADDRESS,</li>
     *    <li>CITY,</li>
      *    <li>STATE,</li>
     *    <li>ZIP,</li>
     *    <li>COUNTRY </li>
     *  </ul>
     *  
     * @param customer - The Customer.accountNo of the customer we want to find
     * @param billNo -  A bill number (e.g. B1-1111) OR bill line item number (e.g. B1-111,5) of the customer we want to find  - remove everything after the comma
     * @param orderNo - An order number (e.g. 200000011111) OR order line item number (e.g. 200000011111,5) of the customer we want to find - remove everything after the comma
     * @param pson - A BRM trans_id number (Paymenttech merchant number) of the payment event
     * 
     * @return A  Customer object
     *             c.setAccountNo(rs.getString("ACCOUNT_NO"));
        c.setFirstName(rs.getString("FIRST_NAME"));
        c.setLastName(rs.getString("LAST_NAME"));
        c.setCompany(rs.getString("COMPANY"));
        c.setPhone(rs.getString("PHONE"));
        c.setAddress(rs.getString("ADDRESS"));
        c.setCity(rs.getString("CITY"));
        c.setState(rs.getString("STATE"));
        c.setZip(rs.getString("ZIP"));
        c.setCountry(rs.getString("COUNTRY"));
        
     * 
     */
    @Override
    public Customer getCustomerInfo(String customer, String billNo, String orderNo, String pson)
            throws JSONException {

        Customer c = null;

        try {
            //csv file containing data
            String strFile = directory + "customer.csv";

            //create BufferedReader to read csv file
            BufferedReader br = new BufferedReader(new FileReader(strFile));
            String strLine = "";
            int tokenNumber = 0;

            //read comma separated file line by line
            while ((strLine = br.readLine()) != null) {

                if (strLine.startsWith("$")) {
                    continue;
                }

                //break comma separated line using ","
                String[] splitted = strLine.split(",");
                tokenNumber = 0;

                String accountNo = splitted[tokenNumber];

                if (accountNo != null && accountNo.toLowerCase().equals(customer.toLowerCase())) {

                    c = new Customer();
                    c.setAccountNo(splitted[tokenNumber++]);
                    c.setFirstName(splitted[tokenNumber++]);
                    c.setLastName(splitted[tokenNumber++]);
                    c.setCompany(splitted[tokenNumber++]);
                    c.setPhone(splitted[tokenNumber++]);
                    c.setAddress(splitted[tokenNumber++]);
                    c.setCity(splitted[tokenNumber++]);
                    c.setState(splitted[tokenNumber++]);
                    c.setZip(splitted[tokenNumber++]);
                    c.setCountry(splitted[tokenNumber++]);
                    break;
                }
            }

            br.close();

        } catch (Exception e) {
            System.out.println("Exception while reading csv file:  " + e);
            throw JSONException.noDataFound("Bad file read " + e.getMessage());

        }

        if (c == null) {
            throw JSONException.noDataFound("Null set returned - no data found");
        }

        return c;
    }

    /**
     * getCustomerList
     * 
     * <p/>
     * <p/>
     * <b>DATABASE PROCEDURE:</b>
     *  
     * @code
     *FUNCTION fn_search_customers
     * (
     *    phone      IN VARCHAR2,
     *    first_name IN VARCHAR2,
     *    last_name  IN VARCHAR2,
     *    company    IN VARCHAR2,
     *    cc_num     IN VARCHAR2,
     *    eft_num    IN VARCHAR2,
     *    records    IN INTEGER
     *  )
     *  RETURN ref_cursor;
     * @endcode
     *  
     * <p/>
     * <b>DATABASE RESULT SET:</b>
     * <ul>
     *    <li>ACCOUNT_NO,</li>
     *    <li>FIRST_NAME,</li>
     *    <li>LAST_NAME,</li>
     *    <li>COMPANY,</li>
     *    <li>PHONE,</li>
     *    <li>ADDRESS,</li>
     *    <li>CITY,</li>
      *    <li>STATE,</li>
     *    <li>ZIP,</li>
     *    <li>COUNTRY </li>
     *  </ul>
     *  
     * @param phone - The customer's phone number
     * @param firstName -  A wild-carded first name
     * @param lastName -  A wild-carded last name
     * @param company -  A wild-carded company name
     * @param ccNum -  A four digit last-four of a credit card
     * @param eftNum -  A four digit last-four of a bank account number
     * @param pageSize  :  How many records to retrieve 
     * 
     * @return A list of Customer objects in lastname, company alphabetical order
     *         - if rows returned is greater than pageSize will not return TOO MANY rows erros
     * 
     */
    @Override
    public List<Customer> getCustomerList(String phone, String firstName, String lastName, String company,
            String ccNum, String eftNum, Integer pageSize)

            throws JSONException {

        Integer startPage = 1;
        List<Customer> customers = new ArrayList<Customer>();

        try {
            //csv file containing data
            String strFile = directory + "customer.csv";

            //create BufferedReader to read csv file
            BufferedReader br = new BufferedReader(new FileReader(strFile));
            String strLine = "";
            int lineNumber = 0, tokenNumber = 0;

            //read comma separated file line by line
            while ((strLine = br.readLine()) != null) {

                if (strLine.startsWith("$")) {
                    continue;
                }

                lineNumber++;

                if (startPage >= 1 && lineNumber < startPage) {
                    continue;
                }

                if (startPage >= 1 && pageSize > 0 && lineNumber >= startPage + pageSize) {
                    break;
                }

                // break comma separated line using ","
                String[] splitted = strLine.split(",");
                tokenNumber = 0;

                Customer c = new Customer();
                boolean vote = false;

                c.setAccountNo(splitted[tokenNumber++]);
                c.setFirstName(splitted[tokenNumber++]);
                if (c.getFirstName() != null && !c.getFirstName().isEmpty() && firstName != null
                        && !firstName.isEmpty()
                        && c.getFirstName().toLowerCase().contains(firstName.toLowerCase())) {
                    vote = true;
                }

                c.setLastName(splitted[tokenNumber++]);
                if (c.getLastName() != null && !c.getLastName().isEmpty() && lastName != null && !lastName.isEmpty()
                        && c.getLastName().toLowerCase().contains(lastName.toLowerCase())) {
                    vote = true;
                }

                c.setCompany(splitted[tokenNumber++]);
                if (c.getCompany() != null && !c.getCompany().isEmpty() && company != null && !company.isEmpty()
                        && c.getCompany().toLowerCase().contains(company.toLowerCase())) {
                    vote = true;
                }
                if (!vote) {
                    continue;
                }

                c.setPhone(splitted[tokenNumber++]);
                c.setAddress(splitted[tokenNumber++]);
                c.setCity(splitted[tokenNumber++]);
                c.setState(splitted[tokenNumber++]);
                c.setZip(splitted[tokenNumber++]);
                c.setCountry(splitted[tokenNumber++]);
                customers.add(c);

            }

            br.close();

        } catch (Exception e) {
            System.out.println("Exception while reading csv file:  " + e);
            throw JSONException.noDataFound("Bad file read " + e.getMessage());

        }

        if (customers == null || customers.isEmpty()) {
            throw JSONException.noDataFound("Null set returned - no data found");
        }

        return customers;
    }

    /**
     * PaymentInfoCC
     * 
     * <p/>
     * <p/>
     * <b>DATABASE PROCEDURE:</b>
     *  
     * @code
     *FUNCTION fn_get_payinfo_cc
     * (
     *    item_no      IN VARCHAR2
     *  )
     *  RETURN ref_cursor;
     * @endcode
     *  
     * <p/>
     * <b>DATABASE RESULT SET:</b>
     * <ul>
     *    <li>BILLING_PROFILE_ID,</li>
     *    <li>BDOM,</li>
     *    <li>PAYINFO_NAME,</li>
     *    <li>CC_NUMBER,</li>
     *    <li>EXPIRE_MM,</li>
     *    <li>EXPIRE_YYYY,</li>
     *  </ul>
     *  
     * @param itemNo - The item number (e.g. P1-111)of the item we want payment info for
     * 
     * @return A single Payment Info record
     * 
     * TODO 
     * Decide how to determine the card type from the token
     * 
     */
    @Override
    public PaymentInfoCC getPayinfoCC(String itemNo) throws JSONException {
        // TODO Auto-generated method stub

        PaymentInfoCC c = null;

        try {
            //csv file containing data
            String strFile = directory + "payinfocc.csv";

            //create BufferedReader to read csv file
            BufferedReader br = new BufferedReader(new FileReader(strFile));
            String strLine = "";
            int tokenNumber = 0;

            //read comma separated file line by line
            while ((strLine = br.readLine()) != null) {

                if (strLine.startsWith("$")) {
                    continue;
                }

                //break comma separated line using ","
                String[] splitted = strLine.split(",");
                tokenNumber = 0;

                String matchNo = splitted[tokenNumber++];

                if (matchNo != null && matchNo.toLowerCase().equals(itemNo.toLowerCase())) {

                    c = new PaymentInfoCC();
                    c.setBillingProfile(splitted[tokenNumber++]);
                    c.setCardholderName(splitted[tokenNumber++]);
                    c.setCcNumber(splitted[tokenNumber++]);
                    c.setExpiryMonth(splitted[tokenNumber++]);
                    c.setExpiryYear(splitted[tokenNumber++]);
                    c.setProfileBdom(Integer.parseInt(splitted[tokenNumber++]));
                    break;
                }
            }

            br.close();

        } catch (Exception e) {
            System.out.println("Exception while reading csv file:  " + e);
            throw JSONException.noDataFound("Bad file read " + e.getMessage());

        }

        if (c == null) {
            throw JSONException.noDataFound("Null set returned - no data found");
        }

        return c;
    }

    /**
     * PaymentInfoEFT
     * 
     * <p/>
     * <p/>
     * <b>DATABASE PROCEDURE:</b>
     *  
     * @code
     *FUNCTION fn_get_payinfo_eft
     * (
     *    item_no      IN VARCHAR2
     *  )
     *  RETURN ref_cursor
     * @endcode
     * <p/>
     * <b>DATABASE RESULT SET:</b>
     * <ul>
     *    <li>BILLING_PROFILE_ID,</li>
     *    <li>BDOM,</li>
     *    <li>PAYINFO_NAME,</li>
     *    <li>BANK_ACCOUNT_NO,</li>
     *    <li>BANK_NUMBER,</li>
     *  </ul>
     *  
     * @param itemNo - The item number (e.g. P1-111)of the item we want payment info for
     * 
     * @return A single Payment Info record
     * 
     */
    @Override
    public PaymentInfoEFT getPayinfoEFT(String itemNo) throws JSONException {

        PaymentInfoEFT c = null;

        try {
            //csv file containing data
            String strFile = directory + "payinfoeft.csv";

            //create BufferedReader to read csv file
            BufferedReader br = new BufferedReader(new FileReader(strFile));
            String strLine = "";
            int tokenNumber = 0;

            //read comma separated file line by line
            while ((strLine = br.readLine()) != null) {

                if (strLine.startsWith("$")) {
                    continue;
                }

                //break comma separated line using ","
                String[] splitted = strLine.split(",");
                tokenNumber = 0;

                String matchNo = splitted[tokenNumber++];

                if (matchNo != null && matchNo.toLowerCase().equals(itemNo.toLowerCase())) {

                    c = new PaymentInfoEFT();
                    c.setBillingProfile(splitted[tokenNumber++]);
                    c.setCustomerName(splitted[tokenNumber++]);
                    c.setProfileBdom(Integer.parseInt(splitted[tokenNumber++]));
                    c.setBankAccountNumber(splitted[tokenNumber++]);
                    c.setBankNumber(splitted[tokenNumber++]);
                    break;
                }
            }

            br.close();

        } catch (Exception e) {
            System.out.println("Exception while reading csv file:  " + e);
            throw JSONException.noDataFound("Bad file read " + e.getMessage());

        }

        if (c == null) {
            throw JSONException.noDataFound("Null set returned - no data found");
        }

        return c;
    }

    /**
     * PaymentInfoCheck
     * <p/>
     * <p/>
     * <b>DATABASE PROCEDURE:</b>
     *  
     * @code
     *FUNCTION fn_get_payinfo_check
     * (
     *    item_no      IN VARCHAR2
     *  )
     *  RETURN ref_cursor;
     * @endcode
     * <p/>
     * <b>DATABASE RESULT SET:</b>
     * <ul>
     *    <li>BILLING_PROFILE_ID,</li>
     *    <li>BDOM,</li>
     *    <li>PAYINFO_NAME,</li>
     *    <li>NET_TERMS,</li>
     *    <li>CHECK_NO,</li>
     *  </ul>
     *  
     * @param itemNo - The item number (e.g. P1-111)of the item we want payment info for
     * 
     * @return A single Payment Info record
     * 
     */
    @Override
    public PaymentInfoCheck getPayinfoCheck(String itemNo) throws JSONException {

        PaymentInfoCheck c = null;

        try {
            //csv file containing data
            String strFile = directory + "payinfocheck.csv";

            //create BufferedReader to read csv file
            BufferedReader br = new BufferedReader(new FileReader(strFile));
            String strLine = "";
            int tokenNumber = 0;

            //read comma separated file line by line
            while ((strLine = br.readLine()) != null) {

                if (strLine.startsWith("$")) {
                    continue;
                }

                //break comma separated line using ","
                String[] splitted = strLine.split(",");
                tokenNumber = 0;

                String matchNo = splitted[tokenNumber++];

                if (matchNo != null && matchNo.toLowerCase().equals(itemNo.toLowerCase())) {

                    c = new PaymentInfoCheck();
                    c.setBillingProfile(splitted[tokenNumber++]);
                    c.setCustomerName(splitted[tokenNumber++]);
                    c.setProfileBdom(Integer.parseInt(splitted[tokenNumber++]));
                    c.setNetTerms(splitted[tokenNumber++]);
                    c.setCheckNumber(splitted[tokenNumber++]);
                    break;
                }
            }

            br.close();

        } catch (Exception e) {
            System.out.println("Exception while reading csv file:  " + e);
            throw JSONException.noDataFound("Bad file read " + e.getMessage());

        }

        if (c == null) {
            throw JSONException.noDataFound("Null set returned - no data found");
        }

        return c;
    }

    Connection getConnection() throws NamingException, SQLException {
        Context initContext = null;
        Context envContext = null;
        Connection conn = null;
        DataSource ds = null;

        initContext = new InitialContext();
        envContext = (Context) initContext.lookup("java:/comp/env");
        ds = (DataSource) envContext.lookup("jdbc/myoracle");
        conn = ds.getConnection();

        return conn;
    }
}