1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.process.poc.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.core.hold.dto.HoldInfo; |
26 | |
|
27 | |
import java.util.ArrayList; |
28 | |
import java.util.Collections; |
29 | |
import java.util.List; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
public class RegistrationHoldProposition extends AbstractLeafProposition { |
37 | |
|
38 | |
private final String issueKey; |
39 | |
|
40 | 0 | public RegistrationHoldProposition(String issueKey) { |
41 | 0 | this.issueKey = issueKey; |
42 | 0 | } |
43 | |
|
44 | |
@Override |
45 | |
public PropositionResult evaluate(ExecutionEnvironment environment) { |
46 | |
|
47 | |
|
48 | 0 | Term studentRegistrationHoldsTerm = new Term(RulesExecutionConstants.STUDENT_REGISTRATION_HOLDS_TERM_NAME, Collections.singletonMap(RulesExecutionConstants.ISSUE_KEY_TERM_PROPERTY, issueKey)); |
49 | 0 | List<HoldInfo> studentRegistrationHolds = environment.resolveTerm(studentRegistrationHoldsTerm, this); |
50 | |
|
51 | 0 | PropositionResult result = null; |
52 | |
|
53 | 0 | if(studentRegistrationHolds.isEmpty()) { |
54 | 0 | result = new PropositionResult(true); |
55 | |
} |
56 | |
else { |
57 | 0 | List<HoldInfo> blockingHolds = new ArrayList<HoldInfo>(); |
58 | 0 | List<HoldInfo> warningHolds = new ArrayList<HoldInfo>(); |
59 | |
|
60 | |
|
61 | 0 | for(HoldInfo hold : studentRegistrationHolds) { |
62 | 0 | if(hold.getIsWarning()) { |
63 | 0 | warningHolds.add(hold); |
64 | |
} |
65 | |
else { |
66 | 0 | blockingHolds.add(hold); |
67 | |
} |
68 | |
} |
69 | |
|
70 | |
|
71 | 0 | result = new PropositionResult(blockingHolds.isEmpty()); |
72 | |
|
73 | |
|
74 | 0 | if(!warningHolds.isEmpty()) { |
75 | 0 | List<String> warningHoldIds = (List<String>) environment.getEngineResults().getAttribute(RulesExecutionConstants.REGISTRATION_HOLD_WARNINGS_ATTRIBUTE); |
76 | 0 | if(warningHoldIds == null) { |
77 | 0 | warningHoldIds = new ArrayList<String>(warningHolds.size()); |
78 | |
} |
79 | |
|
80 | 0 | for(HoldInfo hold : warningHolds) { |
81 | 0 | warningHoldIds.add(hold.getId()); |
82 | |
} |
83 | |
|
84 | 0 | environment.getEngineResults().setAttribute(RulesExecutionConstants.REGISTRATION_HOLD_WARNINGS_ATTRIBUTE, warningHoldIds); |
85 | |
} |
86 | |
} |
87 | |
|
88 | 0 | environment.getEngineResults().addResult(new BasicResult(ResultEvent.PropositionEvaluated, this, environment, result.getResult())); |
89 | |
|
90 | 0 | return result; |
91 | |
} |
92 | |
} |