View Javadoc
1   /*
2    * Copyright 2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.pdp.service.impl;
17  
18  import java.sql.Date;
19  import java.sql.Timestamp;
20  import java.util.Arrays;
21  import java.util.HashMap;
22  import java.util.Iterator;
23  import java.util.List;
24  import java.util.Map;
25  import java.util.TreeMap;
26  
27  import org.apache.commons.lang.StringUtils;
28  import org.kuali.ole.pdp.PdpKeyConstants;
29  import org.kuali.ole.pdp.PdpPropertyConstants;
30  import org.kuali.ole.pdp.businessobject.PaymentGroup;
31  import org.kuali.ole.pdp.businessobject.PaymentProcess;
32  import org.kuali.ole.pdp.dataaccess.PaymentGroupDao;
33  import org.kuali.ole.pdp.service.PaymentGroupService;
34  import org.kuali.ole.sys.DynamicCollectionComparator;
35  import org.kuali.ole.sys.context.SpringContext;
36  import org.kuali.rice.core.api.config.property.ConfigurationService;
37  import org.kuali.rice.core.api.parameter.ParameterEvaluator;
38  import org.kuali.rice.core.api.parameter.ParameterEvaluatorService;
39  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
40  import org.kuali.rice.kns.service.DataDictionaryService;
41  import org.kuali.rice.krad.service.BusinessObjectService;
42  import org.kuali.rice.krad.util.ObjectUtils;
43  import org.springframework.transaction.annotation.Transactional;
44  
45  @Transactional
46  public class PaymentGroupServiceImpl implements PaymentGroupService {
47      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PaymentGroupServiceImpl.class);
48  
49      private PaymentGroupDao paymentGroupDao;
50      private ParameterService parameterService;          
51      private DataDictionaryService dataDictionaryService;            
52      private Map<Integer,ParameterEvaluator> sortGroupSelectionParameters;
53      private BusinessObjectService businessObjectService;
54      
55      public void setPaymentGroupDao(PaymentGroupDao c) {
56          paymentGroupDao = c;
57      }
58  
59      /**
60       * @see org.kuali.ole.pdp.service.PaymentGroupService#getDisbursementNumbersByDisbursementType(java.lang.Integer, java.lang.String)
61       */
62      public List<Integer> getDisbursementNumbersByDisbursementType(Integer pid,String disbursementType) {
63          LOG.debug("getDisbursementNumbersByDisbursementType() started");
64  
65          return paymentGroupDao.getDisbursementNumbersByDisbursementType(pid, disbursementType);
66      }
67  
68      /**
69       * @see org.kuali.ole.pdp.service.PaymentGroupService#getDisbursementNumbersByDisbursementTypeAndBankCode(java.lang.Integer, java.lang.String, java.lang.String)
70       */
71      public List<Integer> getDisbursementNumbersByDisbursementTypeAndBankCode(Integer pid, String disbursementType, String bankCode) {
72          return paymentGroupDao.getDisbursementNumbersByDisbursementTypeAndBankCode(pid, disbursementType, bankCode);
73      }
74  
75      /**
76       * @see org.kuali.ole.pdp.service.PaymentGroupService#getDistinctBankCodesForProcessAndType(java.lang.Integer, java.lang.String)
77       */
78      public List<String> getDistinctBankCodesForProcessAndType(Integer pid, String disbursementType) {
79          return paymentGroupDao.getDistinctBankCodesForProcessAndType(pid, disbursementType);
80      }
81  
82      /**
83       * @see org.kuali.ole.pdp.service.PaymentGroupService#getByDisbursementTypeStatusCode(java.lang.String, java.lang.String)
84       */
85      public Iterator getByDisbursementTypeStatusCode(String disbursementType, String paymentStatusCode) {
86          LOG.debug("getByDisbursementTypeStatusCode() started");
87          
88          Map fieldValues = new HashMap();
89          fieldValues.put(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_DISBURSEMENT_TYPE_CODE, disbursementType);
90          fieldValues.put(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PAYMENT_STATUS_CODE, paymentStatusCode);
91          List paymentGroupList = (List) this.businessObjectService.findMatching(PaymentGroup.class, fieldValues);
92          DynamicCollectionComparator.sort(paymentGroupList, PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_DISBURSEMENT_NBR);
93          
94          return paymentGroupList.iterator();
95      }
96  
97      /**
98       * @see org.kuali.ole.pdp.service.PaymentGroupService#getByProcess(org.kuali.ole.pdp.businessobject.PaymentProcess)
99       */
100     public Iterator getByProcess(PaymentProcess p) {
101         LOG.debug("getByProcess() started");
102         
103         Map fieldValues = new HashMap();
104         fieldValues.put(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PROCESS_ID, p.getId());
105         List paymentGroupList = (List) this.businessObjectService.findMatching(PaymentGroup.class, fieldValues);
106         DynamicCollectionComparator.sort(paymentGroupList, PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_SORT_VALUE, PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_PAYEE_NAME, PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_LINE1_ADDRESS, PdpPropertyConstants.PaymentGroup.NOTES_LINES);
107         
108         return paymentGroupList.iterator();
109     }
110    
111     /**
112      * @see org.kuali.ole.pdp.service.PaymentGroupService#get(java.lang.Integer)
113      */
114     public PaymentGroup get(Integer id) {
115         LOG.debug("get() started");
116         
117         Map primaryKeys = new HashMap();
118         primaryKeys.put(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_ID, id);
119         return (PaymentGroup) this.businessObjectService.findByPrimaryKey(PaymentGroup.class, primaryKeys);
120     }
121 
122     /**
123      * @see org.kuali.ole.pdp.service.PaymentGroupService#getByBatchId(java.lang.Integer)
124      */
125     public List getByBatchId(Integer batchId) {
126         LOG.debug("getByBatchId() started");
127         
128         Map fieldValues = new HashMap();
129         fieldValues.put(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_BATCH_ID, batchId);
130         
131         return (List) this.businessObjectService.findMatching(PaymentGroup.class, fieldValues);
132     }
133 
134     /**
135      * @see org.kuali.ole.pdp.service.PaymentGroupService#getByDisbursementNumber(java.lang.Integer)
136      */
137     public List getByDisbursementNumber(Integer disbursementNbr) {
138         LOG.debug("getByDisbursementNumber() started");
139 
140         Map fieldValues = new HashMap();
141         fieldValues.put(PdpPropertyConstants.PaymentGroup.PAYMENT_GROUP_DISBURSEMENT_NBR, disbursementNbr);
142         
143         return (List) this.businessObjectService.findMatching(PaymentGroup.class, fieldValues);
144     }
145 
146     /**
147      * @see org.kuali.ole.pdp.service.PaymentGroupService#processPaidGroup(org.kuali.ole.pdp.businessobject.PaymentGroup, java.sql.Date)
148      */
149     public void processPaidGroup(PaymentGroup group, Date processDate) {
150         LOG.debug("processPaidGroup() started");
151 
152         Timestamp ts = new Timestamp(processDate.getTime());
153         group.setEpicPaymentPaidExtractedDate(ts);
154         group.setLastUpdate(ts);
155         this.businessObjectService.save(group);
156     }
157 
158     /**
159      * @see org.kuali.ole.pdp.service.PaymentGroupService#processCancelledGroup(org.kuali.ole.pdp.businessobject.PaymentGroup,
160      *      java.sql.Date)
161      */
162     public void processCancelledGroup(PaymentGroup group, Date processDate) {
163         LOG.debug("processCancelledGroup() started");
164 
165         Timestamp ts = new Timestamp(processDate.getTime());
166         group.setEpicPaymentCancelledExtractedDate(ts);
167         group.setLastUpdate(ts);
168         this.businessObjectService.save(group);
169     }
170     
171     /**
172      * @see org.kuali.ole.pdp.service.PaymentGroupService#setParameterService(org.kuali.ole.sys.service.ParameterService)
173      */
174     public void setParameterService(ParameterService parameterService) {
175         this.parameterService = parameterService;
176     }
177     
178     /**
179      * @see org.kuali.ole.pdp.service.PaymentGroupService#getSortGroupId(org.kuali.ole.pdp.businessobject.PaymentGroup)
180      */
181     public int getSortGroupId(PaymentGroup paymentGroup) {      
182         String DEFAULT_SORT_GROUP_ID_PARAMETER = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(PdpKeyConstants.DEFAULT_SORT_GROUP_ID_PARAMETER);
183 
184         for (Integer sortGroupId : getSortGroupSelectionParameters().keySet()) {         
185             List<String> parameterValues = Arrays.asList(StringUtils.substringAfter(getSortGroupSelectionParameters().get(sortGroupId).getValue(), "=").split(";"));         
186             String constrainedValue = String.valueOf(ObjectUtils.getPropertyValue(paymentGroup, StringUtils.substringBefore(getSortGroupSelectionParameters().get(sortGroupId).getValue(), "=")));           
187             if ((getSortGroupSelectionParameters().get(sortGroupId).constraintIsAllow() && parameterValues.contains(constrainedValue))           
188                 || (!getSortGroupSelectionParameters().get(sortGroupId).constraintIsAllow() && !parameterValues.contains(constrainedValue))) {           
189                     return sortGroupId;         
190             }           
191         }
192         
193         return new Integer(parameterService.getParameterValueAsString(PaymentGroup.class, DEFAULT_SORT_GROUP_ID_PARAMETER));            
194     }       
195        
196     /**
197      * @see org.kuali.ole.pdp.service.PaymentGroupService#getSortGroupName(int)
198      */
199     public String getSortGroupName(int sortGroupId) {      
200         String DEFAULT_SORT_GROUP_ID_PARAMETER = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(PdpKeyConstants.DEFAULT_SORT_GROUP_ID_PARAMETER);
201 
202         if ((sortGroupId + "").equals(parameterService.getParameterValueAsString(PaymentGroup.class, DEFAULT_SORT_GROUP_ID_PARAMETER))) {           
203             return SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(PdpKeyConstants.DEFAULT_GROUP_NAME_OTHER);         
204         }       
205         
206         return dataDictionaryService.getAttributeLabel(PaymentGroup.class, StringUtils.substringBefore(getSortGroupSelectionParameters().get(sortGroupId).getValue(), "="));         
207     } 
208     
209     /**
210      * @see org.kuali.ole.pdp.service.PaymentGroupService#getAchPaymentsNeedingAdviceNotification()
211      */
212     public List<PaymentGroup> getAchPaymentsNeedingAdviceNotification() {
213         return this.paymentGroupDao.getAchPaymentsNeedingAdviceNotification();
214     }
215     
216     /**
217      * Gets the sort group parameters
218      * 
219      * @return
220      */
221     protected Map<Integer,ParameterEvaluator> getSortGroupSelectionParameters() {
222         String SORT_GROUP_SELECTION_PARAMETER_PREFIX = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(PdpKeyConstants.SORT_GROUP_SELECTION_PARAMETER_PREFIX);
223         
224         if (sortGroupSelectionParameters == null) {         
225             sortGroupSelectionParameters = new TreeMap<Integer,ParameterEvaluator>();           
226             boolean moreParameters = true;          
227             int i = 1;          
228             while (moreParameters) {            
229                 if (parameterService.parameterExists(PaymentGroup.class, SORT_GROUP_SELECTION_PARAMETER_PREFIX + i)) {          
230                     sortGroupSelectionParameters.put(i, /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(PaymentGroup.class, SORT_GROUP_SELECTION_PARAMETER_PREFIX + i, null));           
231                     i++;            
232                 }           
233                 else {          
234                     moreParameters = false;         
235                 }           
236             }           
237         } 
238         
239         return sortGroupSelectionParameters;            
240     }
241 
242     public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
243         this.dataDictionaryService = dataDictionaryService;
244     }
245     
246     /**
247      * Sets the business object service
248      * 
249      * @param businessObjectService
250      */
251     public void setBusinessObjectService(BusinessObjectService businessObjectService) {
252         this.businessObjectService = businessObjectService;
253     }
254 }