View Javadoc

1   package org.kuali.ole.ingest.krms.action;
2   
3   import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
4   import org.kuali.rice.krms.framework.engine.Action;
5   
6   import java.sql.Timestamp;
7   import java.util.Calendar;
8   
9   /**
10   * Created with IntelliJ IDEA.
11   * User: vivekb
12   * Date: 8/22/12
13   * Time: 3:04 PM
14   * To change this template use File | Settings | File Templates.
15   */
16  public class OleLoanPeriod implements Action {
17      private String loanPeriod;
18  
19      public OleLoanPeriod(String loanPeriod) {
20          this.loanPeriod = loanPeriod;
21      }
22  
23      @Override
24      public void execute(ExecutionEnvironment environment) {
25          Timestamp dueDate = calculateLoanDueDate(loanPeriod);
26          if(dueDate==null){
27                environment.getEngineResults().setAttribute("loanPeriod","You must provide Due Date  <br/>");
28                environment.getEngineResults().setAttribute("dueDate",null);
29          }else{
30              environment.getEngineResults().setAttribute("dueDate",dueDate);
31          }
32      }
33  
34      @Override
35      public void executeSimulation(ExecutionEnvironment environment) {
36         execute(environment);
37      }
38      private Timestamp calculateLoanDueDate(String loanPeriod) {
39          String loanPeriodType[]=null;
40          Timestamp dueDate = null;
41          Calendar calendar = Calendar.getInstance();
42          if(loanPeriod != null && loanPeriod.trim().length()>0){
43              loanPeriodType =  loanPeriod.split("-");
44              int loanPeriodValue =  Integer.parseInt(loanPeriodType[0].toString());
45              String loanPeriodTypeValue =  loanPeriodType[1].toString();
46              if(loanPeriodTypeValue.equalsIgnoreCase("M")){
47                  calendar.add(Calendar.MINUTE, loanPeriodValue);
48              } else if(loanPeriodTypeValue.equalsIgnoreCase("H")) {
49                  calendar.add(Calendar.HOUR, loanPeriodValue);
50              } else if(loanPeriodTypeValue.equalsIgnoreCase("W")) {
51                  calendar.add(Calendar.WEEK_OF_MONTH, loanPeriodValue);
52              } else {
53                  calendar.add(Calendar.DATE, loanPeriodValue);
54              }
55              dueDate =  new java.sql.Timestamp(calendar.getTime().getTime());
56          }
57          return dueDate;
58      }
59  }