@Override public void addVotingPeriod(DelegateElectionVotingPeriod votingPeriod) { if (votingPeriod != null) { validatePeriodGivenExecutionYear(getExecutionYear(), votingPeriod); if (!hasCandidacyPeriod()) { throw new DomainException( "error.elections.createVotingPeriod.mustCreateCandidacyPeriod", new String[] {getDegree().getSigla(), getCurricularYear().getYear().toString()}); } if (!getCandidacyPeriod().endsBefore(votingPeriod)) { throw new DomainException( "error.elections.edit.colidesWithCandidacyPeriod", new String[] { getDegree().getSigla(), getCurricularYear().getYear().toString(), getCandidacyPeriod().getPeriod(), votingPeriod.getPeriod() }); } if (!getLastElectionPeriod().endsBefore(votingPeriod)) { throw new DomainException( "error.elections.edit.colidesWithPreviousVotingPeriod", new String[] { getDegree().getSigla(), getCurricularYear().getYear().toString(), getCandidacyPeriod().getPeriod(), votingPeriod.getPeriod() }); } } super.addVotingPeriod(votingPeriod); }
public DelegateElectionVotingPeriod getCurrentVotingPeriod() { for (DelegateElectionVotingPeriod votingPeriod : getVotingPeriod()) { if (votingPeriod.isCurrentPeriod()) { return votingPeriod; } } return null; }
@Override public void deleteVotingPeriod( DelegateElectionVotingPeriod votingPeriod, boolean removeElection) { if (!votingPeriod.isPastPeriod() && !votingPeriod.isCurrentPeriod()) { super.deleteVotingPeriod(votingPeriod); if (removeElection) { this.deleteCandidacyPeriod(); } } else { throw new DomainException( "error.yearDelegateElections.delete.pastPeriod", new String[] { getDegree().getSigla(), getCurricularYear().getYear().toString(), getVotingPeriod(votingPeriod.getStartDate(), votingPeriod.getEndDate()).getPeriod() }); } }
@Override public void editVotingPeriod( YearMonthDay startDate, YearMonthDay endDate, DelegateElectionVotingPeriod votingPeriod) { if (!endDate.isAfter(getLastVotingEndDate())) { throw new DomainException( "error.elections.edit.newEndDateMustBeGreater", getDegree().getSigla(), getCurricularYear().getYear().toString()); } if (!votingPeriod.isPastPeriod()) { votingPeriod.setEndDate(endDate); } else { throw new DomainException( "error.yearDelegateElections.edit.pastPeriod", new String[] { getDegree().getSigla(), getCurricularYear().getYear().toString(), votingPeriod.getPeriod() }); } }
@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()); } } }
public static StyledExcelSpreadsheet exportElectionsResultsToFile( List<Degree> degrees, ExecutionYear executionYear) throws IOException { StyledExcelSpreadsheet spreadsheet = new StyledExcelSpreadsheet(); final ResourceBundle BUNDLE = ResourceBundle.getBundle( "resources.PedagogicalCouncilResources", Language.getDefaultLocale()); for (Degree degree : degrees) { spreadsheet.getSheet(degree.getSigla()); List<YearDelegateElection> elections = sortByYear(degree.getYearDelegateElectionsGivenExecutionYear(executionYear)); for (YearDelegateElection election : elections) { if (election.hasLastVotingPeriod()) { DelegateElectionVotingPeriod votingPeriod = election.getLastVotingPeriod(); spreadsheet.newHeaderRow(); int fistHeaderRow = spreadsheet.getRow().getRowNum(); spreadsheet.addHeader( String.format( "%s - %s (%s)", BUNDLE.getString("label.elections.excel.curricularYear"), election.getCurricularYear().getYear(), votingPeriod.getPeriod()), 10000); spreadsheet .getSheet() .addMergedRegion(new Region(fistHeaderRow, (short) 0, fistHeaderRow, (short) 5)); spreadsheet.newRow(); if (votingPeriod.getVotesCount() == 0) { spreadsheet.addCell(BUNDLE.getString("label.elections.excel.not.have.votes")); } else { spreadsheet.addHeader(BUNDLE.getString("label.elections.excel.studentNumber"), 6000); spreadsheet.addHeader(BUNDLE.getString("label.elections.excel.studentName"), 10000); spreadsheet.addHeader(BUNDLE.getString("label.phone"), 4000); spreadsheet.addHeader(BUNDLE.getString("label.email"), 6000); spreadsheet.addHeader(BUNDLE.getString("label.address"), 12000); spreadsheet.addHeader(BUNDLE.getString("label.elections.excel.nrTotalVotes"), 5000); List<DelegateElectionResultsByStudentDTO> resultsByStudent = sortByResults(votingPeriod.getDelegateElectionResults()); for (DelegateElectionResultsByStudentDTO resultByStudent : resultsByStudent) { Student student = resultByStudent.getStudent(); Person person = student.getPerson(); String phone = (StringUtils.isEmpty(person.getDefaultPhoneNumber())) ? "-" : person.getDefaultPhoneNumber(); String email = (StringUtils.isEmpty(person.getDefaultEmailAddressValue())) ? "-" : person.getDefaultEmailAddressValue(); String address = (StringUtils.isEmpty(person.getAddress())) ? "-" : person.getAddress(); spreadsheet.newRow(); spreadsheet.addCell(student.getNumber()); spreadsheet.addCell(student.getName()); spreadsheet.addCell(phone); spreadsheet.addCell(email); spreadsheet.addCell(address); spreadsheet.addCell(resultByStudent.getVotesNumber()); } spreadsheet.setRegionBorder(fistHeaderRow, spreadsheet.getRow().getRowNum() + 1, 0, 2); spreadsheet.newRow(); spreadsheet.newRow(); spreadsheet.addCell(BUNDLE.getString("label.elections.excel.nrBlankTotalVotes")); spreadsheet.addCell( votingPeriod.getBlankVotesElection(), spreadsheet.getExcelStyle().getValueStyle()); } } spreadsheet.newRow(); spreadsheet.newRow(); } } return spreadsheet; }