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.EnrolmentInSpecialSituationEvaluation; import net.sourceforge.fenixedu.domain.curricularRules.ICurricularRule; import net.sourceforge.fenixedu.domain.curricularRules.MaximumNumberOfECTSInSpecialSituationEvaluation; 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; import com.linkare.commons.metainfo.Linkare; @Linkare(author = "Paulo Zenida") public class StudentCurricularPlanEnrolmentInSpecialSituationEvaluationManager extends StudentCurricularPlanEnrolment { public StudentCurricularPlanEnrolmentInSpecialSituationEvaluationManager(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.deleteSpecialSituationEvaluation(); } else { throw new DomainException( "StudentCurricularPlanEnrolmentInSpecialSituationEvaluationManager.can.only.manage.enrolment.evaluations.of.enrolments"); } } } @Override protected void addEnroled() { for (final Enrolment enrolment : getStudentCurricularPlan().getSpecialSituationEnrolments(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.hasSpecialSituation()) { curricularRules.add(new EnrolmentInSpecialSituationEvaluation(enrolment)); } curricularRules.add(new MaximumNumberOfECTSInSpecialSituationEvaluation()); result.put(degreeModuleToEvaluate, curricularRules); } else { throw new DomainException( "StudentCurricularPlanEnrolmentInSpecialSituationEvaluationManager.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.hasSpecialSituation()) { enrolment.createSpecialSeasonEvaluation(getResponsiblePerson().getEmployee()); } } else { throw new DomainException( "StudentCurricularPlanEnrolmentInSpecialSituationEvaluationManager.can.only.manage.enrolment.evaluations.of.enrolments"); } } } } } }