View Javadoc
1   package org.kuali.ole.deliver.bo;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.apache.log4j.Logger;
5   import org.kuali.ole.OLEConstants;
6   import org.kuali.ole.deliver.processor.LoanProcessor;
7   import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
8   import org.kuali.ole.docstore.common.document.content.instance.Item;
9   import org.kuali.ole.docstore.common.document.content.instance.OleHoldings;
10  import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
11  import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
12  
13  import org.kuali.ole.sys.context.SpringContext;
14  import org.kuali.rice.krad.service.BusinessObjectService;
15  import org.kuali.rice.krad.service.KRADServiceLocator;
16  
17  import java.util.*;
18  
19  /**
20   * Created with IntelliJ IDEA.
21   * User: ?
22   * Date: 10/18/12
23   * Time: 11:18 AM
24   * To change this template use File | Settings | File Templates.
25   */
26  public class ItemBillHelperService {
27  
28      private static final Logger LOG = Logger.getLogger(org.kuali.ole.deliver.bo.ItemBillHelperService.class);
29      private BusinessObjectService businessObjectService;
30      private DocstoreClientLocator docstoreClientLocator;
31  
32      public DocstoreClientLocator getDocstoreClientLocator() {
33  
34          if (docstoreClientLocator == null) {
35              docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
36  
37          }
38          return docstoreClientLocator;
39      }
40  
41      /**
42       * Gets the businessObjectService attribute.
43       *
44       * @return Returns the businessObjectService
45       */
46      private BusinessObjectService getBusinessObjectService() {
47          if (null == businessObjectService) {
48              businessObjectService = KRADServiceLocator.getBusinessObjectService();
49          }
50          return businessObjectService;
51      }
52  
53      /**
54       * This method will retrieve  FeeType object and iterate it  and set to item bill for differencating paid and unpaid bills
55       *
56       * @return Returns the feeTypeList
57       */
58  
59      public List<FeeType> getItemBillDetails(String itemBarcode) {
60          LOG.debug("Initialized getItemBillDetails Method");
61          Map itemBarcodeMap = new HashMap();
62          itemBarcodeMap.put("itemBarcode", itemBarcode);
63          List<FeeType> feeTypeList = (List<FeeType>) KRADServiceLocator.getBusinessObjectService().findMatching(FeeType.class, itemBarcodeMap);
64          if (feeTypeList == null) {
65              return null;
66          }
67          return sortById(feeTypeList);
68      }
69  
70      public List<FeeType> sortById(List<FeeType> feeTypes) {
71          Collections.sort(feeTypes, new Comparator<FeeType>() {
72              public int compare(FeeType feeType1, FeeType feeType2) {
73                  return Integer.parseInt(feeType1.getBillNumber()) > Integer.parseInt(feeType2.getBillNumber()) ? 1 : -1;
74              }
75          });
76          List<FeeType> outFeeTypes = new ArrayList<FeeType>();
77          List<FeeType> partFeeTypes = new ArrayList<FeeType>();
78          List<FeeType> restFeeTypes = new ArrayList<FeeType>();
79          List<FeeType> categorizedFeeTypes = new ArrayList<FeeType>();
80  
81          for (FeeType feeType : feeTypes) {
82              if (feeType.getPaymentStatusCode().equalsIgnoreCase(OLEConstants.PAY_STATUS_OUTSTANDING_CODE)) {
83                  outFeeTypes.add(feeType);
84              } else if (feeType.getPaymentStatusCode().equalsIgnoreCase(OLEConstants.PAY_STATUS_PART_CODE)) {
85                  partFeeTypes.add(feeType);
86              } else {
87                  restFeeTypes.add(feeType);
88              }
89          }
90          categorizedFeeTypes.addAll(outFeeTypes);
91          categorizedFeeTypes.addAll(partFeeTypes);
92          categorizedFeeTypes.addAll(restFeeTypes);
93  
94          return categorizedFeeTypes;
95      }
96  
97  
98      public FeeType getFeeTypeDetails(FeeType feeType) {
99          LoanProcessor loanProcessor = new LoanProcessor();
100         if (feeType != null && feeType.getItemUuid() != null) {
101             try {
102                 org.kuali.ole.docstore.common.document.Item item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(feeType.getItemUuid());
103                 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
104                 Item itemContent = itemOlemlRecordProcessor.fromXML(item.getContent());
105                 OleHoldings oleHoldings = new HoldingOlemlRecordProcessor().fromXML(item.getHolding().getContent());
106                 feeType.setItemUuid(item.getId());
107 
108                 feeType.setItemTitle(item.getHolding().getBib().getTitle());
109                 feeType.setItemAuthor(item.getHolding().getBib().getAuthor());
110                /* if(itemContent.getCallNumber()!=null && !StringUtils.isEmpty(itemContent.getCallNumber().getNumber())){
111                     feeType.setItemCallNumber(loanProcessor.getItemCallNumber(itemContent.getCallNumber()));
112                 }else {
113                     feeType.setItemCallNumber(loanProcessor.getItemCallNumber(oleHoldings.getCallNumber()));
114                 }*/
115                 feeType.setItemCallNumber(loanProcessor.getItemCallNumber(itemContent.getCallNumber(),oleHoldings.getCallNumber()));
116                 feeType.setItemCopyNumber(itemContent.getCopyNumber());
117                 feeType.setItemChronologyOwnLocation(itemContent.getChronology());
118                 feeType.setItemEnumeration(itemContent.getEnumeration());
119                 if(itemContent.getTemporaryItemType()!=null && itemContent.getTemporaryItemType().getCodeValue()!=null){
120                     feeType.setItemType(itemContent.getTemporaryItemType().getCodeValue());
121                 }else{
122                     feeType.setItemType(itemContent.getItemType().getCodeValue());
123                 }
124 
125             } catch (Exception ex) {
126                 ex.printStackTrace();
127             }
128         }
129         return feeType;
130     }
131 }