package net.sourceforge.fenixedu.domain.student; import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; import net.sourceforge.fenixedu.domain.Degree; import net.sourceforge.fenixedu.domain.DegreeCurricularPlan; import net.sourceforge.fenixedu.domain.Department; import net.sourceforge.fenixedu.domain.DomainReference; import net.sourceforge.fenixedu.domain.ExecutionYear; import net.sourceforge.fenixedu.domain.StudentCurricularPlan; public class SearchStudentsWithEnrolmentsByDepartment implements Serializable { private DomainReference departmentDomainReference; private Set> degreeDomainReferences; private DomainReference executionYearDomainReference; public SearchStudentsWithEnrolmentsByDepartment(final Department department) { departmentDomainReference = department == null ? null : new DomainReference(department); } public Department getDepartment() { return departmentDomainReference == null ? null : departmentDomainReference.getObject(); } public List getDegrees() { final List degrees = new ArrayList(); if (degreeDomainReferences != null) { for (final DomainReference degreeDomainReference : degreeDomainReferences) { degrees.add(degreeDomainReference.getObject()); } } Collections.sort(degrees, Degree.COMPARATOR_BY_DEGREE_TYPE_AND_NAME_AND_ID); return degrees; } public void setDegrees(List degrees) { if (degrees != null) { degreeDomainReferences = new HashSet>(); for (final Degree degree : degrees) { degreeDomainReferences.add(new DomainReference(degree)); } } else { degreeDomainReferences = null; } } public ExecutionYear getExecutionYear() { return executionYearDomainReference == null ? null : executionYearDomainReference.getObject(); } public void setExecutionYear(final ExecutionYear executionYear) { executionYearDomainReference = executionYear == null ? null : new DomainReference(executionYear); } public Set search() { final ExecutionYear executionYear = getExecutionYear(); final Set studentCurricularPlans = new HashSet(); if (degreeDomainReferences != null) { for (final DomainReference degreeDomainReference : degreeDomainReferences) { final Degree degree = degreeDomainReference.getObject(); for (final DegreeCurricularPlan degreeCurricularPlan : degree.getDegreeCurricularPlansSet()) { if (degreeCurricularPlan.isActive()) { for (final StudentCurricularPlan studentCurricularPlan : degreeCurricularPlan .getStudentCurricularPlansSet()) { if (studentCurricularPlan.hasEnrolments(executionYear)) { studentCurricularPlans.add(studentCurricularPlan); } } } } } } return studentCurricularPlans; } public Set getSearch() { return search(); } }