package net.sourceforge.fenixedu.domain.serviceRequests; import net.sourceforge.fenixedu.dataTransferObject.serviceRequests.AcademicServiceRequestBean; import net.sourceforge.fenixedu.dataTransferObject.serviceRequests.RegistrationAcademicServiceRequestCreateBean; import net.sourceforge.fenixedu.domain.ExecutionSemester; import net.sourceforge.fenixedu.domain.ExecutionYear; import net.sourceforge.fenixedu.domain.StudentCurricularPlan; import net.sourceforge.fenixedu.domain.accounting.EventType; import net.sourceforge.fenixedu.domain.accounting.events.serviceRequests.PartialRegistrationRegimeRequestEvent; import net.sourceforge.fenixedu.domain.curricularRules.MaximumNumberOfCreditsForEnrolmentPeriod; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.serviceRequests.documentRequests.AcademicServiceRequestType; import net.sourceforge.fenixedu.domain.student.Registration; import net.sourceforge.fenixedu.domain.student.RegistrationRegime; import net.sourceforge.fenixedu.domain.student.RegistrationRegimeType; public class PartialRegistrationRegimeRequest extends PartialRegistrationRegimeRequest_Base { private PartialRegistrationRegimeRequest() { super(); } public PartialRegistrationRegimeRequest(final RegistrationAcademicServiceRequestCreateBean bean) { this(); super.init(bean); } @Override protected void checkRulesToChangeState(AcademicServiceRequestSituationType situationType) { super.checkRulesToChangeState(situationType); if (situationType == AcademicServiceRequestSituationType.PROCESSING) { checkEctsCredits(getRegistration(), getExecutionYear()); } } private void checkEctsCredits(final Registration registration, final ExecutionYear executionYear) { final StudentCurricularPlan studentCurricularPlan = registration.getLastStudentCurricularPlan(); for (final ExecutionSemester semester : executionYear.getExecutionPeriods()) { final double enroledEctsCredits = studentCurricularPlan.getAccumulatedEctsCredits(semester); if (enroledEctsCredits > MaximumNumberOfCreditsForEnrolmentPeriod.MAXIMUM_NUMBER_OF_CREDITS_PARTIAL_TIME) { throw new DomainException("error.RegistrationRegime.semester.has.more.ects.than.maximum.allowed", String .valueOf(enroledEctsCredits), semester.getQualifiedName(), String .valueOf(MaximumNumberOfCreditsForEnrolmentPeriod.MAXIMUM_NUMBER_OF_CREDITS_PARTIAL_TIME)); } } } @Override protected void internalChangeState(final AcademicServiceRequestBean academicServiceRequestBean) { if (academicServiceRequestBean.isToCancelOrReject() && hasEvent()) { getEvent().cancel(academicServiceRequestBean.getEmployee()); } else if (academicServiceRequestBean.isToConclude()) { if (isPayable() && !isPayed()) { throw new DomainException("AcademicServiceRequest.hasnt.been.payed"); } academicServiceRequestBean.setSituationDate(getActiveSituation().getSituationDate().toYearMonthDay()); } } @Override protected void createAcademicServiceRequestSituations(AcademicServiceRequestBean academicServiceRequestBean) { super.createAcademicServiceRequestSituations(academicServiceRequestBean); if (academicServiceRequestBean.isToProcess() && !isFree()) { new PartialRegistrationRegimeRequestEvent(getAdministrativeOffice(), getPerson(), this); } else if (academicServiceRequestBean.isToConclude()) { AcademicServiceRequestSituation.create(this, new AcademicServiceRequestBean( AcademicServiceRequestSituationType.DELIVERED, academicServiceRequestBean.getEmployee())); if (!getRegistration().isPartialRegime(getExecutionYear())) { new RegistrationRegime(getRegistration(), getExecutionYear(), RegistrationRegimeType.PARTIAL_TIME); } } } @Override public boolean isAvailableForTransitedRegistrations() { return false; } @Override public AcademicServiceRequestType getAcademicServiceRequestType() { return AcademicServiceRequestType.PARTIAL_REGIME_REQUEST; } @Override public EventType getEventType() { return EventType.PARTIAL_REGISTRATION_REGIME_REQUEST; } @Override public boolean hasPersonalInfo() { return false; } @Override public boolean isPayedUponCreation() { return true; } @Override public boolean isPossibleToSendToOtherEntity() { return false; } @Override public boolean isToPrint() { return false; } }