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.enrollment.academicrecord.dto.StudentCourseRecordInfo;
21  import org.kuali.student.r2.common.dto.ContextInfo;
22  import org.kuali.student.r2.common.krms.util.KSKRMSExecutionUtil;
23  import org.kuali.student.r2.core.constants.KSKRMSServiceConstants;
24  import org.kuali.student.r2.lum.lrc.dto.ResultValueInfo;
25  import org.kuali.student.r2.lum.lrc.service.LRCService;
26  
27  import java.util.Collections;
28  import java.util.HashSet;
29  import java.util.List;
30  import java.util.Map;
31  import java.util.Set;
32  
33  /**
34   * Returns true if the student has completed all the courses in the courseset with
35   * a equal or higher grade than the given grade.
36   * <p/>
37   * Rule Statement examples:
38   * 1) Must not have earned a grade of <gradeType> <grade> or higher in <course>
39   * 2) Must have earned a minimum grade of <gradeType> <grade> in <course>
40   *
41   * @author Kuali Student Team
42   */
43  public class CourseWithGradeTermResolver implements TermResolver<Boolean> {
44  
45      private LRCService lrcService;
46  
47      private TermResolver<List<StudentCourseRecordInfo>> courseRecordsForCourseIdTermResolver;
48  
49      @Override
50      public Set<String> getPrerequisites() {
51          Set<String> prereqs = new HashSet<String>(2);
52          prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_PERSON_ID);
53          prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
54          return Collections.unmodifiableSet(prereqs);
55      }
56  
57      @Override
58      public String getOutput() {
59          return KSKRMSServiceConstants.TERM_RESOLVER_COURSEWITHGRADE;
60      }
61  
62      @Override
63      public Set<String> getParameterNames() {
64          Set<String> temp = new HashSet<String>(3);
65          temp.add(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_CLU_KEY);
66          temp.add(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_GRADE_KEY);
67          temp.add(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_GRADE_TYPE_KEY);
68          return Collections.unmodifiableSet(temp);
69      }
70  
71      @Override
72      public int getCost() {
73          return 5;
74      }
75  
76      @Override
77      public Boolean resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException {
78          ContextInfo context = (ContextInfo) resolvedPrereqs.get(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
79          String gradeType = parameters.get(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_GRADE_TYPE_KEY);
80          String grade = parameters.get(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_GRADE_KEY);
81  
82          try {
83  
84              ResultValueInfo gradeValue = this.getLrcService().getResultValue(grade, context);
85              Integer gradeNumericValue = Integer.valueOf(gradeValue.getNumericValue());
86  
87              //Retrieve the list of cluIds from the cluset.
88              List<StudentCourseRecordInfo> courseRecords = this.getCourseRecordsForCourseIdTermResolver().resolve(resolvedPrereqs, parameters);
89              for (StudentCourseRecordInfo courseRecord : courseRecords) {
90                  if (gradeType.equals(courseRecord.getAssignedGradeScaleKey())) {
91                      ResultValueInfo resultValue = this.getLrcService().getResultValue(courseRecord.getAssignedGradeValue(), context);
92                      Integer resultNumericValue = Integer.valueOf(resultValue.getNumericValue());
93                      if(resultNumericValue>=gradeNumericValue){
94                          return true;
95                      }
96                  }
97              }
98  
99          } catch (Exception e) {
100             KSKRMSExecutionUtil.convertExceptionsToTermResolutionException(parameters, e, this);
101         }
102 
103         return false;
104     }
105 
106     public LRCService getLrcService() {
107         return lrcService;
108     }
109 
110     public void setLrcService(LRCService lrcService) {
111         this.lrcService = lrcService;
112     }
113 
114     public TermResolver<List<StudentCourseRecordInfo>> getCourseRecordsForCourseIdTermResolver() {
115         return courseRecordsForCourseIdTermResolver;
116     }
117 
118     public void setCourseRecordsForCourseIdTermResolver(TermResolver<List<StudentCourseRecordInfo>> courseRecordsForCourseIdTermResolver) {
119         this.courseRecordsForCourseIdTermResolver = courseRecordsForCourseIdTermResolver;
120     }
121 
122 }