View Javadoc
1   package org.kuali.ole.sip2.sip2Response;
2   
3   import org.apache.commons.lang3.StringUtils;
4   import org.kuali.ole.sip2.common.MessageUtil;
5   import org.kuali.ole.sip2.common.OLESIP2Util;
6   import org.kuali.ole.sip2.constants.OLESIP2Constants;
7   import org.kuali.ole.sip2.requestParser.OLESIP2FeePaidRequestParser;
8   
9   /**
10   * Created by gayathria on 15/12/14.
11   */
12  public class OLESIP2FeePaidResponse extends OLESIP2Response {
13  
14      public OLESIP2FeePaidResponse() {
15          code = OLESIP2Constants.FEE_PAID_RESPONSE;
16      }
17  
18      public String getFeePaidResponse(String message, OLESIP2FeePaidRequestParser sip2FeePaidRequestParser) {
19          StringBuilder sip2FeePaidResponseBuilder = new StringBuilder();
20          sip2FeePaidResponseBuilder.append(code);
21          if (message.equalsIgnoreCase(OLESIP2Constants.FEE_PAID)) {
22              sip2FeePaidResponseBuilder.append(OLESIP2Util.bool2Char(true));
23          } else {
24              sip2FeePaidResponseBuilder.append(OLESIP2Util.bool2Char(false));
25          }
26          sip2FeePaidResponseBuilder.append(MessageUtil.getSipDateTime());
27          sip2FeePaidResponseBuilder.append(OLESIP2Constants.INSTITUTION_ID_CODE);
28          sip2FeePaidResponseBuilder.append(sip2FeePaidRequestParser.getInstitutionId() != null ? sip2FeePaidRequestParser.getInstitutionId() : "");
29          sip2FeePaidResponseBuilder.append(OLESIP2Constants.SPLIT+
30                  OLESIP2Constants.PATRON_IDENTIFIER_CODE);
31          sip2FeePaidResponseBuilder.append(sip2FeePaidRequestParser.getPatronIdentifier());
32          if (StringUtils.isNotBlank(sip2FeePaidRequestParser.getTransactionId())) {
33              sip2FeePaidResponseBuilder.append(OLESIP2Constants.SPLIT+
34                      OLESIP2Constants.TRANSACTION_ID_CODE);
35              sip2FeePaidResponseBuilder.append(sip2FeePaidRequestParser.getTransactionId());
36          }
37          if (StringUtils.isNotBlank(message)) {
38              sip2FeePaidResponseBuilder.append(OLESIP2Constants.SPLIT+
39                      OLESIP2Constants.SCREEN_MSG_CODE);
40              sip2FeePaidResponseBuilder.append(message);
41          } else {
42              sip2FeePaidResponseBuilder.append(OLESIP2Constants.SPLIT+
43                      OLESIP2Constants.SCREEN_MSG_CODE);
44              sip2FeePaidResponseBuilder.append(OLESIP2Constants.SERVICE_ERROR);
45          }
46          if (StringUtils.isNotBlank(sip2FeePaidRequestParser.getSequenceNum())) {
47              sip2FeePaidResponseBuilder.append(OLESIP2Constants.SPLIT+
48                      OLESIP2Constants.SEQUENCE_NUM_CODE);
49              sip2FeePaidResponseBuilder.append(sip2FeePaidRequestParser.getSequenceNum());
50              sip2FeePaidResponseBuilder.append(MessageUtil.computeChecksum(sip2FeePaidResponseBuilder.toString()));
51          }
52          return sip2FeePaidResponseBuilder.toString() + '\r';
53      }
54  }
55