001/*
002 * Copyright 2007 The Kuali Foundation
003 * 
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * 
008 * http://www.opensource.org/licenses/ecl2.php
009 * 
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.ole.pdp.service.impl;
017
018import java.util.HashMap;
019import java.util.Iterator;
020import java.util.List;
021import java.util.Map;
022
023import org.kuali.ole.pdp.PdpPropertyConstants;
024import org.kuali.ole.pdp.businessobject.PaymentDetail;
025import org.kuali.ole.pdp.dataaccess.PaymentDetailDao;
026import org.kuali.ole.pdp.service.PaymentDetailService;
027import org.kuali.ole.sys.DynamicCollectionComparator;
028import org.kuali.ole.sys.service.NonTransactional;
029import org.kuali.rice.krad.service.BusinessObjectService;
030
031@NonTransactional
032public class PaymentDetailServiceImpl implements PaymentDetailService {
033    private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PaymentDetailServiceImpl.class);
034
035    private PaymentDetailDao paymentDetailDao;
036    private BusinessObjectService businessObjectService;
037    
038    public void setPaymentDetailDao(PaymentDetailDao c) {
039        paymentDetailDao = c;
040    }
041
042    /**
043     * @see org.kuali.ole.pdp.service.PaymentDetailService#getByDisbursementNumber(java.lang.Integer)
044     */
045    public Iterator getByDisbursementNumber(Integer disbursementNumber) {
046        LOG.debug("getByDisbursementNumber() started");
047        
048        Map fieldValues = new HashMap();
049        fieldValues.put(PdpPropertyConstants.PaymentDetail.PAYMENT_DISBURSEMENT_NUMBER, disbursementNumber);
050        List<PaymentDetail> paymentDetailByDisbursementNumberList= (List<PaymentDetail>)this.businessObjectService.findMatching(PaymentDetail.class, fieldValues);
051        DynamicCollectionComparator.sort(paymentDetailByDisbursementNumberList, PdpPropertyConstants.PaymentDetail.PAYMENT_DISBURSEMENT_FINANCIAL_DOCUMENT_TYPE_CODE, PdpPropertyConstants.PaymentDetail.PAYMENT_DISBURSEMENT_CUST_PAYMENT_DOC_NBR);
052
053        return paymentDetailByDisbursementNumberList.iterator();
054    }
055    
056    /**
057     * Returns all PaymentDetail records with the given disbursement number and a group with the given process id, disbursement type, and bank code
058     * @param disbursementNumber the disbursement number of the payment details to find
059     * @param processId the process id of the payment group of payment details to find
060     * @param disbursementType the disbursement type of the payment group of payment details to find
061     * @param bankCode the bank code of the payment group of payment details to find
062     * @return an iterator of PaymentDetail records matching the given criteria
063     */
064    public Iterator<PaymentDetail> getByDisbursementNumber(Integer disbursementNumber, Integer processId, String disbursementType, String bankCode) {
065        if (LOG.isDebugEnabled()) {
066            LOG.debug("getByDisbursementNumber() started");
067        }
068        
069        Map fieldValues = new HashMap();
070        fieldValues.put(PdpPropertyConstants.PaymentDetail.PAYMENT_DISBURSEMENT_NUMBER, disbursementNumber);
071        fieldValues.put(PdpPropertyConstants.PaymentDetail.PAYMENT_GROUP+"."+PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PROCESS_ID, processId);
072        fieldValues.put(PdpPropertyConstants.PaymentDetail.PAYMENT_GROUP+"."+PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_DISBURSEMENT_TYPE_CODE, disbursementType);
073        fieldValues.put(PdpPropertyConstants.PaymentDetail.PAYMENT_GROUP+"."+PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_BANK_CODE, bankCode);
074        List<PaymentDetail> paymentDetailByDisbursementNumberList= (List<PaymentDetail>)this.businessObjectService.findMatching(PaymentDetail.class, fieldValues);
075        DynamicCollectionComparator.sort(paymentDetailByDisbursementNumberList, PdpPropertyConstants.PaymentDetail.PAYMENT_DISBURSEMENT_FINANCIAL_DOCUMENT_TYPE_CODE, PdpPropertyConstants.PaymentDetail.PAYMENT_DISBURSEMENT_CUST_PAYMENT_DOC_NBR);
076
077        return paymentDetailByDisbursementNumberList.iterator();
078    }
079
080    /**
081     * @see org.kuali.ole.pdp.service.PaymentDetailService#getUnprocessedCancelledDetails(java.lang.String, java.lang.String)
082     */
083    public Iterator getUnprocessedCancelledDetails(String organization, List<String> subUnits) {
084        LOG.debug("getUnprocessedCancelledDetails() started");
085
086        return paymentDetailDao.getUnprocessedCancelledDetails(organization, subUnits);
087    }
088
089    /**
090     * @see org.kuali.ole.pdp.service.PaymentDetailService#getUnprocessedPaidDetails(java.lang.String, java.lang.String)
091     */
092    public Iterator getUnprocessedPaidDetails(String organization, List<String> subUnits) {
093        LOG.debug("getUnprocessedPaidDetails() started");
094
095        return paymentDetailDao.getUnprocessedPaidDetails(organization, subUnits);
096    }
097
098    public void setBusinessObjectService(BusinessObjectService businessObjectService) {
099        this.businessObjectService = businessObjectService;
100    }
101}