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