package net.sourceforge.fenixedu.domain.student.registrationStates; import net.sourceforge.fenixedu.domain.Person; import net.sourceforge.fenixedu.domain.accessControl.PermissionType; import net.sourceforge.fenixedu.domain.accessControl.academicAdminOffice.AdministrativeOfficePermission; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.person.RoleType; import net.sourceforge.fenixedu.domain.serviceRequests.documentRequests.DocumentRequestType; import net.sourceforge.fenixedu.domain.student.Registration; import net.sourceforge.fenixedu.domain.util.workflow.IState; import net.sourceforge.fenixedu.domain.util.workflow.StateBean; import net.sourceforge.fenixedu.injectionCode.AccessControl; import org.joda.time.DateTime; import com.linkare.commons.metainfo.Linkare; /** * * @author - Shezad Anavarali (shezad@ist.utl.pt) * */ public class ConcludedState extends ConcludedState_Base { @Linkare(author = "Paulo Zenida", comments = "Delegate the implementation in the constructor having the checkConcluded flag") protected ConcludedState(Registration registration, Person person, DateTime dateTime) { this(registration, person, dateTime, RegistrationState.checkConclusion()); } @Linkare(author = "Paulo Zenida", comments = "Created constructor having a boolean to enable/disable checking if the registration is concluded") protected ConcludedState(Registration registration, Person person, DateTime dateTime, final boolean checkConcluded) { super(); if (checkConcluded && !registration.hasConcluded()) { throw new DomainException("error.registration.is.not.concluded"); } init(registration, person, dateTime); registration.getPerson().addPersonRoleByRoleType(RoleType.ALUMNI); if (registration.getStudent().getRegistrationsCount() == 1) { registration.getPerson().removeRoleByType(RoleType.STUDENT); } } @Override public void delete() { checkRulesToDelete(); super.delete(); } private void checkRulesToDelete() { final Person person = AccessControl.getPerson(); if (person != null) { final AdministrativeOfficePermission permission = person.getEmployeeAdministrativeOffice().getPermission( PermissionType.REPEAT_CONCLUSION_PROCESS, person.getEmployeeCampus()); if (permission != null && permission.isAppliable(getRegistration())) { if (permission.isMember(person)) { return; } } } if (!getRegistration().getSucessfullyFinishedDocumentRequests(DocumentRequestType.DEGREE_FINALIZATION_CERTIFICATE) .isEmpty()) { throw new DomainException("cannot.delete.concluded.state.of.registration.with.concluded.degree.finalization.request"); } if (!getRegistration().getSucessfullyFinishedDocumentRequests(DocumentRequestType.DIPLOMA_REQUEST).isEmpty()) { throw new DomainException("cannot.delete.concluded.state.of.registration.with.concluded.diploma.request"); } } @Override public void checkConditionsToForward(final StateBean bean) { throw new DomainException("error.impossible.to.forward.from.concluded"); } @Override public IState nextState(final StateBean bean) { throw new DomainException("error.impossible.to.forward.from.concluded"); } @Override public RegistrationStateType getStateType() { return RegistrationStateType.CONCLUDED; } }