1 package org.kuali.ole.sip2.sip2Response;
2
3 import org.apache.commons.lang3.StringUtils;
4 import org.kuali.ole.bo.OLERenewItem;
5 import org.kuali.ole.common.OLESIP2Util;
6 import org.kuali.ole.bo.OLERenewItemList;
7 import org.kuali.ole.response.OLESIP2Response;
8 import org.kuali.ole.sip2.constants.OLESIP2Constants;
9 import org.kuali.ole.sip2.requestParser.OLESIP2RenewAllRequestParser;
10 import org.kuali.ole.sip2.sip2Server.MessageUtil;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
15
16
17
18 public class OLESIP2RenewAllResponse extends OLESIP2Response {
19
20 public OLESIP2RenewAllResponse() {
21 this.code = "";
22 }
23
24 public String getSIP2RenewAllResponse(OLERenewItemList oleRenewItemList, OLESIP2RenewAllRequestParser sip2RenewAllRequestParser) {
25 StringBuilder renewAllResponseBuilder = new StringBuilder();
26 renewAllResponseBuilder.append(code);
27 if (oleRenewItemList.getRenewItemList().size() > 0) {
28 renewAllResponseBuilder.append(OLESIP2Util.bool2Int(true));
29 } else {
30 renewAllResponseBuilder.append(OLESIP2Util.bool2Int(false));
31 }
32 int renewedCount = 0;
33 int unRenewedCount = 0;
34 List<String> renewedItems = new ArrayList<>();
35
36
37
38 List<String> unRenewedItems = new ArrayList<>();
39
40 for (int i = 0; i < oleRenewItemList.getRenewItemList().size(); i++) {
41 OLERenewItem oleRenewItem = oleRenewItemList.getRenewItemList().get(i);
42 if (oleRenewItem.getMessage().equalsIgnoreCase(OLESIP2Constants.CHECK_OUT_SUCCESS)) {
43 renewedCount = renewedCount + 1;
44 renewedItems.add(oleRenewItem.getItemBarcode());
45
46 } else {
47 unRenewedCount = unRenewedCount + 1;
48 if(StringUtils.isNotBlank(oleRenewItem.getItemBarcode()))
49 unRenewedItems.add(oleRenewItem.getItemBarcode());
50 }
51 }
52 renewAllResponseBuilder.append(OLESIP2Util.intToFixedLengthString(renewedCount, 4));
53 renewAllResponseBuilder.append(OLESIP2Util.intToFixedLengthString(unRenewedCount, 4));
54 renewAllResponseBuilder.append(MessageUtil.getSipDateTime());
55 renewAllResponseBuilder.append(OLESIP2Constants.INSTITUTION_ID_CODE);
56 renewAllResponseBuilder.append(StringUtils.isNotBlank(sip2RenewAllRequestParser.getInstitutionId()) ? sip2RenewAllRequestParser.getInstitutionId() : "");
57 for (String item : renewedItems) {
58 renewAllResponseBuilder.append(OLESIP2Constants.SPLIT+
59 OLESIP2Constants.RENEWED_ITEMS_CODE);
60 renewAllResponseBuilder.append(item);
61 }
62 for (String item : unRenewedItems) {
63 renewAllResponseBuilder.append(OLESIP2Constants.SPLIT+
64 OLESIP2Constants.UN_RENEWED_ITEMS_CODE);
65 renewAllResponseBuilder.append(item);
66 }
67 renewAllResponseBuilder.append(OLESIP2Constants.SPLIT+
68 OLESIP2Constants.SCREEN_MSG_CODE);
69 renewAllResponseBuilder.append(OLESIP2Constants.REQUEST_PROCESSED);
70 renewAllResponseBuilder.append(OLESIP2Constants.SPLIT+
71 OLESIP2Constants.PRINT_LINE_CODE);
72 renewAllResponseBuilder.append(" " +renewedCount + " - Renewed succesfully. " + unRenewedCount + " - Not Renewed. ");
73 if (StringUtils.isNotBlank(sip2RenewAllRequestParser.getSequenceNum())) {
74 renewAllResponseBuilder.append(OLESIP2Constants.SPLIT+
75 OLESIP2Constants.SEQUENCE_NUM_CODE);
76 renewAllResponseBuilder.append(sip2RenewAllRequestParser.getSequenceNum());
77 renewAllResponseBuilder.append(MessageUtil.computeChecksum(sip2RenewAllRequestParser.toString()));
78 }
79 return renewAllResponseBuilder.toString() + '\r';
80 }
81
82 public String getSIP2RenewAllResponse(String message, OLESIP2RenewAllRequestParser sip2RenewAllRequestParser) {
83
84 StringBuilder renewAllResponseBuilder = new StringBuilder();
85 renewAllResponseBuilder.append(code);
86 renewAllResponseBuilder.append(OLESIP2Util.bool2Int(false));
87 renewAllResponseBuilder.append(OLESIP2Util.intToFixedLengthString(0, 4));
88 renewAllResponseBuilder.append(OLESIP2Util.intToFixedLengthString(0, 4));
89 renewAllResponseBuilder.append(MessageUtil.getSipDateTime());
90 renewAllResponseBuilder.append(OLESIP2Constants.INSTITUTION_ID_CODE);
91 renewAllResponseBuilder.append(StringUtils.isNotBlank(sip2RenewAllRequestParser.getInstitutionId()) ? sip2RenewAllRequestParser.getInstitutionId() : "");
92 renewAllResponseBuilder.append(OLESIP2Constants.SPLIT+
93 OLESIP2Constants.SCREEN_MSG_CODE);
94 renewAllResponseBuilder.append(message);
95 if (StringUtils.isNotBlank(sip2RenewAllRequestParser.getSequenceNum())) {
96 renewAllResponseBuilder.append(OLESIP2Constants.SPLIT+
97 OLESIP2Constants.SEQUENCE_NUM_CODE);
98 renewAllResponseBuilder.append(sip2RenewAllRequestParser.getSequenceNum());
99 renewAllResponseBuilder.append(MessageUtil.computeChecksum(sip2RenewAllRequestParser.toString()));
100 }
101 return renewAllResponseBuilder.toString() + '\r';
102
103 }
104 }