r3192 - branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl
Author: tchemit Date: 2012-03-15 07:09:01 +0100 (Thu, 15 Mar 2012) New Revision: 3192 Url: http://chorem.org/repositories/revision/pollen/3192 Log: close poll action Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-14 17:22:21 UTC (rev 3191) +++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-15 06:09:01 UTC (rev 3192) @@ -65,6 +65,7 @@ import java.io.File; import java.io.IOException; import java.net.URL; +import java.util.Date; import java.util.List; public class PollService extends PollenServiceSupport { @@ -437,6 +438,48 @@ commitTransaction("Could not delete poll" + poll.getTitle()); } + public void closePoll(String pollId, + UserAccount userAccount, + String accountId) throws PollNotFoundException, PollAccountNotFound, UnauthorizedPollAccessException { + + Preconditions.checkNotNull(pollId); + Preconditions.checkNotNull(accountId); + + Poll poll = getPollByPollId(pollId); + + if (poll == null) { + throw new PollNotFoundException(); + } + + if (userAccount == null || userAccount.isAdministrator()) { + + // must check that accountId matches the poll creator id + + PollAccount account = getPollAccountByAccountId(accountId); + + if (account == null) { + throw new PollAccountNotFound(); + } + + if (!account.getAccountId().equals(poll.getCreator().getAccountId())) { + throw new UnauthorizedPollAccessException(); + } + } + + if (!poll.isChoiceEmpty()) { + for (Choice choice : poll.getChoice()) { + choice.setValidate(true); + } + } + Date now = new Date(); + if (poll.getEndDate() == null || now.before(poll.getEndDate())) { + poll.setEndDate(now); + } + poll.setClosed(true); + + commitTransaction("Could not close poll " + poll.getTitle()); + } + public void deleteVote(String pollId, String voteId) throws PollNotFoundException, PollVoteNotFoundException { @@ -517,9 +560,9 @@ return result; } + public static final String THUMB_PREFIX = "thumb_"; - /** * Sauvegarde des images d'un choix de type image. *
participants (1)
-
tchemit@users.chorem.org