1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class2.courseoffering.krms.proposition;
17
18 import java.util.ArrayList;
19 import java.util.Date;
20 import java.util.HashSet;
21 import java.util.List;
22 import java.util.Set;
23
24 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
25 import org.kuali.rice.krms.api.engine.Term;
26 import org.kuali.rice.krms.framework.engine.Proposition;
27 import org.kuali.rice.krms.framework.engine.PropositionResult;
28 import org.kuali.student.enrollment.academicrecord.dto.StudentCourseRecordInfo;
29 import org.kuali.student.enrollment.academicrecord.service.AcademicRecordService;
30 import org.kuali.student.r2.core.constants.KSKRMSServiceConstants;
31 import org.kuali.student.r2.common.dto.ContextInfo;
32 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
33 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
34 import org.kuali.student.r2.common.exceptions.MissingParameterException;
35 import org.kuali.student.r2.common.exceptions.OperationFailedException;
36 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
37 import org.kuali.student.r2.core.atp.dto.AtpInfo;
38 import org.kuali.student.r2.core.atp.service.AtpService;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58 public class CompletedCourseBetweenTermsProposition implements Proposition {
59
60 private static final Logger log = LoggerFactory.getLogger(CompletedCourseBetweenTermsProposition.class);
61
62 private Term studentTerm = new Term(KSKRMSServiceConstants.TERM_TYPE_STUDENT_ID);
63
64 private Term courseTerm = new Term(KSKRMSServiceConstants.TERM_TYPE_COURSE_ID);
65
66 private Term startDateTerm = new Term (KSKRMSServiceConstants.TERM_TYPE_START_DATE);
67
68 private Term endDateTerm = new Term (KSKRMSServiceConstants.TERM_TYPE_END_DATE);
69
70 private final AcademicRecordService recordService;
71
72 private final AtpService atpService;
73
74
75
76
77
78
79
80 public CompletedCourseBetweenTermsProposition(AtpService atpService, AcademicRecordService recordService) {
81 super();
82 this.recordService = recordService;
83 this.atpService = atpService;
84 }
85
86
87
88
89
90
91 @Override
92 public PropositionResult evaluate(ExecutionEnvironment environment) {
93
94
95 String studentId = environment.resolveTerm(studentTerm, this);
96
97 String courseId = environment.resolveTerm(courseTerm, this);
98
99 Date startDateRange = environment.resolveTerm(startDateTerm, this);
100
101 Date endDateRange = environment.resolveTerm(endDateTerm, this);
102
103 ContextInfo contextInfo = new ContextInfo();
104 contextInfo.setCurrentDate(new Date());
105 contextInfo.setAuthenticatedPrincipalId("test-krms");
106 contextInfo.setPrincipalId("test-krms");
107
108 boolean exception = false;
109 boolean matchedTerm = false;
110
111 try {
112 List<StudentCourseRecordInfo> completedCourses = recordService.getCompletedCourseRecordsForCourse(studentId, courseId, contextInfo);
113
114
115 List<AtpInfo> atps = atpService.getAtpsByDates(startDateRange, endDateRange, contextInfo);
116
117 Set<String>atpNames = new HashSet<String>();
118
119
120 for (AtpInfo atpInfo : atps) {
121
122
123 atpNames.add(atpInfo.getName());
124 }
125
126
127
128 for (StudentCourseRecordInfo courseRecordInfo : completedCourses) {
129
130
131
132
133
134 if (atpNames.contains(courseRecordInfo.getTermName())) {
135
136 matchedTerm = true;
137 break;
138 }
139
140 }
141
142
143
144 } catch (DoesNotExistException e) {
145 log.error("exception = ", e);
146 exception = true;
147 } catch (InvalidParameterException e) {
148 log.error("exception = ", e);
149 exception = true;
150 } catch (MissingParameterException e) {
151 log.error("exception = ", e);
152 exception = true;
153 } catch (OperationFailedException e) {
154 log.error("exception = ", e);
155 exception = true;
156 } catch (PermissionDeniedException e) {
157 log.error("exception = ", e);
158 exception = true;
159
160 }
161
162 if (exception) {
163
164 return new PropositionResult(false);
165 }
166 else {
167
168 if (matchedTerm)
169 return new PropositionResult(true);
170 else
171 return new PropositionResult(false);
172 }
173 }
174
175
176
177
178
179
180 @Override
181 public List<Proposition> getChildren() {
182
183 return new ArrayList<Proposition>();
184 }
185
186
187
188
189 @Override
190 public boolean isCompound() {
191
192 return false;
193 }
194
195 }