package net.sourceforge.fenixedu.domain.studentCurriculum; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.Map.Entry; import net.sourceforge.fenixedu.domain.Enrolment; import net.sourceforge.fenixedu.domain.curricularRules.EnrolmentInSpecialSeasonEvaluation; import net.sourceforge.fenixedu.domain.curricularRules.ICurricularRule; import net.sourceforge.fenixedu.domain.curricularRules.MaximumNumberOfECTSInSpecialSeasonEvaluation; import net.sourceforge.fenixedu.domain.curricularRules.executors.ruleExecutors.EnrolmentResultType; import net.sourceforge.fenixedu.domain.enrolment.EnroledCurriculumModuleWrapper; import net.sourceforge.fenixedu.domain.enrolment.EnrolmentContext; import net.sourceforge.fenixedu.domain.enrolment.IDegreeModuleToEvaluate; import net.sourceforge.fenixedu.domain.exceptions.DomainException; public class StudentCurricularPlanEnrolmentInSpecialSeasonEvaluationManager extends StudentCurricularPlanEnrolment { public StudentCurricularPlanEnrolmentInSpecialSeasonEvaluationManager(final EnrolmentContext enrolmentContext) { super(enrolmentContext); } @Override protected void assertEnrolmentPreConditions() { if (!isResponsiblePersonManager() && !getRegistration().isRegistered(getExecutionSemester())) { throw new DomainException("error.StudentCurricularPlan.cannot.enrol.with.registration.inactive"); } super.assertEnrolmentPreConditions(); } @Override protected void unEnrol() { for (final CurriculumModule curriculumModule : enrolmentContext.getToRemove()) { if (curriculumModule instanceof Enrolment) { final Enrolment enrolment = (Enrolment) curriculumModule; enrolment.deleteSpecialSeasonEvaluation(); } else { throw new DomainException( "StudentCurricularPlanEnrolmentInSpecialSeasonEvaluationManager.can.only.manage.enrolment.evaluations.of.enrolments"); } } } @Override protected void addEnroled() { for (final Enrolment enrolment : getStudentCurricularPlan().getSpecialSeasonEnrolments(getExecutionYear())) { enrolmentContext.addDegreeModuleToEvaluate(new EnroledCurriculumModuleWrapper(enrolment, getExecutionSemester())); } } @Override protected Map> getRulesToEvaluate() { final Map> result = new HashMap>(); for (final IDegreeModuleToEvaluate degreeModuleToEvaluate : enrolmentContext.getDegreeModulesToEvaluate()) { if (degreeModuleToEvaluate.isEnroled() && degreeModuleToEvaluate.canCollectRules()) { final EnroledCurriculumModuleWrapper moduleEnroledWrapper = (EnroledCurriculumModuleWrapper) degreeModuleToEvaluate; if (moduleEnroledWrapper.getCurriculumModule() instanceof Enrolment) { final Enrolment enrolment = (Enrolment) moduleEnroledWrapper.getCurriculumModule(); final Set curricularRules = new HashSet(); if (!enrolment.hasSpecialSeason()) { curricularRules.add(new EnrolmentInSpecialSeasonEvaluation(enrolment)); } curricularRules.add(new MaximumNumberOfECTSInSpecialSeasonEvaluation()); result.put(degreeModuleToEvaluate, curricularRules); } else { throw new DomainException( "StudentCurricularPlanEnrolmentInSpecialSeasonEvaluationManager.can.only.manage.enrolment.evaluations.of.enrolments"); } } } return result; } @Override protected void performEnrolments(final Map> degreeModulesToEvaluate) { for (final Entry> entry : degreeModulesToEvaluate.entrySet()) { for (final IDegreeModuleToEvaluate degreeModuleToEvaluate : entry.getValue()) { if (degreeModuleToEvaluate.isEnroled()) { final EnroledCurriculumModuleWrapper moduleEnroledWrapper = (EnroledCurriculumModuleWrapper) degreeModuleToEvaluate; if (moduleEnroledWrapper.getCurriculumModule() instanceof Enrolment) { final Enrolment enrolment = (Enrolment) moduleEnroledWrapper.getCurriculumModule(); if (!enrolment.hasSpecialSeason()) { enrolment.createSpecialSeasonEvaluation(getResponsiblePerson().getEmployee()); } } else { throw new DomainException( "StudentCurricularPlanEnrolmentInSpecialSeasonEvaluationManager.can.only.manage.enrolment.evaluations.of.enrolments"); } } } } } }