View Javadoc
1   package org.kuali.ole.sip2.sip2Response;
2   
3   import org.apache.commons.lang3.StringUtils;
4   import org.kuali.ole.OLEConstants;
5   import org.kuali.ole.ncip.bo.OLECheckOutItem;
6   import org.kuali.ole.ncip.bo.OLERenewItem;
7   import org.kuali.ole.sip2.common.MessageUtil;
8   import org.kuali.ole.sip2.common.OLESIP2Util;
9   import org.kuali.ole.sip2.constants.OLESIP2Constants;
10  import org.kuali.ole.sip2.requestParser.OLESIP2CheckOutRequestParser;
11  
12  /**
13   * Created by gayathria on 27/8/14.
14   */
15  public class OLESIP2CheckOutResponse extends OLESIP2Response {
16  
17  
18      public OLESIP2CheckOutResponse() {
19          this.code = OLESIP2Constants.CHECKOUT_RESPONSE;
20      }
21  
22  
23      public String getSIP2CheckOutResponse(OLECheckOutItem oleCheckOutItem, OLESIP2CheckOutRequestParser sip2CheckOutRequestParser) {
24  
25          StringBuilder checkOutResponseBuilder = new StringBuilder();
26          checkOutResponseBuilder.append(code);
27          if (oleCheckOutItem.code.equalsIgnoreCase("030") || oleCheckOutItem.getMessage().equalsIgnoreCase(OLESIP2Constants.CHECK_OUT_SUCCESS)) {
28              checkOutResponseBuilder.append(OLESIP2Util.bool2Int(true));
29              checkOutResponseBuilder.append(OLESIP2Util.bool2Char(false));
30              checkOutResponseBuilder.append("U");
31              checkOutResponseBuilder.append(OLESIP2Util.bool2Char(true));
32          } else {
33              checkOutResponseBuilder.append(OLESIP2Util.bool2Int(false));
34              checkOutResponseBuilder.append(OLESIP2Util.bool2Char(false));
35              checkOutResponseBuilder.append("U");
36              checkOutResponseBuilder.append(OLESIP2Util.bool2Char(false));
37          }
38          checkOutResponseBuilder.append(MessageUtil.getSipDateTime());
39          checkOutResponseBuilder.append(OLESIP2Constants.INSTITUTION_ID_CODE);
40          checkOutResponseBuilder.append(StringUtils.isNotBlank(sip2CheckOutRequestParser.getInstitutionId()) ? sip2CheckOutRequestParser.getInstitutionId() : "");
41          checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
42                  OLESIP2Constants.PATRON_IDENTIFIER_CODE);
43          checkOutResponseBuilder.append(oleCheckOutItem.getPatronBarcode() != null ? oleCheckOutItem.getPatronBarcode() : sip2CheckOutRequestParser.getPatronIdentifier());
44          checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
45                  OLESIP2Constants.ITEM_IDENTIFIER_CODE);
46          checkOutResponseBuilder.append(oleCheckOutItem.getBarcode() != null ? oleCheckOutItem.getBarcode() : sip2CheckOutRequestParser.getItemIdentifier());
47          checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
48                  OLESIP2Constants.TITLE_IDENTIFIER_CODE);
49          checkOutResponseBuilder.append(oleCheckOutItem.getTitleIdentifier() != null ? oleCheckOutItem.getTitleIdentifier() : "");
50          checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
51                  OLESIP2Constants.DUE_DATE_CODE);
52          checkOutResponseBuilder.append(oleCheckOutItem.getDueDate() != null ? oleCheckOutItem.getDueDate() : "");
53          if (OLESIP2Util.getDefaultCurrency() != null) {
54              checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
55                      OLESIP2Constants.CURRENCY_TYPE_CODE);
56              checkOutResponseBuilder.append(OLESIP2Util.getDefaultCurrency().getCurrencyCode());
57          }
58          checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
59                  OLESIP2Constants.ITEM_PROPERTIES_CODE);
60          checkOutResponseBuilder.append(StringUtils.isNotBlank(oleCheckOutItem.getItemProperties()) ? oleCheckOutItem.getItemProperties() : " ");
61          checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
62                  OLESIP2Constants.MEDIA_TYPE_CODE);
63          checkOutResponseBuilder.append(StringUtils.isNotBlank(oleCheckOutItem.getItemType()) ? oleCheckOutItem.getItemType() : "");
64          if (oleCheckOutItem.code.equalsIgnoreCase("030") || oleCheckOutItem.getMessage().equalsIgnoreCase(OLESIP2Constants.CHECK_OUT_SUCCESS)) {
65              checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
66                      OLESIP2Constants.SCREEN_MSG_CODE+OLESIP2Constants.CHECK_OUT_SUCCESSFULLY);
67              checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
68                      OLESIP2Constants.PRINT_LINE_CODE + oleCheckOutItem.getMessage().replaceAll("<br/>", ""));
69          } else {
70              checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
71                      OLESIP2Constants.SCREEN_MSG_CODE+OLESIP2Constants.CHECK_OUT_FAILED);
72              checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
73                      OLESIP2Constants.PRINT_LINE_CODE + oleCheckOutItem.getMessage().replaceAll("<br/>", ""));
74          }
75          if (StringUtils.isNotBlank(sip2CheckOutRequestParser.getSequenceNum())) {
76              checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
77                      OLESIP2Constants.SEQUENCE_NUM_CODE);
78              checkOutResponseBuilder.append(sip2CheckOutRequestParser.getSequenceNum());
79              checkOutResponseBuilder.append(MessageUtil.computeChecksum(checkOutResponseBuilder.toString()));
80          }
81          return checkOutResponseBuilder.toString() + '\r';
82      }
83  
84      public String getSIP2CheckOutResponse( OLERenewItem oleRenewItem, OLESIP2CheckOutRequestParser sip2CheckOutRequestParser) {
85  
86          StringBuilder checkOutResponseBuilder = new StringBuilder();
87          checkOutResponseBuilder.append(code);
88          if (oleRenewItem.getCode().equalsIgnoreCase("030") || oleRenewItem.getMessage().equalsIgnoreCase(OLESIP2Constants.RENEW_SUCCESS)) {
89              checkOutResponseBuilder.append(OLESIP2Util.bool2Int(true));
90              checkOutResponseBuilder.append(OLESIP2Util.bool2Char(false));
91              checkOutResponseBuilder.append("U");
92              checkOutResponseBuilder.append(OLESIP2Util.bool2Char(true));
93          } else {
94              checkOutResponseBuilder.append(OLESIP2Util.bool2Int(false));
95              checkOutResponseBuilder.append(OLESIP2Util.bool2Char(false));
96              checkOutResponseBuilder.append("U");
97              checkOutResponseBuilder.append(OLESIP2Util.bool2Char(false));
98          }
99          checkOutResponseBuilder.append(MessageUtil.getSipDateTime());
100         checkOutResponseBuilder.append(OLESIP2Constants.INSTITUTION_ID_CODE);
101         checkOutResponseBuilder.append(StringUtils.isNotBlank(sip2CheckOutRequestParser.getInstitutionId()) ? sip2CheckOutRequestParser.getInstitutionId() : "");
102         checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
103                 OLESIP2Constants.PATRON_IDENTIFIER_CODE);
104         checkOutResponseBuilder.append(oleRenewItem.getPatronBarcode() != null ? oleRenewItem.getPatronBarcode() : sip2CheckOutRequestParser.getPatronIdentifier());
105         checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
106                 OLESIP2Constants.ITEM_IDENTIFIER_CODE);
107         checkOutResponseBuilder.append(oleRenewItem.getItemBarcode() != null ? oleRenewItem.getItemBarcode() : sip2CheckOutRequestParser.getItemIdentifier());
108         checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
109                 OLESIP2Constants.TITLE_IDENTIFIER_CODE);
110         checkOutResponseBuilder.append(oleRenewItem.getTitleIdentifier() != null ? oleRenewItem.getTitleIdentifier() : "");
111         checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
112                 OLESIP2Constants.DUE_DATE_CODE);
113         checkOutResponseBuilder.append(oleRenewItem.getNewDueDate() != null ? oleRenewItem.getNewDueDate() : "");
114         if (OLESIP2Util.getDefaultCurrency() != null) {
115             checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
116                     OLESIP2Constants.CURRENCY_TYPE_CODE);
117             checkOutResponseBuilder.append(OLESIP2Util.getDefaultCurrency().getCurrencyCode());
118         }
119         checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
120                 OLESIP2Constants.ITEM_PROPERTIES_CODE);
121         checkOutResponseBuilder.append(StringUtils.isNotBlank(oleRenewItem.getItemProperties()) ? oleRenewItem.getItemProperties() : " ");
122        /* checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
123                 OLESIP2Constants.MEDIA_TYPE_CODE);
124         checkOutResponseBuilder.append(StringUtils.isNotBlank(oleRenewItem.getItemType()) ? oleRenewItem.getItemType() : "");*/
125         if (oleRenewItem.getCode().equalsIgnoreCase("030") || oleRenewItem.getMessage().equalsIgnoreCase(OLESIP2Constants.RENEW_SUCCESS)) {
126             checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
127                     OLESIP2Constants.SCREEN_MSG_CODE+OLESIP2Constants.CHECK_OUT_SUCCESSFULLY);
128             checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
129                     OLESIP2Constants.PRINT_LINE_CODE + oleRenewItem.getMessage().replaceAll("<br/>", ""));
130         } else {
131             checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
132                     OLESIP2Constants.SCREEN_MSG_CODE+OLESIP2Constants.CHECK_OUT_FAILED);
133             checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
134                     OLESIP2Constants.PRINT_LINE_CODE + oleRenewItem.getMessage().replaceAll("<br/>", ""));
135         }
136         if (StringUtils.isNotBlank(sip2CheckOutRequestParser.getSequenceNum())) {
137             checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
138                     OLESIP2Constants.SEQUENCE_NUM_CODE);
139             checkOutResponseBuilder.append(sip2CheckOutRequestParser.getSequenceNum());
140             checkOutResponseBuilder.append(MessageUtil.computeChecksum(checkOutResponseBuilder.toString()));
141         }
142         return checkOutResponseBuilder.toString() + '\r';
143     }
144 
145 
146 }