1 package org.kuali.ole.sip2.sip2Response;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.ole.OLEConstants;
5 import org.kuali.ole.deliver.bo.OleItemSearch;
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.OLESIP2ItemInformationRequestParser;
11
12
13
14
15 public class OLESIP2ItemInformationResponse extends OLESIP2Response {
16
17
18 public OLESIP2ItemInformationResponse() {
19 this.code = OLESIP2Constants.ITEM_INFORMATION_RESPONSE;
20 }
21
22
23 public String getSIP2ItemInfoResponse(OleItemSearch oleItemSearch, OLESIP2ItemInformationRequestParser sip2ItemInformationRequestParser) {
24
25 StringBuilder builder = new StringBuilder();
26
27 builder.append(code);
28 builder.append("08");
29 builder.append("00");
30 builder.append(OLESIP2Constants.BLOCK_PATRON_REQUEST);
31 builder.append(MessageUtil.getSipDateTime());
32 builder.append(OLESIP2Constants.ITEM_IDENTIFIER_CODE);
33 builder.append(oleItemSearch.getItemBarCode() != null ? oleItemSearch.getItemBarCode() : sip2ItemInformationRequestParser.getItemIdentifier());
34 builder.append(OLESIP2Constants.SPLIT+
35 OLESIP2Constants.TITLE_IDENTIFIER_CODE);
36 builder.append(oleItemSearch.getTitle() != null ? oleItemSearch.getTitle().replaceAll(OLESIP2Constants.NON_ROMAN_REGEX,""): "");
37 builder.append(OLESIP2Constants.SPLIT+
38 OLESIP2Constants.CURRENCY_TYPE_CODE);
39 builder.append(OLESIP2Util.getDefaultCurrency().getCurrencyCode());
40
41
42
43 builder.append(OLESIP2Constants.SPLIT+
44 OLESIP2Constants.CURRENT_LOCATION_CODE);
45 builder.append(StringUtils.isNotBlank(oleItemSearch.getShelvingLocation()) ? oleItemSearch.getShelvingLocation() : " ");
46 if(StringUtils.isBlank(oleItemSearch.getItemBarCode()) && StringUtils.isBlank(oleItemSearch.getItemStatus())){
47 builder.append(OLESIP2Constants.SPLIT+
48 OLESIP2Constants.SCREEN_MSG_CODE);
49 builder.append(OLESIP2Constants.ITEM_UNAVAILABLE);
50 }
51 builder.append(OLESIP2Constants.SPLIT+
52 OLESIP2Constants.ITEM_PROPERTIES_CODE);
53 builder.append((StringUtils.isNotBlank(oleItemSearch.getAuthor()) ? OLEConstants.OlePatronBill.LABEL_ITEM_AUTHOR+" : " + oleItemSearch.getAuthor().replaceAll(OLESIP2Constants.NON_ROMAN_REGEX,"") : " ") + (StringUtils.isNotBlank(oleItemSearch.getItemStatus()) ? " Status : " + oleItemSearch.getItemStatus() : " "));
54 if(StringUtils.isBlank(oleItemSearch.getItemBarCode()) && StringUtils.isBlank(oleItemSearch.getItemStatus())){
55 builder.append(OLESIP2Constants.SPLIT+
56 OLESIP2Constants.SCREEN_MSG_CODE);
57 builder.append(OLESIP2Constants.ITEM_UNAVAILABLE);
58 }
59 if (StringUtils.isNotBlank(sip2ItemInformationRequestParser.getSequenceNum())) {
60 builder.append(OLESIP2Constants.SPLIT+
61 OLESIP2Constants.SEQUENCE_NUM_CODE);
62 builder.append(sip2ItemInformationRequestParser.getSequenceNum());
63 builder.append(MessageUtil.computeChecksum(builder.toString()));
64 }
65 return builder.toString() + '\r';
66
67 }
68
69
70 }