Author: tchemit Date: 2012-06-25 19:56:45 +0200 (Mon, 25 Jun 2012) New Revision: 3556 Url: http://chorem.org/repositories/revision/pollen/3556 Log: refs #642 : remove some bi-direction refs #590 : - replace VoteCountingType enum by a simple int (coming from votecounting-api) - usage of votecouting-api (in ui will no more kow anything about votecouting strategies :)) Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollVoteCountingService.java trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/displayVote_CHECKBOX.jsp trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/displayVote_TEXTFIELD.jsp Removed: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/VoteCountingType.java Modified: 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/xmi/pollen.zargo 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/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/entities/migration/PollenMigrationCallbackV1_4.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenNotifierWorker.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.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/PollResultsService.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 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/PollenUIUtils.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/AbstractPollForm.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.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/VoteForPoll.java trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AbstractPollenAuthorization.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/pollForm.jsp 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/img/7terOk.jpg trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeDatePollSIT.java trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateRestrictedTextPollSIT.java trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateTextPollForGroupSIT.java trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/CondorcetMethod.java trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/StandardMethod.java trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/PollDTO.java trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/VoteCountingResultDTO.java trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ImportExportService.java trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ServiceExportImpl.java trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ServiceVoteCountingImpl.java trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/VoteCountingService.java trunk/pom.xml Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfiguration.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfiguration.java 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfiguration.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -29,7 +29,6 @@ import org.apache.commons.logging.LogFactory; import org.chorem.pollen.common.ChoiceType; import org.chorem.pollen.common.PollType; -import org.chorem.pollen.common.VoteCountingType; import org.nuiton.util.ApplicationConfig; import org.nuiton.util.ArgumentsParserException; import org.nuiton.util.FileUtil; @@ -103,9 +102,8 @@ return result; } - public VoteCountingType getDefaultVoteCountingType() { - VoteCountingType result = applicationConfig.getOption( - VoteCountingType.class, + public int getDefaultVoteCountingType() { + int result = applicationConfig.getOptionAsInt( PollenConfigurationOption.DEFAULT_VOTE_COUNTING_TYPE.key); return result; } Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfigurationOption.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfigurationOption.java 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfigurationOption.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -24,7 +24,6 @@ import org.chorem.pollen.common.ChoiceType; import org.chorem.pollen.common.PollType; -import org.chorem.pollen.common.VoteCountingType; import org.hibernate.dialect.H2Dialect; import org.nuiton.util.ApplicationConfig; @@ -90,7 +89,7 @@ DEFAULT_POLL_TYPE("pollen.default.pollType", n_("pollen.configuration.defaultPollType"), PollType.FREE.name(), PollType.class), /** Default vote counting type to use at a new poll creation. */ - DEFAULT_VOTE_COUNTING_TYPE("pollen.default.voteCountingType", n_("pollen.configuration.defaultVoteCountingType"), VoteCountingType.NORMAL.name(), VoteCountingType.class), + DEFAULT_VOTE_COUNTING_TYPE("pollen.default.voteCountingType", n_("pollen.configuration.defaultVoteCountingType"), "0", Integer.class), /** Default choice type to use at a new poll creation. */ DEFAULT_CHOICE_TYPE("pollen.default.choiceType", n_("pollen.configuration.defaultChoiceType"), ChoiceType.TEXT.name(), ChoiceType.class), Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenFunctions.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenFunctions.java 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/PollenFunctions.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -99,7 +99,7 @@ if (!input.isVotingListEmpty()) { result.setVotingGroups(Lists.transform(input.getVotingList(), - VOTING_LIST_TO_BEAN + newVotingListToBean(input) )); } else { // un groupe par défaut si il y en a pas @@ -136,27 +136,50 @@ } }; - public static final Function<VotingList, VotingGroupDTO> VOTING_LIST_TO_BEAN = new Function<VotingList, VotingGroupDTO>() { - @Override - public VotingGroupDTO apply(VotingList input) { - VotingGroupDTO result = new VotingGroupDTO( - input.getTopiaId(), - input.getWeight()); + 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()); + result.setName(input.getName()); - for (PersonToList pToList : input.getPollAccountPersonToList()) { - Vote vote = input.getPoll().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); + 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; } - return result; - } - }; + }; + } +// public static final Function<VotingList, VotingGroupDTO> VOTING_LIST_TO_BEAN = 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 = input.getPoll().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<Vote, VotingPersonDTO> VOTE_TO_BEAN = new Function<Vote, VotingPersonDTO>() { @Override public VotingPersonDTO apply(Vote input) { Modified: trunk/pollen-persistence/src/main/xmi/pollen.zargo =================================================================== (Binary files differ) Modified: trunk/pollen-services/pom.xml =================================================================== --- trunk/pollen-services/pom.xml 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-services/pom.xml 2012-06-25 17:56:45 UTC (rev 3556) @@ -19,6 +19,11 @@ <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> Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/PollenApplicationContext.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/PollenApplicationContext.java 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/PollenApplicationContext.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -24,6 +24,7 @@ import com.opensymphony.xwork2.ActionContext; import org.chorem.pollen.services.PollenNotifierWorker; +import org.chorem.pollen.votecounting.VoteCountingStrategyProvider; import org.nuiton.topia.TopiaContext; import javax.servlet.ServletContext; @@ -45,6 +46,8 @@ protected PollenNotifierWorker pollenNotifierWorker; + protected VoteCountingStrategyProvider voteCountingStrategyProvider; + public static PollenApplicationContext get(ActionContext actionContext) { Map<String, Object> application = actionContext.getApplication(); PollenApplicationContext applicationContext = @@ -98,4 +101,12 @@ public void setPollenNotifierWorker(PollenNotifierWorker pollenNotifierWorker) { this.pollenNotifierWorker = pollenNotifierWorker; } + + public VoteCountingStrategyProvider getVoteCountingStrategyProvider() { + return voteCountingStrategyProvider; + } + + public void setVoteCountingStrategyProvider(VoteCountingStrategyProvider voteCountingStrategyProvider) { + this.voteCountingStrategyProvider = voteCountingStrategyProvider; + } } 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-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/bean/PollResult.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -24,7 +24,6 @@ import org.apache.commons.lang3.builder.ToStringBuilder; import org.chorem.pollen.common.ChoiceType; -import org.chorem.pollen.common.VoteCountingType; import java.io.Serializable; @@ -47,7 +46,7 @@ private ChoiceType choiceType; - private VoteCountingType voteCountingType; + private int voteCountingType; private boolean byGroup; @@ -64,7 +63,7 @@ public PollResult(String name, String pollId, ChoiceType choiceType, - VoteCountingType voteCountingType) { + int voteCountingType) { super(); this.name = name; this.pollId = pollId; @@ -112,11 +111,11 @@ this.choiceType = choiceType; } - public VoteCountingType getVoteCountingType() { + public int getVoteCountingType() { return voteCountingType; } - public void setVoteCountingType(VoteCountingType voteCountingType) { + public void setVoteCountingType(int voteCountingType) { this.voteCountingType = voteCountingType; } 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-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_3.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -28,7 +28,6 @@ import org.chorem.pollen.PollenTechnicalException; import org.chorem.pollen.common.ChoiceType; import org.chorem.pollen.common.PollType; -import org.chorem.pollen.common.VoteCountingType; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaContextImplementor; import org.nuiton.topia.framework.TopiaSQLQuery; @@ -192,9 +191,17 @@ queries.add("DROP TABLE polltype;"); } + enum VoteCountingType { + NORMAL, + PERCENTAGE, + CONDORCET, + NUMBER + } + private void migrateVoteCountingTypes(TopiaContextImplementor tx, List<String> queries) throws TopiaException { + // build the new mapping between old id associated to new enum ordinal Map<String, Integer> mapping = getMapping(tx, "votecounting", VoteCountingType.values()); 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-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_4.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -139,7 +139,8 @@ Locale.getDefault(), tx, configuration, - serviceFactory + serviceFactory, + applicationContext.getVoteCountingStrategyProvider() ); List<Pair<String, String>> choiceIds = @@ -213,7 +214,8 @@ Locale.getDefault(), tx, configuration, - serviceFactory + serviceFactory, + applicationContext.getVoteCountingStrategyProvider() ); PollFeedService feedService = sContext.newService(PollFeedService.class); 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-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -24,6 +24,7 @@ import com.google.common.base.Preconditions; import org.chorem.pollen.PollenConfiguration; +import org.chorem.pollen.votecounting.VoteCountingStrategyProvider; import org.nuiton.topia.TopiaContext; import java.net.URL; @@ -46,13 +47,16 @@ protected Locale locale; + protected VoteCountingStrategyProvider voteCountingStrategyProvider; + public static PollenServiceContext newContext( PollenServiceContext serviceContext, TopiaContext transaction) { return newContext(serviceContext.getLocale(), transaction, serviceContext.getConfiguration(), - serviceContext.getServiceFactory() + serviceContext.getServiceFactory(), + serviceContext.getVoteCountingStrategyProvider() ); } @@ -61,21 +65,26 @@ Locale locale, TopiaContext transaction, PollenConfiguration configuration, - PollenServiceFactory serviceFactory) { + PollenServiceFactory serviceFactory, + VoteCountingStrategyProvider voteCountingStrategyProvider) { return new DefaultPollenServiceContext(locale, transaction, configuration, - serviceFactory); + serviceFactory, + voteCountingStrategyProvider); } - protected DefaultPollenServiceContext(Locale locale, - TopiaContext transaction, - PollenConfiguration configuration, - PollenServiceFactory serviceFactory) { + protected DefaultPollenServiceContext( + Locale locale, + TopiaContext transaction, + PollenConfiguration configuration, + PollenServiceFactory serviceFactory, + VoteCountingStrategyProvider voteCountingStrategyProvider) { this.locale = locale; this.transaction = transaction; this.configuration = configuration; this.serviceFactory = serviceFactory; + this.voteCountingStrategyProvider = voteCountingStrategyProvider; } @Override @@ -123,4 +132,9 @@ public Date getCurrentTime() { return new Date(); } + + @Override + public VoteCountingStrategyProvider getVoteCountingStrategyProvider() { + return voteCountingStrategyProvider; + } } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenNotifierWorker.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenNotifierWorker.java 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenNotifierWorker.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -33,6 +33,7 @@ import java.io.Closeable; import java.io.IOException; +import java.util.Date; import java.util.List; import java.util.Timer; import java.util.TimerTask; @@ -84,7 +85,9 @@ serviceContext.newService(PreventRuleService.class); // Récupération des sondages en cours - List<Poll> polls = pollService.getRunningPolls(true); + Date currentTime = serviceContext.getCurrentTime(); + List<Poll> polls = + pollService.getRunningPolls(currentTime); for (Poll poll : polls) { 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-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -24,6 +24,7 @@ package org.chorem.pollen.services; import org.chorem.pollen.PollenConfiguration; +import org.chorem.pollen.votecounting.VoteCountingStrategyProvider; import org.nuiton.topia.TopiaContext; import java.net.URL; @@ -59,4 +60,6 @@ /** @return the current date */ Date getCurrentTime(); + VoteCountingStrategyProvider getVoteCountingStrategyProvider(); + } 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-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceFunctions.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -35,14 +35,19 @@ 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. @@ -73,6 +78,28 @@ } } + 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 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) { 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-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/FavoriteService.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -50,6 +50,7 @@ TopiaFilterPagerUtil.FilterPagerBean pager) { Preconditions.checkNotNull(user); + Preconditions.checkNotNull(pager); try { PersonListDAO dao = getDAO(PersonList.class); 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-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -37,7 +37,6 @@ import org.chorem.pollen.business.persistence.ResultDAO; import org.chorem.pollen.common.ChoiceType; import org.chorem.pollen.common.PollType; -import org.chorem.pollen.common.VoteCountingType; import org.chorem.pollen.services.PollenServiceFunctions; import org.chorem.pollen.services.PollenServiceSupport; import org.chorem.pollen.services.exceptions.PollNotFoundException; @@ -103,7 +102,7 @@ boolean byGroup = poll.getPollType() == PollType.GROUP; - VoteCountingType voteCountingType = poll.getVoteCountingType(); + int voteCountingType = poll.getVoteCountingType(); // Conversion des résultats List<PollResult> list = Lists.transform( @@ -116,12 +115,6 @@ while (it.hasNext()) { PollResult currentResult = it.next(); - // Cas d'un dépouillement particulier - // Suppression des resultats qui ne sont pas de se dépouillement - if (currentResult.getVoteCountingType() != voteCountingType) { - it.remove(); - } - // Cas d'un sondage de type GROUP avec filtre if (byGroup) { @@ -129,11 +122,6 @@ if (!currentResult.isByGroup()) { it.remove(); } - - // Suppression des autres resultats de depouillements differents - if (currentResult.getVoteCountingType() != voteCountingType) { - it.remove(); - } } } @@ -179,7 +167,7 @@ eResult.setByGroup(result.isByGroup()); // eResult.setPoll(poll); eResult.setResultValue(String.valueOf(choice.getValue())); - eResult.setVoteCountingType(result.getTypeVoteCounting()); + eResult.setVoteCountingType(poll.getVoteCountingType()); poll.addResult(eResult); } 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-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -384,11 +384,11 @@ } } - public List<Poll> getRunningPolls(boolean withEndDate) { + public List<Poll> getRunningPolls(Date currentTime) { try { PollDAO dao = getDAO(Poll.class); - List<Poll> results = dao.getRunningPolls(withEndDate); + List<Poll> results = dao.getRunningPolls(currentTime); return results; } catch (TopiaException e) { throw new PollenTechnicalException("Could not obtain running polls", e); @@ -955,7 +955,7 @@ PollAccount pollAccount2 = newInstance(getDAO(PollAccount.class)); result.setPollAccount(pollAccount2); if (pollAccount != null) { - pollAccount2.setComment(pollAccount.getComment()); +// pollAccount2.setComment(pollAccount.getComment()); pollAccount2.setEmail(pollAccount.getEmail()); pollAccount2.setUserAccount(pollAccount.getUserAccount()); pollAccount2.setVotingId(pollAccount.getVotingId()); @@ -979,9 +979,6 @@ } else { result = poll.getVotingListByTopiaId(votingList.getTopiaId()); - - // FIXME-fdesbois-2012-04-05 : why the poll association is not keeped ?!? because of the clear - result.setPoll(poll); } result.setName(votingList.getName()); @@ -1017,11 +1014,13 @@ } else { // reuse the existing account - pollAccountLoaded = pollAccountDAO.findByAccountId(accountId); + pollAccountLoaded = + pollAccountDAO.findByAccountId(accountId); } } else { - personToListLoaded = getEntityById(PersonToList.class, personToList.getTopiaId()); + personToListLoaded = getEntityById(PersonToList.class, + personToList.getTopiaId()); pollAccountLoaded = personToListLoaded.getPollAccount(); } personToListsUpdated.add(personToListLoaded); @@ -1041,7 +1040,8 @@ // Update the account (otherwise a saving error will occurs if // already exists on delete cascade) - PollAccount pollAccountUpdated = update(pollAccountDAO, pollAccountLoaded); + PollAccount pollAccountUpdated = update(pollAccountDAO, + pollAccountLoaded); personToListLoaded.setPollAccount(pollAccountUpdated); } result.setPollAccountPersonToList(personToListsUpdated); @@ -1052,7 +1052,8 @@ PreventRuleDAO preventRuleDAO = getDAO(PreventRule.class); // For the moment only one rule by scope - PreventRule preventRuleLoaded = poll.getPreventRuleByScope(preventRule.getScope()); + PreventRule preventRuleLoaded = poll.getPreventRuleByScope( + preventRule.getScope()); if (preventRuleLoaded == null) { preventRuleLoaded = create(preventRuleDAO); Added: 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 (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollVoteCountingService.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -0,0 +1,52 @@ +/* + * #%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% + */ +package org.chorem.pollen.services.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.services.PollenServiceSupport; +import org.chorem.pollen.votecounting.VoteCountingService; + +/** + * New Poll vote counting service. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.5 + */ +public class PollVoteCountingService extends PollenServiceSupport { + + /** log. */ + private static final Log log = + LogFactory.getLog(PollVoteCountingService.class); + + protected VoteCountingService delegateService; + + public VoteCountingService getDelegateService() { + if (delegateService == null) { + delegateService = new VoteCountingService(); + delegateService.setProvider( + serviceContext.getVoteCountingStrategyProvider()); + } + return delegateService; + } +} Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollVoteCountingService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native 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-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-services/src/test/java/org/chorem/pollen/services/FakeServiceContext.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -28,6 +28,7 @@ import org.chorem.pollen.PollenConfiguration; import org.chorem.pollen.PollenIOUtil; import org.chorem.pollen.PollenTopiaRootContextFactory; +import org.chorem.pollen.votecounting.VoteCountingStrategyProvider; import org.junit.rules.TestWatcher; import org.junit.runner.Description; import org.nuiton.topia.TopiaContext; @@ -127,6 +128,11 @@ return fakeCurrentTime; } + @Override + public VoteCountingStrategyProvider getVoteCountingStrategyProvider() { + return null; + } + public void setCurrentTime(Date fakeCurrentTime) { this.fakeCurrentTime = fakeCurrentTime; } Modified: trunk/pollen-ui-struts2/pom.xml =================================================================== --- trunk/pollen-ui-struts2/pom.xml 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-ui-struts2/pom.xml 2012-06-25 17:56:45 UTC (rev 3556) @@ -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> @@ -19,6 +21,35 @@ <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-condorcet</artifactId> + <version>${project.version}</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>pollen-votecounting-strategy-normal</artifactId> + <version>${project.version}</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>pollen-votecounting-strategy-number</artifactId> + <version>${project.version}</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>pollen-votecounting-strategy-percentage</artifactId> + <version>${project.version}</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> <artifactId>pollen-votecounting</artifactId> <version>${project.version}</version> </dependency> @@ -249,7 +280,8 @@ <deployFiles>target/${project.build.finalName}.war</deployFiles> <defaultWebContextPath>pollen</defaultWebContextPath> - <defaultSiteUrl>http://localhost:8080/${defaultWebContextPath}</defaultSiteUrl> + <defaultSiteUrl>http://localhost:8080/${defaultWebContextPath} + </defaultSiteUrl> <defaultLogDir>${basedir}/target</defaultLogDir> </properties> @@ -370,7 +402,8 @@ <phase>generate-resources</phase> <configuration> <target> - <mkdir dir="${basedir}/target/pollen-embedded-temp-${project.version}/WEB-INF/classes" /> + <mkdir + dir="${basedir}/target/pollen-embedded-temp-${project.version}/WEB-INF/classes"/> </target> </configuration> <goals> @@ -553,7 +586,9 @@ </activation--> <properties> <pollenTestServerPort>8765</pollenTestServerPort> - <pollenTestUrl>http://localhost:${pollenTestServerPort}/${defaultWebContextPath}</pollenTestUrl> + <pollenTestUrl> + http://localhost:${pollenTestServerPort}/${defaultWebContextPath} + </pollenTestUrl> </properties> <build> @@ -573,7 +608,8 @@ <configuration> <daemon>true</daemon> <webAppConfig> - <descriptor>${basedir}/src/test/resources/web-test.xml</descriptor> + <descriptor>${basedir}/src/test/resources/web-test.xml + </descriptor> <contextPath>/${defaultWebContextPath}</contextPath> </webAppConfig> @@ -630,7 +666,9 @@ <id>selenium-server</id> <properties> <pollenTestServerPort>8765</pollenTestServerPort> - <pollenTestUrl>http://localhost:${pollenTestServerPort}/${defaultWebContextPath}</pollenTestUrl> + <pollenTestUrl> + http://localhost:${pollenTestServerPort}/${defaultWebContextPath} + </pollenTestUrl> <maven.test.skip>true</maven.test.skip> </properties> @@ -651,7 +689,8 @@ <configuration> <daemon>false</daemon> <webAppConfig> - <descriptor>${basedir}/src/test/resources/web-test.xml</descriptor> + <descriptor>${basedir}/src/test/resources/web-test.xml + </descriptor> <contextPath>/${defaultWebContextPath}</contextPath> </webAppConfig> 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-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -37,6 +37,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.VoteCountingStrategyProvider; import org.nuiton.i18n.I18n; import org.nuiton.i18n.init.DefaultI18nInitializer; import org.nuiton.topia.TopiaContext; @@ -96,9 +97,10 @@ PollenConfiguration configuration = prepareConfiguration(); if (log.isInfoEnabled()) { - log.info("Base url "+configuration.getApplicationUrl()); + log.info("Base url " + configuration.getApplicationUrl()); } applicationContext.setConfiguration(configuration); + applicationContext.setVoteCountingStrategyProvider(new VoteCountingStrategyProvider()); File temporaryDirectory = configuration.getTemporaryDirectory(); try { @@ -123,11 +125,11 @@ // init db try { - TopiaContext rootContext - = new PollenTopiaRootContextFactory().newDatabaseFromConfig(configuration); + PollenTopiaRootContextFactory f = + new PollenTopiaRootContextFactory(); + TopiaContext rootContext = f.newDatabaseFromConfig(configuration); applicationContext.setRootContext(rootContext); - initDB(applicationContext); } catch (TopiaException e) { @@ -159,8 +161,6 @@ // close topia root context to pollen db closeRootcontext(applicationContext.getRootContext()); - - } } @@ -171,7 +171,6 @@ * override configuration for tests environnements. * * @return the instanciated configuration - * @see PollenTestApplicationListener * @since 1.4 */ protected PollenConfiguration prepareConfiguration() { @@ -184,7 +183,8 @@ Locale.getDefault(), null, applicationContext.getConfiguration(), - new PollenServiceFactory() + new PollenServiceFactory(), + applicationContext.getVoteCountingStrategyProvider() ); PollenNotifierWorker pollenNotifierWorker = new PollenNotifierWorker( serviceContext, @@ -258,7 +258,8 @@ Locale.getDefault(), transaction, configuration, - serviceFactory + serviceFactory, + applicationContext.getVoteCountingStrategyProvider() ); UserService service = Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenUIUtils.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenUIUtils.java 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenUIUtils.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -22,11 +22,15 @@ */ package org.chorem.pollen.ui; +import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.services.impl.SecurityService; import javax.servlet.ServletContext; import javax.servlet.ServletRequest; +import java.util.Locale; +import static org.nuiton.i18n.I18n.l_; + /** * Useful ui methods. * @@ -59,6 +63,20 @@ return result; } + public static String getVoteSizeMessage(Poll poll, Locale locale) { + + int i = poll.sizeVote(); + String result; + if (i == 0) { + result = l_(locale, "pollen.common.voteNoVote"); + } else if (i == 1) { + result = l_(locale, "pollen.common.voteOneVote"); + } else { + result = l_(locale, "pollen.common.voteNbVotes", i); + } + return result; + } + protected PollenUIUtils() { // helper can not be instanciated } 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-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -27,9 +27,10 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.struts2.ServletActionContext; import org.apache.struts2.StrutsStatics; +import org.chorem.pollen.PollenApplicationContext; import org.chorem.pollen.PollenConfiguration; +import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.UserAccount; -import org.chorem.pollen.common.VoteCountingType; import org.chorem.pollen.services.DefaultPollenServiceContext; import org.chorem.pollen.services.PollenService; import org.chorem.pollen.services.PollenServiceContext; @@ -44,8 +45,9 @@ import org.chorem.pollen.services.impl.SecurityService; import org.chorem.pollen.services.impl.UserService; import org.chorem.pollen.services.impl.VoteService; -import org.chorem.pollen.PollenApplicationContext; import org.chorem.pollen.ui.PollenSession; +import org.chorem.pollen.votecounting.VoteCountingStrategy; +import org.chorem.pollen.votecounting.VoteCountingStrategyProvider; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.framework.TopiaTransactionAware; import org.nuiton.web.filter.TopiaTransactionFilter; @@ -171,7 +173,8 @@ getLocale(), getTransaction(), getConfiguration(), - getServiceFactory() + getServiceFactory(), + getVoteCountingStrategyProvider() ); } return serviceContext; @@ -184,6 +187,17 @@ return serviceFactory; } + public VoteCountingStrategyProvider getVoteCountingStrategyProvider() { + return getPollenApplicationContext().getVoteCountingStrategyProvider(); + } + + protected VoteCountingStrategy getVoteCountingStrategy(Poll poll) { + int voteCountingType = poll.getVoteCountingType(); + VoteCountingStrategy result = + getVoteCountingStrategyProvider().getStrategy(voteCountingType); + return result; + } + /** * Sub-classes should use this method to easily get a service instance. * @@ -230,30 +244,6 @@ return new Date(); } - public String getVoteCountingTypeHelp(VoteCountingType voteCountingType) { - String result; - switch (voteCountingType) { - - default: - case NORMAL: - result = - _("pollen.common.voteCountingTypeHelp.normal"); - break; - case PERCENTAGE: - result = - _("pollen.common.voteCountingTypeHelp.percentage"); - break; - case CONDORCET: - result = - _("pollen.common.voteCountingTypeHelp.condorcet"); - break; - case NUMBER: - result = - _("pollen.common.voteCountingTypeHelp.number"); - } - return result; - } - public String getCurrentUrl() { HttpServletRequest request = ServletActionContext.getRequest(); String result = request.getRequestURL().toString(); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -58,7 +58,6 @@ import org.chorem.pollen.common.ChoiceType; import org.chorem.pollen.common.I18nAble; import org.chorem.pollen.common.PollType; -import org.chorem.pollen.common.VoteCountingType; import org.chorem.pollen.services.PollenServiceFunctions; import org.chorem.pollen.services.exceptions.PollNotFoundException; import org.chorem.pollen.services.impl.PollService; @@ -67,6 +66,8 @@ import org.chorem.pollen.ui.actions.PageSkin; import org.chorem.pollen.ui.actions.PollenActionSupport; import org.chorem.pollen.ui.converters.DateConverter; +import org.chorem.pollen.votecounting.VoteCountingStrategy; +import org.chorem.pollen.votecounting.VoteCountingStrategyProvider; import org.nuiton.util.StringUtil; import javax.servlet.http.HttpServletRequest; @@ -725,14 +726,38 @@ } } + public String getVoteCountingHelp() { + + StringBuilder builder = new StringBuilder(); + VoteCountingStrategyProvider strategyProvider = + getVoteCountingStrategyProvider(); + Set<Integer> strategyIds = strategyProvider.getStrategyIds(); + for (Integer strategyId : strategyIds) { + VoteCountingStrategy strategy = strategyProvider.getStrategy(strategyId); + String strategyHelp = strategy.getStrategyHelp(getLocale()); + builder.append(strategyHelp).append("<br/><br/>"); + } + return builder.toString(); + } + public void prepareFormPage() throws Exception { getPollenSession().removeDynamicDataWithPrefix(IMAGECHOICES_THUMB_PREFIX); pollTypes = decorateToName(PollType.values()); choiceTypes = decorateToName(ChoiceType.values()); - voteCountingTypes = decorateToName(VoteCountingType.values()); + voteCountingTypes = Maps.newTreeMap(); + VoteCountingStrategyProvider strategyProvider = + getVoteCountingStrategyProvider(); + Set<Integer> strategyIds = strategyProvider.getStrategyIds(); + for (Integer strategyId : strategyIds) { + VoteCountingStrategy strategy = strategyProvider.getStrategy(strategyId); + String strategyHelp = strategy.getStrategyName(getLocale()); + voteCountingTypes.put(strategyId + "", strategyHelp); + } +// decorateToName(VoteCountingType.values()); + textChoices = Lists.newArrayList(); imageChoices = Lists.newArrayList(); dateChoices = Lists.newArrayList(); Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -42,12 +42,12 @@ import org.chorem.pollen.business.persistence.VoteToChoice; import org.chorem.pollen.common.ChoiceType; import org.chorem.pollen.common.PollType; -import org.chorem.pollen.common.VoteCountingType; import org.chorem.pollen.services.exceptions.PollAccountNotFound; import org.chorem.pollen.services.exceptions.PollNotFoundException; import org.chorem.pollen.services.impl.SecurityService; import org.chorem.pollen.ui.PollenUIUtils; import org.chorem.pollen.ui.actions.PageSkin; +import org.chorem.pollen.votecounting.VoteCountingStrategy; import javax.servlet.http.HttpServletRequest; import java.io.UnsupportedEncodingException; @@ -220,19 +220,68 @@ } public String getVoteSizeMessage() { - int i = getPoll().sizeVote(); + String result = PollenUIUtils.getVoteSizeMessage(getPoll(), + getLocale()); + return result; + } - String result; - if (i==0) { - result = _("pollen.common.voteNoVote"); - } else if (i==1) { - result = _("pollen.common.voteOneVote"); - }else { - result = _("pollen.common.voteNbVotes", i); - } + public String getVoteCountingTypeName() { + VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll()); + String result = strategy.getStrategyName(getLocale()); return result; } + public String getVoteCountingTypeHelp() { + VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll()); + String result = strategy.getStrategyHelp(getLocale()); + return result; + } + + /** + * Retourne si le choix fait partie du vote (s'il a été renseigné par le + * votant). + * + * @param choice le choix concerné + * @return true si le choix est dans le vote + */ + public boolean isChoiceInVote(VoteToChoice choice) { + VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll()); + boolean result = strategy.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()); + return result; +// switch (poll.getVoteCountingType()) { +// case NORMAL: +// result = "OK"; +// break; +// default: +// result = choice.getVoteValue() + ""; +// } +// return result; + } + public String getCommentAuthor() { if (commentAuthor == null) { @@ -332,22 +381,22 @@ return poll.getChoiceType() == ChoiceType.IMAGE; } - public boolean isNormalVoteCounting() { - return poll.getVoteCountingType() == VoteCountingType.NORMAL; - } +// public boolean isNormalVoteCounting() { +// return poll.getVoteCountingType() == VoteCountingType.NORMAL; +// } +// +// public boolean isPercentageVoteCounting() { +// return poll.getVoteCountingType() == VoteCountingType.PERCENTAGE; +// } +// +// public boolean isCondorcetVoteCounting() { +// return poll.getVoteCountingType() == VoteCountingType.CONDORCET; +// } +// +// public boolean isNumberVoteCounting() { +// return poll.getVoteCountingType() == VoteCountingType.NUMBER; +// } - public boolean isPercentageVoteCounting() { - return poll.getVoteCountingType() == VoteCountingType.PERCENTAGE; - } - - public boolean isCondorcetVoteCounting() { - return poll.getVoteCountingType() == VoteCountingType.CONDORCET; - } - - public boolean isNumberVoteCounting() { - return poll.getVoteCountingType() == VoteCountingType.NUMBER; - } - public boolean isVoteAllowed() { return voteAllowed; } @@ -387,30 +436,10 @@ return val; } - /** - * Retourne si le choix fait partie du vote (s'il a été renseigné par le - * votant). - * - * @param choice le choix concerné - * @return true si le choix est dans le vote - */ - public boolean isChoiceInVote(VoteToChoice choice) { - boolean result = false; - if (choice != null) { - switch (poll.getVoteCountingType()) { - case NORMAL: - result = choice.getVoteValue() > 0; - break; - case PERCENTAGE: - result = true; - break; - case CONDORCET: - result = choice.getVoteValue() < 100; - break; - case NUMBER: - result = choice.getVoteValue() >= 0; - } - } + public String getChoiceFragment() { + VoteCountingStrategy strategy = getVoteCountingStrategy(poll); + String result = + "displayVote_" + strategy.getRenderType().name() + ".jsp"; return result; } 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-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -39,10 +39,11 @@ import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.common.ChoiceType; import org.chorem.pollen.common.PollType; -import org.chorem.pollen.common.VoteCountingType; import org.chorem.pollen.services.impl.PollResultsService; +import org.chorem.pollen.ui.PollenUIUtils; import org.chorem.pollen.ui.actions.PageSkin; import org.chorem.pollen.ui.converters.DateConverter; +import org.chorem.pollen.votecounting.VoteCountingStrategy; import org.nuiton.util.StringUtil; import java.net.URL; @@ -147,12 +148,34 @@ return feedFileExisting; } + public String getVoteCountingTypeName() { + VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll()); + String result = strategy.getStrategyName(getLocale()); + return result; + } + + public String getVoteCountingTypeHelp() { + VoteCountingStrategy strategy = getVoteCountingStrategy(getPoll()); + String result = strategy.getStrategyHelp(getLocale()); + return result; + } + public String getSummaryUrl() { PollUrl url = getPollUrlService().getPollSummaryUrl(poll); url.getPollUri().setAccountId(getAccountId()); return url.getUrl(); } + public String getResultUrl(boolean byGroup) { + PollUrl url = getPollUrlService().getPollResultUrl(poll); + url.getPollUri().setAccountId(getAccountId()); + String result = url.getUrl(); + if (!byGroup) { + result += "?byGroup=false"; + } + return result; + } + public String getVoteUrl() { PollUrl url = getPollUrlService().getPollVoteUrl(poll); url.getPollUri().setAccountId(getAccountId()); @@ -183,16 +206,8 @@ } public String getVoteSizeMessage() { - int i = getPoll().sizeVote(); - - String result; - if (i==0) { - result = _("pollen.common.voteNoVote"); - } else if (i==1) { - result = _("pollen.common.voteOneVote"); - }else { - result = _("pollen.common.voteNbVotes", i); - } + String result = PollenUIUtils.getVoteSizeMessage(getPoll(), + getLocale()); return result; } @@ -200,7 +215,11 @@ String victoryMessage; - if (poll.getVoteCountingType() == VoteCountingType.NUMBER) { + 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)) { victoryMessage = ""; @@ -267,7 +286,8 @@ } } - if (isNumberVoteCounting()) { + VoteCountingStrategy strategy = getVoteCountingStrategy(poll); + if (strategy.isDisplayResultsByChoice()) { // resultats des choix cachés choicesResults = LinkedHashMultimap.create(); @@ -318,22 +338,23 @@ return poll.getChoiceType() == ChoiceType.IMAGE; } - public boolean isNormalVoteCounting() { - return poll.getVoteCountingType() == VoteCountingType.NORMAL; - } + // public boolean isNormalVoteCounting() { +// return poll.getVoteCountingType() == VoteCountingType.NORMAL; +// } +// +// public boolean isPercentageVoteCounting() { +// return poll.getVoteCountingType() == VoteCountingType.PERCENTAGE; +// } +// +// public boolean isCondorcetVoteCounting() { +// return poll.getVoteCountingType() == VoteCountingType.CONDORCET; +// } +// + //FIXME-tchemit-2012-06-24, why doing this ??? Should remove this... +// public boolean isNumberVoteCounting() { +// return poll.getVoteCountingType() == 3; +// } - public boolean isPercentageVoteCounting() { - return poll.getVoteCountingType() == VoteCountingType.PERCENTAGE; - } - - public boolean isCondorcetVoteCounting() { - return poll.getVoteCountingType() == VoteCountingType.CONDORCET; - } - - public boolean isNumberVoteCounting() { - return poll.getVoteCountingType() == VoteCountingType.NUMBER; - } - public boolean isByGroup() { return byGroup; } Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -34,6 +34,7 @@ import org.chorem.pollen.business.persistence.VoteToChoice; import org.chorem.pollen.common.PollType; import org.chorem.pollen.services.impl.VoteService; +import org.chorem.pollen.votecounting.VoteCountingStrategy; /** * Votes to a poll. @@ -100,45 +101,82 @@ int nbVotes = 0; int totalValues = 0; + + VoteCountingStrategy voteCountingStrategy = + getVoteCountingStrategy(getPoll()); + + boolean voteValid = true; for (VoteToChoice voteToChoice : vote.getChoiceVoteToChoice()) { Integer value = voteToChoice.getVoteValue(); - if (value == null) { - // not vote + + // check if vote is null ? + boolean voteNull = voteCountingStrategy.isVoteValueNull(value); + + if (voteNull) { + // null vote, can skip his validation continue; } - // XXX-fdesbois-2012-04-11 : for a VoteCountingType#NUMBER the difference between 0 and null value could be important - if (isCondorcetVoteCounting()) { - if (value > 0) { - // for condorcet vote, must be strictly greater than 0 - // see http://chorem.org/issues/574 - // see http://chorem.org/issues/576 - nbVotes++; - totalValues += value; - } else { + // check if vote value is valid ? + boolean valid = voteCountingStrategy.isVoteValueValid(value); - addFieldError("vote.choices", - _("pollen.error.vote.invalidCondorcetVoteValue")); - } - // for other vote type, value must be > 0 - } else if (value != 0) { + if (valid) { + + // ok this vote value is valid, use it nbVotes++; totalValues += value; + } else { + + // not a valid vote value, mark it and skip other fields validation + String validMessage = + voteCountingStrategy.getVoteValueNotValidMessage(); + addFieldError("vote.choices", _(validMessage)); + voteValid = false; + break; } - } - // check that the number of choices is not greater than maxChoiceNb - int maxChoice = getPoll().getMaxChoiceNb(); - if (maxChoice != 0 && nbVotes > maxChoice) { - addFieldError("vote.choices", - _("pollen.error.vote.maxChoiceNb", maxChoice)); +// // XXX-fdesbois-2012-04-11 : for a VoteCountingType#NUMBER the difference between 0 and null value could be important +// if (isCondorcetVoteCounting()) { +// if (value > 0) { +// +// // for condorcet vote, must be strictly greater than 0 +// // see http://chorem.org/issues/574 +// // see http://chorem.org/issues/576 +// nbVotes++; +// totalValues += value; +// } else { +// +// addFieldError("vote.choices", +// _("pollen.error.vote.invalidCondorcetVoteValue")); +// } +// // for other vote type, value must be > 0 +// } else if (value != 0) { +// nbVotes++; +// totalValues += value; +// } } + if (voteValid) { - // check for percentage that the sum of all values equals 100 - if (isPercentageVoteCounting() && totalValues != 100) { - addFieldError("vote.choices", _("pollen.error.vote.percentage")); + // check that the number of choices is not greater than maxChoiceNb + int maxChoice = getPoll().getMaxChoiceNb(); + if (maxChoice != 0 && nbVotes > maxChoice) { + addFieldError("vote.choices", + _("pollen.error.vote.maxChoiceNb", maxChoice)); + } + + // check that total vote value is ok + if (!voteCountingStrategy.isTotalVoteValueValid(totalValues)) { + + // not valid + String errorMessage = voteCountingStrategy.getTotalVoteValueNotValidMessage(); + addFieldError("vote.choices", _(errorMessage)); + } } +// // check for percentage that the sum of all values equals 100 +// if (isPercentageVoteCounting() && totalValues != 100) { +// addFieldError("vote.choices", _("pollen.error.vote.percentage")); +// } } // @InputConfig(methodName = PREPARE_VOTE_PAGE) 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-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/security/AbstractPollenAuthorization.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -146,10 +146,8 @@ } if (log.isDebugEnabled()) { - log.debug("Can access to this poll " + - pollUri.getPollId()); + log.debug("Can access to this poll " + pollUri.getPollId()); } - } } @@ -177,7 +175,8 @@ locale, transaction, applicationContext.getConfiguration(), - serviceFactory + serviceFactory, + applicationContext.getVoteCountingStrategyProvider() ); } 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-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-06-25 17:56:45 UTC (rev 3556) @@ -151,11 +151,6 @@ pollen.common.voteAction=Vote pollen.common.voteAnonymous=Anonymous vote pollen.common.voteCountingType=Response type -pollen.common.voteCountingType.help=Normal\: selecting 1 to n choices among available choices <br/><br/> Percentage\: allocating a percentage to each choice <br/><br/> Condorcet\: ranking choices in order of preference <br/><br/> Number \: Free response. Summed and the average numbers. -pollen.common.voteCountingTypeHelp.condorcet=Condorcet vote\: 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. -pollen.common.voteCountingTypeHelp.normal=Normal vote\: vote for your favorite choice. -pollen.common.voteCountingTypeHelp.number=Voting by number\: The answer is free, leave blank or enter a integer. -pollen.common.voteCountingTypeHelp.percentage=Percentage vote\: allocate choices to get a 100%% total. pollen.common.voteNbVotes=%d existing votes pollen.common.voteNoVote=No existing vote pollen.common.voteOneVote=1 existing vote 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-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-06-25 17:56:45 UTC (rev 3556) @@ -152,10 +152,6 @@ pollen.common.voteAnonymous=Vote anonyme pollen.common.voteCountingType=Type de Réponse pollen.common.voteCountingType.help=Normal \: sélection de 1 ou n choix parmis les choix possibles <br/><br/> Pourcentage \: attribution d'un pourcentage à chaque choix <br/><br/> Condorcet \: classement des choix par ordre de préférence <br/><br/> Nombre \: Réponse libre. Fait la somme et la moyenne des nombres -pollen.common.voteCountingTypeHelp.condorcet=Vote Condorcet \: 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. -pollen.common.voteCountingTypeHelp.normal=Vote normal \: voter pour le ou les choix préférés. -pollen.common.voteCountingTypeHelp.number=Vote par nombre \: La réponse est libre, laissez vide ou entrez un nombre entier -pollen.common.voteCountingTypeHelp.percentage=Vote par pourcentage \: répartir les choix de manière à obtenir 100%% au total. pollen.common.voteNbVotes=%d votes existants pollen.common.voteNoVote=Pas de vote existant pollen.common.voteOneVote=1 vote existant Added: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/displayVote_CHECKBOX.jsp =================================================================== --- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/displayVote_CHECKBOX.jsp (rev 0) +++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/displayVote_CHECKBOX.jsp 2012-06-25 17:56:45 UTC (rev 3556) @@ -0,0 +1,27 @@ +<%-- + #%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" pageEncoding="UTF-8" %> +<%@ taglib prefix="s" uri="/struts-tags" %> +<s:checkbox theme="simple" + name="vote.choiceVoteToChoice[%{#status.index}].voteValue" + value="%{vote.choiceVoteToChoice[#status.index].voteValue}"/> Property changes on: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/displayVote_CHECKBOX.jsp ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/displayVote_TEXTFIELD.jsp =================================================================== --- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/displayVote_TEXTFIELD.jsp (rev 0) +++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/displayVote_TEXTFIELD.jsp 2012-06-25 17:56:45 UTC (rev 3556) @@ -0,0 +1,27 @@ +<%-- + #%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" pageEncoding="UTF-8" %> +<%@ taglib prefix="s" uri="/struts-tags" %> +<s:textfield required="true" size="3" theme="simple" + name="vote.choiceVoteToChoice[%{#status.index}].voteValue" + value="%{vote.choiceVoteToChoice[#status.index].voteValue}"/> Property changes on: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/displayVote_TEXTFIELD.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/pollForm.jsp =================================================================== --- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/pollForm.jsp 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/pollForm.jsp 2012-06-25 17:56:45 UTC (rev 3556) @@ -111,8 +111,8 @@ <legend> <s:text name="pollen.common.voteCountingType"/> <img src="<s:url value='/img/tooltip.png'/>" class="tooltip" - alt="<s:text name='pollen.common.voteCountingType.help'/>" - title="<s:text name='pollen.common.voteCountingType.help'/>"/> + alt="<s:property value='voteCountingHelp'/>" + title="<s:property value='voteCountingHelp'/>"/> </legend> <s:radio key='poll.voteCountingType' list="voteCountingTypes" label='' theme="simple"/> 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-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/result.jsp 2012-06-25 17:56:45 UTC (rev 3556) @@ -101,9 +101,9 @@ <s:label value="%{poll.beginDate}" key='pollen.common.beginDate'/> <s:label value="%{poll.endDate}" label='%{getText("pollen.common.endDate")}'/> - <s:label value="%{poll.voteCountingType}" + <s:label value="%{voteCountingTypeName}" label='%{getText("pollen.common.voteCountingType")}' - tooltip="%{getVoteCountingTypeHelp(poll.voteCountingType)}" + tooltip="%{voteCountingTypeHelp}" tooltipIconPath="/img/tooltip.png"/> </fieldset> </div> @@ -169,15 +169,14 @@ <s:if test="groupPoll"> <s:text name="pollen.common.results"/> <s:if test="byGroup"> - <s:a namespace="/poll" action="results/%{poll.pollId}"> - <s:param name="byGroup" value="false"/> + <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 namespace="/poll" action="results/%{poll.pollId}"> + <s:a href="%{getResultUrl(true)}"> <s:text name="pollen.common.group"/> </s:a> </s:else> @@ -195,8 +194,7 @@ <s:iterator value="choicesResultNames" var="choicesResultName" status="status"> <img id='chart_<s:property value="#status.index"/>' - alt="<s:property/>" - title="<s:property/>" + alt="<s:property/>" title="<s:property/>" src="<s:property value='%{getChoicesResultCharUrl(400,300, #choicesResultName)}'/>"> </s:iterator> </div> 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-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-06-25 17:56:45 UTC (rev 3556) @@ -147,9 +147,9 @@ <s:label value="%{creatorName}" key='pollen.common.pollCreator'/> <s:label value="%{poll.beginDate}" key='pollen.common.beginDate'/> <s:label value="%{poll.endDate}" key='pollen.common.endDate'/> - <s:label value="%{poll.voteCountingType}" + <s:label value="%{voteCountingTypeName}" label='%{getText("pollen.common.voteCountingType")}' - tooltip="%{getVoteCountingTypeHelp(poll.voteCountingType)}" + tooltip="%{voteCountingTypeHelp}" tooltipIconPath="/img/tooltip.png"/> </fieldset> </div> @@ -290,30 +290,12 @@ <s:else> <th></th> </s:else> + <s:set name="template" value="%{choiceFragment}"/> <s:iterator value="poll.choice" var="choice" status="status"> <s:if test="!isChoiceHidden(#choice)"> <th> - <s:if test="normalVoteCounting"> - <s:checkbox theme="simple" - name="vote.choiceVoteToChoice[%{#status.index}].voteValue" - value="%{vote.choiceVoteToChoice[#status.index].voteValue}"/> - </s:if> - <s:if test="percentageVoteCounting"> - <s:textfield required="true" size="3" theme="simple" - name="vote.choiceVoteToChoice[%{#status.index}].voteValue" - value="%{vote.choiceVoteToChoice[#status.index].voteValue}"/> - </s:if> - <s:if test="condorcetVoteCounting"> - <s:textfield id="condorcetInput" size="3" theme="simple" - name="vote.choiceVoteToChoice[%{#status.index}].voteValue" - value="%{vote.choiceVoteToChoice[#status.index].voteValue}"/> - </s:if> - <s:if test="numberVoteCounting"> - <s:textfield size="3" theme="simple" - name="vote.choiceVoteToChoice[%{#status.index}].voteValue" - value="%{vote.choiceVoteToChoice[#status.index].voteValue}"/> - </s:if> + <jsp:include page="${template}"/> </th> </s:if> </s:iterator> @@ -359,44 +341,14 @@ <td class="anonymous">?</td> </s:if> <s:else> - <s:if test="normalVoteCounting"> - <s:if test="isChoiceInVote(#currentVoteChoice)"> - <td class="voted">OK</td> - </s:if> - <s:else> - <td class="notVoted"></td> - </s:else> + <s:if test="isChoiceInVote(#currentVoteChoice)"> + <td class="voted"> + <s:property value="%{getChoiceValue(#currentVoteChoice)}"/> + </td> </s:if> - <s:if test="percentageVoteCounting"> - <s:if test="isChoiceInVote(#currentVoteChoice)"> - <td class="voted"> - <s:property value="%{#currentVoteChoice.voteValue}"/> % - </td> - </s:if> - <s:else> - <td class="notVoted"></td> - </s:else> - </s:if> - <s:if test="condorcetVoteCounting"> - <s:if test="isChoiceInVote(#currentVoteChoice)"> - <td class="voted"> - <s:property value="%{#currentVoteChoice.voteValue}"/> - </td> - </s:if> - <s:else> - <td class="notVoted"></td> - </s:else> - </s:if> - <s:if test="numberVoteCounting"> - <s:if test="isChoiceInVote(#currentVoteChoice)"> - <td class="voted"> - <s:property value="%{#currentVoteChoice.voteValue}"/> - </td> - </s:if> - <s:else> - <td class="notVoted"></td> - </s:else> - </s:if> + <s:else> + <td class="notVoted"></td> + </s:else> </s:else> </s:if> </s:iterator> Property changes on: trunk/pollen-ui-struts2/src/main/webapp/img/7terOk.jpg ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeDatePollSIT.java =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeDatePollSIT.java 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeDatePollSIT.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -1,8 +1,8 @@ /* * #%L * Pollen :: UI (struts2) - * $Id: CreateFreeTextPollSIT.java 3481 2012-06-15 15:12:06Z ymartel $ - * $HeadURL: http://svn.chorem.org/svn/pollen/trunk/pollen-ui-struts2/src/test/java/org/c... $ + * $Id$ + * $HeadURL$ * %% * Copyright (C) 2009 - 2012 CodeLutin * %% Property changes on: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeDatePollSIT.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateRestrictedTextPollSIT.java =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateRestrictedTextPollSIT.java 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateRestrictedTextPollSIT.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -1,8 +1,8 @@ /* * #%L * Pollen :: UI (struts2) - * $Id: CreateFreeTextPollSIT.java 3507 2012-06-18 09:45:47Z ymartel $ - * $HeadURL: http://svn.chorem.org/svn/pollen/trunk/pollen-ui-struts2/src/test/java/org/c... $ + * $Id$ + * $HeadURL$ * %% * Copyright (C) 2009 - 2012 CodeLutin * %% Property changes on: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateRestrictedTextPollSIT.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateTextPollForGroupSIT.java =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateTextPollForGroupSIT.java 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateTextPollForGroupSIT.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -1,8 +1,8 @@ /* * #%L * Pollen :: UI (struts2) - * $Id: CreateFreeTextPollSIT.java 3507 2012-06-18 09:45:47Z ymartel $ - * $HeadURL: http://svn.chorem.org/svn/pollen/trunk/pollen-ui-struts2/src/test/java/org/c... $ + * $Id$ + * $HeadURL$ * %% * Copyright (C) 2009 - 2012 CodeLutin * %% Property changes on: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateTextPollForGroupSIT.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/VoteCountingType.java =================================================================== --- trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/VoteCountingType.java 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/VoteCountingType.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -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 VoteCountingType implements I18nAble { - NORMAL(n_("pollen.voteCountingType.normal")), - PERCENTAGE(n_("pollen.voteCountingType.percentage")), - CONDORCET(n_("pollen.voteCountingType.condorcet")), - NUMBER(n_("pollen.voteCountingType.number")); - - private final String i18nKey; - - VoteCountingType(String i18nKey) { - this.i18nKey = i18nKey; - } - - @Override - public String getI18nKey() { - return i18nKey; - } - - public static VoteCountingType valueOf(int ordinal) { - VoteCountingType result = null; - for (VoteCountingType curr : VoteCountingType.values()) { - if (curr.ordinal() == ordinal) { - result = curr; - break; - } - } - return result; - } -} Modified: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/CondorcetMethod.java =================================================================== --- trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/CondorcetMethod.java 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/CondorcetMethod.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -163,8 +163,7 @@ * autres votes du votant et mise à jour du nombre de victoires pour ce * vote. * - * @see getVictories(String id, Choice choice, Map<String, Map<Choice, - * Double>> votes) + * @see #getVictories(String, Choice , Map) * @param choices Les choix utilisés pour le dépouillement. * @param votes Les votes de chaque votant. * @param byGroup Calcul sur des groupes. Modified: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/StandardMethod.java =================================================================== --- trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/StandardMethod.java 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/StandardMethod.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -68,13 +68,13 @@ // Calcul avec prise en compte des groupes public void calculateChoicesByGroup(List<Choice> choices) { - Map<String, List<String>> mapGroupsChoosenChoices = this - .getChoosenChoicesByGroup(choices); + Map<String, List<String>> mapGroupsChoosenChoices = + getChoosenChoicesByGroup(choices); for (Choice choice : choices) { double totalChoice = 0.; for (String idGroup : mapGroupsChoosenChoices.keySet()) { - totalChoice += this.getValueForChoiceByGroup(choice, idGroup, + totalChoice += getValueForChoiceByGroup(choice, idGroup, mapGroupsChoosenChoices.get(idGroup)); } choice.setValue(totalChoice); Modified: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/PollDTO.java =================================================================== --- trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/PollDTO.java 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/PollDTO.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -22,14 +22,13 @@ */ package org.chorem.pollen.votecounting.dto; +import org.chorem.pollen.common.ChoiceType; +import org.chorem.pollen.common.PollType; + import java.util.ArrayList; import java.util.Date; import java.util.List; -import org.chorem.pollen.common.ChoiceType; -import org.chorem.pollen.common.PollType; -import org.chorem.pollen.common.VoteCountingType; - /** * Classe DTO représentant un sondage. * @@ -65,7 +64,7 @@ private PollType pollType = null; - private VoteCountingType voteCounting = null; + private int voteCounting; private ChoiceType choiceType = null; @@ -199,11 +198,11 @@ this.pollType = pollType; } - public VoteCountingType getVoteCounting() { + public int getVoteCounting() { return voteCounting; } - public void setVoteCounting(VoteCountingType voteCounting) { + public void setVoteCounting(int voteCounting) { this.voteCounting = voteCounting; } Modified: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/VoteCountingResultDTO.java =================================================================== --- trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/VoteCountingResultDTO.java 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/VoteCountingResultDTO.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -24,8 +24,6 @@ import java.util.List; -import org.chorem.pollen.common.VoteCountingType; - /** * Classe DTO représentant un résultat de sondage. * @@ -39,7 +37,7 @@ private String idPoll; - private VoteCountingType typeVoteCounting; + private int typeVoteCounting; private boolean byGroup; @@ -73,11 +71,11 @@ this.idPoll = idPoll; } - public VoteCountingType getTypeVoteCounting() { + public int getTypeVoteCounting() { return typeVoteCounting; } - public void setTypeVoteCounting(VoteCountingType typeVoteCounting) { + public void setTypeVoteCounting(int typeVoteCounting) { this.typeVoteCounting = typeVoteCounting; } Modified: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ImportExportService.java =================================================================== --- trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ImportExportService.java 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ImportExportService.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -27,7 +27,6 @@ import org.apache.commons.logging.LogFactory; import org.chorem.pollen.common.ChoiceType; import org.chorem.pollen.common.PollType; -import org.chorem.pollen.common.VoteCountingType; import org.chorem.pollen.votecounting.business.NumberMethod; import org.chorem.pollen.votecounting.dto.ChoiceDTO; import org.chorem.pollen.votecounting.dto.CommentDTO; @@ -207,7 +206,7 @@ PollType.valueOf(pollElm.getAttributeValue(POLL_TYPE))); poll.setChoiceType(ChoiceType.valueOf( pollElm.getAttributeValue(CHOICE_TYPE))); - poll.setVoteCounting(VoteCountingType.valueOf( + poll.setVoteCounting(Integer.valueOf( pollElm.getAttributeValue(VOTE_COUNTING))); poll.setClosed(Boolean.valueOf(pollElm.getAttributeValue(CLOSED))); poll.setChoiceAddAllowed(Boolean.valueOf( @@ -408,7 +407,7 @@ pollElm.setAttribute(POLL_ID, poll.getPollId()); pollElm.setAttribute(POLL_TYPE, poll.getPollType().name()); pollElm.setAttribute(CHOICE_TYPE, poll.getChoiceType().name()); - pollElm.setAttribute(VOTE_COUNTING, poll.getVoteCounting().name()); + pollElm.setAttribute(VOTE_COUNTING, String.valueOf(poll.getVoteCounting())); pollElm.setAttribute(CLOSED, poll.isClosed() ? VALUE_TRUE : VALUE_FALSE); pollElm.setAttribute(CHOICE_ADD_ALLOWED, poll.isChoiceAddAllowed() ? VALUE_TRUE : VALUE_FALSE); Modified: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ServiceExportImpl.java =================================================================== --- trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ServiceExportImpl.java 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ServiceExportImpl.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -26,7 +26,6 @@ import org.apache.commons.logging.LogFactory; import org.chorem.pollen.common.ChoiceType; import org.chorem.pollen.common.PollType; -import org.chorem.pollen.common.VoteCountingType; import org.chorem.pollen.votecounting.business.NumberMethod; import org.chorem.pollen.votecounting.dto.ChoiceDTO; import org.chorem.pollen.votecounting.dto.CommentDTO; @@ -129,7 +128,7 @@ pollElm.setAttribute("pollId", poll.getPollId()); pollElm.setAttribute("pollType", poll.getPollType().name()); pollElm.setAttribute("choiceType", poll.getChoiceType().name()); - pollElm.setAttribute("voteCounting", poll.getVoteCounting().name()); + pollElm.setAttribute("voteCounting", String.valueOf(poll.getVoteCounting())); pollElm.setAttribute("closed", poll.isClosed() ? "true" : "false"); pollElm.setAttribute("choiceAddAllowed", poll.isChoiceAddAllowed() ? "true" : "false"); @@ -377,7 +376,7 @@ .valueOf(pollElm.getAttributeValue("pollType"))); poll.setChoiceType(ChoiceType.valueOf(pollElm .getAttributeValue("choiceType"))); - poll.setVoteCounting(VoteCountingType.valueOf(pollElm + poll.setVoteCounting(Integer.valueOf(pollElm .getAttributeValue("voteCounting"))); poll.setClosed(Boolean.valueOf(pollElm.getAttributeValue("closed"))); poll.setChoiceAddAllowed(Boolean.valueOf(pollElm Modified: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ServiceVoteCountingImpl.java =================================================================== --- trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ServiceVoteCountingImpl.java 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ServiceVoteCountingImpl.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -26,7 +26,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.common.VoteCountingType; import org.chorem.pollen.votecounting.business.Choice; import org.chorem.pollen.votecounting.business.CondorcetMethod; import org.chorem.pollen.votecounting.business.Context; @@ -137,19 +136,19 @@ * * @param type : type de dépouillement */ - private void createContext(VoteCountingType type) { + private void createContext(int type) { Method method = null; switch (type) { - case NORMAL: + case 0: method = new StandardMethod(); break; - case PERCENTAGE: + case 1: method = new PercentageMethod(); break; - case CONDORCET: + case 2: method = new CondorcetMethod(); break; - case NUMBER: + case 3: method = new NumberMethod(); break; default: Modified: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/VoteCountingService.java =================================================================== --- trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/VoteCountingService.java 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/VoteCountingService.java 2012-06-25 17:56:45 UTC (rev 3556) @@ -113,16 +113,16 @@ Method method; switch (poll.getVoteCounting()) { - case NORMAL: + case 0: method = new StandardMethod(); break; - case PERCENTAGE: + case 1: method = new PercentageMethod(); break; - case CONDORCET: + case 2: method = new CondorcetMethod(); break; - case NUMBER: + case 3: method = new NumberMethod(); break; default: Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-06-25 17:53:21 UTC (rev 3555) +++ trunk/pom.xml 2012-06-25 17:56:45 UTC (rev 3556) @@ -18,6 +18,11 @@ <version>1.5-SNAPSHOT</version> <modules> + <module>pollen-votecounting-api</module> + <module>pollen-votecounting-strategy-condorcet</module> + <module>pollen-votecounting-strategy-normal</module> + <module>pollen-votecounting-strategy-number</module> + <module>pollen-votecounting-strategy-percentage</module> <module>pollen-votecounting</module> <module>pollen-persistence</module> <module>pollen-services</module>