View Javadoc
1   package org.kuali.ole.deliver.service;
2   
3   import org.apache.commons.collections.CollectionUtils;
4   import org.apache.log4j.Logger;
5   import org.kuali.ole.OLEConstants;
6   import org.kuali.ole.deliver.bo.FeeType;
7   import org.kuali.ole.deliver.bo.OleFeeType;
8   import org.kuali.ole.deliver.bo.OleLoanDocument;
9   import org.kuali.rice.core.api.util.type.KualiDecimal;
10  import org.kuali.rice.krad.service.KRADServiceLocator;
11  
12  import java.util.HashMap;
13  import java.util.List;
14  import java.util.Map;
15  
16  /**
17   * Created by Palanivelrajanb on 7/7/2015.
18   */
19  public class PatronBillResolver {
20  
21      private static final Logger LOG = Logger.getLogger(PatronBillResolver.class);
22  
23      public void checkReplacementFineExistForPatron(OleLoanDocument oleLoanDocument,String patronId) {
24          Map<String, String> map = new HashMap<String, String>();
25          map.put(OLEConstants.ITEM_BARCODE, oleLoanDocument.getItemId());
26          map.put(OLEConstants.FEE_TYPE_FIELD, getOleFeeTypeCode(OLEConstants.FEE_TYPE_CODE_REPL_FEE));
27          List<FeeType> feeTypes = (List<FeeType>) KRADServiceLocator.getBusinessObjectService().findMatching(FeeType.class, map);
28          if (feeTypes != null && feeTypes.size() > 0) {
29              for(FeeType feeType:feeTypes){
30                  if(feeType.getBalFeeAmount().isGreaterThan(new KualiDecimal(0.00)) && feeType.getPatronBillPayment()!=null &&
31                          feeType.getPatronBillPayment().getPatronId().equals(patronId)){
32                      oleLoanDocument.setReplacementFeeExist(true);
33                      oleLoanDocument.setBillName(OLEConstants.REPLACEMENT_FEE);
34                      break;
35                  }
36              }
37          }
38      }
39  
40      private String getOleFeeTypeCode(String typeCode){
41          Map<String, String> map = new HashMap<String, String>();
42          map.put(OLEConstants.FEE_TYPE_CODE, typeCode);
43          List<OleFeeType> feeTypes = (List<OleFeeType>) KRADServiceLocator.getBusinessObjectService().findMatching(OleFeeType.class, map);
44          if(CollectionUtils.isNotEmpty(feeTypes)){
45              return feeTypes.get(0).getFeeTypeId();
46          }
47          return "";
48      }
49  
50      public void checkReplacementFineExist(OleLoanDocument oleLoanDocument) {
51          Map<String, String> map = new HashMap<String, String>();
52          map.put(OLEConstants.ITEM_BARCODE, oleLoanDocument.getItemId());
53          map.put(OLEConstants.FEE_TYPE_FIELD, getOleFeeTypeCode(OLEConstants.FEE_TYPE_CODE_REPL_FEE));
54          List<FeeType> feeTypes = (List<FeeType>) KRADServiceLocator.getBusinessObjectService().findMatching(FeeType.class, map);
55          oleLoanDocument.setFeeType(feeTypes);
56          if (feeTypes != null && feeTypes.size() > 0) {
57              for(FeeType feeType:feeTypes){
58                  if(feeType.getBalFeeAmount().isGreaterThan(new KualiDecimal(0.00))){
59                      oleLoanDocument.setReplacementFeeExist(true);
60                      break;
61                  }
62              }
63          }
64      }
65  
66      public void checkOverdueExist(OleLoanDocument oleLoanDocument) {
67          Map<String, String> map = new HashMap<String, String>();
68          map.put(OLEConstants.ITEM_BARCODE, oleLoanDocument.getItemId());
69          map.put(OLEConstants.FEE_TYPE_FIELD, getOleFeeTypeCode(OLEConstants.FEE_TYPE_CODE_OVERDUE));
70          List<FeeType> feeTypes = (List<FeeType>) KRADServiceLocator.getBusinessObjectService().findMatching(FeeType.class, map);
71          if (feeTypes != null && feeTypes.size() > 0) {
72              for (FeeType feeType : feeTypes) {
73                  if (feeType.getBalFeeAmount().compareTo(OLEConstants.KUALI_BIGDECIMAL_DEF_VALUE) != 0) {
74                      oleLoanDocument.setOverdueFineExist(true);
75                      break;
76                  }
77              }
78          }
79      }
80  
81  }