Author: schorlet Date: 2010-01-11 13:46:59 +0100 (Mon, 11 Jan 2010) New Revision: 2836 Added: trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/ResultListDTO.java trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/NumberMethod.java Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataResultConverter.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataVoteConverter.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataVoteCountingConverter.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/ChoiceDTO.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/ResultDTO.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceResults.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceResultsImpl.java trunk/pollen-ui/pom.xml trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Chart.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java trunk/pollen-ui/src/main/resources/org/apache/tapestry5/internal/ValidationMessages_fr.properties trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/PollCreation_en.properties trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/PollCreation_fr.properties trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/Results_en.properties trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/Results_fr.properties trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_en.properties trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_fr.properties trunk/pollen-ui/src/main/resources/pollen.properties trunk/pollen-ui/src/main/webapp/poll/PollCreation.tml trunk/pollen-ui/src/main/webapp/poll/PollModification.tml trunk/pollen-ui/src/main/webapp/poll/Results.tml trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/VoteCountingType.java trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/Choice.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/Context.java trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/Method.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/ChoiceDTO.java trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/PollChoiceDTO.java trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ServiceVoteCountingImpl.java trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/utils/Utils.java trunk/pom.xml Log: Evolution #96: Nouveau type de consultation: un nombre D?\195?\169but de l'impl?\195?\169mentation de ce nouveau type de sondage, tout n'est pas enti?\195?\168rement test?\195?\169 Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataResultConverter.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataResultConverter.java 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataResultConverter.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -52,15 +52,12 @@ */ public void populateResultEntities(VoteCountingResultDTO dto) throws TopiaException { - for (Object o : dto.getChoices()) { - ChoiceDTO choice = (ChoiceDTO) o; + for (ChoiceDTO choice : dto.getChoices()) { //if (choice.isResult) { - ResultDAO daoResult = PollenModelDAOHelper - .getResultDAO(transaction); + ResultDAO daoResult = PollenModelDAOHelper.getResultDAO(transaction); Result eResult = daoResult.create(); - ChoiceDAO daoChoice = PollenModelDAOHelper - .getChoiceDAO(transaction); + ChoiceDAO daoChoice = PollenModelDAOHelper.getChoiceDAO(transaction); Choice eChoice = daoChoice.findByTopiaId(choice.getIdChoice()); PollDAO daoPoll = PollenModelDAOHelper.getPollDAO(transaction); @@ -71,7 +68,7 @@ eResult.setByGroup(dto.isByGroup()); eResult.setPoll(ePoll); eResult.setResultValue(String.valueOf(choice.getValue())); - + EnumController enumCtrl = new EnumController(transaction); enumCtrl.setVoteCounting(dto.getTypeVoteCounting(), eResult); //} Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataVoteConverter.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataVoteConverter.java 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataVoteConverter.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -105,10 +105,12 @@ if (eVote.getChoiceVoteToChoice() != null) { DataChoiceConverter choiceConverter = new DataChoiceConverter(); for (VoteToChoice voteToChoice : eVote.getChoiceVoteToChoice()) { - ChoiceDTO choiceDTO = choiceConverter - .createChoiceDTO(voteToChoice.getChoice()); - choiceDTO.setValue(voteToChoice.getVoteValue()); - voteDTO.getChoiceDTOs().add(choiceDTO); + if (voteToChoice.getChoice() != null) { + ChoiceDTO choiceDTO = choiceConverter + .createChoiceDTO(voteToChoice.getChoice()); + choiceDTO.setValue(voteToChoice.getVoteValue()); + voteDTO.getChoiceDTOs().add(choiceDTO); + } } } Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataVoteCountingConverter.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataVoteCountingConverter.java 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataVoteCountingConverter.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -125,7 +125,9 @@ votingPerson.setEmail(vote.getPollAccount().getEmail()); for (VoteToChoice vToChoice : vote.getChoiceVoteToChoice()) { - votingPerson.getChoices().add(createVoteToChoiceDTO(vToChoice)); + if (vToChoice != null && vToChoice.getChoice() != null) { + votingPerson.getChoices().add(createVoteToChoiceDTO(vToChoice)); + } } return votingPerson; } Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/ChoiceDTO.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/ChoiceDTO.java 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/ChoiceDTO.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -18,6 +18,8 @@ import java.io.Serializable; +import org.chorem.pollen.votecounting.dto.PollChoiceDTO; + /** * Classe DTO représentant un choix de sondage. * @@ -26,7 +28,11 @@ * @version $Id$ */ public class ChoiceDTO implements Serializable { + + public static final String HIDDEN_PREFIX = PollChoiceDTO.HIDDEN_PREFIX; + private static final long serialVersionUID = 1L; + private String id = ""; private String name = ""; @@ -111,4 +117,12 @@ this.pollId = pollId; } + public boolean isHidden() { + if (name != null) { + return name.startsWith(HIDDEN_PREFIX); + } + + return false; + } + } \ No newline at end of file Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/ResultDTO.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/ResultDTO.java 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/ResultDTO.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -117,4 +117,11 @@ this.byGroup = byGroup; } + public boolean isHidden() { + if (name != null) { + return name.startsWith(ChoiceDTO.HIDDEN_PREFIX); + } + + return false; + } } \ No newline at end of file Added: trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/ResultListDTO.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/ResultListDTO.java (rev 0) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/ResultListDTO.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -0,0 +1,38 @@ +package org.chorem.pollen.business.dto; + +import java.util.List; + +import org.chorem.pollen.votecounting.dto.VoteCountingResultDTO; + +/** + * Classe DTO représentant une liste de résultats. + * + * @version $Revision$ $Date$ + * @since 1.2.2 + */ +public class ResultListDTO { + + /** Liste des résultats */ + private List<ResultDTO> resultDTOs = null; + + /** Résultat issu du dépouillement du vote */ + private VoteCountingResultDTO voteCountingResultDTO = null; + + public List<ResultDTO> getResultDTOs() { + return resultDTOs; + } + + public void setResultDTOs(List<ResultDTO> resultDTOs) { + this.resultDTOs = resultDTOs; + } + + public VoteCountingResultDTO getVoteCountingResultDTO() { + return voteCountingResultDTO; + } + + public void setVoteCountingResultDTO(VoteCountingResultDTO voteCountingResultDTO) { + this.voteCountingResultDTO = voteCountingResultDTO; + } + + +} Property changes on: trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/ResultListDTO.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Date Author Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceResults.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceResults.java 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceResults.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -16,9 +16,7 @@ package org.chorem.pollen.business.services; -import java.util.List; - -import org.chorem.pollen.business.dto.ResultDTO; +import org.chorem.pollen.business.dto.ResultListDTO; import org.chorem.pollen.business.dto.UserDTO; import org.chorem.pollen.common.VoteCountingType; @@ -36,7 +34,7 @@ * @param pollId identifiant du sondage * @return resultats, null si le sondage n'est pas fermé */ - public List<ResultDTO> getAllResults(String pollId); + public ResultListDTO getAllResults(String pollId); /** * Récupère les résultats d'un sondage pour un seul type de dépouillement. @@ -46,7 +44,7 @@ * @return results, null si le sondage n'est pas fermé ou ne peut être * dépouillé de cette façon */ - public List<ResultDTO> getResultsByVoteCounting(String pollId, + public ResultListDTO getResultsByVoteCounting(String pollId, VoteCountingType voteCounting); /** @@ -56,7 +54,7 @@ * @param pollId identifiant du sondage * @return results */ - public List<ResultDTO> getNormalResults(String pollId); + public ResultListDTO getNormalResults(String pollId); /** * Récupère les résultats d'un sondage avec le dépouillement normal avec @@ -65,7 +63,7 @@ * @param pollId identifiant du sondage * @return results si PollType == GROUP, null sinon */ - public List<ResultDTO> getGroupResults(String pollId); + public ResultListDTO getGroupResults(String pollId); /** * Export d'un sondage au format XML. Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceResultsImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceResultsImpl.java 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceResultsImpl.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -27,6 +27,7 @@ import org.chorem.pollen.business.converters.DataVoteCountingConverter; import org.chorem.pollen.business.converters.EnumController; import org.chorem.pollen.business.dto.ResultDTO; +import org.chorem.pollen.business.dto.ResultListDTO; import org.chorem.pollen.business.dto.UserDTO; import org.chorem.pollen.business.persistence.Poll; import org.chorem.pollen.business.persistence.PollDAO; @@ -61,23 +62,23 @@ } @Override - public List<ResultDTO> getAllResults(String pollId) { + public ResultListDTO getAllResults(String pollId) { return getResults(pollId, null, false, false); } @Override - public List<ResultDTO> getResultsByVoteCounting(String pollId, + public ResultListDTO getResultsByVoteCounting(String pollId, VoteCountingType voteCounting) { return getResults(pollId, voteCounting, false, false); } @Override - public List<ResultDTO> getGroupResults(String pollId) { + public ResultListDTO getGroupResults(String pollId) { return getResults(pollId, null, true, true); } @Override - public List<ResultDTO> getNormalResults(String pollId) { + public ResultListDTO getNormalResults(String pollId) { return getResults(pollId, null, true, false); } @@ -90,7 +91,7 @@ * @param groupOnly résultats uniquement par groupe * @return les résultats du sondage */ - private List<ResultDTO> getResults(String pollId, + private ResultListDTO getResults(String pollId, VoteCountingType voteCounting, boolean byGroup, boolean groupOnly) { TopiaContext transaction = null; try { @@ -133,6 +134,9 @@ List<ResultDTO> list = converter.createResultDTOs(ePoll); transaction.closeContext(); + VoteCountingType voteCountingType = EnumController + .getVoteCountingType(ePoll); + Iterator<ResultDTO> it = list.iterator(); while (it.hasNext()) { ResultDTO curr = it.next(); @@ -158,14 +162,17 @@ } // Suppression des autres resultats de depouillements differents - if (curr.getVoteCounting() != EnumController - .getVoteCountingType(ePoll)) { + if (curr.getVoteCounting() != voteCountingType) { it.remove(); } } } - return list; + ResultListDTO resultListDTO = new ResultListDTO(); + resultListDTO.setResultDTOs(list); + resultListDTO.setVoteCountingResultDTO(result); + + return resultListDTO; } catch (TopiaException e) { ContextUtil.doCatch(e, transaction); return null; Modified: trunk/pollen-ui/pom.xml =================================================================== --- trunk/pollen-ui/pom.xml 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-ui/pom.xml 2010-01-11 12:46:59 UTC (rev 2836) @@ -145,6 +145,18 @@ </overlays> </configuration> </plugin> + <plugin> + <groupId>org.mortbay.jetty</groupId> + <artifactId>maven-jetty-plugin</artifactId> + <version>6.1.19</version> + <configuration> + <connectors> + <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector"> + <port>8080</port> + </connector> + </connectors> + </configuration> + </plugin> </plugins> </build> </project> Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Chart.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Chart.java 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Chart.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -23,6 +23,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import java.util.List; import org.apache.tapestry5.ComponentResources; @@ -31,7 +32,9 @@ import org.apache.tapestry5.StreamResponse; import org.apache.tapestry5.annotations.Parameter; import org.apache.tapestry5.dom.Element; +import org.apache.tapestry5.internal.services.ArrayEventContext; import org.apache.tapestry5.ioc.annotations.Inject; +import org.apache.tapestry5.ioc.services.TypeCoercer; import org.apache.tapestry5.services.Response; import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; @@ -92,15 +95,30 @@ @Parameter(required = true) private List<Object> _values; + @Parameter(required = false) + private List<Object> _subtitles; + @Inject private ComponentResources _resources; - + + @Inject + private TypeCoercer typeCoercer; + void beginRender(MarkupWriter writer) { // event link params Object[] params = new Object[] { _title, _type, _width, _height }; + + if (_subtitles != null) { + Object[] size = new Object[] { _subtitles.size() }; + params = ArrayUtil.concat(params, size); + params = ArrayUtil.concat(params, _subtitles.toArray()); + } else { + Object[] size = new Object[] { 0 }; + params = ArrayUtil.concat(params, size); + } params = ArrayUtil.concat(params, _values.toArray()); - + // generate event link Link link = _resources.createEventLink("chart", params); Element img = writer.element("img", "src", link); @@ -112,13 +130,25 @@ writer.end(); } - public StreamResponse onChart(final String title, final int type, - final int width, final int height, Object... rest) { + public StreamResponse onChart(final String title, final int type, final int width, + final int height, final int nbSubtitles, final Object... objects) { + + ArrayEventContext ec = new ArrayEventContext(typeCoercer, objects); + List<Object> subtitles = new ArrayList<Object>(nbSubtitles); + for (int i = 5; i < 5 + nbSubtitles; i += 2) { + String key = ec.get(String.class, i); + String value = ec.get(String.class, i + 1); + subtitles.add(key); + subtitles.add(value); + } + DefaultKeyedValues values = new DefaultKeyedValues(); - for (int i = 4; i < rest.length; i += 2) { - values.addValue(rest[i].toString(), Double.valueOf(rest[i + 1] - .toString())); + for (int i = 5 + nbSubtitles; i < ec.getCount(); i += 2) { + String key = ec.get(String.class, i); + Double value = ec.get(Double.class, i + 1); + values.addValue(key, value); } + values.sortByValues(SortOrder.DESCENDING); PieDataset data = new DefaultPieDataset(values); @@ -151,6 +181,15 @@ Font.BOLD, 12))); chart.setBackgroundPaint(new Color(255, 255, 255)); + if (subtitles != null) { + Font subtitlesFont = new Font(Font.SANS_SERIF, Font.ITALIC, 11); + for (int i = 0; i < subtitles.size(); i += 2) { + String subtitle = subtitles.get(i) + "=" + subtitles.get(i + 1); + TextTitle textTitle = new TextTitle(subtitle, subtitlesFont); + chart.addSubtitle(textTitle); + } + } + // return the image return new StreamResponse() { public String getContentType() { Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -48,7 +48,6 @@ import org.apache.tapestry5.ioc.services.PropertyAccess; import org.apache.tapestry5.json.JSONObject; import org.apache.tapestry5.upload.services.UploadSymbols; -import org.chenillekit.tapestry.core.components.DateTimeField; import org.chorem.pollen.business.business.PreventRuleManager; import org.chorem.pollen.business.dto.ChoiceDTO; import org.chorem.pollen.business.dto.PersonListDTO; @@ -65,7 +64,6 @@ import org.chorem.pollen.common.VoteCountingType; import org.chorem.pollen.ui.base.ContextLink; import org.chorem.pollen.ui.components.FeedBack; -import org.chorem.pollen.ui.components.FeedContextLink; import org.chorem.pollen.ui.components.ImageContextLink; import org.chorem.pollen.ui.data.GenericSelectModel; import org.chorem.pollen.ui.data.Lien; @@ -743,20 +741,23 @@ poll.setVotingListDTOs(votingLists); } + // Ajout des choix au sondage if (isTextChoices()) { - for (ChoiceDTO choice : choices) + for (ChoiceDTO choice : choices) { if (choice.getName() != null) { choice.setValidate(true); poll.getChoiceDTOs().add(choice); } + } } else if (isDateChoices()) { - for (DateChoiceUIO choice : dateTypeChoices) + for (DateChoiceUIO choice : dateTypeChoices) { if (choice.getDate() != null) { choice.setValidate(true); choice.setName(String.valueOf(choice.getDate().getTime())); poll.getChoiceDTOs().add(choice); } + } } else if (isImgChoices()) { for (ImageChoiceUIO imgChoice : imgTypeChoices) { if (imgChoice.getImg() != null) { @@ -775,7 +776,7 @@ } } } - + // Retouche des attributs dépendants l'un de l'autre if (poll.getBeginDate() == null) { poll.setBeginDate(new Date()); @@ -973,6 +974,10 @@ return poll.getVoteCounting() == VoteCountingType.CONDORCET; } + public boolean isNumberVoteCounting() { + return poll.getVoteCounting() == VoteCountingType.NUMBER; + } + public boolean isFreePoll() { return poll.getPollType() == PollType.FREE; } Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -21,8 +21,12 @@ import java.util.Collections; import java.util.Comparator; import java.util.Date; +import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; import org.apache.tapestry5.BindingConstants; import org.apache.tapestry5.annotations.Component; @@ -39,16 +43,19 @@ import org.chorem.pollen.business.dto.PollAccountDTO; import org.chorem.pollen.business.dto.PollDTO; import org.chorem.pollen.business.dto.ResultDTO; +import org.chorem.pollen.business.dto.ResultListDTO; import org.chorem.pollen.business.services.ServicePoll; import org.chorem.pollen.business.services.ServicePollAccount; import org.chorem.pollen.business.services.ServiceResults; import org.chorem.pollen.common.ChoiceType; import org.chorem.pollen.common.PollType; +import org.chorem.pollen.common.VoteCountingType; import org.chorem.pollen.ui.components.Chart; import org.chorem.pollen.ui.components.FeedBack; import org.chorem.pollen.ui.components.ImageContextLink; import org.chorem.pollen.ui.data.Lien; import org.chorem.pollen.ui.services.Configuration; +import org.chorem.pollen.votecounting.dto.VoteCountingResultDTO; import org.slf4j.Logger; /** @@ -104,11 +111,30 @@ /** Résultats du sondage */ @Persist - @Property + @Property(write = false) private List<ResultDTO> results; + /** + * Résultats du sondage. + * + * La map est indexée par les noms de choix. + */ + @Persist + @Property(write = false) + private Map<String, List<String>> choicesResults; + /** Résultat courant */ + @SuppressWarnings("unused") @Property + private Map.Entry<String, List<String>> choicesResult; + + /** Résultats du sondage */ + @Persist + @Property(write = false) + private Map<String, List<String>> subtitles; + + /** Résultat courant */ + @Property private ResultDTO result; /** Choix courant (diagramme) */ @@ -152,7 +178,7 @@ private ServicePollAccount servicePollAccount; @Inject private ServiceResults serviceResults; - + @InjectComponent private ImageContextLink imgContext; @@ -167,11 +193,11 @@ countPoll(); for (ResultDTO result : results) { - String name = String.valueOf(result.getName()); - String value = String.valueOf(result.getValue()); + String name = result.getName(); + String value = result.getValue(); if (poll.getChoiceType() == ChoiceType.DATE) { // mise en forme de la date - Date date = new Date(Long.parseLong(result.getName())); + Date date = new Date(Long.parseLong(name)); name = dateFormat.format(date); } @@ -283,6 +309,8 @@ return messages.get("percentageVote-help"); case CONDORCET: return messages.get("condorcetVote-help"); + case NUMBER: + return messages.get("numberVote-help"); default: return ""; } @@ -290,6 +318,10 @@ /** Retourne le message de victoire indiquant le ou les gagnants. */ public String getVictoryMessage() { + if (poll.getVoteCounting() == VoteCountingType.NUMBER) { + return null; + } + List<ResultDTO> winners = getTopRanking(); if (winners.size() == 0) { @@ -336,12 +368,17 @@ /** Dépouillement du sondage. Mise à jour des résultats. */ private void countPoll() { + ResultListDTO resultListDTO = null; + if (byGroup) { - results = serviceResults.getGroupResults(poll.getPollId()); + resultListDTO = serviceResults.getGroupResults(poll.getPollId()); } else { - results = serviceResults.getNormalResults(poll.getPollId()); + resultListDTO = serviceResults.getNormalResults(poll.getPollId()); } + results = resultListDTO.getResultDTOs(); + computeResults(resultListDTO); + for (ResultDTO res : results) { logger.debug(res.getName() + ": " + res.getValue() + ", (voteCounting=" + res.getVoteCounting() + ", byGroup=" @@ -349,6 +386,75 @@ } } + private void computeResults(ResultListDTO resultListDTO) { + if (poll.getVoteCounting() == VoteCountingType.NUMBER) { + choicesResults = new LinkedHashMap<String, List<String>>(); + subtitles = new LinkedHashMap<String, List<String>>(); + + List<ResultDTO> results2 = new ArrayList<ResultDTO>(); + + // Ajout des résultats des choix cachés + for (ResultDTO result : results) { + if (result.isHidden()) { + String name = result.getName(); + int indexOf = name.indexOf('#'); + String choice = name.substring(ChoiceDTO.HIDDEN_PREFIX.length(), indexOf); + + List<String> votes = choicesResults.get(choice); + if (votes == null) { + votes = new ArrayList<String>(); + } + + String votingId = name.substring(indexOf + 1); + String value = result.getValue(); + + votes.add(votingId); + votes.add(value); + + choicesResults.put(choice, votes); + + } else { + results2.add(result); + } + } + + Set<Entry<String, List<String>>> entries = choicesResults.entrySet(); + for (Entry<String, List<String>> entry : entries) { + String choiceName = entry.getKey(); + + // Récupération du choix correspondant au résultat + VoteCountingResultDTO voteCountingResultDTO = resultListDTO + .getVoteCountingResultDTO(); + + for (org.chorem.pollen.votecounting.dto.ChoiceDTO choice : + voteCountingResultDTO.getChoices()) { + if (choiceName.equals(choice.getName())) { + List<String> choiceSubtitles = subtitles.get(choice); + if (choiceSubtitles == null) { + choiceSubtitles = new ArrayList<String>(); + } + + choiceSubtitles.add("total"); + choiceSubtitles.add(String.valueOf(choice.getValue())); + choiceSubtitles.add("average"); + choiceSubtitles.add(String.valueOf(choice.getAverage())); + choiceSubtitles.add("blanks"); + choiceSubtitles.add(String.valueOf(choice.getNbBlankVotes())); + + subtitles.put(choiceName, choiceSubtitles); + break; + } + } + + } + + results = results2; + if (results.size() == 1) { + results.remove(0); + } + } + } + /** Initialisation des objets de session */ void onActivate(String id) { param = id; Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -54,9 +54,11 @@ import org.chorem.pollen.business.dto.PollDTO; import org.chorem.pollen.business.dto.PreventRuleDTO; import org.chorem.pollen.business.dto.ResultDTO; +import org.chorem.pollen.business.dto.ResultListDTO; import org.chorem.pollen.business.dto.UserDTO; import org.chorem.pollen.business.dto.VoteDTO; import org.chorem.pollen.business.dto.VotingListDTO; +import org.chorem.pollen.business.services.ServiceChoice; import org.chorem.pollen.business.services.ServiceComment; import org.chorem.pollen.business.services.ServicePoll; import org.chorem.pollen.business.services.ServicePollAccount; @@ -260,7 +262,9 @@ private ServicePollAccount servicePollAccount; @Inject private ServiceResults serviceResults; - + @Inject + private ServiceChoice serviceChoice; + /** * Composant pour la gestion des flux RSS */ @@ -307,6 +311,7 @@ poll.getMaxChoiceNb())); return pollZone.getBody(); } + } else if (poll.getVoteCounting() == VoteCountingType.PERCENTAGE) { int total = 0; for (ChoiceDTO choice : poll.getChoiceDTOs()) { @@ -317,6 +322,7 @@ voteForm.recordError(messages.get("not100percent")); return pollZone.getBody(); } + } else if (poll.getVoteCounting() == VoteCountingType.CONDORCET) { for (ChoiceDTO choice : poll.getChoiceDTOs()) { if (choice.getValue() == 0) { @@ -324,6 +330,31 @@ } choiceDTOs.add(choice); } + + } else if (poll.getVoteCounting() == VoteCountingType.NUMBER) { + String votingId = pollAccount.getVotingId(); + if (anonymousVote) { + votingId = "anonymous" + UUID.randomUUID().toString().replaceAll("-", ""); + } + + for (ChoiceDTO choice : poll.getChoiceDTOs()) { + if (!choice.isHidden()) { + choiceDTOs.add(choice); + + // creates a new hidden choice + ChoiceDTO hiddenChoice = new ChoiceDTO(); + hiddenChoice.setName(ChoiceDTO.HIDDEN_PREFIX + + choice.getName() + "#" + votingId); + hiddenChoice.setValue(choice.getValue()); + hiddenChoice.setPollId(choice.getPollId()); + hiddenChoice.setVoteId(choice.getVoteId()); + hiddenChoice.setValidate(false); + + String choiceId = serviceChoice.createChoice(hiddenChoice); + hiddenChoice.setId(choiceId); + choiceDTOs.add(hiddenChoice); + } + } } VoteDTO vote = new VoteDTO(null, poll.getId(), null); @@ -336,10 +367,10 @@ for (VoteDTO v : poll.getVoteDTOs()) { PollAccountDTO voteAccount = servicePollAccount .findPollAccountById(v.getPollAccountId()); - if (voteAccount.getVotingId().equals( - pollAccount.getVotingId())) { + + if (voteAccount.getVotingId().equals(pollAccount.getVotingId())) { vote.setId(v.getId()); - serviceVote.deleteVote(vote.getId()); + deleteVote(vote.getId()); serviceVote.createVote(vote, pollAccount); } } @@ -358,10 +389,29 @@ voteChoices.clear(); return pollZone.getBody(); } + + private void deleteVote(String voteId) { + for (VoteDTO vote : poll.getVoteDTOs()) { + if (vote.getId().equals(voteId)) { + List<ChoiceDTO> choiceDTOs = vote.getChoiceDTOs(); + for (ChoiceDTO choiceDTO : choiceDTOs) { + + if (choiceDTO.isHidden()) { + serviceChoice.deleteChoice(choiceDTO.getId()); + } + } + + break; + } + } + + serviceVote.deleteVote(voteId); + } + /** Méthode appelée lors de la suppression d'un vote. */ Object onActionFromDeleteVote(String voteId) { - serviceVote.deleteVote(voteId); + deleteVote(voteId); // Mise à jour du sondage et des résultats poll = servicePoll.findPollByPollId(poll.getPollId()); @@ -576,6 +626,20 @@ choiceOfVote.setValue((addChoice) ? 1 : 0); } + public void setAddNumberVote(Integer value) { + if (value != null) { + choiceOfVote.setValue(value); + + } else { + choiceOfVote.setValue(-1); + } + } + + public Integer getAddNumberVote() { + return null; + } + + /** * Retourne si le choix fait partie du vote (s'il a été renseigné par le * votant). @@ -592,6 +656,8 @@ return true; case CONDORCET: return choice.getValue() < 100; + case NUMBER: + return choice.getValue() >= 0; } } return null; @@ -602,13 +668,19 @@ * * @return un choix de vote */ - public ChoiceDTO getCurrentVoteChoice() { + @Property(write = false) + private ChoiceDTO currentVoteChoice; + + public char setCurrentVoteChoice() { + currentVoteChoice = null; for (ChoiceDTO choice : vote.getChoiceDTOs()) { if (choice.getId().equals(choiceOfPoll.getId())) { - return choice; + currentVoteChoice = choice; + break; } } - return null; + + return 0; } /** @@ -637,7 +709,7 @@ if (log.isDebugEnabled()) { log.debug("feed context path : " + getFeedContext().getContextPath()); log.debug("feed absolute path : " + feedFile.getAbsolutePath()); - } + } return feedFile.exists() ? true : false; } @@ -821,7 +893,7 @@ } public boolean isPollChoiceStarted() { - Date now = new Date(); + Date now = new Date(); boolean started = poll.getBeginChoiceDate() == null || poll.getBeginChoiceDate().before(now); boolean ended = poll.getEndChoiceDate() != null && poll.getEndChoiceDate().before(now); return started && !ended; @@ -896,6 +968,10 @@ return poll.getVoteCounting() == VoteCountingType.CONDORCET; } + public boolean isNumberVoteCounting() { + return poll.getVoteCounting() == VoteCountingType.NUMBER; + } + /** retourne vrai si l'utilisateur est le créateur du sondage */ public boolean isCreatorUser() { PollAccountDTO creator = servicePollAccount.findPollAccountById(poll @@ -926,6 +1002,8 @@ return messages.get("percentageVote-help"); case CONDORCET: return messages.get("condorcetVote-help"); + case NUMBER: + return messages.get("numberVote-help"); default: return ""; } @@ -960,12 +1038,16 @@ /** Dépouillement du sondage. Mise à jour des résultats. */ private void countPoll() { + ResultListDTO resultListDTO = null; + if (isGroupPoll()) { - results = serviceResults.getGroupResults(poll.getPollId()); + resultListDTO = serviceResults.getGroupResults(poll.getPollId()); } else { - results = serviceResults.getNormalResults(poll.getPollId()); + resultListDTO = serviceResults.getNormalResults(poll.getPollId()); } + results = resultListDTO.getResultDTOs(); + if (logger.isDebugEnabled()) { for (ResultDTO res : results) { logger.debug(res.getName() + ": " + res.getValue() @@ -997,11 +1079,20 @@ .findPollAccountByAccountId(accountId); pollAccountId = pollAccount.getId(); } + if (pollAccount == null) { pollAccount = new PollAccountDTO(); if (userExists) { - pollAccount.setVotingId(user.getFirstName() + " " - + user.getLastName()); + if (user.getFirstName() != null && user.getLastName() != null) { + pollAccount.setVotingId( + user.getFirstName() + " " + user.getLastName()); + + } else if (user.getFirstName() != null) { + pollAccount.setVotingId(user.getFirstName()); + + } else if (user.getLastName() != null) { + pollAccount.setVotingId(user.getLastName()); + } } } Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -16,8 +16,6 @@ package org.chorem.pollen.ui.services; -import java.io.IOException; - import org.apache.tapestry5.SymbolConstants; import org.apache.tapestry5.ioc.MappedConfiguration; import org.apache.tapestry5.ioc.Messages; @@ -25,17 +23,13 @@ import org.apache.tapestry5.ioc.ServiceBinder; import org.apache.tapestry5.ioc.annotations.EagerLoad; import org.apache.tapestry5.ioc.annotations.InjectService; -import org.apache.tapestry5.ioc.annotations.Local; import org.apache.tapestry5.ioc.services.RegistryShutdownHub; import org.apache.tapestry5.ioc.services.RegistryShutdownListener; import org.apache.tapestry5.ioc.services.SymbolProvider; import org.apache.tapestry5.services.ComponentSource; -import org.apache.tapestry5.services.Request; -import org.apache.tapestry5.services.RequestFilter; -import org.apache.tapestry5.services.RequestHandler; -import org.apache.tapestry5.services.Response; import org.apache.tapestry5.upload.services.UploadSymbols; import org.chorem.pollen.business.services.ServiceAuth; +import org.chorem.pollen.business.services.ServiceChoice; import org.chorem.pollen.business.services.ServiceComment; import org.chorem.pollen.business.services.ServiceList; import org.chorem.pollen.business.services.ServicePoll; @@ -73,6 +67,7 @@ binder.bind(ServicePollAccount.class); binder.bind(ServiceResults.class); binder.bind(ServiceVote.class); + binder.bind(ServiceChoice.class); } public static void contributeApplicationDefaults( @@ -88,7 +83,7 @@ // The factory default is true but during the early stages of an application // overriding to false is a good idea. In addition, this is often overridden // on the command line as -Dtapestry.production-mode=false - // The primary difference is how exceptions are reported. + // The primary difference is how exceptions are reported. configuration.add(SymbolConstants.PRODUCTION_MODE, "true"); // Restricting file size in upload component Modified: trunk/pollen-ui/src/main/resources/org/apache/tapestry5/internal/ValidationMessages_fr.properties =================================================================== --- trunk/pollen-ui/src/main/resources/org/apache/tapestry5/internal/ValidationMessages_fr.properties 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-ui/src/main/resources/org/apache/tapestry5/internal/ValidationMessages_fr.properties 2010-01-11 12:46:59 UTC (rev 2836) @@ -5,3 +5,6 @@ max-integer=Le champs %2$s doit avoir une valeur inférieure à %1$d. regexp=Le champs %2$s ne correspond pas à l'expression '%1$s'. invalid-email='%s' n'est pas une adresse email valide. +integer-format-exception=Vous devez fournir une valeur entière pour %s. +number-format-exception=Vous devez fournir une valeur numérique pour %s. + Modified: trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/PollCreation_en.properties =================================================================== --- trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/PollCreation_en.properties 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/PollCreation_en.properties 2010-01-11 12:46:59 UTC (rev 2836) @@ -27,7 +27,7 @@ pollType-label=Poll type pollType-help=Free: accessible to everyone<br/>Restricted: accessible only to a list of persons<br/>Group: accessible to several lists of persons voteCounting-label=Vote counting type -voteCounting-help=Normal: selecting 1 to n choices among available choices<br/>Percentage: allocating a percentage to each choice<br/>Condorcet: ranking choices in order of preference +voteCounting-help=Normal: selecting 1 to n choices among available choices<br/>Percentage: allocating a percentage to each choice<br/>Condorcet: ranking choices in order of preference<br/>Number : Free response. Summed and the average numbers. #options optionsLegend=Step %d : poll options Modified: trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/PollCreation_fr.properties =================================================================== --- trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/PollCreation_fr.properties 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/PollCreation_fr.properties 2010-01-11 12:46:59 UTC (rev 2836) @@ -27,7 +27,7 @@ pollType-label=Type de sondage pollType-help=Free : accessible \u00E0 tout le monde<br/>Restricted : accessible uniquement \u00E0 une liste de votants<br/>Group : accessible \u00E0 plusieurs listes de votants voteCounting-label=Type de d\u00E9pouillement -voteCounting-help=Normal : s\u00E9lection de 1 ou n choix parmis les choix possibles<br/>Percentage : attribution d\'un pourcentage \u00E0 chaque choix<br/>Condorcet : classement des choix par ordre de pr\u00E9f\u00E9rence +voteCounting-help=Normal : s\u00E9lection de 1 ou n choix parmis les choix possibles<br/>Percentage : attribution d\'un pourcentage \u00E0 chaque choix<br/>Condorcet : classement des choix par ordre de pr\u00E9f\u00E9rence<br/>Nombre : R\u00E9ponse libre. Fait la somme et la moyenne des nombres. #options optionsLegend=\u00C9tape %d : les options de votre sondage Modified: trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/Results_en.properties =================================================================== --- trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/Results_en.properties 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/Results_en.properties 2010-01-11 12:46:59 UTC (rev 2836) @@ -3,6 +3,7 @@ normalVote-help=The chart show the total of votes by choice. percentageVote-help=The chart show the total of votes by choice. condorcetVote-help=The chart show the number of victories for each choice and each vote. +numberVote-help=The chart shows the distribution of votes by voting. victory=Winner: victories=Winners: about=About the poll Modified: trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/Results_fr.properties =================================================================== --- trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/Results_fr.properties 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/Results_fr.properties 2010-01-11 12:46:59 UTC (rev 2836) @@ -3,6 +3,7 @@ normalVote-help=Le diagramme représente le cumul des votes par choix. percentageVote-help=Le diagramme représente le cumul des votes par choix. condorcetVote-help=Le diagramme représente le nombre de victoires des choix par rapport aux autres choix de chaque vote. +numberVote-help=Le diagramme présente la répartition des votes par votants. victory=Gagnant : victories=Gagnants : about=À propos du sondage Modified: trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_en.properties =================================================================== --- trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_en.properties 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_en.properties 2010-01-11 12:46:59 UTC (rev 2836) @@ -7,6 +7,7 @@ normalVote-help=Normal vote: vote for your favorite choice. percentageVote-help=Percentage vote: allocate choices to get a 100% total. condorcetVote-help=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. +numberVote-help=Voting by number: The answer is free, leave blank or enter a integer. results=Results results-help=Display results Modified: trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_fr.properties =================================================================== --- trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_fr.properties 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_fr.properties 2010-01-11 12:46:59 UTC (rev 2836) @@ -7,6 +7,7 @@ normalVote-help=Vote normal : voter pour le ou les choix préférés. percentageVote-help=Vote par pourcentage : répartir les choix de manière à obtenir 100% au total. condorcetVote-help=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. +numberVote-help=Vote par nombre : La réponse est libre, laissez vide ou entrez un nombre entier results=Résultats results-help=Voir les résultats Modified: trunk/pollen-ui/src/main/resources/pollen.properties =================================================================== --- trunk/pollen-ui/src/main/resources/pollen.properties 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-ui/src/main/resources/pollen.properties 2010-01-11 12:46:59 UTC (rev 2836) @@ -23,7 +23,7 @@ ## Initialisation de la base de donn\u00C3\u00A9es choiceType=DATE,IMAGE,TEXT pollType=RESTRICTED,FREE,GROUP -voteCounting=NORMAL,PERCENTAGE,CONDORCET +voteCounting=NORMAL,PERCENTAGE,CONDORCET,NUMBER ## Utilisateur par d\u00C3\u00A9faut adminLogin=admin Modified: trunk/pollen-ui/src/main/webapp/poll/PollCreation.tml =================================================================== --- trunk/pollen-ui/src/main/webapp/poll/PollCreation.tml 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-ui/src/main/webapp/poll/PollCreation.tml 2010-01-11 12:46:59 UTC (rev 2836) @@ -228,10 +228,14 @@ <t:FeedContextLink t:id="feedContext" /> <t:form t:id="choicesCreationForm"> <div id="choicesCreationFormDiv"> - <div> - <t:label for="choiceType" />: - <t:select t:id="choiceType" t:value="poll.choiceType" t:validate="required" t:mixins="ck/OnEvent" event="change" onCompleteCallback="onCompleteZoneUpdate"></t:select> - </div> + <t:if test="!isNumberVoteCounting()"> + <div> + <t:label for="choiceType" />: + <t:select t:id="choiceType" t:value="poll.choiceType" t:validate="required" + t:mixins="ck/OnEvent" event="change" onCompleteCallback="onCompleteZoneUpdate"> + </t:select> + </div> + </t:if> <t:errors/> <fieldset> <legend>${stepLegend}</legend> Modified: trunk/pollen-ui/src/main/webapp/poll/PollModification.tml =================================================================== --- trunk/pollen-ui/src/main/webapp/poll/PollModification.tml 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-ui/src/main/webapp/poll/PollModification.tml 2010-01-11 12:46:59 UTC (rev 2836) @@ -156,23 +156,25 @@ <fieldset> <legend>${stepLegend}</legend> <div t:type="loop" t:source="poll.choiceDTOs" t:value="choice" t:volatile="true"> - <div class="fleft choiceName"> - <t:if test="isTextChoices()"> - ${choice.name} - </t:if> - <t:if test="isDateChoices()"> - <t:output value="choiceNameAsDate" format="dateFormat"/> - </t:if> - <t:if test="isImgChoices()"> - ${choice.name} - </t:if> - - - <t:label for="desc" /> - </div> - <div class="fleft"> - <t:textarea cols="35" t:id="desc" t:value="choice.description" /> - </div> - <div class="clr" /> + <t:if test="!choice.hidden"> + <div class="fleft choiceName"> + <t:if test="isTextChoices()"> + ${choice.name} + </t:if> + <t:if test="isDateChoices()"> + <t:output value="choiceNameAsDate" format="dateFormat"/> + </t:if> + <t:if test="isImgChoices()"> + ${choice.name} + </t:if> + - + <t:label for="desc" /> + </div> + <div class="fleft"> + <t:textarea cols="35" t:id="desc" t:value="choice.description" /> + </div> + <div class="clr" /> + </t:if> </div> </fieldset> <div class="buttons"> Modified: trunk/pollen-ui/src/main/webapp/poll/Results.tml =================================================================== --- trunk/pollen-ui/src/main/webapp/poll/Results.tml 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-ui/src/main/webapp/poll/Results.tml 2010-01-11 12:46:59 UTC (rev 2836) @@ -34,26 +34,28 @@ <t:zone t:id="resultZone" show="show" update="show"> <!-- Victoire --> - <h4>${victoryMessage} - <br/> - <t:loop source="topRanking" value="result"> - <t:if test="textType"> - ${result.name} - </t:if> - <t:if test="dateType"> - <t:output value="resultNameAsDate" format="dateFormat"/> - </t:if> - <t:if test="imageType"> - <t:ImageContextLink t:id="imgContext" t:thumb="true" t:dir="poll.pollId" /> - <span t:type="ck/Tooltip" value="${result.name}" effect="appear"> - <t:eventlink event="displayImage" context="${result.name}"> - <t:image src="${result.name}" alt="${result.name}" t:context="imgContext" /> - </t:eventlink> - </span> - </t:if> - <br/> - </t:loop> - </h4> + <t:if test="victoryMessage"> + <h4>${victoryMessage} + <br/> + <t:loop source="topRanking" value="result"> + <t:if test="textType"> + ${result.name} + </t:if> + <t:if test="dateType"> + <t:output value="resultNameAsDate" format="dateFormat"/> + </t:if> + <t:if test="imageType"> + <t:ImageContextLink t:id="imgContext" t:thumb="true" t:dir="poll.pollId" /> + <span t:type="ck/Tooltip" value="${result.name}" effect="appear"> + <t:eventlink event="displayImage" context="${result.name}"> + <t:image src="${result.name}" alt="${result.name}" t:context="imgContext" /> + </t:eventlink> + </span> + </t:if> + <br/> + </t:loop> + </h4> + </t:if> <!-- Diagramme --> <div id="resultChart"> @@ -89,7 +91,9 @@ <div> <t:loop source="choices" value="choice"> - <t:chart width="400" height="300" values="choice" type="${type}"/> + <t:if test="choice"> + <t:chart width="400" height="300" values="choice" type="${type}"/> + </t:if> </t:loop> <!-- <t:if test="byGroup"> <div> @@ -101,6 +105,17 @@ </div> </div> + <!-- Diagramme par choix --> + <div id="resultChart"> + <div> + <t:loop source="choicesResults.entrySet()" value="choicesResult"> + <t:chart title="${choicesResult.key}" width="400" height="300" + values="choicesResult.value" type="${type}" + t:subtitles="subtitles.get(choicesResult.key)" /> + </t:loop> + </div> + </div> + <!-- Classement --> <t:remove> <div id="resultList"> Modified: trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml =================================================================== --- trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml 2010-01-11 12:46:59 UTC (rev 2836) @@ -58,60 +58,66 @@ </t:if> <t:if test="textType"> <t:loop t:source="poll.choiceDTOs" t:value="choiceOfPoll" volatile="true"> - <th> - <t:unless test="isDescNull()"> - <span t:type="ck/Tooltip" title="${message:description}" value="${choiceOfPoll.description}" effect="blind"> - <span class="desc">${choiceOfPoll.name}</span> - </span> - <p:else> - ${choiceOfPoll.name} - </p:else> - </t:unless> - <t:if test="${pollChoiceRunning}"> - <t:if test="creatorUser"> - <t:actionlink t:id="deleteChoice" context="choiceOfPoll.id" t:zone="pollZone"> - <img src="${asset:context:img/delete.png}" title="${message:delete}" alt="${message:delete}"/> - </t:actionlink> - </t:if> - </t:if> - </th> + <t:if test="!choiceOfPoll.hidden"> + <th> + <t:unless test="isDescNull()"> + <span t:type="ck/Tooltip" title="${message:description}" value="${choiceOfPoll.description}" effect="blind"> + <span class="desc">${choiceOfPoll.name}</span> + </span> + <p:else> + ${choiceOfPoll.name} + </p:else> + </t:unless> + <t:if test="${pollChoiceRunning}"> + <t:if test="creatorUser"> + <t:actionlink t:id="deleteChoice" context="choiceOfPoll.id" t:zone="pollZone"> + <img src="${asset:context:img/delete.png}" title="${message:delete}" alt="${message:delete}"/> + </t:actionlink> + </t:if> + </t:if> + </th> + </t:if> </t:loop> </t:if> <t:if test="dateType"> <t:loop t:source="poll.choiceDTOs" t:value="choiceOfPoll" volatile="true"> - <t:unless test="isDescNull()"> - <th class="desc"> - <span t:type="ck/Tooltip" title="${message:description}" value="${choiceOfPoll.description}" effect="blind"> - <t:output value="choiceNameAsDate" format="dateFormat"/> - </span> - </th> - <p:else> - <th> - <t:output value="choiceNameAsDate" format="dateFormat"/> - </th> - </p:else> - </t:unless> + <t:if test="!choiceOfPoll.hidden"> + <t:unless test="isDescNull()"> + <th class="desc"> + <span t:type="ck/Tooltip" title="${message:description}" value="${choiceOfPoll.description}" effect="blind"> + <t:output value="choiceNameAsDate" format="dateFormat"/> + </span> + </th> + <p:else> + <th> + <t:output value="choiceNameAsDate" format="dateFormat"/> + </th> + </p:else> + </t:unless> + </t:if> </t:loop> </t:if> <t:if test="imageType"> <t:ImageContextLink t:id="imgContext" t:thumb="true" t:dir="poll.pollId"/> <t:loop t:source="poll.choiceDTOs" t:value="choiceOfPoll" volatile="true"> - <t:unless test="isDescNull()"> - <th class="desc"> - <span t:type="ck/Tooltip" title="${message:description}" value="${choiceOfPoll.description}" effect="blind"> - <t:eventlink event="displayImage" context="${choiceOfPoll.id}"> - <t:image src="${choiceOfPoll.name}" alt="${choiceOfPoll.name}" t:context="imgContext"/> - </t:eventlink> - </span> - </th> - <p:else> - <th> - <t:eventlink event="displayImage" context="${choiceOfPoll.id}"> - <t:image src="${choiceOfPoll.name}" alt="${choiceOfPoll.name}" t:context="imgContext"/> - </t:eventlink> - </th> - </p:else> - </t:unless> + <t:if test="!choiceOfPoll.hidden"> + <t:unless test="isDescNull()"> + <th class="desc"> + <span t:type="ck/Tooltip" title="${message:description}" value="${choiceOfPoll.description}" effect="blind"> + <t:eventlink event="displayImage" context="${choiceOfPoll.id}"> + <t:image src="${choiceOfPoll.name}" alt="${choiceOfPoll.name}" t:context="imgContext"/> + </t:eventlink> + </span> + </th> + <p:else> + <th> + <t:eventlink event="displayImage" context="${choiceOfPoll.id}"> + <t:image src="${choiceOfPoll.name}" alt="${choiceOfPoll.name}" t:context="imgContext"/> + </t:eventlink> + </th> + </p:else> + </t:unless> + </t:if> </t:loop> </t:if> </tr> @@ -128,17 +134,22 @@ </p:else> </t:if> <t:loop t:source="poll.choiceDTOs" t:value="choiceOfVote" volatile="true"> - <th> - <t:if test="isNormalVoteCounting()"> - <t:checkbox t:value="addChoice" /> - </t:if> - <t:if test="isPercentageVoteCounting()"> - <t:textField t:value="choiceOfVote.value" size="3" t:validate="required, min=0, max=100"/>% - </t:if> - <t:if test="isCondorcetVoteCounting()"> - <t:textField t:id="condorcetInput" t:value="choiceOfVote.value" size="3" t:nulls="zero" t:validate="min=0, max=99"/> - </t:if> - </th> + <t:if test="!choiceOfVote.hidden"> + <th> + <t:if test="isNormalVoteCounting()"> + <t:checkbox t:value="addChoice" /> + </t:if> + <t:if test="isPercentageVoteCounting()"> + <t:textField t:value="choiceOfVote.value" size="3" t:validate="required, min=0, max=100"/>% + </t:if> + <t:if test="isCondorcetVoteCounting()"> + <t:textField t:id="condorcetInput" t:value="choiceOfVote.value" size="3" t:nulls="zero" t:validate="min=0, max=99"/> + </t:if> + <t:if test="isNumberVoteCounting()"> + <t:textField t:value="addNumberVote" size="3" /> + </t:if> + </th> + </t:if> </t:loop> </tr> </tfoot> @@ -169,35 +180,46 @@ </t:unless> </td> <t:loop t:source="poll.choiceDTOs" t:value="choiceOfPoll" volatile="true"> - <t:if test="${poll.anonymous}"> - <td class="anonymous">?</td> - <p:else> - <t:if test="isNormalVoteCounting()"> - <t:if test="isChoiceInVote(currentVoteChoice)"> - <td class="voted">OK</td> - <p:else> - <td class="notVoted"></td> - </p:else> - </t:if> - </t:if> - <t:if test="isPercentageVoteCounting()"> - <t:if test="isChoiceInVote(currentVoteChoice)"> - <td class="voted">${currentVoteChoice.value} %</td> - <p:else> - <td class="notVoted"></td> - </p:else> - </t:if> - </t:if> - <t:if test="isCondorcetVoteCounting()"> - <t:if test="isChoiceInVote(currentVoteChoice)"> - <td class="voted">${currentVoteChoice.value}</td> - <p:else> - <td class="notVoted"></td> - </p:else> - </t:if> - </t:if> - </p:else> - </t:if> + <t:if test="!choiceOfPoll.hidden"> + ${setCurrentVoteChoice()} + <t:if test="${poll.anonymous}"> + <td class="anonymous">?</td> + <p:else> + <t:if test="isNormalVoteCounting()"> + <t:if test="isChoiceInVote(currentVoteChoice)"> + <td class="voted">OK</td> + <p:else> + <td class="notVoted"></td> + </p:else> + </t:if> + </t:if> + <t:if test="isPercentageVoteCounting()"> + <t:if test="isChoiceInVote(currentVoteChoice)"> + <td class="voted">${currentVoteChoice.value} %</td> + <p:else> + <td class="notVoted"></td> + </p:else> + </t:if> + </t:if> + <t:if test="isCondorcetVoteCounting()"> + <t:if test="isChoiceInVote(currentVoteChoice)"> + <td class="voted">${currentVoteChoice.value}</td> + <p:else> + <td class="notVoted"></td> + </p:else> + </t:if> + </t:if> + <t:if test="isNumberVoteCounting()"> + <t:if test="isChoiceInVote(currentVoteChoice)"> + <td class="voted">${currentVoteChoice.value}</td> + <p:else> + <td class="notVoted"></td> + </p:else> + </t:if> + </t:if> + </p:else> + </t:if> + </t:if> </t:loop> </tr> </t:loop> @@ -207,7 +229,9 @@ <t:PageLink t:page="poll/results" t:context="${poll.pollId}">${message:results}</t:PageLink> </td> <t:loop t:source="poll.choiceDTOs" t:value="choiceOfPoll" volatile="true"> - <td class="result">${currentChoiceResult}</td> + <t:if test="!choiceOfPoll.hidden"> + <td class="result">${currentChoiceResult}</td> + </t:if> </t:loop> </tr> </t:if> Modified: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/VoteCountingType.java =================================================================== --- trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/VoteCountingType.java 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/common/VoteCountingType.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -17,5 +17,5 @@ package org.chorem.pollen.common; public enum VoteCountingType { - NORMAL, PERCENTAGE, CONDORCET; + NORMAL, PERCENTAGE, CONDORCET, NUMBER; } Modified: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/Choice.java =================================================================== --- trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/Choice.java 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/Choice.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -35,6 +35,10 @@ */ private String idChoice; /** + * nom du choix + */ + private String name; + /** * valeur du choix déterminé par le dépouillement */ private double value; @@ -55,6 +59,17 @@ } /** + * Constructeur + * + * @param id : identifiant du choix + * @param name : nom du choix + */ + public Choice(String id, String name) { + this(id); + this.name = name; + } + + /** * setValue : Mise à jour de la valeur du choix * * @param value : nouvelle valeur @@ -80,6 +95,15 @@ public String getIdChoice() { return this.idChoice; } + + /** + * getName : Renvoie le nom du choix + * + * @return nom du choix + */ + public String getName() { + return this.name; + } /** * getGroups : Renvoie la map des groupes 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 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/CondorcetMethod.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -16,6 +16,7 @@ package org.chorem.pollen.votecounting.business; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -25,6 +26,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.votecounting.dto.ChoiceDTO; +import org.chorem.pollen.votecounting.utils.PercentageBehavior; +import org.chorem.pollen.votecounting.utils.Utils; /** * Méthode de dépouillement Condorcet. @@ -47,7 +51,7 @@ private static final Log log = LogFactory.getLog(CondorcetMethod.class); @Override - public void executeMethod(List<Choice> choices, boolean byGroup) { + public void executeCounting(List<Choice> choices, boolean byGroup) { if (byGroup) { initPersonVotes(choices); initGroupVotes(choices); @@ -315,4 +319,11 @@ }*/ } } + + @Override + public void executeStats(List<Choice> choices, boolean groupCounting, + Choice choice, ChoiceDTO choiceDTO) { + List<PercentageBehavior> list = new ArrayList<PercentageBehavior>(choices); + choiceDTO.setPercentage(Utils.calculatePercentage(choice, list)); + } } \ No newline at end of file Modified: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/Context.java =================================================================== --- trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/Context.java 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/Context.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -21,6 +21,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.votecounting.dto.ChoiceDTO; +import org.chorem.pollen.votecounting.dto.PollChoiceDTO; +import org.chorem.pollen.votecounting.utils.Utils; /** * Contexte du dépouillement du sondage (PATTERN STRATEGY). @@ -41,7 +44,7 @@ /** * Liste des choix liés au contexte et résultats */ - private List<Choice> choices, results; + private List<Choice> choices, hiddenChoices, results; /** * Méthode de dépouillement choisie pour ce contexte */ @@ -56,6 +59,7 @@ public Context(Method method, boolean groupCounting) { this.groupCounting = groupCounting; this.choices = new ArrayList<Choice>(); + this.hiddenChoices = new ArrayList<Choice>(); this.results = new ArrayList<Choice>(); this.method = method; } @@ -68,12 +72,18 @@ */ public Choice getChoice(String idChoice) { for (Choice choice : this.choices) { - if (choice.getIdChoice().equals(idChoice)) + if (choice.getIdChoice().equals(idChoice)) { return choice; + } } + for (Choice choice : this.hiddenChoices) { + if (choice.getIdChoice().equals(idChoice)) { + return choice; + } + } return null; } - + /** * Renvoie la liste des choix * @@ -84,6 +94,15 @@ } /** + * Renvoie la liste des choix cachés + * + * @return liste des choix cachés + */ + public List<Choice> getHiddenChoices() { + return this.hiddenChoices; + } + + /** * Renvoie la liste des résultats * * @return liste des choix résultats @@ -97,11 +116,20 @@ * * @param idChoice : identifiant du choix */ - public void addChoice(String idChoice) { - this.choices.add(new Choice(idChoice)); + public void addChoice(PollChoiceDTO choice) { + this.choices.add(new Choice(choice.getIdChoice(), choice.getName())); } /** + * Ajout d'un nouveau choix au contexte + * + * @param idChoice : identifiant du choix + */ + public void addHiddenChoice(PollChoiceDTO choice) { + this.hiddenChoices.add(new Choice(choice.getIdChoice(), choice.getName())); + } + + /** * Ajout d'un groupe pour l'ensemble des choix du contexte * * @param idGroup : identifiant du groupe @@ -111,22 +139,44 @@ for (Choice choice : this.choices) { choice.addGroup(idGroup, weight); } + for (Choice choice : this.hiddenChoices) { + choice.addGroup(idGroup, weight); + } } /** + * Test si le choix est un résultat d'après le contexte A utiliser après + * dépouillement sinon aucun résultat + * + * @param choice : choix à tester + * @return true si le choix est un résultat, false sinon + */ + private boolean isChoiceResult(Choice choice) { + for (Choice res : results) { + if (choice.getIdChoice().equals(res.getIdChoice())) { + return true; + } + } + return false; + } + + /** * Execution de la méthode de dépouillement et calcul des choix résultats * * @return liste de choix résultats */ - public boolean execute() { + public boolean executeCounting() { try { - method.executeMethod(choices, groupCounting); + method.executeCounting(choices, groupCounting); + method.executeCounting(hiddenChoices, groupCounting); } catch (Exception e) { log.error("L'exécution du dépouillement a échoué", e); return false; } + this.results.clear(); Choice result = new Choice(""); + for (Choice curr : this.choices) { if (curr.value() > result.value()) { result = curr; @@ -135,8 +185,42 @@ this.results.add(curr); } } + this.results.add(result); return true; } + public List<ChoiceDTO> executeStats() { + List<ChoiceDTO> resChoices = new ArrayList<ChoiceDTO>(); + + try { + for (Choice choice : choices) { + ChoiceDTO choiceDTO = new ChoiceDTO(); + + choiceDTO.setIdChoice(choice.getIdChoice()); + choiceDTO.setName(choice.getName()); + choiceDTO.setValue(choice.getValue()); + choiceDTO.setResult(isChoiceResult(choice)); + choiceDTO.setNbVotes(Utils.calculateNbVotes(choice.getGroups(), groupCounting)); + + method.executeStats(choices, groupCounting, choice, choiceDTO); + resChoices.add(choiceDTO); + } + + for (Choice choice : hiddenChoices) { + ChoiceDTO choiceDTO = new ChoiceDTO(); + choiceDTO.setIdChoice(choice.getIdChoice()); + choiceDTO.setName(choice.getName()); + choiceDTO.setValue(choice.getValue()); + resChoices.add(choiceDTO); + } + + } catch (Exception e) { + log.error("L'exécution des statistiques a échoué", e); + resChoices = new ArrayList<ChoiceDTO>(); + } + + return resChoices; + } + } \ No newline at end of file Modified: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/Method.java =================================================================== --- trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/Method.java 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/Method.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -18,11 +18,33 @@ import java.util.List; +import org.chorem.pollen.votecounting.dto.ChoiceDTO; + /** * Méthode de dépouillement. * * @version $Id$ */ public interface Method { - public void executeMethod(List<Choice> choices, boolean group); + /** + * Execute le dépouillement de l'ensemble des choix spécifiés. + * + * @param choices l'ensemble des choix à dépouiller + * @param groupCounting si le dépouillement doit être groupé + */ + public void executeCounting(List<Choice> choices, boolean groupCounting); + + /** + * Effectue des statistiques sur le <code>choice</code> specifié. + * + * La fonction <code>executeCounting</code> doit avoir été + * executée avant d'appeler cette fonction. + * + * @param choices l'ensemble des choix du dépouillement + * @param groupCounting si le dépouillement doit être groupé + * @param choice le choix sur lequel effectuer des statistiques + * @param choiceDTO le choix contenant les resultats statistiques + */ + public void executeStats(List<Choice> choices, boolean groupCounting, + Choice choice, ChoiceDTO choiceDTO); } \ No newline at end of file Added: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/NumberMethod.java =================================================================== --- trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/NumberMethod.java (rev 0) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/NumberMethod.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -0,0 +1,71 @@ +package org.chorem.pollen.votecounting.business; + +import java.util.List; + +import org.chorem.pollen.votecounting.dto.ChoiceDTO; + +/** + * Méthode de dépouillement pour vote de type number. + * + * @version $Revision$ $Date$ + * @since 1.2.2 + */ +public class NumberMethod extends StandardMethod { + @Override + public void executeCounting(List<Choice> choices, boolean byGroup) { + calculateGroups(choices); +// if (byGroup) { +// calculateChoicesByGroup(choices); +// } + } + + public void calculateGroups(List<Choice> choices) { + for (Choice choice : choices) { + double totalChoice = 0.; + + for (Group group : choice.getGroups()) { + double totalGroup = 0.; + + for (Vote vote : group.getVotes()) { + double value = vote.getValue(); + + if (value >= 0) { + totalGroup += vote.getValue() * vote.getWeight(); + } + } + + group.setValue(totalGroup); + totalChoice += totalGroup; + } + + choice.setValue(totalChoice); + } + } + + @Override + public void executeStats(List<Choice> choices, boolean groupCounting, + Choice choice, ChoiceDTO choiceDTO) { + + super.executeStats(choices, groupCounting, choice, choiceDTO); + + int nbBlankVotes = 0; + double average = 0; + int nbVotes = 0; + + for (Group group : choice.getGroups()) { + for (Vote vote : group.getVotes()) { + nbVotes = nbVotes + 1; + if (vote.getValue() < 0) { + nbBlankVotes = nbBlankVotes + 1; + } + } + } + + if (nbVotes - nbBlankVotes > 0) { + average = choice.value() / (nbVotes - nbBlankVotes); + } + + choiceDTO.setAverage(average); + choiceDTO.setNbBlankVotes(nbBlankVotes); + } +} Property changes on: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/NumberMethod.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Date Author Id Revision HeadURL Added: svn:eol-style + native 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 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/StandardMethod.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -21,6 +21,10 @@ import java.util.List; import java.util.Map; +import org.chorem.pollen.votecounting.dto.ChoiceDTO; +import org.chorem.pollen.votecounting.utils.PercentageBehavior; +import org.chorem.pollen.votecounting.utils.Utils; + /** * Méthode de dépouillement standard. * @@ -29,7 +33,7 @@ public class StandardMethod implements Method { @Override - public void executeMethod(List<Choice> choices, boolean byGroup) { + public void executeCounting(List<Choice> choices, boolean byGroup) { calculateGroups(choices); if (byGroup) { calculateChoicesByGroup(choices); @@ -102,4 +106,11 @@ } return 0; } + + @Override + public void executeStats(List<Choice> choices, boolean groupCounting, + Choice choice, ChoiceDTO choiceDTO) { + List<PercentageBehavior> list = new ArrayList<PercentageBehavior>(choices); + choiceDTO.setPercentage(Utils.calculatePercentage(choice, list)); + } } \ No newline at end of file Modified: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/ChoiceDTO.java =================================================================== --- trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/ChoiceDTO.java 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/ChoiceDTO.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -24,13 +24,19 @@ public class ChoiceDTO { private String idChoice; - + + private String name; + private double value; private double percentage; + private double average; + private int nbVotes; + private int nbBlankVotes; + private boolean result; public ChoiceDTO() { @@ -52,6 +58,14 @@ this.idChoice = idChoice; } + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + public double getValue() { return value; } @@ -68,6 +82,14 @@ this.percentage = percentage; } + public double getAverage() { + return average; + } + + public void setAverage(double average) { + this.average = average; + } + public int getNbVotes() { return nbVotes; } @@ -76,6 +98,14 @@ this.nbVotes = nbVotes; } + public int getNbBlankVotes() { + return nbBlankVotes; + } + + public void setNbBlankVotes(int nbBlankVotes) { + this.nbBlankVotes = nbBlankVotes; + } + public boolean isResult() { return result; } @@ -83,5 +113,4 @@ public void setResult(boolean result) { this.result = result; } - } \ No newline at end of file Modified: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/PollChoiceDTO.java =================================================================== --- trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/PollChoiceDTO.java 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/PollChoiceDTO.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -22,6 +22,7 @@ * @version $Id$ */ public class PollChoiceDTO { + public static final String HIDDEN_PREFIX = "HIDDEN_"; private String idChoice; @@ -65,4 +66,11 @@ this.description = description; } + public boolean isHidden() { + if (name != null) { + return name.startsWith(HIDDEN_PREFIX); + } + + return false; + } } \ No newline at end of file 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 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ServiceVoteCountingImpl.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -16,7 +16,6 @@ package org.chorem.pollen.votecounting.services; -import java.util.ArrayList; import java.util.List; import org.apache.commons.logging.Log; @@ -25,7 +24,9 @@ import org.chorem.pollen.votecounting.business.Choice; import org.chorem.pollen.votecounting.business.CondorcetMethod; import org.chorem.pollen.votecounting.business.Context; +import org.chorem.pollen.votecounting.business.Group; import org.chorem.pollen.votecounting.business.Method; +import org.chorem.pollen.votecounting.business.NumberMethod; import org.chorem.pollen.votecounting.business.PercentageMethod; import org.chorem.pollen.votecounting.business.StandardMethod; import org.chorem.pollen.votecounting.dto.ChoiceDTO; @@ -108,31 +109,15 @@ // Création et remplissage du contexte this.createContext(poll.getVoteCounting()); this.fillContext(poll); + // Execution - if (!this.context.execute()) { + if (!context.executeCounting()) { return null; } + List<ChoiceDTO> resChoices = context.executeStats(); - // Transformation des résultats - List<ChoiceDTO> resChoices = new ArrayList<ChoiceDTO>(); - List choices = this.context.getChoices(); - - for (Choice choice : this.context.getChoices()) { - ChoiceDTO resChoice = new ChoiceDTO(); - resChoice.setIdChoice(choice.getIdChoice()); - resChoice.setNbVotes(this.calculateNbVotes(choice.getGroups(), - this.isByGroup)); - resChoice.setValue(choice.getValue()); - resChoice.setPercentage(Utils.calculatePercentage(choice, choices)); - resChoice.setResult(this.isChoiceResult(choice)); - if (log.isDebugEnabled()) { - log.debug(choice + " _ result ? " + resChoice.isResult()); - } - resChoices.add(resChoice); - } - VoteCountingResultDTO result = new VoteCountingResultDTO(); - result.setNbVotes(this.calculateNbVotes(poll.getVotingGroups(), + result.setNbVotes(Utils.calculateNbVotes(poll.getVotingGroups(), this.isByGroup)); result.setTypeVoteCounting(poll.getVoteCounting()); result.setByGroup(this.isByGroup); @@ -158,6 +143,9 @@ case CONDORCET: method = new CondorcetMethod(); break; + case NUMBER: + method = new NumberMethod(); + break; default: method = new StandardMethod(); } @@ -173,9 +161,12 @@ if (log.isDebugEnabled()) { log.debug("Ajout poll : " + poll.getPollId()); } - for (Object o : poll.getChoices()) { - PollChoiceDTO choice = (PollChoiceDTO) o; - this.context.addChoice(choice.getIdChoice()); + for (PollChoiceDTO choice : poll.getChoices()) { + if (choice.isHidden()) { + this.context.addHiddenChoice(choice); + } else { + this.context.addChoice(choice); + } } for (Object o : poll.getVotingGroups()) { VotingGroupDTO group = (VotingGroupDTO) o; @@ -211,8 +202,7 @@ log.debug("Ajout person : " + person.getVotingId() + " _ weight=" + person.getWeight()); } - for (Object o : person.getChoices()) { - VoteToChoiceDTO vote = (VoteToChoiceDTO) o; + for (VoteToChoiceDTO vote : person.getChoices()) { this.addVoteToContext(vote, person.getWeight(), person .getVotingId()); } @@ -230,36 +220,9 @@ log.debug("Ajout vote : " + vote.getValue() + " _ choice=" + vote.getIdChoice()); } - this.context.getChoice(vote.getIdChoice()) - .getGroup(this.currentIdGroup).addVote(vote.getValue(), weight, - votingID); + Choice choice = this.context.getChoice(vote.getIdChoice()); + Group group = choice.getGroup(this.currentIdGroup); + group.addVote(vote.getValue(), weight, votingID); } - /** - * Calcul le nombre de votes d'une liste - * - * @param list : liste d'éléments (doivent impléméntés ObjectWithList) - * @param byGroup : condition sur le calcul - * @return nombre de votes - */ - private int calculateNbVotes(List list, boolean byGroup) { - return Utils.mayCalculateSubElements(list, byGroup); - } - - /** - * Test si le choix est un résultat d'après le contexte A utiliser après - * dépouillement sinon aucun résultat - * - * @param choice : choix à tester - * @return true si le choix est un résultat, false sinon - */ - private boolean isChoiceResult(Choice choice) { - for (Choice res : this.context.getResults()) { - if (choice.getIdChoice().equals(res.getIdChoice())) { - return true; - } - } - return false; - } - } \ No newline at end of file Modified: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/utils/Utils.java =================================================================== --- trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/utils/Utils.java 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/utils/Utils.java 2010-01-11 12:46:59 UTC (rev 2836) @@ -28,35 +28,36 @@ public static double calculatePercentage(PercentageBehavior in, List<PercentageBehavior> list) { double total = 0.; - for (PercentageBehavior curr : list) + for (PercentageBehavior curr : list) { total += curr.value(); + } return (in.value() / total * 100); } /** + * Calcul le nombre de votes d'une liste + * + * @param list : liste d'éléments (doivent impléméntés ObjectWithList) + * @param byGroup : condition sur le calcul + * @return nombre de votes + */ + public static int calculateNbVotes(List list, boolean byGroup) { + return byGroup ? calculateNbSubElements(list) : list.size(); + } + + /** * Calcul le nombre de sous éléments d'une liste Les éléments du vecteur * doivent implémenter l'interface ListBehavior * * @param list : liste source * @return nombre de sous éléments */ - public static int calculateNbSubElements(List<ListBehavior<Object>> list) { + private static int calculateNbSubElements(List<ListBehavior<Object>> list) { int nbVotes = 0; - for (ListBehavior<Object> curr : list) + for (ListBehavior<Object> curr : list) { nbVotes += curr.list().size(); + } return nbVotes; } - /** - * Calcul le nombre de sous éléments d'une liste sous condition - * - * @param list : liste source - * @param calculate : condition pour calculer ou non le nombre de sous - * éléments - * @return nombre de sous éléments - */ - public static int mayCalculateSubElements(List<ListBehavior<Object>> list, - boolean calculate) { - return calculate ? calculateNbSubElements(list) : list.size(); - } } \ No newline at end of file Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-01-07 03:24:47 UTC (rev 2835) +++ trunk/pom.xml 2010-01-11 12:46:59 UTC (rev 2836) @@ -44,7 +44,7 @@ <dependency> <groupId>org.nuiton</groupId> <artifactId>nuiton-utils</artifactId> - <version>1.1.3-SNAPSHOT</version> + <version>${nuiton-utils.version}</version> </dependency> <dependency> <groupId>org.nuiton.topia</groupId> @@ -297,7 +297,7 @@ <topia.version>2.2.2</topia.version> <eugene.version>1.0.1</eugene.version> <tapestry.version>5.1.0.5</tapestry.version> - + <nuiton-utils.version>1.1.2</nuiton-utils.version> <!--Multilanguage maven-site --> <maven.site.locales>en,fr</maven.site.locales>