package net.sourceforge.fenixedu.domain.candidacy; import java.io.Serializable; import net.sourceforge.fenixedu.dataTransferObject.candidacy.IngressionInformationBean; import net.sourceforge.fenixedu.domain.DomainReference; import net.sourceforge.fenixedu.domain.RootDomainObject; import net.sourceforge.fenixedu.domain.student.Registration; import net.sourceforge.fenixedu.domain.util.FactoryExecutor; import net.sourceforge.fenixedu.util.EntryPhase; import pt.iscte.ci.metadata.ISCTE; /** * * @author rjmvo * */ public class StudentIngression extends StudentIngression_Base { public StudentIngression() { super(); setRootDomainObject(RootDomainObject.getInstance()); } public StudentIngression(final Registration registration, final String ingression, final EntryPhase entryPhase) { this(); setIngression(ingression); setEntryPhase(entryPhase); setRegistration(registration); } @ISCTE(author = "Paulo Zenida", comment = "Added the check for avoiding NullPointerExceptions") public StudentIngression(final Registration registration, final Ingression ingression, final EntryPhase entryPhase) { this(registration, ingression == null ? null : ingression.name(), entryPhase); } public Ingression getIngressionEnum() { return getIngression() != null ? Ingression.valueOf(getIngression()) : null; } public void delete() { removeRegistration(); removeStudentCandidacy(); removeExecutionYear(); removeRootDomainObject(); super.deleteDomainObject(); } public static class RegistrationIngressionCreator extends IngressionInformationBean implements FactoryExecutor, Serializable { public RegistrationIngressionCreator(Registration registration) { super(registration); } public Object execute() { final Registration registration = getRegistration(); registration.setRegistrationAgreement(getRegistrationAgreement()); Registration.checkIngression(getIngression(), registration.getPerson(), registration.getFirstStudentCurricularPlan() .getDegreeCurricularPlan()); if (getIngression() != null) { StudentIngression ingression = new StudentIngression(registration, getIngression(), getEntryPhase()); ingression.setStudentCandidacy(registration.getStudentCandidacy()); ingression.setExecutionYear(getExecutionYear()); ingression.setRemarks(getRemarks()); return ingression; } return null; } } public static class RegistrationIngressionEditor extends IngressionInformationBean implements FactoryExecutor, Serializable { private DomainReference ingression; public RegistrationIngressionEditor(StudentIngression ingression) { super(ingression.getRegistration()); setIngression(ingression.getIngressionEnum()); setEntryPhase(ingression.getEntryPhase()); setExecutionYear(getExecutionYear()); setRemarks(ingression.getRemarks()); setStudentIngression(ingression); } public StudentIngression getStudentIngression() { return ingression == null ? null : ingression.getObject(); } public void setStudentIngression(StudentIngression ingression) { this.ingression = ingression != null ? new DomainReference(ingression) : null; } public Object execute() { getStudentIngression().setIngression(getIngression().name()); getStudentIngression().setEntryPhase(getEntryPhase()); getStudentIngression().setRemarks(getRemarks()); return getStudentIngression(); } } public static class RegistrationIngressionDeleter extends IngressionInformationBean implements FactoryExecutor, Serializable { private DomainReference ingression; public RegistrationIngressionDeleter(StudentIngression ingression) { super(ingression.getRegistration()); setStudentIngression(ingression); } public StudentIngression getStudentIngression() { return ingression == null ? null : ingression.getObject(); } public void setStudentIngression(StudentIngression ingression) { this.ingression = ingression != null ? new DomainReference(ingression) : null; } public Object execute() { getStudentIngression().delete(); return null; } } public boolean isAllowedToDelete() { if (getRegistration().getRegistrationAgreement() != null && !getRegistration().getRegistrationAgreement().isIngressionRequired()) { return true; } return getRegistration().getStudentIngressions().size() > 1; } }