View Javadoc

1   /**
2    * Copyright 2011 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.student.enrollment.class2.courseoffering.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.r2.common.krms.util.KSKRMSExecutionUtil;
21  import org.kuali.student.r2.core.constants.KSKRMSServiceConstants;
22  
23  import java.util.Collections;
24  import java.util.HashSet;
25  import java.util.List;
26  import java.util.Map;
27  import java.util.Set;
28  
29  /**
30   * This TermResolver returns TRUE if a student has passed all the courses in the list of courses passed as a parameter.
31   *
32   * The "list of courses" is obtained from a courseSetId passed as a parameter. The CluService is used to retrieve
33   * courseCodes from the courseSetId.
34   *
35   * The studentId is passed as a resolvedPrereq.
36   *
37   */
38  public class CompletedCoursesTermResolver implements TermResolver<Boolean> {
39  
40      private TermResolver<List<String>> cluIdsInCluSetTermResolver;
41      private TermResolver<Boolean> completedCourseTermResolver;
42  
43      @Override
44      public Set<String> getPrerequisites() {
45          Set<String> prereqs = new HashSet<String>(2);
46          prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_PERSON_ID);
47          prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
48          return Collections.unmodifiableSet(prereqs);
49      }
50  
51      @Override
52      public String getOutput() {
53          return KSKRMSServiceConstants.TERM_RESOLVER_COMPLETEDCOURSES;
54      }
55  
56      @Override
57      public Set<String> getParameterNames() {
58          return Collections.singleton(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_CLUSET_KEY);
59      }
60  
61      @Override
62      public int getCost() {
63          return 5;
64      }
65  
66      @Override
67      public Boolean resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException {
68          try {
69              //Retrieve the list of cluIds from the cluset.
70              List<String> versionIndIds = this.getCluIdsInCluSetTermResolver().resolve(resolvedPrereqs, parameters);
71              for(String versionIndId : versionIndIds){
72                  parameters.put(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_CLU_KEY, versionIndId);
73                  if(!this.getCompletedCourseTermResolver().resolve(resolvedPrereqs, parameters)){
74                      return false;
75                  }
76              }
77          } catch (Exception e) {
78              KSKRMSExecutionUtil.convertExceptionsToTermResolutionException(parameters, e, this);
79          }
80  
81          return true;
82      }
83  
84      public TermResolver<List<String>> getCluIdsInCluSetTermResolver() {
85          return cluIdsInCluSetTermResolver;
86      }
87  
88      public void setCluIdsInCluSetTermResolver(TermResolver<List<String>> cluIdsInCluSetTermResolver) {
89          this.cluIdsInCluSetTermResolver = cluIdsInCluSetTermResolver;
90      }
91  
92      public TermResolver<Boolean> getCompletedCourseTermResolver() {
93          return completedCourseTermResolver;
94      }
95  
96      public void setCompletedCourseTermResolver(TermResolver<Boolean> completedCourseTermResolver) {
97          this.completedCourseTermResolver = completedCourseTermResolver;
98      }
99  }