01/01: use bean for vote counting result (to encore ids)
This is an automated email from the git hooks/post-receive script. New commit to branch devel in repository Pollen. See http://git.None/Pollen.git commit d85e3bc3e6ab6b2377d1e6d99e6002b7616a4d1f Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue May 27 08:39:57 2014 +0200 use bean for vote counting result (to encore ids) --- .../chorem/pollen/rest/api/v1/VoteCountingApi.java | 12 +-- .../pollen/services/bean/ChoiceScoreBean.java | 95 ++++++++++++++++++++++ .../services/bean/GroupVoteCountingResultBean.java | 46 +++++++++++ .../services/bean/VoteCountingResultBean.java | 71 ++++++++++++++++ .../services/service/VoteCountingService.java | 31 ++++--- 5 files changed, 239 insertions(+), 16 deletions(-) diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingApi.java index a4b83ac..ec19159 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingApi.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingApi.java @@ -24,10 +24,10 @@ package org.chorem.pollen.rest.api.v1; */ import org.chorem.pollen.persistence.entity.Poll; +import org.chorem.pollen.services.bean.GroupVoteCountingResultBean; import org.chorem.pollen.services.bean.PollenEntityId; +import org.chorem.pollen.services.bean.VoteCountingResultBean; import org.chorem.pollen.services.service.VoteCountingService; -import org.chorem.pollen.votecounting.model.GroupVoteCountingResult; -import org.chorem.pollen.votecounting.model.VoteCountingResult; import org.debux.webmotion.server.WebMotionController; /** @@ -38,16 +38,16 @@ import org.debux.webmotion.server.WebMotionController; */ public class VoteCountingApi extends WebMotionController { - public VoteCountingResult getMainResult(VoteCountingService voteCountingService, PollenEntityId<Poll> pollId) { + public VoteCountingResultBean getMainResult(VoteCountingService voteCountingService, PollenEntityId<Poll> pollId) { - VoteCountingResult result = voteCountingService.getMainResult(pollId.getEntityId()); + VoteCountingResultBean result = voteCountingService.getMainResult(pollId.getEntityId()); return result; } - public GroupVoteCountingResult getGroupResult(VoteCountingService voteCountingService, PollenEntityId<Poll> pollId) { + public GroupVoteCountingResultBean getGroupResult(VoteCountingService voteCountingService, PollenEntityId<Poll> pollId) { - GroupVoteCountingResult result = voteCountingService.getGroupResult(pollId.getEntityId()); + GroupVoteCountingResultBean result = voteCountingService.getGroupResult(pollId.getEntityId()); return result; } diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceScoreBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceScoreBean.java new file mode 100644 index 0000000..0f07a0d --- /dev/null +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceScoreBean.java @@ -0,0 +1,95 @@ +package org.chorem.pollen.services.bean; + +/* + * #%L + * Pollen :: Service + * %% + * Copyright (C) 2009 - 2014 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 org.chorem.pollen.persistence.entity.Choice; +import org.chorem.pollen.votecounting.model.ChoiceScore; +import org.chorem.pollen.votecounting.model.VoteCountingResult; + +import java.math.BigDecimal; + +/** + * Created on 5/27/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.0 + */ +public class ChoiceScoreBean { + + /** Id of the choice. */ + protected PollenEntityId<Choice> choiceId; + + /** + * 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)). + */ + protected BigDecimal scoreValue; + + /** Order of this score (0 is winner, 1 is second,...). */ + protected int scoreOrder; + + public ChoiceScoreBean() { + this.choiceId = PollenEntityId.newId(Choice.class); + } + + public void fromResult(ChoiceScore result) { + + setChoiceId(result.getChoiceId()); + setScoreOrder(result.getScoreOrder()); + setScoreValue(result.getScoreValue()); + + } + + public PollenEntityId<Choice> getChoiceId() { + return choiceId; + } + + public void setChoiceId(String choiceId) { + + Preconditions.checkNotNull("choiceId can not be null", choiceId); + this.choiceId.setEntityId(choiceId); + } + + + public void setChoiceId(PollenEntityId<Choice> choiceId) { + Preconditions.checkNotNull("choiceId can not be null", choiceId); + this.choiceId = choiceId; + } + + + public BigDecimal getScoreValue() { + return scoreValue; + } + + public void setScoreValue(BigDecimal scoreValue) { + this.scoreValue = scoreValue; + } + + public int getScoreOrder() { + return scoreOrder; + } + + public void setScoreOrder(int scoreOrder) { + this.scoreOrder = scoreOrder; + } +} diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/GroupVoteCountingResultBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/GroupVoteCountingResultBean.java new file mode 100644 index 0000000..0a91df6 --- /dev/null +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/GroupVoteCountingResultBean.java @@ -0,0 +1,46 @@ +package org.chorem.pollen.services.bean; + +/* + * #%L + * Pollen :: Service + * %% + * Copyright (C) 2009 - 2014 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.GroupVoteCountingResult; + +/** + * //FIXME + * Created on 5/27/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.0 + */ +public class GroupVoteCountingResultBean { + + + public void fromResult(GroupVoteCountingResult result) { + + //FIXME + + } + + public VoteCountingResultBean getMainResult() { + return null; + } + +} diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteCountingResultBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteCountingResultBean.java new file mode 100644 index 0000000..d76b13b --- /dev/null +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteCountingResultBean.java @@ -0,0 +1,71 @@ +package org.chorem.pollen.services.bean; + +/* + * #%L + * Pollen :: Service + * %% + * Copyright (C) 2009 - 2014 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.ChoiceScore; +import org.chorem.pollen.votecounting.model.VoteCountingResult; + +import java.util.LinkedList; +import java.util.List; + +/** + * Created on 5/27/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.0 + */ +public class VoteCountingResultBean { + + /** + * Results for each choice. + * <p/> + * <strong>Note:</strong> Natural order is used to describe choice scores + * (first is winner,...). + */ + protected List<ChoiceScoreBean> scores; + + public VoteCountingResultBean() { + scores = new LinkedList<>(); + } + + public void fromResult(VoteCountingResult result) { + + scores.clear(); + + for (ChoiceScore choiceScore : result.getScores()) { + + ChoiceScoreBean choiceScoreBean = new ChoiceScoreBean(); + choiceScoreBean.fromResult(choiceScore); + scores.add(choiceScoreBean); + + } + + } + + public List<ChoiceScoreBean> getScores() { + return scores; + } + + public void setScores(List<ChoiceScoreBean> scores) { + this.scores = scores; + } +} diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingService.java index cd3a08d..90fb857 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingService.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingService.java @@ -32,6 +32,8 @@ import org.chorem.pollen.persistence.entity.Vote; import org.chorem.pollen.persistence.entity.VoteToChoice; import org.chorem.pollen.persistence.entity.VoterList; import org.chorem.pollen.persistence.entity.VoterListMember; +import org.chorem.pollen.services.bean.GroupVoteCountingResultBean; +import org.chorem.pollen.services.bean.VoteCountingResultBean; import org.chorem.pollen.votecounting.VoteCounting; import org.chorem.pollen.votecounting.VoteCountingFactory; import org.chorem.pollen.votecounting.VoteCountingStrategy; @@ -55,18 +57,18 @@ import java.util.Set; */ public class VoteCountingService extends PollenServiceSupport { - public VoteCountingResult getMainResult(String pollId) { + public VoteCountingResultBean getMainResult(String pollId) { Preconditions.checkNotNull(pollId); Poll poll = getPollService().getPoll0(pollId); - VoteCountingResult mainResult; + VoteCountingResultBean mainResult; if (Polls.isPollGroup(poll)) { - GroupVoteCountingResult groupResult = getGroupResult(pollId); + GroupVoteCountingResultBean groupResult = getGroupResult(pollId); mainResult = groupResult.getMainResult(); } else { @@ -78,7 +80,7 @@ public class VoteCountingService extends PollenServiceSupport { } - public VoteCountingResult getSimpleResult(String pollId) { + public VoteCountingResultBean getSimpleResult(String pollId) { Preconditions.checkNotNull(pollId); @@ -90,14 +92,18 @@ public class VoteCountingService extends PollenServiceSupport { GroupOfVoter groupOfVoter = toSimpleVotersGroup(votes); - GroupVoteCountingResult result = strategy.votecount(groupOfVoter); + GroupVoteCountingResult groupVoteCountingResult = strategy.votecount(groupOfVoter); - VoteCountingResult mainResult = result.getMainResult(); - return mainResult; + VoteCountingResult mainResult = groupVoteCountingResult.getMainResult(); + + VoteCountingResultBean result = new VoteCountingResultBean(); + result.fromResult(mainResult); + + return result; } - public GroupVoteCountingResult getGroupResult(String pollId) { + public GroupVoteCountingResultBean getGroupResult(String pollId) { Preconditions.checkNotNull(pollId); @@ -111,14 +117,19 @@ public class VoteCountingService extends PollenServiceSupport { // Create a groupVoter including of the root voters GroupOfVoter group = toGroupOfVoters(poll, voterLists, votes); - GroupVoteCountingResult result = strategy.votecount(group); + GroupVoteCountingResult groupVoteCountingResult = strategy.votecount(group); + + + GroupVoteCountingResultBean result = new GroupVoteCountingResultBean(); + result.fromResult(groupVoteCountingResult); + return result; } /** - * Collect all vote for all voters of the givne poll. + * Collect all vote for all voters of the given poll. * <p/> * The result (a set of simple voters) are stored in a fictiv group of voter. * <p/> -- To stop receiving notification emails like this one, please contact Chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
Chorem.org scm