View Javadoc

1   package org.kuali.ole.myaccount.renewal.service;
2   
3   import org.apache.log4j.Logger;
4   import org.kuali.ole.deliver.request.api.OleDeliverRequestDefinition;
5   import org.kuali.ole.deliver.request.bo.OleDeliverRequestBo;
6   import org.kuali.ole.deliver.request.service.OleDeliverRequestDocumentHelperServiceImpl;
7   import org.kuali.ole.myaccount.renewal.bo.OlePatronLoanDocument;
8   import org.kuali.ole.myaccount.renewal.bo.OlePatronLoanDocuments;
9   import org.kuali.ole.myaccount.renewal.bo.OleRenewalLoanDocument;
10  import org.kuali.ole.patron.api.OlePatronDefinition;
11  import org.kuali.ole.service.OlePatronService;
12  import org.kuali.ole.service.OlePatronServiceImpl;
13  
14  import java.util.ArrayList;
15  import java.util.List;
16  
17  /**
18   * Created with IntelliJ IDEA.
19   * User: ?
20   * Date: 10/26/12
21   * Time: 7:47 PM
22   * To change this template use File | Settings | File Templates.
23   */
24  public class OleMyAccountProcess {
25  
26      private static final Logger LOG = Logger.getLogger(OleMyAccountProcess.class);
27  
28  
29      public List<OleRenewalLoanDocument> oleRenewalLoanDocumentList;
30      private OlePatronService olePatronService;
31      OleDeliverRequestDocumentHelperServiceImpl service = new OleDeliverRequestDocumentHelperServiceImpl();
32  
33      public OlePatronService getOlePatronService(){
34  
35          if(olePatronService==null)
36              olePatronService=new OlePatronServiceImpl();
37          return olePatronService;
38      }
39  
40      public OleMyAccountProcess(){
41          oleRenewalLoanDocumentList=new ArrayList<OleRenewalLoanDocument>();
42      }
43  
44      /**
45       * this method performs to find the  patron information using by patron id
46       * @param patronId
47       * @return
48       */
49      public OlePatronDefinition getPatronInfo(String patronId){
50          LOG.debug("Inside the getPatronInfo method");
51          OlePatronDefinition olePatronDefinition=getOlePatronService().getPatron(patronId);
52          return olePatronDefinition;
53      }
54  
55      /**
56       * this method performs   to find the patron checkout items by using patron barcode
57       * @param patronBarcode
58       * @return
59       */
60      public List<OleRenewalLoanDocument> getPatronLoanedItems(String patronBarcode){
61          LOG.debug("Inside the getPatronLoanedItems method");
62          OlePatronLoanDocuments olePatronLoanDocuments=getOlePatronService().getPatronLoanedItems(patronBarcode);
63          List<OleRenewalLoanDocument> oleRenewalLoanDocumentList=convertRenewalLoanDocuments(olePatronLoanDocuments);
64          return oleRenewalLoanDocumentList;
65  
66      }
67  
68      public List<OleDeliverRequestDefinition> getPatronRequestItems(String patronId){
69          LOG.debug("Inside the getPatronRequestItems method");
70          List<OleDeliverRequestDefinition> oleDeliverRequestDefinition =getOlePatronService().getPatronRequestItems(patronId);
71          return oleDeliverRequestDefinition;
72  
73      }
74  
75      public void cancelRequest(List<OleDeliverRequestDefinition> oleDeliverRequestDefinition){
76          LOG.debug("Inside the cancelRequest method");
77          for(OleDeliverRequestDefinition oleDeliverRequestDefinitions : oleDeliverRequestDefinition) {
78              OleDeliverRequestBo oleDeliverRequestBo = OleDeliverRequestBo.from(oleDeliverRequestDefinitions);
79              service.cancelDocument(oleDeliverRequestBo);
80          }
81      }
82  
83      /**
84       * this method performs to renewal the itmes
85       * @param oleRenewalLoanDocumentList
86       * @return
87       */
88      public List<OleRenewalLoanDocument> performRenewalItem(List<OleRenewalLoanDocument> oleRenewalLoanDocumentList){
89          LOG.debug("Inside the performRenewalItem method");
90          OlePatronLoanDocuments olePatronLoanDocuments=convertOlePatronLoanDocuments(oleRenewalLoanDocumentList);
91          olePatronLoanDocuments=getOlePatronService().performRenewalItems(olePatronLoanDocuments);
92          oleRenewalLoanDocumentList=null;
93          oleRenewalLoanDocumentList=convertRenewalLoanDocuments(olePatronLoanDocuments);
94          return oleRenewalLoanDocumentList;
95      }
96  
97      /**
98       * this method performs to convert list of OleRenewalLoanDocument to  OlePatronLoanDocuments
99       * @param oleRenewalLoanDocumentList
100      * @return
101      */
102     private  OlePatronLoanDocuments convertOlePatronLoanDocuments(List<OleRenewalLoanDocument> oleRenewalLoanDocumentList){
103         LOG.debug("Inside the convertOlePatronLoanDocuments method");
104         List<OlePatronLoanDocument> olePatronLoanItemList=new ArrayList<OlePatronLoanDocument>();
105         for(int i=0;i<oleRenewalLoanDocumentList.size();i++){
106             OleRenewalLoanDocument oleRenewalLoanDocument= oleRenewalLoanDocumentList.get(i);
107             OlePatronLoanDocument olePatronLoanDocument=OlePatronLoanDocuments.to(oleRenewalLoanDocument);
108             olePatronLoanItemList.add(olePatronLoanDocument);
109         }
110         OlePatronLoanDocuments olePatronLoanDocuments=getOlePatronLoanDocuments(olePatronLoanItemList);
111         return olePatronLoanDocuments;
112     }
113 
114     /**
115      * this method performs to convert  OlePatronLoanDocuments  to  list of OleRenewalLoanDocument
116      * @param olePatronLoanDocuments
117      * @return
118      */
119     private List<OleRenewalLoanDocument>  convertRenewalLoanDocuments(OlePatronLoanDocuments olePatronLoanDocuments){
120         LOG.debug("Inside the convertRenewalLoanDocuments method");
121         List<OleRenewalLoanDocument> oleRenewalLoanDocumentList=new ArrayList<OleRenewalLoanDocument>();
122         if(olePatronLoanDocuments!=null)
123               for(int i=0;i<olePatronLoanDocuments.getOlePatronLoanDocuments().size();i++){
124                 OlePatronLoanDocument olePatronLoanDocument=(OlePatronLoanDocument)olePatronLoanDocuments.getOlePatronLoanDocuments().get(i);
125                 OleRenewalLoanDocument oleRenewalLoanDocument=new OleRenewalLoanDocument();
126                 oleRenewalLoanDocument.setItemBarcode(olePatronLoanDocument.getItemBarcode());
127                 oleRenewalLoanDocument.setCallNumber(olePatronLoanDocument.getCallNumber());
128                 oleRenewalLoanDocument.setDueDate(olePatronLoanDocument.getDueDate());
129                 oleRenewalLoanDocument.setLocation(olePatronLoanDocument.getLocation());
130                 oleRenewalLoanDocument.setTitle(olePatronLoanDocument.getTitle());
131                 oleRenewalLoanDocument.setAuthor(olePatronLoanDocument.getAuthor());
132                 oleRenewalLoanDocument.setMessageInfo(olePatronLoanDocument.getMessageInfo());
133                 oleRenewalLoanDocumentList.add(oleRenewalLoanDocument);
134               }
135         return oleRenewalLoanDocumentList;
136     }
137 
138     /**
139      * this method performs to convert  OlePatronLoanDocument  to  list of OleRenewalLoanDocument
140      * @param olePatronLoanItemList
141      * @return
142      */
143     private OlePatronLoanDocuments  getOlePatronLoanDocuments(List<OlePatronLoanDocument> olePatronLoanItemList) {
144         LOG.debug("Inside the getOlePatronLoanDocuments method");
145         OleRenewalLoanDocument oleRenewalLoanDocument=new OleRenewalLoanDocument();
146         if(olePatronLoanItemList.size()!=0) {
147             oleRenewalLoanDocument.setOlePatronLoanDocuments(olePatronLoanItemList);
148             OlePatronLoanDocuments olePatronLoanDocuments=OlePatronLoanDocuments.Builder.create(oleRenewalLoanDocument).build();
149             return olePatronLoanDocuments;
150         }
151 
152         return null;
153 
154     }
155 
156 }