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.OLERenewItem;
6 import org.kuali.ole.sip2.common.MessageUtil;
7 import org.kuali.ole.sip2.common.OLESIP2Util;
8 import org.kuali.ole.sip2.constants.OLESIP2Constants;
9 import org.kuali.ole.sip2.requestParser.OLESIP2RenewRequestParser;
10
11
12
13
14 public class OLESIP2RenewResponse extends OLESIP2Response {
15 public OLESIP2RenewResponse() {
16 code = OLESIP2Constants.RENEW_RESPONSE;
17 }
18
19 public String getSIP2RenewResponse(OLERenewItem oleRenewItem, OLESIP2RenewRequestParser sip2RenewRequestParser) {
20 StringBuilder renewResponseBuilder = new StringBuilder();
21 renewResponseBuilder.append(code);
22 if (oleRenewItem.getCode().equalsIgnoreCase("030") || oleRenewItem.getMessage().equalsIgnoreCase(OLESIP2Constants.RENEW_SUCCESS)) {
23 renewResponseBuilder.append(OLESIP2Util.bool2Int(true));
24 renewResponseBuilder.append(OLESIP2Util.bool2Char(false));
25 renewResponseBuilder.append("U");
26 renewResponseBuilder.append(OLESIP2Util.bool2Char(true));
27 } else {
28 renewResponseBuilder.append(OLESIP2Util.bool2Int(false));
29 renewResponseBuilder.append(OLESIP2Util.bool2Char(false));
30 renewResponseBuilder.append("U");
31 renewResponseBuilder.append(OLESIP2Util.bool2Char(false));
32 }
33 renewResponseBuilder.append(MessageUtil.getSipDateTime());
34 renewResponseBuilder.append(OLESIP2Constants.INSTITUTION_ID_CODE);
35 renewResponseBuilder.append(StringUtils.isNotBlank(sip2RenewRequestParser.getInstitutionId()) ? sip2RenewRequestParser.getInstitutionId() : "");
36 renewResponseBuilder.append(OLESIP2Constants.SPLIT+
37 OLESIP2Constants.PATRON_IDENTIFIER_CODE);
38 renewResponseBuilder.append(oleRenewItem.getPatronBarcode() != null ? oleRenewItem.getPatronBarcode() : sip2RenewRequestParser.getPatronIdentifier());
39 renewResponseBuilder.append(OLESIP2Constants.SPLIT+
40 OLESIP2Constants.ITEM_IDENTIFIER_CODE);
41 renewResponseBuilder.append(oleRenewItem.getItemBarcode() != null ? oleRenewItem.getItemBarcode() : sip2RenewRequestParser.getItemIdentifier());
42 renewResponseBuilder.append(OLESIP2Constants.SPLIT+
43 OLESIP2Constants.TITLE_IDENTIFIER_CODE);
44 renewResponseBuilder.append(StringUtils.isNotBlank(oleRenewItem.getTitleIdentifier()) ? oleRenewItem.getTitleIdentifier() : "");
45 renewResponseBuilder.append(OLESIP2Constants.SPLIT+
46 OLESIP2Constants.DUE_DATE_CODE);
47 renewResponseBuilder.append(StringUtils.isNotBlank(oleRenewItem.getNewDueDate()) ? oleRenewItem.getNewDueDate() : "");
48 if (OLESIP2Util.getDefaultCurrency() != null) {
49 renewResponseBuilder.append(OLESIP2Constants.SPLIT+
50 OLESIP2Constants.CURRENCY_TYPE_CODE);
51 renewResponseBuilder.append(OLESIP2Util.getDefaultCurrency().getCurrencyCode());
52 }
53 if (StringUtils.isNotBlank(oleRenewItem.getMessage())) {
54 renewResponseBuilder.append(OLESIP2Constants.SPLIT+
55 OLESIP2Constants.SCREEN_MSG_CODE + oleRenewItem.getMessage().replaceAll("<br/>", ""));
56 renewResponseBuilder.append(OLESIP2Constants.SPLIT+
57 OLESIP2Constants.PRINT_LINE_CODE + oleRenewItem.getMessage().replaceAll("<br/>", ""));
58 }
59 if (StringUtils.isNotBlank(sip2RenewRequestParser.getSequenceNum())) {
60 renewResponseBuilder.append(OLESIP2Constants.SPLIT+
61 OLESIP2Constants.SEQUENCE_NUM_CODE);
62 renewResponseBuilder.append(sip2RenewRequestParser.getSequenceNum());
63 renewResponseBuilder.append(MessageUtil.computeChecksum(sip2RenewRequestParser.toString()));
64 }
65
66 return renewResponseBuilder.toString() + '\r';
67 }
68 }