r3698 - in trunk: . pollen-persistence pollen-persistence/src/main/java/org/chorem/pollen pollen-persistence/src/main/java/org/chorem/pollen/business/persistence pollen-persistence/src/main/resources/i18n pollen-persistence/src/main/xmi pollen-services pollen-services/src/main/java/org/chorem/pollen/bean pollen-services/src/main/java/org/chorem/pollen/entities/migration pollen-services/src/main/java/org/chorem/pollen/services pollen-services/src/main/java/org/chorem/pollen/services/impl pol
Author: tchemit Date: 2012-09-23 15:01:38 +0200 (Sun, 23 Sep 2012) New Revision: 3698 Url: http://chorem.org/repositories/revision/pollen/3698 Log: refs #590: Refactor votecounting module (remove votecounting module) fixes #541: Add new voting system (Instant-runoff voting aka alternative vote) fixes #542: Add new voting system (Borda count) fixes #543: Add new voting system (Coombs' method) Added: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/ChoiceType.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/I18nAble.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollType.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/Polls.java trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/GroupOfVoterBuilder.java trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/SimpleVoterBuilder.java Removed: trunk/pollen-services/src/main/java/org/chorem/pollen/bean/PollResultList.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServicePredicates.java trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/ChoiceType.java trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/I18nAble.java trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/PollType.java Modified: trunk/pollen-persistence/pom.xml trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfiguration.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfigurationOption.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenFunctions.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollCommentVisibility.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollVoteVisibility.java trunk/pollen-persistence/src/main/resources/i18n/pollen-persistence_en_GB.properties trunk/pollen-persistence/src/main/resources/i18n/pollen-persistence_fr_FR.properties trunk/pollen-persistence/src/main/xmi/pollen.zargo trunk/pollen-services/pom.xml trunk/pollen-services/src/main/java/org/chorem/pollen/bean/PollResult.java trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_3.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollVoteCountingService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java trunk/pollen-ui-struts2/pom.xml trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/AbstractPollForm.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AbstractVoteAction.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AddChoice.java trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/result.jsp trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/ChoiceScore.java trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/GroupOfVoter.java trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/GroupVoteCountingResult.java trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/SimpleVoter.java trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/VoteCountingResult.java trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/VoteForChoice.java trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/Voter.java trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/VoterBuilder.java trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/strategy/AbstractVoteCountingStrategy.java trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategy.java trunk/pollen-votecounting-strategy-borda/src/test/java/org/chorem/pollen/votecounting/strategy/BordaStrategyTest.java trunk/pollen-votecounting-strategy-condorcet/src/test/java/org/chorem/pollen/votecounting/strategy/CondorcetStrategyTest.java trunk/pollen-votecounting-strategy-coombs/src/test/java/org/chorem/pollen/votecounting/strategy/CoombsStrategyTest.java trunk/pollen-votecounting-strategy-instant-runoff/src/test/java/org/chorem/pollen/votecounting/strategy/InstantRunoffStrategyTest.java trunk/pollen-votecounting-strategy-normal/src/test/java/org/chorem/pollen/votecounting/strategy/NormalStrategyTest.java trunk/pollen-votecounting-strategy-number/src/test/java/org/chorem/pollen/votecounting/strategy/NumberStrategyTest.java trunk/pollen-votecounting-strategy-percentage/src/test/java/org/chorem/pollen/votecounting/strategy/PercentageStrategyTest.java trunk/pom.xml Modified: trunk/pollen-persistence/pom.xml =================================================================== --- trunk/pollen-persistence/pom.xml 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-persistence/pom.xml 2012-09-23 13:01:38 UTC (rev 3698) @@ -17,9 +17,10 @@ <artifactId>pollen-persistence</artifactId> <dependencies> + <dependency> <groupId>${project.groupId}</groupId> - <artifactId>pollen-votecounting</artifactId> + <artifactId>pollen-votecounting-api</artifactId> <version>${project.version}</version> </dependency> Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfiguration.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfiguration.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfiguration.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -28,10 +28,10 @@ import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.business.persistence.ChoiceType; import org.chorem.pollen.business.persistence.PollCommentVisibility; +import org.chorem.pollen.business.persistence.PollType; import org.chorem.pollen.business.persistence.PollVoteVisibility; -import org.chorem.pollen.common.ChoiceType; -import org.chorem.pollen.common.PollType; import org.nuiton.util.ApplicationConfig; import org.nuiton.util.ArgumentsParserException; import org.nuiton.util.FileUtil; Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfigurationOption.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfigurationOption.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfigurationOption.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -24,8 +24,8 @@ import org.chorem.pollen.business.persistence.PollCommentVisibility; import org.chorem.pollen.business.persistence.PollVoteVisibility; -import org.chorem.pollen.common.ChoiceType; -import org.chorem.pollen.common.PollType; +import org.chorem.pollen.business.persistence.ChoiceType; +import org.chorem.pollen.business.persistence.PollType; import org.hibernate.dialect.H2Dialect; import org.nuiton.util.ApplicationConfig; Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenFunctions.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenFunctions.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenFunctions.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -23,27 +23,13 @@ package org.chorem.pollen; import com.google.common.base.Function; -import com.google.common.collect.Lists; import org.apache.commons.lang3.tuple.Pair; -import org.chorem.pollen.business.persistence.Choice; -import org.chorem.pollen.business.persistence.Comment; -import org.chorem.pollen.business.persistence.PersonToList; import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.PollAccount; import org.chorem.pollen.business.persistence.UserAccount; import org.chorem.pollen.business.persistence.Vote; -import org.chorem.pollen.business.persistence.VoteToChoice; -import org.chorem.pollen.business.persistence.VotingList; -import org.chorem.pollen.votecounting.business.NumberMethod; -import org.chorem.pollen.votecounting.dto.CommentDTO; -import org.chorem.pollen.votecounting.dto.PollChoiceDTO; -import org.chorem.pollen.votecounting.dto.PollDTO; -import org.chorem.pollen.votecounting.dto.VoteToChoiceDTO; -import org.chorem.pollen.votecounting.dto.VotingGroupDTO; -import org.chorem.pollen.votecounting.dto.VotingPersonDTO; import org.nuiton.topia.persistence.TopiaEntity; -import java.util.List; import java.util.Map; /** @@ -68,97 +54,97 @@ } }; - public static final Function<Poll, PollDTO> POLL_TO_BEAN = new Function<Poll, PollDTO>() { - @Override - public PollDTO apply(Poll input) { - PollDTO result = new PollDTO(input.getPollId()); - result.setTitle(input.getTitle()); - result.setDescription(input.getDescription()); - result.setBeginChoiceDate(input.getBeginChoiceDate()); - result.setBeginDate(input.getBeginDate()); - result.setEndDate(input.getEndDate()); - result.setAnonymous(input.isAnonymous()); - result.setAnonymousVoteAllowed(input.isAnonymousVoteAllowed()); - result.setPublicResults(input.isPublicResults()); - result.setContinuousResults(input.isContinuousResults()); - result.setChoiceAddAllowed(input.isChoiceAddAllowed()); - result.setClosed(input.isClosed()); - result.setCreatorId(input.getCreator().getVotingId()); - result.setCreatorEmail(input.getCreator().getEmail()); - result.setMaxChoiceNb(input.getMaxChoiceNb()); - result.setPollType(input.getPollType()); - result.setChoiceType(input.getChoiceType()); - result.setVoteCounting(input.getVoteCountingType()); +// public static final Function<Poll, PollDTO> POLL_TO_BEAN = new Function<Poll, PollDTO>() { +// @Override +// public PollDTO apply(Poll input) { +// PollDTO result = new PollDTO(input.getPollId()); +// result.setTitle(input.getTitle()); +// result.setDescription(input.getDescription()); +// result.setBeginChoiceDate(input.getBeginChoiceDate()); +// result.setBeginDate(input.getBeginDate()); +// result.setEndDate(input.getEndDate()); +// result.setAnonymous(input.isAnonymous()); +// result.setAnonymousVoteAllowed(input.isAnonymousVoteAllowed()); +// result.setPublicResults(input.isPublicResults()); +// result.setContinuousResults(input.isContinuousResults()); +// result.setChoiceAddAllowed(input.isChoiceAddAllowed()); +// result.setClosed(input.isClosed()); +// result.setCreatorId(input.getCreator().getVotingId()); +// result.setCreatorEmail(input.getCreator().getEmail()); +// result.setMaxChoiceNb(input.getMaxChoiceNb()); +// result.setPollType(input.getPollType()); +// result.setChoiceType(input.getChoiceType()); +// result.setVoteCounting(input.getVoteCountingType()); +// +// result.setComments(Lists.transform(input.getComment(), +// COMMENT_TO_BEAN)); +// +// result.setChoices(Lists.transform(input.getChoice(), +// CHOICE_TO_BEAN)); +// +// if (!input.isVotingListEmpty()) { +// +// result.setVotingGroups(Lists.transform(input.getVotingList(), +// newVotingListToBean(input) +// )); +// } else { +// // un groupe par défaut si il y en a pas +// VotingGroupDTO group = new VotingGroupDTO("unique", 1); +// group.setName("unique"); +// List<VotingPersonDTO> votes = Lists.transform(input.getVote(), +// VOTE_TO_BEAN); +// group.setVotingPersons(votes); +// result.getVotingGroups().add(group); +// } +// return result; +// } +// }; +// +// public static final Function<Comment, CommentDTO> COMMENT_TO_BEAN = new Function<Comment, CommentDTO>() { +// @Override +// public CommentDTO apply(Comment input) { +// CommentDTO result = new CommentDTO( +// input.getAuthor(), input.getText()); +// return result; +// } +// }; +// +// public static final Function<Choice, PollChoiceDTO> CHOICE_TO_BEAN = new Function<Choice, PollChoiceDTO>() { +// @Override +// public PollChoiceDTO apply(Choice input) { +// PollChoiceDTO result = new PollChoiceDTO(input.getTopiaId()); +// String choiceName = input.getName(); +// result.setName(choiceName); +// result.setHidden(choiceName != null && +// choiceName.startsWith(NumberMethod.HIDDEN_PREFIX)); +// result.setDescription(input.getDescription()); +// return result; +// } +// }; +// +// public static Function<VotingList, VotingGroupDTO> newVotingListToBean(final Poll poll) { +// return new Function<VotingList, VotingGroupDTO>() { +// @Override +// public VotingGroupDTO apply(VotingList input) { +// VotingGroupDTO result = new VotingGroupDTO( +// input.getTopiaId(), +// input.getWeight()); +// +// result.setName(input.getName()); +// +// for (PersonToList pToList : input.getPollAccountPersonToList()) { +// Vote vote = poll.getVoteByPollAccount(pToList.getPollAccount()); +// if (vote != null) { +// // Pas de vote pour cette personne : doit engendrer erreur ?!? +// VotingPersonDTO bean = VOTE_TO_BEAN.apply(vote); +// result.getVotingPersons().add(bean); +// } +// } +// return result; +// } +// }; +// } - result.setComments(Lists.transform(input.getComment(), - COMMENT_TO_BEAN)); - - result.setChoices(Lists.transform(input.getChoice(), - CHOICE_TO_BEAN)); - - if (!input.isVotingListEmpty()) { - - result.setVotingGroups(Lists.transform(input.getVotingList(), - newVotingListToBean(input) - )); - } else { - // un groupe par défaut si il y en a pas - VotingGroupDTO group = new VotingGroupDTO("unique", 1); - group.setName("unique"); - List<VotingPersonDTO> votes = Lists.transform(input.getVote(), - VOTE_TO_BEAN); - group.setVotingPersons(votes); - result.getVotingGroups().add(group); - } - return result; - } - }; - - public static final Function<Comment, CommentDTO> COMMENT_TO_BEAN = new Function<Comment, CommentDTO>() { - @Override - public CommentDTO apply(Comment input) { - CommentDTO result = new CommentDTO( - input.getAuthor(), input.getText()); - return result; - } - }; - - public static final Function<Choice, PollChoiceDTO> CHOICE_TO_BEAN = new Function<Choice, PollChoiceDTO>() { - @Override - public PollChoiceDTO apply(Choice input) { - PollChoiceDTO result = new PollChoiceDTO(input.getTopiaId()); - String choiceName = input.getName(); - result.setName(choiceName); - result.setHidden(choiceName != null && - choiceName.startsWith(NumberMethod.HIDDEN_PREFIX)); - result.setDescription(input.getDescription()); - return result; - } - }; - - public static Function<VotingList, VotingGroupDTO> newVotingListToBean(final Poll poll) { - return new Function<VotingList, VotingGroupDTO>() { - @Override - public VotingGroupDTO apply(VotingList input) { - VotingGroupDTO result = new VotingGroupDTO( - input.getTopiaId(), - input.getWeight()); - - result.setName(input.getName()); - - for (PersonToList pToList : input.getPollAccountPersonToList()) { - Vote vote = poll.getVoteByPollAccount(pToList.getPollAccount()); - if (vote != null) { - // Pas de vote pour cette personne : doit engendrer erreur ?!? - VotingPersonDTO bean = VOTE_TO_BEAN.apply(vote); - result.getVotingPersons().add(bean); - } - } - return result; - } - }; - } - // public static final Function<VotingList, VotingGroupDTO> VOTING_LIST_TO_BEAN = new Function<VotingList, VotingGroupDTO>() { // @Override // public VotingGroupDTO apply(VotingList input) { @@ -180,36 +166,44 @@ // } // }; - public static final Function<Vote, VotingPersonDTO> VOTE_TO_BEAN = new Function<Vote, VotingPersonDTO>() { + public static final Function<Vote, PollAccount> VOTE_TO_POLL_ACCOUNT = new Function<Vote, PollAccount>() { @Override - public VotingPersonDTO apply(Vote input) { - VotingPersonDTO result = - new VotingPersonDTO(input.getPollAccount().getVotingId(), input.getWeight()); - result.setEmail(input.getPollAccount().getEmail()); - - if (!input.isChoiceVoteToChoiceEmpty()) { - for (VoteToChoice vToChoice : input.getChoiceVoteToChoice()) { - if (vToChoice != null && vToChoice.getChoice() != null) { - VoteToChoiceDTO bean = VOTE_TO_CHOICE_TO_BEAN.apply(vToChoice); - result.getChoices().add(bean); - } - } - } + public PollAccount apply(Vote input) { + PollAccount result = input.getPollAccount(); return result; } }; - public static final Function<VoteToChoice, VoteToChoiceDTO> VOTE_TO_CHOICE_TO_BEAN = new Function<VoteToChoice, VoteToChoiceDTO>() { - @Override - public VoteToChoiceDTO apply(VoteToChoice input) { - VoteToChoiceDTO result = new VoteToChoiceDTO( - input.getChoice().getTopiaId(), - input.getVoteValue()); +// public static final Function<Vote, VotingPersonDTO> VOTE_TO_BEAN = new Function<Vote, VotingPersonDTO>() { +// @Override +// public VotingPersonDTO apply(Vote input) { +// VotingPersonDTO result = +// new VotingPersonDTO(input.getPollAccount().getVotingId(), input.getWeight()); +// result.setEmail(input.getPollAccount().getEmail()); +// +// if (!input.isChoiceVoteToChoiceEmpty()) { +// for (VoteToChoice vToChoice : input.getChoiceVoteToChoice()) { +// if (vToChoice != null && vToChoice.getChoice() != null) { +// VoteToChoiceDTO bean = VOTE_TO_CHOICE_TO_BEAN.apply(vToChoice); +// result.getChoices().add(bean); +// } +// } +// } +// return result; +// } +// }; +// +// public static final Function<VoteToChoice, VoteToChoiceDTO> VOTE_TO_CHOICE_TO_BEAN = new Function<VoteToChoice, VoteToChoiceDTO>() { +// @Override +// public VoteToChoiceDTO apply(VoteToChoice input) { +// VoteToChoiceDTO result = new VoteToChoiceDTO( +// input.getChoice().getTopiaId(), +// input.getVoteValue()); +// +// return result; +// } +// }; - return result; - } - }; - public static final Function<Map.Entry<Poll, PollAccount>, Pair<Poll, PollAccount>> MAP_ENTRY_TO_PAIR_FUNCTION = new Function<Map.Entry<Poll, PollAccount>, Pair<Poll, PollAccount>>() { @Override public Pair<Poll, PollAccount> apply(Map.Entry<Poll, PollAccount> input) { Copied: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/ChoiceType.java (from rev 3691, trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/ChoiceType.java) =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/ChoiceType.java (rev 0) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/ChoiceType.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -0,0 +1,54 @@ +/* + * #%L + * Pollen :: Vote Counting + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 CodeLutin + * %% + * 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.business.persistence; + +import static org.nuiton.i18n.I18n.n_; + +public enum ChoiceType implements I18nAble { + TEXT(n_("pollen.choiceType.text")), + DATE(n_("pollen.choiceType.date")), + IMAGE(n_("pollen.choiceType.image")); + + private final String i18nKey; + + ChoiceType(String i18nKey) { + this.i18nKey = i18nKey; + } + + @Override + public String getI18nKey() { + return i18nKey; + } + + public static ChoiceType valueOf(int ordinal) { + + ChoiceType result = null; + for (ChoiceType curr : ChoiceType.values()) { + if (curr.ordinal() == ordinal) { + result = curr; + break; + } + } + return result; + } +} Property changes on: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/ChoiceType.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/I18nAble.java (from rev 3691, trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/I18nAble.java) =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/I18nAble.java (rev 0) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/I18nAble.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -0,0 +1,34 @@ +/* + * #%L + * Pollen :: Vote Counting + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 CodeLutin + * %% + * 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.business.persistence; + +/** + * Contract to expose a i18n key. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public interface I18nAble { + + String getI18nKey(); +} Property changes on: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/I18nAble.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollCommentVisibility.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollCommentVisibility.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollCommentVisibility.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -22,8 +22,6 @@ * #L% */ -import org.chorem.pollen.common.I18nAble; - import static org.nuiton.i18n.I18n.n_; /** Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -24,7 +24,6 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Lists; -import org.chorem.pollen.common.PollType; import java.util.Date; import java.util.List; Copied: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollType.java (from rev 3691, trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/PollType.java) =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollType.java (rev 0) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollType.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -0,0 +1,54 @@ +/* + * #%L + * Pollen :: Vote Counting + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 CodeLutin + * %% + * 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.business.persistence; + +import static org.nuiton.i18n.I18n.n_; + +public enum PollType implements I18nAble { + + FREE(n_("pollen.pollType.free")), + RESTRICTED(n_("pollen.pollType.restricted")), + GROUP(n_("pollen.pollType.group")); + + private final String i18nKey; + + PollType(String i18nKey) { + this.i18nKey = i18nKey; + } + + @Override + public String getI18nKey() { + return i18nKey; + } + + public static PollType valueOf(int ordinal) { + PollType result = null; + for (PollType curr : PollType.values()) { + if (curr.ordinal() == ordinal) { + result = curr; + break; + } + } + return result; + } +} Property changes on: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollType.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:mergeinfo + Added: svn:eol-style + native Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollVoteVisibility.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollVoteVisibility.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollVoteVisibility.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -22,8 +22,6 @@ * #L% */ -import org.chorem.pollen.common.I18nAble; - import static org.nuiton.i18n.I18n.n_; /** Added: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/Polls.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/Polls.java (rev 0) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/Polls.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -0,0 +1,96 @@ +package org.chorem.pollen.business.persistence; + +import com.google.common.base.Preconditions; +import com.google.common.collect.Maps; +import org.chorem.pollen.PollenFunctions; +import org.chorem.pollen.votecounting.model.GroupOfVoter; +import org.chorem.pollen.votecounting.model.GroupOfVoterBuilder; +import org.chorem.pollen.votecounting.model.SimpleVoterBuilder; +import org.chorem.pollen.votecounting.model.Voter; +import org.chorem.pollen.votecounting.model.VoterBuilder; +import org.chorem.pollen.votecounting.strategy.VoteCountingStrategy; +import org.chorem.pollen.votecounting.strategy.VoteCountingStrategyProvider; + +import java.util.Map; +import java.util.Set; + +/** + * Useful methods around {@link Poll}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4.6 + */ +public class Polls { + + public static boolean isGroupPoll(Poll poll) { + return PollType.GROUP == poll.getPollType(); + } + + public static boolean isRestrictedPoll(Poll poll) { + return PollType.RESTRICTED == poll.getPollType(); + } + + public static boolean isFreePoll(Poll poll) { + return PollType.FREE == poll.getPollType(); + } + + public static GroupOfVoter toSimpleGroupOfVoters(Poll poll) { + Preconditions.checkNotNull(poll); + SimpleVoterBuilder builder = new SimpleVoterBuilder(); + + for (Vote vote : poll.getVote()) { + fillSimpleVoter(builder, vote); + } + Set<Voter> voter = builder.getVoters(); + GroupOfVoter result = GroupOfVoter.newVoter(null, 1.0, voter); + return result; + } + + public static GroupOfVoter toGroupOfVoters(Poll poll) { + Preconditions.checkNotNull(poll); + GroupOfVoterBuilder builder = new GroupOfVoterBuilder(); + + // create group of voter + Map<PollAccount, Vote> voteByPollAccount = Maps.uniqueIndex( + poll.getVote(), PollenFunctions.VOTE_TO_POLL_ACCOUNT); + + for (VotingList votingList : poll.getVotingList()) { + + builder.newGroupVoter(votingList.getTopiaId(), + votingList.getWeight()); + + for (PersonToList personToList : votingList.getPollAccountPersonToList()) { + PollAccount voterAccount = personToList.getPollAccount(); + Vote vote = voteByPollAccount.get(voterAccount); + if (vote != null) { + fillSimpleVoter(builder, vote); + } + } + } + + Set<Voter> voter = builder.getVoters(); + GroupOfVoter result = GroupOfVoter.newVoter(null, 1.0, voter); + return result; + } + + public static VoteCountingStrategy getVoteCountingStrategy(VoteCountingStrategyProvider provider, Poll poll) { + Preconditions.checkNotNull(provider); + Preconditions.checkNotNull(poll); + int strategyId = poll.getVoteCountingType(); + VoteCountingStrategy result = provider.getStrategy(strategyId); + Preconditions.checkNotNull( + result, "Could not find strategry for id " + strategyId); + return result; + } + + + protected static void fillSimpleVoter(VoterBuilder builder, Vote vote) { + builder.newVoter(vote.getPollAccount().getAccountId(), vote.getWeight()); + for (VoteToChoice voteToChoice : vote.getChoiceVoteToChoice()) { + builder.addVoteForChoice( + voteToChoice.getChoice().getTopiaId(), + Double.valueOf(voteToChoice.getVoteValue())); + } + + } +} Property changes on: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/Polls.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/pollen-persistence/src/main/resources/i18n/pollen-persistence_en_GB.properties =================================================================== --- trunk/pollen-persistence/src/main/resources/i18n/pollen-persistence_en_GB.properties 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-persistence/src/main/resources/i18n/pollen-persistence_en_GB.properties 2012-09-23 13:01:38 UTC (rev 3698) @@ -34,3 +34,13 @@ pollen.pollVoteVisibilty.nobody.help=Poll is anonymous, nobody can see votes pollen.pollVoteVisibilty.participantOnly=Visible for participant pollen.pollVoteVisibilty.participantOnly.help=Only poll's participants can see votes +pollen.choiceType.date=Date +pollen.choiceType.image=Image +pollen.choiceType.text=Text +pollen.pollType.free=Free +pollen.pollType.group=Group +pollen.pollType.restricted=Restricted +pollen.voteCountingType.condorcet=Condorcet +pollen.voteCountingType.normal=Normal +pollen.voteCountingType.number=Number +pollen.voteCountingType.percentage=Percentage Modified: trunk/pollen-persistence/src/main/resources/i18n/pollen-persistence_fr_FR.properties =================================================================== --- trunk/pollen-persistence/src/main/resources/i18n/pollen-persistence_fr_FR.properties 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-persistence/src/main/resources/i18n/pollen-persistence_fr_FR.properties 2012-09-23 13:01:38 UTC (rev 3698) @@ -34,3 +34,13 @@ pollen.pollVoteVisibilty.nobody.help=Le sondage est anonyme, personne ne peut voir les votes pollen.pollVoteVisibilty.participantOnly=Visible pour les participants pollen.pollVoteVisibilty.participantOnly.help=Seuls les participants du sondage peuvent voir les votes +pollen.choiceType.date=Date +pollen.choiceType.image=Image +pollen.choiceType.text=Texte +pollen.pollType.free=Libre +pollen.pollType.group=Groupe +pollen.pollType.restricted=Restreint +pollen.voteCountingType.condorcet=Condorcet +pollen.voteCountingType.normal=Normal +pollen.voteCountingType.number=Nombre +pollen.voteCountingType.percentage=Pourcentage Modified: trunk/pollen-persistence/src/main/xmi/pollen.zargo =================================================================== (Binary files differ) Modified: trunk/pollen-services/pom.xml =================================================================== --- trunk/pollen-services/pom.xml 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-services/pom.xml 2012-09-23 13:01:38 UTC (rev 3698) @@ -1,5 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> @@ -17,18 +19,15 @@ <artifactId>pollen-services</artifactId> <dependencies> + <dependency> <groupId>${project.groupId}</groupId> <artifactId>pollen-votecounting-api</artifactId> <version>${project.version}</version> </dependency> + <dependency> <groupId>${project.groupId}</groupId> - <artifactId>pollen-votecounting</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> <artifactId>pollen-persistence</artifactId> <version>${project.version}</version> </dependency> Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/bean/PollResult.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/bean/PollResult.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/bean/PollResult.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -23,7 +23,7 @@ package org.chorem.pollen.bean; import org.apache.commons.lang3.builder.ToStringBuilder; -import org.chorem.pollen.common.ChoiceType; +import org.chorem.pollen.business.persistence.ChoiceType; import java.io.Serializable; @@ -52,25 +52,6 @@ private boolean hidden; - public PollResult() { - - } - - public PollResult(String id) { - this.id = id; - } - - public PollResult(String name, - String pollId, - ChoiceType choiceType, - int voteCountingType) { - super(); - this.name = name; - this.pollId = pollId; - this.choiceType = choiceType; - this.voteCountingType = voteCountingType; - } - public String getId() { return id; } Deleted: trunk/pollen-services/src/main/java/org/chorem/pollen/bean/PollResultList.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/bean/PollResultList.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/bean/PollResultList.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -1,59 +0,0 @@ -/* - * #%L - * Pollen :: Services - * $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.bean; - -import org.chorem.pollen.votecounting.dto.VoteCountingResultDTO; - -import java.util.List; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class PollResultList { - - /** Liste des résultats */ - private List<PollResult> pollResults; - - /** Résultat issu du dépouillement du vote */ - private VoteCountingResultDTO voteCountingResult; - - public List<PollResult> getPollResults() { - return pollResults; - } - - public void setPollResults(List<PollResult> pollResults) { - this.pollResults = pollResults; - } - - public VoteCountingResultDTO getVoteCountingResult() { - return voteCountingResult; - } - - public void setVoteCountingResult(VoteCountingResultDTO voteCountingResult) { - this.voteCountingResult = voteCountingResult; - } - -} Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_3.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_3.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_3.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -26,8 +26,8 @@ import com.google.common.collect.Maps; import org.apache.commons.lang3.tuple.Pair; import org.chorem.pollen.PollenTechnicalException; -import org.chorem.pollen.common.ChoiceType; -import org.chorem.pollen.common.PollType; +import org.chorem.pollen.business.persistence.ChoiceType; +import org.chorem.pollen.business.persistence.PollType; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaContextImplementor; import org.nuiton.topia.framework.TopiaSQLQuery; Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -29,25 +29,19 @@ import org.chorem.pollen.bean.PollResult; import org.chorem.pollen.business.persistence.Choice; import org.chorem.pollen.business.persistence.ChoiceImpl; +import org.chorem.pollen.business.persistence.ChoiceType; import org.chorem.pollen.business.persistence.PersonToList; import org.chorem.pollen.business.persistence.PersonToListImpl; import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.PollAccount; import org.chorem.pollen.business.persistence.PollAccountImpl; import org.chorem.pollen.business.persistence.Result; -import org.chorem.pollen.business.persistence.Vote; -import org.chorem.pollen.business.persistence.VoteToChoice; import org.chorem.pollen.business.persistence.VotingList; import org.chorem.pollen.business.persistence.VotingListImpl; -import org.chorem.pollen.common.ChoiceType; -import org.chorem.pollen.votecounting.business.NumberMethod; -import org.chorem.pollen.votecounting.model.Voter; -import org.chorem.pollen.votecounting.model.VoterBuilder; import org.nuiton.topia.persistence.TopiaEntity; import java.util.Date; import java.util.List; -import java.util.Set; /** * Usefull functions for the service (and higher) layers. @@ -78,28 +72,28 @@ } } - public static final Function<Poll, Set<Voter>> POLL_TO_VOTERS = new Function<Poll, Set<Voter>>() { - @Override - public Set<Voter> apply(Poll input) { +// public static final Function<Poll, Set<Voter>> POLL_TO_VOTERS = new Function<Poll, Set<Voter>>() { +// @Override +// public Set<Voter> apply(Poll input) { +// +// VoterBuilder builder = new SimpleVoterBuilder(); +// for (Vote vote : input.getVote()) { +// +// String voterId = vote.getPollAccount().getAccountId(); +// double voteWeight = vote.getWeight(); +// builder.newVoter(voterId, voteWeight); +// +// for (VoteToChoice voteToChoice : vote.getChoiceVoteToChoice()) { +// String choiceId = voteToChoice.getChoice().getTopiaId(); +// Double voteValue = Double.valueOf(voteToChoice.getVoteValue()); +// builder.addVoteForChoice(choiceId, voteValue); +// } +// } +// Set<Voter> result = builder.getVoters(); +// return result; +// } +// }; - VoterBuilder builder = new VoterBuilder(); - for (Vote vote : input.getVote()) { - - String voterId = vote.getPollAccount().getAccountId(); - double voteWeight = vote.getWeight(); - builder.newVoter(voterId, voteWeight); - - for (VoteToChoice voteToChoice : vote.getChoiceVoteToChoice()) { - String choiceId = voteToChoice.getChoice().getTopiaId(); - Double voteValue = Double.valueOf(voteToChoice.getVoteValue()); - builder.addVoteForChoice(choiceId, voteValue); - } - } - Set<Voter> result = builder.getVoters(); - return result; - } - }; - public static final Function<Choice, String> CHOICE_TO_NAME = new Function<Choice, String>() { @Override public String apply(Choice input) { @@ -125,6 +119,7 @@ return result; } }; + public static TopiaIdExtractor newTopiaIdExtractor() { return new TopiaIdExtractor(); } @@ -289,8 +284,9 @@ dto.setPollId(poll.getPollId()); String resName = res.getName(); dto.setName(resName); - dto.setHidden(resName != null && - resName.startsWith(NumberMethod.HIDDEN_PREFIX)); +// dto.setHidden(resName != null && +// resName.startsWith(NumberMethod.HIDDEN_PREFIX)); + dto.setHidden(false); dto.setValue(res.getResultValue()); dto.setByGroup(res.isByGroup()); dto.setChoiceType(poll.getChoiceType()); Deleted: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServicePredicates.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServicePredicates.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServicePredicates.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -1,50 +0,0 @@ -/* - * #%L - * Pollen :: Services - * $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.services; - -import com.google.common.base.Predicate; -import org.apache.commons.lang3.StringUtils; -import org.chorem.pollen.business.persistence.PollAccount; - -/** - * Created: 16/04/12 - * - * @author fdesbois <desbois@codelutin.com> - */ -public final class PollenServicePredicates { - - private PollenServicePredicates() { - // never instanciate a class with static methods - } - - /** Check if the PollAccount is empty, i.e. has empty votingId or email. */ - public static final Predicate<PollAccount> POLL_ACCOUNT_NOT_EMPTY = new Predicate<PollAccount>() { - - @Override - public boolean apply(PollAccount input) { - String votingId = input.getVotingId(); - String email = input.getEmail(); - return StringUtils.isNotBlank(votingId) && StringUtils.isNotBlank(email); - } - }; -} Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -47,7 +47,6 @@ import java.io.File; import java.io.FileWriter; import java.io.Writer; -import java.util.Date; import java.util.List; import static org.nuiton.i18n.I18n._; Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -24,42 +24,28 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Lists; -import com.google.common.collect.Multimap; -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.PollenFunctions; import org.chorem.pollen.bean.PollResult; -import org.chorem.pollen.bean.PollResultList; import org.chorem.pollen.business.persistence.Choice; +import org.chorem.pollen.business.persistence.ChoiceType; import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.business.persistence.Polls; import org.chorem.pollen.business.persistence.Result; import org.chorem.pollen.business.persistence.ResultDAO; -import org.chorem.pollen.common.ChoiceType; -import org.chorem.pollen.common.PollType; import org.chorem.pollen.services.PollenServiceFunctions; import org.chorem.pollen.services.PollenServiceSupport; import org.chorem.pollen.services.exceptions.PollNotFoundException; -import org.chorem.pollen.votecounting.business.NumberMethod; -import org.chorem.pollen.votecounting.dto.ChoiceDTO; -import org.chorem.pollen.votecounting.dto.PollDTO; -import org.chorem.pollen.votecounting.dto.PollExportDTO; -import org.chorem.pollen.votecounting.dto.VoteCountingResultDTO; -import org.chorem.pollen.votecounting.services.ImportExportService; -import org.chorem.pollen.votecounting.services.VoteCountingService; +import org.chorem.pollen.votecounting.model.ChoiceScore; +import org.chorem.pollen.votecounting.model.VoteCountingResult; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; import java.util.Date; import java.util.Iterator; import java.util.List; -import java.util.Locale; -import static org.nuiton.i18n.I18n.l_; - /** * Deals with poll results. * @@ -72,66 +58,6 @@ private static final Log log = LogFactory.getLog(PollResultsService.class); /** - * Récurpération des résultats d'un sondage sous forme de - * {@link PollResultList}. - * <p/> - * Si les résultats ne sont pas à jour ({@link Poll#isResultUptodate()}, - * alors ils seront regénérés. - * - * @param poll le sondage à traiter - * @return les résultats du sondage. - */ - public PollResultList getResults(Poll poll) { - - Preconditions.checkNotNull(poll); - - - VoteCountingResultDTO result; - if (!poll.isResultUptodate()) { - - //must regenerate results - - result = generateResult(poll); - - commitTransaction("Could not generate poll result"); - } else { - - result = getResultDTO(poll); - - } - - boolean byGroup = poll.getPollType() == PollType.GROUP; - - int voteCountingType = poll.getVoteCountingType(); - - // Conversion des résultats - List<PollResult> list = Lists.transform( - poll.getResult(), - PollenServiceFunctions.newResultToBeanFunction(poll)); - - // Filtrage des résultats que l'on veut retourner - - Iterator<PollResult> it = list.iterator(); - while (it.hasNext()) { - PollResult currentResult = it.next(); - - // Cas d'un sondage de type GROUP avec filtre - if (byGroup) { - - // Filtre group : Suppression resultats non group - if (!currentResult.isByGroup()) { - it.remove(); - } - } - } - - PollResultList resultList = new PollResultList(); - resultList.setPollResults(list); - resultList.setVoteCountingResult(result); - return resultList; - } - - /** * Génère les résultats d'un sondage (= un dépouillement) et les stoque en * base. * <p/> @@ -142,76 +68,115 @@ * @param poll le sondage à dépouiller * @since 1.4 */ - public VoteCountingResultDTO generateResult(Poll poll) { - + public void generateResult(Poll poll) { Preconditions.checkNotNull(poll); if (log.isInfoEnabled()) { log.info("Will regenerate results for poll " + poll.getPollId()); } - VoteCountingResultDTO result = getResultDTO(poll); + PollVoteCountingService service = + newService(PollVoteCountingService.class); + + VoteCountingResult mainResult; + + if (Polls.isGroupPoll(poll)) { + mainResult = service.getGroupResult(poll).getMainResult(); + } else { + mainResult = service.getSimpleResult(poll); + } + + boolean groupPoll = Polls.isGroupPoll(poll); + int voteCountingType = poll.getVoteCountingType(); + // clear result poll.clearResult(); ResultDAO daoResult = getDAO(Result.class); - for (ChoiceDTO choice : result.getChoices()) { + for (ChoiceScore choice : mainResult.getScores()) { Result eResult = create(daoResult); - Choice eChoice = poll.getChoiceByTopiaId(choice.getIdChoice()); + Choice eChoice = poll.getChoiceByTopiaId(choice.getChoiceId()); eResult.setName(eChoice.getName()); - eResult.setByGroup(result.isByGroup()); -// eResult.setPoll(poll); - eResult.setResultValue(String.valueOf(choice.getValue())); - eResult.setVoteCountingType(poll.getVoteCountingType()); + eResult.setByGroup(groupPoll); + eResult.setResultValue(String.valueOf(choice.getScoreValue())); + eResult.setVoteCountingType(voteCountingType); poll.addResult(eResult); } - poll.setResultUptodate(true); - - return result; } - public String exportPolltoXml(String pollId) throws PollNotFoundException { + /** + * Récurpération des résultats d'un sondage sous forme de + * {@link PollResult}. + * <p/> + * Si les résultats ne sont pas à jour ({@link Poll#isResultUptodate()}, + * alors ils seront regénérés. + * + * @param poll le sondage à traiter + * @return les résultats du sondage. + */ + public List<PollResult> getResults(Poll poll) { - // Recherche du sondage + Preconditions.checkNotNull(poll); - PollService pollService = newService(PollService.class); + if (!poll.isResultUptodate()) { - Poll poll = pollService.getExistingPollByPollId(pollId); + //must regenerate results - PollDTO dto = PollenFunctions.POLL_TO_BEAN.apply(poll); + generateResult(poll); - VoteCountingService service = new VoteCountingService(); + commitTransaction("Could not generate poll result"); + } - List<VoteCountingResultDTO> results = Lists.newArrayList(); + // Conversion des résultats + List<PollResult> list = Lists.transform( + poll.getResult(), + PollenServiceFunctions.newResultToBeanFunction(poll)); + return list; + } - VoteCountingResultDTO result = service.executeVoteCounting(dto); + public String exportPolltoXml(String pollId) throws PollNotFoundException { - results.add(result); + // Recherche du sondage - if (poll.getPollType() == PollType.GROUP) { - VoteCountingResultDTO groupResult = - service.executeGroupCounting(dto); - results.add(groupResult); - } + PollService pollService = newService(PollService.class); - // Transformation du sondage - PollExportDTO pollExport = new PollExportDTO(); - pollExport.setPollId(pollId); - pollExport.setPoll(dto); - pollExport.setVoteCountingResults(results); + Poll poll = pollService.getExistingPollByPollId(pollId); - // Export du sondage - ImportExportService serviceExport = new ImportExportService(); - String content = serviceExport.exportToXml(pollExport); - - return content; + return "TODO in Pollen 2.0"; +// PollDTO dto = PollenFunctions.POLL_TO_BEAN.apply(poll); +// +// VoteCountingService service = new VoteCountingService(); +// +// List<VoteCountingResultDTO> results = Lists.newArrayList(); +// +// VoteCountingResultDTO result = service.executeVoteCounting(dto); +// +// results.add(result); +// +// if (poll.getPollType() == PollType.GROUP) { +// VoteCountingResultDTO groupResult = +// service.executeGroupCounting(dto); +// results.add(groupResult); +// } +// +// // Transformation du sondage +// PollExportDTO pollExport = new PollExportDTO(); +// pollExport.setPollId(pollId); +// pollExport.setPoll(dto); +// pollExport.setVoteCountingResults(results); +// +// // Export du sondage +// ImportExportService serviceExport = new ImportExportService(); +// String content = serviceExport.exportToXml(pollExport); +// +// return content; } public String getResultValue(Choice choice, @@ -227,125 +192,6 @@ return val; } - public List<PollResult> createNumberVoteCountingResult( - PollResultList resultListDTO, - Multimap<String, String> choicesResults, - Multimap<String, String> subtitles) { - Preconditions.checkNotNull(resultListDTO); - Preconditions.checkNotNull(choicesResults); - Preconditions.checkNotNull(subtitles); - - List<PollResult> results = resultListDTO.getPollResults(); - - /* - * liste des vrais choix (les choix pas cachés). - * cette variable sera affectée à la variable results - */ - List<PollResult> results2 = Lists.newArrayList(); - - // Ajout des résultats des choix cachés - for (PollResult result : results) { - if (result.isHidden()) { - String name = result.getName(); - int indexOf = name.indexOf('#'); - String choice = name.substring( - NumberMethod.HIDDEN_PREFIX.length(), indexOf); - - String votingId = name.substring(indexOf + 1); - String value = result.getValue(); - - choicesResults.put(choice, votingId); - choicesResults.put(choice, value); - - } else { - results2.add(result); - } - } - - Locale locale = getLocale(); - - // Récupération du choix correspondant au résultat - VoteCountingResultDTO voteCountingResult = resultListDTO - .getVoteCountingResult(); - - for (String choiceName : choicesResults.keySet()) { - Collection<String> values = choicesResults.get(choiceName); - - for (ChoiceDTO choice : voteCountingResult.getChoices()) { - if (choiceName.equals(choice.getName())) { - subtitles.put( - choiceName, - l_(locale, "pollen.common.numberVote-total")); - subtitles.put( - choiceName, - String.valueOf(choice.getValue())); - - subtitles.put( - choiceName, - l_(locale, "pollen.common.numberVote-average")); - subtitles.put( - choiceName, - String.valueOf(choice.getAverage())); - - subtitles.put( - choiceName, - l_(locale, "pollen.common.numberVote-blank-votes")); - subtitles.put( - choiceName, - String.valueOf(choice.getNbBlankVotes())); - - subtitles.put( - choiceName, - l_(locale, "pollen.common.numberVote-total-votes")); - subtitles.put( - choiceName, - String.valueOf(values.size() / 2)); - break; - } - } - } - - if (results2.size() == 1) { - results2.remove(0); - } - return results2; - } - - public List<PollResult> getTopRanking(List<PollResult> results) { - List<PollResult> ranking = Lists.newArrayList(results); - - Collections.sort(ranking, new Comparator<PollResult>() { - @Override - public int compare(PollResult o1, PollResult o2) { - Double result1 = Double.parseDouble(o1.getValue()); - Double result2 = Double.parseDouble(o2.getValue()); - int comp = 0; // résultat de la comparaison - - if (result1 > result2) { - comp = -1; - } else if (result1 < result2) { - comp = 1; - } - if (comp == 0) { - comp = o1.getName().compareTo(o2.getName()); - } - return comp; - } - }); - - List<PollResult> topRanking = Lists.newArrayList(); - - if (CollectionUtils.isNotEmpty(ranking)) { - String winValue = ranking.get(0).getValue(); - for (PollResult r : ranking) { - if (winValue.equals(r.getValue())) { - topRanking.add(r); - } - } - } - return topRanking; - } - /** * Supprime le 0 final d'un nombre à virgule. Le résultat peut-être un * double : 1,0 -> 1 et 1,2 -> 1,2. @@ -386,16 +232,4 @@ } return res.toString(); } - - protected VoteCountingResultDTO getResultDTO(Poll poll) { - - PollDTO dto = PollenFunctions.POLL_TO_BEAN.apply(poll); - - dto.setVoteCounting(poll.getVoteCountingType()); - - VoteCountingService service = new VoteCountingService(); - - VoteCountingResultDTO result = service.execute(dto); - return result; - } } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -39,6 +39,7 @@ import org.chorem.pollen.bean.PollImageChoice; import org.chorem.pollen.business.persistence.Choice; import org.chorem.pollen.business.persistence.ChoiceDAO; +import org.chorem.pollen.business.persistence.ChoiceType; import org.chorem.pollen.business.persistence.PersonToList; import org.chorem.pollen.business.persistence.PersonToListDAO; import org.chorem.pollen.business.persistence.Poll; @@ -50,7 +51,6 @@ import org.chorem.pollen.business.persistence.UserAccount; import org.chorem.pollen.business.persistence.VotingList; import org.chorem.pollen.business.persistence.VotingListDAO; -import org.chorem.pollen.common.ChoiceType; import org.chorem.pollen.entities.PollenBinderHelper; import org.chorem.pollen.services.PollenServiceFunctions; import org.chorem.pollen.services.PollenServiceSupport; Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollVoteCountingService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollVoteCountingService.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollVoteCountingService.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -23,22 +23,16 @@ package org.chorem.pollen.services.impl; import com.google.common.base.Preconditions; -import com.google.common.collect.Maps; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.business.persistence.Polls; import org.chorem.pollen.services.PollenServiceSupport; -import org.chorem.pollen.votecounting.model.ChoiceScore; import org.chorem.pollen.votecounting.model.GroupOfVoter; import org.chorem.pollen.votecounting.model.GroupVoteCountingResult; import org.chorem.pollen.votecounting.model.VoteCountingResult; -import org.chorem.pollen.votecounting.model.VoteForChoice; -import org.chorem.pollen.votecounting.model.Voter; import org.chorem.pollen.votecounting.strategy.VoteCountingStrategy; -import org.chorem.pollen.votecounting.strategy.VoteCountingStrategyProvider; -import java.util.Map; -import java.util.Set; - /** * New Poll vote counting service. * @@ -52,106 +46,39 @@ LogFactory.getLog(PollVoteCountingService.class); /** - * Provider of {@link VoteCountingStrategy}. - * <p/> - * <strong>Note:</strong> this provider should be injected via method - * {@link #setProvider(VoteCountingStrategyProvider)}. - */ - private VoteCountingStrategyProvider provider; - - public VoteCountingStrategyProvider getProvider() { - if (provider == null) { - provider = serviceContext.getVoteCountingStrategyProvider(); - } - return provider; - } - - public void setProvider(VoteCountingStrategyProvider provider) { - this.provider = provider; - } - - /** - * Execute a vote counting for a given strategy (by his id) and the - * given {@code voters}. + * Execute a vote counting for a given poll. * - * @param strategyId the id of the vote counting strategy to use - * @param voter the votes to vote count + * @param poll poll on wich vote count * @return vote counting result */ - public VoteCountingResult voteCount(int strategyId, Set<Voter> voter) { + public VoteCountingResult getSimpleResult(Poll poll) { - Preconditions.checkNotNull(getProvider()); - Preconditions.checkNotNull(voter); - - VoteCountingStrategy strategy = getProvider().getStrategy(strategyId); + Preconditions.checkNotNull(poll); + VoteCountingStrategy strategy = Polls.getVoteCountingStrategy( + serviceContext.getVoteCountingStrategyProvider(), poll); Preconditions.checkNotNull(strategy); - VoteCountingResult result = strategy.votecount(voter); - return result; + // create vote counting model + GroupOfVoter group = Polls.toSimpleGroupOfVoters(poll); + + // compute result by the strategy + GroupVoteCountingResult result = strategy.votecount(group); + return result.getMainResult(); } - /** - * Execute a vote counting for a given strategy (by his id) and the - * given {@code voters}. - * - * @param strategyId the id of the vote counting strategy to use - * @param voter the votes to vote count - * @return vote counting result - */ - public GroupVoteCountingResult voteCountByGroup(int strategyId, Set<Voter> voter) { + public GroupVoteCountingResult getGroupResult(Poll poll) { - Preconditions.checkNotNull(getProvider()); - Preconditions.checkNotNull(voter); - - VoteCountingStrategy strategy = getProvider().getStrategy(strategyId); + Preconditions.checkNotNull(poll); + VoteCountingStrategy strategy = Polls.getVoteCountingStrategy( + serviceContext.getVoteCountingStrategyProvider(), poll); Preconditions.checkNotNull(strategy); // Create a groupVoter including of the root voters - GroupOfVoter group = GroupOfVoter.newVoter(null, 1.0, null, voter); + GroupOfVoter group = Polls.toGroupOfVoters(poll); - - Map<GroupOfVoter, VoteCountingResult> groupResults = Maps.newHashMap(); - voteCount(strategy, group, groupResults); - - // get result for main group (and remove it from groups) - VoteCountingResult mainResult = groupResults.remove(group); - - GroupVoteCountingResult result = GroupVoteCountingResult.newResult( - mainResult, groupResults); + GroupVoteCountingResult result = strategy.votecount(group); return result; } - protected void voteCount(VoteCountingStrategy strategy, - GroupOfVoter group, - Map<GroupOfVoter, VoteCountingResult> results) { - // all childs of this group - Set<Voter> voters = group.getVoters(); - - // treat before all his group childs - for (Voter voter : voters) { - if (voter instanceof GroupOfVoter) { - - // treat group child before all - voteCount(strategy, (GroupOfVoter) voter, results); - } - } - - // once here, all childs has been treated, can votecount this group - VoteCountingResult voteCountingResult = strategy.votecount(voters); - - // store the result for this group - results.put(group, voteCountingResult); - - // result of the group is now the voteForChoice for it - - for (ChoiceScore choiceScore : voteCountingResult.getScores()) { - VoteForChoice voteForChoice = VoteForChoice.newVote( - choiceScore.getChoiceId(), - //FIXME-tchemit-2012-06-26 Which is the value to set as choice for each result? - choiceScore.getScoreValue().doubleValue()); - group.addVoteForChoice(voteForChoice); - } - - } } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -34,12 +34,12 @@ import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.PollAccount; import org.chorem.pollen.business.persistence.PollAccountDAO; +import org.chorem.pollen.business.persistence.PollType; import org.chorem.pollen.business.persistence.UserAccount; import org.chorem.pollen.business.persistence.Vote; import org.chorem.pollen.business.persistence.VoteDAO; import org.chorem.pollen.business.persistence.VoteToChoice; import org.chorem.pollen.business.persistence.VoteToChoiceDAO; -import org.chorem.pollen.common.PollType; import org.chorem.pollen.entities.PollenBinderHelper; import org.chorem.pollen.services.PollenServiceSupport; import org.chorem.pollen.services.exceptions.PollAccountNotFound; Modified: trunk/pollen-ui-struts2/pom.xml =================================================================== --- trunk/pollen-ui-struts2/pom.xml 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-ui-struts2/pom.xml 2012-09-23 13:01:38 UTC (rev 3698) @@ -17,42 +17,19 @@ <artifactId>pollen-ui-struts2</artifactId> <dependencies> + <dependency> <groupId>${project.groupId}</groupId> <artifactId>pollen-votecounting-api</artifactId> <version>${project.version}</version> </dependency> + <dependency> <groupId>${project.groupId}</groupId> - <artifactId>pollen-votecounting-strategy</artifactId> - <version>${project.version}</version> - <type>pom</type> - <scope>runtime</scope> - <exclusions> - <exclusion> - <groupId>${project.groupId}</groupId> - <artifactId>pollen-votecounting-strategy-borda</artifactId> - </exclusion> - <exclusion> - <groupId>${project.groupId}</groupId> - <artifactId>pollen-votecounting-strategy-coombs</artifactId> - </exclusion> - <exclusion> - <groupId>${project.groupId}</groupId> - <artifactId>pollen-votecounting-strategy-instant-runoff</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>pollen-votecounting</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> <artifactId>pollen-persistence</artifactId> <version>${project.version}</version> </dependency> + <dependency> <groupId>${project.groupId}</groupId> <artifactId>pollen-services</artifactId> @@ -60,8 +37,10 @@ </dependency> <dependency> - <groupId>org.nuiton</groupId> - <artifactId>nuiton-validator</artifactId> + <groupId>${project.groupId}</groupId> + <artifactId>pollen-votecounting-strategy</artifactId> + <version>${project.version}</version> + <type>pom</type> <scope>runtime</scope> </dependency> @@ -115,47 +94,46 @@ </dependency> <dependency> - <groupId>com.jgeppert.struts2.jquery</groupId> - <artifactId>struts2-jquery-plugin</artifactId> - <scope>runtime</scope> + <groupId>org.jfree</groupId> + <artifactId>jfreechart</artifactId> </dependency> <dependency> - <groupId>com.jgeppert.struts2.jquery</groupId> - <artifactId>struts2-jquery-grid-plugin</artifactId> - <scope>runtime</scope> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty-runner</artifactId> </dependency> <dependency> - <groupId>org.apache.struts</groupId> - <artifactId>struts2-json-plugin</artifactId> + <groupId>org.apache.shiro</groupId> + <artifactId>shiro-web</artifactId> </dependency> <dependency> - <groupId>org.apache.struts</groupId> - <artifactId>struts2-sitemesh-plugin</artifactId> - <scope>runtime</scope> + <groupId>org.jfree</groupId> + <artifactId>jcommon</artifactId> </dependency> <dependency> - <groupId>org.apache.struts</groupId> - <artifactId>struts2-jfreechart-plugin</artifactId> - <scope>runtime</scope> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> </dependency> <dependency> - <groupId>org.jfree</groupId> - <artifactId>jfreechart</artifactId> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> </dependency> <dependency> - <groupId>org.mortbay.jetty</groupId> - <artifactId>jetty-runner</artifactId> + <groupId>org.apache.shiro</groupId> + <artifactId>shiro-core</artifactId> </dependency> + <!-- Provided dependencies --> + <dependency> - <groupId>org.apache.shiro</groupId> - <artifactId>shiro-web</artifactId> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <scope>provided</scope> </dependency> <dependency> @@ -164,48 +142,57 @@ <scope>provided</scope> </dependency> + <!-- Runtime dependencies --> + <dependency> - <groupId>org.jfree</groupId> - <artifactId>jcommon</artifactId> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-validator</artifactId> + <scope>runtime</scope> </dependency> <dependency> - <groupId>commons-collections</groupId> - <artifactId>commons-collections</artifactId> + <groupId>com.jgeppert.struts2.jquery</groupId> + <artifactId>struts2-jquery-plugin</artifactId> + <scope>runtime</scope> </dependency> <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> + <groupId>com.jgeppert.struts2.jquery</groupId> + <artifactId>struts2-jquery-grid-plugin</artifactId> + <scope>runtime</scope> </dependency> <dependency> - <groupId>org.apache.shiro</groupId> - <artifactId>shiro-core</artifactId> + <groupId>org.apache.struts</groupId> + <artifactId>struts2-json-plugin</artifactId> </dependency> - <!-- Provided dependencies --> <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <scope>provided</scope> + <groupId>org.apache.struts</groupId> + <artifactId>struts2-sitemesh-plugin</artifactId> + <scope>runtime</scope> </dependency> - <!-- Runtime dependencies --> <dependency> + <groupId>org.apache.struts</groupId> + <artifactId>struts2-jfreechart-plugin</artifactId> + <scope>runtime</scope> + </dependency> + + <dependency> <groupId>postgresql</groupId> <artifactId>postgresql</artifactId> <scope>runtime</scope> </dependency> - <!-- base h2 --> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency> - <!-- test dependencies --> + <!-- Test dependencies --> + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -35,6 +35,7 @@ import org.chorem.pollen.PollenUserSecurityContext; import org.chorem.pollen.bean.PollUri; import org.chorem.pollen.business.persistence.Poll; +import org.chorem.pollen.business.persistence.Polls; import org.chorem.pollen.business.persistence.UserAccount; import org.chorem.pollen.services.DefaultPollenServiceContext; import org.chorem.pollen.services.PollenServiceContext; @@ -458,10 +459,8 @@ } protected VoteCountingStrategy getVoteCountingStrategy(Poll poll) { - int voteCountingType = poll.getVoteCountingType(); - VoteCountingStrategy result = - getVoteCountingStrategyProvider().getStrategy(voteCountingType); - return result; + return Polls.getVoteCountingStrategy(getVoteCountingStrategyProvider(), + poll); } /** Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -22,33 +22,32 @@ */ package org.chorem.pollen.ui.actions.poll; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.google.common.collect.Multimap; import com.opensymphony.xwork2.inject.Inject; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts2.views.util.UrlHelper; -import org.chorem.pollen.bean.PollResult; -import org.chorem.pollen.bean.PollResultList; import org.chorem.pollen.bean.PollUrl; +import org.chorem.pollen.business.persistence.Choice; +import org.chorem.pollen.business.persistence.ChoiceType; import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.PollAccount; -import org.chorem.pollen.common.ChoiceType; -import org.chorem.pollen.common.PollType; -import org.chorem.pollen.services.impl.PollResultsService; +import org.chorem.pollen.business.persistence.Polls; +import org.chorem.pollen.services.impl.PollVoteCountingService; import org.chorem.pollen.ui.PollenUIUtils; import org.chorem.pollen.ui.actions.PageSkin; import org.chorem.pollen.ui.actions.PollUriAware; import org.chorem.pollen.ui.actions.PollenActionSupport; import org.chorem.pollen.ui.actions.PollenUserSecurityAware; import org.chorem.pollen.ui.converters.DateConverter; +import org.chorem.pollen.votecounting.model.ChoiceScore; +import org.chorem.pollen.votecounting.model.GroupVoteCountingResult; +import org.chorem.pollen.votecounting.model.VoteCountingResult; import org.chorem.pollen.votecounting.strategy.VoteCountingStrategy; -import org.nuiton.util.StringUtil; +import org.nuiton.topia.persistence.TopiaId; import java.net.URL; import java.util.Date; @@ -70,20 +69,6 @@ private static final Log log = LogFactory.getLog(ResultForPoll.class); /** - * Is result by group ? - * - * @since 1.3 - */ - private Boolean byGroup; - - /** - * Is user is poll's creator ? - * - * @since 1.4 - */ - private boolean creatorUser; - - /** * Is feed exists for this poll ? * * @since 1.4 @@ -91,42 +76,18 @@ private boolean feedFileExisting; /** - * Résultats du sondage. - * <p/> - * La map est indexée par les noms de choix. - * - * @since 1.3 - */ - private transient Multimap<String, String> choicesResults; - - /** - * Résultats du sondage. - * - * @since 1.3 - */ - private transient Multimap<String, String> subtitles; - - /** * Loaded poll. * * @since 1.3 */ private Poll poll; - /** - * Poll results. - * - * @since 1.3 - */ - private List<PollResult> results; + private GroupVoteCountingResult groupResult; - /** - * Top ranking results. - * - * @since 1.3 - */ - private List<PollResult> topRanking; + private VoteCountingResult pollResult; + private Map<String, Choice> choicesById; + /** * Url helper (to build new url) * @@ -144,7 +105,7 @@ } public boolean isCreatorOrAdmin() { - return creatorUser || isUserAdmin(); + return getUserSecurityContext().isCreator() || isUserAdmin(); } public boolean isFeedFileExisting() { @@ -182,7 +143,7 @@ public String getVoteUrl() { PollUrl url = getPollUrlService().getPollVoteUrl(poll); url.getPollUri().setAccountId(getUserSecurityContext().getAccountId()); - if (poll.isPollFree()) { + if (isFreePoll()) { // can removed accountId only for free poll //FIXME Should found out in ohter case the accountId (if exists for the connected id) if no accountId is given @@ -191,10 +152,6 @@ return url.getUrl(); } - public List<PollResult> getResults() { - return results; - } - public String getPollCreatorName() { PollAccount creator = poll.getCreator(); String result = creator.getVotingId(); @@ -221,17 +178,17 @@ return result; } - public Date getResultAsDate(PollResult result) { - Date date = new Date(Long.valueOf(result.getName())); - return date; + public GroupVoteCountingResult getGroupResult() { + return groupResult; } - public Multimap<String, String> getChoicesResults() { - return choicesResults; + public VoteCountingResult getPollResult() { + return pollResult; } - public Multimap<String, String> getSubtitles() { - return subtitles; + public Date getResultAsDate(String choiceName) { + Date date = new Date(Long.valueOf(choiceName)); + return date; } public String getVoteSizeMessage() { @@ -242,15 +199,10 @@ public String getVictoryMessage() { - String victoryMessage; + Set<ChoiceScore> topRanking = pollResult.getTopRanking(); - VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll()); - boolean displayResultsByChoice = strategy.isDisplayResultsByChoice(); - //FIXME-tchemit-2012-06-24, why doing this ??? Should remove this... -// if (isNumberVoteCounting()) { - if (displayResultsByChoice) { - victoryMessage = null; - } else if (CollectionUtils.isEmpty(topRanking)) { + String victoryMessage; + if (CollectionUtils.isEmpty(topRanking)) { victoryMessage = ""; } else if (topRanking.size() == 1) { victoryMessage = _("pollen.common.victory"); @@ -260,93 +212,48 @@ return victoryMessage; } - /** - * @param result la résultat à utiliser. - * @return la valeur du résultat courant sans le .0 final - */ - public String getTrimValue(PollResult result) { - - String value = result.getValue(); - - // le résultat peut-être un double : 1,0 -> 1 et 1,2 -> 1,2 - if (value.endsWith(".0")) { - value = value.substring(0, value.indexOf('.')); - } - return value; - } - @Override public String execute() throws Exception { poll = getUserSecurityContext().getPoll(); + choicesById = Maps.uniqueIndex(poll.getChoice(), TopiaId.GET_TOPIA_ID); + feedFileExisting = getPollFeedService().isFeedExists(poll); - if (byGroup == null) { + PollVoteCountingService voteCountingService = + getService(PollVoteCountingService.class); - // default byGroup value - byGroup = isGroupPoll(); - } + if (isGroupPoll()) { - creatorUser = getUserSecurityContext().isCreator(); + // load group result + groupResult = voteCountingService.getGroupResult(poll); - if (poll.isRunning(serviceContext.getCurrentTime())) { - addFlashWarning(_("pollen.information.pollRunning")); - } + pollResult = groupResult.getMainResult(); + } else { - // load results - - PollResultsService service = getPollResultsService(); - - PollResultList resultListDTO = service.getResults(poll); - - results = resultListDTO.getPollResults(); - - if (log.isDebugEnabled()) { - for (PollResult res : results) { - log.debug(res - + ", (voteCounting=" + res.getVoteCountingType() - + ", byGroup=" + res.isByGroup() + ")"); - } + // load simple result + pollResult = voteCountingService.getSimpleResult(poll); } - VoteCountingStrategy strategy = getVoteCountingStrategy(poll); - if (strategy.isDisplayResultsByChoice()) { - - // resultats des choix cachés - choicesResults = LinkedHashMultimap.create(); - - // sous-titres des vrais choix (les choix pas cachés) - subtitles = ArrayListMultimap.create(); - - results = service.createNumberVoteCountingResult( - resultListDTO, - choicesResults, - subtitles); + if (poll.isRunning(serviceContext.getCurrentTime())) { + addFlashWarning(_("pollen.information.pollRunning")); } - - topRanking = service.getTopRanking(results); - - if (log.isDebugEnabled()) { - log.debug("topRanking = " + topRanking); + if (log.isInfoEnabled()) { + log.info("topRanking = " + pollResult.getTopRanking()); } - return SUCCESS; } - public List<PollResult> getTopRanking() { - return topRanking; - } - public boolean isFreePoll() { - return poll.isPollFree(); + return Polls.isFreePoll(poll); } public boolean isRestrictedPoll() { - return poll.getPollType() == PollType.RESTRICTED; + return Polls.isRestrictedPoll(poll); } public boolean isGroupPoll() { - return poll.getPollType() == PollType.GROUP; + return Polls.isGroupPoll(poll); } public boolean isTextType() { @@ -361,23 +268,30 @@ return poll.getChoiceType() == ChoiceType.IMAGE; } - public boolean isByGroup() { - return byGroup; + public String getNormalPollResultChartUrl(int width, int height) { + return getPollResultChartUrl(pollResult, width, height); } - public void setByGroup(boolean byGroup) { - this.byGroup = byGroup; + public String getGroupPollResultChartUrl(String groupId, int width, int height) { + VoteCountingResult result = groupResult.getGroupResult(groupId); + return getPollResultChartUrl(result, width, height); } - /** @return Récupération de la liste des résultats pour le diagramme. */ - public List<String> getChoices() { + public String getChoiceName(String id) { + String result = choicesById.get(id).getName(); + return result; + } + protected String getPollResultChartUrl(VoteCountingResult results, + int width, int height) { + List<String> choiceValues = Lists.newArrayList(); - for (PollResult result : results) { - String name = result.getName(); - String value = result.getValue(); + for (ChoiceScore result : results.getScores()) { + String name = getChoiceName(result.getChoiceId()); + String value = String.valueOf(result.getScoreValue()); + if (isDateType()) { // mise en forme de la date Date date = new Date(Long.parseLong(name)); @@ -387,10 +301,7 @@ choiceValues.add(name); choiceValues.add(value); } - return choiceValues; - } - public String getNormalPollResultChartUrl(int width, int height) { URL applicationUrl = getApplicationUrl(); StringBuilder url = new StringBuilder(applicationUrl.toString()); @@ -400,7 +311,7 @@ params.put("width", width); params.put("height", height); params.put("title", ""); - params.put("values", getChoices()); + params.put("values", choiceValues); urlHelper.buildParametersString(params, url, "&"); @@ -408,36 +319,4 @@ return chartUrl; } - public Set<String> getChoicesResultNames() { - return choicesResults.keySet(); - } - - public String getChoicesResultCharUrl(int width, - int height, - String choiceName) { - - URL applicationUrl = getApplicationUrl(); - StringBuilder url = new StringBuilder(applicationUrl.toString()); - - url.append("/io/generateChart"); - - Map<String, Object> params = Maps.newHashMap(); - params.put("width", width); - params.put("height", height); - params.put("title", ""); - params.put("values", choicesResults.get(choiceName)); - params.put("subtitles", subtitles.get(choiceName)); - - urlHelper.buildParametersString(params, url, "&"); - - String chartUrl = url.toString(); - return chartUrl; - - } - - public String getChoicesAsString() { - List<String> choices = getChoices(); - return StringUtil.join(choices, ",", true); - } - } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/AbstractPollForm.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/AbstractPollForm.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/AbstractPollForm.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -45,20 +45,20 @@ import org.chorem.pollen.bean.PollUri; import org.chorem.pollen.business.persistence.Choice; import org.chorem.pollen.business.persistence.ChoiceImpl; +import org.chorem.pollen.business.persistence.ChoiceType; import org.chorem.pollen.business.persistence.PersonToList; import org.chorem.pollen.business.persistence.PersonToListImpl; import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.PollAccount; import org.chorem.pollen.business.persistence.PollAccountImpl; import org.chorem.pollen.business.persistence.PollCommentVisibility; +import org.chorem.pollen.business.persistence.PollType; import org.chorem.pollen.business.persistence.PollVoteVisibility; import org.chorem.pollen.business.persistence.PreventRule; import org.chorem.pollen.business.persistence.UserAccount; import org.chorem.pollen.business.persistence.VotingList; import org.chorem.pollen.business.persistence.VotingListImpl; -import org.chorem.pollen.common.ChoiceType; -import org.chorem.pollen.common.I18nAble; -import org.chorem.pollen.common.PollType; +import org.chorem.pollen.business.persistence.I18nAble; import org.chorem.pollen.services.PollenServiceFunctions; import org.chorem.pollen.services.exceptions.PollNotFoundException; import org.chorem.pollen.services.impl.PollService; Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AbstractVoteAction.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AbstractVoteAction.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AbstractVoteAction.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -29,9 +29,9 @@ import org.apache.struts2.interceptor.ParameterAware; import org.chorem.pollen.PollenTechnicalException; import org.chorem.pollen.bean.PollResult; -import org.chorem.pollen.bean.PollResultList; import org.chorem.pollen.bean.PollUrl; import org.chorem.pollen.business.persistence.Choice; +import org.chorem.pollen.business.persistence.ChoiceType; import org.chorem.pollen.business.persistence.Comment; import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.PollAccount; @@ -40,8 +40,7 @@ import org.chorem.pollen.business.persistence.UserAccount; import org.chorem.pollen.business.persistence.Vote; import org.chorem.pollen.business.persistence.VoteToChoice; -import org.chorem.pollen.common.ChoiceType; -import org.chorem.pollen.common.PollType; +import org.chorem.pollen.business.persistence.PollType; import org.chorem.pollen.services.exceptions.PollAccountNotFound; import org.chorem.pollen.services.exceptions.PollNotFoundException; import org.chorem.pollen.ui.PollenUIUtils; @@ -449,11 +448,8 @@ if (isResultAllowed()) { // load poll results - PollResultList pollResultList = - getPollResultsService().getResults(poll); + results = getPollResultsService().getResults(poll); - results = pollResultList.getPollResults(); - if (log.isDebugEnabled()) { for (PollResult res : results) { log.debug(res.getName() + ": " + res.getValue() Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AddChoice.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AddChoice.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AddChoice.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -28,7 +28,7 @@ import org.chorem.pollen.bean.PollImageChoice; import org.chorem.pollen.business.persistence.Choice; import org.chorem.pollen.business.persistence.Poll; -import org.chorem.pollen.common.ChoiceType; +import org.chorem.pollen.business.persistence.ChoiceType; import org.chorem.pollen.services.PollenServiceFunctions; import org.chorem.pollen.services.exceptions.PollNotFoundException; import org.chorem.pollen.ui.actions.FileUploadAware; Modified: trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties =================================================================== --- trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-09-23 13:01:38 UTC (rev 3698) @@ -66,6 +66,7 @@ pollen.action.voteAction.help=Partager ce lien avec ceux que vous voulez voir voter pollen.banner.newVersion=Nouvelle version \! pollen.common.aboutPoll=A propos du sondage +pollen.common.aboutPollResult=Résultats du sondage pollen.common.addingChoices=Ajout des choix pollen.common.administrator=Admin pollen.common.beginChoiceDate=Date de début des choix Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/result.jsp =================================================================== --- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/result.jsp 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/result.jsp 2012-09-23 13:01:38 UTC (rev 3698) @@ -81,42 +81,41 @@ </h4> <%-- Victoire --%> -<s:if test="victoryMessage != ''"> - <h4><s:property value="victoryMessage"/> +<h4><s:property value="victoryMessage"/> + <br/> + <s:iterator value="pollResult.topRanking" var="result"> + <s:set name="choiceName" value="%{getChoiceName(#result.choiceId)}"/> + <s:if test="textType"> + <s:property value="%{#choiceName}"/> + </s:if> + <s:elseif test="dateType"> + <s:property value="%{getResultAsDate(#choiceName)}"/> + </s:elseif> + <s:elseif test="imageType"> + <s:url id="imageUrl" namespace="/io" action="getPollChoiceImage" + escapeAmp="false"> + <s:param name="choiceId" value="%{#choiceName}"/> + <s:param name="pollId" value="poll.pollId"/> + <s:param name="thumb" value="false"/> + </s:url> + <s:url id="imageUrlThumb" namespace="/io" action="getPollChoiceImage" + escapeAmp="false"> + <s:param name="choiceId" value="%{#choiceName}"/> + <s:param name="pollId" value="poll.pollId"/> + <s:param name="thumb" value="true"/> + </s:url> + <a href="<s:property value='imageUrl'/>" rel="lightbox"> + <img alt="<s:property value='%{#choiceName}'/>" + title="<s:property value='%{#choiceName}'/>" + src="<s:property value='imageUrlThumb'/>"> + </a> + + </s:elseif> <br/> - <s:iterator value="topRanking" var="result"> - <s:if test="textType"> - <s:property value="name"/> - </s:if> - <s:elseif test="dateType"> - <s:property value="%{getResultAsDate(#result)}"/> - </s:elseif> - <s:elseif test="imageType"> - <s:url id="imageUrl" namespace="/io" action="getPollChoiceImage" - escapeAmp="false"> - <s:param name="choiceId" value="name"/> - <s:param name="pollId" value="poll.pollId"/> - <s:param name="thumb" value="false"/> - </s:url> - <s:url id="imageUrlThumb" namespace="/io" action="getPollChoiceImage" - escapeAmp="false"> - <s:param name="choiceId" value="name"/> - <s:param name="pollId" value="poll.pollId"/> - <s:param name="thumb" value="true"/> - </s:url> - <a href="<s:property value='imageUrl'/>" rel="lightbox"> - <img alt="<s:property value='name'/>" - title="<s:property value='name'/>" - src="<s:property value='imageUrlThumb'/>"> - </a> + </s:iterator> +</h4> - </s:elseif> - <br/> - </s:iterator> - </h4> -</s:if> - -<!-- Diagramme --> +<%-- Diagramme --%> <div id="resultChart"> <div class="chartTypeDiv"> <sj:a id='displayChart1' href="#" onclick="return displayCharts(1);"> @@ -133,23 +132,23 @@ </sj:a> </div> - <div class="displayTypeDiv"> - <s:if test="groupPoll"> - <s:text name="pollen.common.results"/> - <s:if test="byGroup"> - <s:a href="%{getResultUrl(false)}"> - <s:text name="pollen.common.normal"/> - </s:a> - - <s:text name="pollen.common.group"/> - </s:if> - <s:else> - <s:text name="pollen.common.normal"/> - - <s:a href="%{getResultUrl(true)}"> - <s:text name="pollen.common.group"/> - </s:a> - </s:else> - </s:if> - </div> + <%--<div class="displayTypeDiv">--%> + <%--<s:if test="groupPoll">--%> + <%--<s:text name="pollen.common.results"/>--%> + <%--<s:if test="byGroup">--%> + <%--<s:a href="%{getResultUrl(false)}">--%> + <%--<s:text name="pollen.common.normal"/>--%> + <%--</s:a>--%> + <%--- <s:text name="pollen.common.group"/>--%> + <%--</s:if>--%> + <%--<s:else>--%> + <%--<s:text name="pollen.common.normal"/> ---%> + <%--<s:a href="%{getResultUrl(true)}">--%> + <%--<s:text name="pollen.common.group"/>--%> + <%--</s:a>--%> + <%--</s:else>--%> + <%--</s:if>--%> + <%--</div>--%> <sj:div id='chartContainer'> <img id='chart_normal'/> @@ -157,16 +156,16 @@ <%-- Diagramme par choix --%> <%--<s:if test="choicesResults != null">--%> - <%--<div id="resultChart">--%> - <%--<div>--%> - <%--<s:iterator value="choicesResultNames" var="choicesResultName"--%> - <%--status="status">--%> - <%--<img id='chart_<s:property value="#status.index"/>'--%> - <%--alt="<s:property/>" title="<s:property/>"--%> - <%--src="<s:property value='%{getChoicesResultCharUrl(400,300, #choicesResultName)}'/>">--%> - <%--</s:iterator>--%> - <%--</div>--%> - <%--</div>--%> + <%--<div id="resultChart">--%> + <%--<div>--%> + <%--<s:iterator value="choicesResultNames" var="choicesResultName"--%> + <%--status="status">--%> + <%--<img id='chart_<s:property value="#status.index"/>'--%> + <%--alt="<s:property/>" title="<s:property/>"--%> + <%--src="<s:property value='%{getChoicesResultCharUrl(400,300, #choicesResultName)}'/>">--%> + <%--</s:iterator>--%> + <%--</div>--%> + <%--</div>--%> <%--</s:if>--%> </div> <!-- Classement --> Deleted: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/ChoiceType.java =================================================================== --- trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/ChoiceType.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/ChoiceType.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -1,54 +0,0 @@ -/* - * #%L - * Pollen :: Vote Counting - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 CodeLutin - * %% - * 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.common; - -import static org.nuiton.i18n.I18n.n_; - -public enum ChoiceType implements I18nAble { - TEXT(n_("pollen.choiceType.text")), - DATE(n_("pollen.choiceType.date")), - IMAGE(n_("pollen.choiceType.image")); - - private final String i18nKey; - - ChoiceType(String i18nKey) { - this.i18nKey = i18nKey; - } - - @Override - public String getI18nKey() { - return i18nKey; - } - - public static ChoiceType valueOf(int ordinal) { - - ChoiceType result = null; - for (ChoiceType curr : ChoiceType.values()) { - if (curr.ordinal() == ordinal) { - result = curr; - break; - } - } - return result; - } -} Deleted: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/I18nAble.java =================================================================== --- trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/I18nAble.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/I18nAble.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -1,34 +0,0 @@ -/* - * #%L - * Pollen :: Vote Counting - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 CodeLutin - * %% - * 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.common; - -/** - * Contract to expose a i18n key. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public interface I18nAble { - - String getI18nKey(); -} Deleted: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/PollType.java =================================================================== --- trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/PollType.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/PollType.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -1,54 +0,0 @@ -/* - * #%L - * Pollen :: Vote Counting - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 CodeLutin - * %% - * 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.common; - -import static org.nuiton.i18n.I18n.n_; - -public enum PollType implements I18nAble { - - FREE(n_("pollen.pollType.free")), - RESTRICTED(n_("pollen.pollType.restricted")), - GROUP(n_("pollen.pollType.group")); - - private final String i18nKey; - - PollType(String i18nKey) { - this.i18nKey = i18nKey; - } - - @Override - public String getI18nKey() { - return i18nKey; - } - - public static PollType valueOf(int ordinal) { - PollType result = null; - for (PollType curr : PollType.values()) { - if (curr.ordinal() == ordinal) { - result = curr; - break; - } - } - return result; - } -} Modified: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/ChoiceScore.java =================================================================== --- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/ChoiceScore.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/ChoiceScore.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -22,6 +22,7 @@ */ package org.chorem.pollen.votecounting.model; +import java.io.Serializable; import java.math.BigDecimal; /** @@ -30,8 +31,10 @@ * @author tchemit <chemit@codelutin.com> * @since 1.4.5 */ -public class ChoiceScore implements ChoiceIdAble, Comparable<ChoiceScore> { +public class ChoiceScore implements ChoiceIdAble, Comparable<ChoiceScore>,Serializable { + private static final long serialVersionUID = 1L; + /** Id of the choice. */ private String choiceId; @@ -78,15 +81,5 @@ int i1 = scoreValue == null ? -1 : scoreValue.intValue(); int i2 = o.scoreValue == null ? -1 : o.scoreValue.intValue(); return i1 - i2; -// BigDecimal v1 = scoreValue; -// BigDecimal v2 = o.scoreValue; -// if (v1 == null) { -// v1 = new BigDecimal(-1); -// } -// if (v2 == null) { -// v2 = new BigDecimal(-1); -// } -// int i = v1.subtract(v2).intValue(); -// return i; } } Modified: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/GroupOfVoter.java =================================================================== --- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/GroupOfVoter.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/GroupOfVoter.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -24,6 +24,7 @@ import com.google.common.collect.Sets; +import java.util.Iterator; import java.util.Set; /** @@ -32,17 +33,12 @@ * @author tchemit <chemit@codelutin.com> * @since 1.4.5 */ -public class GroupOfVoter implements Voter { +public class GroupOfVoter implements Voter, Iterable<Voter> { - /** Id of the group of voters. */ - private String voterId; + private static final long serialVersionUID = 1L; - /** Weight of the group of voters. */ - private double weight; + private final SimpleVoter rootVoter = SimpleVoter.newVoter(null, 1.0, null); - /** All votes for this group of voters. */ - private Set<VoteForChoice> voteForChoices; - /** Set of voters for this group. */ private Set<Voter> voters; @@ -51,54 +47,37 @@ public static GroupOfVoter newVoter(String voterId, double weight, - Set<VoteForChoice> voteForChoices, Set<Voter> voters) { GroupOfVoter result = new GroupOfVoter(); result.setVoterId(voterId); result.setWeight(weight); - if (voters != null) { - for (VoteForChoice voteForChoice : voteForChoices) { - result.addVoteForChoice(voteForChoice); - } - } result.setVoters(voters); return result; } @Override public String getVoterId() { - return voterId; + return rootVoter.getVoterId(); } @Override public double getWeight() { - return weight; + return rootVoter.getWeight(); } @Override public Set<VoteForChoice> getVoteForChoices() { - if (voteForChoices == null) { - voteForChoices = Sets.newHashSet(); - } - return voteForChoices; + return rootVoter.getVoteForChoices(); } - public Set<Voter> getVoters() { - return voters; - } - - public VoteCountingResult getResult() { - return result; - } - @Override public void setVoterId(String voterId) { - this.voterId = voterId; + rootVoter.setVoterId(voterId); } @Override public void setWeight(double weight) { - this.weight = weight; + rootVoter.setWeight(weight); } @Override @@ -106,11 +85,38 @@ getVoteForChoices().add(voteForChoice); } + public Set<Voter> getVoters() { + if (voters == null) { + voters = Sets.newHashSet(); + } + return voters; + } + + public void addVoter(Voter voter) { + getVoters().add(voter); + } + + public VoteCountingResult getResult() { + return result; + } + public void setVoters(Set<Voter> voters) { this.voters = voters; } public void setResult(VoteCountingResult result) { this.result = result; + for (ChoiceScore choiceScore : result.getScores()) { + VoteForChoice voteForChoice = VoteForChoice.newVote( + choiceScore.getChoiceId(), + //FIXME-tchemit-2012-06-26 Which is the value to set as choice for each result? + choiceScore.getScoreValue().doubleValue()); + addVoteForChoice(voteForChoice); + } } + + @Override + public Iterator<Voter> iterator() { + return getVoters().iterator(); + } } Added: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/GroupOfVoterBuilder.java =================================================================== --- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/GroupOfVoterBuilder.java (rev 0) +++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/GroupOfVoterBuilder.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -0,0 +1,69 @@ +package org.chorem.pollen.votecounting.model; + +import com.google.common.base.Preconditions; +import com.google.common.collect.Sets; + +import java.util.Set; + +/** + * {@link GroupOfVoter} builder. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4.6 + */ +public class GroupOfVoterBuilder implements VoterBuilder { + + private Set<Voter> voters = Sets.newHashSet(); + + private GroupOfVoter groupOfVoter; + + private Voter voter; + + @Override + public Set<Voter> getVoters() { + flush(); + return voters; + } + + @Override + public GroupOfVoterBuilder newVoter(String voterId, double weight) { + Preconditions.checkState(groupOfVoter != null, "No groupOfVoter defined, use method newGroupVoter before"); + flushVoter(); + voter = SimpleVoter.newVoter(voterId, weight, null); + return this; + } + + @Override + public GroupOfVoterBuilder addVoteForChoice(String choiceId, Double voteValue) { + Preconditions.checkState(voter != null, "No voter defined, use method newVoter before this one"); + VoteForChoice voteForChoice = VoteForChoice.newVote(choiceId, voteValue); + voter.addVoteForChoice(voteForChoice); + return this; + } + + public GroupOfVoterBuilder newGroupVoter(String voterId, double weight) { + flush(); + groupOfVoter = GroupOfVoter.newVoter(voterId, weight, null); + return this; + } + + public void flushVoter() { + if (voter != null) { + groupOfVoter.addVoter(voter); + voter = null; + } + } + + @Override + public void flush() { + if (groupOfVoter != null) { + flushVoter(); + voters.add(groupOfVoter); + groupOfVoter = null; + } + } + + public GroupOfVoter getRoot() { + return (GroupOfVoter) getVoters().iterator().next(); + } +} Property changes on: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/GroupOfVoterBuilder.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/GroupVoteCountingResult.java =================================================================== --- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/GroupVoteCountingResult.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/GroupVoteCountingResult.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -22,7 +22,12 @@ */ package org.chorem.pollen.votecounting.model; +import com.google.common.base.Function; +import com.google.common.collect.Maps; + +import java.io.Serializable; import java.util.Map; +import java.util.Set; /** * TODO @@ -30,34 +35,43 @@ * @author tchemit <chemit@codelutin.com> * @since 1.4.5 */ -public class GroupVoteCountingResult { +public class GroupVoteCountingResult implements Serializable { - protected VoteCountingResult mainResult; + private static final long serialVersionUID = 1L; - protected Map<GroupOfVoter, VoteCountingResult> groupResults; + protected GroupOfVoter voter; - public static GroupVoteCountingResult newResult( - VoteCountingResult mainResult, - Map<GroupOfVoter, VoteCountingResult> groupResults) { + protected Map<String, GroupOfVoter> groups; + + public static GroupVoteCountingResult newResult(GroupOfVoter voter, + Set<GroupOfVoter> groups) { GroupVoteCountingResult result = new GroupVoteCountingResult(); - result.setMainResult(mainResult); - result.setGroupResults(groupResults); + result.setVoter(voter); + groups.remove(voter); + result.setGroups(groups); return result; } public VoteCountingResult getMainResult() { - return mainResult; + return voter.getResult(); } - public void setMainResult(VoteCountingResult mainResult) { - this.mainResult = mainResult; + public void setVoter(GroupOfVoter voter) { + this.voter = voter; } - public Map<GroupOfVoter, VoteCountingResult> getGroupResults() { - return groupResults; + public void setGroups(Set<GroupOfVoter> groups) { + this.groups = Maps.uniqueIndex(groups, new Function<GroupOfVoter, String>() { + @Override + public String apply(GroupOfVoter input) { + return input.getVoterId(); + } + }); } - public void setGroupResults(Map<GroupOfVoter, VoteCountingResult> groupResults) { - this.groupResults = groupResults; + public VoteCountingResult getGroupResult(String groupId) { + GroupOfVoter groupOfVoter = groups.get(groupId); + VoteCountingResult result = groupOfVoter.getResult(); + return result; } } Modified: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/SimpleVoter.java =================================================================== --- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/SimpleVoter.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/SimpleVoter.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -34,6 +34,8 @@ */ public class SimpleVoter implements Voter { + private static final long serialVersionUID = 1L; + /** Id of the voter. */ private String voterId; Added: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/SimpleVoterBuilder.java =================================================================== --- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/SimpleVoterBuilder.java (rev 0) +++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/SimpleVoterBuilder.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -0,0 +1,48 @@ +package org.chorem.pollen.votecounting.model; + +import com.google.common.base.Preconditions; +import com.google.common.collect.Sets; + +import java.util.Set; + +/** + * {@link SimpleVoter} builder. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4.6 + */ +public class SimpleVoterBuilder implements VoterBuilder { + + private Set<Voter> voters = Sets.newHashSet(); + + private Voter voter; + + @Override + public SimpleVoterBuilder newVoter(String voterId, double weight) { + flush(); + voter = SimpleVoter.newVoter(voterId, weight, null); + return this; + } + + @Override + public SimpleVoterBuilder addVoteForChoice(String choiceId, Double voteValue) { + Preconditions.checkState(voter != null,"No voter defined, use method newVoter before this one"); + VoteForChoice voteForChoice = VoteForChoice.newVote(choiceId, voteValue); + voter.addVoteForChoice(voteForChoice); + return this; + } + + @Override + public Set<Voter> getVoters() { + flush(); + return voters; + } + + @Override + public void flush() { + if (voter != null) { + voters.add(voter); + voter = null; + } + } +} Property changes on: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/SimpleVoterBuilder.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/VoteCountingResult.java =================================================================== --- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/VoteCountingResult.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/VoteCountingResult.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -22,7 +22,15 @@ */ package org.chorem.pollen.votecounting.model; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import org.apache.commons.collections.CollectionUtils; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Collections; import java.util.List; +import java.util.Set; /** * Contains results for a vote. @@ -30,11 +38,15 @@ * @author tchemit <chemit@codelutin.com> * @since 1.4.5 */ -public class VoteCountingResult { +public class VoteCountingResult implements Serializable { + private static final long serialVersionUID = 1L; + /** Results for each choice. */ private List<ChoiceScore> scores; + private Set<ChoiceScore> topRanking; + public static VoteCountingResult newResult(List<ChoiceScore> scores) { VoteCountingResult result = new VoteCountingResult(); result.setScores(scores); @@ -45,7 +57,37 @@ return scores; } + public ChoiceScore getScore(String choiceId) { + ChoiceScore result = null; + for (ChoiceScore score : scores) { + if (choiceId.equals(score.getChoiceId())) { + result = score; + break; + } + } + return result; + } + public void setScores(List<ChoiceScore> scores) { this.scores = scores; + List<ChoiceScore> ranking = Lists.newArrayList(getScores()); + + Collections.sort(ranking); + Collections.reverse(ranking); + + topRanking = Sets.newHashSet(); + + if (CollectionUtils.isNotEmpty(ranking)) { + BigDecimal winValue = ranking.get(0).getScoreValue(); + for (ChoiceScore r : ranking) { + if (winValue.equals(r.getScoreValue())) { + topRanking.add(r); + } + } + } } + + public Set<ChoiceScore> getTopRanking() { + return topRanking; + } } Modified: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/VoteForChoice.java =================================================================== --- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/VoteForChoice.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/VoteForChoice.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -22,14 +22,19 @@ */ package org.chorem.pollen.votecounting.model; +import java.io.Serializable; + /** * A vote for a choice. * * @author tchemit <chemit@codelutin.com> * @since 1.4.5 */ -public class VoteForChoice implements ChoiceIdAble { +public class VoteForChoice implements ChoiceIdAble, Serializable { + private static final long serialVersionUID = 1L; + + /** Id of the choice. */ private String choiceId; Modified: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/Voter.java =================================================================== --- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/Voter.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/Voter.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -22,6 +22,7 @@ */ package org.chorem.pollen.votecounting.model; +import java.io.Serializable; import java.util.Set; /** @@ -30,7 +31,7 @@ * @author tchemit <chemit@codelutin.com> * @since 1.4.5 */ -public interface Voter { +public interface Voter extends Serializable { /** * Gets the voter unique id. Modified: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/VoterBuilder.java =================================================================== --- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/VoterBuilder.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/VoterBuilder.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -22,9 +22,6 @@ */ package org.chorem.pollen.votecounting.model; -import com.google.common.base.Preconditions; -import com.google.common.collect.Sets; - import java.util.Set; /** @@ -33,34 +30,13 @@ * @author tchemit <chemit@codelutin.com> * @since 1.4.5 */ -public class VoterBuilder { +public interface VoterBuilder { - private Set<Voter> voters = Sets.newHashSet(); + public VoterBuilder newVoter(String voterId, double weight); - private Voter voter; + public VoterBuilder addVoteForChoice(String choiceId, Double voteValue); - public VoterBuilder newVoter(String voterId, double weight) { - flushVoter(); - voter = SimpleVoter.newVoter(voterId, weight, null); - return this; - } + public Set<Voter> getVoters(); - public VoterBuilder addVoteForChoice(String choiceId, Double voteValue) { - Preconditions.checkState(voter != null); - VoteForChoice voteForChoice = VoteForChoice.newVote(choiceId, voteValue); - voter.addVoteForChoice(voteForChoice); - return this; - } - - public Set<Voter> getVoters() { - flushVoter(); - return voters; - } - - protected void flushVoter() { - if (voter != null) { - voters.add(voter); - voter = null; - } - } + public void flush(); } Modified: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/strategy/AbstractVoteCountingStrategy.java =================================================================== --- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/strategy/AbstractVoteCountingStrategy.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/strategy/AbstractVoteCountingStrategy.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -28,6 +28,8 @@ import com.google.common.collect.Sets; import org.chorem.pollen.votecounting.model.ChoiceIdAble; import org.chorem.pollen.votecounting.model.ChoiceScore; +import org.chorem.pollen.votecounting.model.GroupOfVoter; +import org.chorem.pollen.votecounting.model.GroupVoteCountingResult; import org.chorem.pollen.votecounting.model.VoteCountingResult; import org.chorem.pollen.votecounting.model.VoteForChoice; import org.chorem.pollen.votecounting.model.Voter; @@ -56,6 +58,17 @@ public static final BigDecimal ZERO_D = BigDecimal.valueOf(0.); @Override + public final GroupVoteCountingResult votecount(GroupOfVoter group) { + + Set<GroupOfVoter> groups = Sets.newHashSet(); + voteCount(group, groups); + + GroupVoteCountingResult result = GroupVoteCountingResult.newResult( + group, groups); + return result; + } + + @Override public String getStrategyName(Locale locale) { String result = l_(locale, getI18nName()); return result; @@ -171,6 +184,29 @@ return result; } + protected void voteCount(GroupOfVoter group, Set<GroupOfVoter> groups) { + + groups.add(group); + + // all childs of this group + Set<Voter> voters = group.getVoters(); + + // treat before all his group childs + for (Voter voter : voters) { + if (voter instanceof GroupOfVoter) { + + // treat group child before all + voteCount((GroupOfVoter) voter, groups); + } + } + + // once here, all childs has been treated, can votecount this group + VoteCountingResult voteCountingResult = votecount(voters); + + // store the result for this group + group.setResult(voteCountingResult); + } + public static class VoteForChoiceComparator implements Comparator<VoteForChoice>, Serializable { private static final long serialVersionUID = 1L; Modified: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategy.java =================================================================== --- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategy.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategy.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -23,6 +23,8 @@ package org.chorem.pollen.votecounting.strategy; import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType; +import org.chorem.pollen.votecounting.model.GroupOfVoter; +import org.chorem.pollen.votecounting.model.GroupVoteCountingResult; import org.chorem.pollen.votecounting.model.VoteCountingResult; import org.chorem.pollen.votecounting.model.Voter; @@ -58,6 +60,8 @@ */ String getI18nHelp(); + GroupVoteCountingResult votecount(GroupOfVoter group); + /** * Vote count for the given {@code voter} and return the result of it. * Modified: trunk/pollen-votecounting-strategy-borda/src/test/java/org/chorem/pollen/votecounting/strategy/BordaStrategyTest.java =================================================================== --- trunk/pollen-votecounting-strategy-borda/src/test/java/org/chorem/pollen/votecounting/strategy/BordaStrategyTest.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-votecounting-strategy-borda/src/test/java/org/chorem/pollen/votecounting/strategy/BordaStrategyTest.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -26,9 +26,9 @@ import com.google.common.collect.Sets; import org.chorem.pollen.votecounting.model.ChoiceIdAble; import org.chorem.pollen.votecounting.model.ChoiceScore; +import org.chorem.pollen.votecounting.model.SimpleVoterBuilder; import org.chorem.pollen.votecounting.model.VoteCountingResult; import org.chorem.pollen.votecounting.model.Voter; -import org.chorem.pollen.votecounting.model.VoterBuilder; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; @@ -81,7 +81,7 @@ // D 17 15 26 42 207 (=17*4+15*3+26*2+42) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("Ville A", 42.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, 2.). @@ -125,7 +125,7 @@ // 2 (a=3 b=2 c=1) c(3) > b(2) > a(1) // 3 (a=1 b=null c=2) a(3) > c(2) > b(1) // Result a = 2*3+1=7, b =2*2+1=5, c = 1*3+1*2+1=6 - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, 2.). @@ -161,7 +161,7 @@ // 3 (a=null b=null c=2) c>a|b // Result (a=3*2+2=8 b=2*3=6 c=1+2*3=7) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, 2.). @@ -197,7 +197,7 @@ // 3 (a=null b=null c=1) c(3) > a|c(2) // Result (a=3+2*2=7 b=3+2*2=7 c=3+2*2=7) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, null). @@ -236,7 +236,7 @@ // 3 (x1) (a=null b=1 c=2) b(3) > c(2) > a(1) // Result (a=2*3+1*2+1*1=9 b=2*2+1*3+1*3=10 c=2*2+1*2+1*2=8) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 2.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, null). @@ -272,7 +272,7 @@ // 3 (x3) (a=null b=2 c=1) c(3) > b(2) > a(1) // Result (a=1*3*2+1*2+1*1*3=11 b=2*2+1*3+3*2=13 c=2*2+1*2+3*3=15) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 2.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, null). Modified: trunk/pollen-votecounting-strategy-condorcet/src/test/java/org/chorem/pollen/votecounting/strategy/CondorcetStrategyTest.java =================================================================== --- trunk/pollen-votecounting-strategy-condorcet/src/test/java/org/chorem/pollen/votecounting/strategy/CondorcetStrategyTest.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-votecounting-strategy-condorcet/src/test/java/org/chorem/pollen/votecounting/strategy/CondorcetStrategyTest.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -26,9 +26,9 @@ import com.google.common.collect.Sets; import org.chorem.pollen.votecounting.model.ChoiceIdAble; import org.chorem.pollen.votecounting.model.ChoiceScore; +import org.chorem.pollen.votecounting.model.SimpleVoterBuilder; import org.chorem.pollen.votecounting.model.VoteCountingResult; import org.chorem.pollen.votecounting.model.Voter; -import org.chorem.pollen.votecounting.model.VoterBuilder; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; @@ -76,7 +76,7 @@ // 3 (a=1 b=null c=2) // Result (a=6 b=1 c=2) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, 2.). @@ -112,7 +112,7 @@ // 3 (a=1 b=null c=2) // Result (a=4 b=2 c=3) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, 2.). @@ -148,7 +148,7 @@ // 3 (a=null b=null c=2) // Result (a=3 b=1 c=3) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, 2.). @@ -186,7 +186,7 @@ // 3 (a=null b=null c=1) // Result (a=2 b=2 c=2) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, null). @@ -225,7 +225,7 @@ // 3 (x1) (a=null b=1 c=2) // Result (a=2 b=2 c=1) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 2.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, null). @@ -263,7 +263,7 @@ // 3 (x3) (a=null b=2 c=1) // Result (a=2 b=4 c=3) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 2.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, null). Modified: trunk/pollen-votecounting-strategy-coombs/src/test/java/org/chorem/pollen/votecounting/strategy/CoombsStrategyTest.java =================================================================== --- trunk/pollen-votecounting-strategy-coombs/src/test/java/org/chorem/pollen/votecounting/strategy/CoombsStrategyTest.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-votecounting-strategy-coombs/src/test/java/org/chorem/pollen/votecounting/strategy/CoombsStrategyTest.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -26,9 +26,9 @@ import com.google.common.collect.Sets; import org.chorem.pollen.votecounting.model.ChoiceIdAble; import org.chorem.pollen.votecounting.model.ChoiceScore; +import org.chorem.pollen.votecounting.model.SimpleVoterBuilder; import org.chorem.pollen.votecounting.model.VoteCountingResult; import org.chorem.pollen.votecounting.model.Voter; -import org.chorem.pollen.votecounting.model.VoterBuilder; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; @@ -82,7 +82,7 @@ // C 15 43 42 0 15 15 // D 17 15 26 42 17 17 - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("Ville A", 42.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, 2.). @@ -126,7 +126,7 @@ // 2 (a=3 b=2 c=1) b 1 // 3 (a=1 b=null c=2) c - - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, 2.). @@ -161,7 +161,7 @@ // 2 (a=1 b=2 c=1) b - // 3 (a=null b=null c=2) c 2 - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, 2.). @@ -198,7 +198,7 @@ // 2 (a=null b=1 c=null) b 1 // 3 (a=null b=null c=1) c 1 - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, null). @@ -236,7 +236,7 @@ // 2 (x1) (a=null b=1 c=null) b 2 // 3 (x1) (a=null b=1 c=2) c - - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 2.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, null). @@ -273,7 +273,7 @@ // 2 (x1) (a=null b=1 c=null) b 1 // 3 (x3) (a=null b=2 c=1) c 3 - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 2.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, null). Modified: trunk/pollen-votecounting-strategy-instant-runoff/src/test/java/org/chorem/pollen/votecounting/strategy/InstantRunoffStrategyTest.java =================================================================== --- trunk/pollen-votecounting-strategy-instant-runoff/src/test/java/org/chorem/pollen/votecounting/strategy/InstantRunoffStrategyTest.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-votecounting-strategy-instant-runoff/src/test/java/org/chorem/pollen/votecounting/strategy/InstantRunoffStrategyTest.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -26,9 +26,9 @@ import com.google.common.collect.Sets; import org.chorem.pollen.votecounting.model.ChoiceIdAble; import org.chorem.pollen.votecounting.model.ChoiceScore; +import org.chorem.pollen.votecounting.model.SimpleVoterBuilder; import org.chorem.pollen.votecounting.model.VoteCountingResult; import org.chorem.pollen.votecounting.model.Voter; -import org.chorem.pollen.votecounting.model.VoterBuilder; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; @@ -82,7 +82,7 @@ // C 15 43 42 0 15 - - // D 17 15 26 42 17 32 58 - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("Ville A", 42.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, 2.). @@ -126,7 +126,7 @@ // 2 (a=3 b=2 c=1) b 1 // 3 (a=1 b=null c=2) c - - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, 2.). @@ -161,7 +161,7 @@ // 2 (a=1 b=2 c=1) b - // 3 (a=null b=null c=2) c 2 - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, 2.). @@ -198,7 +198,7 @@ // 2 (a=null b=1 c=null) b 1 // 3 (a=null b=null c=1) c 1 - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, null). @@ -236,7 +236,7 @@ // 2 (x1) (a=null b=1 c=null) b 2 // 3 (x1) (a=null b=1 c=2) c - - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 2.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, null). @@ -273,7 +273,7 @@ // 2 (x1) (a=null b=1 c=null) b 1 // 3 (x3) (a=null b=2 c=1) c 3 - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 2.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, null). Modified: trunk/pollen-votecounting-strategy-normal/src/test/java/org/chorem/pollen/votecounting/strategy/NormalStrategyTest.java =================================================================== --- trunk/pollen-votecounting-strategy-normal/src/test/java/org/chorem/pollen/votecounting/strategy/NormalStrategyTest.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-votecounting-strategy-normal/src/test/java/org/chorem/pollen/votecounting/strategy/NormalStrategyTest.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -26,12 +26,16 @@ import com.google.common.collect.Sets; import org.chorem.pollen.votecounting.model.ChoiceIdAble; import org.chorem.pollen.votecounting.model.ChoiceScore; +import org.chorem.pollen.votecounting.model.GroupOfVoter; +import org.chorem.pollen.votecounting.model.GroupOfVoterBuilder; +import org.chorem.pollen.votecounting.model.GroupVoteCountingResult; +import org.chorem.pollen.votecounting.model.SimpleVoterBuilder; import org.chorem.pollen.votecounting.model.VoteCountingResult; import org.chorem.pollen.votecounting.model.Voter; -import org.chorem.pollen.votecounting.model.VoterBuilder; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; import java.math.BigDecimal; @@ -76,7 +80,7 @@ // 3 (a=null b=1 c=1) // Result (a=1 b=2 c=1) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, null). @@ -106,7 +110,65 @@ CHOICE_A, CHOICE_C); } + //TODO Finish me + @Ignore @Test + public void groupVotecount() throws Exception { + + // Group poll (all weight to 1) + // 1 (a=1 b=null c=null) + // 2 (a=null b=1 c=null) + // 3 (a=null b=1 c=1) + // Result (a=1 b=2 c=1) + + GroupOfVoter voters = new GroupOfVoterBuilder(). + newGroupVoter("G1", 1.). + newVoter("G1U1", 1.). + addVoteForChoice(CHOICE_A, 1.). + addVoteForChoice(CHOICE_B, null). + addVoteForChoice(CHOICE_C, null). + newVoter("G1U2", 2.). + addVoteForChoice(CHOICE_A, null). + addVoteForChoice(CHOICE_B, 1.). + addVoteForChoice(CHOICE_C, null). + newVoter("G1U3", 3.). + addVoteForChoice(CHOICE_A, null). + addVoteForChoice(CHOICE_B, 1.). + addVoteForChoice(CHOICE_C, 1.). + newGroupVoter("G2", 1.). + newVoter("G2U1", 1.). + addVoteForChoice(CHOICE_A, null). + addVoteForChoice(CHOICE_B, 2.0). + addVoteForChoice(CHOICE_C, null). + newVoter("G2U2", 1.). + addVoteForChoice(CHOICE_A, 1.0). + addVoteForChoice(CHOICE_B, null). + addVoteForChoice(CHOICE_C, null). + newVoter("G2U3", 1.). + addVoteForChoice(CHOICE_A, null). + addVoteForChoice(CHOICE_B, 1.). + addVoteForChoice(CHOICE_C, 1.). + getRoot(); + + GroupVoteCountingResult result = strategy.votecount(voters); + + Assert.assertNotNull(result); + VoteCountingResult mainResult = result.getMainResult(); + Assert.assertNotNull(mainResult); + + List<ChoiceScore> scores = mainResult.getScores(); + Assert.assertNotNull(scores); + Assert.assertEquals(3, scores.size()); + + assertChoiceScore(scores.get(0), CHOICE_B, BigDecimal.valueOf(2.)); + + assertChoiceScoreEquals(BigDecimal.valueOf(1.), + Sets.newHashSet(scores.get(1), + scores.get(2)), + CHOICE_A, CHOICE_C); + } + + @Test public void simpleVotecount2() throws Exception { // Simple poll (all weight to 1) @@ -114,7 +176,7 @@ // 2 (a=1 b=1 c=null) // 3 (a=1 b=1 c=null) // Result (a=3 b=2 c=null) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, null). @@ -149,7 +211,7 @@ // 2 (a=1 b=1 c=null) // 3 (a=1 b=1 c=null) // Result (a=3 b=3 c=null) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, 1.). @@ -186,7 +248,7 @@ // 2 (x1) (a=null b=1 c=null) // 3 (x1) (a=null b=1 c=1) // Result (a=2 b=2 c=1) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 2.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, null). @@ -223,7 +285,7 @@ // 2 (x1) (a=null b=1 c=null) // 3 (x3) (a=null b=1 c=1) // Result (a=2 b=4 c=3) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 2.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, null). Modified: trunk/pollen-votecounting-strategy-number/src/test/java/org/chorem/pollen/votecounting/strategy/NumberStrategyTest.java =================================================================== --- trunk/pollen-votecounting-strategy-number/src/test/java/org/chorem/pollen/votecounting/strategy/NumberStrategyTest.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-votecounting-strategy-number/src/test/java/org/chorem/pollen/votecounting/strategy/NumberStrategyTest.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -26,9 +26,9 @@ import com.google.common.collect.Sets; import org.chorem.pollen.votecounting.model.ChoiceIdAble; import org.chorem.pollen.votecounting.model.ChoiceScore; +import org.chorem.pollen.votecounting.model.SimpleVoterBuilder; import org.chorem.pollen.votecounting.model.VoteCountingResult; import org.chorem.pollen.votecounting.model.Voter; -import org.chorem.pollen.votecounting.model.VoterBuilder; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; @@ -76,7 +76,7 @@ // 3 (a=7 b=12 c=20) // Result (a=10 b=14 c=23) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, 2.). @@ -111,7 +111,7 @@ // 2 (a=1 b=1 c=null) // 3 (a=1 b=1 c=null) // Result (a=3 b=2 c=null) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, null). @@ -146,7 +146,7 @@ // 2 (a=1 b=1 c=null) // 3 (a=1 b=1 c=null) // Result (a=3 b=3 c=null) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, 1.). @@ -183,7 +183,7 @@ // 2 (x1) (a=null b=1 c=null) // 3 (x1) (a=null b=1 c=1) // Result (a=2 b=2 c=1) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 2.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, null). @@ -220,7 +220,7 @@ // 2 (x1) (a=null b=1 c=null) // 3 (x3) (a=null b=1 c=1) // Result (a=2 b=4 c=3) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 2.). addVoteForChoice(CHOICE_A, 1.). addVoteForChoice(CHOICE_B, null). Modified: trunk/pollen-votecounting-strategy-percentage/src/test/java/org/chorem/pollen/votecounting/strategy/PercentageStrategyTest.java =================================================================== --- trunk/pollen-votecounting-strategy-percentage/src/test/java/org/chorem/pollen/votecounting/strategy/PercentageStrategyTest.java 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pollen-votecounting-strategy-percentage/src/test/java/org/chorem/pollen/votecounting/strategy/PercentageStrategyTest.java 2012-09-23 13:01:38 UTC (rev 3698) @@ -26,9 +26,9 @@ import com.google.common.collect.Sets; import org.chorem.pollen.votecounting.model.ChoiceIdAble; import org.chorem.pollen.votecounting.model.ChoiceScore; +import org.chorem.pollen.votecounting.model.SimpleVoterBuilder; import org.chorem.pollen.votecounting.model.VoteCountingResult; import org.chorem.pollen.votecounting.model.Voter; -import org.chorem.pollen.votecounting.model.VoterBuilder; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; @@ -76,7 +76,7 @@ // 3 (a=50 b=50 c=null) // Result (a=100 b=150 c=null) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 100.). addVoteForChoice(CHOICE_B, null). @@ -114,7 +114,7 @@ // 2 (a=50 b=20 c=30) // 3 (a=10 b=50 c=40) // Result (a=80 b=100 c=120) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 20.). addVoteForChoice(CHOICE_B, 30.). @@ -149,7 +149,7 @@ // 2 (a=50 b=50 c=null) // 3 (a=50 b=50 c=null) // Result (a=150 b=150 c=null) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 1.). addVoteForChoice(CHOICE_A, 50.). addVoteForChoice(CHOICE_B, 50.). @@ -186,7 +186,7 @@ // 2 (x1) (a=null b=100 c=null) // 3 (x1) (a=null b=50 c=50) // Result (a=200 b=150 c=50) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 2.). addVoteForChoice(CHOICE_A, 100.). addVoteForChoice(CHOICE_B, null). @@ -220,7 +220,7 @@ // 2 (x1) (a=null b=100 c=null) // 3 (x3) (a=null b=50 c=50) // Result (a=200 b=250 c=150) - Set<Voter> voters = new VoterBuilder(). + Set<Voter> voters = new SimpleVoterBuilder(). newVoter("1", 2.). addVoteForChoice(CHOICE_A, 100.). addVoteForChoice(CHOICE_B, null). Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-09-19 15:48:36 UTC (rev 3697) +++ trunk/pom.xml 2012-09-23 13:01:38 UTC (rev 3698) @@ -20,7 +20,6 @@ <modules> <module>pollen-votecounting-api</module> <module>pollen-votecounting-strategy</module> - <module>pollen-votecounting</module> <module>pollen-persistence</module> <module>pollen-services</module> <module>pollen-ui-struts2</module>
participants (1)
-
tchemit@users.chorem.org