001/** 002 * Copyright 2011 The Kuali Foundation Licensed under the 003 * Educational Community License, Version 2.0 (the "License"); you may 004 * not use this file except in compliance with the License. You may 005 * obtain a copy of the License at 006 * 007 * http://www.osedu.org/licenses/ECL-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, 010 * software distributed under the License is distributed on an "AS IS" 011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 012 * or implied. See the License for the specific language governing 013 * permissions and limitations under the License. 014 */ 015 016package org.kuali.student.enrollment.class2.courseoffering.krms.termresolver; 017 018import org.kuali.rice.krms.api.engine.TermResolutionException; 019import org.kuali.rice.krms.api.engine.TermResolver; 020import org.kuali.student.r2.common.krms.util.KSKRMSExecutionUtil; 021import org.kuali.student.r2.core.constants.KSKRMSServiceConstants; 022 023import java.util.Collections; 024import java.util.HashSet; 025import java.util.List; 026import java.util.Map; 027import java.util.Set; 028 029/** 030 * This TermResolver returns TRUE if a student has passed all the courses in the list of courses passed as a parameter. 031 * 032 * The "list of courses" is obtained from a courseSetId passed as a parameter. The CluService is used to retrieve 033 * courseCodes from the courseSetId. 034 * 035 * The studentId is passed as a resolvedPrereq. 036 * 037 */ 038public class CompletedCoursesTermResolver implements TermResolver<Boolean> { 039 040 private TermResolver<List<String>> cluIdsInCluSetTermResolver; 041 private TermResolver<Boolean> completedCourseTermResolver; 042 043 @Override 044 public Set<String> getPrerequisites() { 045 Set<String> prereqs = new HashSet<String>(2); 046 prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_PERSON_ID); 047 prereqs.add(KSKRMSServiceConstants.TERM_PREREQUISITE_CONTEXTINFO); 048 return Collections.unmodifiableSet(prereqs); 049 } 050 051 @Override 052 public String getOutput() { 053 return KSKRMSServiceConstants.TERM_RESOLVER_COMPLETEDCOURSES; 054 } 055 056 @Override 057 public Set<String> getParameterNames() { 058 return Collections.singleton(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_CLUSET_KEY); 059 } 060 061 @Override 062 public int getCost() { 063 return 5; 064 } 065 066 @Override 067 public Boolean resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException { 068 try { 069 //Retrieve the list of cluIds from the cluset. 070 List<String> versionIndIds = this.getCluIdsInCluSetTermResolver().resolve(resolvedPrereqs, parameters); 071 for(String versionIndId : versionIndIds){ 072 parameters.put(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_CLU_KEY, versionIndId); 073 if(!this.getCompletedCourseTermResolver().resolve(resolvedPrereqs, parameters)){ 074 return false; 075 } 076 } 077 } catch (Exception e) { 078 KSKRMSExecutionUtil.convertExceptionsToTermResolutionException(parameters, e, this); 079 } 080 081 return true; 082 } 083 084 public TermResolver<List<String>> getCluIdsInCluSetTermResolver() { 085 return cluIdsInCluSetTermResolver; 086 } 087 088 public void setCluIdsInCluSetTermResolver(TermResolver<List<String>> cluIdsInCluSetTermResolver) { 089 this.cluIdsInCluSetTermResolver = cluIdsInCluSetTermResolver; 090 } 091 092 public TermResolver<Boolean> getCompletedCourseTermResolver() { 093 return completedCourseTermResolver; 094 } 095 096 public void setCompletedCourseTermResolver(TermResolver<Boolean> completedCourseTermResolver) { 097 this.completedCourseTermResolver = completedCourseTermResolver; 098 } 099}