1 package org.kuali.ole.sip2.sip2Response;
2
3 import org.apache.commons.lang3.StringUtils;
4 import org.kuali.ole.ncip.bo.*;
5 import org.kuali.ole.response.OLESIP2Response;
6 import org.kuali.ole.common.MessageUtil;
7 import org.kuali.ole.common.OLESIP2Util;
8 import org.kuali.ole.sip2.constants.OLESIP2Constants;
9 import org.kuali.ole.sip2.requestParser.OLESIP2PatronInformationRequestParser;
10 import org.kuali.ole.sip2.service.OLESIP2HelperService;
11 import org.kuali.ole.sip2.service.impl.OLESIP2HelperServiceImpl;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
16
17
18
19 public class OLESIP2PatronInformationResponse extends OLESIP2Response {
20
21 OLESIP2HelperService olesip2HelperService = new OLESIP2HelperServiceImpl();
22
23
24 public OLESIP2PatronInformationResponse() {
25 code = OLESIP2Constants.PATRON_INFORMATION_RESPONSE;
26 }
27
28
29 public String getSIP2PatronInfoResponse(OLELookupUser oleLookupUser, OLESIP2PatronInformationRequestParser sip2PatronInformationRequestParser) {
30
31 StringBuilder builder = new StringBuilder();
32 List<String> overDueItemList = new ArrayList<>();
33 List<String> holdItemList = new ArrayList<>();
34 List<String> recallItemList = new ArrayList<>();
35 List<String> readyForPickupList = new ArrayList<>();
36
37 if(oleLookupUser.getOleCheckedOutItems()!=null && oleLookupUser.getOleCheckedOutItems().getCheckedOutItems()!=null){
38 for(OLECheckedOutItem oleCheckedOutItem : oleLookupUser.getOleCheckedOutItems().getCheckedOutItems()){
39 if(oleCheckedOutItem.isOverDue()){
40 overDueItemList.add(oleCheckedOutItem.getItemId());
41 }
42 }
43 }
44 if(oleLookupUser.getOleHolds()!=null && oleLookupUser.getOleHolds().getOleHoldList()!=null){
45 for(OLEHold oleHold : oleLookupUser.getOleHolds().getOleHoldList()){
46 if(oleHold.getRecallStatus().equalsIgnoreCase(OLESIP2Constants.YES)){
47 recallItemList.add(oleHold.getItemId());
48 }
49 if(oleHold.getAvailableStatus().equalsIgnoreCase(OLESIP2Constants.ONHOLD)){
50 readyForPickupList.add(oleHold.getItemId());
51 }else{
52 holdItemList.add(oleHold.getItemId());
53 }
54 }
55 }
56
57 builder.append(code);
58
59
60
61 if(oleLookupUser.isValidPatron()==true){
62 builder.append(" ");
63 }else{
64 builder.append(OLESIP2Constants.Y);
65 }
66 builder.append(" ");
67 builder.append(StringUtils.isNotBlank(sip2PatronInformationRequestParser.getLanguage())?
68 sip2PatronInformationRequestParser.getLanguage():"001");
69 builder.append(MessageUtil.getSipDateTime());
70
71 builder.append(OLESIP2Util.intToFixedLengthString(readyForPickupList.size(), 4));
72
73 builder.append(OLESIP2Util.intToFixedLengthString(overDueItemList.size(), 4));
74
75 builder.append(OLESIP2Util.intToFixedLengthString(oleLookupUser.getOleCheckedOutItems() != null &&
76 oleLookupUser.getOleCheckedOutItems().getCheckedOutItems() != null ?
77 oleLookupUser.getOleCheckedOutItems().getCheckedOutItems().size():0, 4));
78
79 builder.append(OLESIP2Util.intToFixedLengthString(oleLookupUser.getOleItemFines() != null &&
80 oleLookupUser.getOleItemFines().getOleItemFineList() != null ?
81 oleLookupUser.getOleItemFines().getOleItemFineList().size():0, 4));
82
83 builder.append(OLESIP2Util.intToFixedLengthString(recallItemList.size(), 4));
84
85 builder.append(OLESIP2Util.intToFixedLengthString(holdItemList.size(), 4));
86
87
88 builder.append(OLESIP2Constants.INSTITUTION_ID_CODE);
89 builder.append(StringUtils.isNotBlank(sip2PatronInformationRequestParser.getInstitutionId()) ?
90 sip2PatronInformationRequestParser.getInstitutionId() : OLESIP2Constants.INSTITUTION);
91 builder.append(OLESIP2Constants.SPLIT+
92 OLESIP2Constants.PATRON_IDENTIFIER_CODE);
93 builder.append(oleLookupUser.getPatronId() != null ?
94 oleLookupUser.getPatronId() : sip2PatronInformationRequestParser.getPatronIdentifier());
95 builder.append(OLESIP2Constants.SPLIT+
96 OLESIP2Constants.PERSONAL_NAME_CODE);
97 builder.append(oleLookupUser.getPatronName() != null ?
98 oleLookupUser.getPatronName().getFirstName() + " " + oleLookupUser.getPatronName().getLastName() : "");
99
100 builder.append(OLESIP2Constants.SPLIT+
101 OLESIP2Constants.HOLD_ITEMS_LIMIT_CODE);
102 builder.append(OLESIP2Util.intToFixedLengthString(0, 4));
103
104 builder.append(OLESIP2Constants.SPLIT+
105 OLESIP2Constants.OVERDUE_ITEMS_LIMIT_CODE);
106 builder.append(OLESIP2Util.intToFixedLengthString(0, 4));
107
108 builder.append(OLESIP2Constants.SPLIT+
109 OLESIP2Constants.CHARGED_ITEMS_LIMIT_CODE);
110 builder.append(OLESIP2Util.intToFixedLengthString(0, 4));
111 builder.append(OLESIP2Constants.SPLIT+
112 OLESIP2Constants.VALID_PATRON_CODE);
113 builder.append(oleLookupUser.isValidPatron()==true?OLESIP2Constants.Y:OLESIP2Constants.N);
114 builder.append(OLESIP2Constants.SPLIT+
115 OLESIP2Constants.CURRENCY_TYPE_CODE);
116 builder.append(OLESIP2Util.getDefaultCurrency().getCurrencyCode());
117 if (oleLookupUser.getOleItemFines() != null) {
118 builder.append(OLESIP2Constants.SPLIT+
119 OLESIP2Constants.FEE_AMOUNT_CODE);
120 builder.append(olesip2HelperService.calculateTotalFineBalance(oleLookupUser.getOleItemFines().getOleItemFineList()));
121 }
122
123
124
125
126
127
128
129
130
131
132 if(oleLookupUser.getOleCheckedOutItems() != null && oleLookupUser.getOleCheckedOutItems().getCheckedOutItems() != null){
133 for(OLECheckedOutItem oleCheckedOutItem : oleLookupUser.getOleCheckedOutItems().getCheckedOutItems()){
134 builder.append(OLESIP2Constants.SPLIT+
135 OLESIP2Constants.CHARGED_ITEMS_CODE+
136 oleCheckedOutItem.getItemId());
137 }
138 }
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194 if (oleLookupUser.getPatronAddress() != null) {
195 builder.append(OLESIP2Constants.SPLIT+
196 OLESIP2Constants.HOME_ADDRESS_CODE);
197 builder.append(StringUtils.isNotBlank(oleLookupUser.getPatronAddress().getLine1()) ?
198 oleLookupUser.getPatronAddress().getLine1() : "");
199 builder.append(StringUtils.isNotBlank(oleLookupUser.getPatronAddress().getCity()) ?
200 ", " + oleLookupUser.getPatronAddress().getCity() : "");
201 builder.append(StringUtils.isNotBlank(oleLookupUser.getPatronAddress().getStateProvinceCode()) ?
202 ", " + oleLookupUser.getPatronAddress().getStateProvinceCode() : "");
203 builder.append(StringUtils.isNotBlank(oleLookupUser.getPatronAddress().getPostalCode()) ?
204 ", " + oleLookupUser.getPatronAddress().getPostalCode() : "");
205 builder.append(StringUtils.isNotBlank(oleLookupUser.getPatronAddress().getCountryCode()) ?
206 ", " + oleLookupUser.getPatronAddress().getCountryCode() : "");
207 }
208 builder.append(OLESIP2Constants.SPLIT+
209 OLESIP2Constants.EMAIL_ADDRESS_CODE);
210 builder.append(oleLookupUser.getPatronEmail() != null ? oleLookupUser.getPatronEmail().getEmailTypeCode()
211 + " " + oleLookupUser.getPatronEmail().getEmailAddress() : "");
212 builder.append(OLESIP2Constants.SPLIT+
213 OLESIP2Constants.HOME_PHONE_NUM_CODE);
214 builder.append(oleLookupUser.getPatronPhone() != null ? oleLookupUser.getPatronPhone().getPhoneTypeCode()
215 + " " + oleLookupUser.getPatronPhone().getPhoneNumber() : "");
216
217 if (StringUtils.isNotBlank(oleLookupUser.getMessage())) {
218 builder.append(OLESIP2Constants.SPLIT+
219 OLESIP2Constants.SCREEN_MSG_CODE);
220 builder.append(oleLookupUser.getMessage());
221 }
222
223 if (StringUtils.isNotBlank(sip2PatronInformationRequestParser.getSequenceNum())) {
224 builder.append(OLESIP2Constants.SPLIT+OLESIP2Constants.SEQUENCE_NUM_CODE);
225 builder.append(sip2PatronInformationRequestParser.getSequenceNum());
226 builder.append(MessageUtil.computeChecksum(builder.toString()));
227 }
228 return builder.toString() + '\r';
229
230 }
231
232
233 }