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.common.util.krms.proposition;
017
018import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
019import org.kuali.rice.krms.api.engine.Term;
020import org.kuali.student.common.util.krms.RulesExecutionConstants;
021
022import java.util.Collection;
023import java.util.Collections;
024
025/**
026 * Proposition that checks for current enrollment in a set of courses
027 *
028 * @author alubbers
029 */
030public class CourseSetEnrollmentProposition extends CourseEnrollmentProposition {
031
032    private String courseSetId;
033
034    private Collection<String> courseIds;
035
036    public CourseSetEnrollmentProposition(String courseSetId, Integer minToEnroll) {
037        super(minToEnroll);
038        this.courseSetId = courseSetId;
039    }
040
041    public CourseSetEnrollmentProposition(String courseSetId) {
042        super();
043        this.courseSetId = courseSetId;
044    }
045
046    @Override
047    protected Collection<String> getRequiredCourseIds(ExecutionEnvironment environment) {
048
049        if(courseIds == null) {
050
051            Term term = new Term(RulesExecutionConstants.COURSE_SET_TERM_NAME, Collections.singletonMap(RulesExecutionConstants.COURSE_SET_ID_TERM_PROPERTY, courseSetId));
052
053            courseIds = environment.resolveTerm(term, this);
054        }
055
056        return courseIds;
057    }
058}