View Javadoc
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   * Created by gayathria on 17/9/14.
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          //TODO
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          //Hold Items count
71          builder.append(OLESIP2Util.intToFixedLengthString(readyForPickupList.size(), 4));
72          //Overdue Items count
73          builder.append(OLESIP2Util.intToFixedLengthString(overDueItemList.size(), 4));
74          //Charged items count
75          builder.append(OLESIP2Util.intToFixedLengthString(oleLookupUser.getOleCheckedOutItems() != null &&
76                  oleLookupUser.getOleCheckedOutItems().getCheckedOutItems() != null ?
77                  oleLookupUser.getOleCheckedOutItems().getCheckedOutItems().size():0, 4));
78          //Fine Items count
79          builder.append(OLESIP2Util.intToFixedLengthString(oleLookupUser.getOleItemFines() != null &&
80                  oleLookupUser.getOleItemFines().getOleItemFineList() != null ?
81                  oleLookupUser.getOleItemFines().getOleItemFineList().size():0, 4));
82          //Recall Items count
83          builder.append(OLESIP2Util.intToFixedLengthString(recallItemList.size(), 4));
84          //Unavailable holds count
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          //Hold Items Limit
100         builder.append(OLESIP2Constants.SPLIT+
101                 OLESIP2Constants.HOLD_ITEMS_LIMIT_CODE);
102         builder.append(OLESIP2Util.intToFixedLengthString(0, 4));
103         //Overdue Items Limit
104         builder.append(OLESIP2Constants.SPLIT+
105                 OLESIP2Constants.OVERDUE_ITEMS_LIMIT_CODE);
106         builder.append(OLESIP2Util.intToFixedLengthString(0, 4));
107         //Charged items Limit
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         //TODO FeeLimit
123         /* //Hold Items
124         for(String readyForPickupItemBarcode : readyForPickupList){
125             builder.append("|AS"+readyForPickupItemBarcode);
126         }
127         //Overdue Items
128         for(String overDueItemBarcode : overDueItemList){
129             builder.append("|AT"+overDueItemBarcode);
130         }*/
131         //Charged Items
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         /*  //Fine Items
140         if(oleLookupUser.getOleItemFines() != null && oleLookupUser.getOleItemFines().getOleItemFineList() != null){
141             for(OLEItemFine oleItemFine : oleLookupUser.getOleItemFines().getOleItemFineList()){
142                 builder.append("|AV"+oleItemFine.getItemId());
143             }
144         }
145 
146         //Recall Items count
147         for(String recallItemBarcode : recallItemList)  {
148             builder.append("|BU"+recallItemBarcode);
149         }
150         //Unavailable holds count
151         for(String holdItemBarcode : holdItemList)  {
152             builder.append("|CD"+holdItemBarcode);
153         }*/
154 
155         //Ready For pickup/Hold Items
156        /* builder.append("|AS1801665677");
157         builder.append("|AS1801688598");
158        *//* builder.append("|AS1801875083");
159         builder.append("|AS1801966415");*//*
160 
161         //Overdue Items
162         builder.append("|AT1802079773");
163         builder.append("|AT1802222339");
164        *//* builder.append("|AT1802222348");
165         builder.append("|AT1802222796");*//*
166 
167 
168         //Charged Items
169         builder.append("|AU1804300321");
170         builder.append("|AU1804320602");
171        *//* builder.append("|AU1804890660");
172         builder.append("|AU1805909772");*//*
173 
174         //Fine Items
175         builder.append("|AV1806605361");
176         builder.append("|AV1807154526");
177         *//*builder.append("|AV1807193673");
178         builder.append("|AV1902964693");*//*
179 
180         //Recall Items count
181         builder.append("|BU1902964719");
182         builder.append("|BU1903066359");
183         *//*builder.append("|BU1903857371");
184         builder.append("|BU1803170864");*//*
185 
186 
187         //Unavailable holds count
188         builder.append("|CD1903857371");
189         builder.append("|CD1903066359");
190        *//* builder.append("|CD1803102354");
191         builder.append("|CD1802350209");*//*
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 }