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.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.krms.util.KSKRMSExecutionUtil;
21  import org.kuali.student.r2.common.dto.ContextInfo;
22  import org.kuali.student.r2.core.constants.KSKRMSServiceConstants;
23  
24  import java.util.Collections;
25  import java.util.HashSet;
26  import java.util.List;
27  import java.util.Map;
28  import java.util.Set;
29  
30  /**
31   * Return the number of completed courses from a given course list.
32   *
33   * The "list of courses" is obtained from a courseSetId passed as a parameter. The CluService is used to retrieve
34   * courseCodes from the courseSetId.
35   *
36   * The studentId is passed as a resolvedPrereq.
37   *
38   * @author Kuali Student Team
39   */
40  public class NumberOfCompletedCoursesTermResolver implements TermResolver<Integer> {
41  
42      private TermResolver<List<String>> cluIdsInCluSetTermResolver;
43      private TermResolver<Boolean> completedCourseTermResolver;
44  
45      @Override
46      public Set<String> getPrerequisites() {
47          Set<String> temp = new HashSet<String>(2);
48          temp.add(KSKRMSServiceConstants.TERM_PREREQUISITE_PERSON_ID);
49          temp.add(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
50          return Collections.unmodifiableSet(temp);
51      }
52  
53      @Override
54      public String getOutput() {
55          return KSKRMSServiceConstants.TERM_RESOLVER_NUMBEROFCOMPLETEDCOURSES;
56      }
57  
58      @Override
59      public Set<String> getParameterNames() {
60          return Collections.singleton(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_CLUSET_KEY);
61      }
62  
63      @Override
64      public int getCost() {
65          return 5;
66      }
67  
68      @Override
69      public Integer resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException {
70          //Create a counter so that we can check that the student completed all of the courses.
71          int clusCompleted = 0;
72          ContextInfo context = (ContextInfo) resolvedPrereqs.get(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
73          String personId = (String) resolvedPrereqs.get(KSKRMSServiceConstants.TERM_PREREQUISITE_PERSON_ID);
74          try {
75              ///Retrieve the list of cluIds from the cluset.
76              List<String> versionIndIds = this.getCluIdsInCluSetTermResolver().resolve(resolvedPrereqs, parameters);
77              for(String versionIndId : versionIndIds){
78                  parameters.put(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_CLU_KEY, versionIndId);
79                  if(this.getCompletedCourseTermResolver().resolve(resolvedPrereqs, parameters)){
80                      clusCompleted++;
81                  }
82              }
83          } catch (Exception e) {
84              KSKRMSExecutionUtil.convertExceptionsToTermResolutionException(parameters, e, this);
85          }
86  
87          return clusCompleted;
88      }
89  
90      public TermResolver<List<String>> getCluIdsInCluSetTermResolver() {
91          return cluIdsInCluSetTermResolver;
92      }
93  
94      public void setCluIdsInCluSetTermResolver(TermResolver<List<String>> cluIdsInCluSetTermResolver) {
95          this.cluIdsInCluSetTermResolver = cluIdsInCluSetTermResolver;
96      }
97  
98      public TermResolver<Boolean> getCompletedCourseTermResolver() {
99          return completedCourseTermResolver;
100     }
101 
102     public void setCompletedCourseTermResolver(TermResolver<Boolean> completedCourseTermResolver) {
103         this.completedCourseTermResolver = completedCourseTermResolver;
104     }
105 }