r3148 - in branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main: java/org/chorem/pollen/ui/actions/poll resources/config resources/i18n webapp/WEB-INF/jsp/poll
Author: tchemit Date: 2012-02-26 18:20:56 +0100 (Sun, 26 Feb 2012) New Revision: 3148 Url: http://chorem.org/repositories/revision/pollen/3148 Log: continue vote page Added: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java Removed: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Result.java Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-02-26 17:19:55 UTC (rev 3147) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-02-26 17:20:56 UTC (rev 3148) @@ -26,9 +26,11 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.bean.PollResultListBean; import org.chorem.pollen.business.persistence.Choice; import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.PollAccount; +import org.chorem.pollen.business.persistence.Result; import org.chorem.pollen.business.persistence.UserAccount; import org.chorem.pollen.business.persistence.Vote; import org.chorem.pollen.business.persistence.VoteToChoice; @@ -37,10 +39,12 @@ import org.chorem.pollen.common.VoteCountingType; import org.chorem.pollen.services.exceptions.PollNotFoundException; import org.chorem.pollen.services.impl.PollFeedService; +import org.chorem.pollen.services.impl.PollResultsService; import org.chorem.pollen.services.impl.PollService; -import org.chorem.pollen.ui.actions.PollenActionSupport; +import org.chorem.pollen.services.impl.VoteService; import java.util.Date; +import java.util.List; /** * Abstract action for actions on the vote poll page. @@ -69,6 +73,10 @@ protected boolean pollRunning; + protected boolean alreadyVoted; + + private boolean anonymousVote; + protected String voteCountingTypeHelp; protected String defaultCommentName; @@ -83,6 +91,8 @@ private String pollAccountId; + private List<Result> results; + @Override public final String getPageLogo() { return "Vote"; @@ -105,6 +115,11 @@ } public PollAccount getPollAccount() { + if (pollAccount == null) { + PollService service = newService(PollService.class); + pollAccount = service.getNewPollAccount( + getPollenSession().getUserAccount()); + } return pollAccount; } @@ -116,6 +131,14 @@ return pollChoiceOrVoteStarted; } + public boolean isAlreadyVoted() { + return alreadyVoted; + } + + public boolean isAnonymousVote() { + return anonymousVote; + } + public final String getVoteCountingTypeHelp() { return voteCountingTypeHelp; } @@ -128,6 +151,10 @@ return commentName; } + public List<Result> getResults() { + return results; + } + public void prepareVotePage() throws Exception { loadPoll(); @@ -135,6 +162,10 @@ if (poll != null) { loadPollAccount(); + + loadPollResults(); + + PollFeedService pollFeedService = newService(PollFeedService.class); feedFileExisting = pollFeedService.isFeedExists(poll); @@ -168,7 +199,6 @@ defaultCommentName = userAccount.getDisplayName(); } - //TODO Fill this Date currentTime = serviceContext.getCurrentTime(); accountFieldDisplayed = !poll.getAnonymous() || isRestrictedPoll() || isGroupPoll(); @@ -198,38 +228,111 @@ } creatorName = poll.getCreator().getVotingId(); - // voteSizeMessage=XXX; } } - protected void loadPollAccount() { + private transient PollResultsService pollResultsService; + private PollResultsService getPollResultsService() { + if (pollResultsService == null) { + pollResultsService = newService(PollResultsService.class); + } + return pollResultsService; + } + + public String getResultValue(Choice choice) { + + String val = getPollResultsService().getResultValue(choice, results); + return val; + } + + protected void loadPollResults() { + + PollResultsService service = getPollResultsService(); + + PollResultListBean resultListDTO; + if (isGroupPoll()) { + resultListDTO = service.getGroupResults(poll.getPollId()); + } else { + resultListDTO = service.getNormalResults(poll.getPollId()); + } + + results = resultListDTO.getResultDTOs(); + + if (log.isDebugEnabled()) { + for (Result res : results) { + log.debug(res.getName() + ": " + res.getResultValue() + + ", (voteCounting=" + res.getVoteCountingType() + + ", byGroup=" + res.getByGroup() + ")"); + } + } + } + + protected void loadPollAccount() throws PollNotFoundException { + PollService service = newService(PollService.class); - if (StringUtils.isNotEmpty(getAccountId())) { + //// Contrôle et définition du votingId + alreadyVoted = false; + boolean modifAllowed = false; + boolean restrictedListsForbidden = false; - pollAccount = service.getPollAccountByAccountId(getAccountId()); + // The calcul of alreadyVoted will be needed for no double votingId + // Carefull, not correct for an anonymous vote + VoteService voteService = newService(VoteService.class); - if (pollAccount != null) { + // Suppression des espaces pouvant provoquer un double vote + String votingId = getPollAccount().getVotingId().trim(); + getPollAccount().setVotingId(votingId); - pollAccountId = pollAccount.getAccountId(); + alreadyVoted = voteService.hasAlreadyVoted(votingId, poll); - } else { + // Check for restricted poll + if (!alreadyVoted && !isFreePoll()) { + if (StringUtils.isNotEmpty(getAccountId())) { - //TODO Do something in case of none free poll ?, not normal :( - addActionError(_("pollen.error.accountNotFound")); + // The accountUId must be valid for the poll + PollAccount restrictedAccount = + service.getRestrictedAccount(getPollId(), getAccountId()); - if (!isFreePoll()) { + if (restrictedAccount != null) { + // PollAccount is replaced by the good account from db + pollAccount = restrictedAccount; - //TODO Should not be able to see the page ? + // Refresh alreadyVoted value depends on pollAccount +// alreadyVoted = pollAccount.isHasVoted(); + + } else { + // Existing account is null is forbidden for a restricted poll + restrictedListsForbidden = true; } + + } else { + // Not allowed to vote without an accountUId + restrictedListsForbidden = true; } - } else { - pollAccount = service.getNewPollAccount(getPollenSession().getUserAccount()); + if (restrictedListsForbidden) { + addActionError(_("pollen.error.user.restrictedListsForbidden")); + } } + + // Génération d'un identifiant de vote (si le sondage est libre et anonyme) + if (poll.getAnonymous()) { + anonymousVote = true; + if (isFreePoll()) { + getPollAccount().setVotingId( + "anonymous" + serviceContext.createPollenUrlId()); + } + } + + modifAllowed = isModifAllowed(getPollAccount().getVotingId()); + if (alreadyVoted && !modifAllowed) { + addActionError(_("pollen.error.user.alreadyVoted", + getPollAccount().getVotingId())); + } } public String escapeLineBreak(String text) { @@ -263,12 +366,14 @@ return result; } - public boolean isModifAllowed(Vote vote) { + public boolean isModifAllowed(String voteId) { boolean result = false; + Vote vote = poll.getVoteByTopiaId(voteId); + // can only modify a vote if poll is running. - if (pollRunning) { + if (vote != null && pollRunning) { PollAccount votePollAccount = vote.getPollAccount(); // si le votant du vote correspond au votant actuel (pollAccountId) Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Result.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Result.java 2012-02-26 17:19:55 UTC (rev 3147) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Result.java 2012-02-26 17:20:56 UTC (rev 3148) @@ -1,37 +0,0 @@ -/* - * #%L - * Pollen :: UI (strust2) - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package org.chorem.pollen.ui.actions.poll; - -import org.chorem.pollen.ui.actions.PollenActionSupport; - -/** - * Display results of a poll. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.2.6 - */ -public class Result extends PollenActionSupport { - - private static final long serialVersionUID = 1L; -} Copied: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java (from rev 3144, branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Result.java) =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java (rev 0) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-02-26 17:20:56 UTC (rev 3148) @@ -0,0 +1,37 @@ +/* + * #%L + * Pollen :: UI (strust2) + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package org.chorem.pollen.ui.actions.poll; + +import org.chorem.pollen.ui.actions.PollenActionSupport; + +/** + * Display results of a poll. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.2.6 + */ +public class ResultForPoll extends PollenActionSupport { + + private static final long serialVersionUID = 1L; +} Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-02-26 17:19:55 UTC (rev 3147) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-02-26 17:20:56 UTC (rev 3148) @@ -101,7 +101,7 @@ <!-- display poll result --> <action name="result" - class="org.chorem.pollen.ui.actions.poll.Result"> + class="org.chorem.pollen.ui.actions.poll.ResultForPoll"> <result name="input">/WEB-INF/jsp/poll/result.jsp</result> <result>/WEB-INF/jsp/home.jsp</result> </action> Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-02-26 17:19:55 UTC (rev 3147) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-02-26 17:20:56 UTC (rev 3148) @@ -100,11 +100,13 @@ pollen.error.pollAccount.email.required=Em@il mandatory pollen.error.pollAccount.not.found=Poll account not found pollen.error.pollAccount.votingId.required=Name mandatory +pollen.error.user.alreadyVoted=Someone has already used the name %s to vote. pollen.error.user.bad.login.or.password=Login or password invalid. pollen.error.user.email.already.used=This email is already used pollen.error.user.invalid.password=Invalid password pollen.error.user.login.already.used=This login is already used pollen.error.user.not.found=User not found +pollen.error.user.restrictedListsForbidden=The poll is restricted and you are not allowed to vote. Check if you have correctly used the link sent to you by email. pollen.fieldset.connexionInformation=Connexion informations pollen.fieldset.login=Login pollen.fieldset.poll.choices=Choices Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-02-26 17:19:55 UTC (rev 3147) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-02-26 17:20:56 UTC (rev 3148) @@ -102,11 +102,13 @@ pollen.error.pollAccount.email.required=Em@il obliqatoire pollen.error.pollAccount.not.found=Membre non trouvé pollen.error.pollAccount.votingId.required=Nom obliqatoire +pollen.error.user.alreadyVoted=Une personne a d\u00E9j\u00E0 vot\u00E9 sous le nom %s. pollen.error.user.bad.login.or.password=Mauvais identifiant ou mot de passe. pollen.error.user.email.already.used=Le courriel saisi est déjà utilisé par un autre utilisateur pollen.error.user.invalid.password=Mot de passe invalide pollen.error.user.login.already.used=Le login saisie est déjà utilisé par un autre utilisateur pollen.error.user.not.found=Utilisateur non trouvé +pollen.error.user.restrictedListsForbidden=Le sondage est restreint et vous n'\u00EAtes pas autoris\u00E9 \u00E0 voter. V\u00E9rifiez que vous avez bien utiliser le lien qui vous a \u00E9t\u00E9 envoy\u00E9. pollen.fieldset.connexionInformation=Information de connexion pollen.fieldset.login=Connexion pollen.fieldset.poll.choices=Les choix Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-02-26 17:19:55 UTC (rev 3147) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-02-26 17:20:56 UTC (rev 3148) @@ -309,7 +309,7 @@ </s:else> </s:if> <s:if test="!poll.anonymous"> - <s:if test="isModifAllowed(#vote)"> + <s:if test="isModifAllowed(#vote.topiaId)"> <s:a action="editVote" namespace="/poll"> <s:param name="uriId" value="%{uriId}"/> <s:param name="voteId" value="%{#vote.topiaId}"/> @@ -348,8 +348,8 @@ </s:if> <s:if test="percentageVoteCounting"> <s:if test="isChoiceInVote(#currentVoteChoice)"> - <td class="voted"><s:property - value="%{#currentVoteChoice.voteValue}"/> % + <td class="voted"> + <s:property value="%{#currentVoteChoice.voteValue}"/> % </td> </s:if> <s:else> @@ -358,8 +358,9 @@ </s:if> <s:if test="condorcetVoteCounting"> <s:if test="isChoiceInVote(#currentVoteChoice)"> - <td class="voted"><s:property - value="%{#currentVoteChoice.voteValue}"/></td> + <td class="voted"> + <s:property value="%{#currentVoteChoice.voteValue}"/> + </td> </s:if> <s:else> <td class="notVoted"></td> @@ -368,8 +369,9 @@ <s:if test="numberVoteCounting"> <s:if test="isChoiceInVote(#currentVoteChoice)"> - <td class="voted"><s:property - value="%{#currentVoteChoice.voteValue}"/></td> + <td class="voted"> + <s:property value="%{#currentVoteChoice.voteValue}"/> + </td> </s:if> <s:else> <td class="notVoted"></td> @@ -394,7 +396,9 @@ <s:iterator value="poll.choice" var="choice"> <s:if test="!isChoiceHidden(#choice)"> - <td class="result">TODO ${currentChoiceResult}</td> + <td class="result"> + <s:property value="%{getResultValue(#choice)}"/> + </td> </s:if> </s:iterator> </tr>
participants (1)
-
tchemit@users.chorem.org