package net.sourceforge.fenixedu.domain.studentCurriculum; import java.util.Collection; import java.util.HashSet; import java.util.Set; import net.sourceforge.fenixedu.dataTransferObject.administrativeOffice.dismissal.ISCTEDismissalBean.SelectedCurriculumEntry; import net.sourceforge.fenixedu.domain.Enrolment; import net.sourceforge.fenixedu.domain.ExecutionYear; import net.sourceforge.fenixedu.domain.IEnrolment; import net.sourceforge.fenixedu.domain.RootDomainObject; import net.sourceforge.fenixedu.domain.StudentCurricularPlan; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.student.curriculum.ICurriculumEntry; /** * * @author rjmvo * */ public class Certification extends Certification_Base { public Certification() { super(); setRootDomainObject(RootDomainObject.getInstance()); } public Certification(StudentCurricularPlan scp, ExecutionYear executionYear, Collection enrolments) { this(); init(scp, executionYear, enrolments); } protected void init(StudentCurricularPlan scp, ExecutionYear executionYear, Collection enrolments) { if (executionYear == null || scp == null) { throw new DomainException("error.certification.wrong.arguments"); } if (enrolments == null || enrolments.isEmpty()) { throw new DomainException("error.certification.wrong.arguments"); } setExecutionYear(executionYear); setStudentCurricularPlan(scp); addEnrolmentsEntries(enrolments); } private void addEnrolmentsEntries(Collection entries) { for (final SelectedCurriculumEntry entry : entries) { if (entry.getCurriculumEntry() instanceof Dismissal) { new ISCTEDismissalWrapper(this, (Dismissal) entry.getCurriculumEntry()); } else if (!(entry.getCurriculumEntry() instanceof ExternalEnrolment)) { new ISCTEInternalEnrolmentWrapper(this, (Enrolment) entry.getCurriculumEntry()); } else { new ISCTEExternalEnrolmentWrapper(this, (ExternalEnrolment) entry.getCurriculumEntry()); } } } public final Collection getEnrolments() { Set result = new HashSet(); for (EnrolmentWrapper enrolmentWrapper : getEnrolmentWrappers()) { if (enrolmentWrapper.getCurriculumEntry() instanceof IEnrolment) { result.add(enrolmentWrapper.getIEnrolment()); } } return result; } public Collection getCurriculumEntries() { final Set result = new HashSet(); for (final EnrolmentWrapper each : getEnrolmentWrappers()) { result.add(each.getCurriculumEntry()); } return result; } public final void delete() { removeExecutionYear(); removeStudentCurricularPlan(); for (; hasAnyEnrolmentWrappers(); getEnrolmentWrappers().get(0).delete()) ; removeRootDomainObject(); deleteDomainObject(); } }