package net.sourceforge.fenixedu.dataTransferObject.pedagogicalCouncil.elections; import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.List; import net.sourceforge.fenixedu.domain.Degree; import net.sourceforge.fenixedu.domain.DomainReference; import net.sourceforge.fenixedu.domain.ExecutionYear; import net.sourceforge.fenixedu.domain.elections.DelegateElection; import net.sourceforge.fenixedu.domain.elections.YearDelegateElection; public class YearDelegateElectionsPeriodsByDegreeBean implements Serializable { private DomainReference executionYear; private DomainReference degree; private List> elections; private List> firstYearElections; private List> secondYearElections; private List> thirdYearElections; private List> fourthYearElections; private List> fifthYearElections; public YearDelegateElectionsPeriodsByDegreeBean(Degree degree, ExecutionYear executionYear, List elections) { setDegree(degree); setElections(elections); setExecutionYear(executionYear); for(int i = 1; i <= degree.getDegreeType().getYears(); i++) setElectionsByYear(i); } public Degree getDegree() { return (degree == null ? null : degree.getObject()); } public void setDegree(Degree degree) { this.degree = new DomainReference(degree); } public List getElections() { List result = new ArrayList(); for (DomainReference electionDR : this.elections) { result.add(electionDR.getObject()); } return result; } public void setElections(List elections) { this.elections = new ArrayList>(); for(YearDelegateElection election : elections) { this.elections.add(new DomainReference(election)); } } public ExecutionYear getExecutionYear() { return (executionYear == null ? null : executionYear.getObject()); } public void setExecutionYear(ExecutionYear executionYear) { this.executionYear = new DomainReference(executionYear); } private void setElectionsByYear (int year) { switch (year) { case 1: this.firstYearElections = getElectionsGivenYear(year); break; case 2: this.secondYearElections = getElectionsGivenYear(year); break; case 3: this.thirdYearElections = getElectionsGivenYear(year); break; case 4: this.fourthYearElections = getElectionsGivenYear(year); break; case 5: this.fifthYearElections = getElectionsGivenYear(year); break; default: break; } } public List> getElectionsGivenYear(int year) { List> givenYearElections = new ArrayList>(); for(DelegateElection election : getElections()) { if(((YearDelegateElection)election).getCurricularYear().getYear() == year) { givenYearElections.add(new DomainReference(election)); } } return givenYearElections; } public List getFirstYearElections() { List result = new ArrayList(); for (DomainReference electionDR : this.firstYearElections) { result.add((YearDelegateElection)electionDR.getObject()); } return result; } public List getSecondYearElections() { List result = new ArrayList(); for (DomainReference electionDR : this.secondYearElections) { result.add((YearDelegateElection)electionDR.getObject()); } return result; } public List getThirdYearElections() { List result = new ArrayList(); for (DomainReference electionDR : this.thirdYearElections) { result.add((YearDelegateElection)electionDR.getObject()); } return result; } public List getFourthYearElections() { List result = new ArrayList(); for (DomainReference electionDR : this.fourthYearElections) { result.add((YearDelegateElection)electionDR.getObject()); } return result; } public List getFifthYearElections() { List result = new ArrayList(); for (DomainReference electionDR : this.fifthYearElections) { result.add((YearDelegateElection)electionDR.getObject()); } return result; } //CANDIDACY PERIODS public YearDelegateElection getFirstYearLastCandidacyPeriod() { return (!getFirstYearElections().isEmpty() ? (YearDelegateElection)Collections.max(getFirstYearElections(), DelegateElection.ELECTION_COMPARATOR_BY_CANDIDACY_START_DATE) : null); } public YearDelegateElection getSecondYearLastCandidacyPeriod() { return (!getSecondYearElections().isEmpty() ? (YearDelegateElection)Collections.max(getSecondYearElections(), DelegateElection.ELECTION_COMPARATOR_BY_CANDIDACY_START_DATE) : null); } public YearDelegateElection getThirdYearLastCandidacyPeriod() { return (!getThirdYearElections().isEmpty() ? (YearDelegateElection)Collections.max(getThirdYearElections(), DelegateElection.ELECTION_COMPARATOR_BY_CANDIDACY_START_DATE) : null); } public YearDelegateElection getFourthYearLastCandidacyPeriod() { return (!getFourthYearElections().isEmpty() ? (YearDelegateElection)Collections.max(getFourthYearElections(), DelegateElection.ELECTION_COMPARATOR_BY_CANDIDACY_START_DATE) : null); } public YearDelegateElection getFifthYearLastCandidacyPeriod() { return (!getFifthYearElections().isEmpty() ? (YearDelegateElection)Collections.max(getFifthYearElections(), DelegateElection.ELECTION_COMPARATOR_BY_CANDIDACY_START_DATE) : null); } //VOTING PERIODS public YearDelegateElection getFirstYearVotingPeriod() { return getFirstYearLastCandidacyPeriod(); } public YearDelegateElection getSecondYearVotingPeriod() { return getSecondYearLastCandidacyPeriod(); } public YearDelegateElection getThirdYearVotingPeriod() { return getThirdYearLastCandidacyPeriod(); } public YearDelegateElection getFourthYearVotingPeriod() { return getFourthYearLastCandidacyPeriod(); } public YearDelegateElection getFifthYearVotingPeriod() { return getFifthYearLastCandidacyPeriod(); } }