1 package org.kuali.ole.sip2.sip2Response;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.ole.ncip.bo.OLECancelRequest;
5 import org.kuali.ole.ncip.bo.OLEPlaceRequest;
6 import org.kuali.ole.response.OLESIP2Response;
7 import org.kuali.ole.common.MessageUtil;
8 import org.kuali.ole.common.OLESIP2Util;
9 import org.kuali.ole.sip2.constants.OLESIP2Constants;
10 import org.kuali.ole.sip2.requestParser.OLESIP2HoldRequestParser;
11 import org.kuali.ole.sip2.sip2Server.StringUtil;
12
13 import java.text.ParseException;
14 import java.text.SimpleDateFormat;
15
16
17
18
19 public class OLESIP2HoldResponse extends OLESIP2Response {
20 public OLESIP2HoldResponse() {
21 code = OLESIP2Constants.HOLD_RESPONSE;
22 }
23
24 public String getSIP2PlaceHoldRequestService(OLEPlaceRequest olePlaceRequest, OLESIP2HoldRequestParser sip2HoldRequestParser) {
25
26 StringBuilder builder = new StringBuilder();
27 builder.append(this.code);
28 if (olePlaceRequest.getMessage().trim().equalsIgnoreCase(OLESIP2Constants.REQUEST_RAISED)) {
29 builder.append(OLESIP2Util.bool2Int(true));
30 builder.append(OLESIP2Util.bool2Char(true));
31 } else {
32 builder.append(OLESIP2Util.bool2Int(true));
33 builder.append(OLESIP2Util.bool2Char(true));
34 }
35 builder.append(MessageUtil.getSipDateTime());
36 if (olePlaceRequest.getExpirationDate() != null) {
37 builder.append(OLESIP2Constants.EXPIRATION_DATE_CODE);
38 try {
39 builder.append(MessageUtil.toSipDateTime(new SimpleDateFormat().parse(olePlaceRequest.getExpirationDate())));
40 } catch (ParseException e) {
41 e.printStackTrace();
42 }
43 builder.append(OLESIP2Constants.SPLIT);
44 }
45 if (StringUtils.isNotBlank(olePlaceRequest.getQueuePosition())) {
46 builder.append(OLESIP2Constants.QUEUE_POSITION_CODE);
47 builder.append(olePlaceRequest.getQueuePosition());
48 builder.append(OLESIP2Constants.SPLIT);
49 }
50 if (StringUtils.isNotBlank(sip2HoldRequestParser.getPickupLocation())) {
51 builder.append(OLESIP2Constants.PICKUP_LOCATION_CODE);
52 builder.append(sip2HoldRequestParser.getPickupLocation());
53 builder.append(OLESIP2Constants.SPLIT);
54 }
55 builder.append(OLESIP2Constants.INSTITUTION_ID_CODE);
56 builder.append(StringUtils.isNotBlank(sip2HoldRequestParser.getInstitutionId()) ? sip2HoldRequestParser.getInstitutionId() : "");
57 builder.append(OLESIP2Constants.SPLIT+
58 OLESIP2Constants.PATRON_IDENTIFIER_CODE);
59 builder.append(StringUtils.isNotBlank(sip2HoldRequestParser.getPatronIdentifier()) ? sip2HoldRequestParser.getPatronIdentifier() : "");
60 if (StringUtils.isNotBlank(sip2HoldRequestParser.getItemIdentifier())) {
61 builder.append(OLESIP2Constants.SPLIT+
62 OLESIP2Constants.ITEM_IDENTIFIER_CODE);
63 builder.append(sip2HoldRequestParser.getItemIdentifier());
64 }
65 if (StringUtils.isNotBlank(sip2HoldRequestParser.getTitleIdentifier())) {
66 builder.append(OLESIP2Constants.SPLIT+
67 OLESIP2Constants.TITLE_IDENTIFIER_CODE);
68 builder.append(sip2HoldRequestParser.getTitleIdentifier().replaceAll(OLESIP2Constants.NON_ROMAN_REGEX, ""));
69 }
70 if (StringUtils.isNotBlank(olePlaceRequest.getMessage())) {
71 builder.append(OLESIP2Constants.SPLIT+
72 OLESIP2Constants.SCREEN_MSG_CODE);
73 builder.append(olePlaceRequest.getMessage().trim());
74 }
75 if (StringUtils.isNotBlank(sip2HoldRequestParser.getSequenceNum())) {
76 builder.append(OLESIP2Constants.SPLIT+
77 OLESIP2Constants.SEQUENCE_NUM_CODE);
78 builder.append(sip2HoldRequestParser.getSequenceNum());
79 builder.append(MessageUtil.computeChecksum(builder.toString()));
80 }
81
82 return builder.toString() + '\r';
83 }
84
85 public String getSIP2CancelHoldRequestService(OLECancelRequest oleCancelRequest, OLESIP2HoldRequestParser sip2HoldRequestParser) {
86
87 StringBuilder builder = new StringBuilder();
88 builder.append(this.code);
89 if (oleCancelRequest.getMessage().trim().contains(OLESIP2Constants.SUCCESSFULLY)) {
90 builder.append(OLESIP2Util.bool2Int(true));
91 builder.append(OLESIP2Util.bool2Char(true));
92 } else {
93 builder.append(OLESIP2Util.bool2Int(false));
94 builder.append(OLESIP2Util.bool2Char(false));
95 }
96 builder.append(MessageUtil.getSipDateTime());
97 if (sip2HoldRequestParser.getPickupLocation() != null) {
98 builder.append(OLESIP2Constants.PICKUP_LOCATION_CODE);
99 builder.append(sip2HoldRequestParser.getPickupLocation());
100 builder.append(OLESIP2Constants.SPLIT);
101 }
102 builder.append(OLESIP2Constants.INSTITUTION_ID_CODE);
103 builder.append(StringUtils.isNotBlank(sip2HoldRequestParser.getInstitutionId()) ? sip2HoldRequestParser.getInstitutionId() : "");
104 builder.append(OLESIP2Constants.SPLIT+
105 OLESIP2Constants.PATRON_IDENTIFIER_CODE);
106 builder.append(StringUtils.isNotBlank(sip2HoldRequestParser.getPatronIdentifier()) ? sip2HoldRequestParser.getPatronIdentifier() : "");
107 if (StringUtils.isNotBlank(sip2HoldRequestParser.getItemIdentifier())) {
108 builder.append(OLESIP2Constants.SPLIT+
109 OLESIP2Constants.ITEM_IDENTIFIER_CODE);
110 builder.append(sip2HoldRequestParser.getItemIdentifier());
111 }
112 if (StringUtils.isNotBlank(sip2HoldRequestParser.getTitleIdentifier())) {
113 builder.append(OLESIP2Constants.SPLIT+
114 OLESIP2Constants.TITLE_IDENTIFIER_CODE);
115 builder.append(sip2HoldRequestParser.getTitleIdentifier().replaceAll(OLESIP2Constants.NON_ROMAN_REGEX, ""));
116 }
117 if (StringUtils.isNotBlank(oleCancelRequest.getMessage())) {
118 builder.append(OLESIP2Constants.SPLIT+
119 OLESIP2Constants.SCREEN_MSG_CODE);
120 builder.append(oleCancelRequest.getMessage().trim());
121 }
122 if (StringUtils.isNotBlank(sip2HoldRequestParser.getSequenceNum())) {
123 builder.append(OLESIP2Constants.SPLIT+
124 OLESIP2Constants.SEQUENCE_NUM_CODE);
125 builder.append(sip2HoldRequestParser.getSequenceNum());
126 builder.append(MessageUtil.computeChecksum(builder.toString()));
127 }
128
129 return builder.toString() + '\r';
130 }
131
132 public String getSIP2UpdateHoldRequestService(OLESIP2HoldRequestParser sip2HoldRequestParser) {
133
134 StringBuilder builder = new StringBuilder();
135 builder.append(this.code);
136 builder.append(StringUtil.bool2Int(false));
137 builder.append(StringUtil.bool2Char(false));
138 builder.append(org.kuali.ole.sip2.sip2Server.MessageUtil.getSipDateTime());
139 builder.append(OLESIP2Constants.INSTITUTION_ID_CODE);
140 builder.append(StringUtils.isNotBlank(sip2HoldRequestParser.getInstitutionId()) ? sip2HoldRequestParser.getInstitutionId() : "");
141 builder.append(OLESIP2Constants.SPLIT+
142 OLESIP2Constants.PATRON_IDENTIFIER_CODE);
143 builder.append(StringUtils.isNotBlank(sip2HoldRequestParser.getPatronIdentifier()) ? sip2HoldRequestParser.getPatronIdentifier() : "");
144 builder.append(OLESIP2Constants.SPLIT+
145 OLESIP2Constants.SCREEN_MSG_CODE);
146 builder.append(OLESIP2Constants.SERVICE_UNAVAILABLE);
147 if (StringUtils.isNotBlank(sip2HoldRequestParser.getSequenceNum())) {
148 builder.append(OLESIP2Constants.SPLIT+
149 OLESIP2Constants.SEQUENCE_NUM_CODE);
150 builder.append(sip2HoldRequestParser.getSequenceNum());
151 builder.append(MessageUtil.computeChecksum(builder.toString()));
152 }
153 return builder.toString() + '\r';
154 }
155
156 }