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