package net.sourceforge.fenixedu.domain.serviceRequests; import net.sourceforge.fenixedu.domain.Degree; import net.sourceforge.fenixedu.domain.Employee; import net.sourceforge.fenixedu.domain.ExecutionYear; import net.sourceforge.fenixedu.domain.Person; import net.sourceforge.fenixedu.domain.StudentCurricularPlan; import net.sourceforge.fenixedu.domain.administrativeOffice.AdministrativeOffice; import net.sourceforge.fenixedu.domain.degree.DegreeType; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.space.Campus; import net.sourceforge.fenixedu.domain.student.Registration; import net.sourceforge.fenixedu.injectionCode.AccessControl; import net.sourceforge.zas.metainfo.AccessControlled; import pt.iscte.ci.metadata.ISCTE; abstract public class RegistrationAcademicServiceRequest extends RegistrationAcademicServiceRequest_Base { protected RegistrationAcademicServiceRequest() { super(); } protected void init(final Registration registration, final Boolean urgentRequest, final Boolean freeProcessed) { init(registration, null, urgentRequest, freeProcessed); } protected void init(final Registration registration, final ExecutionYear executionYear, final Boolean urgentRequest, final Boolean freeProcessed) { init(registration, executionYear, urgentRequest, freeProcessed, null); } @ISCTE(author = "Nadir Amin") protected void init(final Registration registration, final ExecutionYear executionYear, final Boolean urgentRequest, final Boolean freeProcessed, final StudentCurricularPlan studentCurricularPlan) { // first set own parameters because of findAdministrativeOffice checkParameters(registration); checkRulesToCreate(registration, studentCurricularPlan); super.setRegistration(registration); super.setStudentCurricularPlan(studentCurricularPlan); // then set super parameters super.init(executionYear, urgentRequest, freeProcessed); } @ISCTE(author = "Nadir Amin") private void checkRulesToCreate(Registration registration, StudentCurricularPlan studentCurricularPlan) { if (studentCurricularPlan != null && !registration.getStudentCurricularPlans().contains(studentCurricularPlan)) { throw new DomainException( "error.serviceRequests.RegistrationAcademicServiceRequest.studentCurricularPlan.must.belong.to.registration"); } } private void checkParameters(final Registration registration) { if (registration == null) { throw new DomainException("error.serviceRequests.AcademicServiceRequest.registration.cannot.be.null"); } else if (registration.isTransited()) { throw new DomainException("RegistrationAcademicServiceRequest.registration.cannot.be.transited"); } } @Override protected AdministrativeOffice findAdministrativeOffice() { AdministrativeOffice administrativeOffice = super.findAdministrativeOffice(); if (administrativeOffice == null) { administrativeOffice = AdministrativeOffice.getResponsibleAdministrativeOffice(getRegistration().getDegree()); } return administrativeOffice; } @Override public void setRegistration(Registration registration) { throw new DomainException("error.serviceRequests.RegistrationAcademicServiceRequest.cannot.modify.registration"); } @AccessControlled("MANAGER") @Override public void setStudentCurricularPlan(StudentCurricularPlan studentCurricularPlan) { // ISCTE super.setStudentCurricularPlan(studentCurricularPlan); // throw new // DomainException("error.serviceRequests.RegistrationAcademicServiceRequest.cannot.modify.studentCurricularPlan"); } @ISCTE(author = "Nadir Amin", comment = "Changed to student curricular plan if defined") public StudentCurricularPlan getStudentCurricularPlan() { if (super.getStudentCurricularPlan() != null) { return super.getStudentCurricularPlan(); } final ExecutionYear executionYear = hasExecutionYear() ? getExecutionYear() : ExecutionYear .readByDateTime(getCreationDate()); return getRegistration().getStudentCurricularPlan(executionYear); } /* * Overrided method, because checkDisconnect method invoke this method to * check if can delete object. However getStudentCurricularPlan was * overrided too, and getCreationDate no longer exists after delete method * is invoked. To avoid this we need to check if * super.getStudentCurricularPlan is defined. */ @Override public boolean hasStudentCurricularPlan() { return super.getStudentCurricularPlan() != null; } public Degree getDegree() { return getStudentCurricularPlan().getDegree(); } public DegreeType getDegreeType() { return getDegree().getDegreeType(); } public boolean isBolonha() { return getDegree().isBolonhaDegree(); } public Campus getCampus() { final StudentCurricularPlan studentCurricularPlan = getStudentCurricularPlan(); return studentCurricularPlan != null ? studentCurricularPlan.getCurrentCampus() : null; } @Override public boolean isAvailableForEmployeeToActUpon() { final Person loggedPerson = AccessControl.getPerson(); if (loggedPerson.hasEmployee()) { final Employee employee = loggedPerson.getEmployee(); return employee.getAdministrativeOffice() == getAdministrativeOffice() && employee.getCurrentCampus() == getCampus(); } else { throw new DomainException("RegistrationAcademicServiceRequest.non.employee.person.attempt.to.change.request"); } } @Override public boolean isRequestForRegistration() { return true; } @Override public void delete() { super.setRegistration(null); super.setStudentCurricularPlan(null); super.delete(); } public Person getPerson() { return getRegistration().getPerson(); } @Override public void forceDelete() { super.setRegistration(null); super.setStudentCurricularPlan(null); super.forceDelete(); } }