package net.sourceforge.fenixedu.domain.serviceRequests.documentRequests; import java.util.Collection; import java.util.HashSet; import com.linkare.commons.metainfo.Linkare; import net.sourceforge.fenixedu.dataTransferObject.serviceRequests.DocumentRequestCreateBean; import net.sourceforge.fenixedu.domain.Enrolment; import net.sourceforge.fenixedu.domain.accounting.EventType; import net.sourceforge.fenixedu.domain.accounting.events.serviceRequests.CertificateRequestEvent; import net.sourceforge.fenixedu.domain.exceptions.DomainException; public class EnrolmentCertificateRequest extends EnrolmentCertificateRequest_Base { protected EnrolmentCertificateRequest() { super(); } public EnrolmentCertificateRequest(final DocumentRequestCreateBean bean) { this(); super.init(bean); checkParameters(bean); super.setDetailed(bean.getDetailed()); } @Override protected void checkParameters(final DocumentRequestCreateBean bean) { if (bean.getDetailed() == null) { throw new DomainException( "error.serviceRequests.documentRequests.EnrolmentCertificateRequest.detailed.cannot.be.null"); } if (bean.getExecutionYear() == null) { throw new DomainException( "error.serviceRequests.documentRequests.EnrolmentCertificateRequest.executionYear.cannot.be.null"); } else if (!bean.getRegistration().hasAnyEnrolmentsIn(bean.getExecutionYear())) { throw new DomainException("EnrolmentCertificateRequest.no.enrolments.for.registration.in.given.executionYear"); } } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") @Override public final DocumentRequestType getDocumentRequestType() { return DocumentRequestType.ENROLMENT_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 setDetailed(Boolean detailed) { throw new DomainException("error.serviceRequests.documentRequests.EnrolmentCertificateRequest.cannot.modify.detailed"); } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") @Override public final EventType getEventType() { return EventType.ENROLMENT_CERTIFICATE_REQUEST; } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") @Override public final Integer getNumberOfUnits() { return getEntriesToReport().size() + getExtraCurricularEntriesToReport().size() + getPropaedeuticEntriesToReport().size(); } @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") public final Collection getEntriesToReport() { return filterEntries(); } private Collection filterEntries() { final Collection result = new HashSet(); if (extraCurricular == null) { extraCurricular = new HashSet(); } else { extraCurricular.clear(); } if (propaedeutic == null) { propaedeutic = new HashSet(); } else { propaedeutic.clear(); } for (final Enrolment entry : getRegistration().getLatestCurricularCoursesEnrolments(getExecutionYear())) { if (entry.isExtraCurricular() && !entry.hasAnyEnrolmentWrappers()) { extraCurricular.add(entry); continue; } else if (entry.isPropaedeutic()) { propaedeutic.add(entry); continue; } result.add(entry); } return result; } Collection extraCurricular = null; @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") public final Collection getExtraCurricularEntriesToReport() { if (extraCurricular == null) { filterEntries(); } return extraCurricular; } Collection propaedeutic = null; @Linkare(author = "Paulo Zenida", comments = "Changed the modifiers order according to the JLS suggestions") public final Collection getPropaedeuticEntriesToReport() { if (propaedeutic == null) { filterEntries(); } return propaedeutic; } @Override public boolean isAvailableForTransitedRegistrations() { return true; } @Override public boolean hasPersonalInfo() { return true; } @Override public CertificateRequestEvent getEvent() { return (CertificateRequestEvent) super.getEvent(); } }