Search in sources :

Example 16 with CustomerProfile

use of org.kuali.kfs.pdp.businessobject.CustomerProfile in project cu-kfs by CU-CommunityApps.

the class CuFormatServiceImpl method startFormatProcess.

@Override
public FormatProcessSummary startFormatProcess(Person user, String campus, List<CustomerProfile> customers, Date paydate, String paymentTypes, String paymentDistribution) {
    LOG.debug("startFormatProcess() started");
    for (CustomerProfile element : customers) {
        LOG.debug("startFormatProcess() Customer: " + element);
    }
    // Create the process
    Date d = new Date();
    PaymentProcess paymentProcess = new PaymentProcess();
    paymentProcess.setCampusCode(campus);
    paymentProcess.setProcessUser(user);
    paymentProcess.setProcessTimestamp(new Timestamp(d.getTime()));
    this.businessObjectService.save(paymentProcess);
    // add an entry in the format process table (to lock the format process)
    FormatProcess formatProcess = new FormatProcess();
    formatProcess.setPhysicalCampusProcessCode(campus);
    formatProcess.setBeginFormat(dateTimeService.getCurrentTimestamp());
    formatProcess.setPaymentProcIdentifier(paymentProcess.getId().intValue());
    this.businessObjectService.save(formatProcess);
    Timestamp now = new Timestamp((new Date()).getTime());
    java.sql.Date sqlDate = new java.sql.Date(paydate.getTime());
    Calendar c = Calendar.getInstance();
    c.setTime(sqlDate);
    c.set(Calendar.HOUR, 11);
    c.set(Calendar.MINUTE, 59);
    c.set(Calendar.SECOND, 59);
    c.set(Calendar.MILLISECOND, 59);
    c.set(Calendar.AM_PM, Calendar.PM);
    Timestamp paydateTs = new Timestamp(c.getTime().getTime());
    LOG.debug("startFormatProcess() last update = " + now);
    LOG.debug("startFormatProcess() entered paydate = " + paydate);
    LOG.debug("startFormatProcess() actual paydate = " + paydateTs);
    PaymentStatus format = this.businessObjectService.findBySinglePrimaryKey(PaymentStatus.class, PdpConstants.PaymentStatusCodes.FORMAT);
    List customerIds = new ArrayList();
    for (Iterator iter = customers.iterator(); iter.hasNext(); ) {
        CustomerProfile element = (CustomerProfile) iter.next();
        customerIds.add(element.getId());
    }
    // Mark all of them ready for format
    Iterator groupIterator = ((CuFormatPaymentDao) formatPaymentDao).markPaymentsForFormat(customerIds, paydateTs, paymentTypes, paymentDistribution);
    while (groupIterator.hasNext()) {
        PaymentGroup paymentGroup = (PaymentGroup) groupIterator.next();
        paymentGroup.setLastUpdatedTimestamp(paydateTs);
        paymentGroup.setPaymentStatus(format);
        paymentGroup.setProcess(paymentProcess);
        businessObjectService.save(paymentGroup);
    }
    // summarize them
    FormatProcessSummary preFormatProcessSummary = new FormatProcessSummary();
    Iterator<PaymentGroup> iterator = this.paymentGroupService.getByProcess(paymentProcess);
    while (iterator.hasNext()) {
        PaymentGroup paymentGroup = iterator.next();
        preFormatProcessSummary.add(paymentGroup);
    }
    // if no payments found for format clear the format process
    if (preFormatProcessSummary.getProcessSummaryList().size() == 0) {
        LOG.debug("startFormatProcess() No payments to process.  Format process ending");
        // ?? maybe call end format process
        clearUnfinishedFormat(paymentProcess.getId().intValue());
    }
    return preFormatProcessSummary;
}
Also used : PaymentGroup(org.kuali.kfs.pdp.businessobject.PaymentGroup) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) CustomerProfile(org.kuali.kfs.pdp.businessobject.CustomerProfile) FormatProcess(org.kuali.kfs.pdp.businessobject.FormatProcess) Timestamp(java.sql.Timestamp) Date(java.util.Date) PaymentProcess(org.kuali.kfs.pdp.businessobject.PaymentProcess) FormatProcessSummary(org.kuali.kfs.pdp.businessobject.FormatProcessSummary) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) CuFormatPaymentDao(edu.cornell.kfs.pdp.dataaccess.CuFormatPaymentDao) PaymentStatus(org.kuali.kfs.pdp.businessobject.PaymentStatus)

Example 17 with CustomerProfile

use of org.kuali.kfs.pdp.businessobject.CustomerProfile in project cu-kfs by CU-CommunityApps.

the class CuPaymentFileServiceImpl method getCustomerProfileFromUnparsableFile.

/**
 * @param incomingFileName
 * @param paymentFile
 * @return
 */
private PaymentFileLoad getCustomerProfileFromUnparsableFile(String incomingFileName, PaymentFileLoad paymentFile) {
    FileInputStream exFileContents;
    try {
        exFileContents = new FileInputStream(incomingFileName);
    } catch (FileNotFoundException e1) {
        LOG.error("file to load not found " + incomingFileName, e1);
        throw new RuntimeException("Cannot find the file requested to be loaded " + incomingFileName, e1);
    }
    try {
        InputStreamReader inputReader = new InputStreamReader(exFileContents);
        BufferedReader bufferedReader = new BufferedReader(inputReader);
        String line = "";
        boolean found = false;
        String chartVal = "";
        String unitVal = "";
        String subUnitVal = "";
        while (!found && (line = bufferedReader.readLine()) != null) {
            // Use multiple ifs instead of else/ifs because all values could occur on the same line.
            if (StringUtils.contains(line, CUPdpConstants.CustomerProfilePrimaryKeyTags.CHART_OPEN)) {
                chartVal = StringUtils.substringBetween(line, CUPdpConstants.CustomerProfilePrimaryKeyTags.CHART_OPEN, CUPdpConstants.CustomerProfilePrimaryKeyTags.CHART_CLOSE);
            }
            if (StringUtils.contains(line, CUPdpConstants.CustomerProfilePrimaryKeyTags.UNIT_OPEN)) {
                unitVal = StringUtils.substringBetween(line, CUPdpConstants.CustomerProfilePrimaryKeyTags.UNIT_OPEN, CUPdpConstants.CustomerProfilePrimaryKeyTags.UNIT_CLOSE);
            }
            if (StringUtils.contains(line, CUPdpConstants.CustomerProfilePrimaryKeyTags.SUBUNIT_OPEN)) {
                subUnitVal = StringUtils.substringBetween(line, CUPdpConstants.CustomerProfilePrimaryKeyTags.SUBUNIT_OPEN, CUPdpConstants.CustomerProfilePrimaryKeyTags.SUBUNIT_CLOSE);
                found = true;
            }
        }
        if (found) {
            // Note: the pdpEmailServiceImpl doesn't actually use the customer object from the paymentFile, but rather retrieves an instance using
            // the values provided for chart, unit and sub_unit.  However, it doesn't make sense to even populate the paymentFile object if
            // the values retrieved don't map to a valid customer object, so we will retrieve the object here to validate the values.
            CustomerProfile customer = customerProfileService.get(chartVal, unitVal, subUnitVal);
            if (ObjectUtils.isNotNull(customer)) {
                if (ObjectUtils.isNull(paymentFile)) {
                    paymentFile = new PaymentFileLoad();
                }
                paymentFile.setChart(chartVal);
                paymentFile.setUnit(unitVal);
                paymentFile.setSubUnit(subUnitVal);
                paymentFile.setCustomer(customer);
            }
        }
    } catch (Exception ex) {
        LOG.error("Attempts to retrieve the customer profile from the unparsable XML file failed with the following error.", ex);
    } finally {
        try {
            exFileContents.close();
        } catch (IOException io) {
            LOG.error("File stream object could not be closed.", io);
        }
    }
    return paymentFile;
}
Also used : InputStreamReader(java.io.InputStreamReader) FileNotFoundException(java.io.FileNotFoundException) BufferedReader(java.io.BufferedReader) CustomerProfile(org.kuali.kfs.pdp.businessobject.CustomerProfile) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) PaymentFileLoad(org.kuali.kfs.pdp.businessobject.PaymentFileLoad) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParseException(org.kuali.kfs.sys.exception.ParseException)

Aggregations

CustomerProfile (org.kuali.kfs.pdp.businessobject.CustomerProfile)17 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 PaymentDetail (org.kuali.kfs.pdp.businessobject.PaymentDetail)6 KualiInteger (org.kuali.rice.core.api.util.type.KualiInteger)6 IOException (java.io.IOException)5 PaymentGroup (org.kuali.kfs.pdp.businessobject.PaymentGroup)5 DateTimeService (org.kuali.rice.core.api.datetime.DateTimeService)4 Person (org.kuali.rice.kim.api.identity.Person)4 BufferedWriter (java.io.BufferedWriter)3 FileWriter (java.io.FileWriter)3 Timestamp (java.sql.Timestamp)3 SimpleDateFormat (java.text.SimpleDateFormat)3 List (java.util.List)3 FormatProcessSummary (org.kuali.kfs.pdp.businessobject.FormatProcessSummary)3 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)3 Date (java.sql.Date)2 Calendar (java.util.Calendar)2 Iterator (java.util.Iterator)2 AccountingPeriod (org.kuali.kfs.coa.businessobject.AccountingPeriod)2