Pollen-commits
Threads by month
- ----- 2026 -----
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
September 2012
- 3 participants
- 44 discussions
r3713 - in trunk/pollen-ui-struts2/src/main/webapp/WEB-INF: decorators jsp/poll jsp/user
by tchemit@users.chorem.org Sept. 30, 2012
by tchemit@users.chorem.org Sept. 30, 2012
Sept. 30, 2012
Author: tchemit
Date: 2012-09-30 18:09:37 +0200 (Sun, 30 Sep 2012)
New Revision: 3713
Url: http://chorem.org/repositories/revision/pollen/3713
Log:
fixes #817: Protect some forms
Modified:
trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators/layout-default.jsp
trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/pollForm.jsp
trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/register.jsp
Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators/layout-default.jsp
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators/layout-default.jsp 2012-09-30 12:57:25 UTC (rev 3712)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/decorators/layout-default.jsp 2012-09-30 16:09:37 UTC (rev 3713)
@@ -42,17 +42,15 @@
<sj:head locale="%{locale}" jqueryui="true" jquerytheme="%{jqueryTheme}"/>
</head>
-<%-- TODO AThimel 24/01/2012 Remove this when refactoring is over --%>
-<div id="in-progress">
+<%--div id="in-progress">
<a href="http://chorem.org/projects/pollen">
<s:text name="pollen.banner.newVersion"/>
</a>
-</div>
+</div--%>
-
<script type="text/javascript">
- jQuery(document).ready(function () {
+ $(document).ready(function () {
// apply common style
$('fieldset').addClass('ui-widget-content ui-corner-all');
@@ -68,6 +66,26 @@
dialog.dialog('open');
return false;
});
+
+ $(document).one('mousemove', function() {
+ function KMe(node, attrName, pattern) {
+ var attr = node.attr(attrName).replace( pattern + '\/', '');
+ //console.info("Unlock " + pattern + " " + node.attr('id') +
+ // " - " + attrName + " = " + attr);
+ node.attr(attrName, attr);
+ node.removeClass(pattern);
+ }
+ $('form.KForm').each(function () {
+ KMe($(this),'action','KForm');
+ });
+ $('input[type="submit"].KAction').each(function () {
+ var $this = $(this);
+ KMe($(this),'name','KAction');
+ });
+ $('a.KLink').each(function () {
+ KMe($(this),'href','KLink');
+ });
+ });
});
</script>
<s:set var="user" value="%{#session.pollenSession.userAccount}"/>
@@ -139,7 +157,8 @@
<sj:dialog id="lostPasswordDialog" autoOpen="false" modal="true" width="500"/>
- <s:form id="connection" method="POST" namespace="/user" action="login">
+ <s:form id="connection" method="POST" namespace="/user"
+ action="KForm/login" cssClass="KForm">
<s:hidden name="redirectUrl" value="%{currentUrl}"/>
<ul class="top_middle<s:property value='%{pageLogo}'/>">
<li>
@@ -163,14 +182,15 @@
</a>
</li>
<li>
- <s:submit id="submitform" action="login" key="pollen.action.login"
- align="right"/>
+ <s:submit id="submitform" action="KAction/login" align="right"
+ key="pollen.action.login" cssClass="KAction"/>
</li>
</ul>
</s:form>
</div>
<s:text name="pollen.common.or"/>
- <s:a action="register" method="input" namespace="/user">
+ <s:a action="KLink/register" method="input" namespace="/user"
+ cssClass="KLink" id='registerLink'>
<s:text name="pollen.menu.register"/>
</s:a>
</s:else>
@@ -193,7 +213,8 @@
<div class="top_left<s:property value='%{pageLogo}'/>"></div>
<ul class="top_middle<s:property value='%{pageLogo}'/>">
<li>
- <s:a action="create" namespace="/poll">
+ <s:a id='createPollLink' action="KLink/create" namespace="/poll"
+ cssClass="KLink">
<s:text name="pollen.menu.createPoll"/>
</s:a>
</li>
Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/pollForm.jsp
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/pollForm.jsp 2012-09-30 12:57:25 UTC (rev 3712)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/pollForm.jsp 2012-09-30 16:09:37 UTC (rev 3713)
@@ -85,7 +85,7 @@
</h1>
<s:form method="POST" id="registerForm" namespace="/poll"
- enctype="multipart/form-data">
+ enctype="multipart/form-data" cssClass="KForm" action="KForm/create">
<s:hidden key="poll.topiaId" label=""/>
@@ -214,12 +214,6 @@
label='%{getText("pollen.common.pollOption.pollVoteVisibility")}'
tooltip="%{getText('pollen.common.pollOption.pollVoteVisibility.help')}"
tooltipIconPath="/img/tooltip.png"/>
-
- <%--s:checkbox key="poll.anonymous"
- label="%{getText('pollen.common.pollOption.anonymous')}"
- disabled="%{voteStarted}"
- tooltip="%{getText('pollen.common.pollOption.anonymous.help')}"
- tooltipIconPath="/img/tooltip.png"/--%>
<s:checkbox key="poll.anonymousVoteAllowed"
label="%{getText('pollen.common.pollOption.anonymousVoteAllowed')}"
disabled="%{voteStarted}"
@@ -324,7 +318,8 @@
<s:submit action="clone/%{pollUri}" value="%{actionLabel}" align="center"/>
</s:elseif>
<s:else>
- <s:submit action="create" value="%{actionLabel}" align="center"/>
+ <s:submit action="KAction/create" value="%{actionLabel}" align="center"
+ cssClass="KAction"/>
</s:else>
</s:form>
Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/register.jsp
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/register.jsp 2012-09-30 12:57:25 UTC (rev 3712)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/register.jsp 2012-09-30 16:09:37 UTC (rev 3713)
@@ -29,7 +29,8 @@
<s:text name="pollen.title.register"/>
</h1>
-<s:form method="POST">
+<s:form method="POST" namespace="/user" action="KForm/register"
+ cssClass="KForm" id="registerForm">
<fieldset>
<legend><s:text name="pollen.fieldset.connexionInformation"/></legend>
@@ -52,5 +53,6 @@
key="pollen.common.lastName"/>
</fieldset>
<br/>
- <s:submit action="register" key="pollen.action.register" align="center"/>
+ <s:submit action="KAction/register" key="pollen.action.register"
+ align="center" cssClass="KAction"/>
</s:form>
1
0
Sept. 30, 2012
Author: tchemit
Date: 2012-09-30 14:57:25 +0200 (Sun, 30 Sep 2012)
New Revision: 3712
Url: http://chorem.org/repositories/revision/pollen/3712
Log:
fixes #816: Remove hidden choice mecanism
fixes #815: Do not persist any longer results
fix logging dependencies (doomed by slf4j :()
remove PollResultService
Added:
trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollExportService.java
Removed:
trunk/pollen-services/src/main/java/org/chorem/pollen/bean/PollResult.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java
Modified:
trunk/pollen-persistence/pom.xml
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/Polls.java
trunk/pollen-persistence/src/main/xmi/pollen.zargo
trunk/pollen-services/pom.xml
trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4.java
trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_5.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/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/admin/ExportPoll.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AbstractVoteAction.java
trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/VoteCountingResult.java
trunk/pom.xml
Modified: trunk/pollen-persistence/pom.xml
===================================================================
--- trunk/pollen-persistence/pom.xml 2012-09-29 21:19:04 UTC (rev 3711)
+++ trunk/pollen-persistence/pom.xml 2012-09-30 12:57:25 UTC (rev 3712)
@@ -75,6 +75,12 @@
</dependency>
<dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-jcl</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<scope>test</scope>
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-29 21:19:04 UTC (rev 3711)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java 2012-09-30 12:57:25 UTC (rev 3712)
@@ -38,6 +38,16 @@
}
@Override
+ public boolean isPollGroup() {
+ return PollType.GROUP == getPollType();
+ }
+
+ @Override
+ public boolean isPollRestricted() {
+ return PollType.RESTRICTED == getPollType();
+ }
+
+ @Override
public boolean isAnonymous() {
return PollVoteVisibility.NOBODY == getPollVoteVisibility();
}
@@ -59,14 +69,6 @@
}
@Override
- public List<Result> getResult() {
- if (result == null) {
- result = Lists.newArrayList();
- }
- return result;
- }
-
- @Override
public List<Comment> getComment() {
if (comment == null) {
comment = Lists.newArrayList();
Modified: 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 2012-09-29 21:19:04 UTC (rev 3711)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/Polls.java 2012-09-30 12:57:25 UTC (rev 3712)
@@ -94,7 +94,8 @@
public static GroupOfVoter toGroupOfVoters(Poll poll) {
Preconditions.checkNotNull(poll);
Preconditions.checkArgument(
- isGroupPoll(poll), "Can only use this method for a group poll");
+ poll.isPollGroup(),
+ "Can only use this method for a group poll");
GroupOfVoterBuilder builder = new GroupOfVoterBuilder();
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-29 21:19:04 UTC (rev 3711)
+++ trunk/pollen-services/pom.xml 2012-09-30 12:57:25 UTC (rev 3712)
@@ -105,6 +105,12 @@
</dependency>
<dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-jcl</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<scope>test</scope>
Deleted: 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-29 21:19:04 UTC (rev 3711)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/bean/PollResult.java 2012-09-30 12:57:25 UTC (rev 3712)
@@ -1,126 +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.apache.commons.lang3.builder.ToStringBuilder;
-import org.chorem.pollen.business.persistence.ChoiceType;
-
-import java.io.Serializable;
-
-/**
- * Classe DTO représentant un résultat de sondage.
- *
- * @since 1.3
- */
-public class PollResult implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private String id;
-
- private String name;
-
- private String value;
-
- private String pollId;
-
- private ChoiceType choiceType;
-
- private int voteCountingType;
-
- private boolean byGroup;
-
- private boolean hidden;
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- public String getPollId() {
- return pollId;
- }
-
- public void setPollId(String pollId) {
- this.pollId = pollId;
- }
-
- public ChoiceType getChoiceType() {
- return choiceType;
- }
-
- public void setChoiceType(ChoiceType choiceType) {
- this.choiceType = choiceType;
- }
-
- public int getVoteCountingType() {
- return voteCountingType;
- }
-
- public void setVoteCountingType(int voteCountingType) {
- this.voteCountingType = voteCountingType;
- }
-
- public boolean isByGroup() {
- return byGroup;
- }
-
- public void setByGroup(boolean byGroup) {
- this.byGroup = byGroup;
- }
-
- public boolean isHidden() {
- return hidden;
- }
-
- public void setHidden(boolean hidden) {
- this.hidden = hidden;
- }
-
- @Override
- public String toString() {
- return new ToStringBuilder(this).
- append("name", name).
- append("value", value).
- toString();
- }
-}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4.java 2012-09-29 21:19:04 UTC (rev 3711)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4.java 2012-09-30 12:57:25 UTC (rev 3712)
@@ -241,8 +241,7 @@
}
private void addResultUptodateToPoll(List<String> queries) {
- queries.add("ALTER TABLE poll ADD COLUMN " +
- Poll.PROPERTY_RESULT_UPTODATE + " boolean default false;");
+ queries.add("ALTER TABLE poll ADD COLUMN resultuptodate boolean default false;");
}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_5.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_5.java 2012-09-29 21:19:04 UTC (rev 3711)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_5.java 2012-09-30 12:57:25 UTC (rev 3712)
@@ -98,8 +98,27 @@
// generate missing accountId
// see http://chorem.org/issues/814
generateMissingAccountId(tx, sContext, queries);
+
+ // remove result from persistance
+ // see http://chorem.org/issues/815
+ removeResults(tx, queries);
+
+ // remove hidden choices
+ // see http://chorem.org/issues/816
+ removeHiddenChoices(tx, queries);
}
+ private void removeResults(TopiaContextImplementor tx, List<String> queries) {
+ queries.add("DROP TABLE result;");
+ queries.add("ALTER TABLE poll DROP COLUMN resultUptodate");
+ }
+
+ private void removeHiddenChoices(TopiaContextImplementor tx, List<String> queries) {
+
+ queries.add("DELETE FROM votetochoice WHERE choice in (SELECT topiaid FROM choice WHERE name LIKE 'HIDDEN_%');");
+ queries.add("DELETE FROM choice WHERE name LIKE 'HIDDEN_%';");
+ }
+
private void removeDuplicateVoteWithSameUserAccount(TopiaContextImplementor tx,
PollenServiceContext sContext,
List<String> queries) throws TopiaException {
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-29 21:19:04 UTC (rev 3711)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java 2012-09-30 12:57:25 UTC (rev 3712)
@@ -26,19 +26,15 @@
import com.google.common.collect.Lists;
import org.chorem.pollen.bean.PollDateChoice;
import org.chorem.pollen.bean.PollImageChoice;
-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.VotingList;
import org.chorem.pollen.business.persistence.VotingListImpl;
-import org.nuiton.topia.persistence.TopiaEntity;
import java.util.Date;
import java.util.List;
@@ -72,28 +68,6 @@
}
}
-// 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;
-// }
-// };
-
public static final Function<Choice, String> CHOICE_TO_NAME = new Function<Choice, String>() {
@Override
public String apply(Choice input) {
@@ -120,10 +94,6 @@
}
};
- public static TopiaIdExtractor newTopiaIdExtractor() {
- return new TopiaIdExtractor();
- }
-
public static TextChoiceCreator newTextChoiceCreator() {
return new TextChoiceCreator();
}
@@ -164,14 +134,6 @@
return new PersonToListCreator();
}
- public static class TopiaIdExtractor implements Function<TopiaEntity, String> {
-
- @Override
- public String apply(TopiaEntity input) {
- return input.getTopiaId();
- }
- }
-
public static class TextChoiceCreator implements Function<Choice, Choice> {
@Override
@@ -274,26 +236,4 @@
}
}
- public static Function<Result, PollResult> newResultToBeanFunction(final Poll poll) {
- return new Function<Result, PollResult>() {
-
- @Override
- public PollResult apply(Result res) {
- PollResult dto = new PollResult();
- dto.setId(res.getTopiaId());
- dto.setPollId(poll.getPollId());
- String resName = res.getName();
- dto.setName(resName);
-// dto.setHidden(resName != null &&
-// resName.startsWith(NumberMethod.HIDDEN_PREFIX));
- dto.setHidden(false);
- dto.setValue(res.getResultValue());
- dto.setByGroup(res.isByGroup());
- dto.setChoiceType(poll.getChoiceType());
- dto.setVoteCountingType(poll.getVoteCountingType());
- return dto;
- }
- };
- }
-
}
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollExportService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollExportService.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollExportService.java 2012-09-30 12:57:25 UTC (rev 3712)
@@ -0,0 +1,49 @@
+package org.chorem.pollen.services.impl;
+
+/*
+ * #%L
+ * Pollen :: Services
+ * $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%
+ */
+
+import org.chorem.pollen.business.persistence.Poll;
+import org.chorem.pollen.services.PollenServiceSupport;
+import org.chorem.pollen.services.exceptions.PollNotFoundException;
+
+/**
+ * Service to export poll as xml format (or later other formats).
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.5
+ */
+public class PollExportService extends PollenServiceSupport {
+
+ //FIXME must be done soon
+ public String exportToXml(String pollId) throws PollNotFoundException {
+
+ // Recherche du sondage
+
+ PollService pollService = newService(PollService.class);
+
+ Poll poll = pollService.getExistingPollByPollId(pollId);
+
+ return "<strong>TODO in Pollen 2.0</strong>";
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollExportService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
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-29 21:19:04 UTC (rev 3711)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java 2012-09-30 12:57:25 UTC (rev 3712)
@@ -145,10 +145,10 @@
public void onVoteAdded(Poll poll, Vote vote) {
- PollResultsService pollResultsService =
- newService(PollResultsService.class);
+ PollVoteCountingService service =
+ newService(PollVoteCountingService.class);
- String pollResult = pollResultsService.getResultsAsString(poll);
+ String pollResult = service.getResultsAsString(poll);
String userId;
@@ -168,10 +168,10 @@
public void onVoteUpdated(Poll poll, Vote vote) {
- PollResultsService pollResultsService =
- newService(PollResultsService.class);
+ PollVoteCountingService service =
+ newService(PollVoteCountingService.class);
- String pollResult = pollResultsService.getResultsAsString(poll);
+ String pollResult = service.getResultsAsString(poll);
String userId;
@@ -192,10 +192,10 @@
public void onVoteDeleted(Poll poll, Vote vote,
PollAccount voteAccount, String reason) {
- PollResultsService pollResultsService =
- newService(PollResultsService.class);
+ PollVoteCountingService service =
+ newService(PollVoteCountingService.class);
- String pollResult = pollResultsService.getResultsAsString(poll);
+ String pollResult = service.getResultsAsString(poll);
String userId;
if (vote.isAnonymous()) {
Deleted: 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-29 21:19:04 UTC (rev 3711)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java 2012-09-30 12:57:25 UTC (rev 3712)
@@ -1,235 +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.impl;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.bean.PollResult;
-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.services.PollenServiceFunctions;
-import org.chorem.pollen.services.PollenServiceSupport;
-import org.chorem.pollen.services.exceptions.PollNotFoundException;
-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.Date;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Deals with poll results.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.3
- */
-public class PollResultsService extends PollenServiceSupport {
-
- /** log. */
- private static final Log log = LogFactory.getLog(PollResultsService.class);
-
- /**
- * Génère les résultats d'un sondage (= un dépouillement) et les stoque en
- * base.
- * <p/>
- * <strong>Note importante :</strong> Le commite n'est pas effectuée dans
- * cette méthode car d'autres services vont appeller cette méthode au sein
- * d'une transaction et on ne veut pas faire deux commits.
- *
- * @param poll le sondage à dépouiller
- * @since 1.4
- */
- public void generateResult(Poll poll) {
- Preconditions.checkNotNull(poll);
-
- if (log.isInfoEnabled()) {
- log.info("Will regenerate results for poll " + poll.getPollId());
- }
-
-
- 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 (ChoiceScore choice : mainResult.getScores()) {
-
- Result eResult = create(daoResult);
-
- Choice eChoice = poll.getChoiceByTopiaId(choice.getChoiceId());
-
- eResult.setName(eChoice.getName());
- eResult.setByGroup(groupPoll);
- eResult.setResultValue(String.valueOf(choice.getScoreValue()));
- eResult.setVoteCountingType(voteCountingType);
-
- poll.addResult(eResult);
- }
- poll.setResultUptodate(true);
- }
-
- /**
- * 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) {
-
- Preconditions.checkNotNull(poll);
-
- if (!poll.isResultUptodate()) {
-
- //must regenerate results
-
- generateResult(poll);
-
- commitTransaction("Could not generate poll result");
- }
-
- // Conversion des résultats
- List<PollResult> list = Lists.transform(
- poll.getResult(),
- PollenServiceFunctions.newResultToBeanFunction(poll));
- return list;
- }
-
- public String exportPolltoXml(String pollId) throws PollNotFoundException {
-
- // Recherche du sondage
-
- PollService pollService = newService(PollService.class);
-
- Poll poll = pollService.getExistingPollByPollId(pollId);
-
- 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,
- Collection<PollResult> results) {
-
- String val = "";
- for (PollResult result : results) {
- if (result.getName().equals(choice.getName())) {
- val = removeTrailing0(result.getValue());
- break;
- }
- }
- return val;
- }
-
- /**
- * Supprime le 0 final d'un nombre à virgule. Le résultat peut-être un
- * double : 1,0 -> 1 et 1,2 -> 1,2.
- *
- * @param val le nombre
- * @return le nombre sans 0 final
- */
- protected String removeTrailing0(String val) {
- if (val.endsWith(".0")) {
- val = val.substring(0, val.indexOf('.'));
- }
- return val;
- }
-
- /**
- * Retourne une chaîne contenant les résultats du sondage.
- *
- * @param poll le sondage
- * @return les résultats sous forme de chaine de caractères
- */
- public String getResultsAsString(Poll poll) {
-
- DateFormat dateFormat = new SimpleDateFormat(getDateTimePattern());
- StringBuilder res = new StringBuilder("");
- Iterator<Result> it = poll.getResult().iterator();
- while (it.hasNext()) {
- Result result = it.next();
- if (poll.getChoiceType() == ChoiceType.DATE) {
- Date date = new Date(Long.parseLong(result.getName()));
- res.append(dateFormat.format(date));
- } else {
- res.append(result.getName());
- }
- res.append("=").append(removeTrailing0(result.getResultValue()));
- if (it.hasNext()) {
- res.append(", ");
- }
- }
- return res.toString();
- }
-}
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-29 21:19:04 UTC (rev 3711)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollVoteCountingService.java 2012-09-30 12:57:25 UTC (rev 3712)
@@ -22,18 +22,32 @@
*/
package org.chorem.pollen.services.impl;
+import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+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.services.PollenServiceSupport;
+import org.chorem.pollen.votecounting.VoteCounting;
+import org.chorem.pollen.votecounting.VoteCountingStrategy;
+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.VoteCounting;
-import org.chorem.pollen.votecounting.VoteCountingStrategy;
+import org.nuiton.topia.persistence.TopiaId;
+import java.math.BigDecimal;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
/**
* New Poll vote counting service.
*
@@ -46,6 +60,17 @@
private static final Log log =
LogFactory.getLog(PollVoteCountingService.class);
+ public VoteCountingResult getMainResult(Poll poll) {
+ VoteCountingResult mainResult;
+ if (poll.isPollGroup()) {
+ GroupVoteCountingResult groupResult = getGroupResult(poll);
+ mainResult = groupResult.getMainResult();
+ } else {
+ mainResult = getSimpleResult(poll);
+ }
+ return mainResult;
+ }
+
/**
* Execute a simple vote counting for a given poll (if the poll
* is a group poll, none of his group will be used).
@@ -85,5 +110,72 @@
return result;
}
+ public String getResultValue(Choice choice,
+ List<ChoiceScore> results) {
+ String val = "";
+ for (ChoiceScore result : results) {
+ if (result.getChoiceId().equals(choice.getTopiaId())) {
+ val = getResultValue(result);
+ break;
+ }
+ }
+ return val;
+ }
+
+ public String getResultValue(ChoiceScore result) {
+
+ BigDecimal scoreValue = result.getScoreValue();
+ String val = removeTrailing0(scoreValue == null ? "" :
+ String.valueOf(scoreValue));
+ return val;
+ }
+
+ /**
+ * Retourne une chaîne contenant les résultats du sondage.
+ *
+ * @param poll le sondage
+ * @return les résultats sous forme de chaine de caractères
+ */
+ public String getResultsAsString(Poll poll) {
+
+ VoteCountingResult mainResult = getMainResult(poll);
+ List<ChoiceScore> results = mainResult.getTopRanking();
+
+ ImmutableMap<String, Choice> choicesById = Maps.uniqueIndex(
+ poll.getChoice(), TopiaId.GET_TOPIA_ID);
+
+ DateFormat dateFormat = new SimpleDateFormat(getDateTimePattern());
+ List<String> resultsAsString = Lists.newArrayList();
+ for (ChoiceScore result : results) {
+ String choiceResult;
+ Choice choice = choicesById.get(result.getChoiceId());
+ if (poll.getChoiceType() == ChoiceType.DATE) {
+ Date date = new Date(Long.parseLong(choice.getName()));
+ choiceResult = dateFormat.format(date);
+ } else {
+ choiceResult = choice.getName();
+ }
+ choiceResult += "=" + removeTrailing0(getResultValue(result));
+ resultsAsString.add(choiceResult);
+ }
+ String result = Joiner.on(",").join(resultsAsString);
+ return result;
+ }
+
+ /**
+ * Supprime le 0 final d'un nombre à virgule. Le résultat peut-être un
+ * double : 1,0 -> 1 et 1,2 -> 1,2.
+ *
+ * @param val le nombre
+ * @return le nombre sans 0 final
+ */
+ protected String removeTrailing0(String val) {
+ if (val.endsWith(".0")) {
+ val = val.substring(0, val.indexOf('.'));
+ }
+ return val;
+ }
+
+
}
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-29 21:19:04 UTC (rev 3711)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-09-30 12:57:25 UTC (rev 3712)
@@ -201,7 +201,7 @@
// regnenerate poll results
- generatePollResult(pollToUpdate);
+// generatePollResult(pollToUpdate);
commitTransaction("Could not create vote");
@@ -263,7 +263,7 @@
log.debug("Entity updated: " + result.getTopiaId());
}
- generatePollResult(poll);
+// generatePollResult(poll);
commitTransaction("Could not update vote");
@@ -333,7 +333,7 @@
log.debug("Entity deleted: " + voteId);
}
- generatePollResult(poll);
+// generatePollResult(poll);
commitTransaction("Could not delete vote");
@@ -407,9 +407,4 @@
return result;
}
- protected void generatePollResult(Poll poll) {
- PollResultsService pollResultsService = newService(PollResultsService.class);
- pollResultsService.generateResult(poll);
- }
-
}
Modified: trunk/pollen-ui-struts2/pom.xml
===================================================================
--- trunk/pollen-ui-struts2/pom.xml 2012-09-29 21:19:04 UTC (rev 3711)
+++ trunk/pollen-ui-struts2/pom.xml 2012-09-30 12:57:25 UTC (rev 3712)
@@ -209,6 +209,18 @@
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-jcl</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
<!-- Test dependencies -->
<dependency>
@@ -259,12 +271,6 @@
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <scope>test</scope>
- </dependency>
-
</dependencies>
<build>
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-29 21:19:04 UTC (rev 3711)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-09-30 12:57:25 UTC (rev 3712)
@@ -43,10 +43,11 @@
import org.chorem.pollen.services.PollenServiceSupport;
import org.chorem.pollen.services.impl.FavoriteService;
import org.chorem.pollen.services.impl.PollCommentService;
+import org.chorem.pollen.services.impl.PollExportService;
import org.chorem.pollen.services.impl.PollFeedService;
-import org.chorem.pollen.services.impl.PollResultsService;
import org.chorem.pollen.services.impl.PollService;
import org.chorem.pollen.services.impl.PollUrlService;
+import org.chorem.pollen.services.impl.PollVoteCountingService;
import org.chorem.pollen.services.impl.PreventRuleService;
import org.chorem.pollen.services.impl.SecurityService;
import org.chorem.pollen.services.impl.UserService;
@@ -362,10 +363,14 @@
return getService(PollUrlService.class);
}
- protected final PollResultsService getPollResultsService() {
- return getService(PollResultsService.class);
+ protected final PollExportService getPollExportService() {
+ return getService(PollExportService.class);
}
+ protected final PollVoteCountingService getPollVoteCountingService() {
+ return getService(PollVoteCountingService.class);
+ }
+
protected final VoteService getVoteService() {
return getService(VoteService.class);
}
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/ExportPoll.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/ExportPoll.java 2012-09-29 21:19:04 UTC (rev 3711)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/admin/ExportPoll.java 2012-09-30 12:57:25 UTC (rev 3712)
@@ -61,7 +61,7 @@
String pollId = getUserSecurityContext().getPoll().getPollId();
- String exportContent = getPollResultsService().exportPolltoXml(pollId);
+ String exportContent = getPollExportService().exportToXml(pollId);
filename = "exportPoll-" + pollId + ".xml";
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-29 21:19:04 UTC (rev 3711)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AbstractVoteAction.java 2012-09-30 12:57:25 UTC (rev 3712)
@@ -28,7 +28,6 @@
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.interceptor.ParameterAware;
import org.chorem.pollen.PollenTechnicalException;
-import org.chorem.pollen.bean.PollResult;
import org.chorem.pollen.bean.PollUrl;
import org.chorem.pollen.business.persistence.Choice;
import org.chorem.pollen.business.persistence.ChoiceType;
@@ -49,6 +48,8 @@
import org.chorem.pollen.ui.actions.PollenActionSupport;
import org.chorem.pollen.ui.actions.PollenUserSecurityAware;
import org.chorem.pollen.votecounting.VoteCounting;
+import org.chorem.pollen.votecounting.model.ChoiceScore;
+import org.chorem.pollen.votecounting.model.VoteCountingResult;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
@@ -114,11 +115,11 @@
private String commentAuthor;
/**
- * Results of the poll.
+ * Top ranking result.
*
- * @since 1.3
+ * @since 1.5
*/
- private List<PollResult> results;
+ List<ChoiceScore> results;
/**
* List of comments to display.
@@ -153,7 +154,7 @@
return vote;
}
- public List<PollResult> getResults() {
+ public List<ChoiceScore> getResults() {
return results;
}
@@ -377,7 +378,7 @@
public String getResultValue(Choice choice) {
- String val = getPollResultsService().getResultValue(choice, results);
+ String val = getPollVoteCountingService().getResultValue(choice, results);
return val;
}
@@ -422,13 +423,14 @@
if (isResultAllowed()) {
// load poll results
- results = getPollResultsService().getResults(poll);
+ VoteCountingResult result =
+ getPollVoteCountingService().getMainResult(poll);
+ results = result.getScores();
+
if (log.isDebugEnabled()) {
- for (PollResult res : results) {
- log.debug(res.getName() + ": " + res.getValue()
- + ", (voteCounting=" + res.getVoteCountingType()
- + ", byGroup=" + res.isByGroup() + ")");
+ for (ChoiceScore res : results) {
+ log.debug(res.getChoiceId() + ": " + res.getScoreValue());
}
}
}
Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-09-29 21:19:04 UTC (rev 3711)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-09-30 12:57:25 UTC (rev 3712)
@@ -114,7 +114,6 @@
<h1 class="titleVote"><s:property value="poll.title"/></h1>
<!-- Informations sur le sondage -->
-<!-- Informations sur le sondage -->
<s:set name="showVoteUrl" value="false"/>
<s:set name="showResultUrl" value="true"/>
<%@include file="pollInformation.jsp" %>
@@ -157,91 +156,84 @@
<%--</s:else>--%>
<s:if test="textType">
<s:iterator value="poll.choice" var="choice">
- <s:if test="!isChoiceHidden(#choice)">
- <th>
- <s:if test="!isDescNull(#choice)">
+ <th>
+ <s:if test="!isDescNull(#choice)">
- <span
- title='<s:property value="escapeLineBreak(#choice.description)"/>'>
- <s:property value="name"/>
- </span>
+ <span
+ title='<s:property value="escapeLineBreak(#choice.description)"/>'>
+ <s:property value="name"/>
+ </span>
+ </s:if>
+ <s:else>
+ <s:property value="name"/>
+ </s:else>
+ <s:if test="pollChoiceRunning">
+ <s:if test="creatorOrAdmin">
+ <s:a action="deleteChoice/%{pollUri}" namespace="/poll"
+ onclick="return openDeleteChoiceDialog('%{#choice.topiaId}');">
+ <s:param name="choiceId"><s:property value="id"/></s:param>
+ <img src="<s:url value="/img/delete.png"/>"
+ title="<s:text name="pollen.action.deleteChoice"/>"
+ alt="<s:text name="pollen.action.deleteChoice"/>"/>
+ </s:a>
</s:if>
- <s:else>
- <s:property value="name"/>
- </s:else>
- <s:if test="pollChoiceRunning">
- <s:if test="creatorOrAdmin">
- <s:a action="deleteChoice/%{pollUri}" namespace="/poll"
- onclick="return openDeleteChoiceDialog('%{#choice.topiaId}');">
- <s:param name="choiceId"><s:property value="id"/></s:param>
- <img src="<s:url value="/img/delete.png"/>"
- title="<s:text name="pollen.action.deleteChoice"/>"
- alt="<s:text name="pollen.action.deleteChoice"/>"/>
- </s:a>
- </s:if>
- </s:if>
- </th>
- </s:if>
+ </s:if>
+ </th>
</s:iterator>
</s:if>
<s:if test="dateType">
<s:iterator value="poll.choice" var="choice">
- <s:if test="!isChoiceHidden(#choice)">
- <s:if test="!isDescNull(#choice)">
+ <s:if test="!isDescNull(#choice)">
- <th class="desc">
- <span
- title='<s:property value="escapeLineBreak(#choice.description)"/>'>
- <s:property value="%{getChoiceAsDate(#choice)}"/>
- </span>
- </th>
- </s:if>
- <s:else>
- <th>
- <s:property value="%{getChoiceAsDate(#choice)}"/>
- </th>
- </s:else>
+ <th class="desc">
+ <span
+ title='<s:property value="escapeLineBreak(#choice.description)"/>'>
+ <s:property value="%{getChoiceAsDate(#choice)}"/>
+ </span>
+ </th>
</s:if>
+ <s:else>
+ <th>
+ <s:property value="%{getChoiceAsDate(#choice)}"/>
+ </th>
+ </s:else>
</s:iterator>
</s:if>
<s:if test="imageType">
<s:iterator value="poll.choice" var="choice">
- <s:if test="!isChoiceHidden(#choice)">
+ <s:url id="imageUrl" namespace="/io" action="getPollChoiceImage"
+ escapeAmp="false">
+ <s:param name="choiceId" value="%{getImageChoiceName(#choice)}"/>
+ <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="%{getImageChoiceName(#choice)}"/>
+ <s:param name="pollId" value="poll.pollId"/>
+ <s:param name="thumb" value="true"/>
+ </s:url>
+ <s:if test="!isDescNull(#choice)">
- <s:url id="imageUrl" namespace="/io" action="getPollChoiceImage"
- escapeAmp="false">
- <s:param name="choiceId" value="%{getImageChoiceName(#choice)}"/>
- <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="%{getImageChoiceName(#choice)}"/>
- <s:param name="pollId" value="poll.pollId"/>
- <s:param name="thumb" value="true"/>
- </s:url>
- <s:if test="!isDescNull(#choice)">
-
- <th class="desc">
- <a href="<s:property value='imageUrl'/>" rel="lightbox">
- <img alt="<s:property value='name'/>"
- title='<s:property value="escapeLineBreak(#choice.description)"/>'
- src="<s:property value='imageUrlThumb'/>">
- </a>
- </th>
- </s:if>
- <s:else>
- <th>
- <a href="<s:property value='imageUrl'/>" rel="lightbox">
- <img alt="<s:property value='name'/>"
- title='<s:property value="escapeLineBreak(#choice.description)"/>'
- src="<s:property value='imageUrlThumb'/>">
- </a>
- </th>
- </s:else>
+ <th class="desc">
+ <a href="<s:property value='imageUrl'/>" rel="lightbox">
+ <img alt="<s:property value='name'/>"
+ title='<s:property value="escapeLineBreak(#choice.description)"/>'
+ src="<s:property value='imageUrlThumb'/>">
+ </a>
+ </th>
</s:if>
+ <s:else>
+ <th>
+ <a href="<s:property value='imageUrl'/>" rel="lightbox">
+ <img alt="<s:property value='name'/>"
+ title='<s:property value="escapeLineBreak(#choice.description)"/>'
+ src="<s:property value='imageUrlThumb'/>">
+ </a>
+ </th>
+ </s:else>
</s:iterator>
</s:if>
</tr>
@@ -260,12 +252,9 @@
</s:else>
<s:set name="template" value="%{choiceFragment}"/>
<s:iterator value="poll.choice" var="choice" status="status">
-
- <s:if test="!isChoiceHidden(#choice)">
- <th>
- <jsp:include page="${template}"/>
- </th>
- </s:if>
+ <th>
+ <jsp:include page="${template}"/>
+ </th>
</s:iterator>
</tr>
</tfoot>
@@ -302,23 +291,21 @@
</s:if>
</td>
<s:iterator value="poll.choice" var="choice">
- <s:if test="!isChoiceHidden(#choice)">
- <s:set name="currentVoteChoice"
- value="%{#vote.getChoiceVoteToChoice(#choice)}"/>
- <%--s:if test="poll.anonymous">
- <td class="anonymous">?</td>
- </s:if>
- <s:else--%>
- <s:if test="isChoiceInVote(#currentVoteChoice)">
- <td class="voted">
- <s:property value="%{getChoiceValue(#currentVoteChoice)}"/>
- </td>
- </s:if>
- <s:else>
- <td class="notVoted"></td>
- </s:else>
- <%--</s:else>--%>
+ <s:set name="currentVoteChoice"
+ value="%{#vote.getChoiceVoteToChoice(#choice)}"/>
+ <%--s:if test="poll.anonymous">
+ <td class="anonymous">?</td>
</s:if>
+ <s:else--%>
+ <s:if test="isChoiceInVote(#currentVoteChoice)">
+ <td class="voted">
+ <s:property value="%{getChoiceValue(#currentVoteChoice)}"/>
+ </td>
+ </s:if>
+ <s:else>
+ <td class="notVoted"></td>
+ </s:else>
+ <%--</s:else>--%>
</s:iterator>
</tr>
</s:iterator>
@@ -332,11 +319,9 @@
</td>
<s:iterator value="poll.choice" var="choice">
- <s:if test="!isChoiceHidden(#choice)">
- <td class="result">
- <s:property value="%{getResultValue(#choice)}"/>
- </td>
- </s:if>
+ <td class="result">
+ <s:property value="%{getResultValue(#choice)}"/>
+ </td>
</s:iterator>
</tr>
</s:if>
@@ -368,23 +353,18 @@
enctype="multipart/form-data">
<h4><s:text name="pollen.action.addChoice"/></h4>
<s:if test="textType">
- <s:textfield key="choice.name"
- label="%{getText('pollen.common.choice')}"
- required="true"/>
+ <s:textfield key="choice.name" required="true"
+ label="%{getText('pollen.common.choice')}" />
</s:if>
<s:elseif test="dateType">
- <sj:datepicker key="choice.date"
+ <sj:datepicker key="choice.date" required="true"
label="%{getText('pollen.common.choice')}"
- changeMonth="true" changeYear="true"
- timepicker="true"
- displayFormat="%{getText('pollen.common.datePickerPattern')}"
- required="true"/>
+ changeMonth="true" changeYear="true" timepicker="true"
+ displayFormat="%{getText('pollen.common.datePickerPattern')}" />
</s:elseif>
<s:elseif test="imageType">
- <s:file key="imageChoice[0]"
- label="%{getText('pollen.common.choice')}"
- cssClass="nameField"
- required="true"/>
+ <s:file key="imageChoice[0]" required="true" cssClass="nameField"
+ label="%{getText('pollen.common.choice')}" />
</s:elseif>
<br/>
<s:textarea cols="36" key="choice.description"
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-29 21:19:04 UTC (rev 3711)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/VoteCountingResult.java 2012-09-30 12:57:25 UTC (rev 3712)
@@ -22,13 +22,11 @@
*/
package org.chorem.pollen.votecounting.model;
+import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
-import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import java.io.Serializable;
-import java.util.Collection;
-import java.util.Collections;
import java.util.List;
/**
@@ -54,7 +52,7 @@
*
* @see ChoiceScore#getScoreOrder()
*/
- private transient Multimap<Integer, ChoiceScore> scoresByRank;
+ private transient ArrayListMultimap<Integer, ChoiceScore> scoresByRank;
public static VoteCountingResult newResult(List<ChoiceScore> scores) {
VoteCountingResult result = new VoteCountingResult();
@@ -81,13 +79,14 @@
this.scores = Lists.newArrayList(scores);
}
- public Collection<ChoiceScore> getTopRanking() {
+ public List<ChoiceScore> getTopRanking() {
return getScoresByRank().get(0);
}
- public Multimap<Integer, ChoiceScore> getScoresByRank() {
+ public ArrayListMultimap<Integer, ChoiceScore> getScoresByRank() {
if (scoresByRank == null) {
- scoresByRank = Multimaps.index(scores, ChoiceScore.SCORE_BY_ORDER);
+ scoresByRank = ArrayListMultimap.create(
+ Multimaps.index(scores, ChoiceScore.SCORE_BY_ORDER));
}
return scoresByRank;
}
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-09-29 21:19:04 UTC (rev 3711)
+++ trunk/pom.xml 2012-09-30 12:57:25 UTC (rev 3712)
@@ -343,11 +343,18 @@
<!-- Logging -->
- <dependency>
+ <!--dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4jVersion}</version>
<scope>compile</scope>
+ </dependency-->
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-jcl</artifactId>
+ <version>${slf4jVersion}</version>
+ <scope>runtime</scope>
</dependency>
<!-- Others -->
1
0
Sept. 29, 2012
Author: tchemit
Date: 2012-09-29 23:19:04 +0200 (Sat, 29 Sep 2012)
New Revision: 3711
Url: http://chorem.org/repositories/revision/pollen/3711
Log:
add missing svn properties + license headers
Modified:
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONSimpleAction.java
trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingFactoryTest.java
trunk/pollen-ui-struts2/src/test/resources/log4j.properties
trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCounting.java
trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCounting.java
trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCountingFactory.java
trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCounting.java
trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCounting.java
trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCounting.java
trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCounting.java
trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCounting.java
trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCounting.java
trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCounting.java
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONSimpleAction.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONSimpleAction.java 2012-09-29 21:18:12 UTC (rev 3710)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONSimpleAction.java 2012-09-29 21:19:04 UTC (rev 3711)
@@ -1,5 +1,28 @@
package org.chorem.pollen.ui.actions.json;
+/*
+ * #%L
+ * Pollen :: UI (struts2)
+ * $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%
+ */
+
import org.chorem.pollen.ui.actions.PollenActionSupport;
import java.util.Map;
Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONSimpleAction.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingFactoryTest.java
===================================================================
--- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingFactoryTest.java 2012-09-29 21:18:12 UTC (rev 3710)
+++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingFactoryTest.java 2012-09-29 21:19:04 UTC (rev 3711)
@@ -1,5 +1,28 @@
package org.chorem.pollen.votecounting.strategy;
+/*
+ * #%L
+ * Pollen :: UI (struts2)
+ * $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%
+ */
+
import org.chorem.pollen.votecounting.BordaVoteCounting;
import org.chorem.pollen.votecounting.CondorcetVoteCounting;
import org.chorem.pollen.votecounting.CoombsVoteCounting;
Property changes on: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingFactoryTest.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-ui-struts2/src/test/resources/log4j.properties
===================================================================
--- trunk/pollen-ui-struts2/src/test/resources/log4j.properties 2012-09-29 21:18:12 UTC (rev 3710)
+++ trunk/pollen-ui-struts2/src/test/resources/log4j.properties 2012-09-29 21:19:04 UTC (rev 3711)
@@ -1,3 +1,25 @@
+###
+# #%L
+# Pollen :: UI (struts2)
+# $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%
+###
# Global logging configuration
log4j.rootLogger=WARN, stdout
# Console output...
Modified: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCounting.java 2012-09-29 21:18:12 UTC (rev 3710)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCounting.java 2012-09-29 21:19:04 UTC (rev 3711)
@@ -1,5 +1,28 @@
package org.chorem.pollen.votecounting;
+/*
+ * #%L
+ * Pollen :: VoteCounting (Api)
+ * $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%
+ */
+
import java.util.Locale;
import static org.nuiton.i18n.I18n.l_;
Property changes on: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCounting.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCounting.java
===================================================================
--- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCounting.java 2012-09-29 21:18:12 UTC (rev 3710)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCounting.java 2012-09-29 21:19:04 UTC (rev 3711)
@@ -1,5 +1,28 @@
package org.chorem.pollen.votecounting;
+/*
+ * #%L
+ * Pollen :: VoteCounting (Api)
+ * $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%
+ */
+
import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
import java.util.Locale;
Property changes on: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCounting.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCountingFactory.java
===================================================================
--- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCountingFactory.java 2012-09-29 21:18:12 UTC (rev 3710)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCountingFactory.java 2012-09-29 21:19:04 UTC (rev 3711)
@@ -1,5 +1,28 @@
package org.chorem.pollen.votecounting;
+/*
+ * #%L
+ * Pollen :: VoteCounting (Api)
+ * $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%
+ */
+
import com.google.common.collect.Maps;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Property changes on: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCountingFactory.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCounting.java 2012-09-29 21:18:12 UTC (rev 3710)
+++ trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCounting.java 2012-09-29 21:19:04 UTC (rev 3711)
@@ -1,5 +1,28 @@
package org.chorem.pollen.votecounting;
+/*
+ * #%L
+ * Pollen :: VoteCounting :: Borda
+ * $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%
+ */
+
import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
import java.util.Locale;
Property changes on: trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCounting.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCounting.java 2012-09-29 21:18:12 UTC (rev 3710)
+++ trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCounting.java 2012-09-29 21:19:04 UTC (rev 3711)
@@ -1,5 +1,28 @@
package org.chorem.pollen.votecounting;
+/*
+ * #%L
+ * Pollen :: VoteCounting :: Condorcet
+ * $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%
+ */
+
import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
import java.util.Locale;
Property changes on: trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCounting.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCounting.java 2012-09-29 21:18:12 UTC (rev 3710)
+++ trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCounting.java 2012-09-29 21:19:04 UTC (rev 3711)
@@ -1,5 +1,28 @@
package org.chorem.pollen.votecounting;
+/*
+ * #%L
+ * Pollen :: VoteCounting :: Coombs
+ * $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%
+ */
+
import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
import java.util.Locale;
Property changes on: trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCounting.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCounting.java 2012-09-29 21:18:12 UTC (rev 3710)
+++ trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCounting.java 2012-09-29 21:19:04 UTC (rev 3711)
@@ -1,5 +1,28 @@
package org.chorem.pollen.votecounting;
+/*
+ * #%L
+ * Pollen :: VoteCounting :: Instant Runoff
+ * $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%
+ */
+
import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
import java.util.Locale;
Property changes on: trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCounting.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCounting.java 2012-09-29 21:18:12 UTC (rev 3710)
+++ trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCounting.java 2012-09-29 21:19:04 UTC (rev 3711)
@@ -1,5 +1,28 @@
package org.chorem.pollen.votecounting;
+/*
+ * #%L
+ * Pollen :: VoteCounting :: Normal
+ * $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%
+ */
+
import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
import java.util.Locale;
Property changes on: trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCounting.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCounting.java 2012-09-29 21:18:12 UTC (rev 3710)
+++ trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCounting.java 2012-09-29 21:19:04 UTC (rev 3711)
@@ -1,5 +1,28 @@
package org.chorem.pollen.votecounting;
+/*
+ * #%L
+ * Pollen :: VoteCounting :: Number
+ * $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%
+ */
+
import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
import java.util.Locale;
Property changes on: trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCounting.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCounting.java 2012-09-29 21:18:12 UTC (rev 3710)
+++ trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCounting.java 2012-09-29 21:19:04 UTC (rev 3711)
@@ -1,5 +1,28 @@
package org.chorem.pollen.votecounting;
+/*
+ * #%L
+ * Pollen :: VoteCounting :: Percentage
+ * $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%
+ */
+
import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
import java.util.Locale;
Property changes on: trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCounting.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
1
0
Sept. 29, 2012
Author: tchemit
Date: 2012-09-29 23:18:12 +0200 (Sat, 29 Sep 2012)
New Revision: 3710
Url: http://chorem.org/repositories/revision/pollen/3710
Log:
refs #590: Refactor votecounting module (improve code)
Removed:
trunk/pollen-votecounting-api/src/test/java/org/chorem/pollen/votecounting/model/ChoiceScoreTest.java
Modified:
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java
trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCounting.java
trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCountingStrategy.java
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/VoteCountingResult.java
trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCountingStrategy.java
trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCountingStrategy.java
trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCountingStrategy.java
trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCountingStrategy.java
trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCountingStrategy.java
trunk/pollen-votecounting-normal/src/test/java/org/chorem/pollen/votecounting/NormalVoteCountingStrategyTest.java
trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCountingStrategy.java
trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCountingStrategy.java
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-29 13:06:12 UTC (rev 3709)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-09-29 21:18:12 UTC (rev 3710)
@@ -44,13 +44,14 @@
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.VoteCounting;
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.VoteCounting;
import org.nuiton.topia.persistence.TopiaId;
import java.net.URL;
+import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -221,7 +222,7 @@
public String getVictoryMessage() {
- Set<ChoiceScore> topRanking = pollResult.getTopRanking();
+ Collection<ChoiceScore> topRanking = pollResult.getTopRanking();
String victoryMessage;
if (CollectionUtils.isEmpty(topRanking)) {
Modified: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCounting.java 2012-09-29 13:06:12 UTC (rev 3709)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCounting.java 2012-09-29 21:18:12 UTC (rev 3710)
@@ -12,19 +12,23 @@
*/
public abstract class AbstractVoteCounting<S extends VoteCountingStrategy> implements VoteCounting<S> {
- protected final int strategyId;
+ /** Unique id of the vote counting type. */
+ protected final int id;
+ /** Type of strategy used to vote count. */
protected final Class<S> strategyType;
+ /** I18n key for name of this vote counting type. */
protected final String i18nName;
+ /** I18n Key for help of this vote counting type. */
protected final String i18nHelp;
- public AbstractVoteCounting(int strategyId,
+ protected AbstractVoteCounting(int id,
Class<S> strategyType,
String i18nName,
String i18nHelp) {
- this.strategyId = strategyId;
+ this.id = id;
this.strategyType = strategyType;
this.i18nName = i18nName;
this.i18nHelp = i18nHelp;
@@ -55,7 +59,7 @@
@Override
public final int getId() {
- return strategyId;
+ return id;
}
@Override
Modified: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCountingStrategy.java
===================================================================
--- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCountingStrategy.java 2012-09-29 13:06:12 UTC (rev 3709)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCountingStrategy.java 2012-09-29 21:18:12 UTC (rev 3710)
@@ -25,6 +25,8 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.Multimaps;
import com.google.common.collect.Sets;
import org.chorem.pollen.votecounting.model.ChoiceIdAble;
import org.chorem.pollen.votecounting.model.ChoiceScore;
@@ -34,14 +36,13 @@
import org.chorem.pollen.votecounting.model.VoteForChoice;
import org.chorem.pollen.votecounting.model.Voter;
-import java.io.Serializable;
import java.math.BigDecimal;
+import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.SortedMap;
/**
* Base abstract implementation of a {@link VoteCountingStrategy}.
@@ -53,6 +54,22 @@
public static final BigDecimal ZERO_D = BigDecimal.valueOf(0.);
+ protected final Comparator<VoteForChoice> voteValueComparator = new Comparator<VoteForChoice>() {
+
+ @Override
+ public int compare(VoteForChoice o1, VoteForChoice o2) {
+ Double v1 = o1.getVoteValue();
+ Double v2 = o2.getVoteValue();
+ if (v1 == null) {
+ v1 = Double.MAX_VALUE;
+ }
+ if (v2 == null) {
+ v2 = Double.MAX_VALUE;
+ }
+ return v1.intValue() - v2.intValue();
+ }
+ };
+
@Override
public final GroupVoteCountingResult votecount(GroupOfVoter group) {
@@ -64,11 +81,11 @@
return result;
}
- public SortedMap<String, ChoiceScore> votersToResult(Set<Voter> voters) {
+ public Map<String, ChoiceScore> newEmptyChoiceScoreMap(Set<Voter> voters) {
// get all choice Id
Set<String> choiceIds = getAllChoiceIds(voters);
- SortedMap<String, ChoiceScore> resultByChoice = Maps.newTreeMap();
+ Map<String, ChoiceScore> resultByChoice = Maps.newHashMap();
// creates all empty result for choice
for (String choiceId : choiceIds) {
@@ -78,16 +95,37 @@
return resultByChoice;
}
- public VoteCountingResult resultToList(Map<String, ChoiceScore> resultByChoice) {
- List<ChoiceScore> score = toChoiceScore(resultByChoice);
- return VoteCountingResult.newResult(score);
- }
+ protected VoteCountingResult orderByValues(Collection<ChoiceScore> scores) {
- public List<ChoiceScore> toChoiceScore(Map<String, ChoiceScore> resultByChoice) {
- List<ChoiceScore> score = Lists.newArrayList(resultByChoice.values());
- Collections.sort(score);
- Collections.reverse(score);
- return score;
+ // get scores by score value
+ Multimap<BigDecimal, ChoiceScore> map = Multimaps.index(
+ scores, ChoiceScore.SCORE_BY_VALUE
+ );
+
+ // get all distinct score values
+ List<BigDecimal> values = Lists.newArrayList(map.asMap().keySet());
+ Collections.sort(values);
+ Collections.reverse(values);
+
+ // compute rank for each scores
+ int rank = 0;
+ for (BigDecimal value : values) {
+
+ Collection<ChoiceScore> scoresForValue = map.get(value);
+ for (ChoiceScore score : scoresForValue) {
+ score.setScoreOrder(rank);
+ }
+ rank++;
+ }
+ // get all scores
+ List<ChoiceScore> orderedScores = Lists.newArrayList(map.values());
+
+ // sort them by their rank
+ Collections.sort(orderedScores);
+
+ // transform map of result to list of them (and sort them)
+ VoteCountingResult result = VoteCountingResult.newResult(orderedScores);
+ return result;
}
public Set<String> getAllChoiceIds(Set<Voter> voters) {
@@ -104,24 +142,21 @@
public Map<Voter, List<Set<String>>> buildVoterSortedChoices(Set<Voter> voters) {
- VoteForChoiceComparator comparator = new VoteForChoiceComparator();
-
Map<Voter, List<Set<String>>> voterSortedChoices = Maps.newHashMap();
for (Voter voter : voters) {
List<Set<String>> sortedChoices = sortVoteForChoices(
- voter.getVoteForChoices(), comparator);
+ voter.getVoteForChoices());
voterSortedChoices.put(voter, sortedChoices);
}
return voterSortedChoices;
}
- public List<Set<String>> sortVoteForChoices(Set<VoteForChoice> voteForChoices,
- Comparator<VoteForChoice> comparator) {
+ public List<Set<String>> sortVoteForChoices(Set<VoteForChoice> voteForChoices) {
// get sort vote for choices
List<VoteForChoice> sortedChoices = Lists.newArrayList(voteForChoices);
- Collections.sort(sortedChoices, comparator);
+ Collections.sort(sortedChoices, voteValueComparator);
// build ranks
List<Set<String>> result = Lists.newArrayList();
@@ -131,7 +166,7 @@
VoteForChoice lastVoteForChoice = null;
for (VoteForChoice voteForChoice : sortedChoices) {
if (lastVoteForChoice != null &&
- comparator.compare(lastVoteForChoice, voteForChoice) != 0) {
+ voteValueComparator.compare(lastVoteForChoice, voteForChoice) != 0) {
// new rank found
// register it
@@ -166,22 +201,4 @@
// store the result for this group
group.setResult(voteCountingResult);
}
-
- public static class VoteForChoiceComparator implements Comparator<VoteForChoice>, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public int compare(VoteForChoice o1, VoteForChoice o2) {
- Double v1 = o1.getVoteValue();
- Double v2 = o2.getVoteValue();
- if (v1 == null) {
- v1 = Double.MAX_VALUE;
- }
- if (v2 == null) {
- v2 = Double.MAX_VALUE;
- }
- return v1.intValue() - v2.intValue();
- }
- }
}
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-29 13:06:12 UTC (rev 3709)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/ChoiceScore.java 2012-09-29 21:18:12 UTC (rev 3710)
@@ -22,11 +22,16 @@
*/
package org.chorem.pollen.votecounting.model;
+import com.google.common.base.Function;
+
import java.io.Serializable;
import java.math.BigDecimal;
/**
* Score for a given choice.
+ * <p/>
+ * Rank is given by the field {@link #scoreOrder} and this class is
+ * comparable of this data.
*
* @author tchemit <chemit(a)codelutin.com>
* @since 1.4.5
@@ -35,13 +40,33 @@
private static final long serialVersionUID = 1L;
+ public static final Function<ChoiceScore, Integer> SCORE_BY_ORDER = new Function<ChoiceScore, Integer>() {
+ @Override
+ public Integer apply(ChoiceScore input) {
+ return input.getScoreOrder();
+ }
+ };
+
+ protected static final BigDecimal MIN_VALUE = BigDecimal.valueOf(Double.MIN_VALUE);
+
+ public static final Function<ChoiceScore, BigDecimal> SCORE_BY_VALUE = new Function<ChoiceScore, BigDecimal>() {
+ @Override
+ public BigDecimal apply(ChoiceScore input) {
+ BigDecimal value = input.getScoreValue();
+ return value == null ? MIN_VALUE : value;
+ }
+ };
+
/** Id of the choice. */
private String choiceId;
- /** Global score for this choice (in some poll does not mean a lot...). */
+ /**
+ * Global score for this choice (in some vote count it does not mean a
+ * lot (and it should be improved to take account of the notion of round)).
+ */
private BigDecimal scoreValue;
- /** Order of this score (0 is winner, 1, second,...). */
+ /** Order of this score (0 is winner, 1 is second,...). */
private int scoreOrder;
public static ChoiceScore newScore(String choiceId, BigDecimal scoreValue) {
@@ -89,8 +114,6 @@
@Override
public int compareTo(ChoiceScore o) {
- int i1 = scoreValue == null ? -1 : scoreValue.intValue();
- int i2 = o.scoreValue == null ? -1 : o.scoreValue.intValue();
- return i1 - i2;
+ return scoreOrder - o.scoreOrder;
}
}
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-29 13:06:12 UTC (rev 3709)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/GroupOfVoter.java 2012-09-29 21:18:12 UTC (rev 3710)
@@ -24,6 +24,7 @@
import com.google.common.collect.Sets;
+import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
@@ -106,7 +107,7 @@
public void setResult(VoteCountingResult result) {
this.result = result;
- Set<ChoiceScore> winners = result.getTopRanking();
+ Collection<ChoiceScore> winners = result.getTopRanking();
for (ChoiceScore choiceScore : result.getScores()) {
double score = winners.contains(choiceScore) ? 1d : 0d;
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-29 13:06:12 UTC (rev 3709)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/VoteCountingResult.java 2012-09-29 21:18:12 UTC (rev 3710)
@@ -23,14 +23,13 @@
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 com.google.common.collect.Multimap;
+import com.google.common.collect.Multimaps;
import java.io.Serializable;
-import java.math.BigDecimal;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import java.util.Set;
/**
* Contains results for a vote.
@@ -50,8 +49,12 @@
*/
private List<ChoiceScore> scores;
- /** Get the winners (could be more than one of it). */
- private Set<ChoiceScore> topRanking;
+ /**
+ * Result for each choice order by their winning rank.
+ *
+ * @see ChoiceScore#getScoreOrder()
+ */
+ private transient Multimap<Integer, ChoiceScore> scoresByRank;
public static VoteCountingResult newResult(List<ChoiceScore> scores) {
VoteCountingResult result = new VoteCountingResult();
@@ -75,25 +78,17 @@
}
public void setScores(List<ChoiceScore> scores) {
- this.scores = scores;
- List<ChoiceScore> ranking = Lists.newArrayList(getScores());
+ this.scores = Lists.newArrayList(scores);
+ }
- Collections.sort(ranking);
- Collections.reverse(ranking);
+ public Collection<ChoiceScore> getTopRanking() {
+ return getScoresByRank().get(0);
+ }
- 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 Multimap<Integer, ChoiceScore> getScoresByRank() {
+ if (scoresByRank == null) {
+ scoresByRank = Multimaps.index(scores, ChoiceScore.SCORE_BY_ORDER);
}
+ return scoresByRank;
}
-
- public Set<ChoiceScore> getTopRanking() {
- return topRanking;
- }
}
Deleted: trunk/pollen-votecounting-api/src/test/java/org/chorem/pollen/votecounting/model/ChoiceScoreTest.java
===================================================================
--- trunk/pollen-votecounting-api/src/test/java/org/chorem/pollen/votecounting/model/ChoiceScoreTest.java 2012-09-29 13:06:12 UTC (rev 3709)
+++ trunk/pollen-votecounting-api/src/test/java/org/chorem/pollen/votecounting/model/ChoiceScoreTest.java 2012-09-29 21:18:12 UTC (rev 3710)
@@ -1,81 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting Api
- * $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.votecounting.model;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.math.BigDecimal;
-
-/**
- * Tests the {@link ChoiceScore}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class ChoiceScoreTest {
-
- @Test
- public void compareTo() throws Exception {
-
- ChoiceScore c1;
- ChoiceScore c2;
-
- // c1 == c2
- c1 = ChoiceScore.newScore("c1", null);
- c2 = ChoiceScore.newScore("c2", null);
- Assert.assertTrue(c1.compareTo(c2) == 0);
-
- // c1 < c2
- c1 = ChoiceScore.newScore("c1", null);
- c2 = ChoiceScore.newScore("c2", BigDecimal.ZERO);
- Assert.assertTrue(c1.compareTo(c2) < 0);
-
- // c1 > c2
- c1 = ChoiceScore.newScore("c1", BigDecimal.ZERO);
- c2 = ChoiceScore.newScore("c2", null);
- Assert.assertTrue(c1.compareTo(c2) > 0);
-
- // c1 == c2
- c1 = ChoiceScore.newScore("c1", BigDecimal.ZERO);
- c2 = ChoiceScore.newScore("c2", BigDecimal.ZERO);
- Assert.assertTrue(c1.compareTo(c2) == 0);
-
-
- // c1 > c2
- c1 = ChoiceScore.newScore("c1", BigDecimal.ONE);
- c2 = ChoiceScore.newScore("c2", BigDecimal.ZERO);
- Assert.assertTrue(c1.compareTo(c2) > 0);
-
- // c1 == c2
- c1 = ChoiceScore.newScore("c1", BigDecimal.ONE);
- c2 = ChoiceScore.newScore("c2", BigDecimal.ONE);
- Assert.assertTrue(c1.compareTo(c2) == 0);
-
- // c1 < c2
- c1 = ChoiceScore.newScore("c1", BigDecimal.ONE);
- c2 = ChoiceScore.newScore("c2", BigDecimal.TEN);
- Assert.assertTrue(c1.compareTo(c2) < 0);
-
- }
-}
Modified: trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCountingStrategy.java
===================================================================
--- trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCountingStrategy.java 2012-09-29 13:06:12 UTC (rev 3709)
+++ trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCountingStrategy.java 2012-09-29 21:18:12 UTC (rev 3710)
@@ -48,10 +48,10 @@
public VoteCountingResult votecount(Set<Voter> voters) {
// get empty result by choice
- Map<String, ChoiceScore> resultByChoice = votersToResult(voters);
+ Map<String, ChoiceScore> scores = newEmptyChoiceScoreMap(voters);
// nb of choices
- int nbChoices = resultByChoice.keySet().size();
+ int nbChoices = scores.keySet().size();
if (log.isDebugEnabled()) {
log.debug("Nb choices: " + nbChoices);
@@ -73,16 +73,14 @@
for (String choiceId : sortedChoiceId) {
- resultByChoice.get(choiceId).addScoreValue(choiceWeight);
+ scores.get(choiceId).addScoreValue(choiceWeight);
}
choiceWeight -= weight;
}
}
- // transform map of result to list of them (and sort them)
- VoteCountingResult result = resultToList(resultByChoice);
+ // order scores (using their value) and return result
+ VoteCountingResult result = orderByValues(scores.values());
return result;
}
-
-
}
Modified: trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCountingStrategy.java
===================================================================
--- trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCountingStrategy.java 2012-09-29 13:06:12 UTC (rev 3709)
+++ trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCountingStrategy.java 2012-09-29 21:18:12 UTC (rev 3710)
@@ -22,20 +22,13 @@
*/
package org.chorem.pollen.votecounting;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.votecounting.model.ChoiceIdAble;
import org.chorem.pollen.votecounting.model.ChoiceScore;
import org.chorem.pollen.votecounting.model.VoteCountingResult;
import org.chorem.pollen.votecounting.model.VoteForChoice;
import org.chorem.pollen.votecounting.model.Voter;
-import java.math.BigDecimal;
-import java.util.Arrays;
-import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -55,193 +48,53 @@
public VoteCountingResult votecount(Set<Voter> voters) {
// get empty result by choice
- Map<String, ChoiceScore> resultByChoice = votersToResult(voters);
+ Map<String, ChoiceScore> scores = newEmptyChoiceScoreMap(voters);
- // get order over choices (needed to get coordinates over matrix)
- List<String> choiceIds = Lists.newArrayList(resultByChoice.keySet());
+ for (Voter voter : voters) {
- // nb of choices
- int nbChoices = choiceIds.size();
-
- //matrix of pairwise
- double[][] matrix = new double[nbChoices][nbChoices];
-
- // compute pairwise battle matrix and try to have a direct winner(s)
- Set<String> winners = computePairWiseMatrix(choiceIds, voters, matrix);
-
- // compute nb battles wins for each choice
- // and store it as choice score value
- computeNbBattlesByChoice(resultByChoice, choiceIds, matrix);
-
- // get choice score ordered by their number of win battles
- List<ChoiceScore> choiceScores = toChoiceScore(resultByChoice);
-
- if (winners != null) {
-
- // there is winner(s), re-add them to
-
- if (log.isDebugEnabled()) {
- log.debug("Direct winners : " + winners);
- }
- for (String choiceId : winners) {
- ChoiceScore choiceScore = resultByChoice.get(choiceId);
- choiceScores.remove(choiceScore);
- choiceScores.add(0, choiceScore);
- }
- } else {
-
- // no direct winner, must resolv conflicts
-
- resolvConflicts(choiceScores, matrix);
+ // add this voter votes to result
+ addVoterChoices(voter, scores);
}
- // transform map of result to list of them (and sort them)
- VoteCountingResult result = resultToList(resultByChoice);
+ // order scores (using their value) and return result
+ VoteCountingResult result = orderByValues(scores.values());
return result;
}
- protected void resolvConflicts(List<ChoiceScore> choiceScores,
- double[][] matrix) {
+ protected void addVoterChoices(Voter voter,
+ Map<String, ChoiceScore> scores) {
- // for the moment we use only number of win battles
- // so nothing more to do here...
- }
-
- protected void computeNbBattlesByChoice(Map<String, ChoiceScore> resultByChoice,
- List<String> choiceIds,
- double[][] matrix) {
-
- int nbChoices = choiceIds.size();
-
- for (String choiceId : choiceIds) {
-
- int i = choiceIds.indexOf(choiceId);
-
- double nbBattles = 0;
- for (int j = 0; j < nbChoices; j++) {
- double aRow = matrix[i][j];
- nbBattles += aRow;
- }
-
- resultByChoice.get(choiceId).setScoreValue(
- BigDecimal.valueOf(nbBattles));
-
- if (log.isDebugEnabled()) {
- log.debug("Nb battle wins for choice " + choiceId + ": " + nbBattles);
- }
+ if (log.isDebugEnabled()) {
+ log.debug("Start count for voter " + voter.getVoterId());
}
- }
+ double voterWeight = voter.getWeight();
- private Set<String> computePairWiseMatrix(List<String> choiceIds,
- Set<Voter> voters,
- double[][] matrix) {
+ for (VoteForChoice voteForChoiceX : voter.getVoteForChoices()) {
- int nbChoices = choiceIds.size();
+ String choiceIdX = voteForChoiceX.getChoiceId();
- Set<String> winners = null;
+ double score = 0;
- VoteForChoiceComparator comparator = new VoteForChoiceComparator();
+ for (VoteForChoice voteForChoiceY : voter.getVoteForChoices()) {
- double[] currentVoteWinner = new double[choiceIds.size()];
-
- boolean firstVoter = true;
- for (Voter voter : voters) {
-
- if (log.isDebugEnabled()) {
- log.debug("Start count for voter " + voter.getVoterId());
- }
- double voterWeight = voter.getWeight();
-
- Arrays.fill(currentVoteWinner, 0);
-
- Map<String, VoteForChoice> voteByChoiceIds =
- Maps.uniqueIndex(voter.getVoteForChoices(),
- new ChoiceIdAble.ChoiceIdAbleById());
-
- double maxBattleWins = 0;
-
- for (String choiceId : choiceIds) {
-
- // get vote for this choice
- VoteForChoice voteForChoice = voteByChoiceIds.get(choiceId);
-
- int x = choiceIds.indexOf(choiceId);
-
- for (VoteForChoice voteForChoice1 : voter.getVoteForChoices()) {
-
- String choiceId1 = voteForChoice1.getChoiceId();
- if (choiceId.equals(choiceId1)) {
-
- // can not battle same choice
- continue;
- }
-
- int y = choiceIds.indexOf(choiceId1);
-
- int compare = comparator.compare(voteForChoice,
- voteForChoice1);
-
- if (compare < 0) {
-
- // voteForChoice wins his battle
-
- int pos = x * nbChoices + y;
-
- matrix[x][y] = matrix[x][y] + voterWeight;
- if (log.isTraceEnabled()) {
- log.trace("battle [" + choiceId + "<" +
- voteForChoice.getVoteValue() + "> - " +
- choiceId1 + "<" +
- voteForChoice1.getVoteValue() +
- ">] wins (store to " + pos +
- ", new value=" + matrix[x][y] + ")");
- }
- maxBattleWins = Math.max(
- maxBattleWins,
- currentVoteWinner[x] =
- currentVoteWinner[x] + voterWeight);
- }
+ if (choiceIdX.equals(voteForChoiceY.getChoiceId())) {
+ // no battle for same choice
+ continue;
}
- }
+ int compare = voteValueComparator.compare(voteForChoiceX,
+ voteForChoiceY);
- if (firstVoter || winners != null) {
+ if (compare < 0) {
- // still have a winner, le'ts compute current winner
- Set<String> currentVoteWinners = Sets.newHashSet();
-
- // find winners of this vote
- for (int i = 0; i < currentVoteWinner.length; i++) {
- if (maxBattleWins == currentVoteWinner[i]) {
-
- // this is a winner for this vote
- String choiceId = choiceIds.get(i);
- currentVoteWinners.add(choiceId);
- }
+ // X wins over Y;
+ score += voterWeight;
}
- if (log.isDebugEnabled()) {
- log.debug("Winners of this vote : " + currentVoteWinners);
- }
-
-
- if (firstVoter) {
-
- // keep this first result
- winners = currentVoteWinners;
- } else if (!winners.equals(currentVoteWinners)) {
-
- // current vote has not same winners than previous,
- // so will need resolution
- winners = null;
-
- if (log.isDebugEnabled()) {
- log.debug("Dismatch winners (will need resolv...)");
- }
- }
}
- firstVoter = false;
+ // store new score for this choice
+ ChoiceScore choiceScore = scores.get(choiceIdX);
+ choiceScore.addScoreValue(score);
}
- return winners;
}
}
Modified: trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCountingStrategy.java
===================================================================
--- trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCountingStrategy.java 2012-09-29 13:06:12 UTC (rev 3709)
+++ trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCountingStrategy.java 2012-09-29 21:18:12 UTC (rev 3710)
@@ -35,7 +35,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.SortedMap;
/**
* Coombs vote counting strategy.
@@ -49,7 +48,7 @@
public VoteCountingResult votecount(Set<Voter> voters) {
// get empty result by choice
- SortedMap<String, ChoiceScore> resultByChoice = votersToResult(voters);
+ Map<String, ChoiceScore> scores = newEmptyChoiceScoreMap(voters);
// calcul du score minimum pour atteindre la majorité absolue
double totalWeight = 0.;
@@ -63,24 +62,24 @@
buildVoterSortedChoices(voters);
Set<String> choiceIdsToExclude = Sets.newHashSet();
- Set<String> choiceIdsToKeep = Sets.newHashSet(resultByChoice.keySet());
+ Set<String> choiceIdsToKeep = Sets.newHashSet(scores.keySet());
+ //FIXME Must use round of elemination to order scores
round(topRankChoices,
choiceIdsToExclude,
choiceIdsToKeep,
- resultByChoice,
+ scores,
totalWeight);
-
- // transform map of result to list of them (and sort them)
- VoteCountingResult result = resultToList(resultByChoice);
+ // order scores (using their value) and return result
+ VoteCountingResult result = orderByValues(scores.values());
return result;
}
- public void round(Map<Voter, List<Set<String>>> topRankChoices,
+ protected void round(Map<Voter, List<Set<String>>> topRankChoices,
Set<String> idsToExclude,
Set<String> idsToInclude,
- SortedMap<String, ChoiceScore> resultByChoice,
+ Map<String, ChoiceScore> resultByChoice,
double totalWeight) {
List<ChoiceScore> results = applyScores(topRankChoices,
@@ -117,10 +116,10 @@
}
}
- public List<ChoiceScore> applyScores(Map<Voter, List<Set<String>>> topRankChoices,
+ protected List<ChoiceScore> applyScores(Map<Voter, List<Set<String>>> topRankChoices,
Set<String> idsToExclude,
Set<String> idsToInclude,
- SortedMap<String, ChoiceScore> resultByChoice) {
+ Map<String, ChoiceScore> resultByChoice) {
if (CollectionUtils.isNotEmpty(idsToExclude)) {
@@ -188,7 +187,7 @@
return results;
}
- public void guessChoiceIdsToRemove(Set<String> idsToInclude,
+ protected void guessChoiceIdsToRemove(Set<String> idsToInclude,
Set<String> idsToExclude,
Map<Voter, List<Set<String>>> results) {
Modified: trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCountingStrategy.java
===================================================================
--- trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCountingStrategy.java 2012-09-29 13:06:12 UTC (rev 3709)
+++ trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCountingStrategy.java 2012-09-29 21:18:12 UTC (rev 3710)
@@ -34,7 +34,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.SortedMap;
/**
* InstantRunoff.
@@ -48,7 +47,7 @@
public VoteCountingResult votecount(Set<Voter> voters) {
// get empty result by choice
- SortedMap<String, ChoiceScore> resultByChoice = votersToResult(voters);
+ Map<String, ChoiceScore> scores = newEmptyChoiceScoreMap(voters);
// calcul du score minimum pour atteindre la majorité absolue
double totalWeight = 0.;
@@ -62,23 +61,24 @@
buildVoterSortedChoices(voters);
Set<String> choiceIdsToExclude = Sets.newHashSet();
- Set<String> choiceIdsToKeep = Sets.newHashSet(resultByChoice.keySet());
+ Set<String> choiceIdsToKeep = Sets.newHashSet(scores.keySet());
+ //FIXME Must use round of elemination to order scores
round(topRankChoices,
choiceIdsToExclude,
choiceIdsToKeep,
- resultByChoice,
+ scores,
totalWeight);
- // transform map of result to list of them (and sort them)
- VoteCountingResult result = resultToList(resultByChoice);
+ // order scores (using their value) and return result
+ VoteCountingResult result = orderByValues(scores.values());
return result;
}
- public void round(Map<Voter, List<Set<String>>> topRankChoices,
+ protected void round(Map<Voter, List<Set<String>>> topRankChoices,
Set<String> idsToExclude,
Set<String> idsToInclude,
- SortedMap<String, ChoiceScore> resultByChoice,
+ Map<String, ChoiceScore> resultByChoice,
double totalWeight) {
List<ChoiceScore> results = applyScores(topRankChoices,
@@ -116,10 +116,10 @@
}
}
- public List<ChoiceScore> applyScores(Map<Voter, List<Set<String>>> topRankChoices,
+ protected List<ChoiceScore> applyScores(Map<Voter, List<Set<String>>> topRankChoices,
Set<String> idsToExclude,
Set<String> idsToInclude,
- SortedMap<String, ChoiceScore> resultByChoice) {
+ Map<String, ChoiceScore> resultByChoice) {
if (CollectionUtils.isNotEmpty(idsToExclude)) {
@@ -187,7 +187,7 @@
return results;
}
- public void guessChoiceIdsToRemove(Set<String> idsToExclude,
+ protected void guessChoiceIdsToRemove(Set<String> idsToExclude,
List<ChoiceScore> results) {
double min = results.get(0).getScoreValue().doubleValue();
Modified: trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCountingStrategy.java
===================================================================
--- trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCountingStrategy.java 2012-09-29 13:06:12 UTC (rev 3709)
+++ trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCountingStrategy.java 2012-09-29 21:18:12 UTC (rev 3710)
@@ -31,7 +31,9 @@
import java.util.Set;
/**
- * Condorcet.
+ * Vote counting strategy for {@link NormalVoteCounting}.
+ * <p/>
+ * This is a very basic vote counting:
*
* @author tchemit <chemit(a)codelutin.com>
* @since 1.4.5
@@ -42,19 +44,21 @@
public VoteCountingResult votecount(Set<Voter> voters) {
// get empty result by choice
- Map<String, ChoiceScore> resultByChoice = votersToResult(voters);
+ Map<String, ChoiceScore> scores = newEmptyChoiceScoreMap(voters);
for (Voter voter : voters) {
+
// add this voter votes to result
- addVoterChoices(voter, resultByChoice);
+ addVoterChoices(voter, scores);
}
- // transform map of result to list of them (and sort them)
- VoteCountingResult result = resultToList(resultByChoice);
+
+ // order scores (using their value) and return result
+ VoteCountingResult result = orderByValues(scores.values());
return result;
}
- public void addVoterChoices(Voter voter,
- Map<String, ChoiceScore> resultByChoice) {
+ protected void addVoterChoices(Voter voter,
+ Map<String, ChoiceScore> scores) {
double voterWeight = voter.getWeight();
@@ -63,14 +67,13 @@
if (voteValue != null) {
// get score for choice
- String choiceId = voteForChoice.getChoiceId();
- ChoiceScore choiceScore = resultByChoice.get(choiceId);
+ ChoiceScore score = scores.get(voteForChoice.getChoiceId());
// compute score to add
double scoreToAdd = voteValue * voterWeight;
// add to score this weighted vote
- choiceScore.addScoreValue(scoreToAdd);
+ score.addScoreValue(scoreToAdd);
}
}
}
Modified: trunk/pollen-votecounting-normal/src/test/java/org/chorem/pollen/votecounting/NormalVoteCountingStrategyTest.java
===================================================================
--- trunk/pollen-votecounting-normal/src/test/java/org/chorem/pollen/votecounting/NormalVoteCountingStrategyTest.java 2012-09-29 13:06:12 UTC (rev 3709)
+++ trunk/pollen-votecounting-normal/src/test/java/org/chorem/pollen/votecounting/NormalVoteCountingStrategyTest.java 2012-09-29 21:18:12 UTC (rev 3710)
@@ -103,9 +103,9 @@
Assert.assertNotNull(scores);
Assert.assertEquals(3, scores.size());
- assertChoiceScore(scores.get(0), CHOICE_B, BigDecimal.valueOf(2.));
+ assertChoiceScore(scores.get(0), CHOICE_B, BigDecimal.valueOf(2.), 0);
- assertChoiceScoreEquals(BigDecimal.valueOf(1.),
+ assertChoiceScoreEquals(BigDecimal.valueOf(1.), 1,
Sets.newHashSet(scores.get(1),
scores.get(2)),
CHOICE_A, CHOICE_C);
@@ -166,9 +166,9 @@
Assert.assertNotNull(scores);
Assert.assertEquals(3, scores.size());
- assertChoiceScore(scores.get(0), CHOICE_B, BigDecimal.valueOf(2.));
+ assertChoiceScore(scores.get(0), CHOICE_B, BigDecimal.valueOf(2.), 0);
- assertChoiceScoreEquals(BigDecimal.valueOf(1.),
+ assertChoiceScoreEquals(BigDecimal.valueOf(1.), 1,
Sets.newHashSet(scores.get(1),
scores.get(2)),
CHOICE_A, CHOICE_C);
@@ -204,9 +204,9 @@
Assert.assertNotNull(scores);
Assert.assertEquals(3, scores.size());
- assertChoiceScore(scores.get(0), CHOICE_A, BigDecimal.valueOf(3.));
- assertChoiceScore(scores.get(1), CHOICE_B, BigDecimal.valueOf(2.));
- assertChoiceScore(scores.get(2), CHOICE_C, null);
+ assertChoiceScore(scores.get(0), CHOICE_A, BigDecimal.valueOf(3.), 0);
+ assertChoiceScore(scores.get(1), CHOICE_B, BigDecimal.valueOf(2.), 1);
+ assertChoiceScore(scores.get(2), CHOICE_C, null, 2);
}
@Test
@@ -239,11 +239,11 @@
Assert.assertNotNull(scores);
Assert.assertEquals(3, scores.size());
- assertChoiceScoreEquals(BigDecimal.valueOf(3.),
+ assertChoiceScoreEquals(BigDecimal.valueOf(3.), 0,
Sets.newHashSet(scores.get(0),
scores.get(1)),
CHOICE_A, CHOICE_B);
- assertChoiceScore(scores.get(2), CHOICE_C, null);
+ assertChoiceScore(scores.get(2), CHOICE_C, null, 1);
}
@Test
@@ -276,11 +276,11 @@
Assert.assertNotNull(scores);
Assert.assertEquals(3, scores.size());
- assertChoiceScoreEquals(BigDecimal.valueOf(2.),
+ assertChoiceScoreEquals(BigDecimal.valueOf(2.), 0,
Sets.newHashSet(scores.get(0),
scores.get(1)),
CHOICE_A, CHOICE_B);
- assertChoiceScore(scores.get(2), CHOICE_C, BigDecimal.valueOf(1.));
+ assertChoiceScore(scores.get(2), CHOICE_C, BigDecimal.valueOf(1.), 1);
}
@Test
@@ -313,20 +313,23 @@
Assert.assertNotNull(scores);
Assert.assertEquals(3, scores.size());
- assertChoiceScore(scores.get(0), CHOICE_B, BigDecimal.valueOf(4.));
- assertChoiceScore(scores.get(1), CHOICE_C, BigDecimal.valueOf(3.));
- assertChoiceScore(scores.get(2), CHOICE_A, BigDecimal.valueOf(2.));
+ assertChoiceScore(scores.get(0), CHOICE_B, BigDecimal.valueOf(4.), 0);
+ assertChoiceScore(scores.get(1), CHOICE_C, BigDecimal.valueOf(3.), 1);
+ assertChoiceScore(scores.get(2), CHOICE_A, BigDecimal.valueOf(2.), 2);
}
public static void assertChoiceScore(ChoiceScore choiceScore,
String choiceId,
- BigDecimal choiceResult) {
+ BigDecimal choiceResult,
+ int rank) {
Assert.assertNotNull(choiceScore);
Assert.assertEquals(choiceId, choiceScore.getChoiceId());
Assert.assertEquals(choiceResult, choiceScore.getScoreValue());
+ Assert.assertEquals(rank, choiceScore.getScoreOrder());
}
public static void assertChoiceScoreEquals(BigDecimal choiceResult,
+ int rank,
Set<ChoiceScore> choiceScores,
String... choiceIds) {
@@ -337,7 +340,7 @@
ChoiceScore choiceScore = choicesById.get(choiceId);
Assert.assertNotNull(choiceScore);
- assertChoiceScore(choiceScore, choiceId, choiceResult);
+ assertChoiceScore(choiceScore, choiceId, choiceResult, rank);
}
}
Modified: trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCountingStrategy.java
===================================================================
--- trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCountingStrategy.java 2012-09-29 13:06:12 UTC (rev 3709)
+++ trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCountingStrategy.java 2012-09-29 21:18:12 UTC (rev 3710)
@@ -42,19 +42,21 @@
public VoteCountingResult votecount(Set<Voter> voters) {
// get empty result by choice
- Map<String, ChoiceScore> resultByChoice = votersToResult(voters);
+ Map<String, ChoiceScore> scores = newEmptyChoiceScoreMap(voters);
for (Voter voter : voters) {
+
// add this voter votes to result
- addVoterChoices(voter, resultByChoice);
+ addVoterChoices(voter, scores);
}
- // transform map of result to list of them (and sort them)
- VoteCountingResult result = resultToList(resultByChoice);
+
+ // order scores (using their value) and return result
+ VoteCountingResult result = orderByValues(scores.values());
return result;
}
- public void addVoterChoices(Voter voter,
- Map<String, ChoiceScore> resultByChoice) {
+ protected void addVoterChoices(Voter voter,
+ Map<String, ChoiceScore> scores) {
double voterWeight = voter.getWeight();
@@ -64,7 +66,7 @@
// get score for choice
String choiceId = voteForChoice.getChoiceId();
- ChoiceScore choiceScore = resultByChoice.get(choiceId);
+ ChoiceScore choiceScore = scores.get(choiceId);
// compute score to add
double scoreToAdd = voteValue * voterWeight;
Modified: trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCountingStrategy.java
===================================================================
--- trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCountingStrategy.java 2012-09-29 13:06:12 UTC (rev 3709)
+++ trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCountingStrategy.java 2012-09-29 21:18:12 UTC (rev 3710)
@@ -40,20 +40,23 @@
@Override
public VoteCountingResult votecount(Set<Voter> voters) {
+
// get empty result by choice
- Map<String, ChoiceScore> resultByChoice = votersToResult(voters);
+ Map<String, ChoiceScore> scores = newEmptyChoiceScoreMap(voters);
for (Voter voter : voters) {
+
// add this voter votes to result
- addVoterChoices(voter, resultByChoice);
+ addVoterChoices(voter, scores);
}
- // transform map of result to list of them (and sort them)
- VoteCountingResult result = resultToList(resultByChoice);
+
+ // order scores (using their value) and return result
+ VoteCountingResult result = orderByValues(scores.values());
return result;
}
- public void addVoterChoices(Voter voter,
- Map<String, ChoiceScore> resultByChoice) {
+ protected void addVoterChoices(Voter voter,
+ Map<String, ChoiceScore> scores) {
double voterWeight = voter.getWeight();
@@ -63,7 +66,7 @@
// get score for choice
String choiceId = voteForChoice.getChoiceId();
- ChoiceScore choiceScore = resultByChoice.get(choiceId);
+ ChoiceScore choiceScore = scores.get(choiceId);
// compute score to add
double scoreToAdd = voteValue * voterWeight;
1
0
Sept. 29, 2012
Author: tchemit
Date: 2012-09-29 15:06:12 +0200 (Sat, 29 Sep 2012)
New Revision: 3709
Url: http://chorem.org/repositories/revision/pollen/3709
Log:
refs #590: Refactor votecounting module (clean packages + fix i18n)
Added:
trunk/pollen-votecounting-borda/src/main/resources/i18n/pollen-votecounting-borda_en_GB.properties
trunk/pollen-votecounting-borda/src/main/resources/i18n/pollen-votecounting-borda_fr_FR.properties
trunk/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-condorcet_en_GB.properties
trunk/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-condorcet_fr_FR.properties
trunk/pollen-votecounting-coombs/src/main/resources/i18n/pollen-votecounting-coombs_en_GB.properties
trunk/pollen-votecounting-coombs/src/main/resources/i18n/pollen-votecounting-coombs_fr_FR.properties
trunk/pollen-votecounting-instant-runoff/src/main/resources/i18n/pollen-votecounting-instant-runoff_en_GB.properties
trunk/pollen-votecounting-instant-runoff/src/main/resources/i18n/pollen-votecounting-instant-runoff_fr_FR.properties
trunk/pollen-votecounting-normal/src/main/resources/i18n/pollen-votecounting-normal_en_GB.properties
trunk/pollen-votecounting-normal/src/main/resources/i18n/pollen-votecounting-normal_fr_FR.properties
trunk/pollen-votecounting-number/src/main/resources/i18n/pollen-votecounting-number_en_GB.properties
trunk/pollen-votecounting-number/src/main/resources/i18n/pollen-votecounting-number_fr_FR.properties
trunk/pollen-votecounting-percentage/src/main/resources/i18n/pollen-votecounting-percentage_en_GB.properties
trunk/pollen-votecounting-percentage/src/main/resources/i18n/pollen-votecounting-percentage_fr_FR.properties
Removed:
trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/strategy/
trunk/pollen-votecounting-api/src/test/java/org/chorem/pollen/votecounting/strategy/
trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/strategy/
trunk/pollen-votecounting-borda/src/main/resources/i18n/pollen-votecounting-strategy-borda_en_GB.properties
trunk/pollen-votecounting-borda/src/main/resources/i18n/pollen-votecounting-strategy-borda_fr_FR.properties
trunk/pollen-votecounting-borda/src/test/java/org/chorem/pollen/votecounting/strategy/
trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/strategy/
trunk/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-strategy-condorcet_en_GB.properties
trunk/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-strategy-condorcet_fr_FR.properties
trunk/pollen-votecounting-condorcet/src/test/java/org/chorem/pollen/votecounting/strategy/
trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/strategy/
trunk/pollen-votecounting-coombs/src/main/resources/i18n/pollen-votecounting-strategy-coombs_en_GB.properties
trunk/pollen-votecounting-coombs/src/main/resources/i18n/pollen-votecounting-strategy-coombs_fr_FR.properties
trunk/pollen-votecounting-coombs/src/test/java/org/chorem/pollen/votecounting/strategy/
trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/strategy/
trunk/pollen-votecounting-instant-runoff/src/main/resources/i18n/pollen-votecounting-strategy-instant-runoff_en_GB.properties
trunk/pollen-votecounting-instant-runoff/src/main/resources/i18n/pollen-votecounting-strategy-instant-runoff_fr_FR.properties
trunk/pollen-votecounting-instant-runoff/src/test/java/org/chorem/pollen/votecounting/strategy/
trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/strategy/
trunk/pollen-votecounting-normal/src/main/resources/i18n/pollen-votecounting-strategy-normal_en_GB.properties
trunk/pollen-votecounting-normal/src/main/resources/i18n/pollen-votecounting-strategy-normal_fr_FR.properties
trunk/pollen-votecounting-normal/src/test/java/org/chorem/pollen/votecounting/strategy/
trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/strategy/
trunk/pollen-votecounting-number/src/main/resources/i18n/pollen-votecounting-strategy-number_en_GB.properties
trunk/pollen-votecounting-number/src/main/resources/i18n/pollen-votecounting-strategy-number_fr_FR.properties
trunk/pollen-votecounting-number/src/test/java/org/chorem/pollen/votecounting/strategy/
trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/strategy/
trunk/pollen-votecounting-percentage/src/main/resources/i18n/pollen-votecounting-strategy-percentage_en_GB.properties
trunk/pollen-votecounting-percentage/src/main/resources/i18n/pollen-votecounting-strategy-percentage_fr_FR.properties
trunk/pollen-votecounting-percentage/src/test/java/org/chorem/pollen/votecounting/strategy/
Modified:
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/VoteForPoll.java
trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCounting.java
trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCounting.java
trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCounting.java
trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCounting.java
trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCounting.java
trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCounting.java
trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCounting.java
trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCounting.java
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/VoteForPoll.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/VoteForPoll.java 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/VoteForPoll.java 2012-09-29 13:06:12 UTC (rev 3709)
@@ -117,23 +117,28 @@
voteNumber++;
Integer value = voteToChoice.getVoteValue();
+ String originalValue;
+
if (value == null) {
// check value if same as the one return by request
// otherwise it means there is a conversion error
String[] values = getParameters().get("vote.choiceVoteToChoice[" + voteNumber + "].voteValue");
- String paramValue = values == null || values.length < 1 ? null : values[0];
+ originalValue = values == null || values.length < 1 ? null : values[0];
- if (StringUtils.isNotBlank(paramValue)) {
+ if (StringUtils.isNotBlank(originalValue)) {
// vote value changed
String validMessage =
- _("pollen.error.vote.invalidFormat", voteToChoice.getChoice().getName(), paramValue);
+ _("pollen.error.vote.invalidFormat", voteToChoice.getChoice().getName(), originalValue);
addFieldError("vote.choices", validMessage);
voteValid = false;
break;
}
+ } else {
+ originalValue = String.valueOf(value);
}
+
// check if vote is null ?
boolean voteNull = voteCounting.isVoteValueNull(value);
@@ -154,7 +159,10 @@
// not a valid vote value, mark it and skip other fields validation
String validMessage =
- voteCounting.getVoteValueNotValidMessage(getLocale());
+ voteCounting.getVoteValueNotValidMessage(
+ getLocale(),
+ voteToChoice.getChoice().getName(),
+ originalValue);
addFieldError("vote.choices", validMessage);
voteValid = false;
break;
@@ -183,12 +191,6 @@
@Override
public String execute() throws Exception {
- // REMARQUES :
- // - pas le droit de modif si le pollAccount est rattaché a un userAccount et qu'on est pas loggé ?!?
- // - Ce serait plus simple que l'Admin ne puisse jamais voter, il ne peut que modérer les votes
- //TODO tchemit-2012-08-12 Non l'admin est un user comme les autres,
- //TODO on doit pouvoir gérer tous les cas de manière simple (enfin je crois)
-
Poll poll = getPoll();
Vote vote = getVote();
Modified: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCounting.java
===================================================================
--- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCounting.java 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCounting.java 2012-09-29 13:06:12 UTC (rev 3709)
@@ -85,10 +85,14 @@
/**
* If a vote value is not valid, gets the localized message of the error.
*
- * @param locale the locale used to render the error message
+ * @param locale the locale used to render the error message
+ * @param choiceName name of thechoice
+ * @param voteValue value fo the vote
* @return the localized validation message
*/
- String getVoteValueNotValidMessage(Locale locale);
+ String getVoteValueNotValidMessage(Locale locale,
+ String choiceName,
+ String voteValue);
/**
* Tests if the total values of a vote is valid.
Modified: trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCounting.java 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCounting.java 2012-09-29 13:06:12 UTC (rev 3709)
@@ -32,8 +32,11 @@
}
@Override
- public String getVoteValueNotValidMessage(Locale locale) {
- return l_(locale, "pollen.error.vote.invalidBordaVoteValue");
+ public String getVoteValueNotValidMessage(Locale locale,
+ String choiceName,
+ String voteValue) {
+ return l_(locale, "pollen.error.vote.invalidBordaVoteValue",
+ choiceName, voteValue);
}
@Override
Copied: trunk/pollen-votecounting-borda/src/main/resources/i18n/pollen-votecounting-borda_en_GB.properties (from rev 3708, trunk/pollen-votecounting-borda/src/main/resources/i18n/pollen-votecounting-strategy-borda_en_GB.properties)
===================================================================
--- trunk/pollen-votecounting-borda/src/main/resources/i18n/pollen-votecounting-borda_en_GB.properties (rev 0)
+++ trunk/pollen-votecounting-borda/src/main/resources/i18n/pollen-votecounting-borda_en_GB.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -0,0 +1,3 @@
+pollen.error.vote.invalidBordaVoteValue=The value '%s' of vote for choice %s is not valid, only integer values are authorized.
+pollen.voteCountingType.borda=Borda
+pollen.voteCountingType.borda.help=Rank choices by preference order from 1 to N (1\=favorite). Only the rank is taken into account, not the values. Two choices can have the same value.
Property changes on: trunk/pollen-votecounting-borda/src/main/resources/i18n/pollen-votecounting-borda_en_GB.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-borda/src/main/resources/i18n/pollen-votecounting-borda_fr_FR.properties (from rev 3708, trunk/pollen-votecounting-borda/src/main/resources/i18n/pollen-votecounting-strategy-borda_fr_FR.properties)
===================================================================
--- trunk/pollen-votecounting-borda/src/main/resources/i18n/pollen-votecounting-borda_fr_FR.properties (rev 0)
+++ trunk/pollen-votecounting-borda/src/main/resources/i18n/pollen-votecounting-borda_fr_FR.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -0,0 +1,3 @@
+pollen.error.vote.invalidBordaVoteValue=La valeur du vote '%s' pour le choix %s n'est pas correcte, seul des valeurs entières sont autorisées.
+pollen.voteCountingType.borda=Borda
+pollen.voteCountingType.borda.help=Classer les choix par ordre de préférence de 1 à N (1\=préféré). Seul l'ordre des choix compte, peu importe les valeurs. Deux choix peuvent avoir la même valeur.
Property changes on: trunk/pollen-votecounting-borda/src/main/resources/i18n/pollen-votecounting-borda_fr_FR.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-borda/src/main/resources/i18n/pollen-votecounting-strategy-borda_en_GB.properties
===================================================================
--- trunk/pollen-votecounting-borda/src/main/resources/i18n/pollen-votecounting-strategy-borda_en_GB.properties 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-borda/src/main/resources/i18n/pollen-votecounting-strategy-borda_en_GB.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -1,3 +0,0 @@
-pollen.error.vote.invalidBordaVoteValue=
-pollen.voteCountingType.borda=Borda
-pollen.voteCountingType.borda.help=Rank choices by preference order from 1 to N (1\=favorite). Only the rank is taken into account, not the values. Two choices can have the same value.
Deleted: trunk/pollen-votecounting-borda/src/main/resources/i18n/pollen-votecounting-strategy-borda_fr_FR.properties
===================================================================
--- trunk/pollen-votecounting-borda/src/main/resources/i18n/pollen-votecounting-strategy-borda_fr_FR.properties 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-borda/src/main/resources/i18n/pollen-votecounting-strategy-borda_fr_FR.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -1,3 +0,0 @@
-pollen.error.vote.invalidBordaVoteValue=
-pollen.voteCountingType.borda=Borda
-pollen.voteCountingType.borda.help=Classer les choix par ordre de préférence de 1 à N (1\=préféré). Seul l'ordre des choix compte, peu importe les valeurs. Deux choix peuvent avoir la même valeur.
Modified: trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCounting.java 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCounting.java 2012-09-29 13:06:12 UTC (rev 3709)
@@ -32,8 +32,11 @@
}
@Override
- public String getVoteValueNotValidMessage(Locale locale) {
- return l_(locale, "pollen.error.vote.invalidCondorcetVoteValue");
+ public String getVoteValueNotValidMessage(Locale locale,
+ String choiceName,
+ String voteValue) {
+ return l_(locale, "pollen.error.vote.invalidCondorcetVoteValue",
+ choiceName, voteValue);
}
@Override
Copied: trunk/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-condorcet_en_GB.properties (from rev 3708, trunk/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-strategy-condorcet_en_GB.properties)
===================================================================
--- trunk/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-condorcet_en_GB.properties (rev 0)
+++ trunk/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-condorcet_en_GB.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -0,0 +1,3 @@
+pollen.error.vote.invalidCondorcetVoteValue=The value '%s' of vote for choice %s is not valid, only integer values are authorized.
+pollen.voteCountingType.condorcet=Condorcet
+pollen.voteCountingType.condorcet.help=Rank choices by preference order from 1 to N (1\=favorite). Only the rank is taken into account, not the values. Two choices can have the same value.
Property changes on: trunk/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-condorcet_en_GB.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-condorcet_fr_FR.properties (from rev 3708, trunk/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-strategy-condorcet_fr_FR.properties)
===================================================================
--- trunk/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-condorcet_fr_FR.properties (rev 0)
+++ trunk/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-condorcet_fr_FR.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -0,0 +1,3 @@
+pollen.error.vote.invalidCondorcetVoteValue=La valeur du vote '%s' pour le choix %s n'est pas correcte, seul des valeurs entières sont autorisées.
+pollen.voteCountingType.condorcet=Condorcet
+pollen.voteCountingType.condorcet.help=Classer les choix par ordre de préférence de 1 à N (1\=préféré). Seul l'ordre des choix compte, peu importe les valeurs. Deux choix peuvent avoir la même valeur.
Property changes on: trunk/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-condorcet_fr_FR.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-strategy-condorcet_en_GB.properties
===================================================================
--- trunk/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-strategy-condorcet_en_GB.properties 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-strategy-condorcet_en_GB.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -1,3 +0,0 @@
-pollen.error.vote.invalidCondorcetVoteValue=
-pollen.voteCountingType.condorcet=Condorcet
-pollen.voteCountingType.condorcet.help=Rank choices by preference order from 1 to N (1\=favorite). Only the rank is taken into account, not the values. Two choices can have the same value.
Deleted: trunk/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-strategy-condorcet_fr_FR.properties
===================================================================
--- trunk/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-strategy-condorcet_fr_FR.properties 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-condorcet/src/main/resources/i18n/pollen-votecounting-strategy-condorcet_fr_FR.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -1,3 +0,0 @@
-pollen.error.vote.invalidCondorcetVoteValue=
-pollen.voteCountingType.condorcet=Condorcet
-pollen.voteCountingType.condorcet.help=Classer les choix par ordre de préférence de 1 à N (1\=préféré). Seul l'ordre des choix compte, peu importe les valeurs. Deux choix peuvent avoir la même valeur.
Modified: trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCounting.java 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCounting.java 2012-09-29 13:06:12 UTC (rev 3709)
@@ -32,8 +32,12 @@
}
@Override
- public String getVoteValueNotValidMessage(Locale locale) {
- return l_(locale, "pollen.error.vote.invalidCoombsVoteValue");
+ public String getVoteValueNotValidMessage(Locale locale,
+ String choiceName,
+ String voteValue) {
+ return l_(locale, "pollen.error.vote.invalidCoombsVoteValue",
+ choiceName,
+ voteValue);
}
@Override
Copied: trunk/pollen-votecounting-coombs/src/main/resources/i18n/pollen-votecounting-coombs_en_GB.properties (from rev 3708, trunk/pollen-votecounting-coombs/src/main/resources/i18n/pollen-votecounting-strategy-coombs_en_GB.properties)
===================================================================
--- trunk/pollen-votecounting-coombs/src/main/resources/i18n/pollen-votecounting-coombs_en_GB.properties (rev 0)
+++ trunk/pollen-votecounting-coombs/src/main/resources/i18n/pollen-votecounting-coombs_en_GB.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -0,0 +1,3 @@
+pollen.error.vote.invalidCoombsVoteValue=The value '%s' of vote for choice %s is not valid, only integer values are authorized.
+pollen.voteCountingType.coombs=Coombs
+pollen.voteCountingType.coombs.help=Rank choices by preference order from 1 to N (1\=favorite). Only the rank is taken into account, not the values. Two choices can have the same value.
Property changes on: trunk/pollen-votecounting-coombs/src/main/resources/i18n/pollen-votecounting-coombs_en_GB.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-coombs/src/main/resources/i18n/pollen-votecounting-coombs_fr_FR.properties (from rev 3708, trunk/pollen-votecounting-coombs/src/main/resources/i18n/pollen-votecounting-strategy-coombs_fr_FR.properties)
===================================================================
--- trunk/pollen-votecounting-coombs/src/main/resources/i18n/pollen-votecounting-coombs_fr_FR.properties (rev 0)
+++ trunk/pollen-votecounting-coombs/src/main/resources/i18n/pollen-votecounting-coombs_fr_FR.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -0,0 +1,3 @@
+pollen.error.vote.invalidCoombsVoteValue=La valeur du vote '%s' pour le choix %s n'est pas correcte, seul des valeurs entières sont autorisées.
+pollen.voteCountingType.coombs=Coombs
+pollen.voteCountingType.coombs.help=Classer les choix par ordre de préférence de 1 à N (1\=préféré). Seul l'ordre des choix compte, peu importe les valeurs. Deux choix peuvent avoir la même valeur.
Property changes on: trunk/pollen-votecounting-coombs/src/main/resources/i18n/pollen-votecounting-coombs_fr_FR.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-coombs/src/main/resources/i18n/pollen-votecounting-strategy-coombs_en_GB.properties
===================================================================
--- trunk/pollen-votecounting-coombs/src/main/resources/i18n/pollen-votecounting-strategy-coombs_en_GB.properties 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-coombs/src/main/resources/i18n/pollen-votecounting-strategy-coombs_en_GB.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -1,3 +0,0 @@
-pollen.error.vote.invalidCoombsVoteValue=
-pollen.voteCountingType.coombs=Coombs
-pollen.voteCountingType.coombs.help=Rank choices by preference order from 1 to N (1\=favorite). Only the rank is taken into account, not the values. Two choices can have the same value.
Deleted: trunk/pollen-votecounting-coombs/src/main/resources/i18n/pollen-votecounting-strategy-coombs_fr_FR.properties
===================================================================
--- trunk/pollen-votecounting-coombs/src/main/resources/i18n/pollen-votecounting-strategy-coombs_fr_FR.properties 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-coombs/src/main/resources/i18n/pollen-votecounting-strategy-coombs_fr_FR.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -1,3 +0,0 @@
-pollen.error.vote.invalidCoombsVoteValue=
-pollen.voteCountingType.coombs=Coombs
-pollen.voteCountingType.coombs.help=Classer les choix par ordre de préférence de 1 à N (1\=préféré). Seul l'ordre des choix compte, peu importe les valeurs. Deux choix peuvent avoir la même valeur.
Modified: trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCounting.java 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCounting.java 2012-09-29 13:06:12 UTC (rev 3709)
@@ -32,8 +32,12 @@
}
@Override
- public String getVoteValueNotValidMessage(Locale locale) {
- return l_(locale, "pollen.error.vote.invalidInstantRunoffVoteValue");
+ public String getVoteValueNotValidMessage(Locale locale,
+ String choiceName,
+ String voteValue) {
+ return l_(locale, "pollen.error.vote.invalidInstantRunoffVoteValue",
+ choiceName,
+ voteValue);
}
@Override
Copied: trunk/pollen-votecounting-instant-runoff/src/main/resources/i18n/pollen-votecounting-instant-runoff_en_GB.properties (from rev 3708, trunk/pollen-votecounting-instant-runoff/src/main/resources/i18n/pollen-votecounting-strategy-instant-runoff_en_GB.properties)
===================================================================
--- trunk/pollen-votecounting-instant-runoff/src/main/resources/i18n/pollen-votecounting-instant-runoff_en_GB.properties (rev 0)
+++ trunk/pollen-votecounting-instant-runoff/src/main/resources/i18n/pollen-votecounting-instant-runoff_en_GB.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -0,0 +1,3 @@
+pollen.error.vote.invalidInstantRunoffVoteValue=The value '%s' of vote for choice %s is not valid, only integer values are authorized.
+pollen.voteCountingType.instantRunoff=Instant Runoff
+pollen.voteCountingType.instantRunoff.help=Rank choices by preference order from 1 to N (1\=favorite). Only the rank is taken into account, not the values. Two choices can have the same value.
Property changes on: trunk/pollen-votecounting-instant-runoff/src/main/resources/i18n/pollen-votecounting-instant-runoff_en_GB.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-instant-runoff/src/main/resources/i18n/pollen-votecounting-instant-runoff_fr_FR.properties (from rev 3708, trunk/pollen-votecounting-instant-runoff/src/main/resources/i18n/pollen-votecounting-strategy-instant-runoff_fr_FR.properties)
===================================================================
--- trunk/pollen-votecounting-instant-runoff/src/main/resources/i18n/pollen-votecounting-instant-runoff_fr_FR.properties (rev 0)
+++ trunk/pollen-votecounting-instant-runoff/src/main/resources/i18n/pollen-votecounting-instant-runoff_fr_FR.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -0,0 +1,3 @@
+pollen.error.vote.invalidInstantRunoffVoteValue=La valeur du vote '%s' pour le choix %s n'est pas correcte, seul des valeurs entières sont autorisées.
+pollen.voteCountingType.instantRunoff=Vote alternatif
+pollen.voteCountingType.instantRunoff.help=Classer les choix par ordre de préférence de 1 à N (1\=préféré). Seul l'ordre des choix compte, peu importe les valeurs. Deux choix peuvent avoir la même valeur.
Property changes on: trunk/pollen-votecounting-instant-runoff/src/main/resources/i18n/pollen-votecounting-instant-runoff_fr_FR.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-instant-runoff/src/main/resources/i18n/pollen-votecounting-strategy-instant-runoff_en_GB.properties
===================================================================
--- trunk/pollen-votecounting-instant-runoff/src/main/resources/i18n/pollen-votecounting-strategy-instant-runoff_en_GB.properties 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-instant-runoff/src/main/resources/i18n/pollen-votecounting-strategy-instant-runoff_en_GB.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -1,3 +0,0 @@
-pollen.error.vote.invalidInstantRunoffVoteValue=
-pollen.voteCountingType.instantRunoff=Instant Runoff
-pollen.voteCountingType.instantRunoff.help=Rank choices by preference order from 1 to N (1\=favorite). Only the rank is taken into account, not the values. Two choices can have the same value.
Deleted: trunk/pollen-votecounting-instant-runoff/src/main/resources/i18n/pollen-votecounting-strategy-instant-runoff_fr_FR.properties
===================================================================
--- trunk/pollen-votecounting-instant-runoff/src/main/resources/i18n/pollen-votecounting-strategy-instant-runoff_fr_FR.properties 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-instant-runoff/src/main/resources/i18n/pollen-votecounting-strategy-instant-runoff_fr_FR.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -1,3 +0,0 @@
-pollen.error.vote.invalidInstantRunoffVoteValue=
-pollen.voteCountingType.instantRunoff=Vote alternatif
-pollen.voteCountingType.instantRunoff.help=Classer les choix par ordre de préférence de 1 à N (1\=préféré). Seul l'ordre des choix compte, peu importe les valeurs. Deux choix peuvent avoir la même valeur.
Modified: trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCounting.java 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCounting.java 2012-09-29 13:06:12 UTC (rev 3709)
@@ -57,7 +57,9 @@
}
@Override
- public String getVoteValueNotValidMessage(Locale locale) {
+ public String getVoteValueNotValidMessage(Locale locale,
+ String choiceName,
+ String voteValue) {
// no validation on not null vote value, so no message
return null;
}
Copied: trunk/pollen-votecounting-normal/src/main/resources/i18n/pollen-votecounting-normal_en_GB.properties (from rev 3708, trunk/pollen-votecounting-normal/src/main/resources/i18n/pollen-votecounting-strategy-normal_en_GB.properties)
===================================================================
--- trunk/pollen-votecounting-normal/src/main/resources/i18n/pollen-votecounting-normal_en_GB.properties (rev 0)
+++ trunk/pollen-votecounting-normal/src/main/resources/i18n/pollen-votecounting-normal_en_GB.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -0,0 +1,2 @@
+pollen.voteCountingType.normal=Normal
+pollen.voteCountingType.normal.help=Vote for your favorite choice.
Property changes on: trunk/pollen-votecounting-normal/src/main/resources/i18n/pollen-votecounting-normal_en_GB.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-normal/src/main/resources/i18n/pollen-votecounting-normal_fr_FR.properties (from rev 3708, trunk/pollen-votecounting-normal/src/main/resources/i18n/pollen-votecounting-strategy-normal_fr_FR.properties)
===================================================================
--- trunk/pollen-votecounting-normal/src/main/resources/i18n/pollen-votecounting-normal_fr_FR.properties (rev 0)
+++ trunk/pollen-votecounting-normal/src/main/resources/i18n/pollen-votecounting-normal_fr_FR.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -0,0 +1,2 @@
+pollen.voteCountingType.normal=Normal
+pollen.voteCountingType.normal.help=Voter pour le ou les choix préférés.
Property changes on: trunk/pollen-votecounting-normal/src/main/resources/i18n/pollen-votecounting-normal_fr_FR.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-normal/src/main/resources/i18n/pollen-votecounting-strategy-normal_en_GB.properties
===================================================================
--- trunk/pollen-votecounting-normal/src/main/resources/i18n/pollen-votecounting-strategy-normal_en_GB.properties 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-normal/src/main/resources/i18n/pollen-votecounting-strategy-normal_en_GB.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -1,2 +0,0 @@
-pollen.voteCountingType.normal=Normal
-pollen.voteCountingType.normal.help=Vote for your favorite choice.
Deleted: trunk/pollen-votecounting-normal/src/main/resources/i18n/pollen-votecounting-strategy-normal_fr_FR.properties
===================================================================
--- trunk/pollen-votecounting-normal/src/main/resources/i18n/pollen-votecounting-strategy-normal_fr_FR.properties 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-normal/src/main/resources/i18n/pollen-votecounting-strategy-normal_fr_FR.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -1,2 +0,0 @@
-pollen.voteCountingType.normal=Normal
-pollen.voteCountingType.normal.help=Voter pour le ou les choix préférés.
Modified: trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCounting.java 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCounting.java 2012-09-29 13:06:12 UTC (rev 3709)
@@ -63,7 +63,9 @@
}
@Override
- public String getVoteValueNotValidMessage(Locale locale) {
+ public String getVoteValueNotValidMessage(Locale locale,
+ String choiceName,
+ String voteValue) {
// no validation on not null vote value, so no message
return null;
}
Copied: trunk/pollen-votecounting-number/src/main/resources/i18n/pollen-votecounting-number_en_GB.properties (from rev 3708, trunk/pollen-votecounting-number/src/main/resources/i18n/pollen-votecounting-strategy-number_en_GB.properties)
===================================================================
--- trunk/pollen-votecounting-number/src/main/resources/i18n/pollen-votecounting-number_en_GB.properties (rev 0)
+++ trunk/pollen-votecounting-number/src/main/resources/i18n/pollen-votecounting-number_en_GB.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -0,0 +1,2 @@
+pollen.voteCountingType.number=Number
+pollen.voteCountingType.number.help=The answer is free, leave blank or enter a integer.
Property changes on: trunk/pollen-votecounting-number/src/main/resources/i18n/pollen-votecounting-number_en_GB.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-number/src/main/resources/i18n/pollen-votecounting-number_fr_FR.properties (from rev 3708, trunk/pollen-votecounting-number/src/main/resources/i18n/pollen-votecounting-strategy-number_fr_FR.properties)
===================================================================
--- trunk/pollen-votecounting-number/src/main/resources/i18n/pollen-votecounting-number_fr_FR.properties (rev 0)
+++ trunk/pollen-votecounting-number/src/main/resources/i18n/pollen-votecounting-number_fr_FR.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -0,0 +1,2 @@
+pollen.voteCountingType.number=Nombre
+pollen.voteCountingType.number.help=La réponse est libre, laissez vide ou entrez un nombre entier
Property changes on: trunk/pollen-votecounting-number/src/main/resources/i18n/pollen-votecounting-number_fr_FR.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-number/src/main/resources/i18n/pollen-votecounting-strategy-number_en_GB.properties
===================================================================
--- trunk/pollen-votecounting-number/src/main/resources/i18n/pollen-votecounting-strategy-number_en_GB.properties 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-number/src/main/resources/i18n/pollen-votecounting-strategy-number_en_GB.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -1,2 +0,0 @@
-pollen.voteCountingType.number=Number
-pollen.voteCountingType.number.help=The answer is free, leave blank or enter a integer.
Deleted: trunk/pollen-votecounting-number/src/main/resources/i18n/pollen-votecounting-strategy-number_fr_FR.properties
===================================================================
--- trunk/pollen-votecounting-number/src/main/resources/i18n/pollen-votecounting-strategy-number_fr_FR.properties 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-number/src/main/resources/i18n/pollen-votecounting-strategy-number_fr_FR.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -1,2 +0,0 @@
-pollen.voteCountingType.number=Nombre
-pollen.voteCountingType.number.help=La réponse est libre, laissez vide ou entrez un nombre entier
Modified: trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCounting.java 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCounting.java 2012-09-29 13:06:12 UTC (rev 3709)
@@ -58,7 +58,9 @@
}
@Override
- public String getVoteValueNotValidMessage(Locale locale) {
+ public String getVoteValueNotValidMessage(Locale locale,
+ String choiceName,
+ String voteValue) {
// no validation on not null vote value, so no message
return null;
}
Copied: trunk/pollen-votecounting-percentage/src/main/resources/i18n/pollen-votecounting-percentage_en_GB.properties (from rev 3708, trunk/pollen-votecounting-percentage/src/main/resources/i18n/pollen-votecounting-strategy-percentage_en_GB.properties)
===================================================================
--- trunk/pollen-votecounting-percentage/src/main/resources/i18n/pollen-votecounting-percentage_en_GB.properties (rev 0)
+++ trunk/pollen-votecounting-percentage/src/main/resources/i18n/pollen-votecounting-percentage_en_GB.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -0,0 +1,3 @@
+pollen.error.vote.percentage=
+pollen.voteCountingType.percentage=Percentage
+pollen.voteCountingType.percentage.help=Allocate choices to get a 100%% total.
Property changes on: trunk/pollen-votecounting-percentage/src/main/resources/i18n/pollen-votecounting-percentage_en_GB.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-percentage/src/main/resources/i18n/pollen-votecounting-percentage_fr_FR.properties (from rev 3708, trunk/pollen-votecounting-percentage/src/main/resources/i18n/pollen-votecounting-strategy-percentage_fr_FR.properties)
===================================================================
--- trunk/pollen-votecounting-percentage/src/main/resources/i18n/pollen-votecounting-percentage_fr_FR.properties (rev 0)
+++ trunk/pollen-votecounting-percentage/src/main/resources/i18n/pollen-votecounting-percentage_fr_FR.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -0,0 +1,3 @@
+pollen.error.vote.percentage=
+pollen.voteCountingType.percentage=Pourcentage
+pollen.voteCountingType.percentage.help=Répartir les choix de manière à obtenir 100%% au total.
Property changes on: trunk/pollen-votecounting-percentage/src/main/resources/i18n/pollen-votecounting-percentage_fr_FR.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-percentage/src/main/resources/i18n/pollen-votecounting-strategy-percentage_en_GB.properties
===================================================================
--- trunk/pollen-votecounting-percentage/src/main/resources/i18n/pollen-votecounting-strategy-percentage_en_GB.properties 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-percentage/src/main/resources/i18n/pollen-votecounting-strategy-percentage_en_GB.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -1,3 +0,0 @@
-pollen.error.vote.percentage=
-pollen.voteCountingType.percentage=Percentage
-pollen.voteCountingType.percentage.help=Allocate choices to get a 100%% total.
Deleted: trunk/pollen-votecounting-percentage/src/main/resources/i18n/pollen-votecounting-strategy-percentage_fr_FR.properties
===================================================================
--- trunk/pollen-votecounting-percentage/src/main/resources/i18n/pollen-votecounting-strategy-percentage_fr_FR.properties 2012-09-29 12:36:25 UTC (rev 3708)
+++ trunk/pollen-votecounting-percentage/src/main/resources/i18n/pollen-votecounting-strategy-percentage_fr_FR.properties 2012-09-29 13:06:12 UTC (rev 3709)
@@ -1,3 +0,0 @@
-pollen.error.vote.percentage=
-pollen.voteCountingType.percentage=Pourcentage
-pollen.voteCountingType.percentage.help=Répartir les choix de manière à obtenir 100%% au total.
1
0
Sept. 29, 2012
Author: tchemit
Date: 2012-09-29 14:36:25 +0200 (Sat, 29 Sep 2012)
New Revision: 3708
Url: http://chorem.org/repositories/revision/pollen/3708
Log:
refs #590: Refactor votecounting module (improve voteCounting api : distinguish voteCounting and his voteCoutning strategy)
Added:
trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/votecounting/
trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/votecounting/strategy/
trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingFactoryTest.java
trunk/pollen-ui-struts2/src/test/resources/log4j.properties
trunk/pollen-votecounting-aggregator/
trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCounting.java
trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCountingStrategy.java
trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCounting.java
trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCountingFactory.java
trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCountingNotFound.java
trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCountingStrategy.java
trunk/pollen-votecounting-api/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java
trunk/pollen-votecounting-borda/
trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCounting.java
trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCountingStrategy.java
trunk/pollen-votecounting-borda/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting
trunk/pollen-votecounting-borda/src/test/java/org/chorem/pollen/votecounting/BordaVoteCountingStrategyTest.java
trunk/pollen-votecounting-borda/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java
trunk/pollen-votecounting-condorcet/
trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCounting.java
trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCountingStrategy.java
trunk/pollen-votecounting-condorcet/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting
trunk/pollen-votecounting-condorcet/src/test/java/org/chorem/pollen/votecounting/CondorcetVoteCountingStrategyTest.java
trunk/pollen-votecounting-condorcet/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java
trunk/pollen-votecounting-coombs/
trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCounting.java
trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCountingStrategy.java
trunk/pollen-votecounting-coombs/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting
trunk/pollen-votecounting-coombs/src/test/java/org/chorem/pollen/votecounting/CoombsVoteCountingStrategyTest.java
trunk/pollen-votecounting-coombs/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java
trunk/pollen-votecounting-instant-runoff/
trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCounting.java
trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCountingStrategy.java
trunk/pollen-votecounting-instant-runoff/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting
trunk/pollen-votecounting-instant-runoff/src/test/java/org/chorem/pollen/votecounting/InstantRunoffVoteCountingStrategyTest.java
trunk/pollen-votecounting-instant-runoff/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java
trunk/pollen-votecounting-normal/
trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCounting.java
trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCountingStrategy.java
trunk/pollen-votecounting-normal/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting
trunk/pollen-votecounting-normal/src/test/java/org/chorem/pollen/votecounting/NormalVoteCountingStrategyTest.java
trunk/pollen-votecounting-normal/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java
trunk/pollen-votecounting-number/
trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCounting.java
trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCountingStrategy.java
trunk/pollen-votecounting-number/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting
trunk/pollen-votecounting-number/src/test/java/org/chorem/pollen/votecounting/NumberVoteCountingStrategyTest.java
trunk/pollen-votecounting-number/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java
trunk/pollen-votecounting-percentage/
trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCounting.java
trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCountingStrategy.java
trunk/pollen-votecounting-percentage/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting
trunk/pollen-votecounting-percentage/src/test/java/org/chorem/pollen/votecounting/PercentageVoteCountingStrategyTest.java
trunk/pollen-votecounting-percentage/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java
Removed:
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/VoteCountigStrategyNotFound.java
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/VoteCountingStrategyProvider.java
trunk/pollen-votecounting-api/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java
trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/strategy/BordaStrategy.java
trunk/pollen-votecounting-borda/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy
trunk/pollen-votecounting-borda/src/test/java/org/chorem/pollen/votecounting/strategy/BordaStrategyTest.java
trunk/pollen-votecounting-borda/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java
trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/strategy/CondorcetStrategy.java
trunk/pollen-votecounting-condorcet/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy
trunk/pollen-votecounting-condorcet/src/test/java/org/chorem/pollen/votecounting/strategy/CondorcetStrategyTest.java
trunk/pollen-votecounting-condorcet/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java
trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/strategy/CoombsStrategy.java
trunk/pollen-votecounting-coombs/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy
trunk/pollen-votecounting-coombs/src/test/java/org/chorem/pollen/votecounting/strategy/CoombsStrategyTest.java
trunk/pollen-votecounting-coombs/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java
trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/strategy/InstantRunoffStrategy.java
trunk/pollen-votecounting-instant-runoff/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy
trunk/pollen-votecounting-instant-runoff/src/test/java/org/chorem/pollen/votecounting/strategy/InstantRunoffStrategyTest.java
trunk/pollen-votecounting-instant-runoff/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java
trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/strategy/NormalStrategy.java
trunk/pollen-votecounting-normal/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy
trunk/pollen-votecounting-normal/src/test/java/org/chorem/pollen/votecounting/strategy/NormalStrategyTest.java
trunk/pollen-votecounting-normal/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java
trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/strategy/NumberStrategy.java
trunk/pollen-votecounting-number/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy
trunk/pollen-votecounting-number/src/test/java/org/chorem/pollen/votecounting/strategy/NumberStrategyTest.java
trunk/pollen-votecounting-number/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java
trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/strategy/PercentageStrategy.java
trunk/pollen-votecounting-percentage/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy
trunk/pollen-votecounting-percentage/src/test/java/org/chorem/pollen/votecounting/strategy/PercentageStrategyTest.java
trunk/pollen-votecounting-percentage/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java
trunk/pollen-votecounting-strategy-borda/
trunk/pollen-votecounting-strategy-condorcet/
trunk/pollen-votecounting-strategy-coombs/
trunk/pollen-votecounting-strategy-instant-runoff/
trunk/pollen-votecounting-strategy-normal/
trunk/pollen-votecounting-strategy-number/
trunk/pollen-votecounting-strategy-percentage/
trunk/pollen-votecounting-strategy/
trunk/pollen-votecounting/
Modified:
trunk/pollen-persistence/pom.xml
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/Polls.java
trunk/pollen-services/pom.xml
trunk/pollen-services/src/main/java/org/chorem/pollen/PollenApplicationContext.java
trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4.java
trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_5.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollVoteCountingService.java
trunk/pollen-services/src/test/java/org/chorem/pollen/services/FakeServiceContext.java
trunk/pollen-ui-struts2/pom.xml
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java
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/VoteForPoll.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AbstractPollenAuthorization.java
trunk/pollen-votecounting-aggregator/pom.xml
trunk/pollen-votecounting-api/pom.xml
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/GroupVoteCountingResult.java
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/VoteCountingResult.java
trunk/pollen-votecounting-borda/pom.xml
trunk/pollen-votecounting-condorcet/pom.xml
trunk/pollen-votecounting-coombs/pom.xml
trunk/pollen-votecounting-instant-runoff/pom.xml
trunk/pollen-votecounting-normal/pom.xml
trunk/pollen-votecounting-number/pom.xml
trunk/pollen-votecounting-percentage/pom.xml
trunk/pom.xml
Modified: trunk/pollen-persistence/pom.xml
===================================================================
--- trunk/pollen-persistence/pom.xml 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-persistence/pom.xml 2012-09-29 12:36:25 UTC (rev 3708)
@@ -15,6 +15,8 @@
<groupId>org.chorem.pollen</groupId>
<artifactId>pollen-persistence</artifactId>
+ <name>Pollen :: Persistence</name>
+ <description>Pollen Persistence Layer</description>
<dependencies>
@@ -73,24 +75,13 @@
</dependency>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
</dependency>
+
</dependencies>
- <!-- ************************************************************* -->
- <!-- *** Project Information ************************************* -->
- <!-- ************************************************************* -->
-
- <name>Pollen :: Persistence</name>
- <description>Pollen Persistence Layer</description>
-
- <properties>
- <!-- no site generation -->
- <maven.site.skip>true</maven.site.skip>
- <maven.site.deploy.skip>true</maven.site.deploy.skip>
- </properties>
-
<build>
<plugins>
Modified: 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 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/Polls.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -31,8 +31,8 @@
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 org.chorem.pollen.votecounting.VoteCounting;
+import org.chorem.pollen.votecounting.VoteCountingFactory;
import java.util.Map;
import java.util.Set;
@@ -121,13 +121,13 @@
return result;
}
- public static VoteCountingStrategy getVoteCountingStrategy(VoteCountingStrategyProvider provider, Poll poll) {
- Preconditions.checkNotNull(provider);
+ public static VoteCounting getVoteCounting(VoteCountingFactory factory, Poll poll) {
+ Preconditions.checkNotNull(factory);
Preconditions.checkNotNull(poll);
- int strategyId = poll.getVoteCountingType();
- VoteCountingStrategy result = provider.getStrategy(strategyId);
+ int id = poll.getVoteCountingType();
+ VoteCounting result = factory.getVoteCounting(id);
Preconditions.checkNotNull(
- result, "Could not find strategry for id " + strategyId);
+ result, "Could not find vote counting for id " + id);
return result;
}
Modified: trunk/pollen-services/pom.xml
===================================================================
--- trunk/pollen-services/pom.xml 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-services/pom.xml 2012-09-29 12:36:25 UTC (rev 3708)
@@ -5,10 +5,6 @@
<modelVersion>4.0.0</modelVersion>
- <!-- ************************************************************* -->
- <!-- *** POM Relationships *************************************** -->
- <!-- ************************************************************* -->
-
<parent>
<groupId>org.chorem</groupId>
<artifactId>pollen</artifactId>
@@ -17,6 +13,8 @@
<groupId>org.chorem.pollen</groupId>
<artifactId>pollen-services</artifactId>
+ <name>Pollen :: Services</name>
+ <description>Pollen Service Layer</description>
<dependencies>
@@ -94,30 +92,26 @@
<groupId>org.nuiton.topia</groupId>
<artifactId>topia-service-migration</artifactId>
</dependency>
+
<dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
+
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
</dependency>
+
</dependencies>
- <!-- ************************************************************* -->
- <!-- *** Project Information ************************************* -->
- <!-- ************************************************************* -->
-
- <name>Pollen :: Services</name>
- <description>Pollen Service Layer</description>
-
- <properties>
- <!-- no site generation -->
- <maven.site.skip>true</maven.site.skip>
- <maven.site.deploy.skip>true</maven.site.deploy.skip>
- </properties>
-
<build>
<plugins>
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/PollenApplicationContext.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/PollenApplicationContext.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/PollenApplicationContext.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -24,7 +24,7 @@
import com.opensymphony.xwork2.ActionContext;
import org.chorem.pollen.services.PollenNotifierWorker;
-import org.chorem.pollen.votecounting.strategy.VoteCountingStrategyProvider;
+import org.chorem.pollen.votecounting.VoteCountingFactory;
import org.nuiton.topia.TopiaContext;
import javax.servlet.ServletContext;
@@ -46,7 +46,7 @@
protected PollenNotifierWorker pollenNotifierWorker;
- protected VoteCountingStrategyProvider voteCountingStrategyProvider;
+ protected VoteCountingFactory voteCountingFactory;
public static PollenApplicationContext get(ActionContext actionContext) {
Map<String, Object> application = actionContext.getApplication();
@@ -102,11 +102,11 @@
this.pollenNotifierWorker = pollenNotifierWorker;
}
- public VoteCountingStrategyProvider getVoteCountingStrategyProvider() {
- return voteCountingStrategyProvider;
+ public VoteCountingFactory getVoteCountingFactory() {
+ return voteCountingFactory;
}
- public void setVoteCountingStrategyProvider(VoteCountingStrategyProvider voteCountingStrategyProvider) {
- this.voteCountingStrategyProvider = voteCountingStrategyProvider;
+ public void setVoteCountingFactory(VoteCountingFactory voteCountingFactory) {
+ this.voteCountingFactory = voteCountingFactory;
}
}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -140,7 +140,7 @@
tx,
configuration,
serviceFactory,
- applicationContext.getVoteCountingStrategyProvider()
+ applicationContext.getVoteCountingFactory()
);
List<Pair<String, String>> choiceIds =
@@ -215,7 +215,7 @@
tx,
configuration,
serviceFactory,
- applicationContext.getVoteCountingStrategyProvider()
+ applicationContext.getVoteCountingFactory()
);
PollFeedService feedService = sContext.newService(PollFeedService.class);
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_5.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_5.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_5.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -88,7 +88,7 @@
tx,
applicationContext.getConfiguration(),
new PollenServiceFactory(),
- applicationContext.getVoteCountingStrategyProvider()
+ applicationContext.getVoteCountingFactory()
);
// clean pollAccount for votes
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -24,7 +24,7 @@
import com.google.common.base.Preconditions;
import org.chorem.pollen.PollenConfiguration;
-import org.chorem.pollen.votecounting.strategy.VoteCountingStrategyProvider;
+import org.chorem.pollen.votecounting.VoteCountingFactory;
import org.nuiton.topia.TopiaContext;
import java.net.URL;
@@ -48,7 +48,7 @@
protected Locale locale;
- protected VoteCountingStrategyProvider voteCountingStrategyProvider;
+ protected VoteCountingFactory voteCountingFactory;
public static PollenServiceContext newContext(
PollenServiceContext serviceContext,
@@ -57,7 +57,7 @@
transaction,
serviceContext.getConfiguration(),
serviceContext.getServiceFactory(),
- serviceContext.getVoteCountingStrategyProvider()
+ serviceContext.getVoteCountingFactory()
);
}
@@ -67,12 +67,12 @@
TopiaContext transaction,
PollenConfiguration configuration,
PollenServiceFactory serviceFactory,
- VoteCountingStrategyProvider voteCountingStrategyProvider) {
+ VoteCountingFactory voteCountingFactory) {
return new DefaultPollenServiceContext(locale,
transaction,
configuration,
serviceFactory,
- voteCountingStrategyProvider);
+ voteCountingFactory);
}
protected DefaultPollenServiceContext(
@@ -80,12 +80,12 @@
TopiaContext transaction,
PollenConfiguration configuration,
PollenServiceFactory serviceFactory,
- VoteCountingStrategyProvider voteCountingStrategyProvider) {
+ VoteCountingFactory voteCountingFactory) {
this.locale = locale;
this.transaction = transaction;
this.configuration = configuration;
this.serviceFactory = serviceFactory;
- this.voteCountingStrategyProvider = voteCountingStrategyProvider;
+ this.voteCountingFactory = voteCountingFactory;
}
@Override
@@ -135,8 +135,8 @@
}
@Override
- public VoteCountingStrategyProvider getVoteCountingStrategyProvider() {
- return voteCountingStrategyProvider;
+ public VoteCountingFactory getVoteCountingFactory() {
+ return voteCountingFactory;
}
@Override
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -26,7 +26,7 @@
import org.chorem.pollen.PollenConfiguration;
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.PollAccount;
-import org.chorem.pollen.votecounting.strategy.VoteCountingStrategyProvider;
+import org.chorem.pollen.votecounting.VoteCountingFactory;
import org.nuiton.topia.TopiaContext;
import java.net.URL;
@@ -62,7 +62,7 @@
/** @return the current date */
Date getCurrentTime();
- VoteCountingStrategyProvider getVoteCountingStrategyProvider();
+ VoteCountingFactory getVoteCountingFactory();
/**
* Generates a unique id usable for {@link Poll#getPollId()} or
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-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollVoteCountingService.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -31,7 +31,8 @@
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.strategy.VoteCountingStrategy;
+import org.chorem.pollen.votecounting.VoteCounting;
+import org.chorem.pollen.votecounting.VoteCountingStrategy;
/**
* New Poll vote counting service.
@@ -55,9 +56,10 @@
public VoteCountingResult getSimpleResult(Poll poll) {
Preconditions.checkNotNull(poll);
- VoteCountingStrategy strategy = Polls.getVoteCountingStrategy(
- serviceContext.getVoteCountingStrategyProvider(), poll);
- Preconditions.checkNotNull(strategy);
+ VoteCounting voteCounting = Polls.getVoteCounting(
+ serviceContext.getVoteCountingFactory(), poll);
+ Preconditions.checkNotNull(voteCounting);
+ VoteCountingStrategy strategy = voteCounting.newVoteCountingStrategy();
// create vote counting model
GroupOfVoter group = Polls.toSimpleVotersGroup(poll);
@@ -70,9 +72,11 @@
public GroupVoteCountingResult getGroupResult(Poll poll) {
Preconditions.checkNotNull(poll);
- VoteCountingStrategy strategy = Polls.getVoteCountingStrategy(
- serviceContext.getVoteCountingStrategyProvider(), poll);
- Preconditions.checkNotNull(strategy);
+ Preconditions.checkNotNull(poll);
+ VoteCounting voteCounting = Polls.getVoteCounting(
+ serviceContext.getVoteCountingFactory(), poll);
+ Preconditions.checkNotNull(voteCounting);
+ VoteCountingStrategy strategy = voteCounting.newVoteCountingStrategy();
// Create a groupVoter including of the root voters
GroupOfVoter group = Polls.toGroupOfVoters(poll);
Modified: trunk/pollen-services/src/test/java/org/chorem/pollen/services/FakeServiceContext.java
===================================================================
--- trunk/pollen-services/src/test/java/org/chorem/pollen/services/FakeServiceContext.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-services/src/test/java/org/chorem/pollen/services/FakeServiceContext.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -28,7 +28,7 @@
import org.chorem.pollen.PollenConfiguration;
import org.chorem.pollen.PollenIOUtil;
import org.chorem.pollen.PollenTopiaRootContextFactory;
-import org.chorem.pollen.votecounting.strategy.VoteCountingStrategyProvider;
+import org.chorem.pollen.votecounting.VoteCountingFactory;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.nuiton.topia.TopiaContext;
@@ -130,7 +130,7 @@
}
@Override
- public VoteCountingStrategyProvider getVoteCountingStrategyProvider() {
+ public VoteCountingFactory getVoteCountingFactory() {
return null;
}
Modified: trunk/pollen-ui-struts2/pom.xml
===================================================================
--- trunk/pollen-ui-struts2/pom.xml 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-ui-struts2/pom.xml 2012-09-29 12:36:25 UTC (rev 3708)
@@ -3,10 +3,6 @@
<modelVersion>4.0.0</modelVersion>
- <!-- ************************************************************* -->
- <!-- *** POM Relationships *************************************** -->
- <!-- ************************************************************* -->
-
<parent>
<groupId>org.chorem</groupId>
<artifactId>pollen</artifactId>
@@ -15,7 +11,29 @@
<groupId>org.chorem.pollen</groupId>
<artifactId>pollen-ui-struts2</artifactId>
+ <name>Pollen :: UI (struts2)</name>
+ <description>Interface Graphique Struts2 pour Pollen</description>
+ <packaging>war</packaging>
+
+ <properties>
+ <i18n.silent>true</i18n.silent>
+ <i18n.bundleOutputName>${pollenI18nBundle}</i18n.bundleOutputName>
+
+ <redmine.releaseFiles>
+ target/${project.build.finalName}.war,
+ target/${project.build.finalName}-bin.zip
+ </redmine.releaseFiles>
+
+ <deployFiles>target/${project.build.finalName}.war</deployFiles>
+
+ <defaultWebContextPath>pollen</defaultWebContextPath>
+ <defaultSiteUrl>
+ http://localhost:8080/${defaultWebContextPath}
+ </defaultSiteUrl>
+ <defaultLogDir>${basedir}/target</defaultLogDir>
+ </properties>
+
<dependencies>
<dependency>
@@ -38,7 +56,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>pollen-votecounting-strategy</artifactId>
+ <artifactId>pollen-votecounting-aggregator</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>runtime</scope>
@@ -241,40 +259,14 @@
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
- <!-- ************************************************************* -->
- <!-- *** Project Information ************************************* -->
- <!-- ************************************************************* -->
-
- <name>Pollen :: UI (struts2)</name>
- <description>Interface Graphique Struts2 pour Pollen</description>
-
-
- <!-- ************************************************************* -->
- <!-- *** Build Settings ****************************************** -->
- <!-- ************************************************************* -->
-
- <packaging>war</packaging>
-
- <properties>
- <i18n.silent>true</i18n.silent>
- <i18n.bundleOutputName>${pollenI18nBundle}</i18n.bundleOutputName>
-
- <redmine.releaseFiles>
- target/${project.build.finalName}.war,
- target/${project.build.finalName}-bin.zip
- </redmine.releaseFiles>
-
- <deployFiles>target/${project.build.finalName}.war</deployFiles>
-
- <defaultWebContextPath>pollen</defaultWebContextPath>
- <defaultSiteUrl>
- http://localhost:8080/${defaultWebContextPath}
- </defaultSiteUrl>
- <defaultLogDir>${basedir}/target</defaultLogDir>
- </properties>
-
<build>
<!-- call result war : pollen-xxx.war -->
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -38,7 +38,7 @@
import org.chorem.pollen.services.PollenServiceContext;
import org.chorem.pollen.services.PollenServiceFactory;
import org.chorem.pollen.services.impl.UserService;
-import org.chorem.pollen.votecounting.strategy.VoteCountingStrategyProvider;
+import org.chorem.pollen.votecounting.VoteCountingFactory;
import org.nuiton.i18n.I18n;
import org.nuiton.i18n.init.DefaultI18nInitializer;
import org.nuiton.topia.TopiaContext;
@@ -101,7 +101,7 @@
log.info("Base url " + configuration.getApplicationUrl());
}
applicationContext.setConfiguration(configuration);
- applicationContext.setVoteCountingStrategyProvider(new VoteCountingStrategyProvider());
+ applicationContext.setVoteCountingFactory(new VoteCountingFactory());
File temporaryDirectory = configuration.getTemporaryDirectory();
try {
@@ -202,7 +202,7 @@
null,
applicationContext.getConfiguration(),
new PollenServiceFactory(),
- applicationContext.getVoteCountingStrategyProvider()
+ applicationContext.getVoteCountingFactory()
);
PollenNotifierWorker pollenNotifierWorker = new PollenNotifierWorker(
serviceContext,
@@ -277,7 +277,7 @@
transaction,
configuration,
serviceFactory,
- applicationContext.getVoteCountingStrategyProvider()
+ applicationContext.getVoteCountingFactory()
);
UserService service =
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-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -54,8 +54,8 @@
import org.chorem.pollen.ui.PollenSession;
import org.chorem.pollen.ui.interceptors.PollenSecurityInterceptor;
import org.chorem.pollen.ui.security.AbstractPollenAuthorization;
-import org.chorem.pollen.votecounting.strategy.VoteCountingStrategy;
-import org.chorem.pollen.votecounting.strategy.VoteCountingStrategyProvider;
+import org.chorem.pollen.votecounting.VoteCounting;
+import org.chorem.pollen.votecounting.VoteCountingFactory;
import org.nuiton.topia.TopiaContext;
import org.nuiton.web.filter.TopiaTransactionFilter;
import org.nuiton.web.struts2.BaseAction;
@@ -262,8 +262,8 @@
return result;
}
- public VoteCountingStrategyProvider getVoteCountingStrategyProvider() {
- return getPollenApplicationContext().getVoteCountingStrategyProvider();
+ public VoteCountingFactory getVoteCountingFactory() {
+ return getPollenApplicationContext().getVoteCountingFactory();
}
public TopiaContext getTransaction() {
@@ -458,9 +458,8 @@
return parameters;
}
- protected VoteCountingStrategy getVoteCountingStrategy(Poll poll) {
- return Polls.getVoteCountingStrategy(getVoteCountingStrategyProvider(),
- poll);
+ protected VoteCounting getVoteCounting(Poll poll) {
+ return Polls.getVoteCounting(getVoteCountingFactory(), poll);
}
/**
@@ -476,7 +475,7 @@
getTransaction(),
getConfiguration(),
serviceFactory,
- getVoteCountingStrategyProvider()
+ getVoteCountingFactory()
);
}
return serviceContext;
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-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -47,7 +47,7 @@
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.chorem.pollen.votecounting.VoteCounting;
import org.nuiton.topia.persistence.TopiaId;
import java.net.URL;
@@ -131,14 +131,14 @@
}
public String getVoteCountingTypeName() {
- VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll());
- String result = strategy.getStrategyName(getLocale());
+ VoteCounting voteCounting = getVoteCounting(getPoll());
+ String result = voteCounting.getStrategyName(getLocale());
return result;
}
public String getVoteCountingTypeHelp() {
- VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll());
- String result = strategy.getStrategyHelp(getLocale());
+ VoteCounting voteCounting = getVoteCounting(getPoll());
+ String result = voteCounting.getStrategyHelp(getLocale());
return result;
}
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-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/form/AbstractPollForm.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -46,6 +46,7 @@
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.I18nAble;
import org.chorem.pollen.business.persistence.PersonToList;
import org.chorem.pollen.business.persistence.PersonToListImpl;
import org.chorem.pollen.business.persistence.Poll;
@@ -58,7 +59,6 @@
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.business.persistence.I18nAble;
import org.chorem.pollen.services.PollenServiceFunctions;
import org.chorem.pollen.services.exceptions.PollNotFoundException;
import org.chorem.pollen.services.impl.PollService;
@@ -66,8 +66,8 @@
import org.chorem.pollen.ui.actions.FileUploadAware;
import org.chorem.pollen.ui.actions.PollenActionSupportForEdition;
import org.chorem.pollen.ui.converters.DateConverter;
-import org.chorem.pollen.votecounting.strategy.VoteCountingStrategy;
-import org.chorem.pollen.votecounting.strategy.VoteCountingStrategyProvider;
+import org.chorem.pollen.votecounting.VoteCounting;
+import org.chorem.pollen.votecounting.VoteCountingFactory;
import org.nuiton.util.StringUtil;
import java.io.File;
@@ -714,11 +714,8 @@
public String getVoteCountingHelp() {
StringBuilder builder = new StringBuilder();
- VoteCountingStrategyProvider strategyProvider =
- getVoteCountingStrategyProvider();
- Set<Integer> strategyIds = strategyProvider.getStrategyIds();
- for (Integer strategyId : strategyIds) {
- VoteCountingStrategy strategy = strategyProvider.getStrategy(strategyId);
+ VoteCountingFactory voteCountingFactory = getVoteCountingFactory();
+ for (VoteCounting strategy : voteCountingFactory) {
String strategyHelp = strategy.getStrategyHelp(getLocale());
builder.append(strategyHelp).append("<br/><br/>");
}
@@ -734,15 +731,11 @@
pollVoteVisibilities = decorateToName(PollVoteVisibility.values());
voteCountingTypes = Maps.newTreeMap();
- VoteCountingStrategyProvider strategyProvider =
- getVoteCountingStrategyProvider();
- Set<Integer> strategyIds = strategyProvider.getStrategyIds();
- for (Integer strategyId : strategyIds) {
- VoteCountingStrategy strategy = strategyProvider.getStrategy(strategyId);
+ VoteCountingFactory voteCountingFactory = getVoteCountingFactory();
+ for (VoteCounting strategy : voteCountingFactory) {
String strategyHelp = strategy.getStrategyName(getLocale());
- voteCountingTypes.put(strategyId + "", strategyHelp);
+ voteCountingTypes.put(strategy.getId() + "", strategyHelp);
}
-// decorateToName(VoteCountingType.values());
textChoices = Lists.newArrayList();
imageChoices = Lists.newArrayList();
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-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/AbstractVoteAction.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -36,11 +36,11 @@
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.PollAccount;
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.UserAccount;
import org.chorem.pollen.business.persistence.Vote;
import org.chorem.pollen.business.persistence.VoteToChoice;
-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;
@@ -48,7 +48,7 @@
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.votecounting.strategy.VoteCountingStrategy;
+import org.chorem.pollen.votecounting.VoteCounting;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
@@ -168,14 +168,14 @@
}
public String getVoteCountingTypeName() {
- VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll());
- String result = strategy.getStrategyName(getLocale());
+ VoteCounting voteCounting = getVoteCounting(getPoll());
+ String result = voteCounting.getStrategyName(getLocale());
return result;
}
public String getVoteCountingTypeHelp() {
- VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll());
- String result = strategy.getStrategyHelp(getLocale());
+ VoteCounting voteCounting = getVoteCounting(getPoll());
+ String result = voteCounting.getStrategyHelp(getLocale());
return result;
}
@@ -212,41 +212,15 @@
* @return true si le choix est dans le vote
*/
public boolean isChoiceInVote(VoteToChoice choice) {
- VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll());
- boolean result = strategy.isChoiceInVote(choice.getVoteValue());
+ VoteCounting voteCounting = getVoteCounting(getPoll());
+ boolean result = voteCounting.isChoiceInVote(choice.getVoteValue());
return result;
-// Integer voteValue = choice.getVoteValue();
-// boolean result = false;
-// if (choice != null) {
-// switch (poll.getVoteCountingType()) {
-// case NORMAL:
-// result = voteValue > 0;
-// break;
-// case PERCENTAGE:
-// result = true;
-// break;
-// case CONDORCET:
-// result = voteValue < 100;
-// break;
-// case NUMBER:
-// result = voteValue >= 0;
-// }
-// }
-// return result;
}
public String getChoiceValue(VoteToChoice choice) {
- VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll());
- String result = strategy.getDisplayVoteValue(choice.getVoteValue());
+ VoteCounting voteCounting = getVoteCounting(getPoll());
+ String result = voteCounting.getDisplayVoteValue(choice.getVoteValue());
return result;
-// switch (poll.getVoteCountingType()) {
-// case NORMAL:
-// result = "OK";
-// break;
-// default:
-// result = choice.getVoteValue() + "";
-// }
-// return result;
}
public String getCommentAuthor() {
@@ -408,9 +382,9 @@
}
public String getChoiceFragment() {
- VoteCountingStrategy strategy = getVoteCountingStrategy(poll);
+ VoteCounting voteCounting = getVoteCounting(poll);
String result =
- "displayVote_" + strategy.getVoteValueEditorType().name() + ".jsp";
+ "displayVote_" + voteCounting.getVoteValueEditorType().name() + ".jsp";
return result;
}
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/VoteForPoll.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/VoteForPoll.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/VoteForPoll.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -33,7 +33,7 @@
import org.chorem.pollen.business.persistence.Vote;
import org.chorem.pollen.business.persistence.VoteToChoice;
import org.chorem.pollen.services.impl.VoteService;
-import org.chorem.pollen.votecounting.strategy.VoteCountingStrategy;
+import org.chorem.pollen.votecounting.VoteCounting;
import static org.nuiton.i18n.I18n.n_;
@@ -99,7 +99,7 @@
}
// check if the votingId is available
- if (!getVoteService().isVotingIdFree(poll, pollAccount.getTopiaId(),name)) {
+ if (!getVoteService().isVotingIdFree(poll, pollAccount.getTopiaId(), name)) {
addFieldError("pollAccount.votingId",
_("pollen.error.user.alreadyVoted", name));
}
@@ -108,7 +108,7 @@
int nbVotes = 0;
int totalValues = 0;
- VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll());
+ VoteCounting voteCounting = getVoteCounting(getPoll());
boolean voteValid = true;
int voteNumber = -1;
@@ -122,7 +122,7 @@
// check value if same as the one return by request
// otherwise it means there is a conversion error
String[] values = getParameters().get("vote.choiceVoteToChoice[" + voteNumber + "].voteValue");
- String paramValue = values==null || values.length<1?null:values[0];
+ String paramValue = values == null || values.length < 1 ? null : values[0];
if (StringUtils.isNotBlank(paramValue)) {
@@ -135,7 +135,7 @@
}
}
// check if vote is null ?
- boolean voteNull = strategy.isVoteValueNull(value);
+ boolean voteNull = voteCounting.isVoteValueNull(value);
if (voteNull) {
// null vote, can skip his validation
@@ -143,7 +143,7 @@
}
// check if vote value is valid ?
- boolean valid = strategy.isVoteValueValid(value);
+ boolean valid = voteCounting.isVoteValueValid(value);
if (valid) {
@@ -154,7 +154,7 @@
// not a valid vote value, mark it and skip other fields validation
String validMessage =
- strategy.getVoteValueNotValidMessage(getLocale());
+ voteCounting.getVoteValueNotValidMessage(getLocale());
addFieldError("vote.choices", validMessage);
voteValid = false;
break;
@@ -170,11 +170,11 @@
}
// check that total vote value is ok
- if (!strategy.isTotalVoteValueValid(totalValues)) {
+ if (!voteCounting.isTotalVoteValueValid(totalValues)) {
// not valid
String errorMessage =
- strategy.getTotalVoteValueNotValidMessage(getLocale());
+ voteCounting.getTotalVoteValueNotValidMessage(getLocale());
addFieldError("vote.choices", errorMessage);
}
}
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AbstractPollenAuthorization.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AbstractPollenAuthorization.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AbstractPollenAuthorization.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -233,7 +233,7 @@
transaction,
applicationContext.getConfiguration(),
serviceFactory,
- applicationContext.getVoteCountingStrategyProvider()
+ applicationContext.getVoteCountingFactory()
);
return serviceContext.newService(SecurityService.class);
Added: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingFactoryTest.java
===================================================================
--- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingFactoryTest.java (rev 0)
+++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingFactoryTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,50 @@
+package org.chorem.pollen.votecounting.strategy;
+
+import org.chorem.pollen.votecounting.BordaVoteCounting;
+import org.chorem.pollen.votecounting.CondorcetVoteCounting;
+import org.chorem.pollen.votecounting.CoombsVoteCounting;
+import org.chorem.pollen.votecounting.InstantRunoffVoteCounting;
+import org.chorem.pollen.votecounting.NormalVoteCounting;
+import org.chorem.pollen.votecounting.NumberVoteCounting;
+import org.chorem.pollen.votecounting.PercentageVoteCounting;
+import org.chorem.pollen.votecounting.VoteCounting;
+import org.chorem.pollen.votecounting.VoteCountingFactory;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests the {@link VoteCountingFactory}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class VoteCountingFactoryTest {
+
+ @Test
+ public void getVoteCounting() throws Exception {
+
+ VoteCountingFactory factory = new VoteCountingFactory();
+ VoteCounting voteCounting;
+
+ voteCounting = factory.getVoteCounting(BordaVoteCounting.ID);
+ Assert.assertNotNull(voteCounting);
+
+ voteCounting = factory.getVoteCounting(CondorcetVoteCounting.ID);
+ Assert.assertNotNull(voteCounting);
+
+ voteCounting = factory.getVoteCounting(CoombsVoteCounting.ID);
+ Assert.assertNotNull(voteCounting);
+
+ voteCounting = factory.getVoteCounting(InstantRunoffVoteCounting.ID);
+ Assert.assertNotNull(voteCounting);
+
+ voteCounting = factory.getVoteCounting(NormalVoteCounting.ID);
+ Assert.assertNotNull(voteCounting);
+
+ voteCounting = factory.getVoteCounting(NumberVoteCounting.ID);
+ Assert.assertNotNull(voteCounting);
+
+ voteCounting = factory.getVoteCounting(PercentageVoteCounting.ID);
+ Assert.assertNotNull(voteCounting);
+ }
+}
Property changes on: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingFactoryTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Copied: trunk/pollen-ui-struts2/src/test/resources/log4j.properties (from rev 3707, trunk/pollen-votecounting-strategy-borda/src/test/resources/log4j.properties)
===================================================================
--- trunk/pollen-ui-struts2/src/test/resources/log4j.properties (rev 0)
+++ trunk/pollen-ui-struts2/src/test/resources/log4j.properties 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,8 @@
+# Global logging configuration
+log4j.rootLogger=WARN, stdout
+# Console output...
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d %5p [%t] (%F:%L) %M - %m%n
+# package level
+log4j.logger.org.chorem.pollen=INFO
Property changes on: trunk/pollen-ui-struts2/src/test/resources/log4j.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/pollen-votecounting-aggregator/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy/pom.xml 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-aggregator/pom.xml 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,12 +1,10 @@
<?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>
- <!-- ************************************************************* -->
- <!-- *** POM Relationships *************************************** -->
- <!-- ************************************************************* -->
-
<parent>
<groupId>org.chorem</groupId>
<artifactId>pollen</artifactId>
@@ -14,62 +12,62 @@
</parent>
<groupId>org.chorem.pollen</groupId>
- <artifactId>pollen-votecounting-strategy</artifactId>
+ <artifactId>pollen-votecounting-aggregator</artifactId>
+ <name>Pollen :: VoteCounting (Aggregator)</name>
+ <description>
+ Aggregator of all implementations of votecounting offers by Pollen
+ </description>
+
+ <packaging>pom</packaging>
+
<modules>
- <module>../pollen-votecounting-strategy-normal</module>
- <module>../pollen-votecounting-strategy-percentage</module>
- <module>../pollen-votecounting-strategy-condorcet</module>
- <module>../pollen-votecounting-strategy-number</module>
- <module>../pollen-votecounting-strategy-borda</module>
- <module>../pollen-votecounting-strategy-instant-runoff</module>
- <module>../pollen-votecounting-strategy-coombs</module>
+ <module>../pollen-votecounting-normal</module>
+ <module>../pollen-votecounting-percentage</module>
+ <module>../pollen-votecounting-condorcet</module>
+ <module>../pollen-votecounting-number</module>
+ <module>../pollen-votecounting-borda</module>
+ <module>../pollen-votecounting-instant-runoff</module>
+ <module>../pollen-votecounting-coombs</module>
</modules>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>pollen-votecounting-strategy-normal</artifactId>
+ <artifactId>pollen-votecounting-normal</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>pollen-votecounting-strategy-percentage</artifactId>
+ <artifactId>pollen-votecounting-percentage</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>pollen-votecounting-strategy-condorcet</artifactId>
+ <artifactId>pollen-votecounting-condorcet</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>pollen-votecounting-strategy-number</artifactId>
+ <artifactId>pollen-votecounting-number</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>pollen-votecounting-strategy-borda</artifactId>
+ <artifactId>pollen-votecounting-borda</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>pollen-votecounting-strategy-instant-runoff</artifactId>
+ <artifactId>pollen-votecounting-instant-runoff</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>pollen-votecounting-strategy-coombs</artifactId>
+ <artifactId>pollen-votecounting-coombs</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
- <name>Pollen :: VoteCounting strategy</name>
- <description>
- Aggregator of all implementations of votecounting strategy
- </description>
-
- <packaging>pom</packaging>
-
</project>
Modified: trunk/pollen-votecounting-api/pom.xml
===================================================================
--- trunk/pollen-votecounting-api/pom.xml 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-api/pom.xml 2012-09-29 12:36:25 UTC (rev 3708)
@@ -14,7 +14,7 @@
<groupId>org.chorem.pollen</groupId>
<artifactId>pollen-votecounting-api</artifactId>
- <name>Pollen :: VoteCounting Api</name>
+ <name>Pollen :: VoteCounting (Api)</name>
<description>Define Api to votecount</description>
<dependencies>
@@ -23,23 +23,28 @@
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
+
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
+
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
+
<dependency>
<groupId>org.nuiton.i18n</groupId>
<artifactId>nuiton-i18n</artifactId>
</dependency>
+
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
<scope>test</scope>
</dependency>
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Added: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCounting.java (rev 0)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCounting.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,71 @@
+package org.chorem.pollen.votecounting;
+
+import java.util.Locale;
+
+import static org.nuiton.i18n.I18n.l_;
+
+/**
+ * Base abstract implementation of a {@link VoteCounting}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.6
+ */
+public abstract class AbstractVoteCounting<S extends VoteCountingStrategy> implements VoteCounting<S> {
+
+ protected final int strategyId;
+
+ protected final Class<S> strategyType;
+
+ protected final String i18nName;
+
+ protected final String i18nHelp;
+
+ public AbstractVoteCounting(int strategyId,
+ Class<S> strategyType,
+ String i18nName,
+ String i18nHelp) {
+ this.strategyId = strategyId;
+ this.strategyType = strategyType;
+ this.i18nName = i18nName;
+ this.i18nHelp = i18nHelp;
+ }
+
+ @Override
+ public final S newVoteCountingStrategy() {
+ try {
+ return strategyType.newInstance();
+ } catch (Exception e) {
+ throw new RuntimeException("Could not instanciate strategy", e);
+ }
+ }
+
+ @Override
+ public final String getStrategyName(Locale locale) {
+ String result = l_(locale, getI18nName());
+ return result;
+ }
+
+ @Override
+ public final String getStrategyHelp(Locale locale) {
+ String voteName = l_(locale, getI18nName());
+ String voteHelp = l_(locale, getI18nHelp());
+ String result = l_(locale, "pollen.voteCountingType.help", voteName, voteHelp);
+ return result;
+ }
+
+ @Override
+ public final int getId() {
+ return strategyId;
+ }
+
+ @Override
+ public final String getI18nName() {
+ return i18nName;
+ }
+
+ @Override
+ public final String getI18nHelp() {
+ return i18nHelp;
+ }
+
+}
Property changes on: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCounting.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCountingStrategy.java (from rev 3707, 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/AbstractVoteCountingStrategy.java (rev 0)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCountingStrategy.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,187 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting Api
+ * $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.votecounting;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+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;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+
+/**
+ * Base abstract implementation of a {@link VoteCountingStrategy}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public abstract class AbstractVoteCountingStrategy implements VoteCountingStrategy {
+
+ 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;
+ }
+
+ public SortedMap<String, ChoiceScore> votersToResult(Set<Voter> voters) {
+ // get all choice Id
+ Set<String> choiceIds = getAllChoiceIds(voters);
+
+ SortedMap<String, ChoiceScore> resultByChoice = Maps.newTreeMap();
+
+ // creates all empty result for choice
+ for (String choiceId : choiceIds) {
+ ChoiceScore choiceScore = ChoiceScore.newScore(choiceId, null);
+ resultByChoice.put(choiceId, choiceScore);
+ }
+ return resultByChoice;
+ }
+
+ public VoteCountingResult resultToList(Map<String, ChoiceScore> resultByChoice) {
+ List<ChoiceScore> score = toChoiceScore(resultByChoice);
+ return VoteCountingResult.newResult(score);
+ }
+
+ public List<ChoiceScore> toChoiceScore(Map<String, ChoiceScore> resultByChoice) {
+ List<ChoiceScore> score = Lists.newArrayList(resultByChoice.values());
+ Collections.sort(score);
+ Collections.reverse(score);
+ return score;
+ }
+
+ public Set<String> getAllChoiceIds(Set<Voter> voters) {
+ ChoiceIdAble.ChoiceIdAbleById function = new ChoiceIdAble.ChoiceIdAbleById();
+ Set<String> result = Sets.newHashSet();
+ for (Voter voter : voters) {
+ Iterable<String> transform = Iterables.transform(
+ voter.getVoteForChoices(), function);
+ Iterables.addAll(result, transform);
+
+ }
+ return result;
+ }
+
+ public Map<Voter, List<Set<String>>> buildVoterSortedChoices(Set<Voter> voters) {
+
+ VoteForChoiceComparator comparator = new VoteForChoiceComparator();
+
+ Map<Voter, List<Set<String>>> voterSortedChoices = Maps.newHashMap();
+
+ for (Voter voter : voters) {
+
+ List<Set<String>> sortedChoices = sortVoteForChoices(
+ voter.getVoteForChoices(), comparator);
+ voterSortedChoices.put(voter, sortedChoices);
+ }
+ return voterSortedChoices;
+ }
+
+ public List<Set<String>> sortVoteForChoices(Set<VoteForChoice> voteForChoices,
+ Comparator<VoteForChoice> comparator) {
+ // get sort vote for choices
+ List<VoteForChoice> sortedChoices = Lists.newArrayList(voteForChoices);
+ Collections.sort(sortedChoices, comparator);
+
+ // build ranks
+ List<Set<String>> result = Lists.newArrayList();
+
+ Set<String> set = Sets.newHashSet();
+ result.add(set);
+ VoteForChoice lastVoteForChoice = null;
+ for (VoteForChoice voteForChoice : sortedChoices) {
+ if (lastVoteForChoice != null &&
+ comparator.compare(lastVoteForChoice, voteForChoice) != 0) {
+
+ // new rank found
+ // register it
+ result.add(set = Sets.newHashSet());
+ }
+
+ set.add(voteForChoice.getChoiceId());
+ lastVoteForChoice = voteForChoice;
+ }
+ 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;
+
+ @Override
+ public int compare(VoteForChoice o1, VoteForChoice o2) {
+ Double v1 = o1.getVoteValue();
+ Double v2 = o2.getVoteValue();
+ if (v1 == null) {
+ v1 = Double.MAX_VALUE;
+ }
+ if (v2 == null) {
+ v2 = Double.MAX_VALUE;
+ }
+ return v1.intValue() - v2.intValue();
+ }
+ }
+}
Property changes on: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCountingStrategy.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCounting.java
===================================================================
--- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCounting.java (rev 0)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCounting.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,127 @@
+package org.chorem.pollen.votecounting;
+
+import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
+
+import java.util.Locale;
+
+/**
+ * Contract of a vote counting.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.6
+ */
+public interface VoteCounting<S extends VoteCountingStrategy> {
+
+ /**
+ * Obtains a fresh instance of a vote coutning strategy.
+ *
+ * @return a new instance of vote counting strategy for this type
+ * of vote counting.
+ */
+ S newVoteCountingStrategy();
+
+ /**
+ * Obtains the unique id of this strategy.
+ *
+ * @return the unique id of this strategy.
+ */
+ int getId();
+
+ /**
+ * Obtains the i18n name of this strategy.
+ *
+ * @return the i18n name of this strategy.
+ */
+ String getI18nName();
+
+ /**
+ * Obtains the i18n help of this strategy.
+ *
+ * @return the i18n help of this strategy.
+ */
+ String getI18nHelp();
+
+ /**
+ * Get the value to display for a given vote value in the vote page.
+ *
+ * @param voteValue the vote value to display
+ * @return the string representation of a vote value
+ */
+ String getDisplayVoteValue(Integer voteValue);
+
+ /**
+ * Test if the given value is a vote value (says users has filled it).
+ *
+ * @param voteValue the vote value to test
+ * @return {@code true} if the given value is persisted.
+ */
+ boolean isChoiceInVote(Integer voteValue);
+
+ /**
+ * Get the vote counting strategy name to display in UI.
+ *
+ * @param locale the locale used to render the strategy name
+ * @return the localized vote counting strategy name
+ */
+ String getStrategyName(Locale locale);
+
+ /**
+ * Get the vote counting strategy help to display in UI.
+ *
+ * @param locale the locale used to render the strategy name
+ * @return the localized vote counting strategy help
+ */
+ String getStrategyHelp(Locale locale);
+
+ /**
+ * Tests if the given vote value is valid.
+ *
+ * @param voteValue the vote value to test
+ * @return {@code true} if the given vote value is valid, {@code false}
+ * otherwise.
+ */
+ boolean isVoteValueValid(Integer voteValue);
+
+ /**
+ * If a vote value is not valid, gets the localized message of the error.
+ *
+ * @param locale the locale used to render the error message
+ * @return the localized validation message
+ */
+ String getVoteValueNotValidMessage(Locale locale);
+
+ /**
+ * Tests if the total values of a vote is valid.
+ *
+ * @param totalValues the given total values
+ * @return {@code true} if the total values of a vote is valid,
+ * {@code false} otherwhise.
+ */
+ boolean isTotalVoteValueValid(int totalValues);
+
+ /**
+ * If the total values of a vote is not valid, gets the localized error
+ * message.
+ *
+ * @param locale the locale used to render the error message
+ * @return the localized validation message
+ */
+ String getTotalVoteValueNotValidMessage(Locale locale);
+
+ /**
+ * Tests if a given vote value is null or not.
+ *
+ * @param value the vote value to test
+ * @return {@code true} if the given vote value is null (or considered as
+ * null), {@code false} otherwise.
+ */
+ boolean isVoteValueNull(Integer value);
+
+ /**
+ * Gets the type of editor used to render a vote value.
+ *
+ * @return the type of editor used to render a vote value.
+ * @see ChoiceToVoteRenderType
+ */
+ ChoiceToVoteRenderType getVoteValueEditorType();
+}
Property changes on: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCounting.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCountingFactory.java
===================================================================
--- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCountingFactory.java (rev 0)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCountingFactory.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,69 @@
+package org.chorem.pollen.votecounting;
+
+import com.google.common.collect.Maps;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.ServiceLoader;
+
+/**
+ * Factory of {@link VoteCounting}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.6
+ */
+public class VoteCountingFactory implements Iterable<VoteCounting> {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(VoteCountingFactory.class);
+
+ /**
+ * List of available vote counting detected via the {@link ServiceLoader}
+ * mecanism no contract {@link VoteCounting}.
+ */
+ private final Map<Integer, VoteCounting> voteCountings;
+
+ public VoteCountingFactory() {
+ voteCountings = Maps.newHashMap();
+
+ ServiceLoader<VoteCounting> loader =
+ ServiceLoader.load(VoteCounting.class);
+
+ for (VoteCounting strategy : loader) {
+ int id = strategy.getId();
+
+ if (voteCountings.containsKey(id)) {
+ throw new IllegalStateException(
+ "Strategy [" +
+ strategy.getI18nName() + "] with id " + id +
+ ", can not be used since the id is already used " +
+ "by strategy [" + voteCountings.get(id).getI18nName() + "] ");
+ }
+ if (log.isInfoEnabled()) {
+ log.info("Detected strategy [" + id + "-" +
+ strategy.getI18nName() + "] : " +
+ strategy.getClass().getName());
+ }
+ voteCountings.put(id, strategy);
+ }
+
+
+ }
+
+ public VoteCounting getVoteCounting(int strategyId) throws VoteCountingNotFound {
+ VoteCounting type = voteCountings.get(strategyId);
+
+ if (type == null) {
+ throw new VoteCountingNotFound(
+ "Could not find strategy with id " + strategyId);
+ }
+ return type;
+ }
+
+ @Override
+ public Iterator<VoteCounting> iterator() {
+ return voteCountings.values().iterator();
+ }
+}
Property changes on: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCountingFactory.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCountingNotFound.java (from rev 3707, trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/strategy/VoteCountigStrategyNotFound.java)
===================================================================
--- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCountingNotFound.java (rev 0)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCountingNotFound.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,41 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting Api
+ * $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.votecounting;
+
+/**
+ * Exception when a vote counting could not be found.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class VoteCountingNotFound extends RuntimeException {
+ private static final long serialVersionUID = 1L;
+
+ public VoteCountingNotFound(String message) {
+ super(message);
+ }
+
+ public VoteCountingNotFound(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
Property changes on: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCountingNotFound.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCountingStrategy.java (from rev 3707, 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/VoteCountingStrategy.java (rev 0)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCountingStrategy.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,57 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting Api
+ * $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.votecounting;
+
+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;
+
+import java.util.Set;
+
+/**
+ * Strategy of a vote counting.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public interface VoteCountingStrategy {
+
+ /**
+ * Vote count for the given {@code group} of voters and return the
+ * result of it.
+ *
+ * @param group the group of voters and their votes.
+ * @return the result of the group vote counting for the given voter.
+ */
+ GroupVoteCountingResult votecount(GroupOfVoter group);
+
+ /**
+ * Vote count for the given {@code voter} and return the result of it.
+ *
+ * @param voter the voter and their votes.
+ * @return the result of the vote counting for the given voter.
+ */
+ VoteCountingResult votecount(Set<Voter> voter);
+
+}
Property changes on: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/VoteCountingStrategy.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
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-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/ChoiceScore.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -26,21 +26,24 @@
import java.math.BigDecimal;
/**
- * ChoiceScore for a given choice.
+ * Score for a given choice.
*
* @author tchemit <chemit(a)codelutin.com>
* @since 1.4.5
*/
-public class ChoiceScore implements ChoiceIdAble, Comparable<ChoiceScore>,Serializable {
+public class ChoiceScore implements ChoiceIdAble, Comparable<ChoiceScore>, Serializable {
private static final long serialVersionUID = 1L;
/** Id of the choice. */
private String choiceId;
- /** Score for this choice. */
+ /** Global score for this choice (in some poll does not mean a lot...). */
private BigDecimal scoreValue;
+ /** Order of this score (0 is winner, 1, second,...). */
+ private int scoreOrder;
+
public static ChoiceScore newScore(String choiceId, BigDecimal scoreValue) {
ChoiceScore choiceScore = new ChoiceScore();
choiceScore.setChoiceId(choiceId);
@@ -57,6 +60,14 @@
return scoreValue;
}
+ public int getScoreOrder() {
+ return scoreOrder;
+ }
+
+ public void setScoreOrder(int scoreOrder) {
+ this.scoreOrder = scoreOrder;
+ }
+
public void setChoiceId(String choiceId) {
this.choiceId = choiceId;
}
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-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/GroupVoteCountingResult.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -60,6 +60,7 @@
public Set<String> getGroupIds() {
return Sets.newHashSet(groups.keySet());
}
+
public VoteCountingResult getGroupResult(String groupId) {
GroupOfVoter groupOfVoter = groups.get(groupId);
VoteCountingResult result = groupOfVoter.getResult();
Modified: 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 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/SimpleVoterBuilder.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -49,7 +49,7 @@
@Override
public SimpleVoterBuilder addVoteForChoice(String choiceId, Double voteValue) {
- Preconditions.checkState(voter != null,"No voter defined, use method newVoter before this one");
+ Preconditions.checkState(voter != null, "No voter defined, use method newVoter before this one");
VoteForChoice voteForChoice = VoteForChoice.newVote(choiceId, voteValue);
voter.addVoteForChoice(voteForChoice);
return this;
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-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/VoteCountingResult.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -42,9 +42,15 @@
private static final long serialVersionUID = 1L;
- /** Results for each choice. */
+ /**
+ * Results for each choice.
+ * <p/>
+ * <strong>Note:</strong> Natural order is used to describe choice scores
+ * (first is winner,...).
+ */
private List<ChoiceScore> scores;
+ /** Get the winners (could be more than one of it). */
private Set<ChoiceScore> topRanking;
public static VoteCountingResult newResult(List<ChoiceScore> scores) {
Deleted: 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-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/strategy/AbstractVoteCountingStrategy.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,227 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting Api
- * $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.votecounting.strategy;
-
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-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;
-
-import java.io.Serializable;
-import java.math.BigDecimal;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedMap;
-
-import static org.nuiton.i18n.I18n.l_;
-
-/**
- * Base abstract implementation of a {@link VoteCountingStrategy}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public abstract class AbstractVoteCountingStrategy implements VoteCountingStrategy {
-
- 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;
- }
-
- @Override
- public String getStrategyHelp(Locale locale) {
- String voteName = l_(locale, getI18nName());
- String voteHelp = l_(locale, getI18nHelp());
- String result = l_(locale, "pollen.voteCountingType.help", voteName, voteHelp);
- return result;
- }
-
- public SortedMap<String, ChoiceScore> votersToResult(Set<Voter> voters) {
- // get all choice Id
- Set<String> choiceIds = getAllChoiceIds(voters);
-
- SortedMap<String, ChoiceScore> resultByChoice = Maps.newTreeMap();
-
- // creates all empty result for choice
- for (String choiceId : choiceIds) {
- ChoiceScore choiceScore = ChoiceScore.newScore(choiceId, null);
- resultByChoice.put(choiceId, choiceScore);
- }
- return resultByChoice;
- }
-
- public VoteCountingResult resultToList(Map<String, ChoiceScore> resultByChoice) {
- List<ChoiceScore> score = toChoiceScore(resultByChoice);
- return VoteCountingResult.newResult(score);
- }
-
- public List<ChoiceScore> toChoiceScore(Map<String, ChoiceScore> resultByChoice) {
- List<ChoiceScore> score = Lists.newArrayList(resultByChoice.values());
- Collections.sort(score);
- Collections.reverse(score);
- return score;
- }
-
- public Set<String> getAllChoiceIds(Set<Voter> voters) {
- ChoiceIdAble.ChoiceIdAbleById function = new ChoiceIdAble.ChoiceIdAbleById();
- Set<String> result = Sets.newHashSet();
- for (Voter voter : voters) {
- Iterable<String> transform = Iterables.transform(
- voter.getVoteForChoices(), function);
- Iterables.addAll(result, transform);
-
- }
- return result;
- }
-
- public Map<Voter, List<Set<String>>> buildVoterSortedChoices(Set<Voter> voters) {
-
- VoteForChoiceComparator comparator = new VoteForChoiceComparator();
-
- Map<Voter, List<Set<String>>> voterSortedChoices = Maps.newHashMap();
-
- for (Voter voter : voters) {
-
- List<Set<String>> sortedChoices = sortVoteForChoices(
- voter.getVoteForChoices(), comparator);
- voterSortedChoices.put(voter, sortedChoices);
- }
- return voterSortedChoices;
- }
-
- public List<Set<String>> sortVoteForChoices(Set<VoteForChoice> voteForChoices,
- Comparator<VoteForChoice> comparator) {
- // get sort vote for choices
- List<VoteForChoice> sortedChoices = Lists.newArrayList(voteForChoices);
- Collections.sort(sortedChoices, comparator);
-
- // build ranks
- List<Set<String>> result = Lists.newArrayList();
-
- Set<String> set = Sets.newHashSet();
- result.add(set);
- VoteForChoice lastVoteForChoice = null;
- for (VoteForChoice voteForChoice : sortedChoices) {
- if (lastVoteForChoice != null &&
- comparator.compare(lastVoteForChoice, voteForChoice) != 0) {
-
- // new rank found
- // register it
- result.add(set = Sets.newHashSet());
- }
-
- set.add(voteForChoice.getChoiceId());
- lastVoteForChoice = voteForChoice;
- }
- return result;
- }
-
- public Set<String> getDirectWinners(Collection<List<Set<String>>> values) {
- Set<String> result = null;
- for (List<Set<String>> value : values) {
-
- Set<String> topChoices = value.get(0);
-
- if (result == null) {
- // first time coming here
- result = topChoices;
- } else {
-
- if (!result.equals(topChoices)) {
-
- // not same first ranking, not direct winner
- result = null;
- break;
- }
- }
- }
- 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;
-
- @Override
- public int compare(VoteForChoice o1, VoteForChoice o2) {
- Double v1 = o1.getVoteValue();
- Double v2 = o2.getVoteValue();
- if (v1 == null) {
- v1 = Double.MAX_VALUE;
- }
- if (v2 == null) {
- v2 = Double.MAX_VALUE;
- }
- return v1.intValue() - v2.intValue();
- }
- }
-}
Deleted: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/strategy/VoteCountigStrategyNotFound.java
===================================================================
--- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/strategy/VoteCountigStrategyNotFound.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/strategy/VoteCountigStrategyNotFound.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,41 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting Api
- * $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.votecounting.strategy;
-
-/**
- * Exception when a vote counting could not be found.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class VoteCountigStrategyNotFound extends RuntimeException {
- private static final long serialVersionUID = 1L;
-
- public VoteCountigStrategyNotFound(String message) {
- super(message);
- }
-
- public VoteCountigStrategyNotFound(String message, Throwable cause) {
- super(message, cause);
- }
-}
Deleted: 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-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategy.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,163 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting Api
- * $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.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;
-
-import java.util.Locale;
-import java.util.Set;
-
-/**
- * Contract of a vote counting method.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public interface VoteCountingStrategy {
-
- /**
- * Obtains the unique id of this strategy.
- *
- * @return the unique id of this strategy.
- */
- int getId();
-
- /**
- * Obtains the i18n name of this strategy.
- *
- * @return the i18n name of this strategy.
- */
- String getI18nName();
-
- /**
- * Obtains the i18n help of this strategy.
- *
- * @return the i18n help of this strategy.
- */
- String getI18nHelp();
-
- GroupVoteCountingResult votecount(GroupOfVoter group);
-
- /**
- * Vote count for the given {@code voter} and return the result of it.
- *
- * @param voter the voter and their votes.
- * @return the result of the vote counting for the given voter.
- */
- VoteCountingResult votecount(Set<Voter> voter);
-
- /**
- * Get the value to display for a given vote value in the vote page.
- *
- * @param voteValue the vote value to display
- * @return the string representation of a vote value
- */
- String getDisplayVoteValue(Integer voteValue);
-
- /**
- * Test if the given value is a vote value (says users has filled it).
- *
- * @param voteValue the vote value to test
- * @return {@code true} if the given value is persisted.
- */
- boolean isChoiceInVote(Integer voteValue);
-
- /**
- * Get the vote counting strategy name to display in UI.
- *
- * @param locale the locale used to render the strategy name
- * @return the localized vote counting strategy name
- */
- String getStrategyName(Locale locale);
-
- /**
- * Get the vote counting strategy help to display in UI.
- *
- * @param locale the locale used to render the strategy name
- * @return the localized vote counting strategy help
- */
- String getStrategyHelp(Locale locale);
-
- /**
- * Tests if the given vote value is valid.
- *
- * @param voteValue the vote value to test
- * @return {@code true} if the given vote value is valid, {@code false}
- * otherwise.
- */
- boolean isVoteValueValid(Integer voteValue);
-
- /**
- * If a vote value is not valid, gets the localized message of the error.
- *
- * @param locale the locale used to render the error message
- * @return the localized validation message
- */
- String getVoteValueNotValidMessage(Locale locale);
-
- /**
- * Tests if the total values of a vote is valid.
- *
- * @param totalValues the given total values
- * @return {@code true} if the total values of a vote is valid,
- * {@code false} otherwhise.
- */
- boolean isTotalVoteValueValid(int totalValues);
-
- /**
- * If the total values of a vote is not valid, gets the localized error
- * message.
- *
- * @param locale the locale used to render the error message
- * @return the localized validation message
- */
- String getTotalVoteValueNotValidMessage(Locale locale);
-
- /**
- * Tests if a given vote value is null or not.
- *
- * @param value the vote value to test
- * @return {@code true} if the given vote value is null (or considered as
- * null), {@code false} otherwise.
- */
- boolean isVoteValueNull(Integer value);
-
- /**
- * Gets the type of editor used to render a vote value.
- *
- * @return the type of editor used to render a vote value.
- * @see ChoiceToVoteRenderType
- */
- ChoiceToVoteRenderType getVoteValueEditorType();
-
- /**
- * @return {@code true} if display results by choice.
- * @deprecated since 1.5 (result will be offered by the strategy it-self).
- */
- @Deprecated
- boolean isDisplayResultsByChoice();
-}
Deleted: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProvider.java
===================================================================
--- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProvider.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProvider.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,101 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting Api
- * $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.votecounting.strategy;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Maps;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.util.Map;
-import java.util.ServiceLoader;
-import java.util.Set;
-
-/**
- * Provider of {@link VoteCountingStrategy}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class VoteCountingStrategyProvider {
-
- /** Logger. */
- private static final Log log =
- LogFactory.getLog(VoteCountingStrategyProvider.class);
-
- /**
- * List of available strageries detected via the {@link ServiceLoader}
- * mecanism no contract {@link VoteCountingStrategy}.
- */
- private final Map<Integer, VoteCountingStrategy> strategies;
-
- public VoteCountingStrategyProvider() {
- strategies = load();
- }
-
- public Set<Integer> getStrategyIds() {
- return ImmutableSet.copyOf(strategies.keySet());
- }
-
- public VoteCountingStrategy getStrategy(int strategyId) throws VoteCountigStrategyNotFound {
- VoteCountingStrategy type = strategies.get(strategyId);
-
- if (type == null) {
- throw new VoteCountigStrategyNotFound(
- "Could not find strategy with id " + strategyId);
- }
- try {
- //FIXME-tchemit-2012-06-24 : should we reinstanciate each time ?
- return type.getClass().newInstance();
- } catch (Exception e) {
-
- throw new VoteCountigStrategyNotFound(
- "Could not instanciate stragegy " + strategyId, e);
- }
- }
-
- protected Map<Integer, VoteCountingStrategy> load() {
- Map<Integer, VoteCountingStrategy> result = Maps.newTreeMap();
- ServiceLoader<VoteCountingStrategy> loader =
- ServiceLoader.load(VoteCountingStrategy.class);
-
- for (VoteCountingStrategy strategy : loader) {
- int id = strategy.getId();
- if (result.containsKey(id)) {
- throw new IllegalStateException(
- "Strategy [" +
- strategy.getI18nName() + "] with id " + id +
- ", can not be used since the id is already used " +
- "by strategy [" + result.get(id).getI18nName() + "] ");
- }
- if (log.isInfoEnabled()) {
- log.info("Detected strategy [" + id + "-" +
- strategy.getI18nName() + "] : " +
- strategy.getClass().getName());
- }
- result.put(id, strategy);
- }
- return result;
- }
-
-}
Copied: trunk/pollen-votecounting-api/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java (from rev 3707, trunk/pollen-votecounting-api/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java)
===================================================================
--- trunk/pollen-votecounting-api/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java (rev 0)
+++ trunk/pollen-votecounting-api/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,43 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting Api
+ * $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.votecounting;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests the {@link VoteCountingFactory}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class VoteCountingFactoryTest {
+
+ @Test(expected = VoteCountingNotFound.class)
+ public void getVoteCounting() throws Exception {
+
+ VoteCountingFactory factory = new VoteCountingFactory();
+ VoteCounting voteCounting = factory.getVoteCounting(-1);
+ Assert.assertNull(voteCounting);
+ }
+}
Property changes on: trunk/pollen-votecounting-api/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-api/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java
===================================================================
--- trunk/pollen-votecounting-api/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-api/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,49 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting Api
- * $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.votecounting.strategy;
-
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * Tests the {@link VoteCountingStrategyProvider}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class VoteCountingStrategyProviderTest {
-
- protected static VoteCountingStrategyProvider provider;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- provider = new VoteCountingStrategyProvider();
- }
-
- @Test(expected = VoteCountigStrategyNotFound.class)
- public void getStrategy() throws Exception {
-
- Assert.assertNull(provider.getStrategy(-1));
- }
-}
Modified: trunk/pollen-votecounting-borda/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy-borda/pom.xml 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-borda/pom.xml 2012-09-29 12:36:25 UTC (rev 3708)
@@ -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>
@@ -10,11 +12,10 @@
</parent>
<groupId>org.chorem.pollen</groupId>
- <artifactId>pollen-votecounting-strategy-borda</artifactId>
+ <artifactId>pollen-votecounting-borda</artifactId>
+ <name>Pollen :: VoteCounting :: Borda</name>
+ <description>Implements the borda vote counting</description>
- <name>Pollen :: VoteCounting strategy :: Borda</name>
- <description>Implements the borda vote counting strategy</description>
-
<dependencies>
<dependency>
@@ -39,6 +40,12 @@
</dependency>
<dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
Added: trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCounting.java (rev 0)
+++ trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCounting.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,69 @@
+package org.chorem.pollen.votecounting;
+
+import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
+
+import java.util.Locale;
+
+import static org.nuiton.i18n.I18n.l_;
+import static org.nuiton.i18n.I18n.n_;
+
+/**
+ * Borda vote counting entry point.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.6
+ */
+public class BordaVoteCounting extends AbstractVoteCounting<BordaVoteCountingStrategy> {
+
+ public static final int ID = 4;
+
+ public BordaVoteCounting() {
+ super(ID,
+ BordaVoteCountingStrategy.class,
+ n_("pollen.voteCountingType.borda"),
+ n_("pollen.voteCountingType.borda.help")
+ );
+ }
+
+ @Override
+ public String getTotalVoteValueNotValidMessage(Locale locale) {
+ // no validation on total value, so no message
+ return null;
+ }
+
+ @Override
+ public String getVoteValueNotValidMessage(Locale locale) {
+ return l_(locale, "pollen.error.vote.invalidBordaVoteValue");
+ }
+
+ @Override
+ public String getDisplayVoteValue(Integer voteValue) {
+ return voteValue == null ? "" : String.valueOf(voteValue);
+ }
+
+ @Override
+ public ChoiceToVoteRenderType getVoteValueEditorType() {
+ return ChoiceToVoteRenderType.TEXTFIELD;
+ }
+
+ @Override
+ public boolean isChoiceInVote(Integer voteValue) {
+ return voteValue != null && voteValue > 0 && voteValue < 100;
+ }
+
+ @Override
+ public boolean isVoteValueNull(Integer voteValue) {
+ return voteValue == null;
+ }
+
+ @Override
+ public boolean isVoteValueValid(Integer voteValue) {
+ return voteValue != null && voteValue > 0;
+ }
+
+ @Override
+ public boolean isTotalVoteValueValid(int totalValues) {
+ // no validation on total value
+ return true;
+ }
+}
Property changes on: trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCounting.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCountingStrategy.java (from rev 3707, trunk/pollen-votecounting-strategy-borda/src/main/java/org/chorem/pollen/votecounting/strategy/BordaStrategy.java)
===================================================================
--- trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCountingStrategy.java (rev 0)
+++ trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCountingStrategy.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,88 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting strategy :: Borda
+ * $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.votecounting;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.votecounting.model.ChoiceScore;
+import org.chorem.pollen.votecounting.model.VoteCountingResult;
+import org.chorem.pollen.votecounting.model.Voter;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Condorcet.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class BordaVoteCountingStrategy extends AbstractVoteCountingStrategy {
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(BordaVoteCountingStrategy.class);
+
+ @Override
+ public VoteCountingResult votecount(Set<Voter> voters) {
+
+ // get empty result by choice
+ Map<String, ChoiceScore> resultByChoice = votersToResult(voters);
+
+ // nb of choices
+ int nbChoices = resultByChoice.keySet().size();
+
+ if (log.isDebugEnabled()) {
+ log.debug("Nb choices: " + nbChoices);
+ }
+
+ // calcul pour chaque votant de sa liste des choix dans son ordre préféré
+
+ Map<Voter, List<Set<String>>> voterSortedChoices =
+ buildVoterSortedChoices(voters);
+
+ // calcul des points pour chaque choix selon son ordre d'arrivé (
+ // le 1er à nbChoices * weight point, le second (nbChoices-1) * weight,...)
+
+ for (Map.Entry<Voter, List<Set<String>>> entry : voterSortedChoices.entrySet()) {
+ Voter voter = entry.getKey();
+ double weight = voter.getWeight();
+ double choiceWeight = nbChoices * weight;
+ for (Set<String> sortedChoiceId : entry.getValue()) {
+
+ for (String choiceId : sortedChoiceId) {
+
+ resultByChoice.get(choiceId).addScoreValue(choiceWeight);
+ }
+ choiceWeight -= weight;
+ }
+ }
+
+ // transform map of result to list of them (and sort them)
+ VoteCountingResult result = resultToList(resultByChoice);
+ return result;
+ }
+
+
+}
Property changes on: trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCountingStrategy.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/strategy/BordaStrategy.java
===================================================================
--- trunk/pollen-votecounting-strategy-borda/src/main/java/org/chorem/pollen/votecounting/strategy/BordaStrategy.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/strategy/BordaStrategy.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,156 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting strategy :: Borda
- * $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.votecounting.strategy;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.votecounting.model.ChoiceScore;
-import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
-import org.chorem.pollen.votecounting.model.VoteCountingResult;
-import org.chorem.pollen.votecounting.model.Voter;
-
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-
-import static org.nuiton.i18n.I18n.l_;
-import static org.nuiton.i18n.I18n.n_;
-
-/**
- * Condorcet.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class BordaStrategy extends AbstractVoteCountingStrategy {
-
- public static final int ID = 4;
-
- /** Logger. */
- private static final Log log = LogFactory.getLog(BordaStrategy.class);
-
- @Override
- public int getId() {
- return ID;
- }
-
- @Override
- public String getI18nName() {
- return n_("pollen.voteCountingType.borda");
- }
-
- @Override
- public String getI18nHelp() {
- return n_("pollen.voteCountingType.borda.help");
- }
-
- @Override
- public String getTotalVoteValueNotValidMessage(Locale locale) {
- // no validation on total value, so no message
- return null;
- }
-
- @Override
- public String getVoteValueNotValidMessage(Locale locale) {
- return l_(locale, "pollen.error.vote.invalidBordaVoteValue");
- }
-
- @Override
- public String getDisplayVoteValue(Integer voteValue) {
- return voteValue == null ? "" : String.valueOf(voteValue);
- }
-
- @Override
- public ChoiceToVoteRenderType getVoteValueEditorType() {
- return ChoiceToVoteRenderType.TEXTFIELD;
- }
-
- @Override
- public boolean isChoiceInVote(Integer voteValue) {
- return voteValue != null && voteValue > 0 && voteValue < 100;
- }
-
- @Override
- public boolean isVoteValueNull(Integer voteValue) {
- return voteValue == null;
- }
-
- @Override
- public boolean isDisplayResultsByChoice() {
- return false;
- }
-
- @Override
- public boolean isVoteValueValid(Integer voteValue) {
- return voteValue != null && voteValue > 0;
- }
-
- @Override
- public boolean isTotalVoteValueValid(int totalValues) {
- // no validation on total value
- return true;
- }
-
- @Override
- public VoteCountingResult votecount(Set<Voter> voters) {
-
- // get empty result by choice
- Map<String, ChoiceScore> resultByChoice = votersToResult(voters);
-
- // nb of choices
- int nbChoices = resultByChoice.keySet().size();
-
- if (log.isDebugEnabled()) {
- log.debug("Nb choices: " + nbChoices);
- }
-
- // calcul pour chaque votant de sa liste des choix dans son ordre préféré
-
- Map<Voter, List<Set<String>>> voterSortedChoices =
- buildVoterSortedChoices(voters);
-
- // calcul des points pour chaque choix selon son ordre d'arrivé (
- // le 1er à nbChoices *weight point, le second (nbChoices-1) * weight,...)
-
- for (Map.Entry<Voter, List<Set<String>>> entry : voterSortedChoices.entrySet()) {
- Voter voter = entry.getKey();
- double weight = voter.getWeight();
- double choiceWeight = nbChoices * weight;
- for (Set<String> sortedChoiceId : entry.getValue()) {
-
- for (String choiceId : sortedChoiceId) {
-
- resultByChoice.get(choiceId).addScoreValue(choiceWeight);
- }
- choiceWeight -= weight;
- }
- }
-
- // transform map of result to list of them (and sort them)
- VoteCountingResult result = resultToList(resultByChoice);
- return result;
- }
-
-
-}
Copied: trunk/pollen-votecounting-borda/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting (from rev 3707, trunk/pollen-votecounting-strategy-borda/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy)
===================================================================
--- trunk/pollen-votecounting-borda/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting (rev 0)
+++ trunk/pollen-votecounting-borda/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1 @@
+org.chorem.pollen.votecounting.BordaVoteCounting
Property changes on: trunk/pollen-votecounting-borda/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-borda/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy
===================================================================
--- trunk/pollen-votecounting-strategy-borda/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-borda/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1 +0,0 @@
-org.chorem.pollen.votecounting.strategy.BordaStrategy
Copied: trunk/pollen-votecounting-borda/src/test/java/org/chorem/pollen/votecounting/BordaVoteCountingStrategyTest.java (from rev 3707, trunk/pollen-votecounting-strategy-borda/src/test/java/org/chorem/pollen/votecounting/strategy/BordaStrategyTest.java)
===================================================================
--- trunk/pollen-votecounting-borda/src/test/java/org/chorem/pollen/votecounting/BordaVoteCountingStrategyTest.java (rev 0)
+++ trunk/pollen-votecounting-borda/src/test/java/org/chorem/pollen/votecounting/BordaVoteCountingStrategyTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,326 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting strategy :: Borda
+ * $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.votecounting;
+
+import com.google.common.collect.Maps;
+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.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Tests the {@link BordaVoteCountingStrategy}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class BordaVoteCountingStrategyTest {
+
+ public static final String CHOICE_A = "a";
+
+ public static final String CHOICE_B = "b";
+
+ public static final String CHOICE_C = "c";
+
+ public static final String CHOICE_D = "d";
+
+ protected static VoteCounting voteCounting;
+
+ protected VoteCountingStrategy strategy;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ VoteCountingFactory factory = new VoteCountingFactory();
+ voteCounting = factory.getVoteCounting(BordaVoteCounting.ID);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ strategy = voteCounting.newVoteCountingStrategy();
+ }
+
+ @Test
+ public void simpleVotecount() throws Exception {
+
+ // see http://fr.wikipedia.org/wiki/M%C3%A9thode_Borda
+
+ // Ville 1re 2e 3e 4e Points
+ // A 42 0 0 58 226 (=42*4+58*1)
+ // B 26 42 32 0 294 (=26*4+42*3+32*2)
+ // C 15 43 42 0 273 (=15*4+43*3+42*2)
+ // D 17 15 26 42 207 (=17*4+15*3+26*2+42)
+
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("Ville A", 42.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, 3.).
+ addVoteForChoice(CHOICE_D, 4.).
+ newVoter("Ville B", 26.).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, 2.).
+ addVoteForChoice(CHOICE_D, 3.).
+ addVoteForChoice(CHOICE_A, 4.).
+ newVoter("Ville C", 15.).
+ addVoteForChoice(CHOICE_C, 1.).
+ addVoteForChoice(CHOICE_D, 2.).
+ addVoteForChoice(CHOICE_B, 3.).
+ addVoteForChoice(CHOICE_A, 4.).
+ newVoter("Ville D", 17.).
+ addVoteForChoice(CHOICE_D, 1.).
+ addVoteForChoice(CHOICE_C, 2.).
+ addVoteForChoice(CHOICE_B, 3.).
+ addVoteForChoice(CHOICE_A, 4.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(4, scores.size());
+
+ assertChoiceScore(scores.get(0), CHOICE_B, BigDecimal.valueOf(294.));
+ assertChoiceScore(scores.get(1), CHOICE_C, BigDecimal.valueOf(273.));
+ assertChoiceScore(scores.get(2), CHOICE_A, BigDecimal.valueOf(226.));
+ assertChoiceScore(scores.get(3), CHOICE_D, BigDecimal.valueOf(207.));
+ }
+
+ @Test
+ public void simpleVotecount0() throws Exception {
+
+ // Simple poll (all weight to 1)
+ // 1 (a=1 b=2 c=null) a(3) > b(2) > c(1)
+ // 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 SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, 3.).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, 1.).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, 2.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScore(scores.get(0), CHOICE_A, BigDecimal.valueOf(7.));
+ assertChoiceScore(scores.get(1), CHOICE_C, BigDecimal.valueOf(6.));
+ assertChoiceScore(scores.get(2), CHOICE_B, BigDecimal.valueOf(5.));
+ }
+
+ @Test
+ public void simpleVotecount2() throws Exception {
+
+ // Simple poll (all weight to 1)
+ // 1 (a=1 b=2 c=null) a>b>c
+ // 2 (a=1 b=2 c=1) a|c>b
+ // 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 SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, 1.).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, 2.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScore(scores.get(0), CHOICE_A, BigDecimal.valueOf(8.));
+ assertChoiceScore(scores.get(1), CHOICE_C, BigDecimal.valueOf(7.));
+ assertChoiceScore(scores.get(2), CHOICE_B, BigDecimal.valueOf(6.));
+ }
+
+ @Test
+ public void simpleVotecount3() throws Exception {
+
+ // Simple poll (all weight to 1)
+ // 1 (a=1 b=null c=null) a(3) > b|c(2)
+ // 2 (a=null b=1 c=null) b(3) > a|c(2)
+ // 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 SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, 1.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScoreEquals(BigDecimal.valueOf(7.),
+ Sets.newHashSet(scores.get(0),
+ scores.get(1),
+ scores.get(2)
+ ),
+ CHOICE_A, CHOICE_B, CHOICE_C);
+ }
+
+ @Test
+ public void weightedVotecount1() throws Exception {
+
+ // poll with weighted vote
+ // 1 (x2) (a=1 b=null c=null) a(3) > b|c (2)
+ // 2 (x1) (a=null b=1 c=null) b(3) > a|c (2)
+ // 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 SimpleVoterBuilder().
+ newVoter("1", 2.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, 2.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScore(scores.get(0), CHOICE_B, BigDecimal.valueOf(10.));
+ assertChoiceScore(scores.get(1), CHOICE_A, BigDecimal.valueOf(9.));
+ assertChoiceScore(scores.get(2), CHOICE_C, BigDecimal.valueOf(8.));
+ }
+
+ @Test
+ public void weightedVotecount2() throws Exception {
+
+ // poll with weighted vote
+ // 1 (x2) (a=1 b=null c=null) a(3) > b|c (2)
+ // 2 (x1) (a=null b=1 c=null) b(3) > a|c (2)
+ // 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 SimpleVoterBuilder().
+ newVoter("1", 2.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 3.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, 1.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScore(scores.get(0), CHOICE_C, BigDecimal.valueOf(15.));
+ assertChoiceScore(scores.get(1), CHOICE_B, BigDecimal.valueOf(13.));
+ assertChoiceScore(scores.get(2), CHOICE_A, BigDecimal.valueOf(11.));
+ }
+
+ public static void assertChoiceScore(ChoiceScore choiceScore,
+ String choiceId,
+ BigDecimal choiceResult) {
+ Assert.assertNotNull(choiceScore);
+ Assert.assertEquals(choiceId, choiceScore.getChoiceId());
+ Assert.assertEquals(choiceResult, choiceScore.getScoreValue());
+ }
+
+ public static void assertChoiceScoreEquals(BigDecimal choiceResult,
+ Set<ChoiceScore> choiceScores,
+ String... choiceIds) {
+
+ Assert.assertNotNull(choiceScores);
+ Map<String, ChoiceScore> choicesById = Maps.uniqueIndex(
+ choiceScores, new ChoiceIdAble.ChoiceIdAbleById());
+ for (String choiceId : choiceIds) {
+
+ ChoiceScore choiceScore = choicesById.get(choiceId);
+ Assert.assertNotNull(choiceScore);
+ assertChoiceScore(choiceScore, choiceId, choiceResult);
+ }
+ }
+
+}
Property changes on: trunk/pollen-votecounting-borda/src/test/java/org/chorem/pollen/votecounting/BordaVoteCountingStrategyTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-borda/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java (from rev 3707, trunk/pollen-votecounting-strategy-borda/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java)
===================================================================
--- trunk/pollen-votecounting-borda/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java (rev 0)
+++ trunk/pollen-votecounting-borda/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,43 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting strategy :: Borda
+ * $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.votecounting;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests the {@link VoteCountingFactory}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class VoteCountingFactoryTest {
+
+ @Test
+ public void getVoteCounting() throws Exception {
+ VoteCountingFactory factory = new VoteCountingFactory();
+ VoteCounting voteCounting =
+ factory.getVoteCounting(BordaVoteCounting.ID);
+ Assert.assertNotNull(voteCounting);
+ }
+}
Property changes on: trunk/pollen-votecounting-borda/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-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-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-borda/src/test/java/org/chorem/pollen/votecounting/strategy/BordaStrategyTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,325 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting strategy :: Borda
- * $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.votecounting.strategy;
-
-import com.google.common.collect.Maps;
-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.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import java.math.BigDecimal;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Tests the {@link BordaStrategy}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class BordaStrategyTest {
-
- public static final String CHOICE_A = "a";
-
- public static final String CHOICE_B = "b";
-
- public static final String CHOICE_C = "c";
-
- public static final String CHOICE_D = "d";
-
- protected static VoteCountingStrategyProvider provider;
-
- protected VoteCountingStrategy strategy;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- provider = new VoteCountingStrategyProvider();
- }
-
- @Before
- public void setUp() throws Exception {
- strategy = provider.getStrategy(BordaStrategy.ID);
- }
-
- @Test
- public void simpleVotecount() throws Exception {
-
- // see http://fr.wikipedia.org/wiki/M%C3%A9thode_Borda
-
- // Ville 1re 2e 3e 4e Points
- // A 42 0 0 58 226 (=42*4+58*1)
- // B 26 42 32 0 294 (=26*4+42*3+32*2)
- // C 15 43 42 0 273 (=15*4+43*3+42*2)
- // D 17 15 26 42 207 (=17*4+15*3+26*2+42)
-
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("Ville A", 42.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, 3.).
- addVoteForChoice(CHOICE_D, 4.).
- newVoter("Ville B", 26.).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, 2.).
- addVoteForChoice(CHOICE_D, 3.).
- addVoteForChoice(CHOICE_A, 4.).
- newVoter("Ville C", 15.).
- addVoteForChoice(CHOICE_C, 1.).
- addVoteForChoice(CHOICE_D, 2.).
- addVoteForChoice(CHOICE_B, 3.).
- addVoteForChoice(CHOICE_A, 4.).
- newVoter("Ville D", 17.).
- addVoteForChoice(CHOICE_D, 1.).
- addVoteForChoice(CHOICE_C, 2.).
- addVoteForChoice(CHOICE_B, 3.).
- addVoteForChoice(CHOICE_A, 4.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(4, scores.size());
-
- assertChoiceScore(scores.get(0), CHOICE_B, BigDecimal.valueOf(294.));
- assertChoiceScore(scores.get(1), CHOICE_C, BigDecimal.valueOf(273.));
- assertChoiceScore(scores.get(2), CHOICE_A, BigDecimal.valueOf(226.));
- assertChoiceScore(scores.get(3), CHOICE_D, BigDecimal.valueOf(207.));
- }
-
- @Test
- public void simpleVotecount0() throws Exception {
-
- // Simple poll (all weight to 1)
- // 1 (a=1 b=2 c=null) a(3) > b(2) > c(1)
- // 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 SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, 3.).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, 1.).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, 2.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScore(scores.get(0), CHOICE_A, BigDecimal.valueOf(7.));
- assertChoiceScore(scores.get(1), CHOICE_C, BigDecimal.valueOf(6.));
- assertChoiceScore(scores.get(2), CHOICE_B, BigDecimal.valueOf(5.));
- }
-
- @Test
- public void simpleVotecount2() throws Exception {
-
- // Simple poll (all weight to 1)
- // 1 (a=1 b=2 c=null) a>b>c
- // 2 (a=1 b=2 c=1) a|c>b
- // 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 SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, 1.).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, 2.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScore(scores.get(0), CHOICE_A, BigDecimal.valueOf(8.));
- assertChoiceScore(scores.get(1), CHOICE_C, BigDecimal.valueOf(7.));
- assertChoiceScore(scores.get(2), CHOICE_B, BigDecimal.valueOf(6.));
- }
-
- @Test
- public void simpleVotecount3() throws Exception {
-
- // Simple poll (all weight to 1)
- // 1 (a=1 b=null c=null) a(3) > b|c(2)
- // 2 (a=null b=1 c=null) b(3) > a|c(2)
- // 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 SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, 1.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScoreEquals(BigDecimal.valueOf(7.),
- Sets.newHashSet(scores.get(0),
- scores.get(1),
- scores.get(2)
- ),
- CHOICE_A, CHOICE_B, CHOICE_C);
- }
-
- @Test
- public void weightedVotecount1() throws Exception {
-
- // poll with weighted vote
- // 1 (x2) (a=1 b=null c=null) a(3) > b|c (2)
- // 2 (x1) (a=null b=1 c=null) b(3) > a|c (2)
- // 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 SimpleVoterBuilder().
- newVoter("1", 2.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, 2.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScore(scores.get(0), CHOICE_B, BigDecimal.valueOf(10.));
- assertChoiceScore(scores.get(1), CHOICE_A, BigDecimal.valueOf(9.));
- assertChoiceScore(scores.get(2), CHOICE_C, BigDecimal.valueOf(8.));
- }
-
- @Test
- public void weightedVotecount2() throws Exception {
-
- // poll with weighted vote
- // 1 (x2) (a=1 b=null c=null) a(3) > b|c (2)
- // 2 (x1) (a=null b=1 c=null) b(3) > a|c (2)
- // 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 SimpleVoterBuilder().
- newVoter("1", 2.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 3.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, 1.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScore(scores.get(0), CHOICE_C, BigDecimal.valueOf(15.));
- assertChoiceScore(scores.get(1), CHOICE_B, BigDecimal.valueOf(13.));
- assertChoiceScore(scores.get(2), CHOICE_A, BigDecimal.valueOf(11.));
- }
-
- public static void assertChoiceScore(ChoiceScore choiceScore,
- String choiceId,
- BigDecimal choiceResult) {
- Assert.assertNotNull(choiceScore);
- Assert.assertEquals(choiceId, choiceScore.getChoiceId());
- Assert.assertEquals(choiceResult, choiceScore.getScoreValue());
- }
-
- public static void assertChoiceScoreEquals(BigDecimal choiceResult,
- Set<ChoiceScore> choiceScores,
- String... choiceIds) {
-
- Assert.assertNotNull(choiceScores);
- Map<String, ChoiceScore> choicesById = Maps.uniqueIndex(
- choiceScores, new ChoiceIdAble.ChoiceIdAbleById());
- for (String choiceId : choiceIds) {
-
- ChoiceScore choiceScore = choicesById.get(choiceId);
- Assert.assertNotNull(choiceScore);
- assertChoiceScore(choiceScore, choiceId, choiceResult);
- }
- }
-
-}
Deleted: trunk/pollen-votecounting-borda/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java
===================================================================
--- trunk/pollen-votecounting-strategy-borda/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-borda/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,49 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting strategy :: Borda
- * $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.votecounting.strategy;
-
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * Tests the {@link VoteCountingStrategyProvider}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class VoteCountingStrategyProviderTest {
-
- protected static VoteCountingStrategyProvider provider;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- provider = new VoteCountingStrategyProvider();
- }
-
- @Test
- public void getStrategy() throws Exception {
-
- Assert.assertNotNull(provider.getStrategy(BordaStrategy.ID));
- }
-}
Modified: trunk/pollen-votecounting-condorcet/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy-condorcet/pom.xml 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-condorcet/pom.xml 2012-09-29 12:36:25 UTC (rev 3708)
@@ -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>
@@ -10,11 +12,10 @@
</parent>
<groupId>org.chorem.pollen</groupId>
- <artifactId>pollen-votecounting-strategy-condorcet</artifactId>
+ <artifactId>pollen-votecounting-condorcet</artifactId>
+ <name>Pollen :: VoteCounting :: Condorcet</name>
+ <description>Implements the condorcet vote counting</description>
- <name>Pollen :: VoteCounting strategy :: Condorcet</name>
- <description>Implements the condorcet vote counting strategy</description>
-
<dependencies>
<dependency>
@@ -27,16 +28,24 @@
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
+
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
+
<dependency>
<groupId>org.nuiton.i18n</groupId>
<artifactId>nuiton-i18n</artifactId>
</dependency>
<dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
Added: trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCounting.java (rev 0)
+++ trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCounting.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,69 @@
+package org.chorem.pollen.votecounting;
+
+import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
+
+import java.util.Locale;
+
+import static org.nuiton.i18n.I18n.l_;
+import static org.nuiton.i18n.I18n.n_;
+
+/**
+ * Coombs vote counting entry point.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.6
+ */
+public class CondorcetVoteCounting extends AbstractVoteCounting<CondorcetVoteCountingStrategy> {
+
+ public static final int ID = 2;
+
+ public CondorcetVoteCounting() {
+ super(ID,
+ CondorcetVoteCountingStrategy.class,
+ n_("pollen.voteCountingType.condorcet"),
+ n_("pollen.voteCountingType.condorcet.help")
+ );
+ }
+
+ @Override
+ public String getTotalVoteValueNotValidMessage(Locale locale) {
+ // no validation on total value, so no message
+ return null;
+ }
+
+ @Override
+ public String getVoteValueNotValidMessage(Locale locale) {
+ return l_(locale, "pollen.error.vote.invalidCondorcetVoteValue");
+ }
+
+ @Override
+ public String getDisplayVoteValue(Integer voteValue) {
+ return voteValue == null ? "" : String.valueOf(voteValue);
+ }
+
+ @Override
+ public ChoiceToVoteRenderType getVoteValueEditorType() {
+ return ChoiceToVoteRenderType.TEXTFIELD;
+ }
+
+ @Override
+ public boolean isChoiceInVote(Integer voteValue) {
+ return voteValue != null && voteValue > 0 && voteValue < 100;
+ }
+
+ @Override
+ public boolean isVoteValueNull(Integer voteValue) {
+ return voteValue == null;
+ }
+
+ @Override
+ public boolean isVoteValueValid(Integer voteValue) {
+ return voteValue != null && voteValue > 0;
+ }
+
+ @Override
+ public boolean isTotalVoteValueValid(int totalValues) {
+ // no validation on total value
+ return true;
+ }
+}
Property changes on: trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCounting.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCountingStrategy.java (from rev 3707, trunk/pollen-votecounting-strategy-condorcet/src/main/java/org/chorem/pollen/votecounting/strategy/CondorcetStrategy.java)
===================================================================
--- trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCountingStrategy.java (rev 0)
+++ trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCountingStrategy.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,247 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting strategy :: Condorcet
+ * $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.votecounting;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.votecounting.model.ChoiceIdAble;
+import org.chorem.pollen.votecounting.model.ChoiceScore;
+import org.chorem.pollen.votecounting.model.VoteCountingResult;
+import org.chorem.pollen.votecounting.model.VoteForChoice;
+import org.chorem.pollen.votecounting.model.Voter;
+
+import java.math.BigDecimal;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Condorcet.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class CondorcetVoteCountingStrategy extends AbstractVoteCountingStrategy {
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(CondorcetVoteCountingStrategy.class);
+
+ @Override
+ public VoteCountingResult votecount(Set<Voter> voters) {
+
+ // get empty result by choice
+ Map<String, ChoiceScore> resultByChoice = votersToResult(voters);
+
+ // get order over choices (needed to get coordinates over matrix)
+ List<String> choiceIds = Lists.newArrayList(resultByChoice.keySet());
+
+ // nb of choices
+ int nbChoices = choiceIds.size();
+
+ //matrix of pairwise
+ double[][] matrix = new double[nbChoices][nbChoices];
+
+ // compute pairwise battle matrix and try to have a direct winner(s)
+ Set<String> winners = computePairWiseMatrix(choiceIds, voters, matrix);
+
+ // compute nb battles wins for each choice
+ // and store it as choice score value
+ computeNbBattlesByChoice(resultByChoice, choiceIds, matrix);
+
+ // get choice score ordered by their number of win battles
+ List<ChoiceScore> choiceScores = toChoiceScore(resultByChoice);
+
+ if (winners != null) {
+
+ // there is winner(s), re-add them to
+
+ if (log.isDebugEnabled()) {
+ log.debug("Direct winners : " + winners);
+ }
+ for (String choiceId : winners) {
+ ChoiceScore choiceScore = resultByChoice.get(choiceId);
+ choiceScores.remove(choiceScore);
+ choiceScores.add(0, choiceScore);
+ }
+ } else {
+
+ // no direct winner, must resolv conflicts
+
+ resolvConflicts(choiceScores, matrix);
+ }
+
+ // transform map of result to list of them (and sort them)
+ VoteCountingResult result = resultToList(resultByChoice);
+ return result;
+ }
+
+ protected void resolvConflicts(List<ChoiceScore> choiceScores,
+ double[][] matrix) {
+
+ // for the moment we use only number of win battles
+ // so nothing more to do here...
+ }
+
+ protected void computeNbBattlesByChoice(Map<String, ChoiceScore> resultByChoice,
+ List<String> choiceIds,
+ double[][] matrix) {
+
+ int nbChoices = choiceIds.size();
+
+ for (String choiceId : choiceIds) {
+
+ int i = choiceIds.indexOf(choiceId);
+
+ double nbBattles = 0;
+ for (int j = 0; j < nbChoices; j++) {
+ double aRow = matrix[i][j];
+ nbBattles += aRow;
+ }
+
+ resultByChoice.get(choiceId).setScoreValue(
+ BigDecimal.valueOf(nbBattles));
+
+ if (log.isDebugEnabled()) {
+ log.debug("Nb battle wins for choice " + choiceId + ": " + nbBattles);
+ }
+ }
+ }
+
+ private Set<String> computePairWiseMatrix(List<String> choiceIds,
+ Set<Voter> voters,
+ double[][] matrix) {
+
+ int nbChoices = choiceIds.size();
+
+ Set<String> winners = null;
+
+ VoteForChoiceComparator comparator = new VoteForChoiceComparator();
+
+ double[] currentVoteWinner = new double[choiceIds.size()];
+
+ boolean firstVoter = true;
+ for (Voter voter : voters) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Start count for voter " + voter.getVoterId());
+ }
+ double voterWeight = voter.getWeight();
+
+ Arrays.fill(currentVoteWinner, 0);
+
+ Map<String, VoteForChoice> voteByChoiceIds =
+ Maps.uniqueIndex(voter.getVoteForChoices(),
+ new ChoiceIdAble.ChoiceIdAbleById());
+
+ double maxBattleWins = 0;
+
+ for (String choiceId : choiceIds) {
+
+ // get vote for this choice
+ VoteForChoice voteForChoice = voteByChoiceIds.get(choiceId);
+
+ int x = choiceIds.indexOf(choiceId);
+
+ for (VoteForChoice voteForChoice1 : voter.getVoteForChoices()) {
+
+ String choiceId1 = voteForChoice1.getChoiceId();
+ if (choiceId.equals(choiceId1)) {
+
+ // can not battle same choice
+ continue;
+ }
+
+ int y = choiceIds.indexOf(choiceId1);
+
+ int compare = comparator.compare(voteForChoice,
+ voteForChoice1);
+
+ if (compare < 0) {
+
+ // voteForChoice wins his battle
+
+ int pos = x * nbChoices + y;
+
+ matrix[x][y] = matrix[x][y] + voterWeight;
+ if (log.isTraceEnabled()) {
+ log.trace("battle [" + choiceId + "<" +
+ voteForChoice.getVoteValue() + "> - " +
+ choiceId1 + "<" +
+ voteForChoice1.getVoteValue() +
+ ">] wins (store to " + pos +
+ ", new value=" + matrix[x][y] + ")");
+ }
+ maxBattleWins = Math.max(
+ maxBattleWins,
+ currentVoteWinner[x] =
+ currentVoteWinner[x] + voterWeight);
+ }
+ }
+ }
+
+ if (firstVoter || winners != null) {
+
+ // still have a winner, le'ts compute current winner
+ Set<String> currentVoteWinners = Sets.newHashSet();
+
+ // find winners of this vote
+ for (int i = 0; i < currentVoteWinner.length; i++) {
+ if (maxBattleWins == currentVoteWinner[i]) {
+
+ // this is a winner for this vote
+ String choiceId = choiceIds.get(i);
+ currentVoteWinners.add(choiceId);
+ }
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Winners of this vote : " + currentVoteWinners);
+ }
+
+
+ if (firstVoter) {
+
+ // keep this first result
+ winners = currentVoteWinners;
+ } else if (!winners.equals(currentVoteWinners)) {
+
+ // current vote has not same winners than previous,
+ // so will need resolution
+ winners = null;
+
+ if (log.isDebugEnabled()) {
+ log.debug("Dismatch winners (will need resolv...)");
+ }
+ }
+ }
+
+ firstVoter = false;
+ }
+ return winners;
+ }
+
+}
Property changes on: trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCountingStrategy.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/strategy/CondorcetStrategy.java
===================================================================
--- trunk/pollen-votecounting-strategy-condorcet/src/main/java/org/chorem/pollen/votecounting/strategy/CondorcetStrategy.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/strategy/CondorcetStrategy.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,315 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting strategy :: Condorcet
- * $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.votecounting.strategy;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.votecounting.model.ChoiceIdAble;
-import org.chorem.pollen.votecounting.model.ChoiceScore;
-import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
-import org.chorem.pollen.votecounting.model.VoteCountingResult;
-import org.chorem.pollen.votecounting.model.VoteForChoice;
-import org.chorem.pollen.votecounting.model.Voter;
-
-import java.math.BigDecimal;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-
-import static org.nuiton.i18n.I18n.l_;
-import static org.nuiton.i18n.I18n.n_;
-
-/**
- * Condorcet.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class CondorcetStrategy extends AbstractVoteCountingStrategy {
-
- public static final int ID = 2;
-
- /** Logger. */
- private static final Log log = LogFactory.getLog(CondorcetStrategy.class);
-
- @Override
- public int getId() {
- return ID;
- }
-
- @Override
- public String getI18nName() {
- return n_("pollen.voteCountingType.condorcet");
- }
-
- @Override
- public String getI18nHelp() {
- return n_("pollen.voteCountingType.condorcet.help");
- }
-
- @Override
- public String getTotalVoteValueNotValidMessage(Locale locale) {
- // no validation on total value, so no message
- return null;
- }
-
- @Override
- public String getVoteValueNotValidMessage(Locale locale) {
- return l_(locale, "pollen.error.vote.invalidCondorcetVoteValue");
- }
-
- @Override
- public String getDisplayVoteValue(Integer voteValue) {
- return voteValue == null ? "" : String.valueOf(voteValue);
- }
-
- @Override
- public ChoiceToVoteRenderType getVoteValueEditorType() {
- return ChoiceToVoteRenderType.TEXTFIELD;
- }
-
- @Override
- public boolean isChoiceInVote(Integer voteValue) {
- return voteValue != null && voteValue > 0 && voteValue < 100;
- }
-
- @Override
- public boolean isVoteValueNull(Integer voteValue) {
- return voteValue == null;
- }
-
- @Override
- public boolean isDisplayResultsByChoice() {
- return false;
- }
-
- @Override
- public boolean isVoteValueValid(Integer voteValue) {
- return voteValue != null && voteValue > 0;
- }
-
- @Override
- public boolean isTotalVoteValueValid(int totalValues) {
- // no validation on total value
- return true;
- }
-
- @Override
- public VoteCountingResult votecount(Set<Voter> voters) {
-
- // get empty result by choice
- Map<String, ChoiceScore> resultByChoice = votersToResult(voters);
-
- // get order over choices (needed to get coordinates over matrix)
- List<String> choiceIds = Lists.newArrayList(resultByChoice.keySet());
-
- // nb of choices
- int nbChoices = choiceIds.size();
-
- //matrix of pairwise
- double[][] matrix = new double[nbChoices][nbChoices];
-
- // compute pairwise battle matrix and try to have a direct winner(s)
- Set<String> winners = computePairWiseMatrix(choiceIds, voters, matrix);
-
- // compute nb battles wins for each choice
- // and store it as choice score value
- computeNbBattlesByChoice(resultByChoice, choiceIds, matrix);
-
- // get choice score ordered by their number of win battles
- List<ChoiceScore> choiceScores = toChoiceScore(resultByChoice);
-
- if (winners != null) {
-
- // there is winner(s), re-add them to
-
- if (log.isDebugEnabled()) {
- log.debug("Direct winners : " + winners);
- }
- for (String choiceId : winners) {
- ChoiceScore choiceScore = resultByChoice.get(choiceId);
- choiceScores.remove(choiceScore);
- choiceScores.add(0, choiceScore);
- }
- } else {
-
- // no direct winner, must resolv conflicts
-
- resolvConflicts(choiceScores, matrix);
- }
-
- // transform map of result to list of them (and sort them)
- VoteCountingResult result = resultToList(resultByChoice);
- return result;
- }
-
- protected void resolvConflicts(List<ChoiceScore> choiceScores,
- double[][] matrix) {
-
- // for the moment we use only number of win battles
- // so nothing more to do here...
- }
-
- protected void computeNbBattlesByChoice(Map<String, ChoiceScore> resultByChoice,
- List<String> choiceIds,
- double[][] matrix) {
-
- int nbChoices = choiceIds.size();
-
- for (String choiceId : choiceIds) {
-
- int i = choiceIds.indexOf(choiceId);
-
- double nbBattles = 0;
- for (int j = 0; j < nbChoices; j++) {
- double aRow = matrix[i][j];
- nbBattles += aRow;
- }
-
- resultByChoice.get(choiceId).setScoreValue(
- BigDecimal.valueOf(nbBattles));
-
- if (log.isDebugEnabled()) {
- log.debug("Nb battle wins for choice " + choiceId + ": " + nbBattles);
- }
- }
- }
-
- private Set<String> computePairWiseMatrix(List<String> choiceIds,
- Set<Voter> voters,
- double[][] matrix) {
-
- int nbChoices = choiceIds.size();
-
- Set<String> winners = null;
-
- VoteForChoiceComparator comparator = new VoteForChoiceComparator();
-
- double[] currentVoteWinner = new double[choiceIds.size()];
-
- boolean firstVoter = true;
- for (Voter voter : voters) {
-
- if (log.isDebugEnabled()) {
- log.debug("Start count for voter " + voter.getVoterId());
- }
- double voterWeight = voter.getWeight();
-
- Arrays.fill(currentVoteWinner, 0);
-
- Map<String, VoteForChoice> voteByChoiceIds =
- Maps.uniqueIndex(voter.getVoteForChoices(),
- new ChoiceIdAble.ChoiceIdAbleById());
-
- double maxBattleWins = 0;
-
- for (String choiceId : choiceIds) {
-
- // get vote for this choice
- VoteForChoice voteForChoice = voteByChoiceIds.get(choiceId);
-
- int x = choiceIds.indexOf(choiceId);
-
- for (VoteForChoice voteForChoice1 : voter.getVoteForChoices()) {
-
- String choiceId1 = voteForChoice1.getChoiceId();
- if (choiceId.equals(choiceId1)) {
-
- // can not battle same choice
- continue;
- }
-
- int y = choiceIds.indexOf(choiceId1);
-
- int compare = comparator.compare(voteForChoice,
- voteForChoice1);
-
- if (compare < 0) {
-
- // voteForChoice wins his battle
-
- int pos = x * nbChoices + y;
-
- matrix[x][y] = matrix[x][y] + voterWeight;
- if (log.isTraceEnabled()) {
- log.trace("battle [" + choiceId + "<" +
- voteForChoice.getVoteValue() + "> - " +
- choiceId1 + "<" +
- voteForChoice1.getVoteValue() +
- ">] wins (store to " + pos +
- ", new value=" + matrix[x][y] + ")");
- }
- maxBattleWins = Math.max(
- maxBattleWins,
- currentVoteWinner[x] =
- currentVoteWinner[x] + voterWeight);
- }
- }
- }
-
- if (firstVoter || winners != null) {
-
- // still have a winner, le'ts compute current winner
- Set<String> currentVoteWinners = Sets.newHashSet();
-
- // find winners of this vote
- for (int i = 0; i < currentVoteWinner.length; i++) {
- if (maxBattleWins == currentVoteWinner[i]) {
-
- // this is a winner for this vote
- String choiceId = choiceIds.get(i);
- currentVoteWinners.add(choiceId);
- }
- }
- if (log.isDebugEnabled()) {
- log.debug("Winners of this vote : " + currentVoteWinners);
- }
-
-
- if (firstVoter) {
-
- // keep this first result
- winners = currentVoteWinners;
- } else if (!winners.equals(currentVoteWinners)) {
-
- // current vote has not same winners than previous,
- // so will need resolution
- winners = null;
-
- if (log.isDebugEnabled()) {
- log.debug("Dismatch winners (will need resolv...)");
- }
- }
- }
-
- firstVoter = false;
- }
- return winners;
- }
-
-}
Copied: trunk/pollen-votecounting-condorcet/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting (from rev 3707, trunk/pollen-votecounting-strategy-condorcet/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy)
===================================================================
--- trunk/pollen-votecounting-condorcet/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting (rev 0)
+++ trunk/pollen-votecounting-condorcet/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1 @@
+org.chorem.pollen.votecounting.CondorcetVoteCounting
Property changes on: trunk/pollen-votecounting-condorcet/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-condorcet/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy
===================================================================
--- trunk/pollen-votecounting-strategy-condorcet/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-condorcet/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1 +0,0 @@
-org.chorem.pollen.votecounting.strategy.CondorcetStrategy
Copied: trunk/pollen-votecounting-condorcet/src/test/java/org/chorem/pollen/votecounting/CondorcetVoteCountingStrategyTest.java (from rev 3707, trunk/pollen-votecounting-strategy-condorcet/src/test/java/org/chorem/pollen/votecounting/strategy/CondorcetStrategyTest.java)
===================================================================
--- trunk/pollen-votecounting-condorcet/src/test/java/org/chorem/pollen/votecounting/CondorcetVoteCountingStrategyTest.java (rev 0)
+++ trunk/pollen-votecounting-condorcet/src/test/java/org/chorem/pollen/votecounting/CondorcetVoteCountingStrategyTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,317 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting strategy :: Condorcet
+ * $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.votecounting;
+
+import com.google.common.collect.Maps;
+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.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Tests the {@link CondorcetVoteCountingStrategy}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class CondorcetVoteCountingStrategyTest {
+
+ public static final String CHOICE_A = "a";
+
+ public static final String CHOICE_B = "b";
+
+ public static final String CHOICE_C = "c";
+
+ protected static VoteCounting voteCounting;
+
+ protected VoteCountingStrategy strategy;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ VoteCountingFactory factory = new VoteCountingFactory();
+ voteCounting = factory.getVoteCounting(CondorcetVoteCounting.ID);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ strategy = voteCounting.newVoteCountingStrategy();
+ }
+
+ @Test
+ public void simpleVotecount() throws Exception {
+
+ // Simple poll (all weight to 1)
+ // 1 (a=1 b=2 c=null)
+ // 2 (a=1 b=3 c=2)
+ // 3 (a=1 b=null c=2)
+ // Result (a=6 b=1 c=2)
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 3.).
+ addVoteForChoice(CHOICE_C, 2.).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, 2.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScore(scores.get(0), CHOICE_A, BigDecimal.valueOf(6.));
+ assertChoiceScore(scores.get(1), CHOICE_C, BigDecimal.valueOf(2.));
+ assertChoiceScore(scores.get(2), CHOICE_B, BigDecimal.valueOf(1.));
+ }
+
+ @Test
+ public void simpleVotecount0() throws Exception {
+
+ // Simple poll (all weight to 1)
+ // 1 (a=1 b=2 c=null)
+ // 2 (a=3 b=2 c=1)
+ // 3 (a=1 b=null c=2)
+ // Result (a=4 b=2 c=3)
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, 3.).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, 1.).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, 2.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScore(scores.get(0), CHOICE_A, BigDecimal.valueOf(4.));
+ assertChoiceScore(scores.get(1), CHOICE_C, BigDecimal.valueOf(3.));
+ assertChoiceScore(scores.get(2), CHOICE_B, BigDecimal.valueOf(2.));
+ }
+
+ @Test
+ public void simpleVotecount2() throws Exception {
+
+ // Simple poll (all weight to 1)
+ // 1 (a=1 b=2 c=null)
+ // 2 (a=1 b=2 c=1)
+ // 3 (a=null b=null c=2)
+ // Result (a=3 b=1 c=3)
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, 1.).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, 2.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScoreEquals(BigDecimal.valueOf(3.),
+ Sets.newHashSet(scores.get(0),
+ scores.get(1)),
+ CHOICE_A, CHOICE_C);
+ assertChoiceScore(scores.get(2), CHOICE_B, BigDecimal.valueOf(1.));
+ }
+
+ @Test
+ public void simpleVotecount3() throws Exception {
+
+ // Simple poll (all weight to 1)
+ // 1 (a=1 b=null c=null)
+ // 2 (a=null b=1 c=null)
+ // 3 (a=null b=null c=1)
+ // Result (a=2 b=2 c=2)
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, 1.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScoreEquals(BigDecimal.valueOf(2.),
+ Sets.newHashSet(scores.get(0),
+ scores.get(1),
+ scores.get(2)
+ ),
+ CHOICE_A, CHOICE_B, CHOICE_C);
+ }
+
+ @Test
+ public void weightedVotecount1() throws Exception {
+
+ // poll with weighted vote
+ // 1 (x2) (a=1 b=null c=null)
+ // 2 (x1) (a=null b=1 c=null)
+ // 3 (x1) (a=null b=1 c=2)
+ // Result (a=2 b=2 c=1)
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("1", 2.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, 2.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScoreEquals(BigDecimal.valueOf(4.),
+ Sets.newHashSet(scores.get(0),
+ scores.get(1)),
+ CHOICE_A, CHOICE_B);
+ assertChoiceScore(scores.get(2), CHOICE_C, BigDecimal.valueOf(1.));
+ }
+
+ @Test
+ public void weightedVotecount2() throws Exception {
+
+ // poll with weighted vote
+ // 1 (x2) (a=1 b=null c=null)
+ // 2 (x1) (a=null b=1 c=null)
+ // 3 (x3) (a=null b=2 c=1)
+ // Result (a=2 b=4 c=3)
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("1", 2.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 3.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, 1.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScore(scores.get(0), CHOICE_C, BigDecimal.valueOf(6.));
+ assertChoiceScore(scores.get(1), CHOICE_B, BigDecimal.valueOf(5.));
+ assertChoiceScore(scores.get(2), CHOICE_A, BigDecimal.valueOf(4.));
+ }
+
+ public static void assertChoiceScore(ChoiceScore choiceScore,
+ String choiceId,
+ BigDecimal choiceResult) {
+ Assert.assertNotNull(choiceScore);
+ Assert.assertEquals(choiceId, choiceScore.getChoiceId());
+ Assert.assertEquals(choiceResult, choiceScore.getScoreValue());
+ }
+
+ public static void assertChoiceScoreEquals(BigDecimal choiceResult,
+ Set<ChoiceScore> choiceScores,
+ String... choiceIds) {
+
+ Assert.assertNotNull(choiceScores);
+ Map<String, ChoiceScore> choicesById = Maps.uniqueIndex(
+ choiceScores, new ChoiceIdAble.ChoiceIdAbleById());
+ for (String choiceId : choiceIds) {
+
+ ChoiceScore choiceScore = choicesById.get(choiceId);
+ Assert.assertNotNull(choiceScore);
+ assertChoiceScore(choiceScore, choiceId, choiceResult);
+ }
+ }
+
+}
Property changes on: trunk/pollen-votecounting-condorcet/src/test/java/org/chorem/pollen/votecounting/CondorcetVoteCountingStrategyTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-condorcet/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java (from rev 3707, trunk/pollen-votecounting-strategy-condorcet/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java)
===================================================================
--- trunk/pollen-votecounting-condorcet/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java (rev 0)
+++ trunk/pollen-votecounting-condorcet/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,43 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting strategy :: Condorcet
+ * $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.votecounting;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests the {@link VoteCountingFactory}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class VoteCountingFactoryTest {
+
+ @Test
+ public void getVoteCounting() throws Exception {
+ VoteCountingFactory factory = new VoteCountingFactory();
+ VoteCounting voteCounting =
+ factory.getVoteCounting(CondorcetVoteCounting.ID);
+ Assert.assertNotNull(voteCounting);
+ }
+}
Property changes on: trunk/pollen-votecounting-condorcet/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-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-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-condorcet/src/test/java/org/chorem/pollen/votecounting/strategy/CondorcetStrategyTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,316 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting strategy :: Condorcet
- * $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.votecounting.strategy;
-
-import com.google.common.collect.Maps;
-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.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import java.math.BigDecimal;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Tests the {@link CondorcetStrategy}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class CondorcetStrategyTest {
-
- public static final String CHOICE_A = "a";
-
- public static final String CHOICE_B = "b";
-
- public static final String CHOICE_C = "c";
-
- protected static VoteCountingStrategyProvider provider;
-
- protected VoteCountingStrategy strategy;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- provider = new VoteCountingStrategyProvider();
- }
-
- @Before
- public void setUp() throws Exception {
- strategy = provider.getStrategy(CondorcetStrategy.ID);
- }
-
- @Test
- public void simpleVotecount() throws Exception {
-
- // Simple poll (all weight to 1)
- // 1 (a=1 b=2 c=null)
- // 2 (a=1 b=3 c=2)
- // 3 (a=1 b=null c=2)
- // Result (a=6 b=1 c=2)
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 3.).
- addVoteForChoice(CHOICE_C, 2.).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, 2.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScore(scores.get(0), CHOICE_A, BigDecimal.valueOf(6.));
- assertChoiceScore(scores.get(1), CHOICE_C, BigDecimal.valueOf(2.));
- assertChoiceScore(scores.get(2), CHOICE_B, BigDecimal.valueOf(1.));
- }
-
- @Test
- public void simpleVotecount0() throws Exception {
-
- // Simple poll (all weight to 1)
- // 1 (a=1 b=2 c=null)
- // 2 (a=3 b=2 c=1)
- // 3 (a=1 b=null c=2)
- // Result (a=4 b=2 c=3)
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, 3.).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, 1.).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, 2.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScore(scores.get(0), CHOICE_A, BigDecimal.valueOf(4.));
- assertChoiceScore(scores.get(1), CHOICE_C, BigDecimal.valueOf(3.));
- assertChoiceScore(scores.get(2), CHOICE_B, BigDecimal.valueOf(2.));
- }
-
- @Test
- public void simpleVotecount2() throws Exception {
-
- // Simple poll (all weight to 1)
- // 1 (a=1 b=2 c=null)
- // 2 (a=1 b=2 c=1)
- // 3 (a=null b=null c=2)
- // Result (a=3 b=1 c=3)
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, 1.).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, 2.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScoreEquals(BigDecimal.valueOf(3.),
- Sets.newHashSet(scores.get(0),
- scores.get(1)),
- CHOICE_A, CHOICE_C);
- assertChoiceScore(scores.get(2), CHOICE_B, BigDecimal.valueOf(1.));
- }
-
- @Test
- public void simpleVotecount3() throws Exception {
-
- // Simple poll (all weight to 1)
- // 1 (a=1 b=null c=null)
- // 2 (a=null b=1 c=null)
- // 3 (a=null b=null c=1)
- // Result (a=2 b=2 c=2)
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, 1.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScoreEquals(BigDecimal.valueOf(2.),
- Sets.newHashSet(scores.get(0),
- scores.get(1),
- scores.get(2)
- ),
- CHOICE_A, CHOICE_B, CHOICE_C);
- }
-
- @Test
- public void weightedVotecount1() throws Exception {
-
- // poll with weighted vote
- // 1 (x2) (a=1 b=null c=null)
- // 2 (x1) (a=null b=1 c=null)
- // 3 (x1) (a=null b=1 c=2)
- // Result (a=2 b=2 c=1)
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("1", 2.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, 2.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScoreEquals(BigDecimal.valueOf(4.),
- Sets.newHashSet(scores.get(0),
- scores.get(1)),
- CHOICE_A, CHOICE_B);
- assertChoiceScore(scores.get(2), CHOICE_C, BigDecimal.valueOf(1.));
- }
-
- @Test
- public void weightedVotecount2() throws Exception {
-
- // poll with weighted vote
- // 1 (x2) (a=1 b=null c=null)
- // 2 (x1) (a=null b=1 c=null)
- // 3 (x3) (a=null b=2 c=1)
- // Result (a=2 b=4 c=3)
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("1", 2.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 3.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, 1.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScore(scores.get(0), CHOICE_C, BigDecimal.valueOf(6.));
- assertChoiceScore(scores.get(1), CHOICE_B, BigDecimal.valueOf(5.));
- assertChoiceScore(scores.get(2), CHOICE_A, BigDecimal.valueOf(4.));
- }
-
- public static void assertChoiceScore(ChoiceScore choiceScore,
- String choiceId,
- BigDecimal choiceResult) {
- Assert.assertNotNull(choiceScore);
- Assert.assertEquals(choiceId, choiceScore.getChoiceId());
- Assert.assertEquals(choiceResult, choiceScore.getScoreValue());
- }
-
- public static void assertChoiceScoreEquals(BigDecimal choiceResult,
- Set<ChoiceScore> choiceScores,
- String... choiceIds) {
-
- Assert.assertNotNull(choiceScores);
- Map<String, ChoiceScore> choicesById = Maps.uniqueIndex(
- choiceScores, new ChoiceIdAble.ChoiceIdAbleById());
- for (String choiceId : choiceIds) {
-
- ChoiceScore choiceScore = choicesById.get(choiceId);
- Assert.assertNotNull(choiceScore);
- assertChoiceScore(choiceScore, choiceId, choiceResult);
- }
- }
-
-}
Deleted: trunk/pollen-votecounting-condorcet/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java
===================================================================
--- trunk/pollen-votecounting-strategy-condorcet/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-condorcet/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,49 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting strategy :: Condorcet
- * $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.votecounting.strategy;
-
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * Tests the {@link VoteCountingStrategyProvider}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class VoteCountingStrategyProviderTest {
-
- protected static VoteCountingStrategyProvider provider;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- provider = new VoteCountingStrategyProvider();
- }
-
- @Test
- public void getStrategy() throws Exception {
-
- Assert.assertNotNull(provider.getStrategy(CondorcetStrategy.ID));
- }
-}
Modified: trunk/pollen-votecounting-coombs/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy-coombs/pom.xml 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-coombs/pom.xml 2012-09-29 12:36:25 UTC (rev 3708)
@@ -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>
@@ -10,11 +12,10 @@
</parent>
<groupId>org.chorem.pollen</groupId>
- <artifactId>pollen-votecounting-strategy-coombs</artifactId>
+ <artifactId>pollen-votecounting-coombs</artifactId>
+ <name>Pollen :: VoteCounting :: Coombs</name>
+ <description>Implements the coombs vote counting</description>
- <name>Pollen :: VoteCounting strategy :: Coombs</name>
- <description>Implements the coombs vote counting strategy</description>
-
<dependencies>
<dependency>
@@ -39,6 +40,12 @@
</dependency>
<dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
Added: trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCounting.java (rev 0)
+++ trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCounting.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,69 @@
+package org.chorem.pollen.votecounting;
+
+import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
+
+import java.util.Locale;
+
+import static org.nuiton.i18n.I18n.l_;
+import static org.nuiton.i18n.I18n.n_;
+
+/**
+ * Coombs vote counting entry point.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.6
+ */
+public class CoombsVoteCounting extends AbstractVoteCounting<CoombsVoteCountingStrategy> {
+
+ public static final int ID = 6;
+
+ public CoombsVoteCounting() {
+ super(ID,
+ CoombsVoteCountingStrategy.class,
+ n_("pollen.voteCountingType.coombs"),
+ n_("pollen.voteCountingType.coombs.help")
+ );
+ }
+
+ @Override
+ public String getTotalVoteValueNotValidMessage(Locale locale) {
+ // no validation on total value, so no message
+ return null;
+ }
+
+ @Override
+ public String getVoteValueNotValidMessage(Locale locale) {
+ return l_(locale, "pollen.error.vote.invalidCoombsVoteValue");
+ }
+
+ @Override
+ public String getDisplayVoteValue(Integer voteValue) {
+ return voteValue == null ? "" : String.valueOf(voteValue);
+ }
+
+ @Override
+ public ChoiceToVoteRenderType getVoteValueEditorType() {
+ return ChoiceToVoteRenderType.TEXTFIELD;
+ }
+
+ @Override
+ public boolean isChoiceInVote(Integer voteValue) {
+ return voteValue != null && voteValue > 0 && voteValue < 100;
+ }
+
+ @Override
+ public boolean isVoteValueNull(Integer voteValue) {
+ return voteValue == null;
+ }
+
+ @Override
+ public boolean isVoteValueValid(Integer voteValue) {
+ return voteValue != null && voteValue > 0;
+ }
+
+ @Override
+ public boolean isTotalVoteValueValid(int totalValues) {
+ // no validation on total value
+ return true;
+ }
+}
Property changes on: trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCounting.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCountingStrategy.java (from rev 3707, trunk/pollen-votecounting-strategy-coombs/src/main/java/org/chorem/pollen/votecounting/strategy/CoombsStrategy.java)
===================================================================
--- trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCountingStrategy.java (rev 0)
+++ trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCountingStrategy.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,241 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting strategy :: Coombs
+ * $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.votecounting;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import org.apache.commons.collections.CollectionUtils;
+import org.chorem.pollen.votecounting.model.ChoiceScore;
+import org.chorem.pollen.votecounting.model.VoteCountingResult;
+import org.chorem.pollen.votecounting.model.Voter;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+
+/**
+ * Coombs vote counting strategy.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class CoombsVoteCountingStrategy extends AbstractVoteCountingStrategy {
+
+ @Override
+ public VoteCountingResult votecount(Set<Voter> voters) {
+
+ // get empty result by choice
+ SortedMap<String, ChoiceScore> resultByChoice = votersToResult(voters);
+
+ // calcul du score minimum pour atteindre la majorité absolue
+ double totalWeight = 0.;
+ for (Voter voter : voters) {
+ totalWeight += voter.getWeight();
+ }
+ totalWeight /= 2;
+
+ // calcul pour chaque votant de ses choix préférés
+ Map<Voter, List<Set<String>>> topRankChoices =
+ buildVoterSortedChoices(voters);
+
+ Set<String> choiceIdsToExclude = Sets.newHashSet();
+ Set<String> choiceIdsToKeep = Sets.newHashSet(resultByChoice.keySet());
+
+ round(topRankChoices,
+ choiceIdsToExclude,
+ choiceIdsToKeep,
+ resultByChoice,
+ totalWeight);
+
+
+ // transform map of result to list of them (and sort them)
+ VoteCountingResult result = resultToList(resultByChoice);
+ return result;
+ }
+
+ public void round(Map<Voter, List<Set<String>>> topRankChoices,
+ Set<String> idsToExclude,
+ Set<String> idsToInclude,
+ SortedMap<String, ChoiceScore> resultByChoice,
+ double totalWeight) {
+
+ List<ChoiceScore> results = applyScores(topRankChoices,
+ idsToExclude,
+ idsToInclude,
+ resultByChoice);
+
+ if (!results.isEmpty()) {
+
+ // get best score
+ double max =
+ results.get(results.size() - 1).getScoreValue().doubleValue();
+
+ if (max < totalWeight) {
+
+ // pas de majorité absolue, il faut éliminer le(s) choix les plus mauvais
+
+ guessChoiceIdsToRemove(idsToInclude, idsToExclude, topRankChoices);
+
+ // on ne veux plus utiliser ces choix dans le tour suivant
+ idsToInclude.removeAll(idsToExclude);
+
+ // nouveau tour
+ round(topRankChoices,
+ idsToExclude,
+ idsToInclude,
+ resultByChoice,
+ totalWeight);
+
+ } else {
+
+ // majorité absolue trouvée plus rien à faire en fait :)
+ }
+ }
+ }
+
+ public List<ChoiceScore> applyScores(Map<Voter, List<Set<String>>> topRankChoices,
+ Set<String> idsToExclude,
+ Set<String> idsToInclude,
+ SortedMap<String, ChoiceScore> resultByChoice) {
+
+ if (CollectionUtils.isNotEmpty(idsToExclude)) {
+
+ // on supprime des classements les ids données
+
+ for (List<Set<String>> choicesByLevel : topRankChoices.values()) {
+ Iterator<Set<String>> itr = choicesByLevel.iterator();
+ while (itr.hasNext()) {
+ Set<String> choiceIds = itr.next();
+ choiceIds.removeAll(idsToExclude);
+ if (choiceIds.isEmpty()) {
+
+ // remove this level
+ itr.remove();
+ }
+ }
+ }
+ }
+
+ // on remet à zero les scores pour les ids a conserver
+ for (String id : idsToInclude) {
+ resultByChoice.get(id).setScoreValue(null);
+ }
+
+ // on calcule les scores à partir des classements
+
+ for (Map.Entry<Voter, List<Set<String>>> entry : topRankChoices.entrySet()) {
+ List<Set<String>> idsByLevel = entry.getValue();
+ if (!idsByLevel.isEmpty()) {
+
+ Set<String> winnerIds = idsByLevel.get(0);
+ Voter voter = entry.getKey();
+ double voterWeight = voter.getWeight();
+ for (String id : winnerIds) {
+ if (idsToInclude.contains(id)) {
+ ChoiceScore choiceScore = resultByChoice.get(id);
+ choiceScore.addScoreValue(voterWeight);
+ }
+ }
+ }
+ }
+
+ // recopy choices to run rounds on it and eliminates choices until
+ // there is a choice > 50
+ List<ChoiceScore> results = Lists.newArrayList();
+
+ for (String id : idsToInclude) {
+ results.add(resultByChoice.get(id));
+ }
+
+ Collections.sort(results);
+
+ // on supprime tout score à 0
+ Iterator<ChoiceScore> itr = results.iterator();
+ while (itr.hasNext()) {
+ ChoiceScore choiceScore = itr.next();
+ if (choiceScore.getScoreValue() == null ||
+ ZERO_D.equals(choiceScore.getScoreValue())) {
+ itr.remove();
+ } else {
+ // score > 0 on peut s'arreter
+ break;
+ }
+ }
+ return results;
+ }
+
+ public void guessChoiceIdsToRemove(Set<String> idsToInclude,
+ Set<String> idsToExclude,
+ Map<Voter, List<Set<String>>> results) {
+
+ // pour chaque choix restant on calcule son score lorsqu'il est le dernier
+
+ Map<String, ChoiceScore> badScores = Maps.newTreeMap();
+ for (String id : idsToInclude) {
+ badScores.put(id, ChoiceScore.newScore(id, null));
+ }
+
+ for (Map.Entry<Voter, List<Set<String>>> entry : results.entrySet()) {
+ Voter voter = entry.getKey();
+ List<Set<String>> idsChoices = entry.getValue();
+ if (!idsChoices.isEmpty()) {
+
+ Set<String> lastIds = idsChoices.get(idsChoices.size() - 1);
+
+ double voterWeight = voter.getWeight();
+
+ for (String lastId : lastIds) {
+ badScores.get(lastId).addScoreValue(voterWeight);
+ }
+ }
+ }
+
+ // on construit alors la liste des scores
+ List<ChoiceScore> scores = Lists.newArrayList(badScores.values());
+
+ // que l'on trie
+ Collections.sort(scores);
+
+ // puis revers (pour avoir les meilleurs scores au début)
+ Collections.reverse(scores);
+
+ double maxScore = scores.get(0).getScoreValue().doubleValue();
+
+ idsToExclude.clear();
+
+ for (ChoiceScore choiceScore : scores) {
+
+ if (maxScore == choiceScore.getScoreValue().doubleValue()) {
+
+ idsToExclude.add(choiceScore.getChoiceId());
+ } else {
+ // value < max, on peut s'arreter là
+ break;
+ }
+ }
+ }
+}
Property changes on: trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCountingStrategy.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/strategy/CoombsStrategy.java
===================================================================
--- trunk/pollen-votecounting-strategy-coombs/src/main/java/org/chorem/pollen/votecounting/strategy/CoombsStrategy.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/strategy/CoombsStrategy.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,311 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting strategy :: Coombs
- * $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.votecounting.strategy;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import org.apache.commons.collections.CollectionUtils;
-import org.chorem.pollen.votecounting.model.ChoiceScore;
-import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
-import org.chorem.pollen.votecounting.model.VoteCountingResult;
-import org.chorem.pollen.votecounting.model.Voter;
-
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedMap;
-
-import static org.nuiton.i18n.I18n.l_;
-import static org.nuiton.i18n.I18n.n_;
-
-/**
- * Coombs.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class CoombsStrategy extends AbstractVoteCountingStrategy {
-
- public static final int ID = 6;
-
- @Override
- public int getId() {
- return ID;
- }
-
- @Override
- public String getI18nName() {
- return n_("pollen.voteCountingType.coombs");
- }
-
- @Override
- public String getI18nHelp() {
- return n_("pollen.voteCountingType.coombs.help");
- }
-
- @Override
- public String getTotalVoteValueNotValidMessage(Locale locale) {
- // no validation on total value, so no message
- return null;
- }
-
- @Override
- public String getVoteValueNotValidMessage(Locale locale) {
- return l_(locale, "pollen.error.vote.invalidCoombsVoteValue");
- }
-
- @Override
- public String getDisplayVoteValue(Integer voteValue) {
- return voteValue == null ? "" : String.valueOf(voteValue);
- }
-
- @Override
- public ChoiceToVoteRenderType getVoteValueEditorType() {
- return ChoiceToVoteRenderType.TEXTFIELD;
- }
-
- @Override
- public boolean isChoiceInVote(Integer voteValue) {
- return voteValue != null && voteValue > 0 && voteValue < 100;
- }
-
- @Override
- public boolean isVoteValueNull(Integer voteValue) {
- return voteValue == null;
- }
-
- @Override
- public boolean isDisplayResultsByChoice() {
- return false;
- }
-
- @Override
- public boolean isVoteValueValid(Integer voteValue) {
- return voteValue != null && voteValue > 0;
- }
-
- @Override
- public boolean isTotalVoteValueValid(int totalValues) {
- // no validation on total value
- return true;
- }
-
-
- @Override
- public VoteCountingResult votecount(Set<Voter> voters) {
-
- // get empty result by choice
- SortedMap<String, ChoiceScore> resultByChoice = votersToResult(voters);
-
- // calcul du score minimum pour atteindre la majorité absolue
- double totalWeight = 0.;
- for (Voter voter : voters) {
- totalWeight += voter.getWeight();
- }
- totalWeight /= 2;
-
- // calcul pour chaque votant de ses choix préférés
- Map<Voter, List<Set<String>>> topRankChoices =
- buildVoterSortedChoices(voters);
-
- Set<String> choiceIdsToExclude = Sets.newHashSet();
- Set<String> choiceIdsToKeep = Sets.newHashSet(resultByChoice.keySet());
-
- round(topRankChoices,
- choiceIdsToExclude,
- choiceIdsToKeep,
- resultByChoice,
- totalWeight);
-
-
- // transform map of result to list of them (and sort them)
- VoteCountingResult result = resultToList(resultByChoice);
- return result;
- }
-
- public void round(Map<Voter, List<Set<String>>> topRankChoices,
- Set<String> idsToExclude,
- Set<String> idsToInclude,
- SortedMap<String, ChoiceScore> resultByChoice,
- double totalWeight) {
-
- List<ChoiceScore> results = applyScores(topRankChoices,
- idsToExclude,
- idsToInclude,
- resultByChoice);
-
- if (!results.isEmpty()) {
-
- // get best score
- double max =
- results.get(results.size() - 1).getScoreValue().doubleValue();
-
- if (max < totalWeight) {
-
- // pas de majorité absolue, il faut éliminer le(s) choix les plus mauvais
-
- guessChoiceIdsToRemove(idsToInclude, idsToExclude, topRankChoices);
-
- // on ne veux plus utiliser ces choix dans le tour suivant
- idsToInclude.removeAll(idsToExclude);
-
- // nouveau tour
- round(topRankChoices,
- idsToExclude,
- idsToInclude,
- resultByChoice,
- totalWeight);
-
- } else {
-
- // majorité absolue trouvée plus rien à faire en fait :)
- }
- }
- }
-
- public List<ChoiceScore> applyScores(Map<Voter, List<Set<String>>> topRankChoices,
- Set<String> idsToExclude,
- Set<String> idsToInclude,
- SortedMap<String, ChoiceScore> resultByChoice) {
-
- if (CollectionUtils.isNotEmpty(idsToExclude)) {
-
- // on supprime des classements les ids données
-
- for (List<Set<String>> choicesByLevel : topRankChoices.values()) {
- Iterator<Set<String>> itr = choicesByLevel.iterator();
- while (itr.hasNext()) {
- Set<String> choiceIds = itr.next();
- choiceIds.removeAll(idsToExclude);
- if (choiceIds.isEmpty()) {
-
- // remove this level
- itr.remove();
- }
- }
- }
- }
-
- // on remet à zero les scores pour les ids a conserver
- for (String id : idsToInclude) {
- resultByChoice.get(id).setScoreValue(null);
- }
-
- // on calcule les scores à partir des classements
-
- for (Map.Entry<Voter, List<Set<String>>> entry : topRankChoices.entrySet()) {
- List<Set<String>> idsByLevel = entry.getValue();
- if (!idsByLevel.isEmpty()) {
-
- Set<String> winnerIds = idsByLevel.get(0);
- Voter voter = entry.getKey();
- double voterWeight = voter.getWeight();
- for (String id : winnerIds) {
- if (idsToInclude.contains(id)) {
- ChoiceScore choiceScore = resultByChoice.get(id);
- choiceScore.addScoreValue(voterWeight);
- }
- }
- }
- }
-
- // recopy choices to run rounds on it and eliminates choices until
- // there is a choice > 50
- List<ChoiceScore> results = Lists.newArrayList();
-
- for (String id : idsToInclude) {
- results.add(resultByChoice.get(id));
- }
-
- Collections.sort(results);
-
- // on supprime tout score à 0
- Iterator<ChoiceScore> itr = results.iterator();
- while (itr.hasNext()) {
- ChoiceScore choiceScore = itr.next();
- if (choiceScore.getScoreValue() == null ||
- ZERO_D.equals(choiceScore.getScoreValue())) {
- itr.remove();
- } else {
- // score > 0 on peut s'arreter
- break;
- }
- }
- return results;
- }
-
- public void guessChoiceIdsToRemove(Set<String> idsToInclude,
- Set<String> idsToExclude,
- Map<Voter, List<Set<String>>> results) {
-
- // pour chaque choix restant on calcule son score lorsqu'il est le dernier
-
- Map<String, ChoiceScore> badScores = Maps.newTreeMap();
- for (String id : idsToInclude) {
- badScores.put(id, ChoiceScore.newScore(id, null));
- }
-
- for (Map.Entry<Voter, List<Set<String>>> entry : results.entrySet()) {
- Voter voter = entry.getKey();
- List<Set<String>> idsChoices = entry.getValue();
- if (!idsChoices.isEmpty()) {
-
- Set<String> lastIds = idsChoices.get(idsChoices.size() - 1);
-
- double voterWeight = voter.getWeight();
-
- for (String lastId : lastIds) {
- badScores.get(lastId).addScoreValue(voterWeight);
- }
- }
- }
-
- // on construit alors la liste des scores
- List<ChoiceScore> scores = Lists.newArrayList(badScores.values());
-
- // que l'on trie
- Collections.sort(scores);
-
- // puis revers (pour avoir les meilleurs scores au début)
- Collections.reverse(scores);
-
- double maxScore = scores.get(0).getScoreValue().doubleValue();
-
- idsToExclude.clear();
-
- for (ChoiceScore choiceScore : scores) {
-
- if (maxScore == choiceScore.getScoreValue().doubleValue()) {
-
- idsToExclude.add(choiceScore.getChoiceId());
- } else {
- // value < max, on peut s'arreter là
- break;
- }
- }
- }
-}
Copied: trunk/pollen-votecounting-coombs/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting (from rev 3707, trunk/pollen-votecounting-strategy-coombs/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy)
===================================================================
--- trunk/pollen-votecounting-coombs/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting (rev 0)
+++ trunk/pollen-votecounting-coombs/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1 @@
+org.chorem.pollen.votecounting.CoombsVoteCounting
Property changes on: trunk/pollen-votecounting-coombs/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-coombs/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy
===================================================================
--- trunk/pollen-votecounting-strategy-coombs/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-coombs/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1 +0,0 @@
-org.chorem.pollen.votecounting.strategy.CoombsStrategy
Copied: trunk/pollen-votecounting-coombs/src/test/java/org/chorem/pollen/votecounting/CoombsVoteCountingStrategyTest.java (from rev 3707, trunk/pollen-votecounting-strategy-coombs/src/test/java/org/chorem/pollen/votecounting/strategy/CoombsStrategyTest.java)
===================================================================
--- trunk/pollen-votecounting-coombs/src/test/java/org/chorem/pollen/votecounting/CoombsVoteCountingStrategyTest.java (rev 0)
+++ trunk/pollen-votecounting-coombs/src/test/java/org/chorem/pollen/votecounting/CoombsVoteCountingStrategyTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,327 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting strategy :: Coombs
+ * $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.votecounting;
+
+import com.google.common.collect.Maps;
+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.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Tests the {@link CoombsVoteCountingStrategy}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+@Ignore
+public class CoombsVoteCountingStrategyTest {
+
+ public static final String CHOICE_A = "Ville A";
+
+ public static final String CHOICE_B = "Ville B";
+
+ public static final String CHOICE_C = "Ville C";
+
+ public static final String CHOICE_D = "Ville D";
+
+ protected static VoteCounting voteCounting;
+
+ protected VoteCountingStrategy strategy;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ VoteCountingFactory factory = new VoteCountingFactory();
+ voteCounting = factory.getVoteCounting(CoombsVoteCounting.ID);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ strategy = voteCounting.newVoteCountingStrategy();
+ }
+
+ @Test
+ public void simpleVotecount() throws Exception {
+
+ // see http://fr.wikipedia.org/wiki/M%C3%A9thode_de_Coombs
+
+ // Ville 1re 2e 3e 4e R1 R2
+ // A 42 0 0 58 42 -
+ // B 26 42 32 0 26 26+42
+ // C 15 43 42 0 15 15
+ // D 17 15 26 42 17 17
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("Ville A", 42.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, 3.).
+ addVoteForChoice(CHOICE_D, 4.).
+ newVoter("Ville B", 26.).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, 2.).
+ addVoteForChoice(CHOICE_D, 3.).
+ addVoteForChoice(CHOICE_A, 4.).
+ newVoter("Ville C", 15.).
+ addVoteForChoice(CHOICE_C, 1.).
+ addVoteForChoice(CHOICE_D, 2.).
+ addVoteForChoice(CHOICE_B, 3.).
+ addVoteForChoice(CHOICE_A, 4.).
+ newVoter("Ville D", 17.).
+ addVoteForChoice(CHOICE_D, 1.).
+ addVoteForChoice(CHOICE_C, 2.).
+ addVoteForChoice(CHOICE_B, 3.).
+ addVoteForChoice(CHOICE_A, 4.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(4, scores.size());
+
+ assertChoiceScore(scores.get(0), CHOICE_B, BigDecimal.valueOf(68.));
+ assertChoiceScore(scores.get(1), CHOICE_A, BigDecimal.valueOf(42.));
+ assertChoiceScore(scores.get(2), CHOICE_D, BigDecimal.valueOf(17.));
+ assertChoiceScore(scores.get(3), CHOICE_C, BigDecimal.valueOf(15.));
+ }
+
+ @Test
+ public void simpleVotecount0() throws Exception {
+
+ // Simple poll (all weight to 1) R1
+ // 1 (a=1 b=2 c=null) a 2
+ // 2 (a=3 b=2 c=1) b 1
+ // 3 (a=1 b=null c=2) c -
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, 3.).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, 1.).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, 2.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScore(scores.get(0), CHOICE_A, BigDecimal.valueOf(2.));
+ assertChoiceScore(scores.get(1), CHOICE_C, BigDecimal.valueOf(1.));
+ assertChoiceScore(scores.get(2), CHOICE_B, null);
+ }
+
+ @Test
+ public void simpleVotecount2() throws Exception {
+
+ // Simple poll (all weight to 1) R1
+ // 1 (a=1 b=2 c=null) a 2
+ // 2 (a=1 b=2 c=1) b -
+ // 3 (a=null b=null c=2) c 2
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, 1.).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, 2.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScoreEquals(BigDecimal.valueOf(2.),
+ Sets.newHashSet(scores.get(0),
+ scores.get(1)),
+ CHOICE_A, CHOICE_C);
+ assertChoiceScore(scores.get(2), CHOICE_B, null);
+ }
+
+ @Test
+ public void simpleVotecount3() throws Exception {
+
+ // Simple poll (all weight to 1) R1
+ // 1 (a=1 b=null c=null) a 1
+ // 2 (a=null b=1 c=null) b 1
+ // 3 (a=null b=null c=1) c 1
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, 1.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScoreEquals(BigDecimal.valueOf(1.),
+ Sets.newHashSet(scores.get(0),
+ scores.get(1),
+ scores.get(2)
+ ),
+ CHOICE_A, CHOICE_B, CHOICE_C);
+ }
+
+ @Test
+ public void weightedVotecount1() throws Exception {
+
+ // poll with weighted vote R1
+ // 1 (x2) (a=1 b=null c=null) a 2
+ // 2 (x1) (a=null b=1 c=null) b 2
+ // 3 (x1) (a=null b=1 c=2) c -
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("1", 2.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, 2.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScoreEquals(BigDecimal.valueOf(2.),
+ Sets.newHashSet(scores.get(0),
+ scores.get(1)),
+ CHOICE_A, CHOICE_B);
+ assertChoiceScore(scores.get(2), CHOICE_C, null);
+ }
+
+ @Test
+ public void weightedVotecount2() throws Exception {
+
+ // poll with weighted vote R1
+ // 1 (x2) (a=1 b=null c=null) a 2
+ // 2 (x1) (a=null b=1 c=null) b 1
+ // 3 (x3) (a=null b=2 c=1) c 3
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("1", 2.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 3.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, 1.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScore(scores.get(0), CHOICE_C, BigDecimal.valueOf(3.));
+ assertChoiceScore(scores.get(1), CHOICE_A, BigDecimal.valueOf(2.));
+ assertChoiceScore(scores.get(2), CHOICE_B, BigDecimal.valueOf(1.));
+ }
+
+ public static void assertChoiceScore(ChoiceScore choiceScore,
+ String choiceId,
+ BigDecimal choiceResult) {
+ Assert.assertNotNull(choiceScore);
+ Assert.assertEquals(choiceId, choiceScore.getChoiceId());
+ Assert.assertEquals(choiceResult, choiceScore.getScoreValue());
+ }
+
+ public static void assertChoiceScoreEquals(BigDecimal choiceResult,
+ Set<ChoiceScore> choiceScores,
+ String... choiceIds) {
+
+ Assert.assertNotNull(choiceScores);
+ Map<String, ChoiceScore> choicesById = Maps.uniqueIndex(
+ choiceScores, new ChoiceIdAble.ChoiceIdAbleById());
+ for (String choiceId : choiceIds) {
+
+ ChoiceScore choiceScore = choicesById.get(choiceId);
+ Assert.assertNotNull(choiceScore);
+ assertChoiceScore(choiceScore, choiceId, choiceResult);
+ }
+ }
+
+}
Property changes on: trunk/pollen-votecounting-coombs/src/test/java/org/chorem/pollen/votecounting/CoombsVoteCountingStrategyTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-coombs/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java (from rev 3707, trunk/pollen-votecounting-strategy-coombs/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java)
===================================================================
--- trunk/pollen-votecounting-coombs/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java (rev 0)
+++ trunk/pollen-votecounting-coombs/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,43 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting strategy :: Coombs
+ * $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.votecounting;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests the {@link VoteCountingFactory}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class VoteCountingFactoryTest {
+
+ @Test
+ public void getVoteCounting() throws Exception {
+ VoteCountingFactory factory = new VoteCountingFactory();
+ VoteCounting voteCounting =
+ factory.getVoteCounting(CoombsVoteCounting.ID);
+ Assert.assertNotNull(voteCounting);
+ }
+}
Property changes on: trunk/pollen-votecounting-coombs/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-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-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-coombs/src/test/java/org/chorem/pollen/votecounting/strategy/CoombsStrategyTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,326 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting strategy :: Coombs
- * $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.votecounting.strategy;
-
-import com.google.common.collect.Maps;
-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.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import java.math.BigDecimal;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Tests the {@link CoombsStrategy}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-@Ignore
-public class CoombsStrategyTest {
-
- public static final String CHOICE_A = "Ville A";
-
- public static final String CHOICE_B = "Ville B";
-
- public static final String CHOICE_C = "Ville C";
-
- public static final String CHOICE_D = "Ville D";
-
- protected static VoteCountingStrategyProvider provider;
-
- protected VoteCountingStrategy strategy;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- provider = new VoteCountingStrategyProvider();
- }
-
- @Before
- public void setUp() throws Exception {
- strategy = provider.getStrategy(CoombsStrategy.ID);
- }
-
- @Test
- public void simpleVotecount() throws Exception {
-
- // see http://fr.wikipedia.org/wiki/M%C3%A9thode_de_Coombs
-
- // Ville 1re 2e 3e 4e R1 R2
- // A 42 0 0 58 42 -
- // B 26 42 32 0 26 26+42
- // C 15 43 42 0 15 15
- // D 17 15 26 42 17 17
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("Ville A", 42.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, 3.).
- addVoteForChoice(CHOICE_D, 4.).
- newVoter("Ville B", 26.).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, 2.).
- addVoteForChoice(CHOICE_D, 3.).
- addVoteForChoice(CHOICE_A, 4.).
- newVoter("Ville C", 15.).
- addVoteForChoice(CHOICE_C, 1.).
- addVoteForChoice(CHOICE_D, 2.).
- addVoteForChoice(CHOICE_B, 3.).
- addVoteForChoice(CHOICE_A, 4.).
- newVoter("Ville D", 17.).
- addVoteForChoice(CHOICE_D, 1.).
- addVoteForChoice(CHOICE_C, 2.).
- addVoteForChoice(CHOICE_B, 3.).
- addVoteForChoice(CHOICE_A, 4.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(4, scores.size());
-
- assertChoiceScore(scores.get(0), CHOICE_B, BigDecimal.valueOf(68.));
- assertChoiceScore(scores.get(1), CHOICE_A, BigDecimal.valueOf(42.));
- assertChoiceScore(scores.get(2), CHOICE_D, BigDecimal.valueOf(17.));
- assertChoiceScore(scores.get(3), CHOICE_C, BigDecimal.valueOf(15.));
- }
-
- @Test
- public void simpleVotecount0() throws Exception {
-
- // Simple poll (all weight to 1) R1
- // 1 (a=1 b=2 c=null) a 2
- // 2 (a=3 b=2 c=1) b 1
- // 3 (a=1 b=null c=2) c -
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, 3.).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, 1.).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, 2.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScore(scores.get(0), CHOICE_A, BigDecimal.valueOf(2.));
- assertChoiceScore(scores.get(1), CHOICE_C, BigDecimal.valueOf(1.));
- assertChoiceScore(scores.get(2), CHOICE_B, null);
- }
-
- @Test
- public void simpleVotecount2() throws Exception {
-
- // Simple poll (all weight to 1) R1
- // 1 (a=1 b=2 c=null) a 2
- // 2 (a=1 b=2 c=1) b -
- // 3 (a=null b=null c=2) c 2
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, 1.).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, 2.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScoreEquals(BigDecimal.valueOf(2.),
- Sets.newHashSet(scores.get(0),
- scores.get(1)),
- CHOICE_A, CHOICE_C);
- assertChoiceScore(scores.get(2), CHOICE_B, null);
- }
-
- @Test
- public void simpleVotecount3() throws Exception {
-
- // Simple poll (all weight to 1) R1
- // 1 (a=1 b=null c=null) a 1
- // 2 (a=null b=1 c=null) b 1
- // 3 (a=null b=null c=1) c 1
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, 1.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScoreEquals(BigDecimal.valueOf(1.),
- Sets.newHashSet(scores.get(0),
- scores.get(1),
- scores.get(2)
- ),
- CHOICE_A, CHOICE_B, CHOICE_C);
- }
-
- @Test
- public void weightedVotecount1() throws Exception {
-
- // poll with weighted vote R1
- // 1 (x2) (a=1 b=null c=null) a 2
- // 2 (x1) (a=null b=1 c=null) b 2
- // 3 (x1) (a=null b=1 c=2) c -
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("1", 2.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, 2.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScoreEquals(BigDecimal.valueOf(2.),
- Sets.newHashSet(scores.get(0),
- scores.get(1)),
- CHOICE_A, CHOICE_B);
- assertChoiceScore(scores.get(2), CHOICE_C, null);
- }
-
- @Test
- public void weightedVotecount2() throws Exception {
-
- // poll with weighted vote R1
- // 1 (x2) (a=1 b=null c=null) a 2
- // 2 (x1) (a=null b=1 c=null) b 1
- // 3 (x3) (a=null b=2 c=1) c 3
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("1", 2.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 3.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, 1.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScore(scores.get(0), CHOICE_C, BigDecimal.valueOf(3.));
- assertChoiceScore(scores.get(1), CHOICE_A, BigDecimal.valueOf(2.));
- assertChoiceScore(scores.get(2), CHOICE_B, BigDecimal.valueOf(1.));
- }
-
- public static void assertChoiceScore(ChoiceScore choiceScore,
- String choiceId,
- BigDecimal choiceResult) {
- Assert.assertNotNull(choiceScore);
- Assert.assertEquals(choiceId, choiceScore.getChoiceId());
- Assert.assertEquals(choiceResult, choiceScore.getScoreValue());
- }
-
- public static void assertChoiceScoreEquals(BigDecimal choiceResult,
- Set<ChoiceScore> choiceScores,
- String... choiceIds) {
-
- Assert.assertNotNull(choiceScores);
- Map<String, ChoiceScore> choicesById = Maps.uniqueIndex(
- choiceScores, new ChoiceIdAble.ChoiceIdAbleById());
- for (String choiceId : choiceIds) {
-
- ChoiceScore choiceScore = choicesById.get(choiceId);
- Assert.assertNotNull(choiceScore);
- assertChoiceScore(choiceScore, choiceId, choiceResult);
- }
- }
-
-}
Deleted: trunk/pollen-votecounting-coombs/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java
===================================================================
--- trunk/pollen-votecounting-strategy-coombs/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-coombs/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,49 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting strategy :: Coombs
- * $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.votecounting.strategy;
-
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * Tests the {@link VoteCountingStrategyProvider}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class VoteCountingStrategyProviderTest {
-
- protected static VoteCountingStrategyProvider provider;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- provider = new VoteCountingStrategyProvider();
- }
-
- @Test
- public void getStrategy() throws Exception {
-
- Assert.assertNotNull(provider.getStrategy(CoombsStrategy.ID));
- }
-}
Modified: trunk/pollen-votecounting-instant-runoff/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy-instant-runoff/pom.xml 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-instant-runoff/pom.xml 2012-09-29 12:36:25 UTC (rev 3708)
@@ -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>
@@ -10,11 +12,10 @@
</parent>
<groupId>org.chorem.pollen</groupId>
- <artifactId>pollen-votecounting-strategy-instant-runoff</artifactId>
+ <artifactId>pollen-votecounting-instant-runoff</artifactId>
+ <name>Pollen :: VoteCounting :: Instant Runoff</name>
+ <description>Implements the instant-runoff vote counting</description>
- <name>Pollen :: VoteCounting strategy :: Instant Runoff</name>
- <description>Implements the instant-runoff vote counting strategy</description>
-
<dependencies>
<dependency>
@@ -39,6 +40,12 @@
</dependency>
<dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
Added: trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCounting.java (rev 0)
+++ trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCounting.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,69 @@
+package org.chorem.pollen.votecounting;
+
+import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
+
+import java.util.Locale;
+
+import static org.nuiton.i18n.I18n.l_;
+import static org.nuiton.i18n.I18n.n_;
+
+/**
+ * Coombs vote counting entry point.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.6
+ */
+public class InstantRunoffVoteCounting extends AbstractVoteCounting<InstantRunoffVoteCountingStrategy> {
+
+ public static final int ID = 5;
+
+ public InstantRunoffVoteCounting() {
+ super(ID,
+ InstantRunoffVoteCountingStrategy.class,
+ n_("pollen.voteCountingType.instantRunoff"),
+ n_("pollen.voteCountingType.instantRunoff.help")
+ );
+ }
+
+ @Override
+ public String getTotalVoteValueNotValidMessage(Locale locale) {
+ // no validation on total value, so no message
+ return null;
+ }
+
+ @Override
+ public String getVoteValueNotValidMessage(Locale locale) {
+ return l_(locale, "pollen.error.vote.invalidInstantRunoffVoteValue");
+ }
+
+ @Override
+ public String getDisplayVoteValue(Integer voteValue) {
+ return voteValue == null ? "" : String.valueOf(voteValue);
+ }
+
+ @Override
+ public ChoiceToVoteRenderType getVoteValueEditorType() {
+ return ChoiceToVoteRenderType.TEXTFIELD;
+ }
+
+ @Override
+ public boolean isChoiceInVote(Integer voteValue) {
+ return voteValue != null && voteValue > 0 && voteValue < 100;
+ }
+
+ @Override
+ public boolean isVoteValueNull(Integer voteValue) {
+ return voteValue == null;
+ }
+
+ @Override
+ public boolean isVoteValueValid(Integer voteValue) {
+ return voteValue != null && voteValue > 0;
+ }
+
+ @Override
+ public boolean isTotalVoteValueValid(int totalValues) {
+ // no validation on total value
+ return true;
+ }
+}
Property changes on: trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCounting.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCountingStrategy.java (from rev 3707, trunk/pollen-votecounting-strategy-instant-runoff/src/main/java/org/chorem/pollen/votecounting/strategy/InstantRunoffStrategy.java)
===================================================================
--- trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCountingStrategy.java (rev 0)
+++ trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCountingStrategy.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,209 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting strategy :: Instant Runoff
+ * $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.votecounting;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import org.apache.commons.collections.CollectionUtils;
+import org.chorem.pollen.votecounting.model.ChoiceScore;
+import org.chorem.pollen.votecounting.model.VoteCountingResult;
+import org.chorem.pollen.votecounting.model.Voter;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+
+/**
+ * InstantRunoff.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class InstantRunoffVoteCountingStrategy extends AbstractVoteCountingStrategy {
+
+ @Override
+ public VoteCountingResult votecount(Set<Voter> voters) {
+
+ // get empty result by choice
+ SortedMap<String, ChoiceScore> resultByChoice = votersToResult(voters);
+
+ // calcul du score minimum pour atteindre la majorité absolue
+ double totalWeight = 0.;
+ for (Voter voter : voters) {
+ totalWeight += voter.getWeight();
+ }
+ totalWeight /= 2;
+
+ // calcul pour chaque votant de ses choix préférés
+ Map<Voter, List<Set<String>>> topRankChoices =
+ buildVoterSortedChoices(voters);
+
+ Set<String> choiceIdsToExclude = Sets.newHashSet();
+ Set<String> choiceIdsToKeep = Sets.newHashSet(resultByChoice.keySet());
+
+ round(topRankChoices,
+ choiceIdsToExclude,
+ choiceIdsToKeep,
+ resultByChoice,
+ totalWeight);
+
+ // transform map of result to list of them (and sort them)
+ VoteCountingResult result = resultToList(resultByChoice);
+ return result;
+ }
+
+ public void round(Map<Voter, List<Set<String>>> topRankChoices,
+ Set<String> idsToExclude,
+ Set<String> idsToInclude,
+ SortedMap<String, ChoiceScore> resultByChoice,
+ double totalWeight) {
+
+ List<ChoiceScore> results = applyScores(topRankChoices,
+ idsToExclude,
+ idsToInclude,
+ resultByChoice);
+
+ if (!results.isEmpty()) {
+
+ // get best score
+ double max =
+ results.get(results.size() - 1).getScoreValue().doubleValue();
+
+ if (max < totalWeight) {
+
+ // pas de majorité absolue, il faut éliminer le(s) choix les plus mauvais
+
+ guessChoiceIdsToRemove(idsToExclude, results);
+
+
+ // on ne veux plus utiliser ces choix dans le tour suivant
+ idsToInclude.removeAll(idsToExclude);
+
+ // nouveau tour
+ round(topRankChoices,
+ idsToExclude,
+ idsToInclude,
+ resultByChoice,
+ totalWeight);
+
+ } else {
+
+ // majorité absolue trouvée plus rien à faire en fait :)
+ }
+ }
+ }
+
+ public List<ChoiceScore> applyScores(Map<Voter, List<Set<String>>> topRankChoices,
+ Set<String> idsToExclude,
+ Set<String> idsToInclude,
+ SortedMap<String, ChoiceScore> resultByChoice) {
+
+ if (CollectionUtils.isNotEmpty(idsToExclude)) {
+
+ // on supprime des classements les ids données
+
+ for (List<Set<String>> choicesByLevel : topRankChoices.values()) {
+ Iterator<Set<String>> itr = choicesByLevel.iterator();
+ while (itr.hasNext()) {
+ Set<String> choiceIds = itr.next();
+ choiceIds.removeAll(idsToExclude);
+ if (choiceIds.isEmpty()) {
+
+ // remove this level
+ itr.remove();
+ }
+ }
+ }
+ }
+
+ // on remet à zero les scores pour les ids a conserver
+ for (String id : idsToInclude) {
+ resultByChoice.get(id).setScoreValue(null);
+ }
+
+ // on calcule les scores à partir des classements
+
+ for (Map.Entry<Voter, List<Set<String>>> entry : topRankChoices.entrySet()) {
+ List<Set<String>> idsByLevel = entry.getValue();
+ if (!idsByLevel.isEmpty()) {
+
+ Set<String> winnerIds = idsByLevel.get(0);
+ Voter voter = entry.getKey();
+ double voterWeight = voter.getWeight();
+ for (String id : winnerIds) {
+ if (idsToInclude.contains(id)) {
+ ChoiceScore choiceScore = resultByChoice.get(id);
+ choiceScore.addScoreValue(voterWeight);
+ }
+ }
+ }
+ }
+
+ // recopy choices to run rounds on it and eliminates choices until
+ // there is a choice > 50
+ List<ChoiceScore> results = Lists.newArrayList();
+
+ for (String id : idsToInclude) {
+ results.add(resultByChoice.get(id));
+ }
+
+ Collections.sort(results);
+
+ // on supprime tout score à 0
+ Iterator<ChoiceScore> itr = results.iterator();
+ while (itr.hasNext()) {
+ ChoiceScore choiceScore = itr.next();
+ if (choiceScore.getScoreValue() == null ||
+ ZERO_D.equals(choiceScore.getScoreValue())) {
+ itr.remove();
+ } else {
+ // score > 0 on peut s'arreter
+ break;
+ }
+ }
+ return results;
+ }
+
+ public void guessChoiceIdsToRemove(Set<String> idsToExclude,
+ List<ChoiceScore> results) {
+
+ double min = results.get(0).getScoreValue().doubleValue();
+
+ idsToExclude.clear();
+
+ for (ChoiceScore choiceScore : results) {
+
+ if (min == choiceScore.getScoreValue().doubleValue()) {
+
+ idsToExclude.add(choiceScore.getChoiceId());
+ } else {
+ // value > min, on peut s'arreter là
+ break;
+ }
+ }
+ }
+
+}
Property changes on: trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCountingStrategy.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/strategy/InstantRunoffStrategy.java
===================================================================
--- trunk/pollen-votecounting-strategy-instant-runoff/src/main/java/org/chorem/pollen/votecounting/strategy/InstantRunoffStrategy.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/strategy/InstantRunoffStrategy.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,278 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting strategy :: Instant Runoff
- * $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.votecounting.strategy;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-import org.apache.commons.collections.CollectionUtils;
-import org.chorem.pollen.votecounting.model.ChoiceScore;
-import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
-import org.chorem.pollen.votecounting.model.VoteCountingResult;
-import org.chorem.pollen.votecounting.model.Voter;
-
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedMap;
-
-import static org.nuiton.i18n.I18n.l_;
-import static org.nuiton.i18n.I18n.n_;
-
-/**
- * InstantRunoff.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class InstantRunoffStrategy extends AbstractVoteCountingStrategy {
-
- public static final int ID = 5;
-
- @Override
- public int getId() {
- return ID;
- }
-
- @Override
- public String getI18nName() {
- return n_("pollen.voteCountingType.instantRunoff");
- }
-
- @Override
- public String getI18nHelp() {
- return n_("pollen.voteCountingType.instantRunoff.help");
- }
-
- @Override
- public String getTotalVoteValueNotValidMessage(Locale locale) {
- // no validation on total value, so no message
- return null;
- }
-
- @Override
- public String getVoteValueNotValidMessage(Locale locale) {
- return l_(locale, "pollen.error.vote.invalidInstantRunoffVoteValue");
- }
-
- @Override
- public String getDisplayVoteValue(Integer voteValue) {
- return voteValue == null ? "" : String.valueOf(voteValue);
- }
-
- @Override
- public ChoiceToVoteRenderType getVoteValueEditorType() {
- return ChoiceToVoteRenderType.TEXTFIELD;
- }
-
- @Override
- public boolean isChoiceInVote(Integer voteValue) {
- return voteValue != null && voteValue > 0 && voteValue < 100;
- }
-
- @Override
- public boolean isVoteValueNull(Integer voteValue) {
- return voteValue == null;
- }
-
- @Override
- public boolean isDisplayResultsByChoice() {
- return false;
- }
-
- @Override
- public boolean isVoteValueValid(Integer voteValue) {
- return voteValue != null && voteValue > 0;
- }
-
- @Override
- public boolean isTotalVoteValueValid(int totalValues) {
- // no validation on total value
- return true;
- }
-
- @Override
- public VoteCountingResult votecount(Set<Voter> voters) {
-
- // get empty result by choice
- SortedMap<String, ChoiceScore> resultByChoice = votersToResult(voters);
-
- // calcul du score minimum pour atteindre la majorité absolue
- double totalWeight = 0.;
- for (Voter voter : voters) {
- totalWeight += voter.getWeight();
- }
- totalWeight /= 2;
-
- // calcul pour chaque votant de ses choix préférés
- Map<Voter, List<Set<String>>> topRankChoices =
- buildVoterSortedChoices(voters);
-
- Set<String> choiceIdsToExclude = Sets.newHashSet();
- Set<String> choiceIdsToKeep = Sets.newHashSet(resultByChoice.keySet());
-
- round(topRankChoices,
- choiceIdsToExclude,
- choiceIdsToKeep,
- resultByChoice,
- totalWeight);
-
- // transform map of result to list of them (and sort them)
- VoteCountingResult result = resultToList(resultByChoice);
- return result;
- }
-
- public void round(Map<Voter, List<Set<String>>> topRankChoices,
- Set<String> idsToExclude,
- Set<String> idsToInclude,
- SortedMap<String, ChoiceScore> resultByChoice,
- double totalWeight) {
-
- List<ChoiceScore> results = applyScores(topRankChoices,
- idsToExclude,
- idsToInclude,
- resultByChoice);
-
- if (!results.isEmpty()) {
-
- // get best score
- double max =
- results.get(results.size() - 1).getScoreValue().doubleValue();
-
- if (max < totalWeight) {
-
- // pas de majorité absolue, il faut éliminer le(s) choix les plus mauvais
-
- guessChoiceIdsToRemove(idsToExclude, results);
-
-
- // on ne veux plus utiliser ces choix dans le tour suivant
- idsToInclude.removeAll(idsToExclude);
-
- // nouveau tour
- round(topRankChoices,
- idsToExclude,
- idsToInclude,
- resultByChoice,
- totalWeight);
-
- } else {
-
- // majorité absolue trouvée plus rien à faire en fait :)
- }
- }
- }
-
- public List<ChoiceScore> applyScores(Map<Voter, List<Set<String>>> topRankChoices,
- Set<String> idsToExclude,
- Set<String> idsToInclude,
- SortedMap<String, ChoiceScore> resultByChoice) {
-
- if (CollectionUtils.isNotEmpty(idsToExclude)) {
-
- // on supprime des classements les ids données
-
- for (List<Set<String>> choicesByLevel : topRankChoices.values()) {
- Iterator<Set<String>> itr = choicesByLevel.iterator();
- while (itr.hasNext()) {
- Set<String> choiceIds = itr.next();
- choiceIds.removeAll(idsToExclude);
- if (choiceIds.isEmpty()) {
-
- // remove this level
- itr.remove();
- }
- }
- }
- }
-
- // on remet à zero les scores pour les ids a conserver
- for (String id : idsToInclude) {
- resultByChoice.get(id).setScoreValue(null);
- }
-
- // on calcule les scores à partir des classements
-
- for (Map.Entry<Voter, List<Set<String>>> entry : topRankChoices.entrySet()) {
- List<Set<String>> idsByLevel = entry.getValue();
- if (!idsByLevel.isEmpty()) {
-
- Set<String> winnerIds = idsByLevel.get(0);
- Voter voter = entry.getKey();
- double voterWeight = voter.getWeight();
- for (String id : winnerIds) {
- if (idsToInclude.contains(id)) {
- ChoiceScore choiceScore = resultByChoice.get(id);
- choiceScore.addScoreValue(voterWeight);
- }
- }
- }
- }
-
- // recopy choices to run rounds on it and eliminates choices until
- // there is a choice > 50
- List<ChoiceScore> results = Lists.newArrayList();
-
- for (String id : idsToInclude) {
- results.add(resultByChoice.get(id));
- }
-
- Collections.sort(results);
-
- // on supprime tout score à 0
- Iterator<ChoiceScore> itr = results.iterator();
- while (itr.hasNext()) {
- ChoiceScore choiceScore = itr.next();
- if (choiceScore.getScoreValue() == null ||
- ZERO_D.equals(choiceScore.getScoreValue())) {
- itr.remove();
- } else {
- // score > 0 on peut s'arreter
- break;
- }
- }
- return results;
- }
-
- public void guessChoiceIdsToRemove(Set<String> idsToExclude,
- List<ChoiceScore> results) {
-
- double min = results.get(0).getScoreValue().doubleValue();
-
- idsToExclude.clear();
-
- for (ChoiceScore choiceScore : results) {
-
- if (min == choiceScore.getScoreValue().doubleValue()) {
-
- idsToExclude.add(choiceScore.getChoiceId());
- } else {
- // value > min, on peut s'arreter là
- break;
- }
- }
- }
-
-}
Copied: trunk/pollen-votecounting-instant-runoff/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting (from rev 3707, trunk/pollen-votecounting-strategy-instant-runoff/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy)
===================================================================
--- trunk/pollen-votecounting-instant-runoff/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting (rev 0)
+++ trunk/pollen-votecounting-instant-runoff/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1 @@
+org.chorem.pollen.votecounting.InstantRunoffVoteCounting
Property changes on: trunk/pollen-votecounting-instant-runoff/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-instant-runoff/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy
===================================================================
--- trunk/pollen-votecounting-strategy-instant-runoff/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-instant-runoff/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1 +0,0 @@
-org.chorem.pollen.votecounting.strategy.InstantRunoffStrategy
Copied: trunk/pollen-votecounting-instant-runoff/src/test/java/org/chorem/pollen/votecounting/InstantRunoffVoteCountingStrategyTest.java (from rev 3707, trunk/pollen-votecounting-strategy-instant-runoff/src/test/java/org/chorem/pollen/votecounting/strategy/InstantRunoffStrategyTest.java)
===================================================================
--- trunk/pollen-votecounting-instant-runoff/src/test/java/org/chorem/pollen/votecounting/InstantRunoffVoteCountingStrategyTest.java (rev 0)
+++ trunk/pollen-votecounting-instant-runoff/src/test/java/org/chorem/pollen/votecounting/InstantRunoffVoteCountingStrategyTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,327 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting strategy :: Instant Runoff
+ * $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.votecounting;
+
+import com.google.common.collect.Maps;
+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.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Tests the {@link InstantRunoffVoteCountingStrategy}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+@Ignore
+public class InstantRunoffVoteCountingStrategyTest {
+
+ public static final String CHOICE_A = "Ville A";
+
+ public static final String CHOICE_B = "Ville B";
+
+ public static final String CHOICE_C = "Ville C";
+
+ public static final String CHOICE_D = "Ville D";
+
+ protected static VoteCounting voteCounting;
+
+ protected VoteCountingStrategy strategy;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ VoteCountingFactory factory = new VoteCountingFactory();
+ voteCounting = factory.getVoteCounting(InstantRunoffVoteCounting.ID);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ strategy = voteCounting.newVoteCountingStrategy();
+ }
+
+ @Test
+ public void simpleVotecount() throws Exception {
+
+ // see http://fr.wikipedia.org/wiki/Vote_alternatif
+
+ // Ville 1re 2e 3e 4e R1 R2 R3
+ // A 42 0 0 58 42 42 42
+ // B 26 42 32 0 26 26 -
+ // C 15 43 42 0 15 - -
+ // D 17 15 26 42 17 32 58
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("Ville A", 42.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, 3.).
+ addVoteForChoice(CHOICE_D, 4.).
+ newVoter("Ville B", 26.).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, 2.).
+ addVoteForChoice(CHOICE_D, 3.).
+ addVoteForChoice(CHOICE_A, 4.).
+ newVoter("Ville C", 15.).
+ addVoteForChoice(CHOICE_C, 1.).
+ addVoteForChoice(CHOICE_D, 2.).
+ addVoteForChoice(CHOICE_B, 3.).
+ addVoteForChoice(CHOICE_A, 4.).
+ newVoter("Ville D", 17.).
+ addVoteForChoice(CHOICE_D, 1.).
+ addVoteForChoice(CHOICE_C, 2.).
+ addVoteForChoice(CHOICE_B, 3.).
+ addVoteForChoice(CHOICE_A, 4.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(4, scores.size());
+
+ assertChoiceScore(scores.get(0), CHOICE_D, BigDecimal.valueOf(58.));
+ assertChoiceScore(scores.get(1), CHOICE_A, BigDecimal.valueOf(42.));
+ assertChoiceScore(scores.get(2), CHOICE_B, BigDecimal.valueOf(26.));
+ assertChoiceScore(scores.get(3), CHOICE_C, BigDecimal.valueOf(15.));
+ }
+
+ @Test
+ public void simpleVotecount0() throws Exception {
+
+ // Simple poll (all weight to 1) R1
+ // 1 (a=1 b=2 c=null) a 2
+ // 2 (a=3 b=2 c=1) b 1
+ // 3 (a=1 b=null c=2) c -
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, 3.).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, 1.).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, 2.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScore(scores.get(0), CHOICE_A, BigDecimal.valueOf(2.));
+ assertChoiceScore(scores.get(1), CHOICE_C, BigDecimal.valueOf(1.));
+ assertChoiceScore(scores.get(2), CHOICE_B, null);
+ }
+
+ @Test
+ public void simpleVotecount2() throws Exception {
+
+ // Simple poll (all weight to 1) R1
+ // 1 (a=1 b=2 c=null) a 2
+ // 2 (a=1 b=2 c=1) b -
+ // 3 (a=null b=null c=2) c 2
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, 1.).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, 2.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScoreEquals(BigDecimal.valueOf(2.),
+ Sets.newHashSet(scores.get(0),
+ scores.get(1)),
+ CHOICE_A, CHOICE_C);
+ assertChoiceScore(scores.get(2), CHOICE_B, null);
+ }
+
+ @Test
+ public void simpleVotecount3() throws Exception {
+
+ // Simple poll (all weight to 1) R1
+ // 1 (a=1 b=null c=null) a 1
+ // 2 (a=null b=1 c=null) b 1
+ // 3 (a=null b=null c=1) c 1
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, 1.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScoreEquals(BigDecimal.valueOf(1.),
+ Sets.newHashSet(scores.get(0),
+ scores.get(1),
+ scores.get(2)
+ ),
+ CHOICE_A, CHOICE_B, CHOICE_C);
+ }
+
+ @Test
+ public void weightedVotecount1() throws Exception {
+
+ // poll with weighted vote R1
+ // 1 (x2) (a=1 b=null c=null) a 2
+ // 2 (x1) (a=null b=1 c=null) b 2
+ // 3 (x1) (a=null b=1 c=2) c -
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("1", 2.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, 2.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScoreEquals(BigDecimal.valueOf(2.),
+ Sets.newHashSet(scores.get(0),
+ scores.get(1)),
+ CHOICE_A, CHOICE_B);
+ assertChoiceScore(scores.get(2), CHOICE_C, null);
+ }
+
+ @Test
+ public void weightedVotecount2() throws Exception {
+
+ // poll with weighted vote R1
+ // 1 (x2) (a=1 b=null c=null) a 2
+ // 2 (x1) (a=null b=1 c=null) b 1
+ // 3 (x3) (a=null b=2 c=1) c 3
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("1", 2.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 3.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, 1.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScore(scores.get(0), CHOICE_C, BigDecimal.valueOf(3.));
+ assertChoiceScore(scores.get(1), CHOICE_A, BigDecimal.valueOf(2.));
+ assertChoiceScore(scores.get(2), CHOICE_B, BigDecimal.valueOf(1.));
+ }
+
+ public static void assertChoiceScore(ChoiceScore choiceScore,
+ String choiceId,
+ BigDecimal choiceResult) {
+ Assert.assertNotNull(choiceScore);
+ Assert.assertEquals(choiceId, choiceScore.getChoiceId());
+ Assert.assertEquals(choiceResult, choiceScore.getScoreValue());
+ }
+
+ public static void assertChoiceScoreEquals(BigDecimal choiceResult,
+ Set<ChoiceScore> choiceScores,
+ String... choiceIds) {
+
+ Assert.assertNotNull(choiceScores);
+ Map<String, ChoiceScore> choicesById = Maps.uniqueIndex(
+ choiceScores, new ChoiceIdAble.ChoiceIdAbleById());
+ for (String choiceId : choiceIds) {
+
+ ChoiceScore choiceScore = choicesById.get(choiceId);
+ Assert.assertNotNull(choiceScore);
+ assertChoiceScore(choiceScore, choiceId, choiceResult);
+ }
+ }
+
+}
Property changes on: trunk/pollen-votecounting-instant-runoff/src/test/java/org/chorem/pollen/votecounting/InstantRunoffVoteCountingStrategyTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-instant-runoff/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java (from rev 3707, trunk/pollen-votecounting-strategy-instant-runoff/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java)
===================================================================
--- trunk/pollen-votecounting-instant-runoff/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java (rev 0)
+++ trunk/pollen-votecounting-instant-runoff/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,43 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting strategy :: Instant Runoff
+ * $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.votecounting;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests the {@link VoteCountingFactory}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class VoteCountingFactoryTest {
+
+ @Test
+ public void getVoteCounting() throws Exception {
+ VoteCountingFactory factory = new VoteCountingFactory();
+ VoteCounting voteCounting =
+ factory.getVoteCounting(InstantRunoffVoteCounting.ID);
+ Assert.assertNotNull(voteCounting);
+ }
+}
Property changes on: trunk/pollen-votecounting-instant-runoff/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-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-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-instant-runoff/src/test/java/org/chorem/pollen/votecounting/strategy/InstantRunoffStrategyTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,326 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting strategy :: Instant Runoff
- * $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.votecounting.strategy;
-
-import com.google.common.collect.Maps;
-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.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import java.math.BigDecimal;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Tests the {@link InstantRunoffStrategy}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-@Ignore
-public class InstantRunoffStrategyTest {
-
- public static final String CHOICE_A = "Ville A";
-
- public static final String CHOICE_B = "Ville B";
-
- public static final String CHOICE_C = "Ville C";
-
- public static final String CHOICE_D = "Ville D";
-
- protected static VoteCountingStrategyProvider provider;
-
- protected VoteCountingStrategy strategy;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- provider = new VoteCountingStrategyProvider();
- }
-
- @Before
- public void setUp() throws Exception {
- strategy = provider.getStrategy(InstantRunoffStrategy.ID);
- }
-
- @Test
- public void simpleVotecount() throws Exception {
-
- // see http://fr.wikipedia.org/wiki/Vote_alternatif
-
- // Ville 1re 2e 3e 4e R1 R2 R3
- // A 42 0 0 58 42 42 42
- // B 26 42 32 0 26 26 -
- // C 15 43 42 0 15 - -
- // D 17 15 26 42 17 32 58
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("Ville A", 42.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, 3.).
- addVoteForChoice(CHOICE_D, 4.).
- newVoter("Ville B", 26.).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, 2.).
- addVoteForChoice(CHOICE_D, 3.).
- addVoteForChoice(CHOICE_A, 4.).
- newVoter("Ville C", 15.).
- addVoteForChoice(CHOICE_C, 1.).
- addVoteForChoice(CHOICE_D, 2.).
- addVoteForChoice(CHOICE_B, 3.).
- addVoteForChoice(CHOICE_A, 4.).
- newVoter("Ville D", 17.).
- addVoteForChoice(CHOICE_D, 1.).
- addVoteForChoice(CHOICE_C, 2.).
- addVoteForChoice(CHOICE_B, 3.).
- addVoteForChoice(CHOICE_A, 4.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(4, scores.size());
-
- assertChoiceScore(scores.get(0), CHOICE_D, BigDecimal.valueOf(58.));
- assertChoiceScore(scores.get(1), CHOICE_A, BigDecimal.valueOf(42.));
- assertChoiceScore(scores.get(2), CHOICE_B, BigDecimal.valueOf(26.));
- assertChoiceScore(scores.get(3), CHOICE_C, BigDecimal.valueOf(15.));
- }
-
- @Test
- public void simpleVotecount0() throws Exception {
-
- // Simple poll (all weight to 1) R1
- // 1 (a=1 b=2 c=null) a 2
- // 2 (a=3 b=2 c=1) b 1
- // 3 (a=1 b=null c=2) c -
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, 3.).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, 1.).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, 2.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScore(scores.get(0), CHOICE_A, BigDecimal.valueOf(2.));
- assertChoiceScore(scores.get(1), CHOICE_C, BigDecimal.valueOf(1.));
- assertChoiceScore(scores.get(2), CHOICE_B, null);
- }
-
- @Test
- public void simpleVotecount2() throws Exception {
-
- // Simple poll (all weight to 1) R1
- // 1 (a=1 b=2 c=null) a 2
- // 2 (a=1 b=2 c=1) b -
- // 3 (a=null b=null c=2) c 2
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, 1.).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, 2.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScoreEquals(BigDecimal.valueOf(2.),
- Sets.newHashSet(scores.get(0),
- scores.get(1)),
- CHOICE_A, CHOICE_C);
- assertChoiceScore(scores.get(2), CHOICE_B, null);
- }
-
- @Test
- public void simpleVotecount3() throws Exception {
-
- // Simple poll (all weight to 1) R1
- // 1 (a=1 b=null c=null) a 1
- // 2 (a=null b=1 c=null) b 1
- // 3 (a=null b=null c=1) c 1
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, 1.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScoreEquals(BigDecimal.valueOf(1.),
- Sets.newHashSet(scores.get(0),
- scores.get(1),
- scores.get(2)
- ),
- CHOICE_A, CHOICE_B, CHOICE_C);
- }
-
- @Test
- public void weightedVotecount1() throws Exception {
-
- // poll with weighted vote R1
- // 1 (x2) (a=1 b=null c=null) a 2
- // 2 (x1) (a=null b=1 c=null) b 2
- // 3 (x1) (a=null b=1 c=2) c -
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("1", 2.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, 2.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScoreEquals(BigDecimal.valueOf(2.),
- Sets.newHashSet(scores.get(0),
- scores.get(1)),
- CHOICE_A, CHOICE_B);
- assertChoiceScore(scores.get(2), CHOICE_C, null);
- }
-
- @Test
- public void weightedVotecount2() throws Exception {
-
- // poll with weighted vote R1
- // 1 (x2) (a=1 b=null c=null) a 2
- // 2 (x1) (a=null b=1 c=null) b 1
- // 3 (x3) (a=null b=2 c=1) c 3
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("1", 2.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 3.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, 1.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScore(scores.get(0), CHOICE_C, BigDecimal.valueOf(3.));
- assertChoiceScore(scores.get(1), CHOICE_A, BigDecimal.valueOf(2.));
- assertChoiceScore(scores.get(2), CHOICE_B, BigDecimal.valueOf(1.));
- }
-
- public static void assertChoiceScore(ChoiceScore choiceScore,
- String choiceId,
- BigDecimal choiceResult) {
- Assert.assertNotNull(choiceScore);
- Assert.assertEquals(choiceId, choiceScore.getChoiceId());
- Assert.assertEquals(choiceResult, choiceScore.getScoreValue());
- }
-
- public static void assertChoiceScoreEquals(BigDecimal choiceResult,
- Set<ChoiceScore> choiceScores,
- String... choiceIds) {
-
- Assert.assertNotNull(choiceScores);
- Map<String, ChoiceScore> choicesById = Maps.uniqueIndex(
- choiceScores, new ChoiceIdAble.ChoiceIdAbleById());
- for (String choiceId : choiceIds) {
-
- ChoiceScore choiceScore = choicesById.get(choiceId);
- Assert.assertNotNull(choiceScore);
- assertChoiceScore(choiceScore, choiceId, choiceResult);
- }
- }
-
-}
Deleted: trunk/pollen-votecounting-instant-runoff/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java
===================================================================
--- trunk/pollen-votecounting-strategy-instant-runoff/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-instant-runoff/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,49 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting strategy :: Instant Runoff
- * $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.votecounting.strategy;
-
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * Tests the {@link VoteCountingStrategyProvider}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class VoteCountingStrategyProviderTest {
-
- protected static VoteCountingStrategyProvider provider;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- provider = new VoteCountingStrategyProvider();
- }
-
- @Test
- public void getStrategy() throws Exception {
-
- Assert.assertNotNull(provider.getStrategy(InstantRunoffStrategy.ID));
- }
-}
Modified: trunk/pollen-votecounting-normal/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy-normal/pom.xml 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-normal/pom.xml 2012-09-29 12:36:25 UTC (rev 3708)
@@ -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>
@@ -10,11 +12,10 @@
</parent>
<groupId>org.chorem.pollen</groupId>
- <artifactId>pollen-votecounting-strategy-normal</artifactId>
+ <artifactId>pollen-votecounting-normal</artifactId>
+ <name>Pollen :: VoteCounting :: Normal</name>
+ <description>Implements the normal vote counting</description>
- <name>Pollen :: VoteCounting strategy :: Normal</name>
- <description>Implements the normal vote counting strategy</description>
-
<dependencies>
<dependency>
@@ -27,12 +28,19 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
+
<dependency>
<groupId>org.nuiton.i18n</groupId>
<artifactId>nuiton-i18n</artifactId>
</dependency>
<dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
Added: trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCounting.java (rev 0)
+++ trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCounting.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,71 @@
+package org.chorem.pollen.votecounting;
+
+import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
+
+import java.util.Locale;
+
+import static org.nuiton.i18n.I18n.n_;
+
+/**
+ * Coombs vote counting entry point.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.6
+ */
+public class NormalVoteCounting extends AbstractVoteCounting<NormalVoteCountingStrategy> {
+
+ public static final int ID = 0;
+
+ public NormalVoteCounting() {
+ super(ID,
+ NormalVoteCountingStrategy.class,
+ n_("pollen.voteCountingType.normal"),
+ n_("pollen.voteCountingType.normal.help")
+ );
+ }
+
+ @Override
+ public String getDisplayVoteValue(Integer voteValue) {
+ return voteValue != null ? "OK" : "";
+ }
+
+ @Override
+ public boolean isChoiceInVote(Integer voteValue) {
+ return voteValue != null && voteValue > 0;
+ }
+
+ @Override
+ public boolean isVoteValueNull(Integer voteValue) {
+ return voteValue == null || voteValue == 0;
+ }
+
+ @Override
+ public ChoiceToVoteRenderType getVoteValueEditorType() {
+ return ChoiceToVoteRenderType.CHECKBOX;
+ }
+
+ @Override
+ public boolean isVoteValueValid(Integer voteValue) {
+ // no validation on not null vote value
+ return true;
+ }
+
+ @Override
+ public boolean isTotalVoteValueValid(int totalValues) {
+ // no validation on total value
+ return true;
+ }
+
+ @Override
+ public String getVoteValueNotValidMessage(Locale locale) {
+ // no validation on not null vote value, so no message
+ return null;
+ }
+
+ @Override
+ public String getTotalVoteValueNotValidMessage(Locale locale) {
+ // no validation on total values, so no message
+ return null;
+ }
+
+}
Property changes on: trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCounting.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCountingStrategy.java (from rev 3707, trunk/pollen-votecounting-strategy-normal/src/main/java/org/chorem/pollen/votecounting/strategy/NormalStrategy.java)
===================================================================
--- trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCountingStrategy.java (rev 0)
+++ trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCountingStrategy.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,78 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting strategy :: Normal
+ * $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.votecounting;
+
+import org.chorem.pollen.votecounting.model.ChoiceScore;
+import org.chorem.pollen.votecounting.model.VoteCountingResult;
+import org.chorem.pollen.votecounting.model.VoteForChoice;
+import org.chorem.pollen.votecounting.model.Voter;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Condorcet.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class NormalVoteCountingStrategy extends AbstractVoteCountingStrategy {
+
+ @Override
+ public VoteCountingResult votecount(Set<Voter> voters) {
+
+ // get empty result by choice
+ Map<String, ChoiceScore> resultByChoice = votersToResult(voters);
+
+ for (Voter voter : voters) {
+ // add this voter votes to result
+ addVoterChoices(voter, resultByChoice);
+ }
+ // transform map of result to list of them (and sort them)
+ VoteCountingResult result = resultToList(resultByChoice);
+ return result;
+ }
+
+ public void addVoterChoices(Voter voter,
+ Map<String, ChoiceScore> resultByChoice) {
+
+ double voterWeight = voter.getWeight();
+
+ for (VoteForChoice voteForChoice : voter.getVoteForChoices()) {
+ Double voteValue = voteForChoice.getVoteValue();
+ if (voteValue != null) {
+
+ // get score for choice
+ String choiceId = voteForChoice.getChoiceId();
+ ChoiceScore choiceScore = resultByChoice.get(choiceId);
+
+ // compute score to add
+ double scoreToAdd = voteValue * voterWeight;
+
+ // add to score this weighted vote
+ choiceScore.addScoreValue(scoreToAdd);
+ }
+ }
+ }
+
+}
Property changes on: trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCountingStrategy.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/strategy/NormalStrategy.java
===================================================================
--- trunk/pollen-votecounting-strategy-normal/src/main/java/org/chorem/pollen/votecounting/strategy/NormalStrategy.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/strategy/NormalStrategy.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,148 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting strategy :: Normal
- * $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.votecounting.strategy;
-
-import org.chorem.pollen.votecounting.model.ChoiceScore;
-import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
-import org.chorem.pollen.votecounting.model.VoteCountingResult;
-import org.chorem.pollen.votecounting.model.VoteForChoice;
-import org.chorem.pollen.votecounting.model.Voter;
-
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-
-import static org.nuiton.i18n.I18n.n_;
-
-/**
- * Condorcet.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class NormalStrategy extends AbstractVoteCountingStrategy {
-
- public static final int ID = 0;
-
- @Override
- public int getId() {
- return ID;
- }
-
- @Override
- public String getI18nName() {
- return n_("pollen.voteCountingType.normal");
- }
-
- @Override
- public String getI18nHelp() {
- return n_("pollen.voteCountingType.normal.help");
- }
-
- @Override
- public VoteCountingResult votecount(Set<Voter> voters) {
-
- // get empty result by choice
- Map<String, ChoiceScore> resultByChoice = votersToResult(voters);
-
- for (Voter voter : voters) {
- // add this voter votes to result
- addVoterChoices(voter, resultByChoice);
- }
- // transform map of result to list of them (and sort them)
- VoteCountingResult result = resultToList(resultByChoice);
- return result;
- }
-
- @Override
- public String getDisplayVoteValue(Integer voteValue) {
- return voteValue != null ? "OK" : "";
- }
-
- @Override
- public boolean isChoiceInVote(Integer voteValue) {
- return voteValue != null && voteValue > 0;
- }
-
- @Override
- public boolean isVoteValueNull(Integer voteValue) {
- return voteValue == null || voteValue == 0;
- }
-
- @Override
- public ChoiceToVoteRenderType getVoteValueEditorType() {
- return ChoiceToVoteRenderType.CHECKBOX;
- }
-
- @Override
- public boolean isDisplayResultsByChoice() {
- return false;
- }
-
- @Override
- public boolean isVoteValueValid(Integer voteValue) {
- // no validation on not null vote value
- return true;
- }
-
- @Override
- public boolean isTotalVoteValueValid(int totalValues) {
- // no validation on total value
- return true;
- }
-
- @Override
- public String getVoteValueNotValidMessage(Locale locale) {
- // no validation on not null vote value, so no message
- return null;
- }
-
- @Override
- public String getTotalVoteValueNotValidMessage(Locale locale) {
- // no validation on total values, so no message
- return null;
- }
-
- public void addVoterChoices(Voter voter,
- Map<String, ChoiceScore> resultByChoice) {
-
- double voterWeight = voter.getWeight();
-
- for (VoteForChoice voteForChoice : voter.getVoteForChoices()) {
- Double voteValue = voteForChoice.getVoteValue();
- if (voteValue != null) {
-
- // get score for choice
- String choiceId = voteForChoice.getChoiceId();
- ChoiceScore choiceScore = resultByChoice.get(choiceId);
-
- // compute score to add
- double scoreToAdd = voteValue * voterWeight;
-
- // add to score this weighted vote
- choiceScore.addScoreValue(scoreToAdd);
- }
- }
- }
-
-}
Copied: trunk/pollen-votecounting-normal/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting (from rev 3707, trunk/pollen-votecounting-strategy-normal/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy)
===================================================================
--- trunk/pollen-votecounting-normal/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting (rev 0)
+++ trunk/pollen-votecounting-normal/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1 @@
+org.chorem.pollen.votecounting.NormalVoteCounting
Property changes on: trunk/pollen-votecounting-normal/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-normal/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy
===================================================================
--- trunk/pollen-votecounting-strategy-normal/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-normal/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1 +0,0 @@
-org.chorem.pollen.votecounting.strategy.NormalStrategy
Copied: trunk/pollen-votecounting-normal/src/test/java/org/chorem/pollen/votecounting/NormalVoteCountingStrategyTest.java (from rev 3707, trunk/pollen-votecounting-strategy-normal/src/test/java/org/chorem/pollen/votecounting/strategy/NormalStrategyTest.java)
===================================================================
--- trunk/pollen-votecounting-normal/src/test/java/org/chorem/pollen/votecounting/NormalVoteCountingStrategyTest.java (rev 0)
+++ trunk/pollen-votecounting-normal/src/test/java/org/chorem/pollen/votecounting/NormalVoteCountingStrategyTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,344 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting strategy :: Normal
+ * $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.votecounting;
+
+import com.google.common.collect.Maps;
+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.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Tests the {@link NormalVoteCountingStrategy}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class NormalVoteCountingStrategyTest {
+
+ public static final String CHOICE_A = "a";
+
+ public static final String CHOICE_B = "b";
+
+ public static final String CHOICE_C = "c";
+
+ protected static VoteCounting voteCounting;
+
+ protected VoteCountingStrategy strategy;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ VoteCountingFactory factory = new VoteCountingFactory();
+ voteCounting = factory.getVoteCounting(NormalVoteCounting.ID);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ strategy = voteCounting.newVoteCountingStrategy();
+ }
+
+ @Test
+ public void simpleVotecount() throws Exception {
+
+ // Simple 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)
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, 1.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.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);
+ }
+
+ //TODO Finish me
+ @Ignore
+ @Test
+ public void groupVotecount() throws Exception {
+
+ // Group poll (all weight to 1)
+ // G1U1 (a=1 b=null c=null)
+ // G1U2 (a=null b=1 c=null)
+ // G1U3 (a=null b=1 c=1)
+ // Result G1 (a=1 b=2 c=1)
+ // G2U1 (a=null b=1 c=null)
+ // G2U2 (a=1 b=null c=null)
+ // G2U3 (a=null b=1 c=1)
+ // Result G2 (a=1 b=2 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, 1.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)
+ // 1 (a=1 b=null c=null)
+ // 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 SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScore(scores.get(0), CHOICE_A, BigDecimal.valueOf(3.));
+ assertChoiceScore(scores.get(1), CHOICE_B, BigDecimal.valueOf(2.));
+ assertChoiceScore(scores.get(2), CHOICE_C, null);
+ }
+
+ @Test
+ public void simpleVotecount3() throws Exception {
+
+ // Simple poll (all weight to 1)
+ // 1 (a=1 b=1 c=null)
+ // 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 SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScoreEquals(BigDecimal.valueOf(3.),
+ Sets.newHashSet(scores.get(0),
+ scores.get(1)),
+ CHOICE_A, CHOICE_B);
+ assertChoiceScore(scores.get(2), CHOICE_C, null);
+ }
+
+ @Test
+ public void weightedVotecount1() throws Exception {
+
+ // poll with weighted vote
+ // 1 (x2) (a=1 b=null c=null)
+ // 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 SimpleVoterBuilder().
+ newVoter("1", 2.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, 1.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScoreEquals(BigDecimal.valueOf(2.),
+ Sets.newHashSet(scores.get(0),
+ scores.get(1)),
+ CHOICE_A, CHOICE_B);
+ assertChoiceScore(scores.get(2), CHOICE_C, BigDecimal.valueOf(1.));
+ }
+
+ @Test
+ public void weightedVotecount2() throws Exception {
+
+ // poll with weighted vote
+ // 1 (x2) (a=1 b=null c=null)
+ // 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 SimpleVoterBuilder().
+ newVoter("1", 2.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 3.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, 1.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScore(scores.get(0), CHOICE_B, BigDecimal.valueOf(4.));
+ assertChoiceScore(scores.get(1), CHOICE_C, BigDecimal.valueOf(3.));
+ assertChoiceScore(scores.get(2), CHOICE_A, BigDecimal.valueOf(2.));
+ }
+
+ public static void assertChoiceScore(ChoiceScore choiceScore,
+ String choiceId,
+ BigDecimal choiceResult) {
+ Assert.assertNotNull(choiceScore);
+ Assert.assertEquals(choiceId, choiceScore.getChoiceId());
+ Assert.assertEquals(choiceResult, choiceScore.getScoreValue());
+ }
+
+ public static void assertChoiceScoreEquals(BigDecimal choiceResult,
+ Set<ChoiceScore> choiceScores,
+ String... choiceIds) {
+
+ Assert.assertNotNull(choiceScores);
+ Map<String, ChoiceScore> choicesById = Maps.uniqueIndex(
+ choiceScores, new ChoiceIdAble.ChoiceIdAbleById());
+ for (String choiceId : choiceIds) {
+
+ ChoiceScore choiceScore = choicesById.get(choiceId);
+ Assert.assertNotNull(choiceScore);
+ assertChoiceScore(choiceScore, choiceId, choiceResult);
+ }
+ }
+
+}
Property changes on: trunk/pollen-votecounting-normal/src/test/java/org/chorem/pollen/votecounting/NormalVoteCountingStrategyTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-normal/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java (from rev 3707, trunk/pollen-votecounting-strategy-normal/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java)
===================================================================
--- trunk/pollen-votecounting-normal/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java (rev 0)
+++ trunk/pollen-votecounting-normal/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,43 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting strategy :: Normal
+ * $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.votecounting;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests the {@link VoteCountingFactory}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class VoteCountingFactoryTest {
+
+ @Test
+ public void getVoteCounting() throws Exception {
+ VoteCountingFactory factory = new VoteCountingFactory();
+ VoteCounting voteCounting =
+ factory.getVoteCounting(NormalVoteCounting.ID);
+ Assert.assertNotNull(voteCounting);
+ }
+}
Property changes on: trunk/pollen-votecounting-normal/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-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-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-normal/src/test/java/org/chorem/pollen/votecounting/strategy/NormalStrategyTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,338 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting strategy :: Normal
- * $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.votecounting.strategy;
-
-import com.google.common.collect.Maps;
-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.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import java.math.BigDecimal;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Tests the {@link NormalStrategy}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class NormalStrategyTest {
-
- public static final String CHOICE_A = "a";
-
- public static final String CHOICE_B = "b";
-
- public static final String CHOICE_C = "c";
-
- protected static VoteCountingStrategyProvider provider;
-
- protected VoteCountingStrategy strategy;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- provider = new VoteCountingStrategyProvider();
- }
-
- @Before
- public void setUp() throws Exception {
- strategy = provider.getStrategy(NormalStrategy.ID);
- }
-
- @Test
- public void simpleVotecount() throws Exception {
-
- // Simple 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)
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, 1.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.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);
- }
-
- //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)
- // 1 (a=1 b=null c=null)
- // 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 SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScore(scores.get(0), CHOICE_A, BigDecimal.valueOf(3.));
- assertChoiceScore(scores.get(1), CHOICE_B, BigDecimal.valueOf(2.));
- assertChoiceScore(scores.get(2), CHOICE_C, null);
- }
-
- @Test
- public void simpleVotecount3() throws Exception {
-
- // Simple poll (all weight to 1)
- // 1 (a=1 b=1 c=null)
- // 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 SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScoreEquals(BigDecimal.valueOf(3.),
- Sets.newHashSet(scores.get(0),
- scores.get(1)),
- CHOICE_A, CHOICE_B);
- assertChoiceScore(scores.get(2), CHOICE_C, null);
- }
-
- @Test
- public void weightedVotecount1() throws Exception {
-
- // poll with weighted vote
- // 1 (x2) (a=1 b=null c=null)
- // 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 SimpleVoterBuilder().
- newVoter("1", 2.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, 1.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScoreEquals(BigDecimal.valueOf(2.),
- Sets.newHashSet(scores.get(0),
- scores.get(1)),
- CHOICE_A, CHOICE_B);
- assertChoiceScore(scores.get(2), CHOICE_C, BigDecimal.valueOf(1.));
- }
-
- @Test
- public void weightedVotecount2() throws Exception {
-
- // poll with weighted vote
- // 1 (x2) (a=1 b=null c=null)
- // 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 SimpleVoterBuilder().
- newVoter("1", 2.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 3.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, 1.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScore(scores.get(0), CHOICE_B, BigDecimal.valueOf(4.));
- assertChoiceScore(scores.get(1), CHOICE_C, BigDecimal.valueOf(3.));
- assertChoiceScore(scores.get(2), CHOICE_A, BigDecimal.valueOf(2.));
- }
-
- public static void assertChoiceScore(ChoiceScore choiceScore,
- String choiceId,
- BigDecimal choiceResult) {
- Assert.assertNotNull(choiceScore);
- Assert.assertEquals(choiceId, choiceScore.getChoiceId());
- Assert.assertEquals(choiceResult, choiceScore.getScoreValue());
- }
-
- public static void assertChoiceScoreEquals(BigDecimal choiceResult,
- Set<ChoiceScore> choiceScores,
- String... choiceIds) {
-
- Assert.assertNotNull(choiceScores);
- Map<String, ChoiceScore> choicesById = Maps.uniqueIndex(
- choiceScores, new ChoiceIdAble.ChoiceIdAbleById());
- for (String choiceId : choiceIds) {
-
- ChoiceScore choiceScore = choicesById.get(choiceId);
- Assert.assertNotNull(choiceScore);
- assertChoiceScore(choiceScore, choiceId, choiceResult);
- }
- }
-
-}
Deleted: trunk/pollen-votecounting-normal/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java
===================================================================
--- trunk/pollen-votecounting-strategy-normal/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-normal/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,49 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting strategy :: Normal
- * $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.votecounting.strategy;
-
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * Tests the {@link VoteCountingStrategyProvider}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class VoteCountingStrategyProviderTest {
-
- protected static VoteCountingStrategyProvider provider;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- provider = new VoteCountingStrategyProvider();
- }
-
- @Test
- public void getStrategy() throws Exception {
-
- Assert.assertNotNull(provider.getStrategy(NormalStrategy.ID));
- }
-}
Modified: trunk/pollen-votecounting-number/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy-number/pom.xml 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-number/pom.xml 2012-09-29 12:36:25 UTC (rev 3708)
@@ -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>
@@ -10,11 +12,10 @@
</parent>
<groupId>org.chorem.pollen</groupId>
- <artifactId>pollen-votecounting-strategy-number</artifactId>
+ <artifactId>pollen-votecounting-number</artifactId>
+ <name>Pollen :: VoteCounting :: Number</name>
+ <description>Implements the number vote counting</description>
- <name>Pollen :: VoteCounting strategy :: Number</name>
- <description>Implements the number vote counting strategy</description>
-
<dependencies>
<dependency>
@@ -27,12 +28,19 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
+
<dependency>
<groupId>org.nuiton.i18n</groupId>
<artifactId>nuiton-i18n</artifactId>
</dependency>
<dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
Added: trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCounting.java (rev 0)
+++ trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCounting.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,71 @@
+package org.chorem.pollen.votecounting;
+
+import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
+
+import java.util.Locale;
+
+import static org.nuiton.i18n.I18n.n_;
+
+/**
+ * Coombs vote counting entry point.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.6
+ */
+public class NumberVoteCounting extends AbstractVoteCounting<NumberVoteCountingStrategy> {
+
+ public static final int ID = 3;
+
+ public NumberVoteCounting() {
+ super(ID,
+ NumberVoteCountingStrategy.class,
+ n_("pollen.voteCountingType.number"),
+ n_("pollen.voteCountingType.number.help")
+ );
+ }
+
+ @Override
+ public String getDisplayVoteValue(Integer voteValue) {
+ return voteValue == null ? "" : String.valueOf(voteValue);
+ }
+
+ @Override
+ public boolean isChoiceInVote(Integer voteValue) {
+ return voteValue != null && voteValue >= 0;
+ }
+
+ @Override
+ public boolean isVoteValueNull(Integer voteValue) {
+ return voteValue == null || voteValue == 0;
+ }
+
+ @Override
+ public ChoiceToVoteRenderType getVoteValueEditorType() {
+ return ChoiceToVoteRenderType.TEXTFIELD;
+ }
+
+ @Override
+ public boolean isVoteValueValid(Integer voteValue) {
+ // no validation on not null vote value
+ return true;
+ }
+
+ @Override
+ public boolean isTotalVoteValueValid(int totalValues) {
+ // no validation on total value
+ return true;
+ }
+
+ @Override
+ public String getTotalVoteValueNotValidMessage(Locale locale) {
+ // no validation on total values, so no message
+ return null;
+ }
+
+ @Override
+ public String getVoteValueNotValidMessage(Locale locale) {
+ // no validation on not null vote value, so no message
+ return null;
+ }
+
+}
Property changes on: trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCounting.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCountingStrategy.java (from rev 3707, trunk/pollen-votecounting-strategy-number/src/main/java/org/chorem/pollen/votecounting/strategy/NumberStrategy.java)
===================================================================
--- trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCountingStrategy.java (rev 0)
+++ trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCountingStrategy.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,77 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting strategy :: Number
+ * $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.votecounting;
+
+import org.chorem.pollen.votecounting.model.ChoiceScore;
+import org.chorem.pollen.votecounting.model.VoteCountingResult;
+import org.chorem.pollen.votecounting.model.VoteForChoice;
+import org.chorem.pollen.votecounting.model.Voter;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Number strategy.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class NumberVoteCountingStrategy extends AbstractVoteCountingStrategy {
+
+ @Override
+ public VoteCountingResult votecount(Set<Voter> voters) {
+
+ // get empty result by choice
+ Map<String, ChoiceScore> resultByChoice = votersToResult(voters);
+
+ for (Voter voter : voters) {
+ // add this voter votes to result
+ addVoterChoices(voter, resultByChoice);
+ }
+ // transform map of result to list of them (and sort them)
+ VoteCountingResult result = resultToList(resultByChoice);
+ return result;
+ }
+
+ public void addVoterChoices(Voter voter,
+ Map<String, ChoiceScore> resultByChoice) {
+
+ double voterWeight = voter.getWeight();
+
+ for (VoteForChoice voteForChoice : voter.getVoteForChoices()) {
+ Double voteValue = voteForChoice.getVoteValue();
+ if (voteValue != null) {
+
+ // get score for choice
+ String choiceId = voteForChoice.getChoiceId();
+ ChoiceScore choiceScore = resultByChoice.get(choiceId);
+
+ // compute score to add
+ double scoreToAdd = voteValue * voterWeight;
+
+ // add to score this weighted vote
+ choiceScore.addScoreValue(scoreToAdd);
+ }
+ }
+ }
+}
Property changes on: trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCountingStrategy.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/strategy/NumberStrategy.java
===================================================================
--- trunk/pollen-votecounting-strategy-number/src/main/java/org/chorem/pollen/votecounting/strategy/NumberStrategy.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/strategy/NumberStrategy.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,147 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting strategy :: Number
- * $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.votecounting.strategy;
-
-import org.chorem.pollen.votecounting.model.ChoiceScore;
-import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
-import org.chorem.pollen.votecounting.model.VoteCountingResult;
-import org.chorem.pollen.votecounting.model.VoteForChoice;
-import org.chorem.pollen.votecounting.model.Voter;
-
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-
-import static org.nuiton.i18n.I18n.n_;
-
-/**
- * Number strategy.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class NumberStrategy extends AbstractVoteCountingStrategy {
-
- public static final int ID = 3;
-
- @Override
- public int getId() {
- return ID;
- }
-
- @Override
- public String getI18nName() {
- return n_("pollen.voteCountingType.number");
- }
-
- @Override
- public String getI18nHelp() {
- return n_("pollen.voteCountingType.number.help");
- }
-
- @Override
- public VoteCountingResult votecount(Set<Voter> voters) {
-
- // get empty result by choice
- Map<String, ChoiceScore> resultByChoice = votersToResult(voters);
-
- for (Voter voter : voters) {
- // add this voter votes to result
- addVoterChoices(voter, resultByChoice);
- }
- // transform map of result to list of them (and sort them)
- VoteCountingResult result = resultToList(resultByChoice);
- return result;
- }
-
- @Override
- public String getDisplayVoteValue(Integer voteValue) {
- return voteValue == null ? "" : String.valueOf(voteValue);
- }
-
- @Override
- public boolean isChoiceInVote(Integer voteValue) {
- return voteValue != null && voteValue >= 0;
- }
-
- @Override
- public boolean isVoteValueNull(Integer voteValue) {
- return voteValue == null || voteValue == 0;
- }
-
- @Override
- public ChoiceToVoteRenderType getVoteValueEditorType() {
- return ChoiceToVoteRenderType.TEXTFIELD;
- }
-
- @Override
- public boolean isDisplayResultsByChoice() {
- return true;
- }
-
- @Override
- public boolean isVoteValueValid(Integer voteValue) {
- // no validation on not null vote value
- return true;
- }
-
- @Override
- public boolean isTotalVoteValueValid(int totalValues) {
- // no validation on total value
- return true;
- }
-
- @Override
- public String getTotalVoteValueNotValidMessage(Locale locale) {
- // no validation on total values, so no message
- return null;
- }
-
- @Override
- public String getVoteValueNotValidMessage(Locale locale) {
- // no validation on not null vote value, so no message
- return null;
- }
-
- public void addVoterChoices(Voter voter,
- Map<String, ChoiceScore> resultByChoice) {
-
- double voterWeight = voter.getWeight();
-
- for (VoteForChoice voteForChoice : voter.getVoteForChoices()) {
- Double voteValue = voteForChoice.getVoteValue();
- if (voteValue != null) {
-
- // get score for choice
- String choiceId = voteForChoice.getChoiceId();
- ChoiceScore choiceScore = resultByChoice.get(choiceId);
-
- // compute score to add
- double scoreToAdd = voteValue * voterWeight;
-
- // add to score this weighted vote
- choiceScore.addScoreValue(scoreToAdd);
- }
- }
- }
-}
Copied: trunk/pollen-votecounting-number/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting (from rev 3707, trunk/pollen-votecounting-strategy-number/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy)
===================================================================
--- trunk/pollen-votecounting-number/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting (rev 0)
+++ trunk/pollen-votecounting-number/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1 @@
+org.chorem.pollen.votecounting.NumberVoteCounting
Property changes on: trunk/pollen-votecounting-number/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-number/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy
===================================================================
--- trunk/pollen-votecounting-strategy-number/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-number/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1 +0,0 @@
-org.chorem.pollen.votecounting.strategy.NumberStrategy
Copied: trunk/pollen-votecounting-number/src/test/java/org/chorem/pollen/votecounting/NumberVoteCountingStrategyTest.java (from rev 3707, trunk/pollen-votecounting-strategy-number/src/test/java/org/chorem/pollen/votecounting/strategy/NumberStrategyTest.java)
===================================================================
--- trunk/pollen-votecounting-number/src/test/java/org/chorem/pollen/votecounting/NumberVoteCountingStrategyTest.java (rev 0)
+++ trunk/pollen-votecounting-number/src/test/java/org/chorem/pollen/votecounting/NumberVoteCountingStrategyTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,274 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting strategy :: Number
+ * $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.votecounting;
+
+import com.google.common.collect.Maps;
+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.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Tests the {@link NumberVoteCountingStrategy}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class NumberVoteCountingStrategyTest {
+
+ public static final String CHOICE_A = "a";
+
+ public static final String CHOICE_B = "b";
+
+ public static final String CHOICE_C = "c";
+
+ protected static VoteCounting voteCounting;
+
+ protected VoteCountingStrategy strategy;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ VoteCountingFactory factory = new VoteCountingFactory();
+ voteCounting = factory.getVoteCounting(NumberVoteCounting.ID);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ strategy = voteCounting.newVoteCountingStrategy();
+ }
+
+ @Test
+ public void simpleVotecount() throws Exception {
+
+ // Simple poll (all weight to 1)
+ // 1 (a=1 b=2 c=null)
+ // 2 (a=2 b=null c=3)
+ // 3 (a=7 b=12 c=20)
+ // Result (a=10 b=14 c=23)
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 2.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, 2.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, 3.).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, 7.).
+ addVoteForChoice(CHOICE_B, 12.).
+ addVoteForChoice(CHOICE_C, 20.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScore(scores.get(0), CHOICE_C, BigDecimal.valueOf(23.));
+ assertChoiceScore(scores.get(1), CHOICE_B, BigDecimal.valueOf(14.));
+ assertChoiceScore(scores.get(2), CHOICE_A, BigDecimal.valueOf(10.));
+ }
+
+ @Test
+ public void simpleVotecount2() throws Exception {
+
+ // Simple poll (all weight to 1)
+ // 1 (a=1 b=null c=null)
+ // 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 SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScore(scores.get(0), CHOICE_A, BigDecimal.valueOf(3.));
+ assertChoiceScore(scores.get(1), CHOICE_B, BigDecimal.valueOf(2.));
+ assertChoiceScore(scores.get(2), CHOICE_C, null);
+ }
+
+ @Test
+ public void simpleVotecount3() throws Exception {
+
+ // Simple poll (all weight to 1)
+ // 1 (a=1 b=1 c=null)
+ // 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 SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScoreEquals(BigDecimal.valueOf(3.),
+ Sets.newHashSet(scores.get(0),
+ scores.get(1)),
+ CHOICE_A, CHOICE_B);
+ assertChoiceScore(scores.get(2), CHOICE_C, null);
+ }
+
+ @Test
+ public void weightedVotecount1() throws Exception {
+
+ // poll with weighted vote
+ // 1 (x2) (a=1 b=null c=null)
+ // 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 SimpleVoterBuilder().
+ newVoter("1", 2.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, 1.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScoreEquals(BigDecimal.valueOf(2.),
+ Sets.newHashSet(scores.get(0),
+ scores.get(1)),
+ CHOICE_A, CHOICE_B);
+ assertChoiceScore(scores.get(2), CHOICE_C, BigDecimal.valueOf(1.));
+ }
+
+ @Test
+ public void weightedVotecount2() throws Exception {
+
+ // poll with weighted vote
+ // 1 (x2) (a=1 b=null c=null)
+ // 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 SimpleVoterBuilder().
+ newVoter("1", 2.).
+ addVoteForChoice(CHOICE_A, 1.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 3.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 1.).
+ addVoteForChoice(CHOICE_C, 1.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScore(scores.get(0), CHOICE_B, BigDecimal.valueOf(4.));
+ assertChoiceScore(scores.get(1), CHOICE_C, BigDecimal.valueOf(3.));
+ assertChoiceScore(scores.get(2), CHOICE_A, BigDecimal.valueOf(2.));
+ }
+
+ public static void assertChoiceScore(ChoiceScore choiceScore,
+ String choiceId,
+ BigDecimal choiceResult) {
+ Assert.assertNotNull(choiceScore);
+ Assert.assertEquals(choiceId, choiceScore.getChoiceId());
+ Assert.assertEquals(choiceResult, choiceScore.getScoreValue());
+ }
+
+ public static void assertChoiceScoreEquals(BigDecimal choiceResult,
+ Set<ChoiceScore> choiceScores,
+ String... choiceIds) {
+
+ Assert.assertNotNull(choiceScores);
+ Map<String, ChoiceScore> choicesById = Maps.uniqueIndex(
+ choiceScores, new ChoiceIdAble.ChoiceIdAbleById());
+ for (String choiceId : choiceIds) {
+
+ ChoiceScore choiceScore = choicesById.get(choiceId);
+ Assert.assertNotNull(choiceScore);
+ assertChoiceScore(choiceScore, choiceId, choiceResult);
+ }
+ }
+
+}
Property changes on: trunk/pollen-votecounting-number/src/test/java/org/chorem/pollen/votecounting/NumberVoteCountingStrategyTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-number/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java (from rev 3707, trunk/pollen-votecounting-strategy-number/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java)
===================================================================
--- trunk/pollen-votecounting-number/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java (rev 0)
+++ trunk/pollen-votecounting-number/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,43 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting strategy :: Number
+ * $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.votecounting;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests the {@link VoteCountingFactory}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class VoteCountingFactoryTest {
+
+ @Test
+ public void getVoteCounting() throws Exception {
+ VoteCountingFactory factory = new VoteCountingFactory();
+ VoteCounting voteCounting =
+ factory.getVoteCounting(NumberVoteCounting.ID);
+ Assert.assertNotNull(voteCounting);
+ }
+}
Property changes on: trunk/pollen-votecounting-number/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-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-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-number/src/test/java/org/chorem/pollen/votecounting/strategy/NumberStrategyTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,273 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting strategy :: Number
- * $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.votecounting.strategy;
-
-import com.google.common.collect.Maps;
-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.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import java.math.BigDecimal;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Tests the {@link NumberStrategy}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class NumberStrategyTest {
-
- public static final String CHOICE_A = "a";
-
- public static final String CHOICE_B = "b";
-
- public static final String CHOICE_C = "c";
-
- protected static VoteCountingStrategyProvider provider;
-
- protected VoteCountingStrategy strategy;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- provider = new VoteCountingStrategyProvider();
- }
-
- @Before
- public void setUp() throws Exception {
- strategy = provider.getStrategy(NumberStrategy.ID);
- }
-
- @Test
- public void simpleVotecount() throws Exception {
-
- // Simple poll (all weight to 1)
- // 1 (a=1 b=2 c=null)
- // 2 (a=2 b=null c=3)
- // 3 (a=7 b=12 c=20)
- // Result (a=10 b=14 c=23)
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 2.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, 2.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, 3.).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, 7.).
- addVoteForChoice(CHOICE_B, 12.).
- addVoteForChoice(CHOICE_C, 20.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScore(scores.get(0), CHOICE_C, BigDecimal.valueOf(23.));
- assertChoiceScore(scores.get(1), CHOICE_B, BigDecimal.valueOf(14.));
- assertChoiceScore(scores.get(2), CHOICE_A, BigDecimal.valueOf(10.));
- }
-
- @Test
- public void simpleVotecount2() throws Exception {
-
- // Simple poll (all weight to 1)
- // 1 (a=1 b=null c=null)
- // 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 SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScore(scores.get(0), CHOICE_A, BigDecimal.valueOf(3.));
- assertChoiceScore(scores.get(1), CHOICE_B, BigDecimal.valueOf(2.));
- assertChoiceScore(scores.get(2), CHOICE_C, null);
- }
-
- @Test
- public void simpleVotecount3() throws Exception {
-
- // Simple poll (all weight to 1)
- // 1 (a=1 b=1 c=null)
- // 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 SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScoreEquals(BigDecimal.valueOf(3.),
- Sets.newHashSet(scores.get(0),
- scores.get(1)),
- CHOICE_A, CHOICE_B);
- assertChoiceScore(scores.get(2), CHOICE_C, null);
- }
-
- @Test
- public void weightedVotecount1() throws Exception {
-
- // poll with weighted vote
- // 1 (x2) (a=1 b=null c=null)
- // 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 SimpleVoterBuilder().
- newVoter("1", 2.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, 1.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScoreEquals(BigDecimal.valueOf(2.),
- Sets.newHashSet(scores.get(0),
- scores.get(1)),
- CHOICE_A, CHOICE_B);
- assertChoiceScore(scores.get(2), CHOICE_C, BigDecimal.valueOf(1.));
- }
-
- @Test
- public void weightedVotecount2() throws Exception {
-
- // poll with weighted vote
- // 1 (x2) (a=1 b=null c=null)
- // 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 SimpleVoterBuilder().
- newVoter("1", 2.).
- addVoteForChoice(CHOICE_A, 1.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 3.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 1.).
- addVoteForChoice(CHOICE_C, 1.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScore(scores.get(0), CHOICE_B, BigDecimal.valueOf(4.));
- assertChoiceScore(scores.get(1), CHOICE_C, BigDecimal.valueOf(3.));
- assertChoiceScore(scores.get(2), CHOICE_A, BigDecimal.valueOf(2.));
- }
-
- public static void assertChoiceScore(ChoiceScore choiceScore,
- String choiceId,
- BigDecimal choiceResult) {
- Assert.assertNotNull(choiceScore);
- Assert.assertEquals(choiceId, choiceScore.getChoiceId());
- Assert.assertEquals(choiceResult, choiceScore.getScoreValue());
- }
-
- public static void assertChoiceScoreEquals(BigDecimal choiceResult,
- Set<ChoiceScore> choiceScores,
- String... choiceIds) {
-
- Assert.assertNotNull(choiceScores);
- Map<String, ChoiceScore> choicesById = Maps.uniqueIndex(
- choiceScores, new ChoiceIdAble.ChoiceIdAbleById());
- for (String choiceId : choiceIds) {
-
- ChoiceScore choiceScore = choicesById.get(choiceId);
- Assert.assertNotNull(choiceScore);
- assertChoiceScore(choiceScore, choiceId, choiceResult);
- }
- }
-
-}
Deleted: trunk/pollen-votecounting-number/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java
===================================================================
--- trunk/pollen-votecounting-strategy-number/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-number/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,49 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting strategy :: Number
- * $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.votecounting.strategy;
-
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * Tests the {@link VoteCountingStrategyProvider}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class VoteCountingStrategyProviderTest {
-
- protected static VoteCountingStrategyProvider provider;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- provider = new VoteCountingStrategyProvider();
- }
-
- @Test
- public void getStrategy() throws Exception {
-
- Assert.assertNotNull(provider.getStrategy(NumberStrategy.ID));
- }
-}
Modified: trunk/pollen-votecounting-percentage/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy-percentage/pom.xml 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-percentage/pom.xml 2012-09-29 12:36:25 UTC (rev 3708)
@@ -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>
@@ -10,11 +12,10 @@
</parent>
<groupId>org.chorem.pollen</groupId>
- <artifactId>pollen-votecounting-strategy-percentage</artifactId>
+ <artifactId>pollen-votecounting-percentage</artifactId>
+ <name>Pollen :: VoteCounting :: Percentage</name>
+ <description>Implements the percentage vote counting</description>
- <name>Pollen :: VoteCounting strategy :: Percentage</name>
- <description>Implements the percentage vote counting strategy</description>
-
<dependencies>
<dependency>
@@ -23,23 +24,22 @@
<version>${project.version}</version>
</dependency>
- <!--dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </dependency-->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
+
<dependency>
<groupId>org.nuiton.i18n</groupId>
<artifactId>nuiton-i18n</artifactId>
</dependency>
+
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
<scope>test</scope>
</dependency>
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Added: trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCounting.java
===================================================================
--- trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCounting.java (rev 0)
+++ trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCounting.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,71 @@
+package org.chorem.pollen.votecounting;
+
+import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
+
+import java.util.Locale;
+
+import static org.nuiton.i18n.I18n.l_;
+import static org.nuiton.i18n.I18n.n_;
+
+/**
+ * Coombs vote counting entry point.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.6
+ */
+public class PercentageVoteCounting extends AbstractVoteCounting<PercentageVoteCountingStrategy> {
+
+ public static final int ID = 1;
+
+ public PercentageVoteCounting() {
+ super(ID,
+ PercentageVoteCountingStrategy.class,
+ n_("pollen.voteCountingType.percentage"),
+ n_("pollen.voteCountingType.percentage.help")
+ );
+ }
+
+ @Override
+ public String getDisplayVoteValue(Integer voteValue) {
+ return voteValue == null ? "" : String.valueOf(voteValue);
+ }
+
+ @Override
+ public boolean isChoiceInVote(Integer voteValue) {
+ return voteValue != null && voteValue >= 0 && voteValue <= 100;
+ }
+
+
+ @Override
+ public boolean isVoteValueNull(Integer value) {
+ return value == null || value == 0;
+ }
+
+ @Override
+ public ChoiceToVoteRenderType getVoteValueEditorType() {
+ return ChoiceToVoteRenderType.TEXTFIELD;
+ }
+
+ @Override
+ public boolean isVoteValueValid(Integer voteValue) {
+ // no validation on not null vote value
+ return true;
+ }
+
+ @Override
+ public boolean isTotalVoteValueValid(int totalValues) {
+ return totalValues == 100;
+ }
+
+ @Override
+ public String getVoteValueNotValidMessage(Locale locale) {
+ // no validation on not null vote value, so no message
+ return null;
+ }
+
+ @Override
+ public String getTotalVoteValueNotValidMessage(Locale locale) {
+ return l_(locale, "pollen.error.vote.percentage");
+ }
+
+}
Property changes on: trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCounting.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCountingStrategy.java (from rev 3707, trunk/pollen-votecounting-strategy-percentage/src/main/java/org/chorem/pollen/votecounting/strategy/PercentageStrategy.java)
===================================================================
--- trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCountingStrategy.java (rev 0)
+++ trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCountingStrategy.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,76 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting strategy :: Percentage
+ * $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.votecounting;
+
+import org.chorem.pollen.votecounting.model.ChoiceScore;
+import org.chorem.pollen.votecounting.model.VoteCountingResult;
+import org.chorem.pollen.votecounting.model.VoteForChoice;
+import org.chorem.pollen.votecounting.model.Voter;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Percentage strategy.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class PercentageVoteCountingStrategy extends AbstractVoteCountingStrategy {
+
+ @Override
+ public VoteCountingResult votecount(Set<Voter> voters) {
+ // get empty result by choice
+ Map<String, ChoiceScore> resultByChoice = votersToResult(voters);
+
+ for (Voter voter : voters) {
+ // add this voter votes to result
+ addVoterChoices(voter, resultByChoice);
+ }
+ // transform map of result to list of them (and sort them)
+ VoteCountingResult result = resultToList(resultByChoice);
+ return result;
+ }
+
+ public void addVoterChoices(Voter voter,
+ Map<String, ChoiceScore> resultByChoice) {
+
+ double voterWeight = voter.getWeight();
+
+ for (VoteForChoice voteForChoice : voter.getVoteForChoices()) {
+ Double voteValue = voteForChoice.getVoteValue();
+ if (voteValue != null) {
+
+ // get score for choice
+ String choiceId = voteForChoice.getChoiceId();
+ ChoiceScore choiceScore = resultByChoice.get(choiceId);
+
+ // compute score to add
+ double scoreToAdd = voteValue * voterWeight;
+
+ // add to score this weighted vote
+ choiceScore.addScoreValue(scoreToAdd);
+ }
+ }
+ }
+}
Property changes on: trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCountingStrategy.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/strategy/PercentageStrategy.java
===================================================================
--- trunk/pollen-votecounting-strategy-percentage/src/main/java/org/chorem/pollen/votecounting/strategy/PercentageStrategy.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/strategy/PercentageStrategy.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,146 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting strategy :: Percentage
- * $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.votecounting.strategy;
-
-import org.chorem.pollen.votecounting.model.ChoiceScore;
-import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType;
-import org.chorem.pollen.votecounting.model.VoteCountingResult;
-import org.chorem.pollen.votecounting.model.VoteForChoice;
-import org.chorem.pollen.votecounting.model.Voter;
-
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-
-import static org.nuiton.i18n.I18n.l_;
-import static org.nuiton.i18n.I18n.n_;
-
-/**
- * Percentage strategy.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class PercentageStrategy extends AbstractVoteCountingStrategy {
-
- public static final int ID = 1;
-
- @Override
- public int getId() {
- return ID;
- }
-
- @Override
- public String getI18nName() {
- return n_("pollen.voteCountingType.percentage");
- }
-
- @Override
- public String getI18nHelp() {
- return n_("pollen.voteCountingType.percentage.help");
- }
-
- @Override
- public VoteCountingResult votecount(Set<Voter> voters) {
- // get empty result by choice
- Map<String, ChoiceScore> resultByChoice = votersToResult(voters);
-
- for (Voter voter : voters) {
- // add this voter votes to result
- addVoterChoices(voter, resultByChoice);
- }
- // transform map of result to list of them (and sort them)
- VoteCountingResult result = resultToList(resultByChoice);
- return result;
- }
-
- @Override
- public String getDisplayVoteValue(Integer voteValue) {
- return voteValue == null ? "" : String.valueOf(voteValue);
- }
-
- @Override
- public boolean isChoiceInVote(Integer voteValue) {
- return voteValue != null && voteValue >= 0 && voteValue <= 100;
- }
-
-
- @Override
- public boolean isVoteValueNull(Integer value) {
- return value == null || value == 0;
- }
-
- @Override
- public ChoiceToVoteRenderType getVoteValueEditorType() {
- return ChoiceToVoteRenderType.TEXTFIELD;
- }
-
- @Override
- public boolean isDisplayResultsByChoice() {
- return false;
- }
-
- @Override
- public boolean isVoteValueValid(Integer voteValue) {
- // no validation on not null vote value
- return true;
- }
-
- @Override
- public boolean isTotalVoteValueValid(int totalValues) {
- return totalValues == 100;
- }
-
- @Override
- public String getVoteValueNotValidMessage(Locale locale) {
- // no validation on not null vote value, so no message
- return null;
- }
-
- @Override
- public String getTotalVoteValueNotValidMessage(Locale locale) {
- return l_(locale, "pollen.error.vote.percentage");
- }
-
- public void addVoterChoices(Voter voter,
- Map<String, ChoiceScore> resultByChoice) {
-
- double voterWeight = voter.getWeight();
-
- for (VoteForChoice voteForChoice : voter.getVoteForChoices()) {
- Double voteValue = voteForChoice.getVoteValue();
- if (voteValue != null) {
-
- // get score for choice
- String choiceId = voteForChoice.getChoiceId();
- ChoiceScore choiceScore = resultByChoice.get(choiceId);
-
- // compute score to add
- double scoreToAdd = voteValue * voterWeight;
-
- // add to score this weighted vote
- choiceScore.addScoreValue(scoreToAdd);
- }
- }
- }
-}
Copied: trunk/pollen-votecounting-percentage/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting (from rev 3707, trunk/pollen-votecounting-strategy-percentage/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy)
===================================================================
--- trunk/pollen-votecounting-percentage/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting (rev 0)
+++ trunk/pollen-votecounting-percentage/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1 @@
+org.chorem.pollen.votecounting.PercentageVoteCounting
Property changes on: trunk/pollen-votecounting-percentage/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.VoteCounting
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-percentage/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy
===================================================================
--- trunk/pollen-votecounting-strategy-percentage/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-percentage/src/main/resources/META-INF/services/org.chorem.pollen.votecounting.strategy.VoteCountingStrategy 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1 +0,0 @@
-org.chorem.pollen.votecounting.strategy.PercentageStrategy
Copied: trunk/pollen-votecounting-percentage/src/test/java/org/chorem/pollen/votecounting/PercentageVoteCountingStrategyTest.java (from rev 3707, trunk/pollen-votecounting-strategy-percentage/src/test/java/org/chorem/pollen/votecounting/strategy/PercentageStrategyTest.java)
===================================================================
--- trunk/pollen-votecounting-percentage/src/test/java/org/chorem/pollen/votecounting/PercentageVoteCountingStrategyTest.java (rev 0)
+++ trunk/pollen-votecounting-percentage/src/test/java/org/chorem/pollen/votecounting/PercentageVoteCountingStrategyTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,275 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting strategy :: Percentage
+ * $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.votecounting;
+
+import com.google.common.collect.Maps;
+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.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Tests the {@link PercentageVoteCountingStrategy}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class PercentageVoteCountingStrategyTest {
+
+ public static final String CHOICE_A = "a";
+
+ public static final String CHOICE_B = "b";
+
+ public static final String CHOICE_C = "c";
+
+ protected static VoteCounting voteCounting;
+
+ protected VoteCountingStrategy strategy;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ VoteCountingFactory factory = new VoteCountingFactory();
+ voteCounting = factory.getVoteCounting(PercentageVoteCounting.ID);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+
+ strategy = voteCounting.newVoteCountingStrategy();
+ }
+
+ @Test
+ public void simpleVotecount() throws Exception {
+
+ // Simple poll (all weight to 1)
+ // 1 (a=100 b=null c=null)
+ // 2 (a=null b=100 c=null)
+ // 3 (a=50 b=50 c=null)
+ // Result (a=100 b=150 c=null)
+
+ Set<Voter> voters = new SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 100.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 100.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, 50.).
+ addVoteForChoice(CHOICE_B, 50.).
+ addVoteForChoice(CHOICE_C, null).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScoreEquals(BigDecimal.valueOf(150.),
+ Sets.newHashSet(scores.get(0),
+ scores.get(1)),
+ CHOICE_A, CHOICE_B);
+
+ assertChoiceScore(scores.get(2), CHOICE_C, null);
+ }
+
+ @Test
+ public void simpleVotecount2() throws Exception {
+
+ // Simple poll (all weight to 1)
+ // 1 (a=20 b=30 c=50)
+ // 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 SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 20.).
+ addVoteForChoice(CHOICE_B, 30.).
+ addVoteForChoice(CHOICE_C, 50.).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, 50.).
+ addVoteForChoice(CHOICE_B, 20.).
+ addVoteForChoice(CHOICE_C, 30.).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, 10.).
+ addVoteForChoice(CHOICE_B, 50.).
+ addVoteForChoice(CHOICE_C, 40.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScore(scores.get(0), CHOICE_C, BigDecimal.valueOf(120.));
+ assertChoiceScore(scores.get(1), CHOICE_B, BigDecimal.valueOf(100.));
+ assertChoiceScore(scores.get(2), CHOICE_A, BigDecimal.valueOf(80.));
+ }
+
+ @Test
+ public void simpleVotecount3() throws Exception {
+
+ // Simple poll (all weight to 1)
+ // 1 (a=50 b=50 c=null)
+ // 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 SimpleVoterBuilder().
+ newVoter("1", 1.).
+ addVoteForChoice(CHOICE_A, 50.).
+ addVoteForChoice(CHOICE_B, 50.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, 50.).
+ addVoteForChoice(CHOICE_B, 50.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, 50.).
+ addVoteForChoice(CHOICE_B, 50.).
+ addVoteForChoice(CHOICE_C, null).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScoreEquals(BigDecimal.valueOf(150.),
+ Sets.newHashSet(scores.get(0),
+ scores.get(1)),
+ CHOICE_A, CHOICE_B);
+ assertChoiceScore(scores.get(2), CHOICE_C, null);
+ }
+
+ @Test
+ public void weightedVotecount1() throws Exception {
+
+ // poll with weighted vote
+ // 1 (x2) (a=100 b=null c=null)
+ // 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 SimpleVoterBuilder().
+ newVoter("1", 2.).
+ addVoteForChoice(CHOICE_A, 100.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 100.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 50.).
+ addVoteForChoice(CHOICE_C, 50.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+ assertChoiceScore(scores.get(0), CHOICE_A, BigDecimal.valueOf(200.));
+ assertChoiceScore(scores.get(1), CHOICE_B, BigDecimal.valueOf(150.));
+ assertChoiceScore(scores.get(2), CHOICE_C, BigDecimal.valueOf(50.));
+ }
+
+ @Test
+ public void weightedVotecount2() throws Exception {
+
+ // poll with weighted vote
+ // 1 (x2) (a=100 b=null c=null)
+ // 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 SimpleVoterBuilder().
+ newVoter("1", 2.).
+ addVoteForChoice(CHOICE_A, 100.).
+ addVoteForChoice(CHOICE_B, null).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("2", 1.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 100.).
+ addVoteForChoice(CHOICE_C, null).
+ newVoter("3", 3.).
+ addVoteForChoice(CHOICE_A, null).
+ addVoteForChoice(CHOICE_B, 50.).
+ addVoteForChoice(CHOICE_C, 50.).
+ getVoters();
+
+ VoteCountingResult result = strategy.votecount(voters);
+
+ Assert.assertNotNull(result);
+ List<ChoiceScore> scores = result.getScores();
+ Assert.assertNotNull(scores);
+ Assert.assertEquals(3, scores.size());
+
+ assertChoiceScore(scores.get(0), CHOICE_B, BigDecimal.valueOf(250.));
+ assertChoiceScore(scores.get(1), CHOICE_A, BigDecimal.valueOf(200.));
+ assertChoiceScore(scores.get(2), CHOICE_C, BigDecimal.valueOf(150.));
+ }
+
+ public static void assertChoiceScore(ChoiceScore choiceScore,
+ String choiceId,
+ BigDecimal choiceResult) {
+ Assert.assertNotNull(choiceScore);
+ Assert.assertEquals(choiceId, choiceScore.getChoiceId());
+ Assert.assertEquals(choiceResult, choiceScore.getScoreValue());
+ }
+
+ public static void assertChoiceScoreEquals(BigDecimal choiceResult,
+ Set<ChoiceScore> choiceScores,
+ String... choiceIds) {
+
+ Assert.assertNotNull(choiceScores);
+ Map<String, ChoiceScore> choicesById = Maps.uniqueIndex(
+ choiceScores, new ChoiceIdAble.ChoiceIdAbleById());
+ for (String choiceId : choiceIds) {
+
+ ChoiceScore choiceScore = choicesById.get(choiceId);
+ Assert.assertNotNull(choiceScore);
+ assertChoiceScore(choiceScore, choiceId, choiceResult);
+ }
+ }
+
+}
Property changes on: trunk/pollen-votecounting-percentage/src/test/java/org/chorem/pollen/votecounting/PercentageVoteCountingStrategyTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/pollen-votecounting-percentage/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java (from rev 3707, trunk/pollen-votecounting-strategy-percentage/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java)
===================================================================
--- trunk/pollen-votecounting-percentage/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java (rev 0)
+++ trunk/pollen-votecounting-percentage/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -0,0 +1,44 @@
+/*
+ * #%L
+ * Pollen :: VoteCounting strategy :: Percentage
+ * $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.votecounting;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests the {@link VoteCountingFactory}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5
+ */
+public class VoteCountingFactoryTest {
+
+ @Test
+ public void getVoteCounting() throws Exception {
+
+ VoteCountingFactory factory = new VoteCountingFactory();
+ VoteCounting voteCounting =
+ factory.getVoteCounting(PercentageVoteCounting.ID);
+ Assert.assertNotNull(voteCounting);
+ }
+}
Property changes on: trunk/pollen-votecounting-percentage/src/test/java/org/chorem/pollen/votecounting/VoteCountingFactoryTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/pollen-votecounting-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-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-percentage/src/test/java/org/chorem/pollen/votecounting/strategy/PercentageStrategyTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,273 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting strategy :: Percentage
- * $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.votecounting.strategy;
-
-import com.google.common.collect.Maps;
-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.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import java.math.BigDecimal;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Tests the {@link PercentageStrategy}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class PercentageStrategyTest {
-
- public static final String CHOICE_A = "a";
-
- public static final String CHOICE_B = "b";
-
- public static final String CHOICE_C = "c";
-
- protected static VoteCountingStrategyProvider provider;
-
- protected VoteCountingStrategy strategy;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- provider = new VoteCountingStrategyProvider();
- }
-
- @Before
- public void setUp() throws Exception {
- strategy = provider.getStrategy(PercentageStrategy.ID);
- }
-
- @Test
- public void simpleVotecount() throws Exception {
-
- // Simple poll (all weight to 1)
- // 1 (a=100 b=null c=null)
- // 2 (a=null b=100 c=null)
- // 3 (a=50 b=50 c=null)
- // Result (a=100 b=150 c=null)
-
- Set<Voter> voters = new SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 100.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 100.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, 50.).
- addVoteForChoice(CHOICE_B, 50.).
- addVoteForChoice(CHOICE_C, null).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScoreEquals(BigDecimal.valueOf(150.),
- Sets.newHashSet(scores.get(0),
- scores.get(1)),
- CHOICE_A, CHOICE_B);
-
- assertChoiceScore(scores.get(2), CHOICE_C, null);
- }
-
- @Test
- public void simpleVotecount2() throws Exception {
-
- // Simple poll (all weight to 1)
- // 1 (a=20 b=30 c=50)
- // 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 SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 20.).
- addVoteForChoice(CHOICE_B, 30.).
- addVoteForChoice(CHOICE_C, 50.).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, 50.).
- addVoteForChoice(CHOICE_B, 20.).
- addVoteForChoice(CHOICE_C, 30.).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, 10.).
- addVoteForChoice(CHOICE_B, 50.).
- addVoteForChoice(CHOICE_C, 40.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScore(scores.get(0), CHOICE_C, BigDecimal.valueOf(120.));
- assertChoiceScore(scores.get(1), CHOICE_B, BigDecimal.valueOf(100.));
- assertChoiceScore(scores.get(2), CHOICE_A, BigDecimal.valueOf(80.));
- }
-
- @Test
- public void simpleVotecount3() throws Exception {
-
- // Simple poll (all weight to 1)
- // 1 (a=50 b=50 c=null)
- // 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 SimpleVoterBuilder().
- newVoter("1", 1.).
- addVoteForChoice(CHOICE_A, 50.).
- addVoteForChoice(CHOICE_B, 50.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, 50.).
- addVoteForChoice(CHOICE_B, 50.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, 50.).
- addVoteForChoice(CHOICE_B, 50.).
- addVoteForChoice(CHOICE_C, null).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScoreEquals(BigDecimal.valueOf(150.),
- Sets.newHashSet(scores.get(0),
- scores.get(1)),
- CHOICE_A, CHOICE_B);
- assertChoiceScore(scores.get(2), CHOICE_C, null);
- }
-
- @Test
- public void weightedVotecount1() throws Exception {
-
- // poll with weighted vote
- // 1 (x2) (a=100 b=null c=null)
- // 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 SimpleVoterBuilder().
- newVoter("1", 2.).
- addVoteForChoice(CHOICE_A, 100.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 100.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 50.).
- addVoteForChoice(CHOICE_C, 50.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
- assertChoiceScore(scores.get(0), CHOICE_A, BigDecimal.valueOf(200.));
- assertChoiceScore(scores.get(1), CHOICE_B, BigDecimal.valueOf(150.));
- assertChoiceScore(scores.get(2), CHOICE_C, BigDecimal.valueOf(50.));
- }
-
- @Test
- public void weightedVotecount2() throws Exception {
-
- // poll with weighted vote
- // 1 (x2) (a=100 b=null c=null)
- // 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 SimpleVoterBuilder().
- newVoter("1", 2.).
- addVoteForChoice(CHOICE_A, 100.).
- addVoteForChoice(CHOICE_B, null).
- addVoteForChoice(CHOICE_C, null).
- newVoter("2", 1.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 100.).
- addVoteForChoice(CHOICE_C, null).
- newVoter("3", 3.).
- addVoteForChoice(CHOICE_A, null).
- addVoteForChoice(CHOICE_B, 50.).
- addVoteForChoice(CHOICE_C, 50.).
- getVoters();
-
- VoteCountingResult result = strategy.votecount(voters);
-
- Assert.assertNotNull(result);
- List<ChoiceScore> scores = result.getScores();
- Assert.assertNotNull(scores);
- Assert.assertEquals(3, scores.size());
-
- assertChoiceScore(scores.get(0), CHOICE_B, BigDecimal.valueOf(250.));
- assertChoiceScore(scores.get(1), CHOICE_A, BigDecimal.valueOf(200.));
- assertChoiceScore(scores.get(2), CHOICE_C, BigDecimal.valueOf(150.));
- }
-
- public static void assertChoiceScore(ChoiceScore choiceScore,
- String choiceId,
- BigDecimal choiceResult) {
- Assert.assertNotNull(choiceScore);
- Assert.assertEquals(choiceId, choiceScore.getChoiceId());
- Assert.assertEquals(choiceResult, choiceScore.getScoreValue());
- }
-
- public static void assertChoiceScoreEquals(BigDecimal choiceResult,
- Set<ChoiceScore> choiceScores,
- String... choiceIds) {
-
- Assert.assertNotNull(choiceScores);
- Map<String, ChoiceScore> choicesById = Maps.uniqueIndex(
- choiceScores, new ChoiceIdAble.ChoiceIdAbleById());
- for (String choiceId : choiceIds) {
-
- ChoiceScore choiceScore = choicesById.get(choiceId);
- Assert.assertNotNull(choiceScore);
- assertChoiceScore(choiceScore, choiceId, choiceResult);
- }
- }
-
-}
Deleted: trunk/pollen-votecounting-percentage/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java
===================================================================
--- trunk/pollen-votecounting-strategy-percentage/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pollen-votecounting-percentage/src/test/java/org/chorem/pollen/votecounting/strategy/VoteCountingStrategyProviderTest.java 2012-09-29 12:36:25 UTC (rev 3708)
@@ -1,49 +0,0 @@
-/*
- * #%L
- * Pollen :: VoteCounting strategy :: Percentage
- * $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.votecounting.strategy;
-
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * Tests the {@link VoteCountingStrategyProvider}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5
- */
-public class VoteCountingStrategyProviderTest {
-
- protected static VoteCountingStrategyProvider provider;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- provider = new VoteCountingStrategyProvider();
- }
-
- @Test
- public void getStrategy() throws Exception {
-
- Assert.assertNotNull(provider.getStrategy(PercentageStrategy.ID));
- }
-}
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-09-25 15:32:42 UTC (rev 3707)
+++ trunk/pom.xml 2012-09-29 12:36:25 UTC (rev 3708)
@@ -3,10 +3,6 @@
<modelVersion>4.0.0</modelVersion>
- <!-- ************************************************************* -->
- <!-- *** POM Relationships *************************************** -->
- <!-- ************************************************************* -->
-
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
@@ -19,7 +15,7 @@
<modules>
<module>pollen-votecounting-api</module>
- <module>pollen-votecounting-strategy</module>
+ <module>pollen-votecounting-aggregator</module>
<module>pollen-persistence</module>
<module>pollen-services</module>
<module>pollen-ui-struts2</module>
@@ -163,7 +159,7 @@
<struts2Version>2.3.4</struts2Version>
<jqueryPluginVersion>3.3.1</jqueryPluginVersion>
<shiroVersion>1.2.0</shiroVersion>
- <slf4jVersion>1.6.5</slf4jVersion>
+ <slf4jVersion>1.6.6</slf4jVersion>
<jettyVersion>${jettyPluginVersion}</jettyVersion>
<hibernateVersion>3.6.10.Final</hibernateVersion>
<seleniumVersion>2.25.0</seleniumVersion>
@@ -353,12 +349,6 @@
<version>${slf4jVersion}</version>
<scope>compile</scope>
</dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>${slf4jVersion}</version>
- <scope>runtime</scope>
- </dependency>
<!-- Others -->
@@ -533,10 +523,6 @@
</resources>
</build>
- <!-- ************************************************************* -->
- <!-- *** Build Environment ************************************** -->
- <!-- ************************************************************* -->
-
<scm>
<connection>scm:svn:http://svn.chorem.org/svn/pollen/trunk</connection>
<developerConnection>
1
0
r3707 - in trunk: pollen-persistence/src/main/java/org/chorem/pollen/business/persistence pollen-services/src/main/java/org/chorem/pollen/services/impl pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll pollen-ui-struts2/src/main/resources/i18n pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model
by tchemit@users.chorem.org Sept. 25, 2012
by tchemit@users.chorem.org Sept. 25, 2012
Sept. 25, 2012
Author: tchemit
Date: 2012-09-25 17:32:42 +0200 (Tue, 25 Sep 2012)
New Revision: 3707
Url: http://chorem.org/repositories/revision/pollen/3707
Log:
refs #590: Refactor votecounting module (make group vote counting working again)
Modified:
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/Polls.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollVoteCountingService.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java
trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
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/GroupVoteCountingResult.java
Modified: 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 2012-09-23 19:07:20 UTC (rev 3706)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/Polls.java 2012-09-25 15:32:42 UTC (rev 3707)
@@ -57,8 +57,21 @@
return PollType.FREE == poll.getPollType();
}
- public static GroupOfVoter toSimpleGroupOfVoters(Poll poll) {
+ /**
+ * Collect all vote for all voters of the givne poll.
+ * <p/>
+ * The result (a set of simple voters) are stored in a fictiv group of voter.
+ * <p/>
+ * <strong>Note:</strong> Even if the poll is a group type, then no of his
+ * group are used (just collect simple voters with no group linkage).
+ *
+ * @param poll the poll to scan
+ * @return the aggregate group of voter containing simple voters with
+ * their votes.
+ */
+ public static GroupOfVoter toSimpleVotersGroup(Poll poll) {
Preconditions.checkNotNull(poll);
+
SimpleVoterBuilder builder = new SimpleVoterBuilder();
for (Vote vote : poll.getVote()) {
@@ -69,8 +82,20 @@
return result;
}
+ /**
+ * Build the group of voter of the poll, using his group to build sub
+ * group of the poll.
+ * <p/>
+ * <strong>Note:</strong> This method can only be used for a group poll.
+ *
+ * @param poll the poll to scan
+ * @return the aggregate group of group of voters with their votes
+ */
public static GroupOfVoter toGroupOfVoters(Poll poll) {
Preconditions.checkNotNull(poll);
+ Preconditions.checkArgument(
+ isGroupPoll(poll), "Can only use this method for a group poll");
+
GroupOfVoterBuilder builder = new GroupOfVoterBuilder();
// create group of voter
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-23 19:07:20 UTC (rev 3706)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollVoteCountingService.java 2012-09-25 15:32:42 UTC (rev 3707)
@@ -46,7 +46,8 @@
LogFactory.getLog(PollVoteCountingService.class);
/**
- * Execute a vote counting for a given poll.
+ * Execute a simple vote counting for a given poll (if the poll
+ * is a group poll, none of his group will be used).
*
* @param poll poll on wich vote count
* @return vote counting result
@@ -59,7 +60,7 @@
Preconditions.checkNotNull(strategy);
// create vote counting model
- GroupOfVoter group = Polls.toSimpleGroupOfVoters(poll);
+ GroupOfVoter group = Polls.toSimpleVotersGroup(poll);
// compute result by the strategy
GroupVoteCountingResult result = strategy.votecount(group);
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-23 19:07:20 UTC (rev 3706)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-09-25 15:32:42 UTC (rev 3707)
@@ -36,6 +36,7 @@
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.PollAccount;
import org.chorem.pollen.business.persistence.Polls;
+import org.chorem.pollen.business.persistence.VotingList;
import org.chorem.pollen.services.impl.PollVoteCountingService;
import org.chorem.pollen.ui.PollenUIUtils;
import org.chorem.pollen.ui.actions.PageSkin;
@@ -82,20 +83,29 @@
*/
private Poll poll;
+ /** Poll main votecounting result. */
+ private VoteCountingResult pollResult;
+
+ /** Group result (if poll is group and {]code byGroup} flag is on). */
private GroupVoteCountingResult groupResult;
- private VoteCountingResult pollResult;
-
+ /** choices of the poll indexed by ther id. */
private Map<String, Choice> choicesById;
+ /** group of the poll indexed by ther id. */
+ private Map<String, VotingList> groupsById;
+
/**
* Url helper (to build new url)
*
* @since 1.3.1
*/
@Inject(required = true)
- private UrlHelper urlHelper;
+ private transient UrlHelper urlHelper;
+ /** Flag to votecount by group (only used if a poll is group). */
+ private Boolean byGroup;
+
public ResultForPoll() {
super(PageSkin.RESULT);
}
@@ -112,6 +122,14 @@
return feedFileExisting;
}
+ public Boolean getByGroup() {
+ return byGroup;
+ }
+
+ public void setByGroup(Boolean byGroup) {
+ this.byGroup = byGroup;
+ }
+
public String getVoteCountingTypeName() {
VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll());
String result = strategy.getStrategyName(getLocale());
@@ -178,6 +196,10 @@
return result;
}
+ public Set<String> getGroupIds() {
+ return groupResult.getGroupIds();
+ }
+
public GroupVoteCountingResult getGroupResult() {
return groupResult;
}
@@ -216,6 +238,12 @@
public String execute() throws Exception {
poll = getUserSecurityContext().getPoll();
+ if (byGroup == null) {
+
+ // nothing defined, use default value
+ byGroup = isGroupPoll();
+ }
+
choicesById = Maps.uniqueIndex(poll.getChoice(), TopiaId.GET_TOPIA_ID);
feedFileExisting = getPollFeedService().isFeedExists(poll);
@@ -223,8 +251,14 @@
PollVoteCountingService voteCountingService =
getService(PollVoteCountingService.class);
- if (isGroupPoll()) {
+ if (isGroupPoll() && getByGroup()) {
+ groupsById = Maps.newHashMap();
+
+ for (VotingList votingList : poll.getVotingList()) {
+ groupsById.put(votingList.getTopiaId(), votingList);
+ }
+
// load group result
groupResult = voteCountingService.getGroupResult(poll);
@@ -269,12 +303,23 @@
}
public String getNormalPollResultChartUrl(int width, int height) {
- return getPollResultChartUrl(pollResult, width, height);
+ String title;
+ if (isGroupPoll() && !getByGroup()) {
+
+ // means poll votecount as anot group poll
+ title = _("pollen.common.pollResult.forPollAsNotGroupPoll");
+ } else {
+ title = _("pollen.common.pollResult.forPoll");
+
+ }
+ return getPollResultChartUrl(pollResult, title, width, height);
}
public String getGroupPollResultChartUrl(String groupId, int width, int height) {
VoteCountingResult result = groupResult.getGroupResult(groupId);
- return getPollResultChartUrl(result, width, height);
+ String groupName = getGroupName(groupId);
+ String title = _("pollen.common.pollResult.forGroup", groupName);
+ return getPollResultChartUrl(result, title, width, height);
}
public String getChoiceName(String id) {
@@ -282,7 +327,13 @@
return result;
}
+ public String getGroupName(String id) {
+ String result = groupsById.get(id).getName();
+ return result;
+ }
+
protected String getPollResultChartUrl(VoteCountingResult results,
+ String title,
int width, int height) {
List<String> choiceValues = Lists.newArrayList();
@@ -310,7 +361,7 @@
Map<String, Object> params = Maps.newHashMap();
params.put("width", width);
params.put("height", height);
- params.put("title", "");
+ params.put("title", title);
params.put("values", choiceValues);
urlHelper.buildParametersString(params, url, "&");
Modified: trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
===================================================================
--- trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-09-23 19:07:20 UTC (rev 3706)
+++ trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-09-25 15:32:42 UTC (rev 3707)
@@ -140,6 +140,9 @@
pollen.common.pollOption.reminder=Send reminder emails
pollen.common.pollOption.reminder.help=An email is sent to remind persons who have not yet voted N hours before poll end
pollen.common.pollOption.reminderHourCountdown=Hours before end
+pollen.common.pollResult.forGroup=Poll result for group %s
+pollen.common.pollResult.forPoll=Poll result
+pollen.common.pollResult.forPollAsNotGroupPoll=Poll result (without taking account of groups)
pollen.common.pollType=Who can vote ?
pollen.common.pollType.help=Free\: accessible to everyone <br/><br/> Restricted\: accessible only to a list of persons <br/><br/> Group\: accessible to several lists of persons
pollen.common.pollVoteVisibility=Vote visibility
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-23 19:07:20 UTC (rev 3706)
+++ trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-09-25 15:32:42 UTC (rev 3707)
@@ -141,6 +141,9 @@
pollen.common.pollOption.reminder=Envoyer des emails de rappel
pollen.common.pollOption.reminder.help=Un email de rappel est envoyé aux votants qui n'ont pas encore voté N heures avant la fin du sondage
pollen.common.pollOption.reminderHourCountdown=heures avant la fin du sondage
+pollen.common.pollResult.forGroup=Résultat du sondage pour le groupe %s
+pollen.common.pollResult.forPoll=Résultat du sondage
+pollen.common.pollResult.forPollAsNotGroupPoll=Résultat du sondage (sans tenir compte des groupes)
pollen.common.pollType=Qui peut voter ?
pollen.common.pollType.help=Libre \: accessible à tout le monde <br/><br/> Restreint \: accessible uniquement à une liste de votants <br/><br/> Groupe \: accessible à plusieurs listes de votants
pollen.common.pollVoteVisibility=Visibilité des votes
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-23 19:07:20 UTC (rev 3706)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/result.jsp 2012-09-25 15:32:42 UTC (rev 3707)
@@ -47,11 +47,17 @@
var chartUrls = {};
chartUrls['chart_normal'] = "<s:url value='%{getNormalPollResultChartUrl(400, 300)}' escapeAmp='false'/>";
- <s:if test="numberVoteCounting">
- <s:iterator value="choicesResultNames" var="choicesResultName" status="status">
- chartUrls['chart_<s:property value="#status.index"/>'] = "<s:url value='%{getChoicesResultCharUrl(400,300, #choicesResultName)}' escapeAmp='false'/>";
+ <s:if test="byGroup">
+ //Add all result by group
+ <s:iterator value="groupIds" var="groupId" status="status">
+ chartUrls['chart_Group_<s:property value="#status.index"/>'] = "<s:url value='%{getGroupPollResultChartUrl(#groupId, 400, 300)}' escapeAmp='false'/>";
</s:iterator>
- </s:if>
+ </s:if>
+ <%--<s:if test="numberVoteCounting">--%>
+ <%--<s:iterator value="choicesResultNames" var="choicesResultName" status="status">--%>
+ <%--chartUrls['chart_<s:property value="#status.index"/>'] = "<s:url value='%{getChoicesResultCharUrl(400,300, #choicesResultName)}' escapeAmp='false'/>";--%>
+ <%--</s:iterator>--%>
+ <%--</s:if>--%>
jQuery(document).ready(function () {
@@ -132,28 +138,44 @@
</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'/>
</sj:div>
+ <%-- result by group --%>
+ <s:if test="byGroup">
+ <div id="resultChart">
+ <div>
+ <s:iterator value="groupIds" var="groupId" status="status">
+ <hr/>
+ <s:set name="groupName" value="%{getGroupName(#groupId)}"/>
+ <img id='chart_Group_<s:property value="#status.index"/>'
+ alt="<s:property value='%{#groupName}'/>"
+ title="<s:property value='%{#groupName}'/>"/>
+ </s:iterator>
+ </div>
+ <br/>
+ </div>
+ </s:if>
+
<%-- Diagramme par choix --%>
<%--<s:if test="choicesResults != null">--%>
<%--<div id="resultChart">--%>
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-23 19:07:20 UTC (rev 3706)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/GroupVoteCountingResult.java 2012-09-25 15:32:42 UTC (rev 3707)
@@ -24,6 +24,7 @@
import com.google.common.base.Function;
import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
import java.io.Serializable;
import java.util.Map;
@@ -56,6 +57,15 @@
return voter.getResult();
}
+ public Set<String> getGroupIds() {
+ return Sets.newHashSet(groups.keySet());
+ }
+ public VoteCountingResult getGroupResult(String groupId) {
+ GroupOfVoter groupOfVoter = groups.get(groupId);
+ VoteCountingResult result = groupOfVoter.getResult();
+ return result;
+ }
+
public void setVoter(GroupOfVoter voter) {
this.voter = voter;
}
@@ -68,10 +78,4 @@
}
});
}
-
- public VoteCountingResult getGroupResult(String groupId) {
- GroupOfVoter groupOfVoter = groups.get(groupId);
- VoteCountingResult result = groupOfVoter.getResult();
- return result;
- }
}
1
0
r3706 - trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model
by tchemit@users.chorem.org Sept. 23, 2012
by tchemit@users.chorem.org Sept. 23, 2012
Sept. 23, 2012
Author: tchemit
Date: 2012-09-23 21:07:20 +0200 (Sun, 23 Sep 2012)
New Revision: 3706
Url: http://chorem.org/repositories/revision/pollen/3706
Log:
fix group voter choices
Modified:
trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/GroupOfVoter.java
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-23 14:37:50 UTC (rev 3705)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/GroupOfVoter.java 2012-09-23 19:07:20 UTC (rev 3706)
@@ -106,11 +106,13 @@
public void setResult(VoteCountingResult result) {
this.result = result;
+ Set<ChoiceScore> winners = result.getTopRanking();
for (ChoiceScore choiceScore : result.getScores()) {
+
+ double score = winners.contains(choiceScore) ? 1d : 0d;
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());
+ score);
addVoteForChoice(voteForChoice);
}
}
1
0
r3705 - in trunk/pollen-services/src/main/java/org/chorem/pollen: entities/migration services/impl
by tchemit@users.chorem.org Sept. 23, 2012
by tchemit@users.chorem.org Sept. 23, 2012
Sept. 23, 2012
Author: tchemit
Date: 2012-09-23 16:37:50 +0200 (Sun, 23 Sep 2012)
New Revision: 3705
Url: http://chorem.org/repositories/revision/pollen/3705
Log:
fixes #814: There is some pollAccount with no accountId
Modified:
trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_5.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_5.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_5.java 2012-09-23 14:37:19 UTC (rev 3704)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_5.java 2012-09-23 14:37:50 UTC (rev 3705)
@@ -94,6 +94,10 @@
// clean pollAccount for votes
// see http://chorem.org/issues/804
removeDuplicateVoteWithSameUserAccount(tx, sContext, queries);
+
+ // generate missing accountId
+ // see http://chorem.org/issues/814
+ generateMissingAccountId(tx, sContext, queries);
}
private void removeDuplicateVoteWithSameUserAccount(TopiaContextImplementor tx,
@@ -207,6 +211,36 @@
}
+ private void generateMissingAccountId(TopiaContextImplementor tx,
+ PollenServiceContext sContext,
+ List<String> queries) throws TopiaException {
+ // get all pollAccount with no accountId
+ TopiaSQLQuery<String> sqlQuery = new TopiaSQLQuery<String>() {
+
+ @Override
+ protected PreparedStatement prepareQuery(Connection connection) throws SQLException {
+ PreparedStatement ps = connection.prepareStatement(
+ "SELECT p.topiaId FROM pollAccount p, vote v WHERE " +
+ "p.accountId = '' AND v.pollaccount = p.topiaid");
+ return ps;
+ }
+
+ @Override
+ protected String prepareResult(ResultSet set) throws SQLException {
+ String pollAccountId = set.getString(1);
+ return pollAccountId;
+ }
+ };
+
+ List<String> accountIds = sqlQuery.findMultipleResult(tx);
+
+ String request =
+ "UPDATE pollaccount set accountId = '%s' WHERE topiaid='%s';";
+ for (String id : accountIds) {
+ queries.add(String.format(request, sContext.generateId(), id));
+ }
+ }
+
final Function<Vote, UserAccount> voteToUserAccount = new Function<Vote, UserAccount>() {
@Override
public UserAccount apply(Vote input) {
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-23 14:37:19 UTC (rev 3704)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-09-23 14:37:50 UTC (rev 3705)
@@ -25,6 +25,7 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.PollenTechnicalException;
@@ -61,11 +62,12 @@
VoteDAO dao = getDAO(Vote.class);
Vote voteLoaded = null;
- if (accountEditable.getAccountId() != null) {
+ if (StringUtils.isNotBlank(accountEditable.getAccountId())) {
// if pollAccount has no accoutId, so not yet voted, no need to
// seek for something is db.
try {
- voteLoaded = dao.findByAccountId(accountEditable.getAccountId());
+ voteLoaded = dao.findByPollAndAccountId(
+ poll, accountEditable.getAccountId());
} catch (TopiaException e) {
throw new PollenTechnicalException(e);
}
@@ -153,7 +155,7 @@
// Create new account
PollAccountDAO pollAccountDAO = getDAO(PollAccount.class);
pollAccountLoaded = createWithProperties(
- pollAccountDAO, PollAccount.PROPERTY_ACCOUNT_ID, generateId());
+ pollAccountDAO, PollAccount.PROPERTY_ACCOUNT_ID, serviceContext.generateId());
} else {
// Load existing account (restricted poll)
1
0
r3704 - in trunk/pollen-persistence/src: main/java/org/chorem/pollen/business/persistence test/java/org/chorem/pollen/business/persistence
by tchemit@users.chorem.org Sept. 23, 2012
by tchemit@users.chorem.org Sept. 23, 2012
Sept. 23, 2012
Author: tchemit
Date: 2012-09-23 16:37:19 +0200 (Sun, 23 Sep 2012)
New Revision: 3704
Url: http://chorem.org/repositories/revision/pollen/3704
Log:
make sure we use talso the poll to get the pollAccount
Modified:
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java
trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/VoteDAOImplTest.java
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java 2012-09-23 14:36:50 UTC (rev 3703)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java 2012-09-23 14:37:19 UTC (rev 3704)
@@ -65,22 +65,25 @@
return result;
}
- public Vote findVoteByPollAndVotingId(Poll poll, String votingId) throws TopiaException {
+ public E findVoteByPollAndVotingId(Poll poll, String votingId) throws TopiaException {
String hql = "SELECT e FROM VoteImpl e, PollImpl p WHERE " +
"p = :p AND " +
"e in elements(p.vote) AND " +
"e.pollAccount.votingId = :v";
- Vote result = findByQuery(Vote.class, hql, "p", poll, "v", votingId);
+ E result = findByQuery(hql, "p", poll, "v", votingId);
return result;
}
- public E findByAccountId(String accountId) throws TopiaException {
+ public E findByPollAndAccountId(Poll poll, String accountId) throws TopiaException {
- String hql = "FROM VoteImpl e WHERE e.pollAccount.accountId = :a";
+ String hql = "SELECT e FROM VoteImpl e, PollImpl p WHERE " +
+ "p = :p AND " +
+ "e in elements(p.vote) AND " +
+ "e.pollAccount.accountId = :a";
- E result = findByQuery(hql, "a", accountId);
+ E result = findByQuery(hql,"p", poll, "a", accountId);
return result;
}
}
Modified: trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/VoteDAOImplTest.java
===================================================================
--- trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/VoteDAOImplTest.java 2012-09-23 14:36:50 UTC (rev 3703)
+++ trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/VoteDAOImplTest.java 2012-09-23 14:37:19 UTC (rev 3704)
@@ -170,13 +170,20 @@
}
@Test
- public void findByAccountId() throws Exception {
+ public void findByPollAndAccountId() throws Exception {
TopiaContext tx = beginTransaction();
+ PollDAO pollDAO = PollenDAOHelper.getPollDAO(tx);
+ PollAccountDAO pollAccountDAO = PollenDAOHelper.getPollAccountDAO(tx);
VoteDAO voteDAO = PollenDAOHelper.getVoteDAO(tx);
- PollAccountDAO pollAccountDAO = PollenDAOHelper.getPollAccountDAO(tx);
+
+ Poll poll1 = pollDAO.create(Poll.PROPERTY_POLL_ID, "pollId1");
+ Poll poll2 = pollDAO.create(Poll.PROPERTY_POLL_ID, "pollId2",
+ Poll.PROPERTY_POLL_VOTE_VISIBILITY,
+ PollVoteVisibility.NOBODY);
+
String accountId1 = "accountId1";
PollAccount pollAccount1 = pollAccountDAO.create(PollAccount.PROPERTY_ACCOUNT_ID, accountId1);
String accountId2 = "accountId2";
@@ -185,28 +192,29 @@
tx.commitTransaction();
Vote actual;
- actual = voteDAO.findByAccountId(accountId1);
+ actual = voteDAO.findByPollAndAccountId(poll1, accountId1);
Assert.assertNull(actual);
- actual = voteDAO.findByAccountId(accountId2);
+ actual = voteDAO.findByPollAndAccountId(poll1, accountId2);
Assert.assertNull(actual);
// attach accountId1 to vote1
Vote vote1 = voteDAO.create(Vote.PROPERTY_POLL_ACCOUNT, pollAccount1);
-
+ poll1.addVote(vote1);
tx.commitTransaction();
- actual = voteDAO.findByAccountId(accountId1);
+ actual = voteDAO.findByPollAndAccountId(poll1, accountId1);
Assert.assertNotNull(actual);
Assert.assertEquals(vote1, actual);
- actual = voteDAO.findByAccountId(accountId2);
+ actual = voteDAO.findByPollAndAccountId(poll1, accountId2);
Assert.assertNull(actual);
// attach accountId2 to vote2
Vote vote2 = voteDAO.create(Vote.PROPERTY_POLL_ACCOUNT, pollAccount2);
+ poll2.addVote(vote2);
tx.commitTransaction();
- actual = voteDAO.findByAccountId(accountId2);
+ actual = voteDAO.findByPollAndAccountId(poll2, accountId2);
Assert.assertNotNull(actual);
Assert.assertEquals(vote2, actual);
}
1
0
r3703 - in trunk/pollen-services/src: main/java/org/chorem/pollen/services main/java/org/chorem/pollen/services/impl test/java/org/chorem/pollen/services
by tchemit@users.chorem.org Sept. 23, 2012
by tchemit@users.chorem.org Sept. 23, 2012
Sept. 23, 2012
Author: tchemit
Date: 2012-09-23 16:36:50 +0200 (Sun, 23 Sep 2012)
New Revision: 3703
Url: http://chorem.org/repositories/revision/pollen/3703
Log:
service context is reponsible of generating id (to mock it in test later)
Modified:
trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
trunk/pollen-services/src/test/java/org/chorem/pollen/services/FakeServiceContext.java
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2012-09-23 13:48:42 UTC (rev 3702)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2012-09-23 14:36:50 UTC (rev 3703)
@@ -30,6 +30,7 @@
import java.net.URL;
import java.util.Date;
import java.util.Locale;
+import java.util.UUID;
/**
* Instances of this class will be given to service factory.
@@ -137,4 +138,9 @@
public VoteCountingStrategyProvider getVoteCountingStrategyProvider() {
return voteCountingStrategyProvider;
}
+
+ @Override
+ public String generateId() {
+ return UUID.randomUUID().toString().replaceAll("-", "");
+ }
}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java 2012-09-23 13:48:42 UTC (rev 3702)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java 2012-09-23 14:36:50 UTC (rev 3703)
@@ -24,6 +24,8 @@
package org.chorem.pollen.services;
import org.chorem.pollen.PollenConfiguration;
+import org.chorem.pollen.business.persistence.Poll;
+import org.chorem.pollen.business.persistence.PollAccount;
import org.chorem.pollen.votecounting.strategy.VoteCountingStrategyProvider;
import org.nuiton.topia.TopiaContext;
@@ -62,4 +64,13 @@
VoteCountingStrategyProvider getVoteCountingStrategyProvider();
+ /**
+ * Generates a unique id usable for {@link Poll#getPollId()} or
+ * {@link PollAccount#getAccountId()}.
+ *
+ * @return a fresh generated id
+ * @since 1.5
+ */
+ String generateId();
+
}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java 2012-09-23 13:48:42 UTC (rev 3702)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java 2012-09-23 14:36:50 UTC (rev 3703)
@@ -26,8 +26,6 @@
import org.apache.commons.lang3.StringUtils;
import org.chorem.pollen.PollenConfiguration;
import org.chorem.pollen.PollenTechnicalException;
-import org.chorem.pollen.business.persistence.Poll;
-import org.chorem.pollen.business.persistence.PollAccount;
import org.chorem.pollen.entities.PollenDAOHelper;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
@@ -39,7 +37,6 @@
import java.util.Date;
import java.util.List;
import java.util.Locale;
-import java.util.UUID;
import static org.nuiton.i18n.I18n.l_;
@@ -154,6 +151,7 @@
throw new PollenTechnicalException("Could not create entity ", e);
}
}
+
protected <T extends TopiaEntity, D extends TopiaDAO<? super T>> T createWithProperties(D dao, Object... properties) {
try {
return (T) dao.create(properties);
@@ -195,15 +193,4 @@
tx.getHibernate().flush();
}
- /**
- * Generates a unique id usable for {@link Poll#getPollId()} or
- * {@link PollAccount#getAccountId()}.
- *
- * @return a fresh generated id
- * @since 1.4
- */
- protected String generateId() {
- return UUID.randomUUID().toString().replaceAll("-", "");
- }
-
}
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-23 13:48:42 UTC (rev 3702)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-09-23 14:36:50 UTC (rev 3703)
@@ -283,7 +283,7 @@
PollDAO pollDAO = getDAO(Poll.class);
Poll result = createWithProperties(
pollDAO,
- Poll.PROPERTY_POLL_ID, generateId(),
+ Poll.PROPERTY_POLL_ID, serviceContext.generateId(),
Poll.PROPERTY_POLL_VOTE_VISIBILITY, poll.getPollVoteVisibility(),
Poll.PROPERTY_POLL_COMMENT_VISIBILITY, poll.getPollCommentVisibility());
@@ -315,7 +315,7 @@
PollAccountDAO pollAccountDAO = getDAO(PollAccount.class);
PollAccount creatorCreated = createWithProperties(
pollAccountDAO,
- PollAccount.PROPERTY_ACCOUNT_ID, generateId());
+ PollAccount.PROPERTY_ACCOUNT_ID, serviceContext.generateId());
PollAccount creator = poll.getCreator();
creatorCreated.setVotingId(creator.getVotingId());
creatorCreated.setEmail(creator.getEmail());
@@ -937,7 +937,7 @@
// creates a new pollAccount
pollAccountLoaded = createWithProperties(
pollAccountDAO,
- PollAccount.PROPERTY_ACCOUNT_ID, generateId());
+ PollAccount.PROPERTY_ACCOUNT_ID, serviceContext.generateId());
if (log.isInfoEnabled()) {
log.info(String.format(
Modified: trunk/pollen-services/src/test/java/org/chorem/pollen/services/FakeServiceContext.java
===================================================================
--- trunk/pollen-services/src/test/java/org/chorem/pollen/services/FakeServiceContext.java 2012-09-23 13:48:42 UTC (rev 3702)
+++ trunk/pollen-services/src/test/java/org/chorem/pollen/services/FakeServiceContext.java 2012-09-23 14:36:50 UTC (rev 3703)
@@ -41,6 +41,7 @@
import java.util.Date;
import java.util.Locale;
import java.util.Properties;
+import java.util.UUID;
/**
* Provide an implementation of {@link PollenServiceContext} suitable for repeatable,
@@ -133,6 +134,11 @@
return null;
}
+ @Override
+ public String generateId() {
+ return UUID.randomUUID().toString().replaceAll("-", "");
+ }
+
public void setCurrentTime(Date fakeCurrentTime) {
this.fakeCurrentTime = fakeCurrentTime;
}
1
0
r3702 - in trunk/pollen-ui-struts2/src/main: java/org/chorem/pollen/ui/actions/json resources resources/config webapp/WEB-INF/jsp/admin webapp/WEB-INF/jsp/user webapp/js
by tchemit@users.chorem.org Sept. 23, 2012
by tchemit@users.chorem.org Sept. 23, 2012
Sept. 23, 2012
Author: tchemit
Date: 2012-09-23 15:48:42 +0200 (Sun, 23 Sep 2012)
New Revision: 3702
Url: http://chorem.org/repositories/revision/pollen/3702
Log:
normalize json actions (all will use a data field
Added:
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONSimpleAction.java
Modified:
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONPaginedAction.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetCreatedPolls.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteList.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccount.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccounts.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteLists.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetInvitedPolls.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetParticipatedPolls.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPolls.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUser.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUsers.java
trunk/pollen-ui-struts2/src/main/resources/config/struts-json.xml
trunk/pollen-ui-struts2/src/main/resources/struts.xml
trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/pollsList.jsp
trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/usersList.jsp
trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/createdList.jsp
trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteList.jsp
trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteLists.jsp
trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/invitedList.jsp
trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/participatedList.jsp
trunk/pollen-ui-struts2/src/main/webapp/js/favoriteList.js
trunk/pollen-ui-struts2/src/main/webapp/js/usersList.js
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONPaginedAction.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONPaginedAction.java 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONPaginedAction.java 2012-09-23 13:48:42 UTC (rev 3702)
@@ -28,6 +28,8 @@
import org.chorem.pollen.ui.actions.PollenActionSupport;
import org.nuiton.topia.persistence.pager.TopiaPagerBean;
+import java.util.Map;
+
/**
* Abstract JSON action with pagination support.
*
@@ -38,6 +40,8 @@
private static final long serialVersionUID = 1L;
+ public abstract Map<String, Object>[] getData();
+
public final Integer getRows() {
return pager.getPageSize();
}
Added: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONSimpleAction.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONSimpleAction.java (rev 0)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONSimpleAction.java 2012-09-23 13:48:42 UTC (rev 3702)
@@ -0,0 +1,18 @@
+package org.chorem.pollen.ui.actions.json;
+
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+
+import java.util.Map;
+
+/**
+ * Abstract JSON action for a simple result (one row).
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.5
+ */
+public abstract class AbstractJSONSimpleAction extends PollenActionSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ public abstract Map<String, Object> getData();
+}
Property changes on: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONSimpleAction.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetCreatedPolls.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetCreatedPolls.java 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetCreatedPolls.java 2012-09-23 13:48:42 UTC (rev 3702)
@@ -44,10 +44,11 @@
private static final long serialVersionUID = 1L;
- protected transient Map<String, Object>[] polls;
+ protected transient Map<String, Object>[] data;
- public Map<String, Object>[] getPolls() {
- return polls;
+ @Override
+ public Map<String, Object>[] getData() {
+ return data;
}
@Override
@@ -59,7 +60,7 @@
pager,
getPollenUserAccount());
- polls = new Map[pollList.size()];
+ data = new Map[pollList.size()];
Binder<Poll, Poll> binder =
PollenBinderHelper.getSimpleTopiaBinder(Poll.class);
int index = 0;
@@ -72,7 +73,7 @@
map.put("resultId", poll.getPollId());
map.put("adminId", poll.getAdminId());
map.put("functions", getPollFunctions(poll));
- polls[index++] = map;
+ data[index++] = map;
}
return SUCCESS;
}
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteList.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteList.java 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteList.java 2012-09-23 13:48:42 UTC (rev 3702)
@@ -24,7 +24,6 @@
import com.google.common.collect.Maps;
import org.chorem.pollen.business.persistence.PersonList;
-import org.chorem.pollen.ui.actions.PollenActionSupport;
import java.util.Map;
@@ -34,13 +33,13 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 1.3
*/
-public class GetFavoriteList extends PollenActionSupport {
+public class GetFavoriteList extends AbstractJSONSimpleAction {
private static final long serialVersionUID = 1L;
private String favoriteListId;
- private transient Map<String, Object> favoriteList;
+ private transient Map<String, Object> data;
public String getFavoriteListId() {
return favoriteListId;
@@ -50,8 +49,9 @@
this.favoriteListId = favoriteListId;
}
- public Map<String, Object> getFavoriteList() {
- return favoriteList;
+ @Override
+ public Map<String, Object> getData() {
+ return data;
}
@Override
@@ -60,9 +60,9 @@
PersonList personList =
getFavoriteService().getEntityById(PersonList.class, favoriteListId);
- favoriteList = Maps.newHashMap();
- favoriteList.put("id", personList.getTopiaId());
- favoriteList.put(PersonList.PROPERTY_NAME, personList.getName());
+ data = Maps.newHashMap();
+ data.put("id", personList.getTopiaId());
+ data.put(PersonList.PROPERTY_NAME, personList.getName());
return SUCCESS;
}
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccount.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccount.java 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccount.java 2012-09-23 13:48:42 UTC (rev 3702)
@@ -24,7 +24,6 @@
import org.chorem.pollen.business.persistence.PollAccount;
import org.chorem.pollen.entities.PollenBinderHelper;
-import org.chorem.pollen.ui.actions.PollenActionSupport;
import org.nuiton.util.beans.Binder;
import java.util.Map;
@@ -35,13 +34,13 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 1.3
*/
-public class GetFavoriteListPollAccount extends PollenActionSupport {
+public class GetFavoriteListPollAccount extends AbstractJSONSimpleAction {
private static final long serialVersionUID = 1L;
private String pollAccountId;
- private transient Map<String, Object> pollAccount;
+ private transient Map<String, Object> data;
public String getPollAccountId() {
return pollAccountId;
@@ -51,8 +50,9 @@
this.pollAccountId = pollAccountId;
}
- public Map<String, Object> getPollAccount() {
- return pollAccount;
+ @Override
+ public Map<String, Object> getData() {
+ return data;
}
@Override
@@ -63,12 +63,12 @@
Binder<PollAccount, PollAccount> binder =
PollenBinderHelper.getSimpleTopiaBinder(PollAccount.class);
- pollAccount = binder.obtainProperties(
+ data = binder.obtainProperties(
userAccount,
PollAccount.PROPERTY_VOTING_ID,
PollAccount.PROPERTY_EMAIL
);
- pollAccount.put("id", userAccount.getTopiaId());
+ data.put("id", userAccount.getTopiaId());
return SUCCESS;
}
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccounts.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccounts.java 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccounts.java 2012-09-23 13:48:42 UTC (rev 3702)
@@ -41,12 +41,13 @@
private static final long serialVersionUID = 1L;
- protected transient Map<String, Object>[] pollAccounts;
+ protected transient Map<String, Object>[] data;
protected String favoriteListId;
- public Map<String, Object>[] getPollAccounts() {
- return pollAccounts;
+ @Override
+ public Map<String, Object>[] getData() {
+ return data;
}
public String getFavoriteListId() {
@@ -69,7 +70,7 @@
favoriteList,
pager);
- pollAccounts = new Map[allPollAccounts.size()];
+ data = new Map[allPollAccounts.size()];
Binder<PollAccount, PollAccount> binder =
PollenBinderHelper.getSimpleTopiaBinder(PollAccount.class);
int index = 0;
@@ -80,7 +81,7 @@
PollAccount.PROPERTY_EMAIL
);
map.put("id", pollAccount.getTopiaId());
- pollAccounts[index++] = map;
+ data[index++] = map;
}
return SUCCESS;
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteLists.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteLists.java 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteLists.java 2012-09-23 13:48:42 UTC (rev 3702)
@@ -38,10 +38,11 @@
private static final long serialVersionUID = 1L;
- protected transient Map<String, Object>[] favoriteLists;
+ protected transient Map<String, Object>[] data;
- public Map<String, Object>[] getFavoriteLists() {
- return favoriteLists;
+ @Override
+ public Map<String, Object>[] getData() {
+ return data;
}
@Override
@@ -51,14 +52,14 @@
getPollenUserAccount(),
pager);
- favoriteLists = new Map[allFavoriteLists.size()];
+ data = new Map[allFavoriteLists.size()];
int index = 0;
for (PersonList favoriteList : allFavoriteLists) {
Map<String, Object> map = Maps.newHashMap();
map.put(PersonList.PROPERTY_NAME, favoriteList.getName());
map.put("id", favoriteList.getTopiaId());
map.put("nbAccounts", favoriteList.sizePollAccount());
- favoriteLists[index++] = map;
+ data[index++] = map;
}
return SUCCESS;
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetInvitedPolls.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetInvitedPolls.java 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetInvitedPolls.java 2012-09-23 13:48:42 UTC (rev 3702)
@@ -47,10 +47,11 @@
private static final long serialVersionUID = 1L;
- protected transient Map<String, Object>[] polls;
+ protected transient Map<String, Object>[] data;
- public Map<String, Object>[] getPolls() {
- return polls;
+ @Override
+ public Map<String, Object>[] getData() {
+ return data;
}
@Override
@@ -61,7 +62,7 @@
List<Pair<Poll, PollAccount>> invitedPolls =
pollService.getInvitedPolls(pager, getPollenUserAccount());
- polls = new Map[invitedPolls.size()];
+ data = new Map[invitedPolls.size()];
Binder<Poll, Poll> binder =
PollenBinderHelper.getSimpleTopiaBinder(Poll.class);
int index = 0;
@@ -81,7 +82,7 @@
Set<String> functions = getPollFunctions(poll, pollUri);
map.put("functions", functions);
- polls[index++] = map;
+ data[index++] = map;
}
return SUCCESS;
}
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetParticipatedPolls.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetParticipatedPolls.java 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetParticipatedPolls.java 2012-09-23 13:48:42 UTC (rev 3702)
@@ -47,10 +47,11 @@
private static final long serialVersionUID = 1L;
- protected transient Map<String, Object>[] polls;
+ protected transient Map<String, Object>[] data;
- public Map<String, Object>[] getPolls() {
- return polls;
+ @Override
+ public Map<String, Object>[] getData() {
+ return data;
}
@Override
@@ -61,7 +62,7 @@
List<Pair<Poll, PollAccount>> participatedPolls =
pollService.getParticipatedPolls(pager, getPollenUserAccount());
- polls = new Map[participatedPolls.size()];
+ data = new Map[participatedPolls.size()];
Binder<Poll, Poll> binder =
PollenBinderHelper.getSimpleTopiaBinder(Poll.class);
int index = 0;
@@ -87,7 +88,7 @@
Set<String> functions = getPollFunctions(poll, pollUri);
map.put("functions", functions);
- polls[index++] = map;
+ data[index++] = map;
}
return SUCCESS;
}
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java 2012-09-23 13:48:42 UTC (rev 3702)
@@ -44,7 +44,7 @@
private static final long serialVersionUID = 1L;
- protected transient Map<String, Object>[] comments;
+ protected transient Map<String, Object>[] data;
protected String pollId;
@@ -52,8 +52,9 @@
this.pollId = pollId;
}
- public Map<String, Object>[] getComments() {
- return comments;
+ @Override
+ public Map<String, Object>[] getData() {
+ return data;
}
@Override
@@ -71,7 +72,7 @@
getPollenUserAccount(), pollId, null, poll);
securityContext.loadUserRoles(getSecurityService());
- comments = new Map[commentList.size()];
+ data = new Map[commentList.size()];
Binder<Comment, Comment> binder =
PollenBinderHelper.getSimpleTopiaBinder(Comment.class);
int index = 0;
@@ -88,7 +89,7 @@
comment,
securityContext);
map.put("functions", functions);
- comments[index++] = map;
+ data[index++] = map;
}
return SUCCESS;
}
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPolls.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPolls.java 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPolls.java 2012-09-23 13:48:42 UTC (rev 3702)
@@ -41,10 +41,11 @@
private static final long serialVersionUID = 1L;
- protected transient Map<String, Object>[] polls;
+ protected transient Map<String, Object>[] data;
- public Map<String, Object>[] getPolls() {
- return polls;
+ @Override
+ public Map<String, Object>[] getData() {
+ return data;
}
@Override
@@ -54,7 +55,7 @@
List<Poll> pollList = pollService.getPolls(pager);
- polls = new Map[pollList.size()];
+ data = new Map[pollList.size()];
Binder<Poll, Poll> binder =
PollenBinderHelper.getSimpleTopiaBinder(Poll.class);
int index = 0;
@@ -64,7 +65,7 @@
map.put("adminId", poll.getAdminId());
map.put("functions", Sets.newHashSet("summary"));
- polls[index++] = map;
+ data[index++] = map;
}
return SUCCESS;
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUser.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUser.java 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUser.java 2012-09-23 13:48:42 UTC (rev 3702)
@@ -24,7 +24,6 @@
import org.chorem.pollen.business.persistence.UserAccount;
import org.chorem.pollen.entities.PollenBinderHelper;
-import org.chorem.pollen.ui.actions.PollenActionSupport;
import org.nuiton.util.beans.Binder;
import java.util.Map;
@@ -35,13 +34,13 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 1.3
*/
-public class GetUser extends PollenActionSupport {
+public class GetUser extends AbstractJSONSimpleAction {
private static final long serialVersionUID = 1L;
private String userId;
- private transient Map<String, Object> user;
+ private transient Map<String, Object> data;
public String getUserId() {
return userId;
@@ -51,8 +50,9 @@
this.userId = userId;
}
- public Map<String, Object> getUser() {
- return user;
+ @Override
+ public Map<String, Object> getData() {
+ return data;
}
@Override
@@ -63,10 +63,8 @@
Binder<UserAccount, UserAccount> binder =
PollenBinderHelper.getSimpleTopiaBinder(UserAccount.class);
- user = binder.obtainProperties(
- userAccount
- );
- user.put("id", userAccount.getTopiaId());
+ data = binder.obtainProperties(userAccount);
+ data.put("id", userAccount.getTopiaId());
return SUCCESS;
}
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUsers.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUsers.java 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUsers.java 2012-09-23 13:48:42 UTC (rev 3702)
@@ -41,10 +41,11 @@
private static final long serialVersionUID = 1L;
- protected transient Map<String, Object>[] users;
+ protected transient Map<String, Object>[] data;
- public Map<String, Object>[] getUsers() {
- return users;
+ @Override
+ public Map<String, Object>[] getData() {
+ return data;
}
@Override
@@ -53,7 +54,7 @@
List<UserAccount> allUsers = getUserService().getUsers(pager);
UserAccount userAccount = getPollenUserAccount();
- users = new Map[allUsers.size()];
+ data = new Map[allUsers.size()];
Binder<UserAccount, UserAccount> binder =
PollenBinderHelper.getSimpleTopiaBinder(UserAccount.class);
int index = 0;
@@ -65,7 +66,7 @@
Set<String> functions = getUserFunctions(userAccount, user);
map.put("functions", functions);
- users[index++] = map;
+ data[index++] = map;
}
return SUCCESS;
Modified: trunk/pollen-ui-struts2/src/main/resources/config/struts-json.xml
===================================================================
--- trunk/pollen-ui-struts2/src/main/resources/config/struts-json.xml 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/resources/config/struts-json.xml 2012-09-23 13:48:42 UTC (rev 3702)
@@ -28,7 +28,8 @@
<package name="json" extends="default" namespace="/json">
- <action name="get*" class="org.chorem.pollen.ui.actions.json.Get{1}">
+ <action name="get*" class="org.chorem.pollen.ui.actions.json.Get{1}"
+ method="execute">
<interceptor-ref name="pollenBasicStack"/>
<result type="json"/>
</action>
Modified: trunk/pollen-ui-struts2/src/main/resources/struts.xml
===================================================================
--- trunk/pollen-ui-struts2/src/main/resources/struts.xml 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/resources/struts.xml 2012-09-23 13:48:42 UTC (rev 3702)
@@ -44,13 +44,13 @@
<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.devMode" value="false"/>
- <bean class="org.chorem.pollen.services.PollenServiceFactory" />
+ <bean class="org.chorem.pollen.services.PollenServiceFactory"/>
<!--Performance tuning-->
<!--see http://struts.apache.org/2.2.3/docs/performance-tuning.html-->
<constant name="struts.freemarker.templatesCache" value="true"/>
- <package name="default" extends="json-default" namespace="/">
+ <package name="default" extends="struts-default" namespace="/">
<result-types>
<result-type name="redirectToHome"
@@ -67,6 +67,14 @@
<param name="location">${redirectUrl}</param>
<param name="prependServletContext">false</param>
</result-type>
+
+ <result-type name="json" class="org.apache.struts2.json.JSONResult">
+ <param name="includeProperties">
+ rows,page,total,records,data,data.*,sord,sidx,filters,searchField,searchString,searchOper
+ </param>
+ <param name="ignoreHierarchy">false</param>
+ <!--<param name="defaultEncoding">UTF-8</param>-->
+ </result-type>
</result-types>
<interceptors>
@@ -92,7 +100,9 @@
<interceptor-ref name="multiselect"/>
<interceptor-ref name="actionMappingParams"/>
<interceptor-ref name="params">
- <param name="excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*</param>
+ <param name="excludeParams">
+ dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*
+ </param>
</interceptor-ref>
<interceptor-ref name="conversionError"/>
</interceptor-stack>
Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/pollsList.jsp
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/pollsList.jsp 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/pollsList.jsp 2012-09-23 13:48:42 UTC (rev 3702)
@@ -36,7 +36,7 @@
<s:url id="loadUrl" action="getPolls" namespace="/json" escapeAmp="false"/>
-<sjg:grid id="polls" dataType="json" href="%{loadUrl}" gridModel="polls"
+<sjg:grid id="polls" dataType="json" href="%{loadUrl}" gridModel="data"
sortable="true" pager="true" pagerButtons="true" pagerInput="true"
navigator="true" rownumbers="false" autowidth="true"
onSelectRowTopics='users-rowSelect' editurl="%{loadUrl}"
Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/usersList.jsp
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/usersList.jsp 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/admin/usersList.jsp 2012-09-23 13:48:42 UTC (rev 3702)
@@ -56,7 +56,7 @@
});
</script>
-<sjg:grid id="users" dataType="json" href="%{loadUsers}" gridModel="users"
+<sjg:grid id="users" dataType="json" href="%{loadUsers}" gridModel="data"
sortable="true" pager="true" pagerButtons="true" pagerInput="true"
navigator="true" rownumbers="false" autowidth="true"
onSelectRowTopics='users-rowSelect' editinline="false"
Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/createdList.jsp
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/createdList.jsp 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/createdList.jsp 2012-09-23 13:48:42 UTC (rev 3702)
@@ -55,7 +55,7 @@
<s:url id="loadUrl" action="getCreatedPolls" namespace="/json"
escapeAmp="false"/>
-<sjg:grid id="polls" dataType="json" href="%{loadUrl}" gridModel="polls"
+<sjg:grid id="polls" dataType="json" href="%{loadUrl}" gridModel="data"
sortable="true" pager="true" pagerButtons="true" pagerInput="true"
navigator="true" rownumbers="false" autowidth="true"
onSelectRowTopics='users-rowSelect' editurl="%{loadUrl}"
Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteList.jsp
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteList.jsp 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteList.jsp 2012-09-23 13:48:42 UTC (rev 3702)
@@ -71,7 +71,7 @@
</h1>
<sjg:grid id="pollAccounts" dataType="json" href="%{loadPollAccounts}"
- gridModel="pollAccounts" sortable="true" pager="true"
+ gridModel="data" sortable="true" pager="true"
pagerButtons="true" pagerInput="true"
navigator="true" rownumbers="false" autowidth="true"
onSelectRowTopics='pollAccounts-rowSelect' editinline="false"
Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteLists.jsp
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteLists.jsp 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/favoriteLists.jsp 2012-09-23 13:48:42 UTC (rev 3702)
@@ -69,7 +69,7 @@
</div>
</s:set>
<sjg:grid id="favoriteLists" dataType="json" href='%{loadFavoriteLists}'
- gridModel="favoriteLists" sortable="true" pager="true"
+ gridModel="data" sortable="true" pager="true"
pagerButtons="true" pagerInput="true" navigator="true"
rownumbers="false" autowidth="true" viewrecords="true"
onSelectRowTopics='favoriteLists-rowSelect'
Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/invitedList.jsp
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/invitedList.jsp 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/invitedList.jsp 2012-09-23 13:48:42 UTC (rev 3702)
@@ -39,7 +39,7 @@
<s:url id="loadInvitedUrl" action="getInvitedPolls"
namespace="/json" escapeAmp="false"/>
-<sjg:grid dataType="json" href="%{loadInvitedUrl}" gridModel="polls"
+<sjg:grid dataType="json" href="%{loadInvitedUrl}" gridModel="data"
sortable="true" pager="true" pagerButtons="true" pagerInput="true"
navigator="true" rownumbers="false" autowidth="true"
onSelectRowTopics='users-rowSelect' editurl="%{loadUrl}"
Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/participatedList.jsp
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/participatedList.jsp 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/user/participatedList.jsp 2012-09-23 13:48:42 UTC (rev 3702)
@@ -39,7 +39,7 @@
<s:url id="loadParticipatedUrl" action="getParticipatedPolls"
namespace="/json" escapeAmp="false"/>
-<sjg:grid dataType="json" href="%{loadParticipatedUrl}" gridModel="polls"
+<sjg:grid dataType="json" href="%{loadParticipatedUrl}" gridModel="data"
sortable="true" pager="true" pagerButtons="true" pagerInput="true"
navigator="true" rownumbers="false" autowidth="true"
onSelectRowTopics='users-rowSelect' editurl="%{loadUrl}"
Modified: trunk/pollen-ui-struts2/src/main/webapp/js/favoriteList.js
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/js/favoriteList.js 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/webapp/js/favoriteList.js 2012-09-23 13:48:42 UTC (rev 3702)
@@ -80,7 +80,7 @@
jQuery.getJSON(
loadPollActionUrl, { "pollAccountId":id }, function (result) {
- var pollAccount = result.pollAccount;
+ var pollAccount = result.data;
$('#editForm [name="editPollAccount.topiaId"]').val(pollAccount.id);
$('#editForm [name="editPollAccount.votingId"]').val(pollAccount.votingId);
$('#editForm [name="editPollAccount.email"]').val(pollAccount.email);
Modified: trunk/pollen-ui-struts2/src/main/webapp/js/usersList.js
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/js/usersList.js 2012-09-23 13:16:05 UTC (rev 3701)
+++ trunk/pollen-ui-struts2/src/main/webapp/js/usersList.js 2012-09-23 13:48:42 UTC (rev 3702)
@@ -89,7 +89,7 @@
jQuery.getJSON(
loadUserUrl, { "userId":id }, function (result) {
- var user = result.user;
+ var user = result.data;
$('#editForm [name="editUser.topiaId"]').val(user.id);
$('#editForm [name="editUser.login"]').val(user.login);
$('#editForm [name="editUser.email"]').val(user.email);
1
0
r3701 - in trunk: pollen-persistence pollen-votecounting-api
by tchemit@users.chorem.org Sept. 23, 2012
by tchemit@users.chorem.org Sept. 23, 2012
Sept. 23, 2012
Author: tchemit
Date: 2012-09-23 15:16:05 +0200 (Sun, 23 Sep 2012)
New Revision: 3701
Url: http://chorem.org/repositories/revision/pollen/3701
Log:
optimize dependencies
Modified:
trunk/pollen-persistence/pom.xml
trunk/pollen-votecounting-api/pom.xml
Modified: trunk/pollen-persistence/pom.xml
===================================================================
--- trunk/pollen-persistence/pom.xml 2012-09-23 13:09:29 UTC (rev 3700)
+++ trunk/pollen-persistence/pom.xml 2012-09-23 13:16:05 UTC (rev 3701)
@@ -34,6 +34,10 @@
<artifactId>commons-logging</artifactId>
</dependency>
<dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
Modified: trunk/pollen-votecounting-api/pom.xml
===================================================================
--- trunk/pollen-votecounting-api/pom.xml 2012-09-23 13:09:29 UTC (rev 3700)
+++ trunk/pollen-votecounting-api/pom.xml 2012-09-23 13:16:05 UTC (rev 3701)
@@ -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>
@@ -18,6 +20,10 @@
<dependencies>
<dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ </dependency>
+ <dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
1
0
r3700 - in trunk: pollen-persistence/src/main/java/org/chorem/pollen/business/persistence pollen-persistence/src/main/resources/i18n pollen-persistence/src/main/xmi pollen-services/src/main/java/org/chorem/pollen/entities/migration pollen-services/src/main/resources/META-INF/services pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model
by tchemit@users.chorem.org Sept. 23, 2012
by tchemit@users.chorem.org Sept. 23, 2012
Sept. 23, 2012
Author: tchemit
Date: 2012-09-23 15:09:29 +0200 (Sun, 23 Sep 2012)
New Revision: 3700
Url: http://chorem.org/repositories/revision/pollen/3700
Log:
move to version 1.5-SNAPSHOT
Added:
trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_5.java
Removed:
trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4_5_2.java
Modified:
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/Polls.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.properties
trunk/pollen-services/src/main/resources/META-INF/services/org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG$MigrationCallBackForVersion
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
Modified: 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 2012-09-23 13:03:52 UTC (rev 3699)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/Polls.java 2012-09-23 13:09:29 UTC (rev 3700)
@@ -1,5 +1,28 @@
package org.chorem.pollen.business.persistence;
+/*
+ * #%L
+ * Pollen :: Persistence
+ * $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%
+ */
+
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import org.chorem.pollen.PollenFunctions;
Property changes on: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/Polls.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
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-23 13:03:52 UTC (rev 3699)
+++ trunk/pollen-persistence/src/main/resources/i18n/pollen-persistence_en_GB.properties 2012-09-23 13:09:29 UTC (rev 3700)
@@ -1,4 +1,7 @@
pollen.application.config=Pollen configuration
+pollen.choiceType.date=Date
+pollen.choiceType.image=Image
+pollen.choiceType.text=Text
pollen.configuration.adminEmail=email for default admin
pollen.configuration.charset=Charset used by Pollen
pollen.configuration.contactEmail=email for contact link
@@ -26,6 +29,9 @@
pollen.configuration.tmpDirectory=Temporary directory (is cleaned at each startup of application)
pollen.pollCommentVisibilty.everybody=Use comments on poll
pollen.pollCommentVisibilty.nobody=No usage of comments on poll
+pollen.pollType.free=Free
+pollen.pollType.group=Group
+pollen.pollType.restricted=Restricted
pollen.pollVoteVisibilty.creatorOnly=Visible for creator
pollen.pollVoteVisibilty.creatorOnly.help=On poll's creator or administrator can see votes
pollen.pollVoteVisibilty.everybody=Public vote
@@ -34,12 +40,6 @@
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
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-23 13:03:52 UTC (rev 3699)
+++ trunk/pollen-persistence/src/main/resources/i18n/pollen-persistence_fr_FR.properties 2012-09-23 13:09:29 UTC (rev 3700)
@@ -1,4 +1,7 @@
pollen.application.config=Configuration de Pollen
+pollen.choiceType.date=Date
+pollen.choiceType.image=Image
+pollen.choiceType.text=Texte
pollen.configuration.adminEmail=Email de l'utilisateur par défaut (Utilisateur crée lors du premier lancement de pollen)
pollen.configuration.charset=Encoding utilisé par Pollen
pollen.configuration.contactEmail=Email pour le lien Contact
@@ -26,6 +29,9 @@
pollen.configuration.tmpDirectory=Répertoire temporaire (est nettoyé à chaque démarrage de l'application)
pollen.pollCommentVisibilty.everybody=Utiliser les commentaires
pollen.pollCommentVisibilty.nobody=Interdir les commentaires sur le sondage
+pollen.pollType.free=Libre
+pollen.pollType.group=Groupe
+pollen.pollType.restricted=Restreint
pollen.pollVoteVisibilty.creatorOnly=Visible pour le créateur
pollen.pollVoteVisibilty.creatorOnly.help=Seul le créateur ou un administrateur peut voir les votes
pollen.pollVoteVisibilty.everybody=Vote publique
@@ -34,12 +40,6 @@
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
Modified: trunk/pollen-persistence/src/main/xmi/pollen.properties
===================================================================
--- trunk/pollen-persistence/src/main/xmi/pollen.properties 2012-09-23 13:03:52 UTC (rev 3699)
+++ trunk/pollen-persistence/src/main/xmi/pollen.properties 2012-09-23 13:09:29 UTC (rev 3700)
@@ -24,7 +24,7 @@
#model.tagvalue.dbSchema=Pollen
model.tagvalue.constantPrefix=PROPERTY_
model.tagvalue.java.lang.String=text
-model.tagvalue.version=1.4.5.2
+model.tagvalue.version=1.5
model.tagvalue.doNotGenerateBooleanGetMethods=true
model.tagvalue.indexForeignKeys=true
Deleted: trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4_5_2.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4_5_2.java 2012-09-23 13:03:52 UTC (rev 3699)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4_5_2.java 2012-09-23 13:09:29 UTC (rev 3700)
@@ -1,195 +0,0 @@
-package org.chorem.pollen.entities.migration;
-
-import com.google.common.base.Function;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.Multimap;
-import com.opensymphony.xwork2.ActionContext;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.PollenApplicationContext;
-import org.chorem.pollen.business.persistence.Poll;
-import org.chorem.pollen.business.persistence.PollAccount;
-import org.chorem.pollen.business.persistence.PollDAO;
-import org.chorem.pollen.business.persistence.UserAccount;
-import org.chorem.pollen.business.persistence.Vote;
-import org.chorem.pollen.entities.PollenDAOHelper;
-import org.chorem.pollen.services.DefaultPollenServiceContext;
-import org.chorem.pollen.services.PollenServiceContext;
-import org.chorem.pollen.services.PollenServiceFactory;
-import org.chorem.pollen.services.impl.VoteService;
-import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.framework.TopiaContextImplementor;
-import org.nuiton.topia.framework.TopiaSQLQuery;
-import org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG;
-import org.nuiton.util.Version;
-import org.nuiton.util.VersionUtil;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.List;
-import java.util.Locale;
-import java.util.Set;
-
-/**
- * Migration for version {@code 1.4.5.2}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.4.5.2
- */
-public class PollenMigrationCallbackV1_4_5_2 extends TopiaMigrationCallbackByClassNG.MigrationCallBackForVersion {
-
- /** Logger. */
- private static final Log log =
- LogFactory.getLog(PollenMigrationCallbackV1_4_5_2.class);
-
- @Override
- public Version getVersion() {
- return VersionUtil.valueOf("1.4.5.2");
- }
-
- @Override
- protected void prepareMigrationScript(TopiaContextImplementor tx,
- List<String> queries,
- boolean showSql,
- boolean showProgression) throws TopiaException {
-
- PollenApplicationContext applicationContext = PollenApplicationContext.get(
- ActionContext.getContext());
-
- PollenServiceContext sContext = DefaultPollenServiceContext.newContext(
- Locale.getDefault(),
- tx,
- applicationContext.getConfiguration(),
- new PollenServiceFactory(),
- applicationContext.getVoteCountingStrategyProvider()
- );
-
- // clean pollAccount for votes
- // see http://chorem.org/issues/804
- removeDuplicateVoteWithSameUserAccount(tx, sContext, queries);
- }
-
- private void removeDuplicateVoteWithSameUserAccount(TopiaContextImplementor tx,
- PollenServiceContext sContext,
- List<String> queries) throws TopiaException {
-
- // get all poll with several votes with same userAccount
- TopiaSQLQuery<String> getAllPollIdsQuery = new TopiaSQLQuery<String>() {
-
- @Override
- protected PreparedStatement prepareQuery(Connection connection) throws SQLException {
- PreparedStatement ps = connection.prepareStatement(
- "SELECT p.pollid FROM poll p WHERE " +
- "(SELECT COUNT(pa) > COUNT(DISTINCT(pa.useraccount)) " +
- "FROM vote v,pollaccount pa WHERE " +
- "v.poll = p.topiaid AND v.pollaccount = pa.topiaid " +
- "AND pa.useraccount IS NOT NULL);");
- return ps;
- }
-
- @Override
- protected String prepareResult(ResultSet set) throws SQLException {
- String pollId = set.getString(1);
- return pollId;
- }
- };
-
- List<String> pollIds = getAllPollIdsQuery.findMultipleResult(tx);
-
- PollDAO pollDAO = PollenDAOHelper.getPollDAO(tx);
-
- VoteService voteService = sContext.newService(VoteService.class);
-
- Multimap<Poll, PollAccount> accountToAnonymous = ArrayListMultimap.create();
- Multimap<Poll, Vote> voteToFixByPoll = ArrayListMultimap.create();
-
- long nbPolls = pollIds.size();
- int currentPollIndex = 0;
-
- for (String pollId : pollIds) {
-
- if (log.isInfoEnabled()) {
- log.info("Treat bad poll [" + (currentPollIndex++) + "/" +
- nbPolls + "]" + pollId);
- }
-
- Poll poll = pollDAO.findByPollId(pollId);
- boolean pollAnonymous = poll.isAnonymous();
-
- List<Vote> votes = voteService.getAllVotes(poll);
-
- Multimap<UserAccount, Vote> voteByUserAccount = ArrayListMultimap.create();
- for (Vote vote : votes) {
- UserAccount useraccount = voteToUserAccount.apply(vote);
- if (useraccount != null) {
- voteByUserAccount.put(useraccount, vote);
- }
- }
-
- for (UserAccount userAccount : voteByUserAccount.keySet()) {
-
- if (userAccount != null) {
-
- Collection<Vote> votesForUser = voteByUserAccount.get(userAccount);
- if (votesForUser.size() > 1) {
-
- // ok found a userAccount
- if (log.isWarnEnabled()) {
- log.warn("Poll" + (pollAnonymous ? "(anonymous)" : "") + " [" + poll.getPollId() + "] with multi vote for the same userAccount : " +
- userAccount.getEmail());
- }
- if (pollAnonymous) {
- for (Vote vote : votesForUser) {
- accountToAnonymous.put(poll, vote.getPollAccount());
- }
- } else {
- voteToFixByPoll.putAll(poll, votesForUser);
- }
- }
- }
- }
- }
-
- // treat anonymous vote
- Set<Poll> anonymousPollToFix = accountToAnonymous.keySet();
-
- if (CollectionUtils.isNotEmpty(anonymousPollToFix)) {
- if (log.isWarnEnabled()) {
- log.warn("There is " + anonymousPollToFix.size() + " anonymous " +
- "poll to fix, will remove the userAccount from " +
- "anonymous votes");
- }
- String request = "UPDATE pollaccount set useraccount = NULL WHERE topiaid='%s';";
- for (PollAccount account : accountToAnonymous.values()) {
- queries.add(String.format(request, account.getTopiaId()));
- }
- }
-
- // treat other votes
- Set<Poll> pollToFix = voteToFixByPoll.keySet();
- if (CollectionUtils.isNotEmpty(pollToFix)) {
- if (log.isWarnEnabled()) {
- log.warn("There is " + pollToFix.size() + " other polls " +
- "to fix, will remove the userAccount from any votes");
- }
- String request = "UPDATE pollaccount set useraccount = NULL WHERE topiaid='%s';";
- for (Vote account : voteToFixByPoll.values()) {
- queries.add(String.format(request, account.getPollAccount().getTopiaId()));
- }
- }
-
- }
-
- final Function<Vote, UserAccount> voteToUserAccount = new Function<Vote, UserAccount>() {
- @Override
- public UserAccount apply(Vote input) {
- PollAccount pollAccount = input.getPollAccount();
- return pollAccount == null ? null : pollAccount.getUserAccount();
- }
- };
-
-}
\ No newline at end of file
Copied: trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_5.java (from rev 3697, trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4_5_2.java)
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_5.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_5.java 2012-09-23 13:09:29 UTC (rev 3700)
@@ -0,0 +1,218 @@
+package org.chorem.pollen.entities.migration;
+
+/*
+ * #%L
+ * Pollen :: Services
+ * $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%
+ */
+
+import com.google.common.base.Function;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+import com.opensymphony.xwork2.ActionContext;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.PollenApplicationContext;
+import org.chorem.pollen.business.persistence.Poll;
+import org.chorem.pollen.business.persistence.PollAccount;
+import org.chorem.pollen.business.persistence.PollDAO;
+import org.chorem.pollen.business.persistence.UserAccount;
+import org.chorem.pollen.business.persistence.Vote;
+import org.chorem.pollen.entities.PollenDAOHelper;
+import org.chorem.pollen.services.DefaultPollenServiceContext;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.PollenServiceFactory;
+import org.chorem.pollen.services.impl.VoteService;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaContextImplementor;
+import org.nuiton.topia.framework.TopiaSQLQuery;
+import org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG;
+import org.nuiton.util.Version;
+import org.nuiton.util.VersionUtil;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * Migration for version {@code 1.4.5.2}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5.2
+ */
+public class PollenMigrationCallbackV1_5 extends TopiaMigrationCallbackByClassNG.MigrationCallBackForVersion {
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(PollenMigrationCallbackV1_5.class);
+
+ @Override
+ public Version getVersion() {
+ return VersionUtil.valueOf("1.5");
+ }
+
+ @Override
+ protected void prepareMigrationScript(TopiaContextImplementor tx,
+ List<String> queries,
+ boolean showSql,
+ boolean showProgression) throws TopiaException {
+
+ PollenApplicationContext applicationContext = PollenApplicationContext.get(
+ ActionContext.getContext());
+
+ PollenServiceContext sContext = DefaultPollenServiceContext.newContext(
+ Locale.getDefault(),
+ tx,
+ applicationContext.getConfiguration(),
+ new PollenServiceFactory(),
+ applicationContext.getVoteCountingStrategyProvider()
+ );
+
+ // clean pollAccount for votes
+ // see http://chorem.org/issues/804
+ removeDuplicateVoteWithSameUserAccount(tx, sContext, queries);
+ }
+
+ private void removeDuplicateVoteWithSameUserAccount(TopiaContextImplementor tx,
+ PollenServiceContext sContext,
+ List<String> queries) throws TopiaException {
+
+ // get all poll with several votes with same userAccount
+ TopiaSQLQuery<String> getAllPollIdsQuery = new TopiaSQLQuery<String>() {
+
+ @Override
+ protected PreparedStatement prepareQuery(Connection connection) throws SQLException {
+ PreparedStatement ps = connection.prepareStatement(
+ "SELECT p.pollid FROM poll p WHERE " +
+ "(SELECT COUNT(pa) > COUNT(DISTINCT(pa.useraccount)) " +
+ "FROM vote v,pollaccount pa WHERE " +
+ "v.poll = p.topiaid AND v.pollaccount = pa.topiaid " +
+ "AND pa.useraccount IS NOT NULL);");
+ return ps;
+ }
+
+ @Override
+ protected String prepareResult(ResultSet set) throws SQLException {
+ String pollId = set.getString(1);
+ return pollId;
+ }
+ };
+
+ List<String> pollIds = getAllPollIdsQuery.findMultipleResult(tx);
+
+ PollDAO pollDAO = PollenDAOHelper.getPollDAO(tx);
+
+ VoteService voteService = sContext.newService(VoteService.class);
+
+ Multimap<Poll, PollAccount> accountToAnonymous = ArrayListMultimap.create();
+ Multimap<Poll, Vote> voteToFixByPoll = ArrayListMultimap.create();
+
+ long nbPolls = pollIds.size();
+ int currentPollIndex = 0;
+
+ for (String pollId : pollIds) {
+
+ if (log.isInfoEnabled()) {
+ log.info("Treat bad poll [" + (currentPollIndex++) + "/" +
+ nbPolls + "]" + pollId);
+ }
+
+ Poll poll = pollDAO.findByPollId(pollId);
+ boolean pollAnonymous = poll.isAnonymous();
+
+ List<Vote> votes = voteService.getAllVotes(poll);
+
+ Multimap<UserAccount, Vote> voteByUserAccount = ArrayListMultimap.create();
+ for (Vote vote : votes) {
+ UserAccount useraccount = voteToUserAccount.apply(vote);
+ if (useraccount != null) {
+ voteByUserAccount.put(useraccount, vote);
+ }
+ }
+
+ for (UserAccount userAccount : voteByUserAccount.keySet()) {
+
+ if (userAccount != null) {
+
+ Collection<Vote> votesForUser = voteByUserAccount.get(userAccount);
+ if (votesForUser.size() > 1) {
+
+ // ok found a userAccount
+ if (log.isWarnEnabled()) {
+ log.warn("Poll" + (pollAnonymous ? "(anonymous)" : "") + " [" + poll.getPollId() + "] with multi vote for the same userAccount : " +
+ userAccount.getEmail());
+ }
+ if (pollAnonymous) {
+ for (Vote vote : votesForUser) {
+ accountToAnonymous.put(poll, vote.getPollAccount());
+ }
+ } else {
+ voteToFixByPoll.putAll(poll, votesForUser);
+ }
+ }
+ }
+ }
+ }
+
+ // treat anonymous vote
+ Set<Poll> anonymousPollToFix = accountToAnonymous.keySet();
+
+ if (CollectionUtils.isNotEmpty(anonymousPollToFix)) {
+ if (log.isWarnEnabled()) {
+ log.warn("There is " + anonymousPollToFix.size() + " anonymous " +
+ "poll to fix, will remove the userAccount from " +
+ "anonymous votes");
+ }
+ String request = "UPDATE pollaccount set useraccount = NULL WHERE topiaid='%s';";
+ for (PollAccount account : accountToAnonymous.values()) {
+ queries.add(String.format(request, account.getTopiaId()));
+ }
+ }
+
+ // treat other votes
+ Set<Poll> pollToFix = voteToFixByPoll.keySet();
+ if (CollectionUtils.isNotEmpty(pollToFix)) {
+ if (log.isWarnEnabled()) {
+ log.warn("There is " + pollToFix.size() + " other polls " +
+ "to fix, will remove the userAccount from any votes");
+ }
+ String request = "UPDATE pollaccount set useraccount = NULL WHERE topiaid='%s';";
+ for (Vote account : voteToFixByPoll.values()) {
+ queries.add(String.format(request, account.getPollAccount().getTopiaId()));
+ }
+ }
+
+ }
+
+ final Function<Vote, UserAccount> voteToUserAccount = new Function<Vote, UserAccount>() {
+ @Override
+ public UserAccount apply(Vote input) {
+ PollAccount pollAccount = input.getPollAccount();
+ return pollAccount == null ? null : pollAccount.getUserAccount();
+ }
+ };
+
+}
\ No newline at end of file
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_5.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/pollen-services/src/main/resources/META-INF/services/org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG$MigrationCallBackForVersion
===================================================================
--- trunk/pollen-services/src/main/resources/META-INF/services/org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG$MigrationCallBackForVersion 2012-09-23 13:03:52 UTC (rev 3699)
+++ trunk/pollen-services/src/main/resources/META-INF/services/org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG$MigrationCallBackForVersion 2012-09-23 13:09:29 UTC (rev 3700)
@@ -4,4 +4,4 @@
org.chorem.pollen.entities.migration.PollenMigrationCallbackV1_3_1
org.chorem.pollen.entities.migration.PollenMigrationCallbackV1_4
org.chorem.pollen.entities.migration.PollenMigrationCallbackV1_4_5
-org.chorem.pollen.entities.migration.PollenMigrationCallbackV1_4_5_2
\ No newline at end of file
+org.chorem.pollen.entities.migration.PollenMigrationCallbackV1_5
\ No newline at end of file
Modified: 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 2012-09-23 13:03:52 UTC (rev 3699)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/GroupOfVoterBuilder.java 2012-09-23 13:09:29 UTC (rev 3700)
@@ -1,5 +1,28 @@
package org.chorem.pollen.votecounting.model;
+/*
+ * #%L
+ * Pollen :: VoteCounting Api
+ * $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%
+ */
+
import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
Property changes on: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/GroupOfVoterBuilder.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: 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 2012-09-23 13:03:52 UTC (rev 3699)
+++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/SimpleVoterBuilder.java 2012-09-23 13:09:29 UTC (rev 3700)
@@ -1,5 +1,28 @@
package org.chorem.pollen.votecounting.model;
+/*
+ * #%L
+ * Pollen :: VoteCounting Api
+ * $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%
+ */
+
import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
Property changes on: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/model/SimpleVoterBuilder.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
1
0
Sept. 23, 2012
Author: tchemit
Date: 2012-09-23 15:03:52 +0200 (Sun, 23 Sep 2012)
New Revision: 3699
Url: http://chorem.org/repositories/revision/pollen/3699
Log:
move to version 1.5-SNAPSHOT
Modified:
trunk/pollen-persistence/pom.xml
trunk/pollen-services/pom.xml
trunk/pollen-ui-struts2/pom.xml
trunk/pollen-votecounting-api/pom.xml
trunk/pollen-votecounting-strategy-borda/pom.xml
trunk/pollen-votecounting-strategy-condorcet/pom.xml
trunk/pollen-votecounting-strategy-coombs/pom.xml
trunk/pollen-votecounting-strategy-instant-runoff/pom.xml
trunk/pollen-votecounting-strategy-normal/pom.xml
trunk/pollen-votecounting-strategy-number/pom.xml
trunk/pollen-votecounting-strategy-percentage/pom.xml
trunk/pollen-votecounting-strategy/pom.xml
trunk/pom.xml
Modified: trunk/pollen-persistence/pom.xml
===================================================================
--- trunk/pollen-persistence/pom.xml 2012-09-23 13:01:38 UTC (rev 3698)
+++ trunk/pollen-persistence/pom.xml 2012-09-23 13:03:52 UTC (rev 3699)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.chorem</groupId>
<artifactId>pollen</artifactId>
- <version>1.4.5.2-SNAPSHOT</version>
+ <version>1.5-SNAPSHOT</version>
</parent>
<groupId>org.chorem.pollen</groupId>
Modified: trunk/pollen-services/pom.xml
===================================================================
--- trunk/pollen-services/pom.xml 2012-09-23 13:01:38 UTC (rev 3698)
+++ trunk/pollen-services/pom.xml 2012-09-23 13:03:52 UTC (rev 3699)
@@ -12,7 +12,7 @@
<parent>
<groupId>org.chorem</groupId>
<artifactId>pollen</artifactId>
- <version>1.4.5.2-SNAPSHOT</version>
+ <version>1.5-SNAPSHOT</version>
</parent>
<groupId>org.chorem.pollen</groupId>
Modified: trunk/pollen-ui-struts2/pom.xml
===================================================================
--- trunk/pollen-ui-struts2/pom.xml 2012-09-23 13:01:38 UTC (rev 3698)
+++ trunk/pollen-ui-struts2/pom.xml 2012-09-23 13:03:52 UTC (rev 3699)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.chorem</groupId>
<artifactId>pollen</artifactId>
- <version>1.4.5.2-SNAPSHOT</version>
+ <version>1.5-SNAPSHOT</version>
</parent>
<groupId>org.chorem.pollen</groupId>
Modified: trunk/pollen-votecounting-api/pom.xml
===================================================================
--- trunk/pollen-votecounting-api/pom.xml 2012-09-23 13:01:38 UTC (rev 3698)
+++ trunk/pollen-votecounting-api/pom.xml 2012-09-23 13:03:52 UTC (rev 3699)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.chorem</groupId>
<artifactId>pollen</artifactId>
- <version>1.4.5.2-SNAPSHOT</version>
+ <version>1.5-SNAPSHOT</version>
</parent>
<groupId>org.chorem.pollen</groupId>
Modified: trunk/pollen-votecounting-strategy/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy/pom.xml 2012-09-23 13:01:38 UTC (rev 3698)
+++ trunk/pollen-votecounting-strategy/pom.xml 2012-09-23 13:03:52 UTC (rev 3699)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.chorem</groupId>
<artifactId>pollen</artifactId>
- <version>1.4.5.2-SNAPSHOT</version>
+ <version>1.5-SNAPSHOT</version>
</parent>
<groupId>org.chorem.pollen</groupId>
Modified: trunk/pollen-votecounting-strategy-borda/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy-borda/pom.xml 2012-09-23 13:01:38 UTC (rev 3698)
+++ trunk/pollen-votecounting-strategy-borda/pom.xml 2012-09-23 13:03:52 UTC (rev 3699)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.chorem</groupId>
<artifactId>pollen</artifactId>
- <version>1.4.5.2-SNAPSHOT</version>
+ <version>1.5-SNAPSHOT</version>
</parent>
<groupId>org.chorem.pollen</groupId>
Modified: trunk/pollen-votecounting-strategy-condorcet/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy-condorcet/pom.xml 2012-09-23 13:01:38 UTC (rev 3698)
+++ trunk/pollen-votecounting-strategy-condorcet/pom.xml 2012-09-23 13:03:52 UTC (rev 3699)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.chorem</groupId>
<artifactId>pollen</artifactId>
- <version>1.4.5.2-SNAPSHOT</version>
+ <version>1.5-SNAPSHOT</version>
</parent>
<groupId>org.chorem.pollen</groupId>
Modified: trunk/pollen-votecounting-strategy-coombs/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy-coombs/pom.xml 2012-09-23 13:01:38 UTC (rev 3698)
+++ trunk/pollen-votecounting-strategy-coombs/pom.xml 2012-09-23 13:03:52 UTC (rev 3699)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.chorem</groupId>
<artifactId>pollen</artifactId>
- <version>1.4.5.2-SNAPSHOT</version>
+ <version>1.5-SNAPSHOT</version>
</parent>
<groupId>org.chorem.pollen</groupId>
Modified: trunk/pollen-votecounting-strategy-instant-runoff/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy-instant-runoff/pom.xml 2012-09-23 13:01:38 UTC (rev 3698)
+++ trunk/pollen-votecounting-strategy-instant-runoff/pom.xml 2012-09-23 13:03:52 UTC (rev 3699)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.chorem</groupId>
<artifactId>pollen</artifactId>
- <version>1.4.5.2-SNAPSHOT</version>
+ <version>1.5-SNAPSHOT</version>
</parent>
<groupId>org.chorem.pollen</groupId>
Modified: trunk/pollen-votecounting-strategy-normal/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy-normal/pom.xml 2012-09-23 13:01:38 UTC (rev 3698)
+++ trunk/pollen-votecounting-strategy-normal/pom.xml 2012-09-23 13:03:52 UTC (rev 3699)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.chorem</groupId>
<artifactId>pollen</artifactId>
- <version>1.4.5.2-SNAPSHOT</version>
+ <version>1.5-SNAPSHOT</version>
</parent>
<groupId>org.chorem.pollen</groupId>
Modified: trunk/pollen-votecounting-strategy-number/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy-number/pom.xml 2012-09-23 13:01:38 UTC (rev 3698)
+++ trunk/pollen-votecounting-strategy-number/pom.xml 2012-09-23 13:03:52 UTC (rev 3699)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.chorem</groupId>
<artifactId>pollen</artifactId>
- <version>1.4.5.2-SNAPSHOT</version>
+ <version>1.5-SNAPSHOT</version>
</parent>
<groupId>org.chorem.pollen</groupId>
Modified: trunk/pollen-votecounting-strategy-percentage/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy-percentage/pom.xml 2012-09-23 13:01:38 UTC (rev 3698)
+++ trunk/pollen-votecounting-strategy-percentage/pom.xml 2012-09-23 13:03:52 UTC (rev 3699)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.chorem</groupId>
<artifactId>pollen</artifactId>
- <version>1.4.5.2-SNAPSHOT</version>
+ <version>1.5-SNAPSHOT</version>
</parent>
<groupId>org.chorem.pollen</groupId>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-09-23 13:01:38 UTC (rev 3698)
+++ trunk/pom.xml 2012-09-23 13:03:52 UTC (rev 3699)
@@ -15,7 +15,7 @@
<groupId>org.chorem</groupId>
<artifactId>pollen</artifactId>
- <version>1.4.5.2-SNAPSHOT</version>
+ <version>1.5-SNAPSHOT</version>
<modules>
<module>pollen-votecounting-api</module>
1
0
Sept. 23, 2012
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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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>
1
0
Sept. 19, 2012
Author: tchemit
Date: 2012-09-19 17:48:36 +0200 (Wed, 19 Sep 2012)
New Revision: 3697
Url: http://chorem.org/repositories/revision/pollen/3697
Log:
remove reporting profile from poms for modules with no site
Modified:
trunk/pollen-persistence/pom.xml
trunk/pollen-services/pom.xml
trunk/pollen-ui-struts2/pom.xml
trunk/pollen-votecounting-api/pom.xml
trunk/pollen-votecounting-strategy-borda/pom.xml
trunk/pollen-votecounting-strategy-condorcet/pom.xml
trunk/pollen-votecounting-strategy-coombs/pom.xml
trunk/pollen-votecounting-strategy-instant-runoff/pom.xml
trunk/pollen-votecounting-strategy-normal/pom.xml
trunk/pollen-votecounting-strategy-number/pom.xml
trunk/pollen-votecounting-strategy-percentage/pom.xml
trunk/pollen-votecounting-strategy/pom.xml
trunk/pollen-votecounting/pom.xml
Modified: trunk/pollen-persistence/pom.xml
===================================================================
--- trunk/pollen-persistence/pom.xml 2012-09-19 15:42:53 UTC (rev 3696)
+++ trunk/pollen-persistence/pom.xml 2012-09-19 15:48:36 UTC (rev 3697)
@@ -148,45 +148,5 @@
</plugins>
</build>
- <profiles>
-
- <profile>
- <id>reporting</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-site-plugin</artifactId>
- <configuration>
- <reportPlugins>
- <plugin>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <reports>
- <report>index</report>
- <report>project-team</report>
- <report>mailing-list</report>
- <report>cim</report>
- <report>issue-tracking</report>
- <report>license</report>
- <report>scm</report>
- <report>dependency-convergence</report>
- <report>dependency-management</report>
- </reports>
- </plugin>
- </reportPlugins>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- </profile>
- </profiles>
-
</project>
Modified: trunk/pollen-services/pom.xml
===================================================================
--- trunk/pollen-services/pom.xml 2012-09-19 15:42:53 UTC (rev 3696)
+++ trunk/pollen-services/pom.xml 2012-09-19 15:48:36 UTC (rev 3697)
@@ -138,45 +138,5 @@
</plugins>
</build>
- <profiles>
-
- <profile>
- <id>reporting</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-site-plugin</artifactId>
- <configuration>
- <reportPlugins>
- <plugin>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <reports>
- <report>index</report>
- <report>project-team</report>
- <report>mailing-list</report>
- <report>cim</report>
- <report>issue-tracking</report>
- <report>license</report>
- <report>scm</report>
- <report>dependency-convergence</report>
- <report>dependency-management</report>
- </reports>
- </plugin>
- </reportPlugins>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- </profile>
- </profiles>
-
</project>
Modified: trunk/pollen-ui-struts2/pom.xml
===================================================================
--- trunk/pollen-ui-struts2/pom.xml 2012-09-19 15:42:53 UTC (rev 3696)
+++ trunk/pollen-ui-struts2/pom.xml 2012-09-19 15:48:36 UTC (rev 3697)
@@ -653,43 +653,6 @@
</reporting>
</profile>
- <profile>
- <id>reporting</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-site-plugin</artifactId>
- <configuration>
- <reportPlugins>
- <plugin>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <reports>
- <report>index</report>
- <report>project-team</report>
- <report>mailing-list</report>
- <report>cim</report>
- <report>issue-tracking</report>
- <report>license</report>
- <report>scm</report>
- <report>dependency-convergence</report>
- <report>dependency-management</report>
- </reports>
- </plugin>
- </reportPlugins>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- </profile>
-
</profiles>
</project>
Modified: trunk/pollen-votecounting/pom.xml
===================================================================
--- trunk/pollen-votecounting/pom.xml 2012-09-19 15:42:53 UTC (rev 3696)
+++ trunk/pollen-votecounting/pom.xml 2012-09-19 15:48:36 UTC (rev 3697)
@@ -61,45 +61,4 @@
</plugins>
</build>
- <profiles>
-
- <profile>
- <id>reporting</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-site-plugin</artifactId>
- <configuration>
- <reportPlugins>
- <plugin>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <reports>
- <report>index</report>
- <report>project-team</report>
- <report>mailing-list</report>
- <report>cim</report>
- <report>issue-tracking</report>
- <report>license</report>
- <report>scm</report>
- <report>dependency-convergence</report>
- <report>dependency-management</report>
- </reports>
- </plugin>
- </reportPlugins>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- </profile>
-
- </profiles>
-
</project>
Modified: trunk/pollen-votecounting-api/pom.xml
===================================================================
--- trunk/pollen-votecounting-api/pom.xml 2012-09-19 15:42:53 UTC (rev 3696)
+++ trunk/pollen-votecounting-api/pom.xml 2012-09-19 15:48:36 UTC (rev 3697)
@@ -58,45 +58,4 @@
</plugins>
</build>
- <profiles>
-
- <profile>
- <id>reporting</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-site-plugin</artifactId>
- <configuration>
- <reportPlugins>
- <plugin>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <reports>
- <report>index</report>
- <report>project-team</report>
- <report>mailing-list</report>
- <report>cim</report>
- <report>issue-tracking</report>
- <report>license</report>
- <report>scm</report>
- <report>dependency-convergence</report>
- <report>dependency-management</report>
- </reports>
- </plugin>
- </reportPlugins>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- </profile>
-
- </profiles>
-
</project>
Modified: trunk/pollen-votecounting-strategy/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy/pom.xml 2012-09-19 15:42:53 UTC (rev 3696)
+++ trunk/pollen-votecounting-strategy/pom.xml 2012-09-19 15:48:36 UTC (rev 3697)
@@ -71,46 +71,5 @@
<packaging>pom</packaging>
- <profiles>
-
- <profile>
- <id>reporting</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-site-plugin</artifactId>
- <configuration>
- <reportPlugins>
- <plugin>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <reports>
- <report>index</report>
- <report>project-team</report>
- <report>mailing-list</report>
- <report>cim</report>
- <report>issue-tracking</report>
- <report>license</report>
- <report>scm</report>
- <report>dependency-convergence</report>
- <report>dependency-management</report>
- </reports>
- </plugin>
- </reportPlugins>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- </profile>
-
- </profiles>
-
</project>
Modified: trunk/pollen-votecounting-strategy-borda/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy-borda/pom.xml 2012-09-19 15:42:53 UTC (rev 3696)
+++ trunk/pollen-votecounting-strategy-borda/pom.xml 2012-09-19 15:48:36 UTC (rev 3697)
@@ -62,45 +62,4 @@
</plugins>
</build>
- <profiles>
-
- <profile>
- <id>reporting</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-site-plugin</artifactId>
- <configuration>
- <reportPlugins>
- <plugin>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <reports>
- <report>index</report>
- <report>project-team</report>
- <report>mailing-list</report>
- <report>cim</report>
- <report>issue-tracking</report>
- <report>license</report>
- <report>scm</report>
- <report>dependency-convergence</report>
- <report>dependency-management</report>
- </reports>
- </plugin>
- </reportPlugins>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- </profile>
-
- </profiles>
-
</project>
Modified: trunk/pollen-votecounting-strategy-condorcet/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy-condorcet/pom.xml 2012-09-19 15:42:53 UTC (rev 3696)
+++ trunk/pollen-votecounting-strategy-condorcet/pom.xml 2012-09-19 15:48:36 UTC (rev 3697)
@@ -60,45 +60,4 @@
</plugins>
</build>
- <profiles>
-
- <profile>
- <id>reporting</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-site-plugin</artifactId>
- <configuration>
- <reportPlugins>
- <plugin>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <reports>
- <report>index</report>
- <report>project-team</report>
- <report>mailing-list</report>
- <report>cim</report>
- <report>issue-tracking</report>
- <report>license</report>
- <report>scm</report>
- <report>dependency-convergence</report>
- <report>dependency-management</report>
- </reports>
- </plugin>
- </reportPlugins>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- </profile>
-
- </profiles>
-
</project>
Modified: trunk/pollen-votecounting-strategy-coombs/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy-coombs/pom.xml 2012-09-19 15:42:53 UTC (rev 3696)
+++ trunk/pollen-votecounting-strategy-coombs/pom.xml 2012-09-19 15:48:36 UTC (rev 3697)
@@ -62,45 +62,4 @@
</plugins>
</build>
- <profiles>
-
- <profile>
- <id>reporting</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-site-plugin</artifactId>
- <configuration>
- <reportPlugins>
- <plugin>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <reports>
- <report>index</report>
- <report>project-team</report>
- <report>mailing-list</report>
- <report>cim</report>
- <report>issue-tracking</report>
- <report>license</report>
- <report>scm</report>
- <report>dependency-convergence</report>
- <report>dependency-management</report>
- </reports>
- </plugin>
- </reportPlugins>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- </profile>
-
- </profiles>
-
</project>
Modified: trunk/pollen-votecounting-strategy-instant-runoff/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy-instant-runoff/pom.xml 2012-09-19 15:42:53 UTC (rev 3696)
+++ trunk/pollen-votecounting-strategy-instant-runoff/pom.xml 2012-09-19 15:48:36 UTC (rev 3697)
@@ -62,45 +62,4 @@
</plugins>
</build>
- <profiles>
-
- <profile>
- <id>reporting</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-site-plugin</artifactId>
- <configuration>
- <reportPlugins>
- <plugin>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <reports>
- <report>index</report>
- <report>project-team</report>
- <report>mailing-list</report>
- <report>cim</report>
- <report>issue-tracking</report>
- <report>license</report>
- <report>scm</report>
- <report>dependency-convergence</report>
- <report>dependency-management</report>
- </reports>
- </plugin>
- </reportPlugins>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- </profile>
-
- </profiles>
-
</project>
Modified: trunk/pollen-votecounting-strategy-normal/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy-normal/pom.xml 2012-09-19 15:42:53 UTC (rev 3696)
+++ trunk/pollen-votecounting-strategy-normal/pom.xml 2012-09-19 15:48:36 UTC (rev 3697)
@@ -56,45 +56,4 @@
</plugins>
</build>
- <profiles>
-
- <profile>
- <id>reporting</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-site-plugin</artifactId>
- <configuration>
- <reportPlugins>
- <plugin>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <reports>
- <report>index</report>
- <report>project-team</report>
- <report>mailing-list</report>
- <report>cim</report>
- <report>issue-tracking</report>
- <report>license</report>
- <report>scm</report>
- <report>dependency-convergence</report>
- <report>dependency-management</report>
- </reports>
- </plugin>
- </reportPlugins>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- </profile>
-
- </profiles>
-
</project>
Modified: trunk/pollen-votecounting-strategy-number/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy-number/pom.xml 2012-09-19 15:42:53 UTC (rev 3696)
+++ trunk/pollen-votecounting-strategy-number/pom.xml 2012-09-19 15:48:36 UTC (rev 3697)
@@ -56,45 +56,4 @@
</plugins>
</build>
- <profiles>
-
- <profile>
- <id>reporting</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-site-plugin</artifactId>
- <configuration>
- <reportPlugins>
- <plugin>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <reports>
- <report>index</report>
- <report>project-team</report>
- <report>mailing-list</report>
- <report>cim</report>
- <report>issue-tracking</report>
- <report>license</report>
- <report>scm</report>
- <report>dependency-convergence</report>
- <report>dependency-management</report>
- </reports>
- </plugin>
- </reportPlugins>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- </profile>
-
- </profiles>
-
</project>
Modified: trunk/pollen-votecounting-strategy-percentage/pom.xml
===================================================================
--- trunk/pollen-votecounting-strategy-percentage/pom.xml 2012-09-19 15:42:53 UTC (rev 3696)
+++ trunk/pollen-votecounting-strategy-percentage/pom.xml 2012-09-19 15:48:36 UTC (rev 3697)
@@ -64,45 +64,4 @@
</plugins>
</build>
- <profiles>
-
- <profile>
- <id>reporting</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-site-plugin</artifactId>
- <configuration>
- <reportPlugins>
- <plugin>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <reports>
- <report>index</report>
- <report>project-team</report>
- <report>mailing-list</report>
- <report>cim</report>
- <report>issue-tracking</report>
- <report>license</report>
- <report>scm</report>
- <report>dependency-convergence</report>
- <report>dependency-management</report>
- </reports>
- </plugin>
- </reportPlugins>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- </profile>
-
- </profiles>
-
</project>
1
0
r3696 - trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence
by tchemit@users.chorem.org Sept. 19, 2012
by tchemit@users.chorem.org Sept. 19, 2012
Sept. 19, 2012
Author: tchemit
Date: 2012-09-19 17:42:53 +0200 (Wed, 19 Sep 2012)
New Revision: 3696
Url: http://chorem.org/repositories/revision/pollen/3696
Log:
fixes #813: Impossible de consulter une liste de votants
Modified:
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollDAOImpl.java
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollDAOImpl.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollDAOImpl.java 2012-09-19 15:42:39 UTC (rev 3695)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollDAOImpl.java 2012-09-19 15:42:53 UTC (rev 3696)
@@ -31,7 +31,6 @@
import org.nuiton.topia.persistence.pager.TopiaPagerBean;
import org.nuiton.util.PagerBeanUtil;
-import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -122,7 +121,7 @@
mapResult.put(poll, pollAccount);
}
long records = mapResult.size();
- pager.setRecords((int) records);
+ pager.setRecords(records);
PagerBeanUtil.computeRecordIndexesAndPagesNumber(pager);
List<Map.Entry<Poll, PollAccount>> entries =
Lists.newLinkedList(mapResult.entrySet());
@@ -137,7 +136,7 @@
PagerBeanUtil.computeRecordIndexesAndPagesNumber(pager);
List<E> subList = PagerBeanUtil.getPage(elements, pager.getPageIndex(), pager.getPageSize());
- List<E> result = new ArrayList<E>(subList);
+ List<E> result = Lists.newArrayList(subList);
return result;
}
1
0
r3695 - trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence
by tchemit@users.chorem.org Sept. 19, 2012
by tchemit@users.chorem.org Sept. 19, 2012
Sept. 19, 2012
Author: tchemit
Date: 2012-09-19 17:42:39 +0200 (Wed, 19 Sep 2012)
New Revision: 3695
Url: http://chorem.org/repositories/revision/pollen/3695
Log:
fixes #812: Impossible de cr?\195?\169er une liste ?\195?\160 la main ou par import CSV
Modified:
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java 2012-09-19 10:07:17 UTC (rev 3694)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java 2012-09-19 15:42:39 UTC (rev 3695)
@@ -30,6 +30,7 @@
import org.apache.commons.logging.LogFactory;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.persistence.pager.TopiaPagerBean;
+import org.nuiton.util.PagerBeanUtil;
import java.util.List;
@@ -175,6 +176,7 @@
int records = favoriteList.sizePollAccount();
pager.setRecords(records);
+ PagerBeanUtil.computeRecordIndexesAndPagesNumber(pager);
String hql = createSimpleQuery("e") + " WHERE e.personList = :owner";
@@ -188,7 +190,7 @@
Preconditions.checkNotNull(personListToUpdate);
Preconditions.checkNotNull(pollAccount);
- String hql = createSimpleQuery("e") + " WHERE " +
+ String hql = "SELECT COUNT(*) " + createSimpleQuery("e") + " WHERE " +
"e.personList = :person AND " +
"e.email = :email";
String pollAccountId = pollAccount.getTopiaId();
1
0
r3694 - trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll
by tchemit@users.chorem.org Sept. 19, 2012
by tchemit@users.chorem.org Sept. 19, 2012
Sept. 19, 2012
Author: tchemit
Date: 2012-09-19 12:07:17 +0200 (Wed, 19 Sep 2012)
New Revision: 3694
Url: http://chorem.org/repositories/revision/pollen/3694
Log:
remove commented code
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/vote.jsp
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 10:07:02 UTC (rev 3693)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/result.jsp 2012-09-19 10:07:17 UTC (rev 3694)
@@ -71,52 +71,16 @@
<h1 class="titleVoteCounting"><s:property value="poll.title"/></h1>
-<!-- Informations sur le sondage -->
+<%-- Informations sur le sondage --%>
<s:set name="showVoteUrl" value="true"/>
<s:set name="showResultUrl" value="false"/>
<%@include file="pollInformation.jsp" %>
-<%--<div id="resultTop">--%>
- <%--<div style="white-space:pre-wrap; text-align: start;">--%>
- <%--<s:property value="poll.description"/>--%>
- <%--</div>--%>
- <%--<fieldset>--%>
- <%--<legend><s:text name="pollen.common.aboutPoll"/></legend>--%>
- <%--<div style="float: right">--%>
- <%--<s:if test="creatorOrAdmin">--%>
- <%--<s:a href="%{summaryUrl}">--%>
- <%--<img src="<s:url value='/img/editSmall.png'/>"--%>
- <%--title="<s:text name='pollen.action.summaryPoll'/>"--%>
- <%--alt="<s:text name='pollen.action.summaryPoll'/>"/>--%>
- <%--</s:a>--%>
- <%--</s:if>--%>
- <%--<s:a href='%{voteUrl}'>--%>
- <%--<img src="<s:url value='/img/vote.png'/>"--%>
- <%--title="<s:text name="pollen.common.vote.return-help"/>"--%>
- <%--alt="<s:text name="pollen.common.vote.return"/>"/>--%>
- <%--</s:a>--%>
- <%--<s:if test="feedFileExisting">--%>
- <%--<s:a namespace="/poll" action="getFeed">--%>
- <%--<s:param name="pollId" value="poll.pollId"/>--%>
- <%--<img src="<s:url value='/img/feed.png'/>" title="Atom" alt="Atom"/>--%>
- <%--</s:a>--%>
- <%--</s:if>--%>
- <%--</div>--%>
- <%--<s:label value="%{pollCreatorName}" key='pollen.common.pollCreator'/>--%>
- <%--<s:label value="%{pollBeginDate}" key='pollen.common.beginDate'/>--%>
- <%--<s:label value="%{pollEndDate}" key='pollen.common.endDate'/>--%>
- <%--<s:label value="%{voteCountingTypeName}"--%>
- <%--key='pollen.common.voteCountingType'--%>
- <%--tooltip="%{voteCountingTypeHelp}"--%>
- <%--tooltipIconPath="/img/tooltip.png"/>--%>
- <%--</fieldset>--%>
-<%--</div>--%>
-
<h4>
<s:property value="%{voteSizeMessage}"/>
</h4>
-<!-- Victoire -->
+<%-- Victoire --%>
<s:if test="victoryMessage != ''">
<h4><s:property value="victoryMessage"/>
<br/>
@@ -191,19 +155,19 @@
<img id='chart_normal'/>
</sj:div>
- <!-- 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>
- </s:if>
+ <%-- 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>--%>
+ <%--</s:if>--%>
</div>
<!-- Classement -->
<%--<t:remove>--%>
Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-09-19 10:07:02 UTC (rev 3693)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-09-19 10:07:17 UTC (rev 3694)
@@ -119,48 +119,6 @@
<s:set name="showResultUrl" value="true"/>
<%@include file="pollInformation.jsp" %>
-<%--<div id="pollTop">--%>
- <%--<div style="white-space:pre-wrap; text-align: start;">--%>
- <%--<s:property value="poll.description"/>--%>
- <%--</div>--%>
- <%--<fieldset>--%>
- <%--<legend><s:text name="pollen.common.aboutPoll"/></legend>--%>
- <%--<div style="float: right">--%>
- <%--<s:if test="creatorOrAdmin">--%>
- <%--<s:a href="%{summaryUrl}">--%>
- <%--<img src="<s:url value='/img/editSmall.png'/>"--%>
- <%--title="<s:text name='pollen.action.summaryPoll'/>"--%>
- <%--alt="<s:text name='pollen.action.summaryPoll'/>"/>--%>
- <%--</s:a>--%>
- <%--</s:if>--%>
- <%--<s:if test="resultAllowed">--%>
- <%--<s:a href="%{resultUrl}">--%>
- <%--<img src="<s:url value='/img/count.png'/>"--%>
- <%--title="<s:text name='pollen.common.vote.results-help'/>"--%>
- <%--alt="<s:text name='pollen.common.vote.results'/>"/>--%>
- <%--</s:a>--%>
- <%--</s:if>--%>
- <%--<s:if test="feedFileExisting">--%>
- <%--<s:a namespace="/poll" action="getFeed">--%>
- <%--<s:param name="pollId" value="poll.pollId"/>--%>
- <%--<img src="<s:url value='/img/feed.png'/>" title="Atom" alt="Atom"/>--%>
- <%--</s:a>--%>
- <%--</s:if>--%>
- <%--</div>--%>
- <%--<s:label value="%{pollCreatorName}" key='pollen.common.pollCreator'/>--%>
- <%--<s:label value="%{pollBeginDate}" key='pollen.common.beginDate'/>--%>
- <%--<s:label value="%{pollEndDate}" key='pollen.common.endDate'/>--%>
- <%--<s:label value="%{voteCountingTypeName}"--%>
- <%--key='pollen.common.voteCountingType'--%>
- <%--tooltip="%{voteCountingTypeHelp}"--%>
- <%--tooltipIconPath="/img/tooltip.png"/>--%>
- <%--<s:label value="%{pollVoteVisibilityName}"--%>
- <%--key='pollen.common.pollVoteVisibility'--%>
- <%--tooltip="%{pollVoteVisibilityHelp}"--%>
- <%--tooltipIconPath="/img/tooltip.png"/>--%>
- <%--</fieldset>--%>
-<%--</div>--%>
-
<div id="pollZone">
<s:if test="pollChoiceOrVoteStarted">
1
0
r3693 - in trunk/pollen-ui-struts2/src/main: java/org/chorem/pollen/ui/actions/poll/vote resources/i18n
by tchemit@users.chorem.org Sept. 19, 2012
by tchemit@users.chorem.org Sept. 19, 2012
Sept. 19, 2012
Author: tchemit
Date: 2012-09-19 12:07:02 +0200 (Wed, 19 Sep 2012)
New Revision: 3693
Url: http://chorem.org/repositories/revision/pollen/3693
Log:
fixes #811: Bad vote validation
Modified:
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/VoteForPoll.java
trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/VoteForPoll.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/VoteForPoll.java 2012-09-19 08:25:53 UTC (rev 3692)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/vote/VoteForPoll.java 2012-09-19 10:07:02 UTC (rev 3693)
@@ -111,12 +111,13 @@
VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll());
boolean voteValid = true;
- int voteNumber = 0;
+ int voteNumber = -1;
for (VoteToChoice voteToChoice : vote.getChoiceVoteToChoice()) {
+ voteNumber++;
Integer value = voteToChoice.getVoteValue();
- if (value==null) {
+ if (value == null) {
// check value if same as the one return by request
// otherwise it means there is a conversion error
@@ -127,7 +128,7 @@
// vote value changed
String validMessage =
- _("pollen.error.vote.invalidFormat", paramValue);
+ _("pollen.error.vote.invalidFormat", voteToChoice.getChoice().getName(), paramValue);
addFieldError("vote.choices", validMessage);
voteValid = false;
break;
Modified: trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties
===================================================================
--- trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-09-19 08:25:53 UTC (rev 3692)
+++ trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-09-19 10:07:02 UTC (rev 3693)
@@ -232,7 +232,7 @@
pollen.error.user.restrictedListsForbidden=The poll is restricted and you are not allowed to vote. Check if you have correctly used the link sent to you by email.
pollen.error.userNotAllowed=You are not allowed to count the votes for this poll.
pollen.error.vote.invalidCondorcetVoteValue=Invalid position\: in a condorcet vote, you can let empty values, or put values greater than zero.
-pollen.error.vote.invalidFormat=Vote value invalid (must be a integer number)
+pollen.error.vote.invalidFormat=Vote '%s' value %s is invalid (must be a integer number)
pollen.error.vote.maxChoiceNb=The maximal number of choices is %d.
pollen.error.vote.percentage=The sum of the values must be equals to 100.
pollen.fieldset.choice.options=Choices
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 08:25:53 UTC (rev 3692)
+++ trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-09-19 10:07:02 UTC (rev 3693)
@@ -233,7 +233,7 @@
pollen.error.user.restrictedListsForbidden=Le sondage est restreint et vous n'êtes pas autorisé à voter. Vérifiez que vous avez bien utiliser le lien qui vous a été envoyé.
pollen.error.userNotAllowed=Vous n'êtes pas autorisé à dépouiller ce sondage.
pollen.error.vote.invalidCondorcetVoteValue=Position invalide \: dans un vote condorcet, vous pouvez soit laisser laisser vide un choix, soit mettre une valeur strictement positive.
-pollen.error.vote.invalidFormat=Valeur de vote %s invalide (doit être un nombre entier)
+pollen.error.vote.invalidFormat=Valeur de vote '%s' %s invalide (doit être un nombre entier)
pollen.error.vote.maxChoiceNb=Le nombre de choix maximal est de %d.
pollen.error.vote.percentage=La somme des valeurs doit être égale à 100.
pollen.fieldset.choice.options=Les choix
1
0
r3692 - in trunk/pollen-ui-struts2/src/main/webapp: WEB-INF/jsp/poll css
by tchemit@users.chorem.org Sept. 19, 2012
by tchemit@users.chorem.org Sept. 19, 2012
Sept. 19, 2012
Author: tchemit
Date: 2012-09-19 10:25:53 +0200 (Wed, 19 Sep 2012)
New Revision: 3692
Url: http://chorem.org/repositories/revision/pollen/3692
Log:
factorize poll information ui fragment
Added:
trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/pollInformation.jsp
trunk/pollen-ui-struts2/src/main/webapp/css/pollInformation.css
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/vote.jsp
trunk/pollen-ui-struts2/src/main/webapp/css/results.css
trunk/pollen-ui-struts2/src/main/webapp/css/vote.css
Added: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/pollInformation.jsp
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/pollInformation.jsp (rev 0)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/pollInformation.jsp 2012-09-19 08:25:53 UTC (rev 3692)
@@ -0,0 +1,70 @@
+<%--
+ #%L
+ Pollen :: UI (struts2)
+ $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%
+ --%>
+<%@ page contentType="text/html" language="java" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<div id="pollInformationTop">
+ <div style="white-space:pre-wrap; text-align: start;">
+ <s:property value="poll.description"/>
+ </div>
+ <fieldset>
+ <legend><s:text name="pollen.common.aboutPoll"/></legend>
+ <div style="float: right">
+ <s:if test="creatorOrAdmin">
+ <s:a href="%{summaryUrl}">
+ <img src="<s:url value='/img/editSmall.png'/>"
+ title="<s:text name='pollen.action.summaryPoll'/>"
+ alt="<s:text name='pollen.action.summaryPoll'/>"/>
+ </s:a>
+ </s:if>
+ <s:if test="#showVoteUrl">
+ <s:a href='%{voteUrl}'>
+ <img src="<s:url value='/img/vote.png'/>"
+ title="<s:text name="pollen.common.vote.return-help"/>"
+ alt="<s:text name="pollen.common.vote.return"/>"/>
+ </s:a>
+ </s:if>
+ <s:if test="#showResultUrl">
+ <s:if test="resultAllowed">
+ <s:a href="%{resultUrl}">
+ <img src="<s:url value='/img/count.png'/>"
+ title="<s:text name='pollen.common.vote.results-help'/>"
+ alt="<s:text name='pollen.common.vote.results'/>"/>
+ </s:a>
+ </s:if>
+ </s:if>
+ <s:if test="feedFileExisting">
+ <s:a namespace="/poll" action="getFeed">
+ <s:param name="pollId" value="poll.pollId"/>
+ <img src="<s:url value='/img/feed.png'/>" title="Atom" alt="Atom"/>
+ </s:a>
+ </s:if>
+ </div>
+ <s:label value="%{pollCreatorName}" key='pollen.common.pollCreator'/>
+ <s:label value="%{pollBeginDate}" key='pollen.common.beginDate'/>
+ <s:label value="%{pollEndDate}" key='pollen.common.endDate'/>
+ <s:label value="%{voteCountingTypeName}"
+ key='pollen.common.voteCountingType'
+ tooltip="%{voteCountingTypeHelp}"
+ tooltipIconPath="/img/tooltip.png"/>
+ </fieldset>
+</div>
\ No newline at end of file
Property changes on: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/pollInformation.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
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-14 16:33:06 UTC (rev 3691)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/result.jsp 2012-09-19 08:25:53 UTC (rev 3692)
@@ -20,12 +20,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
#L%
--%>
-<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ page contentType="text/html" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
<link rel="stylesheet" type="text/css"
href="<s:url value='/css/results.css'/>"/>
<link rel="stylesheet" type="text/css"
+ href="<s:url value='/css/pollInformation.css'/>"/>
+<link rel="stylesheet" type="text/css"
href="<s:url value='/css/jquery.lightbox-0.5.css'/>"/>
@@ -70,42 +72,46 @@
<h1 class="titleVoteCounting"><s:property value="poll.title"/></h1>
<!-- Informations sur le sondage -->
-<div id="resultTop">
- <div style="white-space:pre-wrap; text-align: start;">
- <s:property value="poll.description"/>
- </div>
- <fieldset>
- <legend><s:text name="pollen.common.aboutPoll"/></legend>
- <div style="float: right">
- <s:if test="creatorOrAdmin">
- <s:a href="%{summaryUrl}">
- <img src="<s:url value='/img/editSmall.png'/>"
- title="<s:text name='pollen.action.summaryPoll'/>"
- alt="<s:text name='pollen.action.summaryPoll'/>"/>
- </s:a>
- </s:if>
- <s:a href='%{voteUrl}'>
- <img src="<s:url value='/img/vote.png'/>"
- title="<s:text name="pollen.common.vote.return-help"/>"
- alt="<s:text name="pollen.common.vote.return"/>"/>
- </s:a>
- <s:if test="feedFileExisting">
- <s:a namespace="/poll" action="getFeed">
- <s:param name="pollId" value="poll.pollId"/>
- <img src="<s:url value='/img/feed.png'/>" title="Atom" alt="Atom"/>
- </s:a>
- </s:if>
- </div>
- <s:label value="%{pollCreatorName}" key='pollen.common.pollCreator'/>
- <s:label value="%{pollBeginDate}" key='pollen.common.beginDate'/>
- <s:label value="%{pollEndDate}" key='pollen.common.endDate'/>
- <s:label value="%{voteCountingTypeName}"
- key='pollen.common.voteCountingType'
- tooltip="%{voteCountingTypeHelp}"
- tooltipIconPath="/img/tooltip.png"/>
- </fieldset>
-</div>
+<s:set name="showVoteUrl" value="true"/>
+<s:set name="showResultUrl" value="false"/>
+<%@include file="pollInformation.jsp" %>
+<%--<div id="resultTop">--%>
+ <%--<div style="white-space:pre-wrap; text-align: start;">--%>
+ <%--<s:property value="poll.description"/>--%>
+ <%--</div>--%>
+ <%--<fieldset>--%>
+ <%--<legend><s:text name="pollen.common.aboutPoll"/></legend>--%>
+ <%--<div style="float: right">--%>
+ <%--<s:if test="creatorOrAdmin">--%>
+ <%--<s:a href="%{summaryUrl}">--%>
+ <%--<img src="<s:url value='/img/editSmall.png'/>"--%>
+ <%--title="<s:text name='pollen.action.summaryPoll'/>"--%>
+ <%--alt="<s:text name='pollen.action.summaryPoll'/>"/>--%>
+ <%--</s:a>--%>
+ <%--</s:if>--%>
+ <%--<s:a href='%{voteUrl}'>--%>
+ <%--<img src="<s:url value='/img/vote.png'/>"--%>
+ <%--title="<s:text name="pollen.common.vote.return-help"/>"--%>
+ <%--alt="<s:text name="pollen.common.vote.return"/>"/>--%>
+ <%--</s:a>--%>
+ <%--<s:if test="feedFileExisting">--%>
+ <%--<s:a namespace="/poll" action="getFeed">--%>
+ <%--<s:param name="pollId" value="poll.pollId"/>--%>
+ <%--<img src="<s:url value='/img/feed.png'/>" title="Atom" alt="Atom"/>--%>
+ <%--</s:a>--%>
+ <%--</s:if>--%>
+ <%--</div>--%>
+ <%--<s:label value="%{pollCreatorName}" key='pollen.common.pollCreator'/>--%>
+ <%--<s:label value="%{pollBeginDate}" key='pollen.common.beginDate'/>--%>
+ <%--<s:label value="%{pollEndDate}" key='pollen.common.endDate'/>--%>
+ <%--<s:label value="%{voteCountingTypeName}"--%>
+ <%--key='pollen.common.voteCountingType'--%>
+ <%--tooltip="%{voteCountingTypeHelp}"--%>
+ <%--tooltipIconPath="/img/tooltip.png"/>--%>
+ <%--</fieldset>--%>
+<%--</div>--%>
+
<h4>
<s:property value="%{voteSizeMessage}"/>
</h4>
Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-09-14 16:33:06 UTC (rev 3691)
+++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-09-19 08:25:53 UTC (rev 3692)
@@ -29,6 +29,8 @@
<link rel="stylesheet" type="text/css"
href="<s:url value='/css/vote.css'/>"/>
<link rel="stylesheet" type="text/css"
+ href="<s:url value='/css/pollInformation.css'/>"/>
+<link rel="stylesheet" type="text/css"
href="<s:url value='/css/jquery.lightbox-0.5.css'/>"/>
<script type="text/javascript"
@@ -112,48 +114,52 @@
<h1 class="titleVote"><s:property value="poll.title"/></h1>
<!-- Informations sur le sondage -->
+<!-- Informations sur le sondage -->
+<s:set name="showVoteUrl" value="false"/>
+<s:set name="showResultUrl" value="true"/>
+<%@include file="pollInformation.jsp" %>
-<div id="pollTop">
- <div style="white-space:pre-wrap; text-align: start;">
- <s:property value="poll.description"/>
- </div>
- <fieldset>
- <legend><s:text name="pollen.common.aboutPoll"/></legend>
- <div style="float: right">
- <s:if test="creatorOrAdmin">
- <s:a href="%{summaryUrl}">
- <img src="<s:url value='/img/editSmall.png'/>"
- title="<s:text name='pollen.action.summaryPoll'/>"
- alt="<s:text name='pollen.action.summaryPoll'/>"/>
- </s:a>
- </s:if>
- <s:if test="resultAllowed">
- <s:a href="%{resultUrl}">
- <img src="<s:url value='/img/count.png'/>"
- title="<s:text name='pollen.common.vote.results-help'/>"
- alt="<s:text name='pollen.common.vote.results'/>"/>
- </s:a>
- </s:if>
- <s:if test="feedFileExisting">
- <s:a namespace="/poll" action="getFeed">
- <s:param name="pollId" value="poll.pollId"/>
- <img src="<s:url value='/img/feed.png'/>" title="Atom" alt="Atom"/>
- </s:a>
- </s:if>
- </div>
- <s:label value="%{pollCreatorName}" key='pollen.common.pollCreator'/>
- <s:label value="%{pollBeginDate}" key='pollen.common.beginDate'/>
- <s:label value="%{pollEndDate}" key='pollen.common.endDate'/>
- <s:label value="%{voteCountingTypeName}"
- key='pollen.common.voteCountingType'
- tooltip="%{voteCountingTypeHelp}"
- tooltipIconPath="/img/tooltip.png"/>
- <s:label value="%{pollVoteVisibilityName}"
- key='pollen.common.pollVoteVisibility'
- tooltip="%{pollVoteVisibilityHelp}"
- tooltipIconPath="/img/tooltip.png"/>
- </fieldset>
-</div>
+<%--<div id="pollTop">--%>
+ <%--<div style="white-space:pre-wrap; text-align: start;">--%>
+ <%--<s:property value="poll.description"/>--%>
+ <%--</div>--%>
+ <%--<fieldset>--%>
+ <%--<legend><s:text name="pollen.common.aboutPoll"/></legend>--%>
+ <%--<div style="float: right">--%>
+ <%--<s:if test="creatorOrAdmin">--%>
+ <%--<s:a href="%{summaryUrl}">--%>
+ <%--<img src="<s:url value='/img/editSmall.png'/>"--%>
+ <%--title="<s:text name='pollen.action.summaryPoll'/>"--%>
+ <%--alt="<s:text name='pollen.action.summaryPoll'/>"/>--%>
+ <%--</s:a>--%>
+ <%--</s:if>--%>
+ <%--<s:if test="resultAllowed">--%>
+ <%--<s:a href="%{resultUrl}">--%>
+ <%--<img src="<s:url value='/img/count.png'/>"--%>
+ <%--title="<s:text name='pollen.common.vote.results-help'/>"--%>
+ <%--alt="<s:text name='pollen.common.vote.results'/>"/>--%>
+ <%--</s:a>--%>
+ <%--</s:if>--%>
+ <%--<s:if test="feedFileExisting">--%>
+ <%--<s:a namespace="/poll" action="getFeed">--%>
+ <%--<s:param name="pollId" value="poll.pollId"/>--%>
+ <%--<img src="<s:url value='/img/feed.png'/>" title="Atom" alt="Atom"/>--%>
+ <%--</s:a>--%>
+ <%--</s:if>--%>
+ <%--</div>--%>
+ <%--<s:label value="%{pollCreatorName}" key='pollen.common.pollCreator'/>--%>
+ <%--<s:label value="%{pollBeginDate}" key='pollen.common.beginDate'/>--%>
+ <%--<s:label value="%{pollEndDate}" key='pollen.common.endDate'/>--%>
+ <%--<s:label value="%{voteCountingTypeName}"--%>
+ <%--key='pollen.common.voteCountingType'--%>
+ <%--tooltip="%{voteCountingTypeHelp}"--%>
+ <%--tooltipIconPath="/img/tooltip.png"/>--%>
+ <%--<s:label value="%{pollVoteVisibilityName}"--%>
+ <%--key='pollen.common.pollVoteVisibility'--%>
+ <%--tooltip="%{pollVoteVisibilityHelp}"--%>
+ <%--tooltipIconPath="/img/tooltip.png"/>--%>
+ <%--</fieldset>--%>
+<%--</div>--%>
<div id="pollZone">
<s:if test="pollChoiceOrVoteStarted">
Added: trunk/pollen-ui-struts2/src/main/webapp/css/pollInformation.css
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/css/pollInformation.css (rev 0)
+++ trunk/pollen-ui-struts2/src/main/webapp/css/pollInformation.css 2012-09-19 08:25:53 UTC (rev 3692)
@@ -0,0 +1,48 @@
+/*
+ * #%L
+ * Pollen :: UI (struts2)
+ * $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%
+ */
+#pollInformationTop {
+ width: 700px;
+ margin: auto;
+ text-align: center;
+}
+
+#pollInformationTop legend {
+ color: #727a7e;
+ font-weight: bold;
+}
+
+#pollInformationTop fieldset {
+ width: 350px;
+ border: 1px solid #aab;
+ padding: 15px;
+ padding-bottom: 10px;
+ margin: auto;
+ margin-top: 20px;
+ margin-bottom: 20px;
+ vertical-align: top;
+ text-align: left;
+}
+
+#pollInformationTop fieldset .wwlbl {
+ width: 210px;
+}
\ No newline at end of file
Property changes on: trunk/pollen-ui-struts2/src/main/webapp/css/pollInformation.css
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/pollen-ui-struts2/src/main/webapp/css/results.css
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/css/results.css 2012-09-14 16:33:06 UTC (rev 3691)
+++ trunk/pollen-ui-struts2/src/main/webapp/css/results.css 2012-09-19 08:25:53 UTC (rev 3692)
@@ -20,33 +20,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
-#resultTop {
- width: 700px;
- margin: auto;
- text-align: center;
-}
-
-#resultTop legend {
- color: #727a7e;
- font-weight: bold;
-}
-
-#resultTop fieldset {
- width: 350px;
- border: 1px solid #aab;
- padding: 15px;
- padding-bottom: 10px;
- margin: auto;
- margin-top: 20px;
- margin-bottom: 20px;
- vertical-align: top;
- text-align: left;
-}
-
-#resultTop fieldset .wwlbl {
- width: 210px;
-}
-
#resultChart {
width: 400px;
margin: auto;
Modified: trunk/pollen-ui-struts2/src/main/webapp/css/vote.css
===================================================================
--- trunk/pollen-ui-struts2/src/main/webapp/css/vote.css 2012-09-14 16:33:06 UTC (rev 3691)
+++ trunk/pollen-ui-struts2/src/main/webapp/css/vote.css 2012-09-19 08:25:53 UTC (rev 3692)
@@ -20,33 +20,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
-#pollTop {
- width: 700px;
- margin: auto;
- text-align: center;
-}
-
-#pollTop legend {
- color: #727a7e;
- font-weight: bold;
-}
-
-#pollTop fieldset {
- width: 400px;
- border: 1px solid #aab;
- padding: 15px;
- padding-bottom: 10px;
- margin: auto;
- margin-top: 20px;
- margin-bottom: 20px;
- vertical-align: top;
- text-align: left;
-}
-
-#pollTop fieldset .wwlbl {
- width: 210px;
-}
-
#pollZone {
/*padding: 10px;*/
text-align: center;
1
0
r3691 - in trunk: . pollen-persistence/src/main/java/org/chorem/pollen/business/persistence pollen-persistence/src/test/java/org/chorem/pollen/business/persistence pollen-services/src/main/java/org/chorem/pollen/services/impl pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json
by tchemit@users.chorem.org Sept. 14, 2012
by tchemit@users.chorem.org Sept. 14, 2012
Sept. 14, 2012
Author: tchemit
Date: 2012-09-14 18:33:06 +0200 (Fri, 14 Sep 2012)
New Revision: 3691
Url: http://chorem.org/repositories/revision/pollen/3691
Log:
fixes #806: Updates to nuiton-utils 2.6.2
fixes #807: Updates to topia 2.7
fixes #808: updates to h2 1.3.168
Modified:
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/CommentDAOImpl.java
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PersonListDAOImpl.java
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollDAOImpl.java
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/UserAccountDAOImpl.java
trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java
trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/CommentDAOImplTest.java
trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PersonListDAOImplTest.java
trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PollDAOImplTest.java
trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/UserAccountDAOImplTest.java
trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/VoteDAOImplTest.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.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/UserService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONPaginedAction.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetCreatedPolls.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccounts.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteLists.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetInvitedPolls.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetParticipatedPolls.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPolls.java
trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUsers.java
trunk/pom.xml
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/CommentDAOImpl.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/CommentDAOImpl.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/CommentDAOImpl.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -24,13 +24,13 @@
import com.google.common.base.Preconditions;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+import org.nuiton.topia.persistence.pager.TopiaPagerBean;
import java.util.List;
public class CommentDAOImpl<E extends Comment> extends CommentDAOAbstract<E> {
- public List<E> findComments(TopiaFilterPagerUtil.FilterPagerBean pager,
+ public List<E> findComments(TopiaPagerBean pager,
String pollId) throws TopiaException {
Preconditions.checkNotNull(pager);
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PersonListDAOImpl.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PersonListDAOImpl.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PersonListDAOImpl.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -25,25 +25,23 @@
import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+import org.nuiton.topia.persistence.pager.TopiaPagerBean;
import java.util.List;
public class PersonListDAOImpl<E extends PersonList> extends PersonListDAOAbstract<E> {
public List<E> findFavoriteLists(UserAccount user,
- TopiaFilterPagerUtil.FilterPagerBean pager) throws TopiaException {
+ TopiaPagerBean pager) throws TopiaException {
Preconditions.checkNotNull(user);
Preconditions.checkNotNull(pager);
- String countHql = "SELECT COUNT(*) FROM PersonListImpl WHERE " +
- "owner = :owner";
+ String hql = createSimpleQuery("e") + " WHERE e.owner = :owner";
+ String countHql = "SELECT COUNT(*) " + hql;
computeAndAddRecordsToPager(countHql, pager, "owner", user);
- String hql = "FROM PersonListImpl e WHERE e.owner = :owner";
-
List<E> result = findAllByQueryAndPager(hql, pager, "owner", user);
return result;
}
@@ -52,7 +50,7 @@
Preconditions.checkNotNull(user);
- String hql = "FROM PersonListImpl WHERE owner = :owner";
+ String hql = createSimpleQuery("e") + " WHERE e.owner = :owner";
List<E> result = findAllByQuery(hql, "owner", user);
return result;
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollAccountDAOImpl.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -29,7 +29,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+import org.nuiton.topia.persistence.pager.TopiaPagerBean;
import java.util.List;
@@ -168,7 +168,7 @@
}
public List<E> findFavoriteListUsers(PersonList favoriteList,
- TopiaFilterPagerUtil.FilterPagerBean pager) throws TopiaException {
+ TopiaPagerBean pager) throws TopiaException {
Preconditions.checkNotNull(favoriteList);
Preconditions.checkNotNull(pager);
@@ -176,7 +176,7 @@
int records = favoriteList.sizePollAccount();
pager.setRecords(records);
- String hql = "FROM PollAccountImpl e WHERE e.personList = :owner";
+ String hql = createSimpleQuery("e") + " WHERE e.personList = :owner";
List<E> result = findAllByQueryAndPager(hql, pager, "owner", favoriteList);
return result;
@@ -188,7 +188,7 @@
Preconditions.checkNotNull(personListToUpdate);
Preconditions.checkNotNull(pollAccount);
- String hql = "FROM PollAccountImpl e WHERE " +
+ String hql = createSimpleQuery("e") + " WHERE " +
"e.personList = :person AND " +
"e.email = :email";
String pollAccountId = pollAccount.getTopiaId();
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollDAOImpl.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollDAOImpl.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollDAOImpl.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -28,15 +28,17 @@
import org.apache.commons.lang3.tuple.Pair;
import org.chorem.pollen.PollenFunctions;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+import org.nuiton.topia.persistence.pager.TopiaPagerBean;
+import org.nuiton.util.PagerBeanUtil;
+import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
public class PollDAOImpl<E extends Poll> extends PollDAOAbstract<E> {
- public List<E> getPolls(TopiaFilterPagerUtil.FilterPagerBean pager) throws TopiaException {
+ public List<E> getPolls(TopiaPagerBean pager) throws TopiaException {
Preconditions.checkNotNull(pager);
@@ -50,7 +52,7 @@
return result;
}
- public List<E> findCreatedPolls(TopiaFilterPagerUtil.FilterPagerBean pager,
+ public List<E> findCreatedPolls(TopiaPagerBean pager,
UserAccount user) throws TopiaException {
Preconditions.checkNotNull(pager);
@@ -67,7 +69,7 @@
return result;
}
- public List<Pair<Poll, PollAccount>> findInvitedPolls(TopiaFilterPagerUtil.FilterPagerBean pager,
+ public List<Pair<Poll, PollAccount>> findInvitedPolls(TopiaPagerBean pager,
UserAccount user) throws TopiaException {
Preconditions.checkNotNull(pager);
@@ -82,7 +84,7 @@
return result;
}
- public List<Pair<Poll, PollAccount>> findParticipatedPolls(TopiaFilterPagerUtil.FilterPagerBean pager,
+ public List<Pair<Poll, PollAccount>> findParticipatedPolls(TopiaPagerBean pager,
UserAccount user) throws TopiaException {
Preconditions.checkNotNull(pager);
@@ -108,7 +110,7 @@
}
protected List<Pair<Poll, PollAccount>> findAllWithPollAccounts(String hql,
- TopiaFilterPagerUtil.FilterPagerBean pager, Object... params)
+ TopiaPagerBean pager, Object... params)
throws TopiaException {
List<Object[]> queryResults = findAllByQuery(Object[].class, hql, params);
@@ -121,13 +123,23 @@
}
long records = mapResult.size();
pager.setRecords((int) records);
- TopiaFilterPagerUtil.computeRecordIndexesAndPagesNumber(pager);
+ PagerBeanUtil.computeRecordIndexesAndPagesNumber(pager);
List<Map.Entry<Poll, PollAccount>> entries =
Lists.newLinkedList(mapResult.entrySet());
List<Pair<Poll, PollAccount>> result =
- Lists.transform(TopiaFilterPagerUtil.getPageFromList(entries, pager),
+ Lists.transform(getPageFromList(entries, pager),
PollenFunctions.MAP_ENTRY_TO_PAIR_FUNCTION);
return result;
}
+ public static <E> List<E> getPageFromList(List<E> elements,
+ TopiaPagerBean pager) {
+
+ PagerBeanUtil.computeRecordIndexesAndPagesNumber(pager);
+ List<E> subList = PagerBeanUtil.getPage(elements, pager.getPageIndex(), pager.getPageSize());
+ List<E> result = new ArrayList<E>(subList);
+
+ return result;
+ }
+
}
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/UserAccountDAOImpl.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/UserAccountDAOImpl.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/UserAccountDAOImpl.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -25,7 +25,7 @@
import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+import org.nuiton.topia.persistence.pager.TopiaPagerBean;
import java.util.List;
@@ -48,16 +48,16 @@
return result;
}
- public List<E> findUsers(TopiaFilterPagerUtil.FilterPagerBean pager) throws TopiaException {
+ public List<E> findUsers(TopiaPagerBean pager) throws TopiaException {
Preconditions.checkNotNull(pager);
- String countHql = "SELECT COUNT(*) FROM UserAccountImpl";
+ String hql = createSimpleQuery("e");
+ String countHql = "SELECT COUNT(*) " + hql;
+
computeAndAddRecordsToPager(countHql, pager);
- String hql = "FROM UserAccountImpl";
-
List<E> result = findAllByQueryAndPager(hql, pager);
return result;
}
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -24,7 +24,7 @@
import com.google.common.base.Preconditions;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+import org.nuiton.topia.persistence.pager.TopiaPagerBean;
import java.util.List;
@@ -45,7 +45,7 @@
}
public List<E> findAllVotesByPoll(Poll poll,
- TopiaFilterPagerUtil.FilterPagerBean pager) throws TopiaException {
+ TopiaPagerBean pager) throws TopiaException {
Preconditions.checkNotNull(poll);
Preconditions.checkNotNull(pager);
Modified: trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/CommentDAOImplTest.java
===================================================================
--- trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/CommentDAOImplTest.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/CommentDAOImplTest.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -26,7 +26,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+import org.nuiton.topia.persistence.pager.TopiaPagerBean;
import java.util.List;
@@ -52,9 +52,9 @@
tx.commitTransaction();
List<Comment> actual;
- TopiaFilterPagerUtil.FilterPagerBean pager;
+ TopiaPagerBean pager;
- pager = TopiaFilterPagerUtil.newFilterPagerBean();
+ pager = new TopiaPagerBean();
pager.setPageSize(5);
pager.setSortColumn(Comment.PROPERTY_TEXT);
pager.setSortAscendant(true);
@@ -65,7 +65,7 @@
Assert.assertEquals("comment" + i, actual.get(i).getText());
}
- pager = TopiaFilterPagerUtil.newFilterPagerBean();
+ pager = new TopiaPagerBean();
pager.setPageSize(5);
pager.setPageIndex(2);
pager.setSortColumn(Comment.PROPERTY_TEXT);
@@ -77,7 +77,7 @@
Assert.assertEquals("comment" + (5 + i), actual.get(i).getText());
}
- pager = TopiaFilterPagerUtil.newFilterPagerBean();
+ pager = new TopiaPagerBean();
pager.setPageSize(5);
pager.setSortColumn(Comment.PROPERTY_TEXT);
pager.setSortAscendant(false);
@@ -88,7 +88,7 @@
Assert.assertEquals("comment" + (8 - i), actual.get(i).getText());
}
- pager = TopiaFilterPagerUtil.newFilterPagerBean();
+ pager = new TopiaPagerBean();
pager.setPageSize(5);
pager.setSortColumn(Comment.PROPERTY_TEXT);
pager.setSortAscendant(false);
Modified: trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PersonListDAOImplTest.java
===================================================================
--- trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PersonListDAOImplTest.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PersonListDAOImplTest.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -26,7 +26,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+import org.nuiton.topia.persistence.pager.TopiaPagerBean;
import java.util.List;
@@ -85,9 +85,9 @@
tx.commitTransaction();
List<PersonList> actual;
- TopiaFilterPagerUtil.FilterPagerBean pager;
+ TopiaPagerBean pager;
- pager = TopiaFilterPagerUtil.newFilterPagerBean();
+ pager = new TopiaPagerBean();
pager.setPageSize(5);
pager.setSortColumn(PersonList.PROPERTY_NAME);
pager.setSortAscendant(true);
@@ -99,7 +99,7 @@
Assert.assertEquals("name" + i, actual.get(i).getName());
}
- pager = TopiaFilterPagerUtil.newFilterPagerBean();
+ pager = new TopiaPagerBean();
pager.setPageSize(5);
pager.setPageIndex(2);
pager.setSortColumn(PersonList.PROPERTY_NAME);
@@ -111,7 +111,7 @@
Assert.assertEquals("name" + (5 + i), actual.get(i).getName());
}
- pager = TopiaFilterPagerUtil.newFilterPagerBean();
+ pager = new TopiaPagerBean();
pager.setPageSize(5);
pager.setSortColumn(PersonList.PROPERTY_NAME);
pager.setSortAscendant(false);
@@ -122,7 +122,7 @@
Assert.assertEquals("name" + (8 - i), actual.get(i).getName());
}
- pager = TopiaFilterPagerUtil.newFilterPagerBean();
+ pager = new TopiaPagerBean();
pager.setPageSize(5);
pager.setSortColumn(PersonList.PROPERTY_NAME);
pager.setSortAscendant(false);
Modified: trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PollDAOImplTest.java
===================================================================
--- trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PollDAOImplTest.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/PollDAOImplTest.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -29,7 +29,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+import org.nuiton.topia.persistence.pager.TopiaPagerBean;
import org.nuiton.util.DateUtil;
import java.util.Date;
@@ -68,9 +68,9 @@
tx.commitTransaction();
List<Poll> actual;
- TopiaFilterPagerUtil.FilterPagerBean pager;
+ TopiaPagerBean pager;
- pager = TopiaFilterPagerUtil.newFilterPagerBean();
+ pager = new TopiaPagerBean();
pager.setPageSize(5);
pager.setSortColumn(Poll.PROPERTY_TITLE);
pager.setSortAscendant(true);
@@ -81,7 +81,7 @@
Assert.assertEquals("title" + i, actual.get(i).getTitle());
}
- pager = TopiaFilterPagerUtil.newFilterPagerBean();
+ pager = new TopiaPagerBean();
pager.setPageSize(5);
pager.setPageIndex(2);
pager.setSortColumn(Poll.PROPERTY_TITLE);
@@ -93,7 +93,7 @@
Assert.assertEquals("title" + (5 + i), actual.get(i).getTitle());
}
- pager = TopiaFilterPagerUtil.newFilterPagerBean();
+ pager = new TopiaPagerBean();
pager.setPageSize(5);
pager.setSortColumn(Poll.PROPERTY_TITLE);
pager.setSortAscendant(false);
@@ -104,7 +104,7 @@
Assert.assertEquals("title" + (8 - i), actual.get(i).getTitle());
}
- pager = TopiaFilterPagerUtil.newFilterPagerBean();
+ pager = new TopiaPagerBean();
pager.setPageSize(5);
pager.setPageIndex(3);
pager.setSortColumn(Poll.PROPERTY_TITLE);
@@ -136,9 +136,9 @@
tx.commitTransaction();
List<Poll> actual;
- TopiaFilterPagerUtil.FilterPagerBean pager;
+ TopiaPagerBean pager;
- pager = TopiaFilterPagerUtil.newFilterPagerBean();
+ pager = new TopiaPagerBean();
pager.setPageSize(5);
pager.setSortColumn(Poll.PROPERTY_TITLE);
pager.setSortAscendant(true);
@@ -149,7 +149,7 @@
Assert.assertEquals("title" + i, actual.get(i).getTitle());
}
- pager = TopiaFilterPagerUtil.newFilterPagerBean();
+ pager = new TopiaPagerBean();
pager.setPageSize(5);
pager.setPageIndex(2);
pager.setSortColumn(Poll.PROPERTY_TITLE);
@@ -161,7 +161,7 @@
Assert.assertEquals("title" + (5 + i), actual.get(i).getTitle());
}
- pager = TopiaFilterPagerUtil.newFilterPagerBean();
+ pager = new TopiaPagerBean();
pager.setPageSize(5);
pager.setSortColumn(Poll.PROPERTY_TITLE);
pager.setSortAscendant(false);
@@ -172,7 +172,7 @@
Assert.assertEquals("title" + (8 - i), actual.get(i).getTitle());
}
- pager = TopiaFilterPagerUtil.newFilterPagerBean();
+ pager = new TopiaPagerBean();
pager.setPageSize(5);
pager.setSortColumn(Poll.PROPERTY_TITLE);
pager.setSortAscendant(false);
@@ -208,10 +208,10 @@
tx.commitTransaction();
- TopiaFilterPagerUtil.FilterPagerBean pager;
+ TopiaPagerBean pager;
List<Pair<Poll, PollAccount>> actual;
- pager = TopiaFilterPagerUtil.newFilterPagerBean();
+ pager = new TopiaPagerBean();
pager.setPageSize(5);
actual = dao.findParticipatedPolls(pager, userAccount1);
Modified: trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/UserAccountDAOImplTest.java
===================================================================
--- trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/UserAccountDAOImplTest.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/UserAccountDAOImplTest.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -26,7 +26,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+import org.nuiton.topia.persistence.pager.TopiaPagerBean;
import java.util.List;
@@ -92,10 +92,10 @@
tx.commitTransaction();
- TopiaFilterPagerUtil.FilterPagerBean pager;
+ TopiaPagerBean pager;
List<UserAccount> actual;
- pager = TopiaFilterPagerUtil.newFilterPagerBean();
+ pager = new TopiaPagerBean();
pager.setPageSize(5);
pager.setSortColumn(UserAccount.PROPERTY_LOGIN);
pager.setSortAscendant(true);
@@ -106,7 +106,7 @@
Assert.assertEquals("login" + i, actual.get(i).getLogin());
}
- pager = TopiaFilterPagerUtil.newFilterPagerBean();
+ pager = new TopiaPagerBean();
pager.setPageSize(5);
pager.setPageIndex(2);
pager.setSortColumn(UserAccount.PROPERTY_LOGIN);
@@ -118,7 +118,7 @@
Assert.assertEquals("login" + (5 + i), actual.get(i).getLogin());
}
- pager = TopiaFilterPagerUtil.newFilterPagerBean();
+ pager = new TopiaPagerBean();
pager.setPageSize(5);
pager.setSortColumn(UserAccount.PROPERTY_LOGIN);
pager.setSortAscendant(false);
Modified: trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/VoteDAOImplTest.java
===================================================================
--- trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/VoteDAOImplTest.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/VoteDAOImplTest.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -26,7 +26,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+import org.nuiton.topia.persistence.pager.TopiaPagerBean;
import org.nuiton.util.DateUtil;
import java.util.List;
@@ -107,8 +107,7 @@
tx.commitTransaction();
List<Vote> actual;
- TopiaFilterPagerUtil.FilterPagerBean pager =
- TopiaFilterPagerUtil.newFilterPagerBean();
+ TopiaPagerBean pager = new TopiaPagerBean();
pager.setPageSize(10);
actual = voteDAO.findAllVotesByPoll(poll1, pager);
@@ -118,7 +117,7 @@
Assert.assertEquals(vote1, actual.get(1));
Assert.assertFalse(actual.contains(vote3));
- pager = TopiaFilterPagerUtil.newFilterPagerBean();
+ pager = new TopiaPagerBean();
pager.setPageSize(10);
actual = voteDAO.findAllVotesByPoll(poll2, pager);
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteService.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteService.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -45,7 +45,7 @@
import org.chorem.pollen.services.exceptions.ParticipantNotFoundInListException;
import org.chorem.pollen.services.exceptions.UserNotFoundException;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+import org.nuiton.topia.persistence.pager.TopiaPagerBean;
import org.nuiton.util.StringUtil;
import javax.naming.NamingEnumeration;
@@ -72,7 +72,7 @@
private static final Log log = LogFactory.getLog(FavoriteService.class);
public List<PersonList> getFavoriteLists(UserAccount user,
- TopiaFilterPagerUtil.FilterPagerBean pager) {
+ TopiaPagerBean pager) {
Preconditions.checkNotNull(user);
Preconditions.checkNotNull(pager);
@@ -128,7 +128,7 @@
}
public List<PollAccount> getFavoriteListUsers(PersonList favoriteList,
- TopiaFilterPagerUtil.FilterPagerBean pager) {
+ TopiaPagerBean pager) {
Preconditions.checkNotNull(favoriteList);
Preconditions.checkNotNull(pager);
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -33,7 +33,7 @@
import org.chorem.pollen.services.PollenServiceSupport;
import org.chorem.pollen.services.exceptions.PollCommentNotFound;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+import org.nuiton.topia.persistence.pager.TopiaPagerBean;
import java.util.List;
@@ -145,8 +145,7 @@
return result;
}
- public List<Comment> getComments(TopiaFilterPagerUtil.FilterPagerBean pager,
- String pollId) {
+ public List<Comment> getComments(TopiaPagerBean pager, String pollId) {
Preconditions.checkNotNull(pager);
Preconditions.checkNotNull(pollId);
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-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -58,7 +58,7 @@
import org.chorem.pollen.services.exceptions.PollChoiceNotFoundException;
import org.chorem.pollen.services.exceptions.PollNotFoundException;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+import org.nuiton.topia.persistence.pager.TopiaPagerBean;
import org.nuiton.util.beans.Binder;
import javax.imageio.ImageIO;
@@ -421,7 +421,7 @@
return pollToUpdate;
}
- public List<Poll> getPolls(TopiaFilterPagerUtil.FilterPagerBean pager) {
+ public List<Poll> getPolls(TopiaPagerBean pager) {
Preconditions.checkNotNull(pager);
try {
@@ -433,8 +433,7 @@
}
}
- public List<Poll> getCreatedPolls(TopiaFilterPagerUtil.FilterPagerBean pager,
- UserAccount user) {
+ public List<Poll> getCreatedPolls(TopiaPagerBean pager, UserAccount user) {
Preconditions.checkNotNull(pager);
Preconditions.checkNotNull(user);
@@ -448,7 +447,7 @@
}
public List<Pair<Poll, PollAccount>> getInvitedPolls(
- TopiaFilterPagerUtil.FilterPagerBean pager,
+ TopiaPagerBean pager,
UserAccount user) {
Preconditions.checkNotNull(pager);
@@ -469,9 +468,8 @@
}
}
- public List<Pair<Poll, PollAccount>> getParticipatedPolls(
- TopiaFilterPagerUtil.FilterPagerBean pager,
- UserAccount user) {
+ public List<Pair<Poll, PollAccount>> getParticipatedPolls(TopiaPagerBean pager,
+ UserAccount user) {
Preconditions.checkNotNull(pager);
Preconditions.checkNotNull(user);
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -39,7 +39,7 @@
import org.chorem.pollen.services.exceptions.UserLoginAlreadyUsedException;
import org.chorem.pollen.services.exceptions.UserNotFoundException;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+import org.nuiton.topia.persistence.pager.TopiaPagerBean;
import org.nuiton.topia.persistence.util.TopiaEntityBinder;
import org.nuiton.util.StringUtil;
import org.nuiton.util.beans.Binder;
@@ -263,7 +263,7 @@
}
}
- public List<UserAccount> getUsers(TopiaFilterPagerUtil.FilterPagerBean pager) {
+ public List<UserAccount> getUsers(TopiaPagerBean pager) {
Preconditions.checkNotNull(pager);
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-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -45,7 +45,7 @@
import org.chorem.pollen.services.exceptions.PollAccountNotFound;
import org.chorem.pollen.services.exceptions.VoteNotFoundException;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+import org.nuiton.topia.persistence.pager.TopiaPagerBean;
import java.util.List;
@@ -352,8 +352,7 @@
}
}
- public List<Vote> getVotesByPoll(Poll poll,
- TopiaFilterPagerUtil.FilterPagerBean pager) {
+ public List<Vote> getVotesByPoll(Poll poll, TopiaPagerBean pager) {
try {
VoteDAO dao = getDAO(Vote.class);
List<Vote> results = dao.findAllVotesByPoll(poll, pager);
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONPaginedAction.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONPaginedAction.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/AbstractJSONPaginedAction.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -26,7 +26,7 @@
import org.apache.struts2.json.JSONException;
import org.apache.struts2.json.JSONUtil;
import org.chorem.pollen.ui.actions.PollenActionSupport;
-import org.nuiton.topia.persistence.TopiaFilterPagerUtil;
+import org.nuiton.topia.persistence.pager.TopiaPagerBean;
/**
* Abstract JSON action with pagination support.
@@ -38,16 +38,23 @@
private static final long serialVersionUID = 1L;
- public abstract Integer getRows();
+ public final Integer getRows() {
+ return pager.getPageSize();
+ }
- public abstract Integer getPage();
+ public final Integer getPage() {
+ return pager.getPageIndex();
+ }
- public abstract Integer getTotal();
+ public final Long getTotal() {
+ return pager.getPagesNumber();
+ }
- public abstract Integer getRecords();
+ public final Long getRecords() {
+ return pager.getRecords();
+ }
- protected TopiaFilterPagerUtil.FilterPagerBean pager =
- TopiaFilterPagerUtil.newFilterPagerBean();
+ protected TopiaPagerBean pager = new TopiaPagerBean();
protected String filters;
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetCreatedPolls.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetCreatedPolls.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetCreatedPolls.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -51,26 +51,6 @@
}
@Override
- public Integer getRows() {
- return pager.getPageSize();
- }
-
- @Override
- public Integer getPage() {
- return pager.getPageIndex();
- }
-
- @Override
- public Integer getTotal() {
- return pager.getPagesNumber();
- }
-
- @Override
- public Integer getRecords() {
- return pager.getRecords();
- }
-
- @Override
public String execute() throws Exception {
PollService pollService = getPollService();
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccounts.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccounts.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteListPollAccounts.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -58,26 +58,6 @@
}
@Override
- public Integer getRows() {
- return pager.getPageSize();
- }
-
- @Override
- public Integer getPage() {
- return pager.getPageIndex();
- }
-
- @Override
- public Integer getTotal() {
- return pager.getPagesNumber();
- }
-
- @Override
- public Integer getRecords() {
- return pager.getRecords();
- }
-
- @Override
public String execute() throws Exception {
FavoriteService service = getFavoriteService();
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteLists.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteLists.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetFavoriteLists.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -45,26 +45,6 @@
}
@Override
- public Integer getRows() {
- return pager.getPageSize();
- }
-
- @Override
- public Integer getPage() {
- return pager.getPageIndex();
- }
-
- @Override
- public Integer getTotal() {
- return pager.getPagesNumber();
- }
-
- @Override
- public Integer getRecords() {
- return pager.getRecords();
- }
-
- @Override
public String execute() throws Exception {
List<PersonList> allFavoriteLists = getFavoriteService().getFavoriteLists(
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetInvitedPolls.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetInvitedPolls.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetInvitedPolls.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -54,26 +54,6 @@
}
@Override
- public Integer getRows() {
- return pager.getPageSize();
- }
-
- @Override
- public Integer getPage() {
- return pager.getPageIndex();
- }
-
- @Override
- public Integer getTotal() {
- return pager.getPagesNumber();
- }
-
- @Override
- public Integer getRecords() {
- return pager.getRecords();
- }
-
- @Override
public String execute() throws Exception {
PollService pollService = getPollService();
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetParticipatedPolls.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetParticipatedPolls.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetParticipatedPolls.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -54,26 +54,6 @@
}
@Override
- public Integer getRows() {
- return pager.getPageSize();
- }
-
- @Override
- public Integer getPage() {
- return pager.getPageIndex();
- }
-
- @Override
- public Integer getTotal() {
- return pager.getPagesNumber();
- }
-
- @Override
- public Integer getRecords() {
- return pager.getRecords();
- }
-
- @Override
public String execute() throws Exception {
PollService pollService = getPollService();
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPollComments.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -57,26 +57,6 @@
}
@Override
- public Integer getRows() {
- return pager.getPageSize();
- }
-
- @Override
- public Integer getPage() {
- return pager.getPageIndex();
- }
-
- @Override
- public Integer getTotal() {
- return pager.getPagesNumber();
- }
-
- @Override
- public Integer getRecords() {
- return pager.getRecords();
- }
-
- @Override
public String execute() throws Exception {
Preconditions.checkNotNull(pollId);
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPolls.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPolls.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPolls.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -48,26 +48,6 @@
}
@Override
- public Integer getRows() {
- return pager.getPageSize();
- }
-
- @Override
- public Integer getPage() {
- return pager.getPageIndex();
- }
-
- @Override
- public Integer getTotal() {
- return pager.getPagesNumber();
- }
-
- @Override
- public Integer getRecords() {
- return pager.getRecords();
- }
-
- @Override
public String execute() throws Exception {
PollService pollService = getPollService();
Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUsers.java
===================================================================
--- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUsers.java 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetUsers.java 2012-09-14 16:33:06 UTC (rev 3691)
@@ -48,26 +48,6 @@
}
@Override
- public Integer getRows() {
- return pager.getPageSize();
- }
-
- @Override
- public Integer getPage() {
- return pager.getPageIndex();
- }
-
- @Override
- public Integer getTotal() {
- return pager.getPagesNumber();
- }
-
- @Override
- public Integer getRecords() {
- return pager.getRecords();
- }
-
- @Override
public String execute() throws Exception {
List<UserAccount> allUsers = getUserService().getUsers(pager);
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-09-05 21:04:41 UTC (rev 3690)
+++ trunk/pom.xml 2012-09-14 16:33:06 UTC (rev 3691)
@@ -153,13 +153,13 @@
<projectId>pollen</projectId>
<!-- customized versions -->
- <topiaVersion>2.6.14-SNAPSHOT</topiaVersion>
+ <topiaVersion>2.7</topiaVersion>
<eugenePluginVersion>2.5</eugenePluginVersion>
<nuitonI18nVersion>2.5</nuitonI18nVersion>
<nuitonWebVersion>1.11</nuitonWebVersion>
- <nuitonUtilsVersion>2.6.1</nuitonUtilsVersion>
- <h2Version>1.3.167</h2Version>
+ <nuitonUtilsVersion>2.6.2</nuitonUtilsVersion>
+ <h2Version>1.3.168</h2Version>
<postgresqlVersion>9.1-901-1.jdbc4</postgresqlVersion>
<struts2Version>2.3.4</struts2Version>
<jqueryPluginVersion>3.3.1</jqueryPluginVersion>
1
0
r3690 - trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration
by tchemit@users.chorem.org Sept. 5, 2012
by tchemit@users.chorem.org Sept. 5, 2012
Sept. 5, 2012
Author: tchemit
Date: 2012-09-05 23:04:41 +0200 (Wed, 05 Sep 2012)
New Revision: 3690
Url: http://chorem.org/repositories/revision/pollen/3690
Log:
fixes #804: Can not acces no more to poll where I was admin and voter
Modified:
trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4_5_2.java
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4_5_2.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4_5_2.java 2012-09-05 20:09:16 UTC (rev 3689)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4_5_2.java 2012-09-05 21:04:41 UTC (rev 3690)
@@ -8,7 +8,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.PollenApplicationContext;
-import org.chorem.pollen.PollenConfiguration;
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.PollAccount;
import org.chorem.pollen.business.persistence.PollDAO;
@@ -19,13 +18,17 @@
import org.chorem.pollen.services.PollenServiceContext;
import org.chorem.pollen.services.PollenServiceFactory;
import org.chorem.pollen.services.impl.VoteService;
-import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaContextImplementor;
+import org.nuiton.topia.framework.TopiaSQLQuery;
import org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG;
import org.nuiton.util.Version;
import org.nuiton.util.VersionUtil;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
@@ -54,34 +57,49 @@
boolean showSql,
boolean showProgression) throws TopiaException {
-
- PollenServiceFactory serviceFactory = new PollenServiceFactory();
-
PollenApplicationContext applicationContext = PollenApplicationContext.get(
ActionContext.getContext());
- PollenConfiguration configuration =
- applicationContext.getConfiguration();
-
-
PollenServiceContext sContext = DefaultPollenServiceContext.newContext(
Locale.getDefault(),
tx,
- configuration,
- serviceFactory,
+ applicationContext.getConfiguration(),
+ new PollenServiceFactory(),
applicationContext.getVoteCountingStrategyProvider()
);
// clean pollAccount for votes
// see http://chorem.org/issues/804
- removeDuplicateVoteWithSameUserAccount(sContext, queries);
+ removeDuplicateVoteWithSameUserAccount(tx, sContext, queries);
}
- private void removeDuplicateVoteWithSameUserAccount(PollenServiceContext sContext,
+ private void removeDuplicateVoteWithSameUserAccount(TopiaContextImplementor tx,
+ PollenServiceContext sContext,
List<String> queries) throws TopiaException {
- TopiaContext tx = sContext.getTransaction();
+ // get all poll with several votes with same userAccount
+ TopiaSQLQuery<String> getAllPollIdsQuery = new TopiaSQLQuery<String>() {
+ @Override
+ protected PreparedStatement prepareQuery(Connection connection) throws SQLException {
+ PreparedStatement ps = connection.prepareStatement(
+ "SELECT p.pollid FROM poll p WHERE " +
+ "(SELECT COUNT(pa) > COUNT(DISTINCT(pa.useraccount)) " +
+ "FROM vote v,pollaccount pa WHERE " +
+ "v.poll = p.topiaid AND v.pollaccount = pa.topiaid " +
+ "AND pa.useraccount IS NOT NULL);");
+ return ps;
+ }
+
+ @Override
+ protected String prepareResult(ResultSet set) throws SQLException {
+ String pollId = set.getString(1);
+ return pollId;
+ }
+ };
+
+ List<String> pollIds = getAllPollIdsQuery.findMultipleResult(tx);
+
PollDAO pollDAO = PollenDAOHelper.getPollDAO(tx);
VoteService voteService = sContext.newService(VoteService.class);
@@ -89,15 +107,17 @@
Multimap<Poll, PollAccount> accountToAnonymous = ArrayListMultimap.create();
Multimap<Poll, Vote> voteToFixByPoll = ArrayListMultimap.create();
- long nbPolls = pollDAO.count();
+ long nbPolls = pollIds.size();
int currentPollIndex = 0;
- for (Poll poll : pollDAO) {
+ for (String pollId : pollIds) {
if (log.isInfoEnabled()) {
- log.info("Scan poll [" + (currentPollIndex++) + "/" +
- nbPolls + "]" + poll.getPollId());
+ log.info("Treat bad poll [" + (currentPollIndex++) + "/" +
+ nbPolls + "]" + pollId);
}
+
+ Poll poll = pollDAO.findByPollId(pollId);
boolean pollAnonymous = poll.isAnonymous();
List<Vote> votes = voteService.getAllVotes(poll);
@@ -119,9 +139,8 @@
// ok found a userAccount
if (log.isWarnEnabled()) {
- log.warn("Found a poll" + (pollAnonymous ? "(anonymous)" : "") + " [" + poll.getPollId() + "] with multi vote for the same userAccount : " +
+ log.warn("Poll" + (pollAnonymous ? "(anonymous)" : "") + " [" + poll.getPollId() + "] with multi vote for the same userAccount : " +
userAccount.getEmail());
-
}
if (pollAnonymous) {
for (Vote vote : votesForUser) {
@@ -144,7 +163,7 @@
"poll to fix, will remove the userAccount from " +
"anonymous votes");
}
- String request = "UPDATE pollaccount set useraccount IS NULL WHERE topiaid='%s';";
+ String request = "UPDATE pollaccount set useraccount = NULL WHERE topiaid='%s';";
for (PollAccount account : accountToAnonymous.values()) {
queries.add(String.format(request, account.getTopiaId()));
}
@@ -157,9 +176,12 @@
log.warn("There is " + pollToFix.size() + " other polls " +
"to fix, will remove the userAccount from any votes");
}
+ String request = "UPDATE pollaccount set useraccount = NULL WHERE topiaid='%s';";
+ for (Vote account : voteToFixByPoll.values()) {
+ queries.add(String.format(request, account.getPollAccount().getTopiaId()));
+ }
}
-
}
final Function<Vote, UserAccount> voteToUserAccount = new Function<Vote, UserAccount>() {
1
0
r3689 - in trunk: . pollen-persistence/src/main/xmi pollen-services/src/main/java/org/chorem/pollen/entities/migration pollen-services/src/main/resources/META-INF/services
by tchemit@users.chorem.org Sept. 5, 2012
by tchemit@users.chorem.org Sept. 5, 2012
Sept. 5, 2012
Author: tchemit
Date: 2012-09-05 22:09:16 +0200 (Wed, 05 Sep 2012)
New Revision: 3689
Url: http://chorem.org/repositories/revision/pollen/3689
Log:
refs #804: Can not acces no more to poll where I was admin and voter (fix by migration for anonymous poll)
Added:
trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4_5_2.java
Modified:
trunk/pollen-persistence/src/main/xmi/pollen.properties
trunk/pollen-services/src/main/resources/META-INF/services/org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG$MigrationCallBackForVersion
trunk/pom.xml
Modified: trunk/pollen-persistence/src/main/xmi/pollen.properties
===================================================================
--- trunk/pollen-persistence/src/main/xmi/pollen.properties 2012-09-05 17:49:33 UTC (rev 3688)
+++ trunk/pollen-persistence/src/main/xmi/pollen.properties 2012-09-05 20:09:16 UTC (rev 3689)
@@ -24,7 +24,7 @@
#model.tagvalue.dbSchema=Pollen
model.tagvalue.constantPrefix=PROPERTY_
model.tagvalue.java.lang.String=text
-model.tagvalue.version=1.4.5
+model.tagvalue.version=1.4.5.2
model.tagvalue.doNotGenerateBooleanGetMethods=true
model.tagvalue.indexForeignKeys=true
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4_5_2.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4_5_2.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4_5_2.java 2012-09-05 20:09:16 UTC (rev 3689)
@@ -0,0 +1,173 @@
+package org.chorem.pollen.entities.migration;
+
+import com.google.common.base.Function;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+import com.opensymphony.xwork2.ActionContext;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.PollenApplicationContext;
+import org.chorem.pollen.PollenConfiguration;
+import org.chorem.pollen.business.persistence.Poll;
+import org.chorem.pollen.business.persistence.PollAccount;
+import org.chorem.pollen.business.persistence.PollDAO;
+import org.chorem.pollen.business.persistence.UserAccount;
+import org.chorem.pollen.business.persistence.Vote;
+import org.chorem.pollen.entities.PollenDAOHelper;
+import org.chorem.pollen.services.DefaultPollenServiceContext;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.PollenServiceFactory;
+import org.chorem.pollen.services.impl.VoteService;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaContextImplementor;
+import org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG;
+import org.nuiton.util.Version;
+import org.nuiton.util.VersionUtil;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * Migration for version {@code 1.4.5.2}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4.5.2
+ */
+public class PollenMigrationCallbackV1_4_5_2 extends TopiaMigrationCallbackByClassNG.MigrationCallBackForVersion {
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(PollenMigrationCallbackV1_4_5_2.class);
+
+ @Override
+ public Version getVersion() {
+ return VersionUtil.valueOf("1.4.5.2");
+ }
+
+ @Override
+ protected void prepareMigrationScript(TopiaContextImplementor tx,
+ List<String> queries,
+ boolean showSql,
+ boolean showProgression) throws TopiaException {
+
+
+ PollenServiceFactory serviceFactory = new PollenServiceFactory();
+
+ PollenApplicationContext applicationContext = PollenApplicationContext.get(
+ ActionContext.getContext());
+
+ PollenConfiguration configuration =
+ applicationContext.getConfiguration();
+
+
+ PollenServiceContext sContext = DefaultPollenServiceContext.newContext(
+ Locale.getDefault(),
+ tx,
+ configuration,
+ serviceFactory,
+ applicationContext.getVoteCountingStrategyProvider()
+ );
+
+ // clean pollAccount for votes
+ // see http://chorem.org/issues/804
+ removeDuplicateVoteWithSameUserAccount(sContext, queries);
+ }
+
+ private void removeDuplicateVoteWithSameUserAccount(PollenServiceContext sContext,
+ List<String> queries) throws TopiaException {
+
+ TopiaContext tx = sContext.getTransaction();
+
+ PollDAO pollDAO = PollenDAOHelper.getPollDAO(tx);
+
+ VoteService voteService = sContext.newService(VoteService.class);
+
+ Multimap<Poll, PollAccount> accountToAnonymous = ArrayListMultimap.create();
+ Multimap<Poll, Vote> voteToFixByPoll = ArrayListMultimap.create();
+
+ long nbPolls = pollDAO.count();
+ int currentPollIndex = 0;
+
+ for (Poll poll : pollDAO) {
+
+ if (log.isInfoEnabled()) {
+ log.info("Scan poll [" + (currentPollIndex++) + "/" +
+ nbPolls + "]" + poll.getPollId());
+ }
+ boolean pollAnonymous = poll.isAnonymous();
+
+ List<Vote> votes = voteService.getAllVotes(poll);
+
+ Multimap<UserAccount, Vote> voteByUserAccount = ArrayListMultimap.create();
+ for (Vote vote : votes) {
+ UserAccount useraccount = voteToUserAccount.apply(vote);
+ if (useraccount != null) {
+ voteByUserAccount.put(useraccount, vote);
+ }
+ }
+
+ for (UserAccount userAccount : voteByUserAccount.keySet()) {
+
+ if (userAccount != null) {
+
+ Collection<Vote> votesForUser = voteByUserAccount.get(userAccount);
+ if (votesForUser.size() > 1) {
+
+ // ok found a userAccount
+ if (log.isWarnEnabled()) {
+ log.warn("Found a poll" + (pollAnonymous ? "(anonymous)" : "") + " [" + poll.getPollId() + "] with multi vote for the same userAccount : " +
+ userAccount.getEmail());
+
+ }
+ if (pollAnonymous) {
+ for (Vote vote : votesForUser) {
+ accountToAnonymous.put(poll, vote.getPollAccount());
+ }
+ } else {
+ voteToFixByPoll.putAll(poll, votesForUser);
+ }
+ }
+ }
+ }
+ }
+
+ // treat anonymous vote
+ Set<Poll> anonymousPollToFix = accountToAnonymous.keySet();
+
+ if (CollectionUtils.isNotEmpty(anonymousPollToFix)) {
+ if (log.isWarnEnabled()) {
+ log.warn("There is " + anonymousPollToFix.size() + " anonymous " +
+ "poll to fix, will remove the userAccount from " +
+ "anonymous votes");
+ }
+ String request = "UPDATE pollaccount set useraccount IS NULL WHERE topiaid='%s';";
+ for (PollAccount account : accountToAnonymous.values()) {
+ queries.add(String.format(request, account.getTopiaId()));
+ }
+ }
+
+ // treat other votes
+ Set<Poll> pollToFix = voteToFixByPoll.keySet();
+ if (CollectionUtils.isNotEmpty(pollToFix)) {
+ if (log.isWarnEnabled()) {
+ log.warn("There is " + pollToFix.size() + " other polls " +
+ "to fix, will remove the userAccount from any votes");
+ }
+ }
+
+
+ }
+
+ final Function<Vote, UserAccount> voteToUserAccount = new Function<Vote, UserAccount>() {
+ @Override
+ public UserAccount apply(Vote input) {
+ PollAccount pollAccount = input.getPollAccount();
+ return pollAccount == null ? null : pollAccount.getUserAccount();
+ }
+ };
+
+}
\ No newline at end of file
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4_5_2.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: trunk/pollen-services/src/main/resources/META-INF/services/org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG$MigrationCallBackForVersion
===================================================================
--- trunk/pollen-services/src/main/resources/META-INF/services/org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG$MigrationCallBackForVersion 2012-09-05 17:49:33 UTC (rev 3688)
+++ trunk/pollen-services/src/main/resources/META-INF/services/org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG$MigrationCallBackForVersion 2012-09-05 20:09:16 UTC (rev 3689)
@@ -3,4 +3,5 @@
org.chorem.pollen.entities.migration.PollenMigrationCallbackV1_3
org.chorem.pollen.entities.migration.PollenMigrationCallbackV1_3_1
org.chorem.pollen.entities.migration.PollenMigrationCallbackV1_4
-org.chorem.pollen.entities.migration.PollenMigrationCallbackV1_4_5
\ No newline at end of file
+org.chorem.pollen.entities.migration.PollenMigrationCallbackV1_4_5
+org.chorem.pollen.entities.migration.PollenMigrationCallbackV1_4_5_2
\ No newline at end of file
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-09-05 17:49:33 UTC (rev 3688)
+++ trunk/pom.xml 2012-09-05 20:09:16 UTC (rev 3689)
@@ -153,7 +153,7 @@
<projectId>pollen</projectId>
<!-- customized versions -->
- <topiaVersion>2.6.13</topiaVersion>
+ <topiaVersion>2.6.14-SNAPSHOT</topiaVersion>
<eugenePluginVersion>2.5</eugenePluginVersion>
<nuitonI18nVersion>2.5</nuitonI18nVersion>
1
0