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