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.krms.termresolver;
017
018import org.kuali.rice.krms.api.engine.TermResolutionException;
019import org.kuali.rice.krms.api.engine.TermResolver;
020import org.kuali.student.common.util.krms.RulesExecutionConstants;
021import org.kuali.student.enrollment.academicrecord.dto.StudentCourseRecordInfo;
022import org.kuali.student.enrollment.courseregistration.dto.CourseRegistrationInfo;
023import org.kuali.student.enrollment.courseregistration.service.CourseRegistrationService;
024import org.kuali.student.krms.util.KSKRMSExecutionConstants;
025import org.kuali.student.krms.util.KSKRMSExecutionUtil;
026import org.kuali.student.r2.common.dto.ContextInfo;
027import org.kuali.student.r2.common.exceptions.InvalidParameterException;
028import org.kuali.student.r2.common.exceptions.MissingParameterException;
029import org.kuali.student.r2.common.exceptions.OperationFailedException;
030import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
031import org.kuali.student.r2.core.atp.dto.MilestoneInfo;
032import org.kuali.student.r2.core.atp.service.AtpService;
033
034import java.util.Calendar;
035import java.util.Collections;
036import java.util.Date;
037import java.util.HashSet;
038import java.util.List;
039import java.util.Map;
040import java.util.Set;
041
042public class EnrolledEffectiveDateToTermResolver implements TermResolver<List<CourseRegistrationInfo>> {    
043
044    private CourseRegistrationService courseRegistrationService;
045    
046    
047    public CourseRegistrationService getAcademicRecordService() {
048        return courseRegistrationService;
049    }
050
051    public void setCourseRegistrationService(CourseRegistrationService courseRegistrationService) {
052        this.courseRegistrationService = courseRegistrationService;
053    }
054
055    @Override
056    public Set<String> getPrerequisites() {
057        return Collections.singleton(RulesExecutionConstants.CONTEXT_INFO_TERM_NAME);
058    }
059
060    @Override
061    public String getOutput() {
062        return "EnrolledEffectiveDateToTermResolver.getOutput()";
063    }
064
065    @Override
066    public Set<String> getParameterNames() {
067        Set<String> temp = new HashSet<String>(1);
068        temp.add(KSKRMSExecutionConstants.PERSON_ID_TERM_PROPERTY);
069        return Collections.unmodifiableSet(temp);
070    }
071
072    @Override
073    public int getCost() {
074        // TODO Analyze, though probably not much to check here
075        return 5;
076    }
077
078    @Override
079    public List<CourseRegistrationInfo> resolve(Map<String, Object> resolvedPrereqs, Map<String, String> parameters) throws TermResolutionException {
080        ContextInfo context = (ContextInfo) resolvedPrereqs.get(RulesExecutionConstants.CONTEXT_INFO_TERM_NAME);
081        String personId = parameters.get(KSKRMSExecutionConstants.PERSON_ID_TERM_PROPERTY);
082        String termId = parameters.get(KSKRMSExecutionConstants.TERM_ID_TERM_PROPERTY);
083        
084        List<CourseRegistrationInfo> result = null;
085        try {
086            result = courseRegistrationService.getCourseRegistrationsByStudentAndTerm(personId, termId, context);
087        } catch (Exception e) {
088            KSKRMSExecutionUtil.convertExceptionsToTermResolutionException(parameters, e, this);
089        }
090        return result;
091    }
092}