1 package org.kuali.ole.response;
2
3 import org.apache.commons.lang3.StringUtils;
4 import org.apache.log4j.Logger;
5 import org.kuali.ole.bo.OLECheckOutItem;
6 import org.kuali.ole.bo.OLERenewItem;
7 import org.kuali.ole.common.MessageUtil;
8 import org.kuali.ole.common.OLESIP2Util;
9 import org.kuali.ole.constants.OLESIP2Constants;
10 import org.kuali.ole.request.OLESIP2CheckOutRequestParser;
11
12
13
14
15 public class OLESIP2CheckOutResponse extends OLESIP2Response {
16
17
18 public OLESIP2CheckOutResponse() {
19 this.code = OLESIP2Constants.CHECKOUT_RESPONSE;
20 }
21
22 private final static Logger LOG = Logger.getLogger(OLESIP2CheckOutResponse.class.getName());
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().replaceAll(OLESIP2Constants.NON_ROMAN_REGEX, "") : "");
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().replaceAll(OLESIP2Constants.NON_ROMAN_REGEX, "") : " ");
61
62
63
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
82 LOG.info("OLESIP2CheckOutResponse.getSIP2CheckOutResponse -- checkout "+checkOutResponseBuilder.toString());
83
84 return checkOutResponseBuilder.toString() + '\r';
85 }
86
87 public String getSIP2CheckOutResponse( OLERenewItem oleRenewItem, OLESIP2CheckOutRequestParser sip2CheckOutRequestParser) {
88
89 StringBuilder checkOutResponseBuilder = new StringBuilder();
90 checkOutResponseBuilder.append(code);
91 if (oleRenewItem.getCode().equalsIgnoreCase("030") || oleRenewItem.getMessage().equalsIgnoreCase(OLESIP2Constants.RENEW_SUCCESS)) {
92 checkOutResponseBuilder.append(OLESIP2Util.bool2Int(true));
93 checkOutResponseBuilder.append(OLESIP2Util.bool2Char(false));
94 checkOutResponseBuilder.append("U");
95 checkOutResponseBuilder.append(OLESIP2Util.bool2Char(true));
96 } else {
97 checkOutResponseBuilder.append(OLESIP2Util.bool2Int(false));
98 checkOutResponseBuilder.append(OLESIP2Util.bool2Char(false));
99 checkOutResponseBuilder.append("U");
100 checkOutResponseBuilder.append(OLESIP2Util.bool2Char(false));
101 }
102 checkOutResponseBuilder.append(MessageUtil.getSipDateTime());
103 checkOutResponseBuilder.append(OLESIP2Constants.INSTITUTION_ID_CODE);
104 checkOutResponseBuilder.append(StringUtils.isNotBlank(sip2CheckOutRequestParser.getInstitutionId()) ? sip2CheckOutRequestParser.getInstitutionId() : "");
105 checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
106 OLESIP2Constants.PATRON_IDENTIFIER_CODE);
107 checkOutResponseBuilder.append(oleRenewItem.getPatronBarcode() != null ? oleRenewItem.getPatronBarcode() : sip2CheckOutRequestParser.getPatronIdentifier());
108 checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
109 OLESIP2Constants.ITEM_IDENTIFIER_CODE);
110 checkOutResponseBuilder.append(oleRenewItem.getItemBarcode() != null ? oleRenewItem.getItemBarcode() : sip2CheckOutRequestParser.getItemIdentifier());
111 checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
112 OLESIP2Constants.TITLE_IDENTIFIER_CODE);
113 checkOutResponseBuilder.append(oleRenewItem.getTitleIdentifier() != null ? oleRenewItem.getTitleIdentifier().replaceAll(OLESIP2Constants.NON_ROMAN_REGEX, "") : "");
114 checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
115 OLESIP2Constants.DUE_DATE_CODE);
116 checkOutResponseBuilder.append(oleRenewItem.getNewDueDate() != null ? oleRenewItem.getNewDueDate() : "");
117 if (OLESIP2Util.getDefaultCurrency() != null) {
118 checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
119 OLESIP2Constants.CURRENCY_TYPE_CODE);
120 checkOutResponseBuilder.append(OLESIP2Util.getDefaultCurrency().getCurrencyCode());
121 }
122 checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
123 OLESIP2Constants.ITEM_PROPERTIES_CODE);
124 checkOutResponseBuilder.append(StringUtils.isNotBlank(oleRenewItem.getItemProperties()) ? oleRenewItem.getItemProperties().replaceAll(OLESIP2Constants.NON_ROMAN_REGEX, "") : " ");
125
126
127
128 if (oleRenewItem.getCode().equalsIgnoreCase("030") || oleRenewItem.getMessage().equalsIgnoreCase(OLESIP2Constants.RENEW_SUCCESS)) {
129 checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
130 OLESIP2Constants.SCREEN_MSG_CODE+OLESIP2Constants.CHECK_OUT_SUCCESSFULLY);
131 checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
132 OLESIP2Constants.PRINT_LINE_CODE + oleRenewItem.getMessage().replaceAll("<br/>", ""));
133 } else {
134 checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
135 OLESIP2Constants.SCREEN_MSG_CODE+OLESIP2Constants.CHECK_OUT_FAILED);
136 checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
137 OLESIP2Constants.PRINT_LINE_CODE + oleRenewItem.getMessage().replaceAll("<br/>", ""));
138 }
139 if (StringUtils.isNotBlank(sip2CheckOutRequestParser.getSequenceNum())) {
140 checkOutResponseBuilder.append(OLESIP2Constants.SPLIT+
141 OLESIP2Constants.SEQUENCE_NUM_CODE);
142 checkOutResponseBuilder.append(sip2CheckOutRequestParser.getSequenceNum());
143 checkOutResponseBuilder.append(MessageUtil.computeChecksum(checkOutResponseBuilder.toString()));
144 }
145
146 LOG.info("OLESIP2CheckOutResponse.getSIP2CheckOutResponse -- renew "+checkOutResponseBuilder.toString());
147 return checkOutResponseBuilder.toString() + '\r';
148 }
149
150
151 }