View Javadoc

1   package org.kuali.ole.service;
2   
3   import org.kuali.ole.loan.bo.OleLoanDocument;
4   import org.kuali.ole.patron.bo.OlePatronBo;
5   import org.kuali.ole.patron.bo.OlePatronDocument;
6   import org.kuali.rice.krad.service.KRADServiceLocator;
7   
8   import java.sql.Timestamp;
9   import java.text.ParseException;
10  import java.text.SimpleDateFormat;
11  import java.util.*;
12  
13  /**
14   * Created with IntelliJ IDEA.
15   * User: Bala.km
16   * Date: 7/2/12
17   * Time: 2:04 PM
18   * Service class to provide input to the krms rule engine for loans circulation policy
19   */
20  public class OleCirculationPolicyServiceImpl implements OleCirculationPolicyService {
21      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleLocationServiceImpl.class);
22  
23      /**
24       *  This method checks valid patron code using patron barcode.
25       * @param patronBarcode
26       * @return boolean
27       */
28      @Override
29      public boolean isValidBarcode(String patronBarcode) {
30          return true;
31      }
32  
33      /**
34       *  This method returns MembershipExpireDate using patronBarcode.
35       * @param patronBarcode
36       * @return Date
37       */
38      @Override
39      public Date getPatronMembershipExpireDate(String patronBarcode) {
40          Date expirationDate=null;
41          try{
42              Map<String, String> criteria = new HashMap<String, String>();
43              criteria.put("barcode", patronBarcode);
44              List<OlePatronDocument> olePatronDocument = (List<OlePatronDocument>)  KRADServiceLocator.getBusinessObjectService().findMatching(OlePatronDocument.class,criteria);
45              if(olePatronDocument.size()==1) {
46                  expirationDate = olePatronDocument.get(0).getExpirationDate();
47              }
48          }catch(Exception e){
49              LOG.error(e.getMessage());
50          }
51          return expirationDate;
52      }
53  
54      /**
55       *  This method returns number of items loaned for a particular patron id.
56       * @param olePatronId
57       * @return int
58       */
59      @Override
60      public int getNoOfItemsLoaned(String olePatronId) {
61          Map<String, String> criteria = new HashMap<String, String>();
62          Collection<OleLoanDocument> oleLoanDocuments=null;
63          try{
64              criteria.put("patronId", olePatronId);
65              oleLoanDocuments = KRADServiceLocator.getBusinessObjectService().findMatching(OleLoanDocument.class,criteria);
66          }catch(Exception e){
67              LOG.error(e.getMessage());
68          }
69          return oleLoanDocuments!=null ?oleLoanDocuments.size()+1:0;
70      }
71  
72      /**
73       *  This method returns loan due date using loan period.
74       * @param loanPeriod
75       * @return  Timestamp
76       */
77      @Override
78      public Timestamp calculateLoanDueDate(String loanPeriod) {
79          String loanPeriodType[]=null;
80          Timestamp dueDate = null;
81          Calendar calendar = Calendar.getInstance();
82          if(loanPeriod != null && loanPeriod.trim().length()>0){
83              loanPeriodType =  loanPeriod.split("-");
84              int loanPeriodValue =  Integer.parseInt(loanPeriodType[0].toString());
85              String loanPeriodTypeValue =  loanPeriodType[1].toString();
86              if(loanPeriodTypeValue.equalsIgnoreCase("MINUTE")){
87                  calendar.add(Calendar.MINUTE, loanPeriodValue);
88              } else if(loanPeriodTypeValue.equalsIgnoreCase("HOUR")) {
89                  calendar.add(Calendar.HOUR, loanPeriodValue);
90              } else if(loanPeriodTypeValue.equalsIgnoreCase("WEEK")) {
91                  calendar.add(Calendar.WEEK_OF_MONTH, loanPeriodValue);
92              } else {
93                  calendar.add(Calendar.DATE, loanPeriodValue);
94              }
95              dueDate =  new java.sql.Timestamp(calendar.getTime().getTime());
96          }
97          return dueDate;
98      }
99  }