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