1 package org.kuali.ole.sip2.sip2Response;
2
3 import org.apache.commons.lang3.StringUtils;
4 import org.kuali.ole.ncip.bo.OLELookupUser;
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.OLESIP2BlockPatronRequestParser;
9 import org.kuali.ole.sip2.requestParser.OLESIP2PatronStatusRequestParser;
10 import org.kuali.ole.sip2.service.OLESIP2HelperService;
11 import org.kuali.ole.sip2.service.impl.OLESIP2HelperServiceImpl;
12
13
14
15
16 public class OLESIP2PatronStatusResponse extends OLESIP2Response {
17
18 OLESIP2HelperService olesip2HelperService = new OLESIP2HelperServiceImpl();
19
20
21 public OLESIP2PatronStatusResponse() {
22 code = OLESIP2Constants.PATRON_STATUS_RESPONSE;
23 }
24
25 public String getSIP2PatronStatusResponse(OLELookupUser oleLookupUser, OLESIP2PatronStatusRequestParser sip2PatronStatusRequestParser) {
26
27 StringBuilder builder = new StringBuilder();
28 builder.append(OLESIP2Constants.PATRON_STATUS_RESPONSE);
29 builder.append(" ");
30 builder.append("001");
31 builder.append(MessageUtil.getSipDateTime());
32 builder.append(OLESIP2Constants.INSTITUTION_ID_CODE);
33 builder.append(StringUtils.isNotBlank(sip2PatronStatusRequestParser.getInstitutionId()) ? sip2PatronStatusRequestParser.getInstitutionId() : "");
34 builder.append(OLESIP2Constants.SPLIT+
35 OLESIP2Constants.PATRON_IDENTIFIER_CODE);
36 builder.append(oleLookupUser.getPatronId() != null ? oleLookupUser.getPatronId() : sip2PatronStatusRequestParser.getPatronIdentifier());
37 builder.append(OLESIP2Constants.SPLIT+
38 OLESIP2Constants.PERSONAL_NAME_CODE);
39 builder.append(oleLookupUser.getPatronName() != null ? oleLookupUser.getPatronName().getFirstName() + " " + oleLookupUser.getPatronName().getLastName() : "");
40 builder.append(OLESIP2Constants.SPLIT+
41 OLESIP2Constants.VALID_PATRON_CODE);
42 builder.append(OLESIP2Util.bool2Char(oleLookupUser.isValidPatron()));
43 builder.append(OLESIP2Constants.SPLIT);
44 builder.append(OLESIP2Constants.CURRENCY_TYPE_CODE);
45 builder.append(OLESIP2Util.getDefaultCurrency().getCurrencyCode());
46 if (oleLookupUser.getOleItemFines() != null) {
47 builder.append(OLESIP2Constants.SPLIT);
48 builder.append(OLESIP2Constants.FEE_AMOUNT_CODE);
49 builder.append(olesip2HelperService.calculateTotalFineBalance(oleLookupUser.getOleItemFines().getOleItemFineList()));
50 }
51 if (StringUtils.isNotBlank(oleLookupUser.getMessage())) {
52 builder.append(OLESIP2Constants.SPLIT+
53 OLESIP2Constants.SCREEN_MSG_CODE);
54 builder.append(oleLookupUser.getMessage());
55 }
56 if (StringUtils.isNotBlank(sip2PatronStatusRequestParser.getSequenceNum())) {
57 builder.append(OLESIP2Constants.SPLIT+
58 OLESIP2Constants.SEQUENCE_NUM_CODE);
59 builder.append(sip2PatronStatusRequestParser.getSequenceNum());
60 builder.append(MessageUtil.computeChecksum(builder.toString()));
61 }
62 return builder.toString() + '\r';
63 }
64
65 public String getSIP2PatronStatusResponse(OLELookupUser oleLookupUser, OLESIP2BlockPatronRequestParser sip2BlockPatronRequestParser) {
66
67 StringBuilder builder = new StringBuilder();
68 builder.append(OLESIP2Constants.PATRON_STATUS_RESPONSE);
69 builder.append(" ");
70 builder.append("001");
71 builder.append(MessageUtil.getSipDateTime());
72 builder.append(OLESIP2Constants.INSTITUTION_ID_CODE);
73 builder.append(StringUtils.isNotBlank(sip2BlockPatronRequestParser.getInstitutionId()) ? sip2BlockPatronRequestParser.getInstitutionId() : "");
74 builder.append(OLESIP2Constants.SPLIT+
75 OLESIP2Constants.PATRON_IDENTIFIER_CODE);
76 builder.append(oleLookupUser.getPatronId() != null ? oleLookupUser.getPatronId() : sip2BlockPatronRequestParser.getPatronIdentifier());
77 builder.append(OLESIP2Constants.SPLIT+
78 OLESIP2Constants.PERSONAL_NAME_CODE);
79 builder.append(oleLookupUser.getPatronName() != null ? oleLookupUser.getPatronName().getFirstName() + " " + oleLookupUser.getPatronName().getLastName() : "");
80 builder.append(OLESIP2Constants.SPLIT+
81 OLESIP2Constants.VALID_PATRON_CODE);
82 builder.append(OLESIP2Util.bool2Char(oleLookupUser.isValidPatron()));
83 builder.append(OLESIP2Constants.SPLIT+
84 OLESIP2Constants.CURRENCY_TYPE_CODE);
85 builder.append(OLESIP2Util.getDefaultCurrency().getCurrencyCode());
86 if (oleLookupUser.getOleItemFines() != null) {
87 builder.append(OLESIP2Constants.SPLIT+
88 OLESIP2Constants.FEE_AMOUNT_CODE);
89 builder.append(olesip2HelperService.calculateTotalFineBalance(oleLookupUser.getOleItemFines().getOleItemFineList()));
90 }
91 if (StringUtils.isNotBlank(oleLookupUser.getMessage())) {
92 builder.append(OLESIP2Constants.SPLIT+
93 OLESIP2Constants.SCREEN_MSG_CODE);
94 builder.append(oleLookupUser.getMessage());
95 }
96 if (StringUtils.isNotBlank(sip2BlockPatronRequestParser.getSequenceNum())) {
97 builder.append(OLESIP2Constants.SPLIT+
98 OLESIP2Constants.SEQUENCE_NUM_CODE);
99 builder.append(sip2BlockPatronRequestParser.getSequenceNum());
100 builder.append(MessageUtil.computeChecksum(builder.toString()));
101 }
102 return builder.toString() + '\r';
103 }
104
105
106 }