1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.process.poc.krms.termresolver; |
17 | |
|
18 | |
import org.kuali.rice.krms.api.engine.TermResolutionException; |
19 | |
import org.kuali.rice.krms.api.engine.TermResolver; |
20 | |
import org.kuali.student.common.util.krms.RulesExecutionConstants; |
21 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
22 | |
import org.kuali.student.r2.common.exceptions.InvalidParameterException; |
23 | |
import org.kuali.student.r2.common.exceptions.MissingParameterException; |
24 | |
import org.kuali.student.r2.common.exceptions.OperationFailedException; |
25 | |
import org.kuali.student.r2.common.exceptions.PermissionDeniedException; |
26 | |
import org.kuali.student.r2.core.hold.dto.HoldInfo; |
27 | |
import org.kuali.student.r2.core.hold.service.HoldService; |
28 | |
|
29 | |
import java.util.ArrayList; |
30 | |
import java.util.Collections; |
31 | |
import java.util.HashSet; |
32 | |
import java.util.List; |
33 | |
import java.util.Map; |
34 | |
import java.util.Set; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 0 | public class RegistrationHoldsTermResolver implements TermResolver<List<HoldInfo>> { |
44 | |
|
45 | |
private HoldService holdService; |
46 | |
|
47 | 0 | private final static Set<String> prerequisites = new HashSet<String>(2); |
48 | |
|
49 | |
static { |
50 | 0 | prerequisites.add(RulesExecutionConstants.STUDENT_ID_TERM_NAME); |
51 | 0 | prerequisites.add(RulesExecutionConstants.CONTEXT_INFO_TERM_NAME); |
52 | 0 | } |
53 | |
|
54 | |
public void setHoldService(HoldService holdService) { |
55 | 0 | this.holdService = holdService; |
56 | 0 | } |
57 | |
|
58 | |
@Override |
59 | |
public Set<String> getPrerequisites() { |
60 | 0 | return prerequisites; |
61 | |
} |
62 | |
|
63 | |
@Override |
64 | |
public String getOutput() { |
65 | 0 | return RulesExecutionConstants.STUDENT_REGISTRATION_HOLDS_TERM_NAME; |
66 | |
} |
67 | |
|
68 | |
@Override |
69 | |
public Set<String> getParameterNames() { |
70 | 0 | return Collections.singleton(RulesExecutionConstants.ISSUE_KEY_TERM_PROPERTY); |
71 | |
} |
72 | |
|
73 | |
@Override |
74 | |
public int getCost() { |
75 | |
|
76 | 0 | return 0; |
77 | |
} |
78 | |
|
79 | |
@Override |
80 | |
public List<HoldInfo> resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException { |
81 | 0 | String studentId = (String) resolvedPrereqs.get(RulesExecutionConstants.STUDENT_ID_TERM_NAME); |
82 | 0 | ContextInfo context = (ContextInfo) resolvedPrereqs.get(RulesExecutionConstants.CONTEXT_INFO_TERM_NAME); |
83 | 0 | String issueKey = parameters.get(RulesExecutionConstants.ISSUE_KEY_TERM_PROPERTY); |
84 | |
|
85 | |
List<HoldInfo> studentHolds; |
86 | |
|
87 | |
|
88 | |
try { |
89 | 0 | studentHolds = holdService.getActiveHoldsByIssueAndPerson(issueKey, studentId, context); |
90 | 0 | } catch (InvalidParameterException e) { |
91 | 0 | throw new TermResolutionException(e.getMessage(), this, parameters); |
92 | 0 | } catch (MissingParameterException e) { |
93 | 0 | throw new TermResolutionException(e.getMessage(), this, parameters); |
94 | 0 | } catch (OperationFailedException e) { |
95 | 0 | throw new TermResolutionException(e.getMessage(), this, parameters); |
96 | 0 | } catch (PermissionDeniedException e) { |
97 | 0 | throw new TermResolutionException(e.getMessage(), this, parameters); |
98 | 0 | } |
99 | |
|
100 | 0 | return studentHolds; |
101 | |
} |
102 | |
} |