1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.r2.core.class1.process.krms.proposition; |
17 | |
|
18 | |
import org.kuali.rice.krms.api.engine.ExecutionEnvironment; |
19 | |
import org.kuali.rice.krms.api.engine.ResultEvent; |
20 | |
import org.kuali.rice.krms.api.engine.Term; |
21 | |
import org.kuali.rice.krms.framework.engine.PropositionResult; |
22 | |
import org.kuali.rice.krms.framework.engine.result.BasicResult; |
23 | |
import org.kuali.student.common.util.krms.RulesExecutionConstants; |
24 | |
import org.kuali.student.common.util.krms.proposition.AbstractLeafProposition; |
25 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
26 | |
import org.kuali.student.r2.common.dto.ValidationResultInfo; |
27 | |
import org.kuali.student.r2.common.exceptions.OperationFailedException; |
28 | |
import org.kuali.student.r2.core.class1.process.context.CourseRegistrationProcessContextInfo; |
29 | |
import org.kuali.student.r2.core.class1.process.evaluator.ProcessEvaluator; |
30 | |
|
31 | |
import java.util.HashMap; |
32 | |
import java.util.List; |
33 | |
import java.util.Map; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public class SubProcessProposition extends AbstractLeafProposition { |
41 | |
|
42 | |
private CourseRegistrationProcessContextInfo checkContext; |
43 | |
private ProcessEvaluator<CourseRegistrationProcessContextInfo> processEvaluator; |
44 | |
|
45 | 0 | public SubProcessProposition(CourseRegistrationProcessContextInfo checkContext, ProcessEvaluator<CourseRegistrationProcessContextInfo> processEvaluator) { |
46 | 0 | this.checkContext = checkContext; |
47 | 0 | this.processEvaluator = processEvaluator; |
48 | 0 | } |
49 | |
|
50 | |
@Override |
51 | |
public PropositionResult evaluate(ExecutionEnvironment environment) { |
52 | |
|
53 | 0 | ContextInfo context = environment.resolveTerm(new Term(RulesExecutionConstants.CONTEXT_INFO_TERM_NAME), this); |
54 | 0 | List<ValidationResultInfo> results = null; |
55 | |
|
56 | 0 | Map<String, Object> resultDetails = new HashMap<String, Object>(); |
57 | |
|
58 | |
try { |
59 | 0 | results = processEvaluator.evaluate(checkContext, context); |
60 | 0 | } catch (OperationFailedException e) { |
61 | |
|
62 | |
|
63 | 0 | resultDetails.put(RulesExecutionConstants.SUBPROCESS_EVALUATION_EXCEPTION, e); |
64 | 0 | environment.getEngineResults().addResult(new BasicResult(resultDetails, ResultEvent.PROPOSITION_EVALUATED, this, environment, false)); |
65 | 0 | return new PropositionResult(false); |
66 | |
|
67 | 0 | } |
68 | |
|
69 | |
|
70 | 0 | resultDetails.put(RulesExecutionConstants.SUBPROCESS_EVALUATION_RESULTS, results); |
71 | |
|
72 | 0 | boolean propositionResult = true; |
73 | 0 | for (ValidationResultInfo evalResult : results) { |
74 | |
|
75 | 0 | if(evalResult.isError()) { |
76 | 0 | propositionResult = false; |
77 | 0 | break; |
78 | |
} |
79 | |
} |
80 | |
|
81 | |
|
82 | 0 | environment.getEngineResults().addResult(new BasicResult(resultDetails, ResultEvent.PROPOSITION_EVALUATED, this, environment, propositionResult)); |
83 | |
|
84 | 0 | return new PropositionResult(propositionResult); |
85 | |
} |
86 | |
|
87 | |
} |