package net.sourceforge.fenixedu.domain.serviceRequests.documentRequests; import java.util.Arrays; import java.util.Collections; import java.util.List; import com.linkare.commons.metainfo.Linkare; import net.sourceforge.fenixedu.dataTransferObject.serviceRequests.AcademicServiceRequestBean; import net.sourceforge.fenixedu.dataTransferObject.serviceRequests.DocumentRequestCreateBean; import net.sourceforge.fenixedu.domain.accounting.EventType; import net.sourceforge.fenixedu.domain.accounting.events.serviceRequests.DiplomaRequestEvent; import net.sourceforge.fenixedu.domain.degree.DegreeType; import net.sourceforge.fenixedu.domain.degreeStructure.CycleType; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.serviceRequests.AcademicServiceRequestSituationType; import net.sourceforge.fenixedu.domain.student.Registration; import net.sourceforge.fenixedu.domain.studentCurriculum.CycleCurriculumGroup; import pt.ist.fenixWebFramework.security.accessControl.Checked; import pt.ist.fenixWebFramework.services.Service; public class DiplomaRequest extends DiplomaRequest_Base { public DiplomaRequest() { super(); } public DiplomaRequest(final DocumentRequestCreateBean bean) { this(); super.init(bean); checkParameters(bean); if (isPayedUponCreation() && !isFree()) { DiplomaRequestEvent.create(getAdministrativeOffice(), getRegistration().getPerson(), this); } } @Override protected void checkParameters(final DocumentRequestCreateBean bean) { if (getDegreeType().isComposite()) { if (bean.getRequestedCycle() == null) { throw new DomainException("DiplomaRequest.diploma.requested.cycle.must.be.given"); } else if (!getDegreeType().getCycleTypes().contains(bean.getRequestedCycle())) { throw new DomainException( "DiplomaRequest.diploma.requested.degree.type.is.not.allowed.for.given.student.curricular.plan"); } super.setRequestedCycle(bean.getRequestedCycle()); } checkForDuplicate(bean.getRequestedCycle()); } private void checkForDuplicate(final CycleType requestedCycle) { final DiplomaRequest diplomaRequest = getRegistration().getDiplomaRequest(requestedCycle); if (diplomaRequest != null && diplomaRequest != this) { throw new DomainException("DiplomaRequest.diploma.already.requested"); } } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") @Override public final void setRequestedCycle(final CycleType requestedCycle) { throw new DomainException("DiplomaRequest.cannot.modify.requestedCycle"); } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") @Override public final String getDescription() { final DegreeType degreeType = getDegreeType(); final CycleType requestedCycle = getRequestedCycle(); return getDescription(getAcademicServiceRequestType(), getDocumentRequestType().getQualifiedName() + "." + degreeType.name() + (degreeType.isComposite() ? "." + requestedCycle.name() : "")); } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") @Override public final DocumentRequestType getDocumentRequestType() { return DocumentRequestType.DIPLOMA_REQUEST; } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") @Override public final String getDocumentTemplateKey() { String result = getClass().getName() + "." + getDegreeType().getName(); if (getRequestedCycle() != null) { result += "." + getRequestedCycle().name(); } return result; } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions. Added new cases.") @Override public final EventType getEventType() { switch (getDegreeType()) { case DEGREE: case BOLONHA_OLD_DEGREE: case BOLONHA_DEGREE: return EventType.BOLONHA_DEGREE_DIPLOMA_REQUEST; case MASTER_DEGREE: case BOLONHA_MASTER_DEGREE: return EventType.BOLONHA_MASTER_DEGREE_DIPLOMA_REQUEST; case BOLONHA_INTEGRATED_MASTER_DEGREE: return (getRequestedCycle() == CycleType.FIRST_CYCLE) ? EventType.BOLONHA_DEGREE_DIPLOMA_REQUEST : EventType.BOLONHA_MASTER_DEGREE_DIPLOMA_REQUEST; case BOLONHA_ADVANCED_FORMATION_DIPLOMA: return EventType.BOLONHA_ADVANCED_FORMATION_DIPLOMA_REQUEST; default: throw new DomainException("DiplomaRequest.not.available.for.given.degree.type"); } } @Override final protected void internalChangeState(AcademicServiceRequestBean academicServiceRequestBean) { if (academicServiceRequestBean.isToProcess()) { if (NOT_AVAILABLE.contains(getRegistration().getDegreeType())) { throw new DomainException("DiplomaRequest.diploma.not.available"); } checkForDuplicate(getRequestedCycle()); if (!getRegistration().isRegistrationConclusionProcessed(getRequestedCycle())) { throw new DomainException("DiplomaRequest.registration.not.submited.to.conclusion.process"); } if (hasDissertationTitle() && !getRegistration().hasDissertationThesis()) { throw new DomainException("DiplomaRequest.registration.doesnt.have.dissertation.thesis"); } if (!getFreeProcessed()) { if (hasCycleCurriculumGroup()) { assertPayedEvents(getCycleCurriculumGroup().getIEnrolmentsLastExecutionYear()); } else { assertPayedEvents(); } } if (isPayable() && !isPayed()) { throw new DomainException("AcademicServiceRequest.hasnt.been.payed"); } } if (academicServiceRequestBean.isToConclude() && !isFree() && !hasEvent() && !isPayedUponCreation()) { DiplomaRequestEvent.create(getAdministrativeOffice(), getRegistration().getPerson(), this); } if (academicServiceRequestBean.isToCancelOrReject() && hasEvent()) { getEvent().cancel(academicServiceRequestBean.getEmployee()); } } static final private List NOT_AVAILABLE = Arrays.asList(DegreeType.BOLONHA_ADVANCED_SPECIALIZATION_DIPLOMA, DegreeType.BOLONHA_SPECIALIZATION_DEGREE); @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") public final boolean hasFinalAverageDescription() { return !hasDissertationTitle(); } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") public final boolean hasDissertationTitle() { return getDegreeType() == DegreeType.MASTER_DEGREE; } /* TODO refactor, always set requested cycle type in document creation */ public CycleType getWhatShouldBeRequestedCycle() { return hasCycleCurriculumGroup() ? getCycleCurriculumGroup().getCycleType() : null; } public CycleCurriculumGroup getCycleCurriculumGroup() { final CycleType requestedCycle = getRequestedCycle(); final Registration registration = getRegistration(); if (requestedCycle == null) { if (registration.getDegreeType().hasExactlyOneCycleType()) { return registration.getLastStudentCurricularPlan().getLastOrderedCycleCurriculumGroup(); } else { return null; } } else { return registration.getLastStudentCurricularPlan().getCycle(requestedCycle); } } public boolean hasCycleCurriculumGroup() { return getCycleCurriculumGroup() != null; } @Override public boolean hasPersonalInfo() { return true; } @Override public boolean isPagedDocument() { return false; } @Override public boolean isToPrint() { return !isDelivered(); } @Override protected List getProcessingSituationAcceptedSituationsTypes() { return Collections.unmodifiableList(Arrays.asList(AcademicServiceRequestSituationType.CANCELLED, AcademicServiceRequestSituationType.REJECTED, AcademicServiceRequestSituationType.CONCLUDED)); } @Override protected List getReceivedFromExternalEntitySituationAcceptedSituationsTypes() { return Collections.unmodifiableList(Arrays.asList(AcademicServiceRequestSituationType.DELIVERED)); } @Override protected List getConcludedSituationAcceptedSituationsTypes() { return Collections.unmodifiableList(Arrays.asList(AcademicServiceRequestSituationType.DELIVERED, AcademicServiceRequestSituationType.SENT_TO_EXTERNAL_ENTITY)); } @Override public boolean isPossibleToSendToOtherEntity() { return true; } @Override public boolean isAvailableForTransitedRegistrations() { return false; } @Override public boolean isPayedUponCreation() { return getDegreeType() != DegreeType.BOLONHA_ADVANCED_FORMATION_DIPLOMA; } @Service @Override @Checked("AcademicServiceRequestPredicates.REVERT_TO_PROCESSING_STATE") public void revertToProcessingState() { internalRevertToProcessingState(); } }