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