001package org.kuali.ole.sip2.requestParser; 002 003import org.apache.log4j.Logger; 004import org.kuali.ole.sip2.constants.OLESIP2Constants; 005 006/** 007 * Created by gayathria on 2/12/14. 008 */ 009public class OLESIP2HoldRequestParser extends OLESIP2RequestParser { 010 011 private String holdMode; 012 private String ExpirationDate; 013 private String pickupLocation; 014 private String holdType; 015 private String titleIdentifier; 016 private static final Logger LOG = Logger.getLogger(OLESIP2HoldRequestParser.class); 017 018 019 public OLESIP2HoldRequestParser(String requestData) { 020 this.parseHoldRequest(requestData); 021 } 022 023 024 public void parseHoldRequest(String requestData) { 025 026 LOG.info("Entry OLESIP2HoldRequestParser.parseHoldRequest(String requestData)"); 027 String[] requestDataArray = requestData.split("\\|"); 028 try { 029 for (String data : requestDataArray) { 030 code = data.substring(0, 2); 031 if (data.startsWith(OLESIP2Constants.HOLD_REQUEST)) { 032 char holdMode = data.charAt(2); 033 if (holdMode == '+') { 034 holdType = OLESIP2Constants.ADD_HOLD; 035 } else if (holdMode == '-') { 036 holdType = OLESIP2Constants.DELETE_HOLD; 037 } else if (holdMode == '*') { 038 holdType = OLESIP2Constants.UPDATE_HOLD; 039 } 040 if(data.contains(OLESIP2Constants.PICKUP_LOCATION_CODE)){ 041 if(data.length() > data.indexOf(OLESIP2Constants.PICKUP_LOCATION_CODE)+2) 042 pickupLocation = data.substring(data.indexOf(OLESIP2Constants.PICKUP_LOCATION_CODE)+2); 043 } 044 } 045 046 if (data.startsWith(OLESIP2Constants.PICKUP_LOCATION_CODE)) { 047 pickupLocation = (data.replaceFirst(OLESIP2Constants.PICKUP_LOCATION_CODE, "")).trim(); 048 } 049 if (data.startsWith(OLESIP2Constants.HOLD_TYPE_CODE)) { 050 holdType = (data.replaceFirst(OLESIP2Constants.HOLD_TYPE_CODE, "")).trim(); 051 } 052 if (data.startsWith(OLESIP2Constants.INSTITUTION_ID_CODE)) { 053 institutionId = (data.replaceFirst(OLESIP2Constants.INSTITUTION_ID_CODE, "")).trim(); 054 } 055 if (data.startsWith(OLESIP2Constants.PATRON_IDENTIFIER_CODE)) { 056 patronIdentifier = (data.replaceFirst(OLESIP2Constants.PATRON_IDENTIFIER_CODE, "")).trim(); 057 } 058 if (data.startsWith(OLESIP2Constants.PATRON_PWD_CODE)) { 059 patronPassword = (data.replaceFirst(OLESIP2Constants.PATRON_PWD_CODE, "")).trim(); 060 } 061 if (data.startsWith(OLESIP2Constants.ITEM_IDENTIFIER_CODE)) { 062 itemIdentifier = (data.replaceFirst(OLESIP2Constants.ITEM_IDENTIFIER_CODE, "")).trim(); 063 } 064 if (data.startsWith(OLESIP2Constants.TITLE_IDENTIFIER_CODE)) { 065 titleIdentifier = (data.replaceFirst(OLESIP2Constants.TITLE_IDENTIFIER_CODE, "")).trim(); 066 } 067 if (data.startsWith(OLESIP2Constants.TERMINAL_PWD_CODE)) { 068 terminalPassword = (data.replaceFirst(OLESIP2Constants.TERMINAL_PWD_CODE, "")).trim(); 069 } 070 if (data.startsWith(OLESIP2Constants.FEE_ACKNOWLEDGED_CODE)) { 071 feeAcknowledged = charToBool(data.charAt(2)); 072 } 073 if (data.startsWith(OLESIP2Constants.SEQUENCE_NUM_CODE)) { 074 sequenceNum = data.substring(2, 5); 075 checkSum = data.substring(5); 076 } 077 } 078 } catch (Exception e) { 079 LOG.error(e.getMessage(), e); 080 } 081 LOG.info("Exit OLESIP2HoldRequestParser.parseHoldRequest(String requestData)"); 082 } 083 084 public String getHoldMode() { 085 return holdMode; 086 } 087 088 public void setHoldMode(String holdMode) { 089 this.holdMode = holdMode; 090 } 091 092 public String getExpirationDate() { 093 return ExpirationDate; 094 } 095 096 public void setExpirationDate(String expirationDate) { 097 ExpirationDate = expirationDate; 098 } 099 100 public String getPickupLocation() { 101 return pickupLocation; 102 } 103 104 public void setPickupLocation(String pickupLocation) { 105 this.pickupLocation = pickupLocation; 106 } 107 108 public String getHoldType() { 109 return holdType; 110 } 111 112 public void setHoldType(String holdType) { 113 this.holdType = holdType; 114 } 115 116 public String getTitleIdentifier() { 117 return titleIdentifier; 118 } 119 120 public void setTitleIdentifier(String titleIdentifier) { 121 this.titleIdentifier = titleIdentifier; 122 } 123}