1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krms.framework.engine; |
17 | |
|
18 | |
import java.util.List; |
19 | |
|
20 | |
import org.kuali.rice.krms.api.engine.ExecutionEnvironment; |
21 | |
import org.kuali.rice.krms.api.engine.ResultEvent; |
22 | |
import org.kuali.rice.krms.framework.engine.result.BasicResult; |
23 | |
|
24 | |
public class BasicRule implements Rule { |
25 | 1 | private static final ResultLogger LOG = ResultLogger.getInstance(); |
26 | |
|
27 | |
private String name; |
28 | |
private Proposition proposition; |
29 | |
private List<Action> actions; |
30 | |
|
31 | 34 | public BasicRule(String name, Proposition proposition, List<Action> actions) { |
32 | 34 | if (proposition == null) { |
33 | 0 | throw new IllegalArgumentException("Proposition cannot be null."); |
34 | |
} |
35 | 34 | this.name = name; |
36 | 34 | this.proposition = proposition; |
37 | 34 | this.actions = actions; |
38 | 34 | } |
39 | |
|
40 | |
public BasicRule(Proposition proposition, List<Action> actions) { |
41 | 0 | this(null, proposition, actions); |
42 | 0 | } |
43 | |
|
44 | |
@Override |
45 | |
public boolean evaluate(ExecutionEnvironment environment) { |
46 | 35 | boolean result = proposition.evaluate(environment).getResult(); |
47 | 35 | if (actions != null) { |
48 | 34 | for (Action action : actions) { |
49 | 34 | if (shouldExecuteAction(result)) { |
50 | 19 | action.execute(environment); |
51 | |
} |
52 | |
} |
53 | |
} |
54 | 35 | if (LOG.isEnabled(environment)){ |
55 | 35 | LOG.logResult(new BasicResult(ResultEvent.RuleEvaluated, this, environment, result)); |
56 | |
} |
57 | 35 | return result; |
58 | |
} |
59 | |
|
60 | |
protected boolean shouldExecuteAction(boolean ruleExecutionResult) { |
61 | 34 | return ruleExecutionResult; |
62 | |
} |
63 | |
|
64 | |
public String getName() { |
65 | 0 | return name; |
66 | |
} |
67 | |
|
68 | |
public String toString(){ |
69 | 0 | return name; |
70 | |
} |
71 | |
} |