package net.sourceforge.fenixedu.dataTransferObject.administrativeOffice.dismissal; import java.io.Serializable; import java.util.HashSet; import java.util.Set; import net.sourceforge.fenixedu.domain.CompetenceCourse; import net.sourceforge.fenixedu.domain.CurricularCourse; import net.sourceforge.fenixedu.domain.DomainObject; import net.sourceforge.fenixedu.domain.DomainReference; import net.sourceforge.fenixedu.domain.ExecutionPeriod; import net.sourceforge.fenixedu.domain.Grade; import net.sourceforge.fenixedu.domain.StudentCurricularPlan; import net.sourceforge.fenixedu.domain.degreeStructure.CourseGroup; import net.sourceforge.fenixedu.domain.student.curriculum.ICurriculumEntry; import net.sourceforge.fenixedu.domain.studentCurriculum.CurriculumGroup; /** * * @author rjmvo * */ public class ISCTEDismissalBean implements Serializable { private static final long serialVersionUID = 1L; public static enum DismissalType { CURRICULAR_COURSE_CREDITS, CURRICULUM_GROUP_CREDITS, NO_COURSE_GROUP_CURRICULUM_GROUP_CREDITS; public String getName() { return name(); } } private DomainReference executionPeriod; private DomainReference courseGroup; private DomainReference curriculumGroup; private DomainReference studentCurricularPlan; private Set enrolments = new HashSet(); private Set dismissals = new HashSet(); private Grade grade; private Double credits; private Double weight; private DismissalType dismissalType; private boolean curricularIntegration; public ExecutionPeriod getExecutionPeriod() { return (this.executionPeriod != null) ? this.executionPeriod.getObject() : null; } public void setExecutionPeriod(ExecutionPeriod executionPeriod) { this.executionPeriod = (executionPeriod != null) ? new DomainReference(executionPeriod) : null; } public CourseGroup getCourseGroup() { return (this.courseGroup != null) ? this.courseGroup.getObject() : null; } public void setCourseGroup(CourseGroup courseGroup) { this.courseGroup = (courseGroup != null) ? new DomainReference(courseGroup) : 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 (this.studentCurricularPlan != null) ? this.studentCurricularPlan.getObject() : null; } public void setStudentCurricularPlan(StudentCurricularPlan studentCurricularPlan) { this.studentCurricularPlan = (studentCurricularPlan != null) ? new DomainReference( studentCurricularPlan) : null; } public Grade getGrade() { return grade; } public void setGrade(Grade grade) { this.grade = grade; } public Double getCredits() { return credits; } public void setCredits(Double credits) { this.credits = credits; } public Double getWeight() { return weight; } public void setWeight(Double weight) { this.weight = weight; } public DismissalType getDismissalType() { return dismissalType; } public void setDismissalType(DismissalType dismissalType) { this.dismissalType = dismissalType; } public boolean isCurricularIntegration() { return curricularIntegration; } public void setCurricularIntegration(boolean curricularIntegration) { this.curricularIntegration = curricularIntegration; } public boolean hasAnyEnrolments() { return !enrolments.isEmpty(); } public SelectedCurriculumEntry getEnrolmentEntry() { return null; } public void setEnrolmentEntry(SelectedCurriculumEntry entry) { if (entry != null && !enrolments.contains(entry)) { enrolments.add(entry); } } public void removeEnrolmentEntry(Integer entryId) { for (SelectedCurriculumEntry enrolment : enrolments) { if (enrolment.getCurriculumEntry().getIdInternal().equals(entryId)) { enrolments.remove(enrolment); break; } } } public void removeEnrolmentEntry(SelectedCurriculumEntry entry) { enrolments.remove(entry); } public boolean hasAnyDismissals() { return !dismissals.isEmpty(); } public SelectedDismissalEntry getDismissalEntry() { return null; } public void setDismissalEntry(SelectedDismissalEntry entry) { if (entry != null && !dismissals.contains(entry)) { dismissals.add(entry); } } public void removeDismissalEntry(Integer entryId) { for (SelectedDismissalEntry dismissal : dismissals) { if (dismissal.getCurricularCourse().getIdInternal().equals(entryId)) { dismissals.remove(dismissal); break; } } } public void removeDismissalEntry(SelectedDismissalEntry entry) { dismissals.remove(entry); } public Set getSelectedEnrolmentsEntries() { return enrolments; } public Set getSelectedDismissalsEntries() { return dismissals; } public Set getSelectedCurricularCourses() { final Set result = new HashSet(); for (final SelectedDismissalEntry entry : getSelectedDismissalsEntries()) { if (!entry.getCurricularCourse().isOptionalCurricularCourse()) { result.add(entry); } } return result; } public Set getSelectedOptionalCurricularCourses() { final Set result = new HashSet(); for (final SelectedDismissalEntry entry : getSelectedDismissalsEntries()) { if (entry.getCurricularCourse().isOptionalCurricularCourse()) { result.add(entry); } } return result; } public boolean isGradeEditable() { return getDismissalType() == DismissalType.CURRICULAR_COURSE_CREDITS && !getSelectedCurricularCourses().isEmpty() && getSelectedEnrolmentsEntries().isEmpty(); } public void clearSelectedEntries() { this.dismissals.clear(); this.enrolments.clear(); } public static class SelectedCurriculumEntry implements Serializable { private static final long serialVersionUID = 1L; private Double weigth = 1.; private Double creditsEcts; // It can be an Enrolment, ExternalEnrolment or even a Dismissal private DomainReference entry; public SelectedCurriculumEntry(ICurriculumEntry entry) { setCurriculumEntry(entry); } public Double getWeigth() { return weigth; } public void setWeigth(Double weigth) { this.weigth = weigth; } public Double getCreditsEcts() { return creditsEcts != null ? creditsEcts : new Double(getCurriculumEntry().getEctsCreditsForCurriculum() .doubleValue()); } public void setCreditsEcts(Double creditsEcts) { this.creditsEcts = creditsEcts; } public ICurriculumEntry getCurriculumEntry() { return (this.entry != null) ? (ICurriculumEntry) this.entry.getObject() : null; } public void setCurriculumEntry(ICurriculumEntry entry) { if (entry != null) { this.entry = new DomainReference((DomainObject) entry); } } @Override public int hashCode() { return getCurriculumEntry().hashCode(); } @Override public boolean equals(final Object obj) { if (!(obj instanceof SelectedCurriculumEntry)) { return false; } return getCurriculumEntry() == ((SelectedCurriculumEntry) obj).getCurriculumEntry(); } } public static class SelectedCompetenceCourseEntry extends SelectedCurriculumEntry { private static final long serialVersionUID = 1L; private Grade grade; private Double creditsEcts; private DomainReference competenceCourse; public SelectedCompetenceCourseEntry(CompetenceCourse competenceCourse) { super(null); setCompetenceCourse(competenceCourse); } public CompetenceCourse getCompetenceCourse() { return (this.competenceCourse != null) ? competenceCourse.getObject() : null; } public void setCompetenceCourse(CompetenceCourse competenceCourse) { if (competenceCourse != null) { this.competenceCourse = new DomainReference(competenceCourse); } } public Grade getGrade() { return grade; } public void setGrade(Grade grade) { this.grade = grade; } @Override public Double getCreditsEcts() { return creditsEcts != null ? creditsEcts : getCompetenceCourse().getEctsCredits(); } @Override public void setCreditsEcts(Double creditsEcts) { this.creditsEcts = creditsEcts; } @Override public int hashCode() { return getCompetenceCourse().hashCode(); } @Override public boolean equals(final Object obj) { if (!(obj instanceof SelectedCompetenceCourseEntry)) { return false; } return getCompetenceCourse() == ((SelectedCompetenceCourseEntry) obj).getCompetenceCourse(); } } public static class SelectedDismissalEntry implements Serializable { private static final long serialVersionUID = 1L; private Double creditsEcts; private Double weight = 1.0; private DomainReference executionPeriod; private DomainReference curriculumGroup; private DomainReference curricularCourse; private DomainReference studentCurricularPlan; public SelectedDismissalEntry(final StudentCurricularPlan studentCurricularPlan) { setStudentCurricularPlan(studentCurricularPlan); } public SelectedDismissalEntry(CurricularCourse curricularCourse, StudentCurricularPlan scp) { setCurricularCourse(curricularCourse); setStudentCurricularPlan(scp); } public SelectedDismissalEntry(CurricularCourse curricularCourse, StudentCurricularPlan studentCurricularPlan, CurriculumGroup curriculumGroup) { this(curricularCourse, studentCurricularPlan); setCurriculumGroup(curriculumGroup); } public String getName() { return getCurricularCourse().getName(getExecutionPeriod()); } public Double getCreditsEcts() { CurricularCourse dismissal = getCurricularCourse(); return dismissal == null || dismissal.isOptionalCurricularCourse() ? creditsEcts : dismissal.getEctsCredits(); } public Double getCreditsEcts(ExecutionPeriod executionPeriod) { final CurricularCourse curricularCourse = getCurricularCourse(); if (curricularCourse == null || curricularCourse.isOptionalCurricularCourse()) { return this.creditsEcts; } return curricularCourse.getEctsCredits(executionPeriod); } public void setCreditsEcts(Double creditsEcts) { this.creditsEcts = creditsEcts; } public Double getWeight() { return this.weight; } public void setWeight(Double weight) { this.weight = weight; } public ExecutionPeriod getExecutionPeriod() { return (this.executionPeriod != null) ? this.executionPeriod.getObject() : null; } public void setExecutionPeriod(ExecutionPeriod executionPeriod) { this.executionPeriod = (executionPeriod != null) ? new DomainReference(executionPeriod) : null; } public CurriculumGroup getCurriculumGroup() { return curriculumGroup != null ? curriculumGroup.getObject() : null; } public void setCurriculumGroup(CurriculumGroup curriculumGroup) { this.curriculumGroup = curriculumGroup != null ? new DomainReference(curriculumGroup) : null; } public CurricularCourse getCurricularCourse() { return curricularCourse != null ? curricularCourse.getObject() : null; } public void setCurricularCourse(CurricularCourse curricularCourse) { this.curricularCourse = curricularCourse != null ? new DomainReference(curricularCourse) : null; } public boolean hasCurricularCourse() { return getCurricularCourse() != null; } public StudentCurricularPlan getStudentCurricularPlan() { return (this.studentCurricularPlan != null) ? this.studentCurricularPlan.getObject() : null; } public void setStudentCurricularPlan(StudentCurricularPlan studentCurricularPlan) { this.studentCurricularPlan = (studentCurricularPlan != null) ? new DomainReference( studentCurricularPlan) : null; } @Override public int hashCode() { return getCurricularCourse().hashCode(); } @Override public boolean equals(final Object obj) { if (!(obj instanceof SelectedDismissalEntry)) { return false; } return getCurricularCourse() == ((SelectedDismissalEntry) obj).getCurricularCourse(); } } }