r3858 - branches/pollen-1.5.x/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form
Author: tchemit Date: 2013-12-07 09:00:40 +0100 (Sat, 07 Dec 2013) New Revision: 3858 Url: http://chorem.org/projects/pollen/repository/revisions/3858 Log: fixes #962: You cannot modify the end date if there is a date to add choices Modified: branches/pollen-1.5.x/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/AbstractPollForm.java branches/pollen-1.5.x/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/ClonePoll.java branches/pollen-1.5.x/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/CreatePoll.java branches/pollen-1.5.x/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/EditPoll.java Modified: branches/pollen-1.5.x/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/AbstractPollForm.java =================================================================== --- branches/pollen-1.5.x/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/AbstractPollForm.java 2013-12-02 13:10:39 UTC (rev 3857) +++ branches/pollen-1.5.x/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/AbstractPollForm.java 2013-12-07 08:00:40 UTC (rev 3858) @@ -194,7 +194,7 @@ * * @since 1.3 */ - private Map<Integer, VotingList> votingLists; + Map<Integer, VotingList> votingLists; private PollUri pollUri; @@ -204,6 +204,8 @@ public abstract boolean isEdit(); + protected abstract void validateChoiceDate(Date currentTime); + @Override public void prepare() throws Exception { @@ -528,7 +530,19 @@ } validateInformations(); - validateOptions(); + validateVotingLists(); + + validateCreatorEmail(); + + Date currentTime = serviceContext.getCurrentTime(); + + validateChoiceDate(currentTime); + + validatePollDate(currentTime); + + validateMaxChoices(); + + validateReminderHourCountdown(); } @Override @@ -942,80 +956,43 @@ } } - protected void validateOptions() { - - if (isVoteStarted()) { - - // no validation on votingLists if vote is started - - } else { - - // -- VotingList -- // - - if (poll.isPollFree()) { - - // nothing to validate - - } else { - - Set<String> groups = Sets.newHashSet(); - Set<String> voters = Sets.newHashSet(); - Set<String> emails = Sets.newHashSet(); - - for (Map.Entry<Integer, VotingList> entry : votingLists.entrySet()) { - validateVotingList(entry.getKey(), - entry.getValue(), - groups, - voters, - emails); - } - } - } - - String creatorEmail = poll.getCreator().getEmail(); - if (StringUtils.isNotBlank(creatorEmail) && - !StringUtil.isEmail(creatorEmail)) { - - addOptionsError("poll.creator.email", - _("pollen.error.email.invalid")); - } - - Date currentTime = serviceContext.getCurrentTime(); - - if (validateEndDate(poll.getBeginChoiceDate(), poll.getEndChoiceDate())) { - - addOptionsError( - "poll.endChoiceDate", - _("pollen.error.poll.endChoiceDate.before.beginChoiceDate")); - } - - if (validateEndDate(currentTime, poll.getEndChoiceDate())) { - - addOptionsError( - "poll.endChoiceDate", - _("pollen.error.poll.endChoiceDate.before.now")); - } - + protected void validatePollDate(Date currentTime) { + // --- beginDate < endDate if (validateEndDate(poll.getBeginDate(), poll.getEndDate())) { addOptionsError("poll.endDate", _("pollen.error.poll.endDate.before.beginDate")); } - + // --- currentTime < endDate if (validateEndDate(currentTime, poll.getEndDate())) { addOptionsError( "poll.endDate", _("pollen.error.poll.endDate.before.now")); } + } - if (validateEndDate(poll.getEndChoiceDate(), poll.getEndDate())) { + protected void validateReminderHourCountdown() { + if (isReminder()) { - addOptionsError("poll.endChoiceDate", - _("pollen.error.poll.endChoiceDate.after.endDate")); + // validate reminderHourCountdown + + if (getReminderHourCountdown() == null) { + + // reminderHourCountdown == null + addOptionsError("reminderHourCountdown", + _("pollen.error.poll.reminderHourCountdown.required")); + } else if (getReminderHourCountdown() < 1) { + + // reminderHourCountdown <= 0 + addOptionsError("reminderHourCountdown", + _("pollen.error.poll.reminderHourCountdown.greater.than.0")); + } } + } + protected void validateMaxChoices() { if (isLimitChoice()) { // validate maxChoices @@ -1030,21 +1007,45 @@ _("pollen.error.poll.maxChoice.greater.than.0")); } } + } - if (isReminder()) { + protected void validateCreatorEmail() { + String creatorEmail = poll.getCreator().getEmail(); + if (StringUtils.isNotBlank(creatorEmail) && + !StringUtil.isEmail(creatorEmail)) { - // validate reminderHourCountdown + addOptionsError("poll.creator.email", + _("pollen.error.email.invalid")); + } + } - if (getReminderHourCountdown() == null) { + protected void validateVotingLists() { - // reminderHourCountdown == null - addOptionsError("reminderHourCountdown", - _("pollen.error.poll.reminderHourCountdown.required")); - } else if (getReminderHourCountdown() < 1) { + if (isVoteStarted()) { - // reminderHourCountdown <= 0 - addOptionsError("reminderHourCountdown", - _("pollen.error.poll.reminderHourCountdown.greater.than.0")); + // no validation on votingLists if vote is started + + } else { + + // -- VotingList -- // + + if (poll.isPollFree()) { + + // nothing to validate + + } else { + + Set<String> groups = Sets.newHashSet(); + Set<String> voters = Sets.newHashSet(); + Set<String> emails = Sets.newHashSet(); + + for (Map.Entry<Integer, VotingList> entry : votingLists.entrySet()) { + validateVotingList(entry.getKey(), + entry.getValue(), + groups, + voters, + emails); + } } } } Modified: branches/pollen-1.5.x/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/ClonePoll.java =================================================================== --- branches/pollen-1.5.x/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/ClonePoll.java 2013-12-02 13:10:39 UTC (rev 3857) +++ branches/pollen-1.5.x/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/ClonePoll.java 2013-12-07 08:00:40 UTC (rev 3858) @@ -24,6 +24,8 @@ import org.chorem.pollen.business.persistence.Poll; +import java.util.Date; + /** * Clones a poll. * @@ -51,4 +53,22 @@ return poll; } + @Override + protected void validateChoiceDate(Date currentTime) { + + // --- beginChoicedate < endChoiceDate + if (validateEndDate(poll.getBeginChoiceDate(), poll.getEndChoiceDate())) { + + addOptionsError( + "poll.endChoiceDate", + _("pollen.error.poll.endChoiceDate.before.beginChoiceDate")); + } + + // --- endChoiceDate < endDate + if (validateEndDate(poll.getEndChoiceDate(), poll.getEndDate())) { + + addOptionsError("poll.endChoiceDate", + _("pollen.error.poll.endChoiceDate.after.endDate")); + } + } } Modified: branches/pollen-1.5.x/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/CreatePoll.java =================================================================== --- branches/pollen-1.5.x/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/CreatePoll.java 2013-12-02 13:10:39 UTC (rev 3857) +++ branches/pollen-1.5.x/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/CreatePoll.java 2013-12-07 08:00:40 UTC (rev 3858) @@ -24,6 +24,8 @@ import org.chorem.pollen.business.persistence.Poll; +import java.util.Date; + /** * Creates a poll. * @@ -51,4 +53,30 @@ return poll; } + @Override + protected void validateChoiceDate(Date currentTime ) { + + // --- beginChoicedate < endChoiceDate + if (validateEndDate(poll.getBeginChoiceDate(), poll.getEndChoiceDate())) { + + addOptionsError( + "poll.endChoiceDate", + _("pollen.error.poll.endChoiceDate.before.beginChoiceDate")); + } + + // --- currentTime < endChoiceDate + if (validateEndDate(currentTime, poll.getEndChoiceDate())) { + + addOptionsError( + "poll.endChoiceDate", + _("pollen.error.poll.endChoiceDate.before.now")); + } + + // --- endChoiceDate < endDate + if (validateEndDate(poll.getEndChoiceDate(), poll.getEndDate())) { + + addOptionsError("poll.endChoiceDate", + _("pollen.error.poll.endChoiceDate.after.endDate")); + } + } } Modified: branches/pollen-1.5.x/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/EditPoll.java =================================================================== --- branches/pollen-1.5.x/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/EditPoll.java 2013-12-02 13:10:39 UTC (rev 3857) +++ branches/pollen-1.5.x/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/EditPoll.java 2013-12-07 08:00:40 UTC (rev 3858) @@ -25,6 +25,8 @@ import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.services.exceptions.PollNotFoundException; +import java.util.Date; + /** * Edit a poll (load it via {@link #input()}), and save it * via {@link #execute()}). @@ -55,4 +57,23 @@ return poll; } + @Override + protected void validateChoiceDate(Date currentTime) { + + // --- beginChoicedate < endChoiceDate + if (validateEndDate(poll.getBeginChoiceDate(), poll.getEndChoiceDate())) { + + addOptionsError( + "poll.endChoiceDate", + _("pollen.error.poll.endChoiceDate.before.beginChoiceDate")); + } + + // --- endChoiceDate < endDate + if (validateEndDate(poll.getEndChoiceDate(), poll.getEndDate())) { + + addOptionsError("poll.endChoiceDate", + _("pollen.error.poll.endChoiceDate.after.endDate")); + } + } + }
participants (1)
-
tchemit@users.chorem.org