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