View Javadoc
1   package org.kuali.ole.deliver.drools.rules;
2   
3   import org.kuali.ole.deliver.bo.drools.DroolsRuleBo;
4   import org.kuali.ole.deliver.drools.DroolFileGenerator;
5   import org.kuali.ole.deliver.drools.DroolsConstants;
6   
7   import java.io.File;
8   import java.util.*;
9   
10  /**
11   * Created by pvsubrah on 7/2/15.
12   */
13  public class GeneralChecksDroolFileGenerator extends DroolFileGenerator {
14      List<RuleFormulator> ruleFormulators;
15  
16      private String fileDir;
17      private String activationGroup;
18  
19      public List<RuleFormulator> getRuleFormulators() {
20          if (null == ruleFormulators) {
21              ruleFormulators = new ArrayList<>();
22              ruleFormulators.add(new IsActiveRuleFormulator());
23              ruleFormulators.add(new PatronActivationDateRuleFormulator());
24              ruleFormulators.add(new IsAddressVerifiedRuleFormulator());
25              ruleFormulators.add(new GeneralBlockRuleFormulator());
26              ruleFormulators.add(new PatronExpiredRuleFormulator());
27              ruleFormulators.add(new PatronAllChargesRuleFormulator());
28              ruleFormulators.add(new PatronReplacementAmountRuleFormulator());
29              ruleFormulators.add(new PatronOverdueDaysRuleFormulator());
30              ruleFormulators.add(new PatronRecallAndOverDueDaysRuleFormulator());
31              ruleFormulators.add(new ItemOverdueFineAmountRuleFormulator());
32          }
33          return ruleFormulators;
34      }
35  
36      public void setRuleFormulators(List<RuleFormulator> ruleFormulators) {
37          this.ruleFormulators = ruleFormulators;
38      }
39  
40      public void setFileDir(String fileDir) {
41          this.fileDir = fileDir;
42      }
43  
44      @Override
45      public String getFilePath(String fileName) {
46          if (null == fileDir) {
47              fileDir = getDroolBaseDirectory() + File.separator + "general" + File.separator + "general-checks.drl";
48          }
49          return fileDir;
50      }
51  
52      @Override
53      protected List<Map> getCustomRules() {
54          List<Map> rules = new ArrayList<>();
55          List<DroolsRuleBo> droolsRuleBos = getDroolsRuleBos();
56          for (Iterator<DroolsRuleBo> iterator = droolsRuleBos.iterator(); iterator.hasNext(); ) {
57              DroolsRuleBo droolsRuleBo = iterator.next();
58              for (Iterator<RuleFormulator> ruleFormulatorIterator = getRuleFormulators().iterator(); ruleFormulatorIterator.hasNext(); ) {
59                  RuleFormulator ruleFormulator = ruleFormulatorIterator.next();
60                  if(ruleFormulator.isInterested(droolsRuleBo.getRuleType())){
61                      rules.add(ruleFormulator.formulateRuleMap(droolsRuleBo));
62                      break;
63                  }
64              }
65          }
66          return rules;
67      }
68  
69      public void setActivationGroup(String activationGroup) {
70          this.activationGroup = activationGroup;
71      }
72  
73      @Override
74      public List<Map> getCustomRulesWithParameters() {
75          List<Map> rules = new ArrayList<>();
76  
77          List<DroolsRuleBo> droolsRuleBos = getDroolsRuleBos();
78  
79          for (Iterator<DroolsRuleBo> iterator = droolsRuleBos.iterator(); iterator.hasNext(); ) {
80              DroolsRuleBo droolsRuleBo = iterator.next();
81              for (Iterator<RuleFormulator> ruleFormulatorIterator = getRuleFormulators().iterator(); ruleFormulatorIterator.hasNext(); ) {
82                  RuleFormulator ruleFormulator = ruleFormulatorIterator.next();
83                  if(ruleFormulator.isInterestedForParameters(droolsRuleBo.getRuleType())){
84                      rules.add(ruleFormulator.formulateRuleMap(droolsRuleBo));
85                      break;
86                  }
87              }
88          }
89          return rules;
90      }
91  
92      @Override
93      public boolean isInterested(String value) {
94          return value.equals(DroolsConstants.EDITOR_TYPE.GENERAL_CHECK);
95      }
96  
97      @Override
98      protected String getThenCustomRules() {
99          return "";
100     }
101 }