package net.sourceforge.fenixedu.domain.serviceRequests.documentRequests; import java.util.Collection; import java.util.HashSet; import net.sourceforge.fenixedu.dataTransferObject.serviceRequests.AcademicServiceRequestBean; import net.sourceforge.fenixedu.dataTransferObject.serviceRequests.DocumentRequestCreateBean; import net.sourceforge.fenixedu.dataTransferObject.student.RegistrationConclusionBean; import net.sourceforge.fenixedu.domain.accounting.EventType; 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.student.MobilityProgram; import net.sourceforge.fenixedu.domain.student.Registration; import net.sourceforge.fenixedu.domain.student.curriculum.ICurriculum; import net.sourceforge.fenixedu.domain.student.curriculum.ICurriculumEntry; import net.sourceforge.fenixedu.domain.studentCurriculum.CycleCurriculumGroup; import net.sourceforge.fenixedu.domain.studentCurriculum.Dismissal; import org.joda.time.YearMonthDay; import com.linkare.commons.metainfo.Linkare; import pt.ist.fenixWebFramework.security.accessControl.Checked; import pt.ist.fenixWebFramework.services.Service; public class DegreeFinalizationCertificateRequest extends DegreeFinalizationCertificateRequest_Base { protected DegreeFinalizationCertificateRequest() { super(); } public DegreeFinalizationCertificateRequest(final DocumentRequestCreateBean bean) { this(); super.init(bean); checkParameters(bean); super.setAverage(bean.getAverage()); super.setDetailed(bean.getDetailed()); super.setMobilityProgram(bean.getMobilityProgram()); super.setIgnoreExternalEntries(bean.isIgnoreExternalEntries()); super.setTechnicalEngineer(bean.getTechnicalEngineer()); super.setInternshipAbolished(bean.getInternshipAbolished()); super.setInternshipApproved(bean.getInternshipApproved()); super.setStudyPlan(bean.getStudyPlan()); super.setBranch(bean.getBranchName()); super.setExceptionalConclusionDate(bean.getExceptionalConclusionDate()); super.setLanguage(bean.getLanguage()); } @Override protected void checkParameters(final DocumentRequestCreateBean bean) { if (bean.getAverage() == null) { throw new DomainException("DegreeFinalizationCertificateRequest.average.cannot.be.null"); } if (bean.getDetailed() == null) { throw new DomainException("DegreeFinalizationCertificateRequest.detailed.cannot.be.null"); } if (bean.getMobilityProgram() != null && bean.isIgnoreExternalEntries()) { throw new DomainException("ApprovementCertificateRequest.cannot.ignore.external.entries.within.a.mobility.program"); } if ((bean.getInternshipAbolished() || bean.getInternshipApproved() || bean.getStudyPlan()) && bean.getExceptionalConclusionDate() == null) { throw new DomainException( "DegreeFinalizationCertificateRequest.must.indicate.date.for.exceptional.conclusion.situation"); } if (bean.getLanguage() == null) { throw new DomainException("DegreeFinalizationCertificateRequest.missing.language"); } if (getDegreeType().isComposite()) { if (bean.getRequestedCycle() == null) { throw new DomainException("DegreeFinalizationCertificateRequest.requested.cycle.must.be.given"); } else if (!getDegreeType().getCycleTypes().contains(bean.getRequestedCycle())) { throw new DomainException( "DegreeFinalizationCertificateRequest.requested.degree.type.is.not.allowed.for.given.student.curricular.plan"); } super.setRequestedCycle(bean.getRequestedCycle()); } checkSpecificConditions(); } private void checkSpecificConditions() { if (getRegistration().getDegreeType().getQualifiesForGraduateTitle()) { checkForDiplomaRequest(getRegistration(), getRequestedCycle()); } else { if (!getRegistration().isRegistrationConclusionProcessed(getRequestedCycle())) { throw new DomainException("DiplomaRequest.registration.not.submited.to.conclusion.process"); } } } static public void checkForDiplomaRequest(final Registration registration, final CycleType requestedCycle) { final DiplomaRequest diplomaRequest = registration.getDiplomaRequest(requestedCycle); if (diplomaRequest == null) { throw new DomainException("DegreeFinalizationCertificateRequest.registration.withoutDiplomaRequest"); } else if (diplomaRequest.isPayedUponCreation() && diplomaRequest.hasEvent() && !diplomaRequest.getEvent().isPayed()) { throw new DomainException("DegreeFinalizationCertificateRequest.registration.withoutPayedDiplomaRequest"); } } @Override final protected void internalChangeState(AcademicServiceRequestBean academicServiceRequestBean) { if (academicServiceRequestBean.isToProcess()) { checkSpecificConditions(); if (!getRegistration().isRegistrationConclusionProcessed(getRequestedCycle())) { throw new DomainException("DegreeFinalizationCertificateRequest.registration.not.submited.to.conclusion.process"); } if (!getFreeProcessed()) { if (hasCycleCurriculumGroup()) { assertPayedEvents(getCycleCurriculumGroup().getIEnrolmentsLastExecutionYear()); } else { assertPayedEvents(); } } if (hasPersonalInfo() && hasMissingPersonalInfo()) { throw new DomainException("AcademicServiceRequest.has.missing.personal.info"); } } if (academicServiceRequestBean.isToConclude()) { tryConcludeServiceRequest(academicServiceRequestBean); } if (academicServiceRequestBean.isToCancelOrReject() && hasEvent()) { getEvent().cancel(academicServiceRequestBean.getEmployee()); } if (academicServiceRequestBean.isToDeliver()) { if (isPayable() && !isPayed()) { throw new DomainException("AcademicServiceRequest.hasnt.been.payed"); } } } @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.DEGREE_FINALIZATION_CERTIFICATE; } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") @Override public final String getDocumentTemplateKey() { return getClass().getName(); } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") @Override public final void setAverage(final Boolean average) { throw new DomainException("DegreeFinalizationCertificateRequest.cannot.modify.average"); } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") @Override public final void setDetailed(final Boolean detailed) { throw new DomainException("DegreeFinalizationCertificateRequest.cannot.modify.detailed"); } @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("DegreeFinalizationCertificateRequest.cannot.modify.requestedCycle"); } @Override public void setMobilityProgram(MobilityProgram mobilityProgram) { throw new DomainException("error.DegreeFinalizationCertificateRequest.cannot.modify"); } @Override public void setIgnoreExternalEntries(Boolean ignoreExternalEntries) { throw new DomainException("error.DegreeFinalizationCertificateRequest.cannot.modify"); } @Override public void setTechnicalEngineer(Boolean technicalEngineer) { throw new DomainException("error.DegreeFinalizationCertificateRequest.cannot.modify"); } @Override public void setInternshipAbolished(Boolean internshipAbolished) { throw new DomainException("error.DegreeFinalizationCertificateRequest.cannot.modify"); } @Override public void setInternshipApproved(Boolean internshipApproved) { throw new DomainException("error.DegreeFinalizationCertificateRequest.cannot.modify"); } @Override public void setExceptionalConclusionDate(YearMonthDay exceptionalConclusionDate) { throw new DomainException("error.DegreeFinalizationCertificateRequest.cannot.modify"); } @Override public void setStudyPlan(Boolean studyPlan) { throw new DomainException("error.DegreeFinalizationCertificateRequest.cannot.modify"); } /* 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; } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") @Override public final EventType getEventType() { return EventType.DEGREE_FINALIZATION_CERTIFICATE_REQUEST; } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") @Override public final Integer getNumberOfUnits() { return getDetailed() ? getEntriesToReport().size() : 0; } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") private final RegistrationConclusionBean getBean() { return new RegistrationConclusionBean(getRegistration(), getCycleCurriculumGroup()); } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") public final boolean hasExceptionalConclusionDate() { return getExceptionalConclusionDate() != null; } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") public final boolean hasExceptionalConclusionInfo() { return getTechnicalEngineer() || getInternshipAbolished() || getInternshipApproved() || getStudyPlan(); } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") public final boolean mustHideConclusionDate() { return getInternshipAbolished() || getInternshipApproved() || (getStudyPlan() && getRegistration().isFirstCycleAtributionIngression()); } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") public final YearMonthDay getConclusionDate() { return getBean().getConclusionDate(); } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") public final Integer getFinalAverage() { return getBean().getFinalAverage(); } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") public final double getEctsCredits() { return getBean().getEctsCredits(); } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") public final ICurriculum getCurriculum() { return getBean().getCurriculumForConclusion(); } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") public final Collection getEntriesToReport() { final Collection result = new HashSet(); for (final ICurriculumEntry entry : getCurriculum().getCurriculumEntries()) { if (entry instanceof Dismissal) { final Dismissal dismissal = (Dismissal) entry; if (dismissal.getCredits().isEquivalence() || (dismissal.isCreditsDismissal() && !dismissal.getCredits().isSubstitution())) { continue; } } result.add(entry); } return result; } @Override public boolean hasPersonalInfo() { return true; } @Service @Override @Checked("AcademicServiceRequestPredicates.REVERT_TO_PROCESSING_STATE") public void revertToProcessingState() { internalRevertToProcessingState(); } }