View Javadoc

1   package org.kuali.student.krms.termresolver;
2   
3   import org.kuali.rice.krms.api.engine.TermResolutionException;
4   import org.kuali.rice.krms.api.engine.TermResolver;
5   import org.kuali.student.enrollment.academicrecord.dto.StudentProgramRecordInfo;
6   import org.kuali.student.enrollment.academicrecord.service.AcademicRecordService;
7   import org.kuali.student.krms.util.KSKRMSExecutionUtil;
8   import org.kuali.student.r2.common.dto.ContextInfo;
9   import org.kuali.student.r2.core.constants.KSKRMSServiceConstants;
10  
11  import java.util.Collections;
12  import java.util.HashSet;
13  import java.util.List;
14  import java.util.Map;
15  import java.util.Set;
16  
17  /**
18   * Returns true if the student is admitted to the given program.
19   *
20   * From services:
21   * The StudentProgramRecord will indicate admission into a Program. Since there is no program offering and enrollment
22   * services, that's the only path available at this point.
23   *
24   * Example rule statements:
25   * 1) Must have been admitted to the <program> program
26   * 2) Must not have been admitted to the <program> program
27   *
28   * @author Kuali Student Team
29   */
30  public class AdmittedProgramTermResolver implements TermResolver<Boolean> {
31  
32      private AcademicRecordService academicRecordService;
33  
34      @Override
35      public Set<String> getPrerequisites() {
36          Set<String> prereqs = new HashSet<String>(2);
37          prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_PERSON_ID);
38          prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
39          return Collections.unmodifiableSet(prereqs);
40      }
41  
42      @Override
43      public String getOutput() {
44          return KSKRMSServiceConstants.TERM_RESOLVER_ADMITTEDTOPROGRAM;
45      }
46  
47      @Override
48      public Set<String> getParameterNames() {
49          return Collections.singleton(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_CLU_KEY);
50      }
51  
52      @Override
53      public int getCost() {
54          return 0;  //To change body of implemented methods use File | Settings | File Templates.
55      }
56  
57      @Override
58      public Boolean resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException {
59          ContextInfo context = (ContextInfo) resolvedPrereqs.get(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO);
60          String personId = (String) resolvedPrereqs.get(KSKRMSServiceConstants.TERM_PREREQUISITE_PERSON_ID);
61  
62          try {
63              String programId = parameters.get(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_CLU_KEY);
64  
65              //Retrieve the students academic record.
66              List<StudentProgramRecordInfo> programRecords = this.getAcademicRecordService().getProgramRecords(personId, context);
67              for(StudentProgramRecordInfo programRecord : programRecords){
68                  if(programRecord.getProgramId().equals(programId)){
69                      return true;
70                  }
71              }
72          } catch (Exception e) {
73              KSKRMSExecutionUtil.convertExceptionsToTermResolutionException(parameters, e, this);
74          }
75  
76          return false;
77      }
78  
79      public AcademicRecordService getAcademicRecordService() {
80          return academicRecordService;
81      }
82  
83      public void setAcademicRecordService(AcademicRecordService academicRecordService) {
84          this.academicRecordService = academicRecordService;
85      }
86  
87  }