View Javadoc
1   package org.kuali.ole.sip2.sip2Response;
2   
3   import org.apache.commons.lang3.StringUtils;
4   import org.kuali.ole.ncip.bo.OLECheckInItem;
5   import org.kuali.ole.sip2.common.MessageUtil;
6   import org.kuali.ole.sip2.constants.OLESIP2Constants;
7   import org.kuali.ole.sip2.requestParser.OLESIP2CheckInRequestParser;
8   
9   
10  /**
11   * Created by gayathria on 1/9/14.
12   */
13  public class OLESIP2CheckInResponse extends OLESIP2Response {
14  
15      public OLESIP2CheckInResponse() {
16          this.code = OLESIP2Constants.CHECK_IN_RESPONSE;
17      }
18  
19  
20      public String getSIP2CheckInResponse(OLECheckInItem oleCheckInItem, OLESIP2CheckInRequestParser sip2CheckInRequestParser) {
21  
22          StringBuilder oleCheckInBuilder = new StringBuilder();
23  
24          oleCheckInBuilder.append(this.code);
25  
26          if (oleCheckInItem.getCode().equalsIgnoreCase("024") || oleCheckInItem.getMessage().equalsIgnoreCase(OLESIP2Constants.CHECK_IN_SUCCESS)) {
27              oleCheckInBuilder.append("1");
28              oleCheckInBuilder.append(OLESIP2Constants.Y);
29              oleCheckInBuilder.append(OLESIP2Constants.Y);
30              oleCheckInBuilder.append(OLESIP2Constants.Y);
31          } else {
32              oleCheckInBuilder.append("0");
33              oleCheckInBuilder.append(OLESIP2Constants.N);
34              oleCheckInBuilder.append(OLESIP2Constants.N);
35              oleCheckInBuilder.append(OLESIP2Constants.N);
36          }
37  
38          oleCheckInBuilder.append(MessageUtil.getSipDateTime());
39          oleCheckInBuilder.append(OLESIP2Constants.INSTITUTION_ID_CODE);
40          if (StringUtils.isNotBlank(sip2CheckInRequestParser.getInstitutionId())) {
41              oleCheckInBuilder.append(sip2CheckInRequestParser.getInstitutionId());
42          }
43          oleCheckInBuilder.append(OLESIP2Constants.SPLIT+
44                  OLESIP2Constants.ITEM_IDENTIFIER_CODE);
45          oleCheckInBuilder.append(oleCheckInItem.getBarcode() != null ? oleCheckInItem.getBarcode() : sip2CheckInRequestParser.getItemIdentifier());
46          oleCheckInBuilder.append(OLESIP2Constants.SPLIT+
47                  OLESIP2Constants.PERMANENT_LOCATION_CODE);
48          if (StringUtils.isNotBlank(oleCheckInItem.getItemLocation())) {
49              oleCheckInBuilder.append(oleCheckInItem.getItemLocation());
50          }
51          if (StringUtils.isNotBlank(oleCheckInItem.getTitle())) {
52              oleCheckInBuilder.append(OLESIP2Constants.SPLIT+
53                      OLESIP2Constants.TITLE_IDENTIFIER_CODE);
54              oleCheckInBuilder.append(oleCheckInItem.getTitle().replaceAll(OLESIP2Constants.NON_ROMAN_REGEX,""));
55          }
56          if (StringUtils.isNotBlank(oleCheckInItem.getPatronBarcode())) {
57              oleCheckInBuilder.append(OLESIP2Constants.SPLIT+
58                      OLESIP2Constants.PATRON_IDENTIFIER_CODE);
59              oleCheckInBuilder.append(oleCheckInItem.getPatronBarcode());
60          }
61  
62          if (StringUtils.isNotBlank(oleCheckInItem.getItemType())) {
63              oleCheckInBuilder.append(OLESIP2Constants.SPLIT+
64                      OLESIP2Constants.MEDIA_TYPE_CODE);
65              oleCheckInBuilder.append(oleCheckInItem.getItemType());
66          }
67  
68  
69          if (StringUtils.isNotBlank(oleCheckInItem.getAuthor())) {
70              oleCheckInBuilder.append(OLESIP2Constants.SPLIT+
71                      OLESIP2Constants.ITEM_PROPERTIES_CODE);
72              oleCheckInBuilder.append("Author  :  " + oleCheckInItem.getAuthor().replaceAll(OLESIP2Constants.NON_ROMAN_REGEX,""));
73          }
74  
75          if (StringUtils.isNotBlank(oleCheckInItem.getMessage())) {
76              oleCheckInBuilder.append(OLESIP2Constants.SPLIT+
77                      OLESIP2Constants.SCREEN_MSG_CODE);
78              oleCheckInBuilder.append(oleCheckInItem.getMessage().replaceAll("<br/>", ""));
79              oleCheckInBuilder.append(OLESIP2Constants.SPLIT+
80                      OLESIP2Constants.PRINT_LINE_CODE);
81              oleCheckInBuilder.append(oleCheckInItem.getMessage().replaceAll("<br/>", ""));
82          }
83  
84          if (StringUtils.isNotBlank(sip2CheckInRequestParser.getSequenceNum())) {
85              oleCheckInBuilder.append(OLESIP2Constants.SPLIT+
86                      OLESIP2Constants.SEQUENCE_NUM_CODE);
87              oleCheckInBuilder.append(sip2CheckInRequestParser.getSequenceNum());
88              oleCheckInBuilder.append(MessageUtil.computeChecksum(oleCheckInBuilder.toString()));
89          }
90  
91          System.out.println(oleCheckInBuilder.toString());
92  
93  
94          return oleCheckInBuilder.toString() + '\r';
95  
96  
97      }
98  
99  }