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