001package org.kuali.ole.sip2.sip2Response; 002 003import org.apache.commons.lang.StringUtils; 004import org.kuali.ole.deliver.bo.OleItemSearch; 005import org.kuali.ole.sip2.common.MessageUtil; 006import org.kuali.ole.sip2.common.OLESIP2Util; 007import org.kuali.ole.sip2.constants.OLESIP2Constants; 008import org.kuali.ole.sip2.requestParser.OLESIP2ItemInformationRequestParser; 009 010/** 011 * Created by gayathria on 17/9/14. 012 */ 013public class OLESIP2ItemInformationResponse extends OLESIP2Response { 014 015 016 public OLESIP2ItemInformationResponse() { 017 this.code = OLESIP2Constants.ITEM_INFORMATION_RESPONSE; 018 } 019 020 021 public String getSIP2ItemInfoResponse(OleItemSearch oleItemSearch, OLESIP2ItemInformationRequestParser sip2ItemInformationRequestParser) { 022 023 StringBuilder builder = new StringBuilder(); 024 025 builder.append(code); 026 builder.append("08"); 027 builder.append("00"); 028 builder.append(OLESIP2Constants.BLOCK_PATRON_REQUEST); 029 builder.append(MessageUtil.getSipDateTime()); 030 builder.append(OLESIP2Constants.ITEM_IDENTIFIER_CODE); 031 builder.append(oleItemSearch.getItemBarCode() != null ? oleItemSearch.getItemBarCode() : sip2ItemInformationRequestParser.getItemIdentifier()); 032 builder.append(OLESIP2Constants.SPLIT+ 033 OLESIP2Constants.TITLE_IDENTIFIER_CODE); 034 builder.append(oleItemSearch.getTitle() != null ? oleItemSearch.getTitle().replaceAll(OLESIP2Constants.NON_ROMAN_REGEX,""): ""); 035 builder.append(OLESIP2Constants.SPLIT+ 036 OLESIP2Constants.CURRENCY_TYPE_CODE); 037 builder.append(OLESIP2Util.getDefaultCurrency().getCurrencyCode()); 038 builder.append(OLESIP2Constants.SPLIT+ 039 OLESIP2Constants.MEDIA_TYPE_CODE); 040 builder.append(StringUtils.isNotBlank(oleItemSearch.getItemType()) ? oleItemSearch.getItemType() : " "); 041 builder.append(OLESIP2Constants.SPLIT+ 042 OLESIP2Constants.CURRENT_LOCATION_CODE); 043 builder.append(StringUtils.isNotBlank(oleItemSearch.getShelvingLocation()) ? oleItemSearch.getShelvingLocation() : " "); 044 if(StringUtils.isBlank(oleItemSearch.getItemBarCode()) && StringUtils.isBlank(oleItemSearch.getItemStatus())){ 045 builder.append(OLESIP2Constants.SPLIT+ 046 OLESIP2Constants.SCREEN_MSG_CODE); 047 builder.append(OLESIP2Constants.ITEM_UNAVAILABLE); 048 } 049 builder.append(OLESIP2Constants.SPLIT+ 050 OLESIP2Constants.ITEM_PROPERTIES_CODE); 051 builder.append((StringUtils.isNotBlank(oleItemSearch.getAuthor()) ? "Author : " + oleItemSearch.getAuthor().replaceAll(OLESIP2Constants.NON_ROMAN_REGEX,"") : " ") + (StringUtils.isNotBlank(oleItemSearch.getItemStatus()) ? " Status : " + oleItemSearch.getItemStatus() : " ")); 052 if(StringUtils.isBlank(oleItemSearch.getItemBarCode()) && StringUtils.isBlank(oleItemSearch.getItemStatus())){ 053 builder.append(OLESIP2Constants.SPLIT+ 054 OLESIP2Constants.SCREEN_MSG_CODE); 055 builder.append(OLESIP2Constants.ITEM_UNAVAILABLE); 056 } 057 if (StringUtils.isNotBlank(sip2ItemInformationRequestParser.getSequenceNum())) { 058 builder.append(OLESIP2Constants.SPLIT+ 059 OLESIP2Constants.SEQUENCE_NUM_CODE); 060 builder.append(sip2ItemInformationRequestParser.getSequenceNum()); 061 builder.append(MessageUtil.computeChecksum(builder.toString())); 062 } 063 return builder.toString() + '\r'; 064 065 } 066 067 068}