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.common.util.krms.RulesExecutionConstants;
21  import org.kuali.student.enrollment.academicrecord.dto.StudentCourseRecordInfo;
22  import org.kuali.student.enrollment.academicrecord.service.AcademicRecordService;
23  import org.kuali.student.krms.util.KSKRMSExecutionConstants;
24  import org.kuali.student.krms.util.KSKRMSExecutionUtil;
25  import org.kuali.student.r2.common.dto.ContextInfo;
26  import org.kuali.student.r2.common.exceptions.InvalidParameterException;
27  import org.kuali.student.r2.common.exceptions.MissingParameterException;
28  import org.kuali.student.r2.common.exceptions.OperationFailedException;
29  import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
30  import org.kuali.student.r2.core.atp.dto.MilestoneInfo;
31  import org.kuali.student.r2.core.atp.service.AtpService;
32  
33  import java.util.Calendar;
34  import java.util.Collections;
35  import java.util.Date;
36  import java.util.HashSet;
37  import java.util.List;
38  import java.util.Map;
39  import java.util.Set;
40  
41  public class NumberOfCreditsTermResolver implements TermResolver<String> {	
42  
43      private AcademicRecordService academicRecordService;
44      
45      
46      public AcademicRecordService getAcademicRecordService() {
47          return academicRecordService;
48      }
49  
50      public void setAcademicRecordService(AcademicRecordService academicRecordService) {
51          this.academicRecordService = academicRecordService;
52      }
53  
54      @Override
55      public Set<String> getPrerequisites() {
56          return Collections.singleton(RulesExecutionConstants.CONTEXT_INFO_TERM_NAME);
57      }
58  
59      @Override
60      public String getOutput() {
61          return "NumberOfCreditsTermResolver.getOutput()";
62      }
63  
64      @Override
65      public Set<String> getParameterNames() {
66          Set<String> temp = new HashSet<String>(1);
67          temp.add(KSKRMSExecutionConstants.PERSON_ID_TERM_PROPERTY);
68          temp.add(KSKRMSExecutionConstants.CALC_TYPE_KEY_TERM_PROPERTY);
69          return Collections.unmodifiableSet(temp);
70      }
71  
72      @Override
73      public int getCost() {
74          // TODO Analyze, though probably not much to check here
75          return 5;
76      }
77  
78      @Override
79      public String resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException {
80          ContextInfo context = (ContextInfo) resolvedPrereqs.get(RulesExecutionConstants.CONTEXT_INFO_TERM_NAME);
81          String personId = parameters.get(KSKRMSExecutionConstants.PERSON_ID_TERM_PROPERTY);
82          String calcTypeKeyId = parameters.get(KSKRMSExecutionConstants.CALC_TYPE_KEY_TERM_PROPERTY);
83          
84          String result = null;
85          try {
86              result = academicRecordService.getEarnedCredits(personId, calcTypeKeyId, context);
87          } catch (Exception e) {
88              KSKRMSExecutionUtil.convertExceptionsToTermResolutionException(parameters, e, this);
89          }
90          return result;
91      }
92  }