package net.sourceforge.fenixedu.domain.executionCourse; import java.io.Serializable; import java.util.SortedSet; import java.util.TreeSet; import net.sourceforge.fenixedu.domain.DomainReference; import net.sourceforge.fenixedu.domain.ExecutionCourse; import net.sourceforge.fenixedu.domain.Professorship; import net.sourceforge.fenixedu.domain.Shift; import net.sourceforge.fenixedu.domain.ShiftType; import net.sourceforge.fenixedu.domain.Summary; public class SummariesSearchBean implements Serializable { private final DomainReference executionCourseDomainReference; private ShiftType shiftType; private DomainReference shiftDomainReference; private DomainReference professorshipDomainReference; private Boolean showOtherProfessors; private Boolean ascendant = false; public SummariesSearchBean(final ExecutionCourse executionCourse) { this.executionCourseDomainReference = new DomainReference(executionCourse); } public ExecutionCourse getExecutionCourse() { return executionCourseDomainReference.getObject(); } public Professorship getProfessorship() { return professorshipDomainReference == null ? null : professorshipDomainReference.getObject(); } public void setProfessorship(final Professorship professorship) { professorshipDomainReference = new DomainReference(professorship); } public Shift getShift() { return shiftDomainReference == null ? null : shiftDomainReference.getObject(); } public void setShift(final Shift shift) { shiftDomainReference = new DomainReference(shift); } public ShiftType getShiftType() { return shiftType; } public void setShiftType(ShiftType shiftType) { this.shiftType = shiftType; } public Boolean getShowOtherProfessors() { return showOtherProfessors; } public void setShowOtherProfessors(final Boolean showOtherProfessors) { this.showOtherProfessors = showOtherProfessors; } public SortedSet search() { final SortedSet summaries; if (isAscendant()) { summaries = new TreeSet(Summary.COMPARATOR_BY_DATE_AND_HOUR_ASC); } else { summaries = new TreeSet(Summary.COMPARATOR_BY_DATE_AND_HOUR); } for (final Summary summary : getExecutionCourse().getAssociatedSummariesSet()) { final Shift shift = summary.getShift(); if (getShift() == null || getShift() == shift) { if (getShiftType() == null || getShiftType() == summary.getSummaryType()) { final Professorship professorship = summary.getProfessorship(); if (getProfessorship() == null && showOtherProfessors == null) { summaries.add(summary); } else if (professorship == null && showOtherProfessors != null && showOtherProfessors.booleanValue()) { summaries.add(summary); } else if (showOtherProfessors == null && ((getProfessorship() == null && professorship != null) || getProfessorship() == professorship)) { summaries.add(summary); } } } } return summaries; } public SortedSet getSummaries() { return search(); } public SortedSet getSummariesInverted() { final SortedSet summaries = new TreeSet(Summary.COMPARATOR_BY_DATE_AND_HOUR_ASC); summaries.addAll(search()); return summaries; } public SortedSet getShiftTypes() { final SortedSet shiftTypes = new TreeSet(); for (final Shift shift : getExecutionCourse().getAssociatedShifts()) { shiftTypes.addAll(shift.getTypes()); } return shiftTypes; } public void setAscendant(Boolean descendant) { this.ascendant = descendant; } public Boolean isAscendant() { return ascendant; } }