package net.sourceforge.fenixedu.dataTransferObject.student; import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; import net.sourceforge.fenixedu.domain.DomainReference; import net.sourceforge.fenixedu.domain.Enrolment; import net.sourceforge.fenixedu.domain.ExecutionSemester; import net.sourceforge.fenixedu.domain.OptionalEnrolment; import net.sourceforge.fenixedu.domain.StudentCurricularPlan; import net.sourceforge.fenixedu.domain.degreeStructure.OptionalCurricularCourse; import net.sourceforge.fenixedu.domain.enrolment.CurriculumModuleMoveWrapper; import net.sourceforge.fenixedu.domain.enrolment.IDegreeModuleToEvaluate; import net.sourceforge.fenixedu.domain.student.Student; import net.sourceforge.fenixedu.domain.studentCurriculum.CurriculumGroup; public class OptionalCurricularCoursesLocationBean implements Serializable { private DomainReference studentCurricularPlan; private List enrolmentBeans; private List optionalEnrolmentBeans; public OptionalCurricularCoursesLocationBean(final StudentCurricularPlan studentCurricularPlan) { setStudentCurricularPlan(studentCurricularPlan); setEnrolmentBeans(new ArrayList()); setOptionalEnrolmentBeans(new ArrayList()); } public StudentCurricularPlan getStudentCurricularPlan() { return (this.studentCurricularPlan != null) ? this.studentCurricularPlan.getObject() : null; } public void setStudentCurricularPlan(StudentCurricularPlan studentCurricularPlan) { this.studentCurricularPlan = (studentCurricularPlan != null) ? new DomainReference( studentCurricularPlan) : null; } public List getEnrolmentBeans() { return enrolmentBeans; } public void setEnrolmentBeans(List enrolmentBeans) { this.enrolmentBeans = enrolmentBeans; } public List getOptionalEnrolmentBeans() { return optionalEnrolmentBeans; } public void setOptionalEnrolmentBeans(List optionalEnrolmentBeans) { this.optionalEnrolmentBeans = optionalEnrolmentBeans; } public void addEnrolment(Enrolment enrolment) { if (enrolment.isOptional()) { getOptionalEnrolmentBeans().add(new OptionalEnrolmentLocationBean((OptionalEnrolment) enrolment)); } else { getEnrolmentBeans().add(new EnrolmentLocationBean(enrolment)); } } public void addEnrolments(final Collection enrolments) { for (final Enrolment enrolment : enrolments) { addEnrolment(enrolment); } } public Set getIDegreeModulesToEvaluate(final ExecutionSemester executionPeriod) { final Set result = new HashSet(); for (final EnrolmentLocationBean bean : this.enrolmentBeans) { result.add(CurriculumModuleMoveWrapper.create(bean.getCurriculumGroup(getStudentCurricularPlan()), executionPeriod)); } for (final OptionalEnrolmentLocationBean bean : this.optionalEnrolmentBeans) { result.add(CurriculumModuleMoveWrapper.create(bean.getCurriculumGroup(), executionPeriod)); } return result; } static public class EnrolmentLocationBean implements Serializable { private DomainReference enrolment; private DomainReference optionalCurricularCourse; public EnrolmentLocationBean(final Enrolment enrolment) { setEnrolment(enrolment); } public Enrolment getEnrolment() { return (this.enrolment != null) ? this.enrolment.getObject() : null; } public void setEnrolment(Enrolment enrolment) { this.enrolment = (enrolment != null) ? new DomainReference(enrolment) : null; } public OptionalCurricularCourse getOptionalCurricularCourse() { return (this.optionalCurricularCourse != null) ? this.optionalCurricularCourse.getObject() : null; } public void setOptionalCurricularCourse(OptionalCurricularCourse optionalCurricularCourse) { this.optionalCurricularCourse = (optionalCurricularCourse != null) ? new DomainReference( optionalCurricularCourse) : null; } public CurriculumGroup getCurriculumGroup(final StudentCurricularPlan studentCurricularPlan) { final List curriculumGroups = new ArrayList(studentCurricularPlan .getCurricularCoursePossibleGroupsWithoutNoCourseGroupCurriculumGroups(getOptionalCurricularCourse())); Collections.sort(curriculumGroups, CurriculumGroup.COMPARATOR_BY_NAME_AND_ID); return curriculumGroups.isEmpty() ? null : curriculumGroups.get(0); } public StudentCurricularPlan getStudentCurricularPlan() { return getEnrolment().getStudentCurricularPlan(); } public Student getStudent() { return getStudentCurricularPlan().getRegistration().getStudent(); } } static public class OptionalEnrolmentLocationBean implements Serializable { private DomainReference enrolment; private DomainReference curriculumGroup; public OptionalEnrolmentLocationBean(final OptionalEnrolment enrolment) { setEnrolment(enrolment); } public OptionalEnrolment getEnrolment() { return (this.enrolment != null) ? this.enrolment.getObject() : null; } public void setEnrolment(OptionalEnrolment enrolment) { this.enrolment = (enrolment != null) ? new DomainReference(enrolment) : null; } public CurriculumGroup getCurriculumGroup() { return (this.curriculumGroup != null) ? this.curriculumGroup.getObject() : null; } public void setCurriculumGroup(CurriculumGroup curriculumGroup) { this.curriculumGroup = (curriculumGroup != null) ? new DomainReference(curriculumGroup) : null; } public StudentCurricularPlan getStudentCurricularPlan() { return getEnrolment().getStudentCurricularPlan(); } public Student getStudent() { return getStudentCurricularPlan().getRegistration().getStudent(); } } }