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