@Override public void setCandidacyPeriod(DelegateElectionCandidacyPeriod candidacyPeriod) { if (candidacyPeriod != null) { validatePeriodGivenExecutionYear(getExecutionYear(), candidacyPeriod); if (hasLastVotingPeriod()) { if (candidacyPeriod.endsBefore(getLastVotingPeriod())) { throw new DomainException( "error.elections.edit.colidesWithVotingPeriod", new String[] { getDegree().getSigla(), getCurricularYear().getYear().toString(), candidacyPeriod.getPeriod(), getLastVotingPeriod().getPeriod() }); } } } super.setCandidacyPeriod(candidacyPeriod); }
@Override public void editCandidacyPeriod(final YearMonthDay startDate, final YearMonthDay endDate) { final DelegateElectionCandidacyPeriod candidacyPeriod = getCandidacyPeriod(); final DelegateElectionVotingPeriod votingPeriod = getVotingPeriod(startDate, endDate); if (candidacyPeriod.isPastPeriod() && votingPeriod != null && votingPeriod.getStartDate().isBefore(new YearMonthDay())) { throw new DomainException( "error.yearDelegateElections.edit.pastPeriod", new String[] { getDegree().getSigla(), getCurricularYear().getYear().toString(), getCandidacyPeriod().getPeriod() }); } else { try { candidacyPeriod.delete(); setCandidacyPeriod(new DelegateElectionCandidacyPeriod(startDate, endDate)); } catch (DomainException ex) { throw new DomainException(ex.getMessage(), ex.getArgs()); } } }
/* * Checks if the new election candidacy period colides with another election * candidacy period, previously added to this degree and curricular year */ private static void checkNewElectionCandidacyPeriod( Degree degree, ExecutionYear executionYear, CurricularYear curricularYear, DelegateElectionCandidacyPeriod candidacyPeriod) throws DomainException { for (DelegateElection election : degree.getYearDelegateElectionsGivenExecutionYearAndCurricularYear( executionYear, curricularYear)) { if (!election.getCandidacyPeriod().endsBefore(candidacyPeriod)) { throw new DomainException( "error.elections.newElection.invalidPeriod", new String[] { degree.getSigla(), curricularYear.getYear().toString(), candidacyPeriod.getPeriod(), election.getCandidacyPeriod().getPeriod() }); } } }