View Javadoc
1   package org.kuali.ole.sip2.sip2Response;
2   
3   import org.apache.commons.lang3.StringUtils;
4   import org.kuali.ole.deliver.bo.OlePatronDocument;
5   import org.kuali.ole.response.OLESIP2Response;
6   import org.kuali.ole.common.MessageUtil;
7   import org.kuali.ole.common.OLESIP2Util;
8   import org.kuali.ole.sip2.constants.OLESIP2Constants;
9   import org.kuali.ole.sip2.requestParser.OLESIP2PatronEnableRequestParser;
10  
11  /**
12   * Created by gayathria on 10/11/14.
13   */
14  public class OLESIP2PatronEnableResponse extends OLESIP2Response {
15  
16  
17      public OLESIP2PatronEnableResponse() {
18          this.code = OLESIP2Constants.PATRON_ENABLE_RESPONSE;
19      }
20  
21      public String getSIP2PatronEnableResponse(OlePatronDocument olePatronDocument, OLESIP2PatronEnableRequestParser sip2PatronEnableRequestParser, boolean isValidPatron) {
22  
23          StringBuilder builder = new StringBuilder();
24          builder.append(code);
25          builder.append("YYYYYYYYYYYYYY");
26          builder.append("001");
27          builder.append(MessageUtil.getSipDateTime());
28          builder.append(OLESIP2Constants.INSTITUTION_ID_CODE);
29          builder.append(StringUtils.isNotBlank(sip2PatronEnableRequestParser.getInstitutionId()) ? sip2PatronEnableRequestParser.getInstitutionId() : "");
30          builder.append(OLESIP2Constants.SPLIT+
31                  OLESIP2Constants.PATRON_IDENTIFIER_CODE);
32          builder.append(StringUtils.isNotBlank(olePatronDocument.getBarcode()) ? olePatronDocument.getBarcode() : sip2PatronEnableRequestParser.getPatronIdentifier());
33          builder.append(OLESIP2Constants.SPLIT+
34                  OLESIP2Constants.PERSONAL_NAME_CODE);
35          builder.append(olePatronDocument.getEntity().getNames().get(0).getFirstName() + " " + olePatronDocument.getEntity().getNames().get(0).getLastName());
36          builder.append(OLESIP2Constants.SPLIT+
37                  OLESIP2Constants.VALID_PATRON_CODE);
38          builder.append(OLESIP2Util.bool2Char(isValidPatron));
39          builder.append(OLESIP2Constants.SPLIT+
40                  OLESIP2Constants.SCREEN_MSG_CODE);
41          builder.append(OLESIP2Constants.PATRON_ENABLED);
42          if (sip2PatronEnableRequestParser.getSequenceNum() != null && !sip2PatronEnableRequestParser.getSequenceNum().equalsIgnoreCase("")) {
43              builder.append(OLESIP2Constants.SPLIT+
44                      OLESIP2Constants.SEQUENCE_NUM_CODE);
45              builder.append(sip2PatronEnableRequestParser.getSequenceNum());
46              builder.append(MessageUtil.computeChecksum(builder.toString()));
47          }
48          return builder.toString() + '\r';
49  
50      }
51  
52  
53  
54  
55  
56  
57  
58  
59      /*
60        StringBuilder builder = new StringBuilder();
61          builder.append(code);
62          builder.append(status);
63  
64          builder.append(this.language);
65          builder.append(this.transactionDate);
66          builder.append("AO");
67          builder.append(this.institutionId);
68          builder.append("|AA");
69          builder.append(this.patronIdentifier);
70          builder.append("|AE");
71          builder.append(this.personalName);
72  
73          if (validPatronUsed) {
74              builder.append("|BL");
75              builder.append(StringUtil.bool2Char(validPatron));
76          }
77          if (validPatronPasswordUsed) {
78              builder.append("|CQ");
79              builder.append(StringUtil.bool2Char(validPatronPassword));
80          }
81  
82          for (String msg : screenMessage) {
83              builder.append("|AF");
84              builder.append(msg);
85          }
86  
87          for (String msg : printLine) {
88              builder.append("|AG");
89              builder.append(msg);
90          }
91  
92          builder.append("|");
93  
94          if (isSequence()) {
95              builder.append("AY");
96              builder.append(sequence);
97          }
98          builder.append("AZ");
99          return MessageUtil.computeChecksum(builder.toString());
100      */
101 }