View Javadoc
1   package org.kuali.ole.deliver.util;
2   
3   import org.apache.commons.lang3.StringUtils;
4   import org.apache.log4j.Logger;
5   import org.kuali.ole.OLEConstants;
6   import org.kuali.ole.deliver.bo.OleLoanDocument;
7   import org.kuali.ole.deliver.controller.checkout.CircUtilController;
8   import org.kuali.ole.deliver.service.ParameterValueResolver;
9   import org.kuali.ole.bo.OLERenewItem;
10  import org.kuali.rice.core.api.config.property.ConfigContext;
11  
12  import java.sql.Timestamp;
13  import java.util.*;
14  
15  /**
16   * Created by sheiksalahudeenm on 8/13/15.
17   */
18  public class RenewItemControllerUtil extends CircUtilController{
19  
20      private static final Logger LOG = Logger.getLogger(RenewItemControllerUtil.class);
21  
22      public Integer incrementRenewalCount(OleLoanDocument oleLoanDocument) {
23          Integer numRenewals = 0;
24          String numberOfRenewalsPreviously = oleLoanDocument.getNumberOfRenewals();
25          if (StringUtils.isNotBlank(numberOfRenewalsPreviously)) {
26              numRenewals = new Integer(numberOfRenewalsPreviously) + 1;
27          }
28          return numRenewals;
29      }
30  
31      public Map getUpdateParameters(OleLoanDocument currentLoanDocument) {
32          HashMap parameterValues = new HashMap();
33          parameterValues.put("itemUUID", currentLoanDocument.getItemUuid());
34          parameterValues.put("loanDueDate", currentLoanDocument.getLoanDueDate());
35          parameterValues.put("numRenewals", currentLoanDocument.getNumberOfRenewals());
36          return parameterValues;
37      }
38  
39      public OLERenewItem getRenewItemForSuccessLoanDocument(OleLoanDocument oleLoanDocument) {
40          OLERenewItem oleRenewItem = new OLERenewItem();
41          String itemBarcode = oleLoanDocument.getItemId();
42          oleRenewItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RENEW_SUCCESS) + " - Item Barcode(" + itemBarcode + ")");
43          oleRenewItem.setSuccess(true);
44          oleRenewItem.setItemBarcode(itemBarcode);
45          oleRenewItem.setPastDueDate(oleLoanDocument.getPastDueDate().toString());
46          oleRenewItem.setNewDueDate(oleLoanDocument.getLoanDueDate().toString());
47          oleRenewItem.setRenewalCount(oleLoanDocument.getNumberOfRenewals());
48          oleRenewItem.setPatronBarcode(oleLoanDocument.getOlePatron().getBarcode());
49          oleRenewItem.setTitleIdentifier(oleLoanDocument.getTitle());
50          oleRenewItem.setItemProperties(oleLoanDocument.getAuthor() != null ? "Author=" + oleLoanDocument.getAuthor() : null);
51          oleRenewItem.setMediaType(oleLoanDocument.getItemType());
52          return oleRenewItem;
53      }
54      public OLERenewItem getRenewItemForFailureLoanDocument(OleLoanDocument oleLoanDocument) {
55          OLERenewItem oleRenewItem = new OLERenewItem();
56          String itemBarcode = oleLoanDocument.getItemId();
57          oleRenewItem.setMessage(oleLoanDocument.getErrorMessage());
58          oleRenewItem.setItemBarcode(itemBarcode);
59          Date pastDueDate = oleLoanDocument.getPastDueDate();
60          oleRenewItem.setPastDueDate(pastDueDate != null ? pastDueDate.toString() : null);
61          Timestamp loanDueDate = oleLoanDocument.getLoanDueDate();
62          oleRenewItem.setNewDueDate(loanDueDate != null ? loanDueDate.toString() : null);
63          oleRenewItem.setRenewalCount(oleLoanDocument.getNumberOfRenewals());
64          oleRenewItem.setPatronBarcode(oleLoanDocument.getOlePatron() != null ? oleLoanDocument.getOlePatron().getBarcode() : null);
65          oleRenewItem.setTitleIdentifier(oleLoanDocument.getTitle());
66          oleRenewItem.setItemProperties(oleLoanDocument.getAuthor() != null ? "Author=" + oleLoanDocument.getAuthor() : null);
67          oleRenewItem.setMediaType(oleLoanDocument.getItemType());
68          return oleRenewItem;
69      }
70  
71      public int getMaximumNumberOfThreadForRenewService() {
72          String maxNumberOfThreadFromParameter = ParameterValueResolver.getInstance().getParameter(OLEConstants
73                  .APPL_ID_OLE, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, OLEConstants.MAX_NO_OF_THREAD_FOR_RENEW_SERVICE);
74          int maxNumberOfThread = 10;
75          if(StringUtils.isNotBlank(maxNumberOfThreadFromParameter)){
76              try{
77                  int maxNumberOfThreadFromParameterInterger = Integer.parseInt(maxNumberOfThreadFromParameter);
78                  if(maxNumberOfThreadFromParameterInterger > 0){
79                      maxNumberOfThread = maxNumberOfThreadFromParameterInterger;
80                  }else{
81                      LOG.info("Invalid max number of thread for renew service from system parameter. So taking the default max number of thread : " + maxNumberOfThread);
82                  }
83              }catch(Exception exception){
84                  LOG.info("Invalid max number of thread for renew service from system parameter. So taking the default max number of thread : " + maxNumberOfThread);
85              }
86          }else{
87              LOG.info("Invalid max number of thread for renew service from system parameter. So taking the default max number of thread : " + maxNumberOfThread);
88          }
89          return maxNumberOfThread;
90      }
91  
92  }