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
18
19
20
21
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
45
46
47
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
57
58
59
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
86
87
88
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
101
102
103
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
119
120
121
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
144
145
146
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 }