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.service.AcademicRecordService;
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  
25  import java.util.Collections;
26  import java.util.HashSet;
27  import java.util.Map;
28  import java.util.Set;
29  
30  /**
31   *
32   * Rule statement examples:
33   * 1) Must have earned a minimum Cumulative GPA of <GPA> in <durationCount><durationType>
34   *
35   * @author Kuali Student Team
36   */
37  public class GPAForDurationTermResolver implements TermResolver<Float> {
38  
39      private AcademicRecordService academicRecordService;
40  
41      @Override
42      public Set<String> getPrerequisites() {
43          Set<String> prereqs = new HashSet<String>(2);
44          prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_PERSON_ID);
45          prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
46          return Collections.unmodifiableSet(prereqs);
47      }
48  
49      @Override
50      public String getOutput() {
51          return KSKRMSServiceConstants.TERM_RESOLVER_GPAFORDURATION;
52      }
53  
54      @Override
55      public Set<String> getParameterNames() {
56          return Collections.emptySet();//Collections.singleton(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_CLU_KEY);
57      }
58  
59      @Override
60      public int getCost() {
61          return 5;
62      }
63  
64      @Override
65      public Float resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException {
66          ContextInfo context = (ContextInfo) resolvedPrereqs.get(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
67          String personId = (String) resolvedPrereqs.get(KSKRMSServiceConstants.TERM_PREREQUISITE_PERSON_ID);
68          //String courseId = parameters.get(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_CLU_KEY);
69  
70          Float result = null;
71          try {
72              //GPAInfo cumulativeGPA = academicRecordService.getCumulativeGPA(personId, AcademicRecordServiceConstants.ACADEMIC_RECORD_CALCULATION_GPA_TYPE_KEY, context);
73              //result = Float.parseFloat(cumulativeGPA.getValue());
74          } catch (Exception e) {
75              KSKRMSExecutionUtil.convertExceptionsToTermResolutionException(parameters, e, this);
76          }
77  
78          return result;
79      }
80  
81      public AcademicRecordService getAcademicRecordService() {
82          return academicRecordService;
83      }
84  
85      public void setAcademicRecordService(AcademicRecordService academicRecordService) {
86          this.academicRecordService = academicRecordService;
87      }
88  }