Pollen-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
March 2012
- 3 participants
- 68 discussions
r3171 - in branches/pollen-1.2.6-struts2/pollen-persistence/src/main: java/org/chorem/pollen java/org/chorem/pollen/business/persistence xmi
by tchemit@users.chorem.org 08 Mar '12
by tchemit@users.chorem.org 08 Mar '12
08 Mar '12
Author: tchemit
Date: 2012-03-08 01:20:00 +0100 (Thu, 08 Mar 2012)
New Revision: 3171
Url: http://chorem.org/repositories/revision/pollen/3171
Log:
add some usefull function for binding + poll firs method
Added:
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java
Modified:
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/PollenFunctions.java
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/xmi/pollen.zargo
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/PollenFunctions.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/PollenFunctions.java 2012-03-07 23:02:51 UTC (rev 3170)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/PollenFunctions.java 2012-03-08 00:20:00 UTC (rev 3171)
@@ -24,9 +24,26 @@
package org.chorem.pollen;
import com.google.common.base.Function;
+import com.google.common.collect.Lists;
+import org.chorem.pollen.business.persistence.Choice;
+import org.chorem.pollen.business.persistence.Comment;
+import org.chorem.pollen.business.persistence.PersonToList;
+import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.UserAccount;
+import org.chorem.pollen.business.persistence.Vote;
+import org.chorem.pollen.business.persistence.VoteToChoice;
+import org.chorem.pollen.business.persistence.VotingList;
+import org.chorem.pollen.votecounting.business.NumberMethod;
+import org.chorem.pollen.votecounting.dto.CommentDTO;
+import org.chorem.pollen.votecounting.dto.PollChoiceDTO;
+import org.chorem.pollen.votecounting.dto.PollDTO;
+import org.chorem.pollen.votecounting.dto.VoteToChoiceDTO;
+import org.chorem.pollen.votecounting.dto.VotingGroupDTO;
+import org.chorem.pollen.votecounting.dto.VotingPersonDTO;
import org.nuiton.topia.persistence.TopiaEntity;
+import java.util.List;
+
/**
* Usefull pollen functions.
*
@@ -49,4 +66,121 @@
}
};
+ public static final Function<Poll, PollDTO> POLL_TO_BEAN = new Function<Poll, PollDTO>() {
+ @Override
+ public PollDTO apply(Poll input) {
+ PollDTO result = new PollDTO(input.getPollId());
+ result.setTitle(input.getTitle());
+ result.setDescription(input.getDescription());
+ result.setBeginChoiceDate(input.getBeginChoiceDate());
+ result.setBeginDate(input.getBeginDate());
+ result.setEndDate(input.getEndDate());
+ result.setAnonymous(input.isAnonymous());
+ result.setAnonymousVoteAllowed(input.isAnonymousVoteAllowed());
+ result.setPublicResults(input.isPublicResults());
+ result.setContinuousResults(input.isContinuousResults());
+ result.setChoiceAddAllowed(input.isChoiceAddAllowed());
+ result.setClosed(input.isClosed());
+ result.setCreatorId(input.getCreator().getVotingId());
+ result.setCreatorEmail(input.getCreator().getEmail());
+ result.setMaxChoiceNb(input.getMaxChoiceNb());
+ result.setPollType(input.getPollType());
+ result.setChoiceType(input.getChoiceType());
+ result.setVoteCounting(input.getVoteCountingType());
+
+ result.setComments(Lists.transform(input.getComment(),
+ COMMENT_TO_BEAN));
+
+ result.setChoices(Lists.transform(input.getChoice(),
+ CHOICE_TO_BEAN));
+
+ if (!input.isVotingListEmpty()) {
+
+ result.setVotingGroups(Lists.transform(input.getVotingList(),
+ VOTING_LIST_TO_BEAN
+ ));
+ } else {
+ // un groupe par défaut si il y en a pas
+ VotingGroupDTO group = new VotingGroupDTO("unique", 1);
+ group.setName("unique");
+ List<VotingPersonDTO> votes = Lists.transform(input.getVote(),
+ VOTE_TO_BEAN);
+ group.setVotingPersons(votes);
+ result.getVotingGroups().add(group);
+ }
+ return result;
+ }
+ };
+
+ public static final Function<Comment, CommentDTO> COMMENT_TO_BEAN = new Function<Comment, CommentDTO>() {
+ @Override
+ public CommentDTO apply(Comment input) {
+ CommentDTO result = new CommentDTO(
+ input.getPollAccount().getVotingId(), input.getText());
+ return result;
+ }
+ };
+
+ public static final Function<Choice, PollChoiceDTO> CHOICE_TO_BEAN = new Function<Choice, PollChoiceDTO>() {
+ @Override
+ public PollChoiceDTO apply(Choice input) {
+ PollChoiceDTO result = new PollChoiceDTO(input.getTopiaId());
+ String choiceName = input.getName();
+ result.setName(choiceName);
+ result.setHidden(choiceName != null &&
+ choiceName.startsWith(NumberMethod.HIDDEN_PREFIX));
+ result.setDescription(input.getDescription());
+ return result;
+ }
+ };
+
+ public static 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) {
+ VotingPersonDTO result =
+ new VotingPersonDTO(input.getPollAccount().getVotingId(), input.getWeight());
+ result.setEmail(input.getPollAccount().getEmail());
+
+ for (VoteToChoice vToChoice : input.getChoiceVoteToChoice()) {
+ if (vToChoice != null && vToChoice.getChoice() != null) {
+ VoteToChoiceDTO bean = VOTE_TO_CHOICE_TO_BEAN.apply(vToChoice);
+ result.getChoices().add(bean);
+ }
+ }
+ return result;
+ }
+ };
+
+ public static final Function<VoteToChoice, VoteToChoiceDTO> VOTE_TO_CHOICE_TO_BEAN = new Function<VoteToChoice, VoteToChoiceDTO>() {
+ @Override
+ public VoteToChoiceDTO apply(VoteToChoice input) {
+ VoteToChoiceDTO result = new VoteToChoiceDTO(
+ input.getChoice().getTopiaId(),
+ input.getVoteValue());
+
+ return result;
+ }
+ };
+
}
Added: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/PollImpl.java 2012-03-08 00:20:00 UTC (rev 3171)
@@ -0,0 +1,22 @@
+package org.chorem.pollen.business.persistence;
+
+import com.google.common.base.Preconditions;
+
+public class PollImpl extends PollAbstract {
+
+ private static final long serialVersionUID = 1L;
+
+ public Vote getVoteByPollAccount(PollAccount account) {
+ Preconditions.checkNotNull(account);
+ Vote resultVote = null;
+ if (!isVoteEmpty()) {
+ for (Vote vote : this.getVote()) {
+ if (account.equals(vote.getPollAccount())) {
+ resultVote = vote;
+ break;
+ }
+ }
+ }
+ return resultVote;
+ }
+} //PollImpl
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/xmi/pollen.zargo
===================================================================
(Binary files differ)
1
0
r3170 - in branches/pollen-1.2.6-struts2/pollen-votecounting: . src/main/java/org/chorem/pollen/votecounting/business src/main/java/org/chorem/pollen/votecounting/services
by tchemit@users.chorem.org 07 Mar '12
by tchemit@users.chorem.org 07 Mar '12
07 Mar '12
Author: tchemit
Date: 2012-03-08 00:02:51 +0100 (Thu, 08 Mar 2012)
New Revision: 3170
Url: http://chorem.org/repositories/revision/pollen/3170
Log:
debut de refonte du module votecounting
Added:
branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ImportExportService.java
branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/VoteCountingService.java
Modified:
branches/pollen-1.2.6-struts2/pollen-votecounting/pom.xml
branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/Context.java
Modified: branches/pollen-1.2.6-struts2/pollen-votecounting/pom.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-votecounting/pom.xml 2012-03-07 17:10:58 UTC (rev 3169)
+++ branches/pollen-1.2.6-struts2/pollen-votecounting/pom.xml 2012-03-07 23:02:51 UTC (rev 3170)
@@ -32,6 +32,14 @@
<artifactId>nuiton-i18n</artifactId>
</dependency>
<dependency>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuiton-utils</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
Modified: branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/Context.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/Context.java 2012-03-07 17:10:58 UTC (rev 3169)
+++ branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/Context.java 2012-03-07 23:02:51 UTC (rev 3170)
@@ -90,7 +90,7 @@
}
return null;
}
-
+
/**
* Renvoie la liste des choix
*
@@ -108,7 +108,7 @@
public List<Choice> getHiddenChoices() {
return this.hiddenChoices;
}
-
+
/**
* Renvoie la liste des résultats
*
@@ -135,7 +135,7 @@
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
*
@@ -166,24 +166,20 @@
}
return false;
}
-
+
/**
* Execution de la méthode de dépouillement et calcul des choix résultats
*
* @return liste de choix résultats
*/
public boolean executeCounting() {
- try {
- method.executeCounting(choices, groupCounting);
- method.executeCounting(hiddenChoices, groupCounting);
- } catch (Exception e) {
- log.error("L'exécution du dépouillement a échoué", e);
- return false;
- }
-
+
+ method.executeCounting(choices, groupCounting);
+ method.executeCounting(hiddenChoices, groupCounting);
+
this.results.clear();
Choice result = new Choice("");
-
+
for (Choice curr : this.choices) {
if (curr.value() > result.value()) {
result = curr;
@@ -192,7 +188,7 @@
this.results.add(curr);
}
}
-
+
this.results.add(result);
return true;
}
@@ -203,17 +199,17 @@
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());
@@ -221,13 +217,13 @@
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
Added: branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ImportExportService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ImportExportService.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ImportExportService.java 2012-03-07 23:02:51 UTC (rev 3170)
@@ -0,0 +1,610 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.votecounting.services;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.logging.Log;
+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;
+import org.chorem.pollen.votecounting.dto.PollChoiceDTO;
+import org.chorem.pollen.votecounting.dto.PollDTO;
+import org.chorem.pollen.votecounting.dto.PollExportDTO;
+import org.chorem.pollen.votecounting.dto.VoteCountingResultDTO;
+import org.chorem.pollen.votecounting.dto.VoteToChoiceDTO;
+import org.chorem.pollen.votecounting.dto.VotingGroupDTO;
+import org.chorem.pollen.votecounting.dto.VotingPersonDTO;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.Format;
+import org.jdom.output.XMLOutputter;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Service to import / export a poll to or from his xml representation.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class ImportExportService {
+
+ public static final String POLL = "poll";
+
+ public static final String TITLE1 = "title";
+
+ public static final String TITLE = TITLE1;
+
+ public static final String CHOICE = "choice";
+
+ public static final String ID_CHOICE = "idChoice";
+
+ public static final String VALUE = "value";
+
+ public static final String PERCENTAGE = "percentage";
+
+ public static final String NB_VOTES = "nbVotes";
+
+ public static final String IS_BY_GROUP = "isByGroup";
+
+ public static final String CHOICES = "choices";
+
+ public static final String CHOICE_RESULT = "choiceResult";
+
+ public static final String ID_POLL = "idPoll";
+
+ public static final String VOTE_COUNTING_RESULT = "voteCountingResult";
+
+ public static final String DESCRIPTION = "description";
+
+ public static final String NAME = "name";
+
+ public static final String POLL_CHOICE = "pollChoice";
+
+ public static final String VOTING_PERSON = "votingPerson";
+
+ public static final String VOTING_ID = "votingId";
+
+ public static final String WEIGHT = "weight";
+
+ public static final String EMAIL = "email";
+
+ public static final String COMMENT = "comment";
+
+ public static final String VOTING_PERSONS = "votingPersons";
+
+ public static final String ID_GROUP = "idGroup";
+
+ public static final String GROUP = "group";
+
+ public static final String POLL_CHOICES = "pollChoices";
+
+ public static final String VOTE_COUNTING_RESULTS = "voteCountingResults";
+
+ public static final String GROUPS = "groups";
+
+ public static final String COMMENTS = "comments";
+
+ public static final String CREATOR_ID = "creatorId";
+
+ public static final String CREATOR_EMAIL = "creatorEmail";
+
+ public static final String MAX_CHOICE_NB = "maxChoiceNb";
+
+ public static final String POLL_EXPORT = "pollExport";
+
+ public static final String POLL_ID = "pollId";
+
+ public static final String POLL_TYPE = "pollType";
+
+ public static final String CHOICE_TYPE = "choiceType";
+
+ public static final String VOTE_COUNTING = "voteCounting";
+
+ public static final String CLOSED = "closed";
+
+ public static final String CHOICE_ADD_ALLOWED = "choiceAddAllowed";
+
+ public static final String ANONYMOUS_VOTE_ALLOWED = "anonymousVoteAllowed";
+
+ public static final String ANONYMOUS = "anonymous";
+
+ public static final String PUBLIC_RESULTS = "publicResults";
+
+ public static final String CONTINUOUS_RESULTS = "continuousResults";
+
+ public static final String VALUE_TRUE = "true";
+
+ public static final String VALUE_FALSE = "false";
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(ImportExportService.class);
+
+ /**
+ * Export the given poll to an xml representation.
+ *
+ * @param exportPoll the poll to export
+ * @return the xml representation of the given poll
+ */
+ public String exportToXml(PollExportDTO exportPoll) {
+
+ Document document = toDOM(exportPoll);
+
+ // Mise en forme classique avec getPrettyFormat()
+ XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
+ String content = sortie.outputString(document);
+
+ if (log.isDebugEnabled()) {
+ log.debug(content);
+ }
+ return content;
+ }
+
+ /**
+ * Import into a {@link PollExportDTO} his xml representation from the
+ * given file.
+ *
+ * @param file file to load
+ * @return the loaded dto from the xml representation.
+ * @throws JDOMException if could not load xml from file
+ * @throws IOException if could not load the file
+ */
+ public PollExportDTO importFromXml(File file) throws JDOMException, IOException {
+
+ // Création d'un nouveau document JDOM avec le fichier XML en argument
+ Document document = new SAXBuilder().build(file);
+
+ // Initialisation d'un nouvel élément racine
+ Element racine = document.getRootElement();
+
+ PollExportDTO result = toDTO(racine);
+
+ return result;
+ }
+
+ protected PollExportDTO toDTO(Element racine) {
+
+ // Création du sondage
+ Element pollElm = racine.getChild(POLL);
+
+ PollDTO poll = new PollDTO(pollElm.getAttributeValue(POLL_ID));
+ poll.setTitle(pollElm.getChild(TITLE).getText());
+ poll.setDescription(pollElm.getChild(DESCRIPTION).getText());
+ poll.setCreatorId(pollElm.getChild(CREATOR_ID).getText());
+ poll.setCreatorEmail(pollElm.getChild(CREATOR_EMAIL).getText());
+ poll.setMaxChoiceNb(Integer.parseInt(
+ pollElm.getChild(MAX_CHOICE_NB).getText()));
+
+ poll.setPollType(
+ PollType.valueOf(pollElm.getAttributeValue(POLL_TYPE)));
+ poll.setChoiceType(ChoiceType.valueOf(
+ pollElm.getAttributeValue(CHOICE_TYPE)));
+ poll.setVoteCounting(VoteCountingType.valueOf(
+ pollElm.getAttributeValue(VOTE_COUNTING)));
+ poll.setClosed(Boolean.valueOf(pollElm.getAttributeValue(CLOSED)));
+ poll.setChoiceAddAllowed(Boolean.valueOf(
+ pollElm.getAttributeValue(CHOICE_ADD_ALLOWED)));
+ poll.setAnonymousVoteAllowed(Boolean.valueOf(
+ pollElm.getAttributeValue(ANONYMOUS_VOTE_ALLOWED)));
+ poll.setAnonymous(Boolean.valueOf(
+ pollElm.getAttributeValue(ANONYMOUS)));
+ poll.setPublicResults(Boolean.valueOf(pollElm.getAttributeValue(PUBLIC_RESULTS)));
+ poll.setContinuousResults(Boolean.valueOf(
+ pollElm.getAttributeValue(CONTINUOUS_RESULTS)));
+
+ // Ajout des commentaires
+ Element commentsElm = pollElm.getChild(COMMENTS);
+ List<Element> listComments = commentsElm.getChildren(COMMENT);
+ List vectorComments = toComments(listComments);
+
+ poll.setComments(vectorComments);
+
+ // Ajout des groupes
+ Element groupsElm = pollElm.getChild(GROUPS);
+ List<Element> listGroups = groupsElm.getChildren(GROUP);
+ List vectorGroups = toVotingGroups(listGroups);
+
+ poll.setVotingGroups(vectorGroups);
+
+ // Ajout des choix
+ Element pollChoicesElm = pollElm.getChild(POLL_CHOICES);
+ List<Element> listPollChoices = pollChoicesElm.getChildren(POLL_CHOICE);
+ List<PollChoiceDTO> vectorPollChoices = toPollChoices(listPollChoices);
+
+ poll.setChoices(vectorPollChoices);
+
+ // Ajout des résultats
+ Element voteCountingResultsElm = racine.getChild(VOTE_COUNTING_RESULTS);
+ List<Element> listVoteCountingResults =
+ voteCountingResultsElm.getChildren(VOTE_COUNTING_RESULT);
+ List<VoteCountingResultDTO> vectorVoteCountingResults =
+ toVoteCountingResults(listVoteCountingResults);
+
+ // Création du sondage PollExportDTO
+ PollExportDTO pollExport = new PollExportDTO();
+ pollExport.setPollId(poll.getPollId());
+ pollExport.setPoll(poll);
+ pollExport.setVoteCountingResults(vectorVoteCountingResults);
+
+ return pollExport;
+ }
+
+ protected List<CommentDTO> toComments(List<Element> listComments) {
+ List<CommentDTO> vectorComments = Lists.newArrayList();
+
+ for (Element commentElm : listComments) {
+ CommentDTO comment = new CommentDTO(
+ commentElm.getAttributeValue(VOTING_ID),
+ commentElm.getText());
+ vectorComments.add(comment);
+ }
+
+ return vectorComments;
+ }
+
+ protected List<VotingGroupDTO> toVotingGroups(List<Element> listGroups) {
+ List<VotingGroupDTO> vectorGroups = Lists.newArrayList();
+
+ for (Element groupElm : listGroups) {
+ VotingGroupDTO group = new VotingGroupDTO(
+ groupElm.getAttributeValue(ID_GROUP),
+ Double.parseDouble((groupElm.getAttributeValue(WEIGHT))));
+
+ group.setName(groupElm.getAttributeValue(NAME));
+
+ Element votingPersonsElm = groupElm.getChild(VOTING_PERSONS);
+ List<Element> listVotingPersons = votingPersonsElm
+ .getChildren(VOTING_PERSON);
+ List vectorVotingPersons = toVotingPersons(listVotingPersons);
+
+ group.setVotingPersons(vectorVotingPersons);
+
+ vectorGroups.add(group);
+ }
+
+ return vectorGroups;
+ }
+
+ protected List<VotingPersonDTO> toVotingPersons(List<Element> listVotingPersons) {
+ List<VotingPersonDTO> vectorVotingPersons = Lists.newArrayList();
+
+ for (Element votingPersonElm : listVotingPersons) {
+ VotingPersonDTO votingPerson = new VotingPersonDTO(
+ votingPersonElm.getAttributeValue(VOTING_ID),
+ Double.parseDouble(votingPersonElm.getAttributeValue(WEIGHT)));
+
+ votingPerson.setEmail(votingPersonElm.getChild(EMAIL).getValue());
+ votingPerson.setComment(votingPersonElm.getChild(COMMENT)
+ .getValue());
+
+ Element choicesElm = votingPersonElm.getChild(CHOICES);
+
+ List<Element> listVoteToChoices = choicesElm.getChildren(CHOICE);
+ List vectorVoteToChoices = toVoteToChoices(listVoteToChoices);
+
+ votingPerson.setChoices(vectorVoteToChoices);
+ vectorVotingPersons.add(votingPerson);
+ }
+
+ return vectorVotingPersons;
+ }
+
+ protected List<VoteToChoiceDTO> toVoteToChoices(List<Element> listVoteToChoices) {
+ List<VoteToChoiceDTO> vectorVoteToChoices = Lists.newArrayList();
+
+ for (Element voteToChoiceElm : listVoteToChoices) {
+ VoteToChoiceDTO voteToChoice = new VoteToChoiceDTO(
+ voteToChoiceElm.getAttributeValue(ID_CHOICE),
+ Double.parseDouble(voteToChoiceElm.getAttributeValue(VALUE)));
+ vectorVoteToChoices.add(voteToChoice);
+ }
+
+ return vectorVoteToChoices;
+ }
+
+ protected List<PollChoiceDTO> toPollChoices(List<Element> listPollChoices) {
+ List<PollChoiceDTO> vectorPollChoices = Lists.newArrayList();
+
+ for (Element pollChoiceElm : listPollChoices) {
+ PollChoiceDTO pollChoice = new PollChoiceDTO(
+ pollChoiceElm.getAttributeValue(ID_CHOICE));
+
+ String pollChoiceName = pollChoiceElm.getChild(NAME).getValue();
+ pollChoice.setName(pollChoiceName);
+ pollChoice.setHidden(pollChoiceName != null
+ && pollChoiceName.startsWith(NumberMethod.HIDDEN_PREFIX));
+
+ pollChoice.setDescription(pollChoiceElm.getChild(DESCRIPTION)
+ .getValue());
+
+ vectorPollChoices.add(pollChoice);
+ }
+
+ return vectorPollChoices;
+ }
+
+ protected List<VoteCountingResultDTO> toVoteCountingResults(List<Element> listVoteCountingResults) {
+ List<VoteCountingResultDTO> vectorVoteCountingResults = Lists.newArrayList();
+
+ for (Element voteCountingResultElm : listVoteCountingResults) {
+ VoteCountingResultDTO voteCountingResult = new VoteCountingResultDTO();
+ voteCountingResult.setIdPoll(
+ voteCountingResultElm.getAttributeValue(ID_POLL));
+ voteCountingResult.setNbVotes(
+ Integer.parseInt(voteCountingResultElm.getChild(NB_VOTES)
+ .getValue()));
+ voteCountingResult.setChoiceResult(voteCountingResultElm.getChild(
+ CHOICE_RESULT).getValue());
+ voteCountingResult.setByGroup(
+ Boolean.parseBoolean(
+ voteCountingResultElm.getChild(IS_BY_GROUP).getValue()));
+
+ Element choicesElm = voteCountingResultElm.getChild(CHOICES);
+ List<Element> listChoices = choicesElm.getChildren(CHOICE);
+ List vectorChoices = toChoices(listChoices);
+ voteCountingResult.setChoices(vectorChoices);
+ vectorVoteCountingResults.add(voteCountingResult);
+ }
+
+ return vectorVoteCountingResults;
+ }
+
+ protected List<ChoiceDTO> toChoices(List<Element> listChoices) {
+ List<ChoiceDTO> vectorChoices = Lists.newArrayList();
+
+ for (Element choiceElm : listChoices) {
+ ChoiceDTO choice = new ChoiceDTO(
+ choiceElm.getAttribute(ID_CHOICE).getName(),
+ Double.parseDouble(choiceElm.getAttribute(VALUE).getValue()),
+ Double.parseDouble(choiceElm.getChild(PERCENTAGE).getValue()),
+ Integer.parseInt((choiceElm.getChild(NB_VOTES).getValue())));
+ vectorChoices.add(choice);
+ }
+
+ return vectorChoices;
+ }
+
+ protected Document toDOM(PollExportDTO exportPoll) {
+
+ PollDTO poll = exportPoll.getPoll();
+
+ List<VoteCountingResultDTO> voteCountingResults =
+ exportPoll.getVoteCountingResults();
+
+ // Création de la racine et du document
+ Element racine = new Element(POLL_EXPORT);
+ Document document = new Document(racine);
+
+ // Création du sondage
+ Element pollElm = new Element(POLL);
+ 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(CLOSED, poll.isClosed() ? VALUE_TRUE : VALUE_FALSE);
+ pollElm.setAttribute(CHOICE_ADD_ALLOWED,
+ poll.isChoiceAddAllowed() ? VALUE_TRUE : VALUE_FALSE);
+ pollElm.setAttribute(ANONYMOUS_VOTE_ALLOWED,
+ poll.isAnonymousVoteAllowed() ? VALUE_TRUE : VALUE_FALSE);
+ pollElm.setAttribute(ANONYMOUS,
+ poll.isAnonymous() ? VALUE_TRUE : VALUE_FALSE);
+ pollElm.setAttribute(PUBLIC_RESULTS,
+ poll.isPublicResults() ? VALUE_TRUE : VALUE_FALSE);
+ pollElm.setAttribute(CONTINUOUS_RESULTS,
+ poll.isContinuousResults() ? VALUE_TRUE : VALUE_FALSE);
+
+ Element titleElm = new Element(TITLE1);
+ titleElm.setText(poll.getTitle());
+ pollElm.addContent(titleElm);
+
+ Element descriptionElm = new Element(DESCRIPTION);
+ descriptionElm.setText(poll.getDescription());
+ pollElm.addContent(descriptionElm);
+
+ Element creatorIdElm = new Element(CREATOR_ID);
+ creatorIdElm.setText(poll.getCreatorId());
+ pollElm.addContent(creatorIdElm);
+
+ Element creatorEmailElm = new Element(CREATOR_EMAIL);
+ creatorEmailElm.setText(poll.getCreatorEmail());
+ pollElm.addContent(creatorEmailElm);
+
+ Element maxChoiceNbElm = new Element(MAX_CHOICE_NB);
+ maxChoiceNbElm.setText(Integer.toString(poll.getMaxChoiceNb()));
+ pollElm.addContent(maxChoiceNbElm);
+
+ // Création des commentaires
+ Element commentsElm = new Element(COMMENTS);
+
+ for (CommentDTO commentDTO : poll.getComments()) {
+ Element commentElm = toDOM(commentDTO);
+ commentsElm.addContent(commentElm);
+ }
+
+ pollElm.addContent(commentsElm);
+
+ // Création des groupes de votants
+ Element groupsElm = new Element(GROUPS);
+
+ for (VotingGroupDTO votingGroupDTO : poll.getVotingGroups()) {
+ Element groupElm = toDOM(votingGroupDTO);
+ groupsElm.addContent(groupElm);
+ }
+
+ pollElm.addContent(groupsElm);
+
+ // Création des choix
+ Element pollChoicesElm = new Element(POLL_CHOICES);
+
+ for (PollChoiceDTO pollChoiceDTO : poll.getChoices()) {
+ Element pollChoiceElm = toDOM(pollChoiceDTO);
+ pollChoicesElm.addContent(pollChoiceElm);
+ }
+ pollElm.addContent(pollChoicesElm);
+
+ // Création des résultats
+ Element voteCountingResultsElm = new Element(VOTE_COUNTING_RESULTS);
+
+ for (VoteCountingResultDTO voteCountingResult1 : voteCountingResults) {
+ Element voteCountingResult = toDOM(voteCountingResult1);
+ voteCountingResultsElm.addContent(voteCountingResult);
+ }
+
+ // Ajout du sondage et des résultats à la racine
+ racine.addContent(pollElm);
+
+ racine.addContent(voteCountingResultsElm);
+
+ return document;
+ }
+
+ protected Element toDOM(CommentDTO comment) {
+ Element commentElm = new Element(COMMENT);
+
+ commentElm.setAttribute(VOTING_ID, comment.getVotingID());
+ commentElm.setText(comment.getText());
+
+ return commentElm;
+ }
+
+ protected Element toDOM(VotingGroupDTO group) {
+ Element groupElm = new Element(GROUP);
+
+ groupElm.setAttribute(ID_GROUP, group.getIdGroup());
+ groupElm.setAttribute(NAME, group.getName());
+ groupElm.setAttribute(WEIGHT, Double.toString(group.getWeight()));
+
+ Element votingPersonsElm = new Element(VOTING_PERSONS);
+
+ for (VotingPersonDTO votingPersonDTO : group.getVotingPersons()) {
+ Element votingPersonElm = toDOM(votingPersonDTO);
+ votingPersonsElm.addContent(votingPersonElm);
+ }
+ groupElm.addContent(votingPersonsElm);
+
+ return groupElm;
+ }
+
+ protected Element toDOM(VotingPersonDTO votingPerson) {
+ Element votingPersonElm = new Element(VOTING_PERSON);
+
+ votingPersonElm.setAttribute(VOTING_ID, votingPerson.getVotingId());
+ votingPersonElm.setAttribute(WEIGHT, Double.toString(votingPerson
+ .getWeight()));
+
+ Element emailElm = new Element(EMAIL);
+ emailElm.setText(votingPerson.getEmail());
+ votingPersonElm.addContent(emailElm);
+
+ Element commentElm = new Element(COMMENT);
+ commentElm.setText(votingPerson.getComment());
+ votingPersonElm.addContent(commentElm);
+
+ Element choicesElm = new Element(CHOICES);
+
+ for (VoteToChoiceDTO voteToChoice : votingPerson.getChoices()) {
+ Element choiceElm = new Element(CHOICE);
+ choiceElm.setAttribute(ID_CHOICE, voteToChoice.getIdChoice());
+ choiceElm.setAttribute(VALUE, Double.toString(voteToChoice
+ .getValue()));
+ choicesElm.addContent(choiceElm);
+ }
+
+ votingPersonElm.addContent(choicesElm);
+
+ return votingPersonElm;
+ }
+
+ protected Element toDOM(PollChoiceDTO pollChoice) {
+ Element pollChoiceElm = new Element(POLL_CHOICE);
+
+ pollChoiceElm.setAttribute(ID_CHOICE, pollChoice.getIdChoice());
+
+ Element nameElm = new Element(NAME);
+ nameElm.setText(pollChoice.getName());
+ pollChoiceElm.addContent(nameElm);
+
+ Element descriptionElm = new Element(DESCRIPTION);
+ descriptionElm.setText(pollChoice.getDescription());
+ pollChoiceElm.addContent(descriptionElm);
+
+ return pollChoiceElm;
+ }
+
+ protected Element toDOM(VoteCountingResultDTO voteCountingResults) {
+ Element voteCountingResultElm = new Element(VOTE_COUNTING_RESULT);
+
+ voteCountingResultElm.setAttribute(ID_POLL, voteCountingResults
+ .getIdPoll());
+
+ Element nbVotesElm = new Element(NB_VOTES);
+ nbVotesElm.setText(Integer.toString(voteCountingResults.getNbVotes()));
+ voteCountingResultElm.addContent(nbVotesElm);
+
+ Element choiceResultElm = new Element(CHOICE_RESULT);
+ choiceResultElm.setText(voteCountingResults.getChoiceResult());
+ voteCountingResultElm.addContent(choiceResultElm);
+
+ Element isByGroupElm = new Element(IS_BY_GROUP);
+ isByGroupElm.setText(Boolean.toString(voteCountingResults.isByGroup()));
+ voteCountingResultElm.addContent(isByGroupElm);
+
+ Element choicesElm = new Element(CHOICES);
+
+ for (ChoiceDTO choiceDTO : voteCountingResults.getChoices()) {
+ Element choiceElm = toDOM(choiceDTO);
+ choicesElm.addContent(choiceElm);
+ }
+
+ voteCountingResultElm.addContent(choicesElm);
+
+ return voteCountingResultElm;
+ }
+
+ protected Element toDOM(ChoiceDTO choice) {
+ Element choiceElm = new Element(CHOICE);
+
+ choiceElm.setAttribute(ID_CHOICE, choice.getIdChoice());
+ choiceElm.setAttribute(VALUE, Double.toString(choice.getValue()));
+
+ Element percentageElm = new Element(PERCENTAGE);
+ percentageElm.setText(Double.toString(choice.getPercentage()));
+ choiceElm.addContent(percentageElm);
+
+ Element nbVotesElm = new Element(NB_VOTES);
+ nbVotesElm.setText(Integer.toString(choice.getNbVotes()));
+ choiceElm.addContent(nbVotesElm);
+
+ return choiceElm;
+ }
+
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ImportExportService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/VoteCountingService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/VoteCountingService.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/VoteCountingService.java 2012-03-07 23:02:51 UTC (rev 3170)
@@ -0,0 +1,159 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.votecounting.services;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.common.PollType;
+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;
+import org.chorem.pollen.votecounting.dto.PollChoiceDTO;
+import org.chorem.pollen.votecounting.dto.PollDTO;
+import org.chorem.pollen.votecounting.dto.VoteCountingResultDTO;
+import org.chorem.pollen.votecounting.dto.VoteToChoiceDTO;
+import org.chorem.pollen.votecounting.dto.VotingGroupDTO;
+import org.chorem.pollen.votecounting.dto.VotingPersonDTO;
+import org.chorem.pollen.votecounting.utils.Utils;
+
+import java.util.List;
+
+/**
+ * Service qui permet le dépouillement d'un sondage.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class VoteCountingService {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(VoteCountingService.class);
+
+ public VoteCountingResultDTO execute(PollDTO poll) {
+ boolean byGroup = poll.getPollType() == PollType.GROUP;
+ VoteCountingResultDTO result = execute(poll, byGroup);
+ return result;
+ }
+
+ public VoteCountingResultDTO executeVoteCounting(PollDTO poll) {
+ return execute(poll, false);
+ }
+
+ public VoteCountingResultDTO executeGroupCounting(PollDTO poll) {
+ return execute(poll, true);
+ }
+
+ /**
+ * Execution du dépouillement
+ *
+ * @param poll : sondage
+ * @return resultat
+ */
+ private VoteCountingResultDTO execute(PollDTO poll, boolean isByGroup) {
+ if (log.isInfoEnabled()) {
+ log.info("Dépouillement (byGroup=" + isByGroup + ") du sondage "
+ + poll.getPollId());
+ }
+
+
+ // Création et remplissage du contexte
+ Context context = createContext(poll, isByGroup);
+
+ // Execution
+ if (!context.executeCounting()) {
+ //FIXME tchemit ? Why returning null, prefer use an exception
+ return null;
+ }
+ List<ChoiceDTO> resChoices = context.executeStats();
+
+ VoteCountingResultDTO result = new VoteCountingResultDTO();
+ result.setNbVotes(Utils.calculateNbVotes(poll.getVotingGroups(),
+ isByGroup));
+ result.setTypeVoteCounting(poll.getVoteCounting());
+ result.setByGroup(isByGroup);
+ result.setIdPoll(poll.getPollId());
+ result.setChoices(resChoices);
+ return result;
+ }
+
+ /**
+ * Création du contexte en fonction du type de dépouillement
+ *
+ * @param poll
+ * @param isByGroup
+ * @return
+ */
+ private Context createContext(PollDTO poll, boolean isByGroup) {
+
+ Method method;
+ switch (poll.getVoteCounting()) {
+ case NORMAL:
+ method = new StandardMethod();
+ break;
+ case PERCENTAGE:
+ method = new PercentageMethod();
+ break;
+ case CONDORCET:
+ method = new CondorcetMethod();
+ break;
+ case NUMBER:
+ method = new NumberMethod();
+ break;
+ default:
+ method = new StandardMethod();
+ }
+ Context result = new Context(method, isByGroup);
+
+ for (PollChoiceDTO choice : poll.getChoices()) {
+ if (choice.isHidden()) {
+ result.addHiddenChoice(choice);
+ } else {
+ result.addChoice(choice);
+ }
+ }
+ for (VotingGroupDTO votingGroup : poll.getVotingGroups()) {
+ result.addGroup(votingGroup.getIdGroup(), votingGroup.getWeight());
+ for (VotingPersonDTO person : votingGroup.getVotingPersons()) {
+ String currentIdGroup = votingGroup.getIdGroup();
+ for (VoteToChoiceDTO vote : person.getChoices()) {
+
+ Choice choice = result.getChoice(vote.getIdChoice());
+ Group group = choice.getGroup(currentIdGroup);
+
+ group.addVote(vote.getValue(),
+ person.getWeight(),
+ person.getVotingId());
+ }
+ }
+ }
+ return result;
+ }
+
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/VoteCountingService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
r3169 - branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll
by tchemit@users.chorem.org 07 Mar '12
by tchemit@users.chorem.org 07 Mar '12
07 Mar '12
Author: tchemit
Date: 2012-03-07 18:10:58 +0100 (Wed, 07 Mar 2012)
New Revision: 3169
Url: http://chorem.org/repositories/revision/pollen/3169
Log:
create in lazy poll otherwise loose all his data on validation error
Modified:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java 2012-03-07 16:57:17 UTC (rev 3168)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java 2012-03-07 17:10:58 UTC (rev 3169)
@@ -130,6 +130,11 @@
}
public Poll getPoll() {
+ if (poll == null) {
+ // create poll
+ UserAccount userAccount = getPollenSession().getUserAccount();
+ poll = getPollService().getNewPoll(userAccount);
+ }
return poll;
}
@@ -237,10 +242,6 @@
@Override
public void prepare() throws Exception {
- // create poll
- UserAccount userAccount = getPollenSession().getUserAccount();
- poll = getPollService().getNewPoll(userAccount);
-
pollTypes = decorateToName(PollType.values());
choiceTypes = decorateToName(ChoiceType.values());
voteCountingTypes = decorateToName(VoteCountingType.values());
1
0
r3168 - branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl
by tchemit@users.chorem.org 07 Mar '12
by tchemit@users.chorem.org 07 Mar '12
07 Mar '12
Author: tchemit
Date: 2012-03-07 17:57:17 +0100 (Wed, 07 Mar 2012)
New Revision: 3168
Url: http://chorem.org/repositories/revision/pollen/3168
Log:
prefer commit inside service than outside
Modified:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-03-07 16:56:43 UTC (rev 3167)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-03-07 16:57:17 UTC (rev 3168)
@@ -76,7 +76,7 @@
// add it to poll
pollToUpdate.addComment(commentCreated);
- commitTransaction("Could not create comment");
+ commitTransaction("Could not create comment "+comment.getText());
// feed notification
@@ -108,6 +108,9 @@
//FIXME Should we also delete the associated pollAccount ?
dao.delete(comment);
+
+ commitTransaction("Could not delete comment "+comment.getText());
+
} catch (TopiaException e) {
throw new PollenTechnicalException(e);
}
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-07 16:56:43 UTC (rev 3167)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-07 16:57:17 UTC (rev 3168)
@@ -559,6 +559,8 @@
VoteDAO dao = getDAO(Vote.class);
delete(dao, vote);
+
+ commitTransaction("Could not delete vote " + vote);
}
public void deleteChoice(String pollId, String choiceId)
@@ -577,6 +579,8 @@
ChoiceDAO dao = getDAO(Choice.class);
delete(dao, choice);
+
+ commitTransaction("Could not delete choice " + choice.getName());
}
public PollAccount getRestrictedAccount(String pollId,
1
0
r3167 - in branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main: java/org/chorem/pollen/ui java/org/chorem/pollen/ui/actions java/org/chorem/pollen/ui/actions/admin java/org/chorem/pollen/ui/actions/poll java/org/chorem/pollen/ui/actions/user resources/config webapp/WEB-INF/jsp/poll
by tchemit@users.chorem.org 07 Mar '12
by tchemit@users.chorem.org 07 Mar '12
07 Mar '12
Author: tchemit
Date: 2012-03-07 17:56:43 +0100 (Wed, 07 Mar 2012)
New Revision: 3167
Url: http://chorem.org/repositories/revision/pollen/3167
Log:
reuse the siteUrl applicationUrl, safer than using url from request...
rename poll actions (to be uniform with other actions of the package)
prefer commit in service instead of action
continue create action
add PollenNotifierWorker
Added:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClonePoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetPollFeed.java
Removed:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Clone.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Close.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Create.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Delete.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Edit.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Export.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetFeed.java
Modified:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationContext.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManageUsers.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteChoice.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayDateChoice.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Register.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/dateChoice.jsp
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationContext.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationContext.java 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationContext.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -24,10 +24,9 @@
package org.chorem.pollen.ui;
import org.chorem.pollen.PollenConfiguration;
+import org.chorem.pollen.services.PollenNotifierWorker;
import org.nuiton.topia.TopiaContext;
-import java.net.URL;
-
/**
* @author tchemit <chemit(a)codelutin.com>
* @since 1.2.6
@@ -38,7 +37,7 @@
protected TopiaContext rootContext;
- protected URL applicationUrl;
+ protected PollenNotifierWorker pollenNotifierWorker;
public PollenConfiguration getConfiguration() {
return configuration;
@@ -56,11 +55,11 @@
this.rootContext = rootContext;
}
- public URL getApplicationUrl() {
- return applicationUrl;
+ public PollenNotifierWorker getPollenNotifierWorker() {
+ return pollenNotifierWorker;
}
- public void setApplicationUrl(URL applicationUrl) {
- this.applicationUrl = applicationUrl;
+ public void setPollenNotifierWorker(PollenNotifierWorker pollenNotifierWorker) {
+ this.pollenNotifierWorker = pollenNotifierWorker;
}
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenApplicationListener.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -30,6 +30,7 @@
import org.chorem.pollen.PollenTopiaRootContextFactory;
import org.chorem.pollen.entities.PollenDAOHelper;
import org.chorem.pollen.services.DefaultPollenServiceContext;
+import org.chorem.pollen.services.PollenNotifierWorker;
import org.chorem.pollen.services.PollenServiceContext;
import org.chorem.pollen.services.PollenServiceFactory;
import org.chorem.pollen.services.impl.UserService;
@@ -42,6 +43,7 @@
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
+import java.io.IOException;
import java.util.Date;
import java.util.Locale;
@@ -62,8 +64,6 @@
protected static final Log log =
LogFactory.getLog(PollenApplicationListener.class);
- private TopiaContext rootContext;
-
@Override
public void contextInitialized(ServletContextEvent sce) {
@@ -85,11 +85,12 @@
applicationContext.setConfiguration(configuration);
if (log.isInfoEnabled()) {
- log.info("Initializing RootContextSupplier...");
+ log.info("Initializing RootContext...");
}
PollenTopiaRootContextFactory factory =
new PollenTopiaRootContextFactory();
- rootContext = factory.newDatabaseFromConfig(configuration);
+ TopiaContext rootContext
+ = factory.newDatabaseFromConfig(configuration);
applicationContext.setRootContext(rootContext);
// init db
@@ -99,6 +100,9 @@
} catch (TopiaException e) {
throw new PollenTechnicalException("Could not init db", e);
}
+
+ // int pollen notifier worker
+ initPollenNotifierworker(applicationContext);
}
@Override
@@ -107,9 +111,60 @@
if (log.isInfoEnabled()) {
log.info("Application is ending at " + new Date() + "...");
}
+
+ PollenApplicationContext applicationContext =
+ (PollenApplicationContext) sce.getServletContext().getAttribute(PollenActionSupport.APPLICATION_CONTEXT_PARAMETER);
+
+ if (applicationContext != null) {
+
+ // close pollen notifier worker
+ closePollenNotifierWorker(applicationContext.getPollenNotifierWorker());
+
+ // close topia root context to pollen db
+ closeRootcontext(applicationContext.getRootContext());
+
+
+ }
+ }
+
+ private void initPollenNotifierworker(PollenApplicationContext applicationContext) {
+ PollenServiceContext serviceContext = DefaultPollenServiceContext.newContext(
+ Locale.getDefault(),
+ null,
+ applicationContext.getConfiguration(),
+ new PollenServiceFactory()
+ );
+ PollenNotifierWorker pollenNotifierWorker = new PollenNotifierWorker(
+ serviceContext,
+ applicationContext.getRootContext()
+ );
+ applicationContext.setPollenNotifierWorker(pollenNotifierWorker);
+
+ pollenNotifierWorker.run();
+ }
+
+ private void closePollenNotifierWorker(PollenNotifierWorker pollenNotifierWorker) {
+
+ if (pollenNotifierWorker != null) {
+ if (log.isInfoEnabled()) {
+ log.info("Shuting down pollenNotifierWorker... " +
+ pollenNotifierWorker);
+ }
+ try {
+ pollenNotifierWorker.close();
+ } catch (IOException e) {
+ if (log.isErrorEnabled()) {
+ log.error("Could not close pollenNotifierWorker", e);
+ }
+ }
+ }
+ }
+
+ private void closeRootcontext(TopiaContext rootContext) {
+
if (rootContext != null) {
if (log.isInfoEnabled()) {
- log.info("Shuting down RootContextSupplier...");
+ log.info("Shuting down RootContext... " + rootContext);
}
if (!rootContext.isClosed()) {
try {
@@ -125,6 +180,8 @@
protected void initDB(PollenApplicationContext applicationContext) throws TopiaException {
+ TopiaContext rootContext = applicationContext.getRootContext();
+
boolean schemaFound = TopiaUtil.isSchemaExist(
rootContext,
PollenDAOHelper.PollenEntityEnum.UserAccount.getImplementation().getName()
@@ -147,8 +204,7 @@
Locale.getDefault(),
transaction,
configuration,
- serviceFactory,
- null
+ serviceFactory
);
UserService service =
@@ -165,7 +221,6 @@
} finally {
closeTransaction(transaction);
}
-
}
/**
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -27,7 +27,6 @@
import com.opensymphony.xwork2.ActionContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsStatics;
import org.chorem.pollen.PollenConfiguration;
import org.chorem.pollen.services.DefaultPollenServiceContext;
@@ -36,7 +35,6 @@
import org.chorem.pollen.services.PollenServiceFactory;
import org.chorem.pollen.ui.PollenApplicationContext;
import org.chorem.pollen.ui.PollenSession;
-import org.chorem.pollen.ui.PollenUIUtils;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.framework.TopiaTransactionAware;
import org.nuiton.web.filter.TopiaTransactionFilter;
@@ -136,16 +134,7 @@
}
public URL getApplicationUrl() {
- URL url = getPollenApplicationContext().getApplicationUrl();
- if (url == null) {
-
- // first time asking this, let's compute it
- url = PollenUIUtils.getApplicationBase(ServletActionContext.getRequest());
- if (log.isInfoEnabled()) {
- log.info("Pollen application url : " + url);
- }
- getPollenApplicationContext().setApplicationUrl(url);
- }
+ URL url = getServiceContext().getApplicationURL();
return url;
}
@@ -161,8 +150,7 @@
getLocale(),
getTransaction(),
getConfiguration(),
- getServiceFactory(),
- getApplicationUrl()
+ getServiceFactory()
);
}
return serviceContext;
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManageUsers.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManageUsers.java 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/admin/ManageUsers.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -76,12 +76,10 @@
Preconditions.checkNotNull(user);
- UserService service = newService(UserService.class);
-
String result = INPUT;
try {
- service.createUser(user, true);
- getTransaction().commitTransaction();
+ newService(UserService.class).createUser(user, true);
+
addActionMessage(
_("pollen.information.user.created",
user.getDisplayName()));
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AddComment.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -75,8 +75,6 @@
// create the comment
service.createComment(poll, comment);
- getTransaction().commitTransaction();
-
// let's use back default comment name
commentName = getDefaultCommentName();
return SUCCESS;
Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Clone.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Clone.java 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Clone.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -1,38 +0,0 @@
-/*
- * #%L
- * Pollen :: UI (strust2)
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package org.chorem.pollen.ui.actions.poll;
-
-import org.chorem.pollen.ui.actions.PollenActionSupport;
-
-/**
- * Creates a new poll by cloning an existing one.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.2.6
- */
-public class Clone extends PollenActionSupport {
-
- private static final long serialVersionUID = 1L;
-
-}
Copied: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClonePoll.java (from rev 3163, branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Clone.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClonePoll.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClonePoll.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -0,0 +1,38 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.actions.poll;
+
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+
+/**
+ * Creates a new poll by cloning an existing one.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class ClonePoll extends AbstractPollUriIdAction {
+
+ private static final long serialVersionUID = 1L;
+
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClonePoll.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Close.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Close.java 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Close.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -1,37 +0,0 @@
-/*
- * #%L
- * Pollen :: UI (strust2)
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package org.chorem.pollen.ui.actions.poll;
-
-import org.chorem.pollen.ui.actions.PollenActionSupport;
-
-/**
- * Closes an existing poll.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.2.6
- */
-public class Close extends PollenActionSupport {
-
- private static final long serialVersionUID = 1L;
-}
Copied: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java (from rev 3163, branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Close.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -0,0 +1,37 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.actions.poll;
+
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+
+/**
+ * Closes an existing poll.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class ClosePoll extends AbstractPollUriIdAction {
+
+ private static final long serialVersionUID = 1L;
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ClosePoll.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Create.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Create.java 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Create.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -1,620 +0,0 @@
-/*
- * #%L
- * Pollen :: UI (strust2)
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package org.chorem.pollen.ui.actions.poll;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import com.opensymphony.xwork2.Preparable;
-import org.apache.commons.collections.MapUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.struts2.interceptor.ParameterAware;
-import org.chorem.pollen.bean.PollImageChoice;
-import org.chorem.pollen.business.persistence.Choice;
-import org.chorem.pollen.business.persistence.ChoiceImpl;
-import org.chorem.pollen.business.persistence.Poll;
-import org.chorem.pollen.business.persistence.UserAccount;
-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.impl.PollService;
-import org.chorem.pollen.ui.actions.PollenActionSupport;
-
-import java.io.File;
-import java.net.URL;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Creates a new poll.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.2.6
- */
-public class Create extends PollenActionSupport implements Preparable, ParameterAware {
-
- private static final long serialVersionUID = 1L;
-
- /** Logger. */
- private static final Log log = LogFactory.getLog(Create.class);
-
- public static final Pattern TEXT_CHOICE_NAME_PATTERN =
- Pattern.compile("textChoice_(\\d+).name");
-
- public static final Pattern DATE_CHOICE_NAME_PATTERN =
- Pattern.compile("dateChoice_(\\d+).name");
-
- public static final Pattern IMAGE_CHOICE_NAME_PATTERN =
- Pattern.compile("imageChoice_(\\d+).name");
-
- protected Poll poll;
-
- protected Map<String, String> pollTypes;
-
- protected Map<String, String> voteCountingTypes;
-
- protected Map<String, String> choiceTypes;
-
- protected boolean notification;
-
- protected boolean reminder;
-
- protected boolean limitChoice;
-
- protected int reminderHourCountdown;
-
- protected int notificationNumber;
-
- private String textChoiceTokenId;
-
- private String dateChoiceTokenId;
-
- private String imageChoiceTokenId;
-
- private int nbTextChoices;
-
- private int nbDateChoices;
-
- private int nbImageChoices;
-
- /** Uploaded images (for choice type poll). */
- private List<File> imageChoice;
-
- /** Uploaded images content type (for choice type poll). */
- private List<String> imageChoiceContentType;
-
- /** Uploaded images name (from use desktop) (for choice type poll). */
- private List<String> imageChoiceFileName;
-
- /**
- * All the parameters send by request used to build back choices of the
- * poll.
- */
- private Map<String, String[]> parameters;
-
- @Override
- public String getPageLogo() {
- return "Creation";
- }
-
- public Poll getPoll() {
- if (poll == null) {
- UserAccount userAccount = getPollenSession().getUserAccount();
- poll = newService(PollService.class).getNewPoll(userAccount);
- }
- return poll;
- }
-
- public int getNbTextChoices() {
- return nbTextChoices;
- }
-
- public String getTextChoiceTokenId() {
- return textChoiceTokenId;
- }
-
- public int getNbDateChoices() {
- return nbDateChoices;
- }
-
- public String getDateChoiceTokenId() {
- return dateChoiceTokenId;
- }
-
- public int getNbImageChoices() {
- return nbImageChoices;
- }
-
- public String getImageChoiceTokenId() {
- return imageChoiceTokenId;
- }
-
- public Map<String, String> getPollTypes() {
- return pollTypes;
- }
-
- public Map<String, String> getVoteCountingTypes() {
- return voteCountingTypes;
- }
-
- public Map<String, String> getChoiceTypes() {
- return choiceTypes;
- }
-
- public boolean isNotification() {
- return notification;
- }
-
- public void setNotification(boolean notification) {
- this.notification = notification;
- }
-
- public boolean isReminder() {
- return reminder;
- }
-
- public void setReminder(boolean reminder) {
- this.reminder = reminder;
- }
-
- public boolean isLimitChoice() {
- return limitChoice;
- }
-
- public void setLimitChoice(boolean limitChoice) {
- this.limitChoice = limitChoice;
- }
-
- public int getReminderHourCountdown() {
- return reminderHourCountdown;
- }
-
- public void setReminderHourCountdown(int reminderHourCountdown) {
- this.reminderHourCountdown = reminderHourCountdown;
- }
-
- public int getNotificationNumber() {
- return notificationNumber;
- }
-
- public void setNotificationNumber(int notificationNumber) {
- this.notificationNumber = notificationNumber;
- }
-
- public List<File> getImageChoice() {
- if (imageChoice == null) {
- imageChoice = Lists.newArrayList();
- }
- return imageChoice;
- }
-
- public void setImageChoice(int index, File imageChoice) {
- addtoList(getImageChoice(), index, imageChoice);
- }
-
- public List<String> getImageChoiceContentType() {
- if (imageChoiceContentType == null) {
- imageChoiceContentType = Lists.newArrayList();
- }
- return imageChoiceContentType;
- }
-
- public List<String> getImageChoiceFileName() {
- if (imageChoiceFileName == null) {
- imageChoiceFileName = Lists.newArrayList();
- }
- return imageChoiceFileName;
- }
-
- public void setImageChoiceContentType(int index, String imageChoiceContentType) {
- addtoList(getImageChoiceContentType(), index, imageChoiceContentType);
- }
-
- public void setImageChoiceFileName(int index, String imageChoiceFileName) {
- addtoList(getImageChoiceFileName(), index, imageChoiceFileName);
- }
-
- @Override
- public void prepare() throws Exception {
-
- pollTypes = decorateToName(PollType.values());
- choiceTypes = decorateToName(ChoiceType.values());
- voteCountingTypes = decorateToName(VoteCountingType.values());
-
- //TODO tchemit-2012-03-05 use a default value from configuration
- nbTextChoices = nbDateChoices = nbImageChoices = 5;
-
- String tokenSuffix = getServiceContext().createPollenUrlId();
-
- textChoiceTokenId = DisplayTextChoice.CHOICE_TOKEN + "_" +
- tokenSuffix;
-
- dateChoiceTokenId = DisplayDateChoice.CHOICE_TOKEN + "_" +
- tokenSuffix;
-
- imageChoiceTokenId = DisplayImageChoice.CHOICE_TOKEN + "_" +
- tokenSuffix;
-
- ChoiceType pollChoiceType = getPoll().getChoiceType();
-
- if (log.isInfoEnabled()) {
- log.info("choice type " + pollChoiceType);
- }
-
- Map<Integer, Choice> choices = null;
- String tokenId = null;
-
- switch (pollChoiceType) {
- case TEXT:
- choices = buildTextChoices(5);
- tokenId = textChoiceTokenId;
- break;
- case DATE:
- choices = buildDateChoices(5);
- tokenId = dateChoiceTokenId;
- break;
- case IMAGE:
- choices = buildImageChoices(5);
- tokenId = imageChoiceTokenId;
- break;
- }
- getPollenSession().putDynamicData(tokenId, choices);
- }
-
- @Override
- public void validate() {
-
- Preconditions.checkNotNull(poll);
-
- // poll must have a title
- if (StringUtils.isEmpty(poll.getTitle())) {
- addFieldError("poll.title", _("poll.error.poll.required.title"));
- }
-
- // validate choices
- Map<Integer, Choice> orderedChoices = getOrderedChoices();
-
- if (MapUtils.isEmpty(orderedChoices)) {
-
- // poll must have at least one choice
- addFieldError("poll.choices",
- _("poll.error.poll.required.one.choice"));
- } else {
-
- // check there is no choice with same name
- boolean duplicateNameDetected = false;
- Set<String> names = Sets.newHashSet();
- for (Choice choice : orderedChoices.values()) {
- String choiceName = choice.getName();
- if (!names.add(choiceName)) {
- duplicateNameDetected = true;
- break;
- }
- }
- if (duplicateNameDetected) {
- addFieldError("poll.choices",
- _("poll.error.poll.detected.duplicate.choice.name"));
- }
- }
-
- // validate security stuff
-
- }
-
- @Override
- public String execute() throws Exception {
-
- Map<Integer, Choice> orderedChoices = getOrderedChoices();
-
- List<Choice> choices = Lists.newLinkedList();
-
- for (Integer index : orderedChoices.keySet()) {
- Choice choice = orderedChoices.get(index);
- poll.addChoice(choice);
- }
-
- PollService service = newService(PollService.class);
-
- poll = service.createPoll(poll);
-
- getTransaction().commitTransaction();
-
- // remove all stuff from session
- getPollenSession().removeDynamicData(textChoiceTokenId);
- getPollenSession().removeDynamicData(dateChoiceTokenId);
- getPollenSession().removeDynamicData(imageChoiceTokenId);
-
- addActionMessage(_("poll.info.poll.created"));
- return SUCCESS;
- }
-
- public String getPollVoteUrl() {
- URL applicationUrl = getApplicationUrl();
- StringBuilder url = new StringBuilder(applicationUrl.toString());
-
- url.append("/poll/votefor/").append(poll.getPollId());
-
- if (poll.getPollType() != PollType.FREE) {
- url.append(':').append(poll.getCreator().getAccountId());
- }
- return url.toString();
- }
-
- public String getPollEditUrl() {
- URL applicationUrl = getApplicationUrl();
- StringBuilder url = new StringBuilder(applicationUrl.toString());
-
- url.append("/poll/modification/").append(poll.getPollId());
- url.append(':').append(poll.getCreator().getAccountId());
- return url.toString();
- }
-
- @Override
- public void setParameters(Map<String, String[]> parameters) {
- this.parameters = parameters;
- }
-
- private Map<Integer, Choice> getOrderedChoices() {
-
- Map<Integer, Choice> orderedChoices = null;
- switch (poll.getChoiceType()) {
-
- case TEXT:
- orderedChoices = getPollenSession().getDynamicData(
- textChoiceTokenId);
-
- break;
- case DATE:
- orderedChoices = getPollenSession().getDynamicData(
- dateChoiceTokenId);
- break;
- case IMAGE:
- orderedChoices = getPollenSession().getDynamicData(
- imageChoiceTokenId);
- break;
- }
- return orderedChoices;
- }
-
- private Map<Integer, Choice> buildTextChoices(int nbDefault) {
- Map<Integer, Choice> result = Maps.newTreeMap();
-
- int maxNumber = 0;
-
- for (String paramName : parameters.keySet()) {
-
- Matcher matcher = TEXT_CHOICE_NAME_PATTERN.matcher(paramName);
- if (matcher.matches()) {
-
- // found a text choice name
-
- String paramValue = getNonEmptyParameterValue(paramName);
- if (paramValue != null) {
-
- // can keep this none empty text choice name
-
- Integer choiceNumber = Integer.valueOf(matcher.group(1));
- if (choiceNumber > maxNumber) {
- maxNumber = choiceNumber;
- }
- Choice choice = new ChoiceImpl();
- createChoice(choice, "textChoice_" + choiceNumber,
- paramValue);
- result.put(choiceNumber, choice);
- }
- }
- }
- result = reindexChoices(result, maxNumber);
-
- int size = result.size();
- nbTextChoices = Math.max(nbDefault, size);
- log.info("nbTextChoices (from request) = " + size);
- logChoice(result);
- return result;
- }
-
- private Map<Integer, Choice> buildDateChoices(int nbDefault) {
- Map<Integer, Choice> result = Maps.newTreeMap();
-
- int maxNumber = 0;
- for (String paramName : parameters.keySet()) {
-
- Matcher matcher = DATE_CHOICE_NAME_PATTERN.matcher(paramName);
- if (matcher.matches()) {
-
- // found a text choice name
-
- String paramValue = getNonEmptyParameterValue(paramName);
- if (paramValue != null) {
-
- // can keep this none empty text choice name
-
- Integer choiceNumber = Integer.valueOf(matcher.group(1));
- if (choiceNumber > maxNumber) {
- maxNumber = choiceNumber;
- }
- Choice choice = new ChoiceImpl();
- createChoice(choice,
- "dateChoice_" + choiceNumber,
- paramValue);
- result.put(choiceNumber, choice);
- }
- }
- }
- result = reindexChoices(result, maxNumber);
-
- int size = result.size();
- nbDateChoices = Math.max(nbDefault, size);
- log.info("nbDateChoices (from request) = " + size);
- logChoice(result);
- return result;
- }
-
- private Map<Integer, Choice> buildImageChoices(int nbDefault) {
- Map<Integer, Choice> result = Maps.newTreeMap();
-
- // push back in parameters stuff from uploaded files
- int index = 0;
-
- for (String fileName : getImageChoiceFileName()) {
- if (fileName != null) {
- parameters.put("imageChoice_" + index + ".name", new String[]{fileName});
- parameters.put("imageChoice_" + index + ".location", new String[]{getImageChoice().get(index).getAbsolutePath()});
- }
- index++;
- }
-
- int maxNumber = 0;
- for (String paramName : parameters.keySet()) {
-
- Matcher matcher = IMAGE_CHOICE_NAME_PATTERN.matcher(paramName);
- if (matcher.matches()) {
-
- // found a text choice name
-
- String paramValue = getNonEmptyParameterValue(paramName);
- if (paramValue != null) {
-
- // can keep this none empty text choice name
-
- Integer choiceNumber = Integer.valueOf(matcher.group(1));
- if (choiceNumber > maxNumber) {
- maxNumber = choiceNumber;
- }
- PollImageChoice choice = new PollImageChoice();
- createImageChoice(choice,
- "imageChoice_" + choiceNumber,
- paramValue);
-
- result.put(choiceNumber, choice);
- }
- }
- }
- result = reindexChoices(result, maxNumber);
- int size = result.size();
- nbImageChoices = Math.max(nbDefault, size);
- log.info("nbImageChoices (from request) = " + size);
- logChoice(result);
- return result;
- }
-
- private void logChoice(Map<Integer, Choice> result) {
- for (Map.Entry<Integer, Choice> e : result.entrySet()) {
- Integer choiceId = e.getKey();
- Choice choice = e.getValue();
- if (log.isInfoEnabled()) {
- log.info("Choice [" + choiceId + "] = " +
- choice.getName() + " -- " +
- choice.getDescription());
- }
- }
- }
-
- private Choice createImageChoice(PollImageChoice choice,
- String prefix, String name) {
- createChoice(choice, prefix, name);
- String locationName = prefix + ".location";
- String location = getNonEmptyParameterValue(locationName);
- choice.setLocation(location);
- if (log.isInfoEnabled()) {
- log.info("image location [" + name + "] =" + location);
- }
- return choice;
- }
-
- private Choice createChoice(Choice choice, String prefix, String name) {
- String descriptionName = prefix + ".description";
- String topiaIdName = prefix + ".topiaId";
- String description = getNonEmptyParameterValue(descriptionName);
- String topiaId = getNonEmptyParameterValue(topiaIdName);
- choice.setName(name);
- choice.setDescription(description);
- choice.setTopiaId(topiaId);
- return choice;
- }
-
-
- private Map<Integer, Choice> reindexChoices(Map<Integer, Choice> result,
- int maxNumber) {
- Map<Integer, Choice> result2;
-
- if (maxNumber != result.size() - 1) {
-
- // means there is a hole inside the result (a empty choice was
- // submitted)
-
- // le'ts remove this
- List<Integer> numbers = Lists.newArrayList(result.keySet());
-
- Collections.sort(numbers);
-
- result2 = Maps.newTreeMap();
- int i = 0;
- for (Integer number : numbers) {
- Choice choice = result.get(number);
- result2.put(i++, choice);
- }
- } else {
- result2 = result;
- }
- return result2;
- }
-
- private <O> void addtoList(List<O> list, int index, O object) {
-
- while (list.size() < index) {
- list.add(null);
- }
- list.add(index, object);
- }
-
-
- private String getNonEmptyParameterValue(String paramName) {
- String[] paramValues = parameters.get(paramName);
- String result = null;
- if (paramValues.length == 1) {
- String paramValue = paramValues[0];
- if (StringUtils.isNotEmpty(paramValue)) {
- result = paramValue;
- }
- }
- return result;
- }
-
- private <E extends Enum<E> & I18nAble> Map<String, String> decorateToName(E... values) {
- Map<String, String> result = Maps.newLinkedHashMap();
- for (E value : values) {
- result.put(value.name(), getText(value.getI18nKey()));
- }
- return result;
- }
-}
Copied: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java (from rev 3163, branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Create.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -0,0 +1,638 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.actions.poll;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import com.opensymphony.xwork2.Preparable;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.struts2.interceptor.ParameterAware;
+import org.chorem.pollen.bean.PollDateChoice;
+import org.chorem.pollen.bean.PollImageChoice;
+import org.chorem.pollen.business.persistence.Choice;
+import org.chorem.pollen.business.persistence.ChoiceImpl;
+import org.chorem.pollen.business.persistence.Poll;
+import org.chorem.pollen.business.persistence.PreventRule;
+import org.chorem.pollen.business.persistence.UserAccount;
+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.impl.PollService;
+import org.chorem.pollen.services.impl.PreventRuleService;
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Creates a new poll.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class CreatePoll extends PollenActionSupport implements Preparable, ParameterAware {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(CreatePoll.class);
+
+ public static final Pattern TEXT_CHOICE_NAME_PATTERN =
+ Pattern.compile("textChoice_(\\d+).name");
+
+ public static final Pattern DATE_CHOICE_NAME_PATTERN =
+ Pattern.compile("dateChoice_(\\d+).name");
+
+ public static final Pattern IMAGE_CHOICE_NAME_PATTERN =
+ Pattern.compile("imageChoice_(\\d+).name");
+
+ protected Poll poll;
+
+ protected Map<String, String> pollTypes;
+
+ protected Map<String, String> voteCountingTypes;
+
+ protected Map<String, String> choiceTypes;
+
+ protected boolean notification;
+
+ protected boolean reminder;
+
+ protected boolean limitChoice;
+
+ protected int reminderHourCountdown = 2;
+
+ private String textChoiceTokenId;
+
+ private String dateChoiceTokenId;
+
+ private String imageChoiceTokenId;
+
+ private int nbTextChoices;
+
+ private int nbDateChoices;
+
+ private int nbImageChoices;
+
+ /** Uploaded images (for choice type poll). */
+ private List<File> imageChoice;
+
+ /** Uploaded images content type (for choice type poll). */
+ private List<String> imageChoiceContentType;
+
+ /** Uploaded images name (from use desktop) (for choice type poll). */
+ private List<String> imageChoiceFileName;
+
+ /**
+ * All the parameters send by request used to build back choices of the
+ * poll.
+ */
+ private Map<String, String[]> parameters;
+
+ protected transient PollService pollService;
+
+ @Override
+ public String getPageLogo() {
+ return "Creation";
+ }
+
+ public Poll getPoll() {
+ return poll;
+ }
+
+ public int getNbTextChoices() {
+ return nbTextChoices;
+ }
+
+ public String getTextChoiceTokenId() {
+ return textChoiceTokenId;
+ }
+
+ public int getNbDateChoices() {
+ return nbDateChoices;
+ }
+
+ public String getDateChoiceTokenId() {
+ return dateChoiceTokenId;
+ }
+
+ public int getNbImageChoices() {
+ return nbImageChoices;
+ }
+
+ public String getImageChoiceTokenId() {
+ return imageChoiceTokenId;
+ }
+
+ public Map<String, String> getPollTypes() {
+ return pollTypes;
+ }
+
+ public Map<String, String> getVoteCountingTypes() {
+ return voteCountingTypes;
+ }
+
+ public Map<String, String> getChoiceTypes() {
+ return choiceTypes;
+ }
+
+ public boolean isNotification() {
+ return notification;
+ }
+
+ public void setNotification(boolean notification) {
+ this.notification = notification;
+ }
+
+ public boolean isReminder() {
+ return reminder;
+ }
+
+ public void setReminder(boolean reminder) {
+ this.reminder = reminder;
+ }
+
+ public boolean isLimitChoice() {
+ return limitChoice;
+ }
+
+ public void setLimitChoice(boolean limitChoice) {
+ this.limitChoice = limitChoice;
+ }
+
+ public int getReminderHourCountdown() {
+ return reminderHourCountdown;
+ }
+
+ public void setReminderHourCountdown(int reminderHourCountdown) {
+ this.reminderHourCountdown = reminderHourCountdown;
+ }
+
+ public List<File> getImageChoice() {
+ if (imageChoice == null) {
+ imageChoice = Lists.newArrayList();
+ }
+ return imageChoice;
+ }
+
+ public void setImageChoice(int index, File imageChoice) {
+ addtoList(getImageChoice(), index, imageChoice);
+ }
+
+ public List<String> getImageChoiceContentType() {
+ if (imageChoiceContentType == null) {
+ imageChoiceContentType = Lists.newArrayList();
+ }
+ return imageChoiceContentType;
+ }
+
+ public List<String> getImageChoiceFileName() {
+ if (imageChoiceFileName == null) {
+ imageChoiceFileName = Lists.newArrayList();
+ }
+ return imageChoiceFileName;
+ }
+
+ public void setImageChoiceContentType(int index, String imageChoiceContentType) {
+ addtoList(getImageChoiceContentType(), index, imageChoiceContentType);
+ }
+
+ public void setImageChoiceFileName(int index, String imageChoiceFileName) {
+ addtoList(getImageChoiceFileName(), index, imageChoiceFileName);
+ }
+
+ @Override
+ public void prepare() throws Exception {
+
+ // create poll
+ UserAccount userAccount = getPollenSession().getUserAccount();
+ poll = getPollService().getNewPoll(userAccount);
+
+ pollTypes = decorateToName(PollType.values());
+ choiceTypes = decorateToName(ChoiceType.values());
+ voteCountingTypes = decorateToName(VoteCountingType.values());
+
+ //TODO tchemit-2012-03-05 use a default value from configuration
+ nbTextChoices = nbDateChoices = nbImageChoices = 5;
+
+ String tokenSuffix = getServiceContext().createPollenUrlId();
+
+ textChoiceTokenId = DisplayTextChoice.CHOICE_TOKEN + "_" +
+ tokenSuffix;
+
+ dateChoiceTokenId = DisplayDateChoice.CHOICE_TOKEN + "_" +
+ tokenSuffix;
+
+ imageChoiceTokenId = DisplayImageChoice.CHOICE_TOKEN + "_" +
+ tokenSuffix;
+
+ ChoiceType pollChoiceType = getPoll().getChoiceType();
+
+ if (log.isInfoEnabled()) {
+ log.info("choice type " + pollChoiceType);
+ }
+
+ Map<Integer, Choice> choices = null;
+ String tokenId = null;
+
+ switch (pollChoiceType) {
+ case TEXT:
+ choices = buildTextChoices(5);
+ tokenId = textChoiceTokenId;
+ break;
+ case DATE:
+ choices = buildDateChoices(5);
+ tokenId = dateChoiceTokenId;
+ break;
+ case IMAGE:
+ choices = buildImageChoices(5);
+ tokenId = imageChoiceTokenId;
+ break;
+ }
+ getPollenSession().putDynamicData(tokenId, choices);
+ }
+
+ @Override
+ public void validate() {
+
+ Preconditions.checkNotNull(poll);
+
+ // poll must have a title
+ if (StringUtils.isEmpty(poll.getTitle())) {
+ addFieldError("poll.title", _("poll.error.poll.required.title"));
+ }
+
+ // validate choices
+ Map<Integer, Choice> orderedChoices = getOrderedChoices();
+
+ if (MapUtils.isEmpty(orderedChoices)) {
+
+ // poll must have at least one choice
+ addFieldError("poll.choices",
+ _("poll.error.poll.required.one.choice"));
+ } else {
+
+ //TODO tchemit improve this (from different cases text-date-image)
+ // check there is no choice with same name
+ boolean duplicateNameDetected = false;
+ Set<String> names = Sets.newHashSet();
+ for (Choice choice : orderedChoices.values()) {
+ String choiceName = choice.getName();
+ if (!names.add(choiceName)) {
+ duplicateNameDetected = true;
+ break;
+ }
+ }
+ if (duplicateNameDetected) {
+ addFieldError("poll.choices",
+ _("poll.error.poll.detected.duplicate.choice.name"));
+ }
+ }
+
+ // validate security stuff
+
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ Map<Integer, Choice> orderedChoices = getOrderedChoices();
+
+ for (Integer index : orderedChoices.keySet()) {
+ Choice choice = orderedChoices.get(index);
+ poll.addChoice(choice);
+ }
+
+ PollService service = getPollService();
+
+ PreventRuleService preventRuleService =
+ newService(PreventRuleService.class);
+ if (isNotification()) {
+
+ // add a notification rule
+
+ PreventRule rule = preventRuleService.createAddVotePreventRule();
+ poll.addPreventRule(rule);
+ }
+
+ if (isReminder()) {
+
+ // add a reminder rule
+
+ PreventRule rule = preventRuleService.createRemindPreventRule(
+ getReminderHourCountdown()
+ );
+
+ poll.addPreventRule(rule);
+ }
+
+ poll = service.createPoll(poll);
+
+ // remove all stuff from session
+ getPollenSession().removeDynamicData(textChoiceTokenId);
+ getPollenSession().removeDynamicData(dateChoiceTokenId);
+ getPollenSession().removeDynamicData(imageChoiceTokenId);
+
+ addActionMessage(_("poll.info.poll.created"));
+ return SUCCESS;
+ }
+
+ public String getPollVoteUrl() {
+ return getPollService().getPollVoteUrl(poll);
+ }
+
+ public String getPollEditUrl() {
+ return getPollService().getPollEditUrl(poll);
+ }
+
+ @Override
+ public void setParameters(Map<String, String[]> parameters) {
+ this.parameters = parameters;
+ }
+
+ protected PollService getPollService() {
+ if (pollService == null) {
+ pollService = newService(PollService.class);
+ }
+ return pollService;
+ }
+
+ protected Map<Integer, Choice> getOrderedChoices() {
+
+ Map<Integer, Choice> orderedChoices = null;
+ switch (poll.getChoiceType()) {
+
+ case TEXT:
+ orderedChoices = getPollenSession().getDynamicData(
+ textChoiceTokenId);
+
+ break;
+ case DATE:
+ orderedChoices = getPollenSession().getDynamicData(
+ dateChoiceTokenId);
+ break;
+ case IMAGE:
+ orderedChoices = getPollenSession().getDynamicData(
+ imageChoiceTokenId);
+ break;
+ }
+ return orderedChoices;
+ }
+
+ protected Map<Integer, Choice> buildTextChoices(int nbDefault) {
+ Map<Integer, Choice> result = Maps.newTreeMap();
+
+ int maxNumber = 0;
+
+ for (String paramName : parameters.keySet()) {
+
+ Matcher matcher = TEXT_CHOICE_NAME_PATTERN.matcher(paramName);
+ if (matcher.matches()) {
+
+ // found a text choice name
+
+ String paramValue = getNonEmptyParameterValue(paramName);
+ if (paramValue != null) {
+
+ // can keep this none empty text choice name
+
+ Integer choiceNumber = Integer.valueOf(matcher.group(1));
+ if (choiceNumber > maxNumber) {
+ maxNumber = choiceNumber;
+ }
+ Choice choice = new ChoiceImpl();
+ createChoice(choice, "textChoice_" + choiceNumber,
+ paramValue);
+ result.put(choiceNumber, choice);
+ }
+ }
+ }
+ result = reindexChoices(result, maxNumber);
+
+ int size = result.size();
+ nbTextChoices = Math.max(nbDefault, size);
+ log.info("nbTextChoices (from request) = " + size);
+ logChoice(result);
+ return result;
+ }
+
+ protected Map<Integer, Choice> buildDateChoices(int nbDefault) {
+ Map<Integer, Choice> result = Maps.newTreeMap();
+
+ int maxNumber = 0;
+ for (String paramName : parameters.keySet()) {
+
+ Matcher matcher = DATE_CHOICE_NAME_PATTERN.matcher(paramName);
+ if (matcher.matches()) {
+
+ // found a text choice name
+
+ String paramValue = getNonEmptyParameterValue(paramName);
+ if (paramValue != null) {
+
+ // can keep this none empty text choice name
+
+ Integer choiceNumber = Integer.valueOf(matcher.group(1));
+ if (choiceNumber > maxNumber) {
+ maxNumber = choiceNumber;
+ }
+ PollDateChoice choice = new PollDateChoice();
+ createDateChoice(choice,
+ "dateChoice_" + choiceNumber,
+ paramValue);
+ result.put(choiceNumber, choice);
+ }
+ }
+ }
+ result = reindexChoices(result, maxNumber);
+
+ int size = result.size();
+ nbDateChoices = Math.max(nbDefault, size);
+ log.info("nbDateChoices (from request) = " + size);
+ logChoice(result);
+ return result;
+ }
+
+ protected Map<Integer, Choice> buildImageChoices(int nbDefault) {
+ Map<Integer, Choice> result = Maps.newTreeMap();
+
+ // push back in parameters stuff from uploaded files
+ int index = 0;
+
+ for (String fileName : getImageChoiceFileName()) {
+ if (fileName != null) {
+ parameters.put("imageChoice_" + index + ".name", new String[]{fileName});
+ parameters.put("imageChoice_" + index + ".location", new String[]{getImageChoice().get(index).getAbsolutePath()});
+ }
+ index++;
+ }
+
+ int maxNumber = 0;
+ for (String paramName : parameters.keySet()) {
+
+ Matcher matcher = IMAGE_CHOICE_NAME_PATTERN.matcher(paramName);
+ if (matcher.matches()) {
+
+ // found a text choice name
+
+ String paramValue = getNonEmptyParameterValue(paramName);
+ if (paramValue != null) {
+
+ // can keep this none empty text choice name
+
+ Integer choiceNumber = Integer.valueOf(matcher.group(1));
+ if (choiceNumber > maxNumber) {
+ maxNumber = choiceNumber;
+ }
+ PollImageChoice choice = new PollImageChoice();
+ createImageChoice(choice,
+ "imageChoice_" + choiceNumber,
+ paramValue);
+
+ result.put(choiceNumber, choice);
+ }
+ }
+ }
+ result = reindexChoices(result, maxNumber);
+ int size = result.size();
+ nbImageChoices = Math.max(nbDefault, size);
+ log.info("nbImageChoices (from request) = " + size);
+ logChoice(result);
+ return result;
+ }
+
+ private void logChoice(Map<Integer, Choice> result) {
+ for (Map.Entry<Integer, Choice> e : result.entrySet()) {
+ Integer choiceId = e.getKey();
+ Choice choice = e.getValue();
+ if (log.isInfoEnabled()) {
+ log.info("Choice [" + choiceId + "] = " +
+ choice.getName() + " -- " +
+ choice.getDescription());
+ }
+ }
+ }
+
+ private Choice createImageChoice(PollImageChoice choice,
+ String prefix,
+ String name) {
+ createChoice(choice, prefix, name);
+ String locationName = prefix + ".location";
+ String location = getNonEmptyParameterValue(locationName);
+ choice.setLocation(location);
+ if (log.isInfoEnabled()) {
+ log.info("image location [" + name + "] =" + location);
+ }
+ return choice;
+ }
+
+ private Choice createDateChoice(PollDateChoice choice,
+ String prefix,
+ String name) {
+ createChoice(choice, prefix, name);
+ if (StringUtils.isNotEmpty(name)) {
+ choice.setDate(new Date(Long.valueOf(name)));
+ }
+ return choice;
+ }
+
+ private Choice createChoice(Choice choice, String prefix, String name) {
+ String descriptionName = prefix + ".description";
+ String topiaIdName = prefix + ".topiaId";
+ String description = getNonEmptyParameterValue(descriptionName);
+ String topiaId = getNonEmptyParameterValue(topiaIdName);
+ choice.setName(name);
+ choice.setDescription(description);
+ choice.setTopiaId(topiaId);
+ return choice;
+ }
+
+
+ private Map<Integer, Choice> reindexChoices(Map<Integer, Choice> result,
+ int maxNumber) {
+ Map<Integer, Choice> result2;
+
+ if (maxNumber != result.size() - 1) {
+
+ // means there is a hole inside the result (a empty choice was
+ // submitted)
+
+ // le'ts remove this
+ List<Integer> numbers = Lists.newArrayList(result.keySet());
+
+ Collections.sort(numbers);
+
+ result2 = Maps.newTreeMap();
+ int i = 0;
+ for (Integer number : numbers) {
+ Choice choice = result.get(number);
+ result2.put(i++, choice);
+ }
+ } else {
+ result2 = result;
+ }
+ return result2;
+ }
+
+ private <O> void addtoList(List<O> list, int index, O object) {
+
+ while (list.size() < index) {
+ list.add(null);
+ }
+ list.add(index, object);
+ }
+
+
+ private String getNonEmptyParameterValue(String paramName) {
+ String[] paramValues = parameters.get(paramName);
+ String result = null;
+ if (paramValues.length == 1) {
+ String paramValue = paramValues[0];
+ if (StringUtils.isNotEmpty(paramValue)) {
+ result = paramValue;
+ }
+ }
+ return result;
+ }
+
+ private <E extends Enum<E> & I18nAble> Map<String, String> decorateToName(E... values) {
+ Map<String, String> result = Maps.newLinkedHashMap();
+ for (E value : values) {
+ result.put(value.name(), getText(value.getI18nKey()));
+ }
+ return result;
+ }
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/CreatePoll.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Delete.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Delete.java 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Delete.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -1,37 +0,0 @@
-/*
- * #%L
- * Pollen :: UI (strust2)
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package org.chorem.pollen.ui.actions.poll;
-
-import org.chorem.pollen.ui.actions.PollenActionSupport;
-
-/**
- * Deletes an existing poll.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.2.6
- */
-public class Delete extends PollenActionSupport {
-
- private static final long serialVersionUID = 1L;
-}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteChoice.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteChoice.java 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteChoice.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -51,7 +51,6 @@
PollService service = newService(PollService.class);
service.deleteChoice(pollId, choiceId);
- getTransaction().commitTransaction();
return SUCCESS;
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteComment.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -64,8 +64,6 @@
service.deleteComment(commentId);
- getTransaction().commitTransaction();
-
commentName = getDefaultCommentName();
return SUCCESS;
Copied: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java (from rev 3163, branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Delete.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -0,0 +1,37 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.actions.poll;
+
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+
+/**
+ * Deletes an existing poll.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class DeletePoll extends AbstractPollUriIdAction {
+
+ private static final long serialVersionUID = 1L;
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeletePoll.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DeleteVote.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -51,7 +51,6 @@
PollService service = newService(PollService.class);
service.deleteVote(pollId, voteId);
- getTransaction().commitTransaction();
return SUCCESS;
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayDateChoice.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayDateChoice.java 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/DisplayDateChoice.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -23,8 +23,7 @@
*/
package org.chorem.pollen.ui.actions.poll;
-import org.chorem.pollen.business.persistence.Choice;
-import org.chorem.pollen.business.persistence.ChoiceImpl;
+import org.chorem.pollen.bean.PollDateChoice;
/**
* To generate the display for a date choice.
@@ -39,10 +38,11 @@
public static final String CHOICE_TOKEN = "dateChoice";
@Override
- protected Choice createEmptyChoice() {
- Choice result = new ChoiceImpl();
+ protected PollDateChoice createEmptyChoice() {
+ PollDateChoice result = new PollDateChoice();
result.setName("");
result.setDescription("");
+ result.setDate(null);
return result;
}
}
Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Edit.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Edit.java 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Edit.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -1,37 +0,0 @@
-/*
- * #%L
- * Pollen :: UI (strust2)
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package org.chorem.pollen.ui.actions.poll;
-
-import org.chorem.pollen.ui.actions.PollenActionSupport;
-
-/**
- * Display a poll.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.2.6
- */
-public class Edit extends PollenActionSupport {
-
- private static final long serialVersionUID = 1L;
-}
Copied: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java (from rev 3163, branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Edit.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -0,0 +1,37 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.actions.poll;
+
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+
+/**
+ * Display a poll.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class EditPoll extends AbstractPollUriIdAction {
+
+ private static final long serialVersionUID = 1L;
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/EditPoll.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Export.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Export.java 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Export.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -1,37 +0,0 @@
-/*
- * #%L
- * Pollen :: UI (strust2)
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package org.chorem.pollen.ui.actions.poll;
-
-import org.chorem.pollen.ui.actions.PollenActionSupport;
-
-/**
- * Exports an existing poll.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.2.6
- */
-public class Export extends PollenActionSupport {
-
- private static final long serialVersionUID = 1L;
-}
Copied: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java (from rev 3163, branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/Export.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -0,0 +1,37 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.pollen.ui.actions.poll;
+
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+
+/**
+ * Exports an existing poll.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class ExportPoll extends AbstractPollUriIdAction {
+
+ private static final long serialVersionUID = 1L;
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetFeed.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetFeed.java 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetFeed.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -1,88 +0,0 @@
-/*
- * #%L
- * Pollen :: UI (strust2)
- *
- * $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.ui.actions.poll;
-
-import com.google.common.base.Preconditions;
-import org.chorem.pollen.business.persistence.Poll;
-import org.chorem.pollen.services.exceptions.PollNotFoundException;
-import org.chorem.pollen.services.impl.PollFeedService;
-import org.chorem.pollen.services.impl.PollService;
-import org.chorem.pollen.ui.actions.PollenActionSupport;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-
-/**
- * Obtain the feed of a given poll.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.2.6
- */
-public class GetFeed extends PollenActionSupport {
-
- private static final long serialVersionUID = 1L;
-
- protected String pollId;
-
- protected long contentLength;
-
- protected transient InputStream inputStream;
-
- public void setPollId(String pollId) {
- this.pollId = pollId;
- }
-
- public long getContentLength() {
- return contentLength;
- }
-
- public InputStream getInputStream() {
- return inputStream;
- }
-
- @Override
- public String execute() throws Exception {
-
- Preconditions.checkNotNull(pollId);
-
- PollService service = newService(PollService.class);
-
- Poll poll = service.getPollByPollId(pollId);
-
- if (poll == null) {
- throw new PollNotFoundException();
- }
-
- PollFeedService pollFeedService = newService(PollFeedService.class);
-
- File feedLocation = pollFeedService.getFeedLocation(poll);
-
- contentLength = feedLocation.length();
-
- inputStream = new FileInputStream(feedLocation);
-
- return SUCCESS;
- }
-}
Copied: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetPollFeed.java (from rev 3163, branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetFeed.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetPollFeed.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetPollFeed.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -0,0 +1,88 @@
+/*
+ * #%L
+ * Pollen :: UI (strust2)
+ *
+ * $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.ui.actions.poll;
+
+import com.google.common.base.Preconditions;
+import org.chorem.pollen.business.persistence.Poll;
+import org.chorem.pollen.services.exceptions.PollNotFoundException;
+import org.chorem.pollen.services.impl.PollFeedService;
+import org.chorem.pollen.services.impl.PollService;
+import org.chorem.pollen.ui.actions.PollenActionSupport;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+/**
+ * Obtain the feed of a given poll.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class GetPollFeed extends PollenActionSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String pollId;
+
+ protected long contentLength;
+
+ protected transient InputStream inputStream;
+
+ public void setPollId(String pollId) {
+ this.pollId = pollId;
+ }
+
+ public long getContentLength() {
+ return contentLength;
+ }
+
+ public InputStream getInputStream() {
+ return inputStream;
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ Preconditions.checkNotNull(pollId);
+
+ PollService service = newService(PollService.class);
+
+ Poll poll = service.getPollByPollId(pollId);
+
+ if (poll == null) {
+ throw new PollNotFoundException();
+ }
+
+ PollFeedService pollFeedService = newService(PollFeedService.class);
+
+ File feedLocation = pollFeedService.getFeedLocation(poll);
+
+ contentLength = feedLocation.length();
+
+ inputStream = new FileInputStream(feedLocation);
+
+ return SUCCESS;
+ }
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/GetPollFeed.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -198,10 +198,6 @@
return topRanking;
}
-// public List<PollResult> getRanking() {
-// return ranking;
-// }
-
public boolean isFreePoll() {
return poll.getPollType() == PollType.FREE;
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Register.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Register.java 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/user/Register.java 2012-03-07 16:56:43 UTC (rev 3167)
@@ -66,12 +66,10 @@
@Override
public String execute() throws Exception {
- UserService service = newService(UserService.class);
-
String result = INPUT;
try {
- UserAccount createdUser = service.createUser(user, false);
- getTransaction().commitTransaction();
+ UserAccount createdUser =
+ newService(UserService.class).createUser(user, false);
getPollenSession().setUserAccount(createdUser);
addActionMessage(_("pollen.information.your.are.loggued"));
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-03-07 16:56:43 UTC (rev 3167)
@@ -42,7 +42,7 @@
<!-- create poll -->
<action name="create"
- class="org.chorem.pollen.ui.actions.poll.Create">
+ class="org.chorem.pollen.ui.actions.poll.CreatePoll">
<result name="input">/WEB-INF/jsp/poll/create.jsp</result>
<result>/WEB-INF/jsp/poll/resume.jsp</result>
</action>
@@ -67,7 +67,7 @@
<!-- edit poll -->
<action name="modification/*"
- class="org.chorem.pollen.ui.actions.poll.Edit">
+ class="org.chorem.pollen.ui.actions.poll.EditPoll">
<param name="uriId">{1}</param>
<result name="input">/WEB-INF/jsp/poll/edit.jsp</result>
<result>/WEB-INF/jsp/poll/resume.jsp</result>
@@ -90,7 +90,7 @@
<!-- clone poll -->
<action name="clone/*"
- class="org.chorem.pollen.ui.actions.poll.Clone">
+ class="org.chorem.pollen.ui.actions.poll.ClonePoll">
<param name="uriId">{1}</param>
<result name="input">/WEB-INF/jsp/poll/clone.jsp</result>
<result>/WEB-INF/jsp/home.jsp</result>
@@ -98,7 +98,7 @@
<!-- export poll -->
<action name="export/*"
- class="org.chorem.pollen.ui.actions.poll.Export">
+ class="org.chorem.pollen.ui.actions.poll.ExportPoll">
<param name="uriId">{1}</param>
<result name="input">/WEB-INF/jsp/poll/export.jsp</result>
<result>/WEB-INF/jsp/home.jsp</result>
@@ -106,7 +106,7 @@
<!-- close poll -->
<action name="close/*"
- class="org.chorem.pollen.ui.actions.poll.Close">
+ class="org.chorem.pollen.ui.actions.poll.ClosePoll">
<param name="uriId">{1}</param>
<result name="input">/WEB-INF/jsp/poll/close.jsp</result>
<result>/WEB-INF/jsp/home.jsp</result>
@@ -114,7 +114,7 @@
<!-- delete poll -->
<action name="delete/*"
- class="org.chorem.pollen.ui.actions.poll.Delete">
+ class="org.chorem.pollen.ui.actions.poll.DeletePoll">
<param name="uriId">{1}</param>
<result name="input">/WEB-INF/jsp/poll/delete.jsp</result>
<result>/WEB-INF/jsp/home.jsp</result>
@@ -163,7 +163,7 @@
</action>
<!-- get the feed of a given poll -->
- <action name="getFeed" class="org.chorem.pollen.ui.actions.poll.GetFeed">
+ <action name="getFeed" class="org.chorem.pollen.ui.actions.poll.GetPollFeed">
<result type="stream">
<param name="contentCharSet">UTF-8</param>
<param name="contentType">application/atom+xml</param>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/create.jsp 2012-03-07 16:56:43 UTC (rev 3167)
@@ -59,15 +59,6 @@
}
});
- $('[name="notification"]').change(function (event) {
- var val = $(this).prop('checked');
- if (val) {
- $('#notificationPanel').show();
- } else {
- $('#notificationPanel').hide();
- }
- });
-
$('[name="poll.anonymous"]').change(function (event) {
var val = $(this).prop('checked');
$('[name="poll.anonymousVoteAllowed"]').prop('checked', val);
@@ -207,10 +198,6 @@
</div>
<s:checkbox key="notification"
label="%{getText('pollen.common.pollOption.notification')}"/>
- <div id='notificationPanel' class="hidden">
- <s:textfield key="notificationNumber"
- label="%{getText('pollen.common.pollOption.notificationNumber')}"/>
- </div>
<s:checkbox key="reminder"
label="%{getText('pollen.common.pollOption.reminder')}"/>
<div id='reminderPanel' class="hidden">
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/dateChoice.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/dateChoice.jsp 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/dateChoice.jsp 2012-03-07 16:56:43 UTC (rev 3167)
@@ -36,7 +36,7 @@
theme="simple" value=''/>
<sj:datepicker id='%{#prefix}.name' key="%{#prefix}.name" changeMonth="true"
changeYear="true" labelSeparator="" theme="simple" label=""
- timepicker="true" value="%{choice.name}"/>
+ timepicker="true" value="%{choice.date}"/>
-
<s:label for="%{#prefix}.description" key="pollen.common.description"
theme="simple"/>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-03-07 16:44:51 UTC (rev 3166)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-03-07 16:56:43 UTC (rev 3167)
@@ -483,7 +483,7 @@
<div id="commentFormDiv">
<s:form id='addCommentForm' method="POST" namespace="/poll">
- <s:hidden key="pollId" label=''/>
+ <s:hidden key="uriId" label=''/>
<s:textfield key="commentName" required="true" size="78"
label="%{getText('pollen.common.commentName')}"/>
<s:textarea key="commentText" required="true" value=''
1
0
r3166 - in branches/pollen-1.2.6-struts2/pollen-services/src: main/java/org/chorem/pollen/bean main/java/org/chorem/pollen/services main/java/org/chorem/pollen/services/impl main/resources/i18n test/java/org/chorem/pollen/services test/resources
by tchemit@users.chorem.org 07 Mar '12
by tchemit@users.chorem.org 07 Mar '12
07 Mar '12
Author: tchemit
Date: 2012-03-07 17:44:51 +0100 (Wed, 07 Mar 2012)
New Revision: 3166
Url: http://chorem.org/repositories/revision/pollen/3166
Log:
reuse the siteUrl applicationUrl, safer than using url from request...
add prevent rule notifier
clean PollFeedService and EmailService
and more...
Added:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollDateChoice.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenNotifierWorker.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PreventRuleService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/SendMail.java
Modified:
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollImageChoice.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/EmailService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties
branches/pollen-1.2.6-struts2/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties
branches/pollen-1.2.6-struts2/pollen-services/src/test/java/org/chorem/pollen/services/FakeServiceContext.java
branches/pollen-1.2.6-struts2/pollen-services/src/test/resources/log4j.properties
branches/pollen-1.2.6-struts2/pollen-services/src/test/resources/pollen-fake.properties
Added: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollDateChoice.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollDateChoice.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollDateChoice.java 2012-03-07 16:44:51 UTC (rev 3166)
@@ -0,0 +1,66 @@
+/*
+ * #%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.bean;
+
+import org.chorem.pollen.business.persistence.Choice;
+import org.chorem.pollen.business.persistence.ChoiceImpl;
+
+import java.util.Date;
+
+/**
+ * Extends the basic choice to keep the date (will be transformed to name)
+ * (during poll creation).
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class PollDateChoice extends ChoiceImpl {
+
+ private static final long serialVersionUID = 1L;
+
+ protected Date date;
+
+ public Date getDate() {
+ return date;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ public void fromChoice(Choice choice) {
+ setName(choice.getName());
+ setDescription(choice.getDescription());
+ setTopiaId(choice.getTopiaId());
+ setValidate(choice.isValidate());
+ setPoll(choice.getPoll());
+ setDate(new Date(Long.valueOf(choice.getName())));
+ }
+
+ public void toChoice(Choice choice) {
+ choice.setName(String.valueOf(getDate().getTime()));
+ choice.setDescription(getDescription());
+ choice.setValidate(isValidate());
+ }
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollDateChoice.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollImageChoice.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollImageChoice.java 2012-03-07 16:43:44 UTC (rev 3165)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/bean/PollImageChoice.java 2012-03-07 16:44:51 UTC (rev 3166)
@@ -23,6 +23,7 @@
*/
package org.chorem.pollen.bean;
+import org.chorem.pollen.business.persistence.Choice;
import org.chorem.pollen.business.persistence.ChoiceImpl;
/**
@@ -33,6 +34,7 @@
* @since 1.2.6
*/
public class PollImageChoice extends ChoiceImpl {
+
private static final long serialVersionUID = 1L;
protected String location;
@@ -44,4 +46,18 @@
public void setLocation(String location) {
this.location = location;
}
+
+ public void fromChoice(Choice choice) {
+ setName(choice.getName());
+ setDescription(choice.getDescription());
+ setTopiaId(choice.getTopiaId());
+ setValidate(choice.isValidate());
+ setPoll(choice.getPoll());
+ }
+
+ public void toChoice(Choice choice) {
+ choice.setName(getName());
+ choice.setDescription(getDescription());
+ choice.setValidate(isValidate());
+ }
}
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2012-03-07 16:43:44 UTC (rev 3165)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2012-03-07 16:44:51 UTC (rev 3166)
@@ -48,16 +48,13 @@
protected Locale locale;
- private final URL applicationURL;
-
public static PollenServiceContext newContext(
PollenServiceContext serviceContext,
TopiaContext transaction) {
return newContext(serviceContext.getLocale(),
transaction,
serviceContext.getConfiguration(),
- serviceContext.getServiceFactory(),
- serviceContext.getApplicationURL()
+ serviceContext.getServiceFactory()
);
}
@@ -66,25 +63,21 @@
Locale locale,
TopiaContext transaction,
PollenConfiguration configuration,
- PollenServiceFactory serviceFactory,
- URL applicationURL) {
+ PollenServiceFactory serviceFactory) {
return new DefaultPollenServiceContext(locale,
transaction,
configuration,
- serviceFactory,
- applicationURL);
+ serviceFactory);
}
protected DefaultPollenServiceContext(Locale locale,
TopiaContext transaction,
PollenConfiguration configuration,
- PollenServiceFactory serviceFactory,
- URL applicationURL) {
+ PollenServiceFactory serviceFactory) {
this.locale = locale;
this.transaction = transaction;
this.configuration = configuration;
this.serviceFactory = serviceFactory;
- this.applicationURL = applicationURL;
}
@Override
@@ -105,7 +98,7 @@
@Override
public URL getApplicationURL() {
- return applicationURL;
+ return getConfiguration().getApplicationUrl();
}
@Override
Added: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenNotifierWorker.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenNotifierWorker.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenNotifierWorker.java 2012-03-07 16:44:51 UTC (rev 3166)
@@ -0,0 +1,116 @@
+/*
+ * #%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;
+
+import com.google.common.base.Preconditions;
+import org.chorem.pollen.PollenTechnicalException;
+import org.chorem.pollen.business.persistence.Poll;
+import org.chorem.pollen.business.persistence.PreventRule;
+import org.chorem.pollen.services.impl.PollService;
+import org.chorem.pollen.services.impl.PreventRuleService;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+
+/**
+ * This service run as a daemon seek to send some notification from running poll
+ * store in {@link PreventRule}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class PollenNotifierWorker implements Runnable, Closeable {
+
+ /** Service context used to create other services. */
+ protected final PollenServiceContext serviceContext;
+
+ /** Timer gérant les threads. */
+ private final Timer timer;
+
+ /** Topia root context to pollen db. */
+ private final TopiaContext rootContext;
+
+ public PollenNotifierWorker(PollenServiceContext serviceContext,
+ TopiaContext rootContext) {
+ Preconditions.checkNotNull(serviceContext);
+ Preconditions.checkNotNull(rootContext);
+ Preconditions.checkState(!rootContext.isClosed());
+ this.rootContext = rootContext;
+ this.serviceContext = serviceContext;
+ timer = new Timer();
+ }
+
+ @Override
+ public void run() {
+
+ // starts it
+ timer.schedule(new TimerTask() {
+
+ @Override
+ public void run() {
+ try {
+ TopiaContext transaction = rootContext.beginTransaction();
+ try {
+ serviceContext.setTransaction(transaction);
+
+ PollService pollService =
+ serviceContext.newService(PollService.class);
+ PreventRuleService preventRuleService =
+ serviceContext.newService(PreventRuleService.class);
+
+ // Récupération des sondages en cours
+ List<Poll> polls = pollService.getRunningPolls(true);
+
+ for (Poll poll : polls) {
+
+ String pollVoteUrl = pollService.getPollVoteUrl(poll);
+
+ preventRuleService.onPollToRemind(poll, pollVoteUrl);
+
+ }
+
+ } finally {
+
+ serviceContext.setTransaction(null);
+
+ transaction.closeContext();
+ }
+ } catch (TopiaException e) {
+ throw new PollenTechnicalException("Topia problem", e);
+ }
+ }
+ }, 600000, 600000);
+ }
+
+ @Override
+ public void close() throws IOException {
+ timer.cancel();
+ }
+
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/PollenNotifierWorker.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/EmailService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/EmailService.java 2012-03-07 16:43:44 UTC (rev 3165)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/EmailService.java 2012-03-07 16:44:51 UTC (rev 3166)
@@ -24,70 +24,295 @@
package org.chorem.pollen.services.impl;
import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
import org.chorem.pollen.PollenConfiguration;
import org.chorem.pollen.PollenTechnicalException;
+import org.chorem.pollen.business.persistence.PersonToList;
+import org.chorem.pollen.business.persistence.Poll;
+import org.chorem.pollen.business.persistence.PollAccount;
+import org.chorem.pollen.business.persistence.UserAccount;
+import org.chorem.pollen.business.persistence.VotingList;
import org.chorem.pollen.services.PollenServiceSupport;
+import org.nuiton.util.StringUtil;
+import java.net.URL;
+import java.util.List;
+import java.util.Locale;
+
+import static org.nuiton.i18n.I18n.l_;
+
public class EmailService extends PollenServiceSupport {
/** Logger. */
private static final Log log = LogFactory.getLog(EmailService.class);
- public void sendEmail(String to,
- String subject,
- String content) {
+ public void onUserCreated(UserAccount user) {
+ URL url = serviceContext.getApplicationURL();
+
+ if (url != null && StringUtil.isEmail(user.getEmail())) {
+
+ Locale locale = getLocale();
+ String subject = l_(locale, "pollen.email.userRegister.subject",
+ user.getLogin());
+ String content = l_(locale, "pollen.email.userRegister.content",
+ user.getDisplayName(),
+ user.getLogin(), user.getPassword(), url);
+
+ PollEmail pollEmail = createPollEmail(user.getEmail(),
+ subject,
+ content);
+
+ sendEmail(pollEmail);
+ }
+ }
+
+ public void onVoteAdded(Poll poll, String voteURL, String modifURL) {
+
+ URL url = serviceContext.getApplicationURL();
+
+ if (url != null) {
+
+ Locale locale = getLocale();
+
+ String pollTitle = poll.getTitle();
+
+ // Mail au créateur
+
+ if (StringUtils.isNotEmpty(poll.getCreator().getEmail())) {
+
+ String subject = l_(locale, "pollen.email.creatorEmail.subject",
+ pollTitle);
+ String content = l_(locale, "pollen.email.creatorEmail.content",
+ pollTitle, voteURL, modifURL);
+
+ PollEmail pollEmail = createPollEmail(
+ poll.getCreator().getEmail(), subject, content);
+
+ sendEmail(pollEmail);
+ }
+
+ }
+ }
+
+ public void onPollCreated(Poll poll, String voteURL, String modifURL) {
+
+ URL url = serviceContext.getApplicationURL();
+
+ if (url != null) {
+
+ Locale locale = getLocale();
+
+ String pollTitle = poll.getTitle();
+
+ // Mail au créateur
+
+ if (StringUtils.isNotEmpty(poll.getCreator().getEmail())) {
+
+ String subject = l_(locale, "pollen.email.creatorEmail.subject",
+ pollTitle);
+ String content = l_(locale, "pollen.email.creatorEmail.content",
+ pollTitle, voteURL, modifURL);
+
+ PollEmail pollEmail = createPollEmail(
+ poll.getCreator().getEmail(), subject, content);
+
+ sendEmail(pollEmail);
+ }
+
+ // Mails à tous les votants
+ List<PollAccount> votingPollAccounts =
+ getVotingPollAccounts(poll, false);
+
+ if (CollectionUtils.isNotEmpty(votingPollAccounts)) {
+ String subject = l_(locale, "pollen.email.votingEmail.subject",
+ pollTitle);
+
+ List<PollEmail> emails = Lists.newArrayList();
+ for (PollAccount account : votingPollAccounts) {
+ String accountVoteURL =
+ voteURL + ":" + account.getAccountId();
+
+ String content =
+ l_(locale, "pollen.email.votingEmail.content",
+ pollTitle, voteURL, accountVoteURL);
+
+ PollEmail pollEmail = createPollEmail(
+ account.getEmail(), subject, content);
+
+ emails.add(pollEmail);
+ }
+
+ sendEmail(emails);
+ }
+ }
+ }
+
+ public void onPollReminder(Poll poll, String voteURL) {
+
+ URL url = serviceContext.getApplicationURL();
+
+ if (url != null) {
+
+ Locale locale = getLocale();
+
+ String pollTitle = poll.getTitle();
+
+ // Mails aux votants qui n'ont toujours pas voté
+ List<PollAccount> votingPollAccounts = getVotingPollAccounts(poll, true);
+
+ if (CollectionUtils.isNotEmpty(votingPollAccounts)) {
+ String subject = l_(locale, "pollen.email.reminderEmail.subject",
+ pollTitle);
+
+ List<PollEmail> emails = Lists.newArrayList();
+ for (PollAccount account : votingPollAccounts) {
+ String accountVoteURL =
+ voteURL + ":" + account.getAccountId();
+
+ String content =
+ l_(locale, "pollen.email.reminderEmail.content",
+ pollTitle, account.getVotingId(), accountVoteURL);
+
+ PollEmail pollEmail = createPollEmail(
+ account.getEmail(), subject, content);
+
+ emails.add(pollEmail);
+ }
+ sendEmail(emails);
+ }
+ }
+ }
+
+ //TODO Move this to Poll
+ protected List<PollAccount> getVotingPollAccounts(Poll poll,
+ boolean keepOnlyIfNotHasVoted) {
+ List<PollAccount> result = Lists.newLinkedList();
+
+ if (!poll.isVotingListEmpty()) {
+
+ for (VotingList votingList : poll.getVotingList()) {
+
+ if (!votingList.isPollAccountPersonToListEmpty()) {
+
+ for (PersonToList personToList :
+ votingList.getPollAccountPersonToList()) {
+
+ if (!keepOnlyIfNotHasVoted || !personToList.isHasVoted()) {
+
+ PollAccount account = personToList.getPollAccount();
+ result.add(account);
+ }
+
+
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ protected void sendEmail(Iterable<PollEmail> pollEmails) {
+
+ //TODO tchemit If two much mails then use SendEmail thread...
+ for (PollEmail pollEmail : pollEmails) {
+ sendEmail(pollEmail);
+ }
+
+// // send mail preparation
+// try {
+// sendMailService.prepareMails(poll.getId(), mailList);
+// sendMailService.wakeUp();
+// } catch (IOException ex) {
+// if (log.isErrorEnabled()) {
+// log.error("Can't prepare send mail on disk, mail won't be send !!!", ex);
+// }
+// }
+
+ }
+
+ protected void sendEmail(PollEmail pollEmail) {
+
+ Preconditions.checkNotNull(pollEmail);
+
+ String to = pollEmail.getTo();
Preconditions.checkNotNull(to);
+
+ String subject = pollEmail.getSubject();
Preconditions.checkNotNull(subject);
+
+ String content = pollEmail.getContent();
Preconditions.checkNotNull(content);
try {
// Create the SimpleEmail to send
- SimpleEmail email = createSimpleEmail(to, subject, content);
+ SimpleEmail email = new SimpleEmail();
+
+ PollenConfiguration configuration = getConfiguration();
+
+ email.setHostName(configuration.getEmailHost());
+ email.setSmtpPort(configuration.getEmailPort());
+ email.setFrom(configuration.getEmailFrom());
+ email.setCharset(configuration.getCharset());
+
+ email.addTo(to);
+ email.setSubject(subject);
+ email.setMsg(content);
email.send();
if (log.isInfoEnabled()) {
log.info("Mail sent to : " + to);
-
- if (log.isDebugEnabled()) {
- log.debug("Email infos : " +
- "\ndate: " + email.getSentDate() +
- "\nhostname: " + email.getHostName() +
- "\nport: " + email.getSmtpPort() +
- "\nfrom: " + email.getFromAddress().toString());
- }
}
+ if (log.isDebugEnabled()) {
+ log.debug("Email infos : " +
+ "\ndate: " + email.getSentDate() +
+ "\nhostname: " + email.getHostName() +
+ "\nport: " + email.getSmtpPort() +
+ "\nfrom: " + email.getFromAddress().toString());
+ }
} catch (EmailException eee) {
throw new PollenTechnicalException(
"could not send email to " + to, eee);
}
}
- protected SimpleEmail createSimpleEmail(
- String to,
- String subject,
- String content) throws EmailException {
+ public static PollEmail createPollEmail(String to,
+ String subject,
+ String content) {
+ return new PollEmail(to, subject, content);
+ }
- Preconditions.checkNotNull(to);
- Preconditions.checkNotNull(subject);
- Preconditions.checkNotNull(content);
+ public static class PollEmail {
- PollenConfiguration configuration = getConfiguration();
+ protected String subject;
- SimpleEmail result = new SimpleEmail();
- result.setHostName(configuration.getEmailHost());
- result.setSmtpPort(configuration.getEmailPort());
- result.setFrom(configuration.getEmailFrom());
- result.setCharset(configuration.getCharset());
+ protected String content;
- result.addTo(to);
- result.setSubject(subject);
- result.setMsg(content);
- return result;
+ protected String to;
+
+
+ private PollEmail(String to, String subject, String content) {
+ this.subject = subject;
+ this.content = content;
+ this.to = to;
+ }
+
+ public String getSubject() {
+ return subject;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public String getTo() {
+ return to;
+ }
}
-
}
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-03-07 16:43:44 UTC (rev 3165)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-03-07 16:44:51 UTC (rev 3166)
@@ -76,9 +76,15 @@
// add it to poll
pollToUpdate.addComment(commentCreated);
- // add a feed entry
+ commitTransaction("Could not create comment");
+
+ // feed notification
+
+ PollService pollService = newService(PollService.class);
+
+ String pollVoteUrl = pollService.getPollVoteUrl(poll);
PollFeedService pollFeedService = newService(PollFeedService.class);
- pollFeedService.addFeedEntryWhenCreateComment(commentCreated);
+ pollFeedService.onAddComment(commentCreated, pollVoteUrl);
return commentCreated;
} catch (TopiaException e) {
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java 2012-03-07 16:43:44 UTC (rev 3165)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollFeedService.java 2012-03-07 16:44:51 UTC (rev 3166)
@@ -23,6 +23,7 @@
*/
package org.chorem.pollen.services.impl;
+import com.google.common.collect.Lists;
import com.sun.syndication.feed.synd.SyndContent;
import com.sun.syndication.feed.synd.SyndContentImpl;
import com.sun.syndication.feed.synd.SyndEntry;
@@ -44,7 +45,6 @@
import java.io.File;
import java.io.FileWriter;
import java.io.Writer;
-import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -81,25 +81,17 @@
return result;
}
- /**
- * Création d'un flux.
- *
- * @param poll poll
- * @param type type de flux (rss_2.0, atom_1.0)
- */
- public void createFeed(Poll poll, String type) {
-
+ public void onPollCreated(Poll poll, String pollVoteUrl) {
File file = getFeedLocation(poll);
String title = l_(getLocale(), "pollen.feed.pollTitle", poll.getTitle());
String description = l_(getLocale(), "pollen.feed.pollDescription", poll.getDescription());
- String link = getPollFeedLink(poll);
try {
SyndFeed feed = new SyndFeedImpl();
- feed.setFeedType(type);
+ feed.setFeedType("atom_1.0");
feed.setTitle(title);
- feed.setLink(link);
+ feed.setLink(pollVoteUrl);
feed.setDescription(description);
Writer writer = new FileWriter(file);
@@ -110,30 +102,102 @@
if (log.isDebugEnabled()) {
log.debug("Feed created: " + file.getAbsolutePath());
}
+
+ title = _("pollen.feed.createPollContent",
+ poll.getCreator().getVotingId());
+
+ String content = _("pollen.feed.createPollContent",
+ poll.getDescription());
+
+ addFeedEntry(poll, title, content, pollVoteUrl);
} catch (Exception e) {
throw new PollenTechnicalException("Could not create feed", e);
}
}
+ public void onAddComment(Comment comment, String pollVoteUrl) {
+
+ //TODO Validate this is ok
+ String title = _("pollen.feed.addCommentTitle",
+ comment.getPollAccount().getVotingId());
+
+ String content = _("pollen.feed.addCommentContent",
+ comment.getText());
+
+ addFeedEntry(comment.getPoll(), title, content, pollVoteUrl);
+ }
+
+ public void onAddVote(Vote vote,
+ boolean anonymousVote,
+ String pollResult
+ , String pollVoteUrl) {
+
+ String userId;
+ if (anonymousVote) {
+ userId = _("pollen.common.anonymous");
+ } else {
+ userId = vote.getPollAccount().getVotingId();
+
+ }
+ String title = _("pollen.feed.addVoteTitle", userId);
+
+ String content = _("pollen.feed.addVoteContent", pollResult);
+
+ addFeedEntry(vote.getPoll(), title, content, pollVoteUrl);
+ }
+
+ public void onAddChoice(Choice choice, String pollVoteUrl) {
+
+ String title = _("pollen.feed.addChoiceTitle", choice.getName());
+
+ String content = _("pollen.feed.addChoiceContent",
+ choice.getDescription());
+
+ addFeedEntry(choice.getPoll(), title, content, pollVoteUrl);
+ }
+
/**
+ * Delete the poll feed file.
+ *
+ * @param poll poll
+ */
+ public void deleteFeed(Poll poll) {
+
+ File feedLocation = getFeedLocation(poll);
+ if (feedLocation.exists()) {
+ boolean wasDeleted = feedLocation.delete();
+ if (!wasDeleted) {
+ throw new PollenTechnicalException("Could not delete feed");
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Feed deleted: " + feedLocation.getAbsolutePath());
+ }
+ }
+ }
+
+ /**
* Ajout d'une entrée dans un flux.
*
- * @param poll poll
- * @param title titre de l'entrée
- * @param content contenu de l'entrée
+ * @param poll poll
+ * @param title titre de l'entrée
+ * @param content contenu de l'entrée
+ * @param pollVoteUrl poll vote url
*/
- public void feedFeed(Poll poll, String title,
- String content) {
+ protected void addFeedEntry(Poll poll,
+ String title,
+ String content,
+ String pollVoteUrl) {
+ //TODO tchemitshould remove this, may migrates when going to version 2.0
+ //TODO pass on all polls from database and creates the feed if not found.
if (!isFeedExists(poll)) {
- createFeed(poll, "atom_1.0");
+ onPollCreated(poll, pollVoteUrl);
}
File file = getFeedLocation(poll);
- String link = getPollFeedLink(poll);
try {
- List entries = new ArrayList();
+ List entries = Lists.newArrayList();
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(file));
entries.addAll(feed.getEntries());
@@ -142,7 +206,7 @@
SyndContent description;
entry = new SyndEntryImpl();
entry.setTitle(title);
- entry.setLink(link);
+ entry.setLink(pollVoteUrl);
entry.setPublishedDate(new Date());
description = new SyndContentImpl();
description.setType("text/plain");
@@ -167,83 +231,4 @@
throw new PollenTechnicalException("Could not feed feed", e);
}
}
-
- /**
- * Delete the poll feed file.
- *
- * @param poll poll
- */
- public void deleteFeed(Poll poll) {
-
- File feedLocation = getFeedLocation(poll);
- if (feedLocation.exists()) {
- boolean wasDeleted = feedLocation.delete();
- if (!wasDeleted) {
- throw new PollenTechnicalException("Could not delete feed");
- }
- if (log.isDebugEnabled()) {
- log.debug("Feed deleted: " + feedLocation.getAbsolutePath());
- }
- }
- }
-
- public void addFeedEntryWhenCreatePoll(Poll poll) {
-
-
- String title = _("pollen.feed.createPollContent",
- poll.getCreator().getVotingId());
-
- String content = _("pollen.feed.createPollContent",
- poll.getDescription());
-
- feedFeed(poll, title, content);
- }
-
-
- public void addFeedEntryWhenCreateComment(Comment comment) {
-
- //TODO Validate this is ok
- String title = _("pollen.feed.addCommentTitle",
- comment.getPollAccount().getVotingId());
-
- String content = _("pollen.feed.addCommentContent",
- comment.getText());
-
- feedFeed(comment.getPoll(), title, content);
- }
-
- public void addFeedEntryWhenAddVote(Vote vote,
- boolean anonymousVote,
- String pollResult) {
-
- String userId;
- if (anonymousVote) {
- userId = _("pollen.common.anonymous");
- } else {
- userId = vote.getPollAccount().getVotingId();
-
- }
- String title = _("pollen.feed.addVoteTitle", userId);
-
- String content = _("pollen.feed.addVoteContent", pollResult);
-
- feedFeed(vote.getPoll(), title, content);
- }
-
- public void addFeedEntryWhenAddChoice(Choice choice) {
-
- String title = _("pollen.feed.addChoiceTitle", choice.getName());
-
- String content = _("pollen.feed.addChoiceContent",
- choice.getDescription());
-
- feedFeed(choice.getPoll(), title, content);
- }
-
- protected String getPollFeedLink(Poll poll) {
- String link =
- serviceContext.getApplicationURL() +
- "/poll/vote?pollId=" + poll.getPollId();
- return link;
- }
}
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-07 16:43:44 UTC (rev 3165)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-07 16:44:51 UTC (rev 3166)
@@ -30,6 +30,7 @@
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.PollenConfiguration;
import org.chorem.pollen.PollenTechnicalException;
+import org.chorem.pollen.bean.PollDateChoice;
import org.chorem.pollen.bean.PollImageChoice;
import org.chorem.pollen.business.persistence.Choice;
import org.chorem.pollen.business.persistence.ChoiceDAO;
@@ -49,6 +50,7 @@
import org.chorem.pollen.business.persistence.VotingList;
import org.chorem.pollen.business.persistence.VotingListDAO;
import org.chorem.pollen.common.ChoiceType;
+import org.chorem.pollen.common.PollType;
import org.chorem.pollen.services.PollenServiceSupport;
import org.chorem.pollen.services.exceptions.PollChoiceNotFoundException;
import org.chorem.pollen.services.exceptions.PollNotFoundException;
@@ -72,6 +74,7 @@
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
+import java.net.URL;
import java.util.List;
public class PollService extends PollenServiceSupport {
@@ -79,6 +82,11 @@
/** Logger. */
private static final Log log = LogFactory.getLog(PollService.class);
+
+ /** Représente l'action qui envoi un email de notification. */
+ public static final String RULE_EMAIL_ACTION = "emailAction";
+
+
/**
* Build a new Poll instance with given {@code user} as administrator
*
@@ -120,6 +128,12 @@
PollDAO pollDAO = getDAO(Poll.class);
Poll result = create(pollDAO);
+ // check max number choice authorized (can not be more than
+ if (poll.getMaxChoiceNb() < 1
+ || poll.getMaxChoiceNb() > poll.sizeChoice()) {
+ poll.setMaxChoiceNb(poll.sizeChoice());
+ }
+
result.setAnonymous(poll.isAnonymous());
result.setAnonymousVoteAllowed(poll.isAnonymousVoteAllowed());
result.setBeginChoiceDate(poll.getBeginChoiceDate());
@@ -212,10 +226,8 @@
ChoiceDAO choiceDAO = getDAO(Choice.class);
for (Choice choice : poll.getChoice()) {
+
Choice choiceCreated = create(choiceDAO);
- choiceCreated.setDescription(choice.getDescription());
- choiceCreated.setName(choice.getName());
- choiceCreated.setValidate(choice.isValidate());
result.addChoice(choiceCreated);
if (choiceType == ChoiceType.IMAGE) {
@@ -223,21 +235,66 @@
// copy image where it belong and generate the thumb
PollImageChoice imageChoice = (PollImageChoice) choice;
-
+ imageChoice.toChoice(choiceCreated);
try {
saveImages(result, imageChoice);
} catch (IOException e) {
throw new PollenTechnicalException(
"Could not create image choice", e);
}
+ } else if (choiceType == ChoiceType.DATE) {
+ // date choice
+ PollDateChoice dateChoice = (PollDateChoice) choice;
+ dateChoice.toChoice(choiceCreated);
+ } else {
+
+ // text choice
+ choiceCreated.setDescription(choice.getDescription());
+ choiceCreated.setValidate(choice.isValidate());
+ choiceCreated.setName(choice.getName());
}
}
}
+ commitTransaction("Could not create poll " + poll.getTitle());
+
+ String pollVoteUrl = getPollVoteUrl(poll);
+
+ // email notification
+ EmailService emailService = newService(EmailService.class);
+ emailService.onPollCreated(poll,
+ pollVoteUrl,
+ getPollEditUrl(poll));
+
+ // feed notification
+ PollFeedService pollFeedService = newService(PollFeedService.class);
+ pollFeedService.onPollCreated(poll, pollVoteUrl);
+
return result;
}
+
+ public String getPollVoteUrl(Poll poll) {
+ URL applicationUrl = serviceContext.getApplicationURL();
+ StringBuilder url = new StringBuilder(applicationUrl.toString());
+
+ url.append("/poll/votefor/").append(poll.getPollId());
+
+ if (poll.getPollType() != PollType.FREE) {
+ url.append(':').append(poll.getCreator().getAccountId());
+ }
+ return url.toString();
+ }
+
+ public String getPollEditUrl(Poll poll) {
+ URL applicationUrl = serviceContext.getApplicationURL();
+ StringBuilder url = new StringBuilder(applicationUrl.toString());
+
+ url.append("/poll/modification/").append(poll.getPollId());
+ url.append(':').append(poll.getCreator().getAccountId());
+ return url.toString();
+ }
/*
private void addFeedEntry() {
PollAccountDTO creator = servicePollAccount.findPollAccountById(poll.getCreatorId());
@@ -406,7 +463,50 @@
} catch (TopiaException e) {
throw new PollenTechnicalException(e);
}
+ }
+ public List<Poll> getRunningPolls(boolean withEndDate) {
+
+ List<Poll> results;
+ try {
+
+ PollDAO dao = getDAO(Poll.class);
+
+ TopiaQuery query;
+
+ if (withEndDate) {
+
+ query = dao.createQuery("poll").
+ addWhere("poll.endDate is not null and poll.endDate > current_timestamp()").
+ addWhere("poll.beginDate is null or poll.beginDate < current_timestamp()");
+
+// results = transaction
+// .find("from "
+// + Poll.class.getName()
+// + " as poll where (poll.endDate is not null and poll.endDate > current_timestamp())"
+// + " and (poll.beginDate is null or poll.beginDate < current_timestamp())");
+ } else {
+ query = dao.createQuery("poll").
+ addWhere("poll.endDate is null or poll.endDate > current_timestamp()").
+ addWhere("poll.beginDate is null or poll.beginDate < current_timestamp()");
+
+// results = transaction
+// .find("from "
+// + Poll.class.getName()
+// + " as poll where (poll.endDate is null or poll.endDate > current_timestamp())"
+// + " and (poll.beginDate is null or poll.beginDate < current_timestamp())");
+ }
+
+ results = dao.findAllByQuery(query);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Entities found: "
+ + ((results == null) ? "null" : results.size()));
+ }
+ return results;
+ } catch (TopiaException e) {
+ throw new PollenTechnicalException("Culd not obtain polls", e);
+ }
}
public Poll getPollByPollId(String pollId) {
Added: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PreventRuleService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PreventRuleService.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PreventRuleService.java 2012-03-07 16:44:51 UTC (rev 3166)
@@ -0,0 +1,192 @@
+/*
+ * #%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 com.google.common.base.Preconditions;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.business.persistence.Poll;
+import org.chorem.pollen.business.persistence.PreventRule;
+import org.chorem.pollen.business.persistence.PreventRuleDAO;
+import org.chorem.pollen.services.PollenServiceSupport;
+
+import java.util.Date;
+
+/**
+ * Manage prevent rules of a poll.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class PreventRuleService extends PollenServiceSupport {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(PreventRuleService.class);
+
+ public PreventRule createAddVotePreventRule() {
+ PreventRuleDAO dao = getDAO(PreventRule.class);
+ PreventRule rule = newInstance(dao);
+ rule.setScope("vote");
+ rule.setSensibility(1);
+ rule.setRepeated(true);
+ return rule;
+ }
+
+ public PreventRule createRemindPreventRule(int sensibility) {
+ PreventRuleDAO dao = getDAO(PreventRule.class);
+ PreventRule rule = newInstance(dao);
+ rule.setScope("rappel");
+ rule.setSensibility(sensibility);
+ rule.setRepeated(false);
+ return rule;
+ }
+
+ public void onVoteAdded(Poll poll, String pollVoteUrl, String modifURL) {
+
+ if (poll.getEndDate() != null) {
+
+ for (PreventRule rule : poll.getPreventRule()) {
+ onVoteAdded(poll,
+ rule,
+ pollVoteUrl,
+ modifURL
+ );
+ }
+ }
+ }
+
+ public void onPollToRemind(Poll poll, String pollVoteUrl) {
+
+ // Parcours des preventRules de chaque sondage
+ // envoi d'un email si endDate-nowDate <= preventRuleSensibility
+ if (poll.getEndDate() != null) {
+
+ Date now = new Date();
+
+ // timeValue = endDate-nowDate
+ long timeValue = poll.getEndDate().getTime() - now.getTime();
+
+ if (log.isDebugEnabled()) {
+ log.debug("Now: " + now.getTime() + " End: "
+ + poll.getEndDate().getTime() + " timeValue: "
+ + timeValue + "(" + timeValue / 3600000 + "h)");
+ }
+
+ int hourBeforeEnd = (int) (timeValue / 3600000);
+
+ for (PreventRule rule : poll.getPreventRule()) {
+
+ onPollToRemind(poll,
+ rule,
+ pollVoteUrl,
+ hourBeforeEnd
+ );
+ }
+ }
+ }
+
+ protected void onVoteAdded(Poll poll,
+ PreventRule preventRule,
+ String pollVoteUrl,
+ String modifURL) {
+
+ // send to creator a email to say hey a new vote was added!
+
+ if (execute("vote", preventRule, 1)) {
+
+ // ok can execute this task
+
+ EmailService emailService = newService(EmailService.class);
+
+ // let's send an email
+ emailService.onVoteAdded(poll, pollVoteUrl, modifURL);
+
+ // and update prevent rule
+ commitTransaction("Could not update prevent rule");
+ }
+ }
+
+ protected void onPollToRemind(Poll poll,
+ PreventRule preventRule,
+ String pollVoteUrl,
+ int timeValue) {
+
+ // send to all voting a email to say hey we need to vote
+
+ if (execute("rappel", preventRule, timeValue)) {
+
+ // ok can execute this task
+
+ EmailService emailService = newService(EmailService.class);
+
+ // let's send an email
+ emailService.onPollReminder(poll, pollVoteUrl);
+
+ // and update prevent rule
+ commitTransaction("Could not update prevent rule");
+ }
+ }
+
+ protected boolean execute(String scope,
+ PreventRule preventRule,
+ Integer value) {
+
+ Preconditions.checkNotNull(scope);
+ Preconditions.checkNotNull(value);
+
+ // Si la règle n'est pas active, on ne fait rien
+ if (!preventRule.isActive()) {
+ log.debug("Règle non active");
+ return false;
+ }
+
+ // Si la règle est à exécution unique, on la désactive
+ if (preventRule.isOneTime()) {
+ log.debug("Règle à exécution unique : désactivation");
+ preventRule.setActive(false);
+ }
+
+ if (!scope.equals(preventRule.getScope())) {
+
+ // pas bon scope
+ return false;
+ }
+
+ // Si la règle est répétitive (exécution tous les n), on met à jour la valeur
+ if (preventRule.isRepeated() && preventRule.getSensibility() != 0) {
+ value = value % preventRule.getSensibility()
+ + preventRule.getSensibility();
+ }
+
+ if (value != preventRule.getSensibility()) {
+
+ // pas la bonne valeur
+ return false;
+ }
+
+ // ok on peut lancer la tâche
+ return true;
+ }
+
+}
Property changes on: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PreventRuleService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/SendMail.java (from rev 3162, branches/pollen-1.2.6-struts2/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/SendMail.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/SendMail.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/SendMail.java 2012-03-07 16:44:51 UTC (rev 3166)
@@ -0,0 +1,316 @@
+/*
+ * #%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%
+ */
+/* *##% Pollen
+ * Copyright (C) 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. ##%*/
+
+package org.chorem.pollen.services.impl;
+
+import au.com.bytecode.opencsv.CSVReader;
+import au.com.bytecode.opencsv.CSVWriter;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.chorem.pollen.PollenConfiguration;
+import org.nuiton.util.FileUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.List;
+
+/**
+ * Note tchemit : Not used at the moment, perharps later if needed.
+ * <p/>
+ * Mass mail management class.
+ * <p/>
+ * This class store email to send in a csv file, and send it (one per second) in
+ * a second time.
+ * This class can restart to send mail at application restart.
+ * <p/>
+ * For a mass mail sending to start, following files must be present:
+ * <ul>
+ * <li>xxx.emails : CSV file ("email", "subject", "body")</li>
+ * <li>xxx.index : next index to manage ( inited at 0)</li>
+ * </ul>
+ *
+ * @author chatellier
+ * @version $Revision$
+ * <p/>
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class SendMail extends Thread {
+
+ /** logger. */
+ private static final Logger log = LoggerFactory.getLogger(SendMail.class);
+
+ public static final String EXTENSION_MAIL = ".mail";
+
+ public static final String EXTENSION_INDEX = ".index";
+
+ protected EmailService emailService;
+
+ /** Pollen configuration. */
+ protected PollenConfiguration configuration;
+
+ /** Mail storage directory. */
+ protected File mailStorageDirectory;
+
+ public SendMail(EmailService emailService,
+ PollenConfiguration configuration) {
+ this.emailService = emailService;
+ this.configuration = configuration;
+
+ // get email directory in configuration
+ // create it if not exists
+// File filename = configuration.getEmailDirectory();
+ mailStorageDirectory = configuration.getEmailDirectory();
+//
+// if (!mailStorageDirectory.exists()) {
+// if (mailStorageDirectory.mkdirs()) {
+// if (log.isDebugEnabled()) {
+// log.debug("Email storage directory created in : " + mailStorageDirectory.getAbsolutePath());
+// }
+// }
+// }
+ }
+
+ /*
+ * @see java.lang.Runnable#run()
+ */
+ @Override
+ public void run() {
+
+ // try to find existing files
+ while (true) {
+ try {
+ sendAllMails();
+
+ // bloque thread until next notify
+ sleep();
+ } catch (Exception ex) {
+ if (log.isErrorEnabled()) {
+ log.error("Error during SendMail main loop", ex);
+ }
+ }
+ }
+ }
+
+ protected synchronized void sleep() throws InterruptedException {
+ wait();
+ }
+
+ public synchronized void wakeUp() {
+ notifyAll();
+ }
+
+ /**
+ * Look for all xx.index file, and restart mail sending on
+ * non ending mass mail sending.
+ * <p/>
+ * After execution, delete mail and index file.
+ *
+ * @throws IOException if could not send emails
+ */
+ protected void sendAllMails() throws IOException {
+
+ // don't do for, allways take the first found
+ // a new one can be created when managing one other
+ List<File> indexFiles = null;
+ do {
+
+ // filter is java valid : .*\\.index
+ indexFiles = FileUtil.find(mailStorageDirectory, ".*\\" + EXTENSION_INDEX, false);
+
+ if (!indexFiles.isEmpty()) {
+ File indexFile = indexFiles.get(0);
+ // convert index content to int
+ String indexContent = FileUtils.readFileToString(indexFile, "UTF-8");
+ int index = Integer.parseInt(indexContent);
+
+ // get mail content file
+ File mailFile = new File(indexFile.getAbsolutePath().replaceAll(EXTENSION_INDEX + "$", EXTENSION_MAIL));
+
+ if (log.isDebugEnabled()) {
+ log.debug("Managing mail file : " + mailFile + " (from index " + indexContent + ")");
+ }
+
+ Reader indexFileReader = new BufferedReader(new FileReader(mailFile));
+ CSVReader cvsReader = new CSVReader(indexFileReader);
+
+ int currentIndex = 0;
+ String[] currentLine = cvsReader.readNext();
+ while (currentLine != null) {
+ String receiver = currentLine[0];
+ String subject = currentLine[1];
+ String body = currentLine[2];
+
+ log.debug("Props = " + configuration.getProperties());
+
+ // index contains next index to treat so == is ok
+ if (currentIndex >= index) {
+
+ EmailService.PollEmail pollEmail =
+ EmailService.createPollEmail(
+ receiver,
+ subject,
+ body
+ );
+ emailService.sendEmail(pollEmail);
+
+// MailUtil.sendMail(configuration.getProperty("email_host"),
+// Integer.parseInt(configuration.getProperty("email_port")),
+// configuration.getProperty("email_from"),
+// receiver, subject, body);
+
+ // index contains next index to treat
+ FileUtils.writeStringToFile(
+ indexFile,
+ String.valueOf(currentIndex + 1));
+
+ // wait 2 secondes between each mail to not
+ // load smtp server
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ex) {
+ if (log.isErrorEnabled()) {
+ log.error("Can't wait between mail", ex);
+ }
+ }
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Mail to " + receiver + " already sent in a previous execution, skip.");
+ }
+ }
+
+ currentIndex++;
+ currentLine = cvsReader.readNext();
+ }
+
+ // delete both index and mail file
+ mailFile.delete();
+ indexFile.delete();
+ } else {
+ if (log.isInfoEnabled()) {
+ log.info("No more index mail index file found, go to sleep a while :)");
+ }
+ }
+ } while (!indexFiles.isEmpty());
+ }
+
+ /**
+ * Prepare mail list.
+ * <p/>
+ * TODO : improve configuration reading
+ *
+ * @param id
+ * @param mailData
+ * @throws IOException
+ */
+ public void prepareMails(String id,
+ List<EmailService.PollEmail> mailData) throws IOException {
+
+ Writer fileWriter = null;
+ CSVWriter cvsWriter = null;
+ try {
+
+ // write CSV datas
+ File emailFile = new File(mailStorageDirectory, id + EXTENSION_MAIL);
+ fileWriter = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(emailFile)));
+ cvsWriter = new CSVWriter(fileWriter);
+
+ for (EmailService.PollEmail singleMailData : mailData) {
+ String[] nextLine = new String[]{
+ singleMailData.getTo(),
+ singleMailData.getSubject(),
+ singleMailData.getTo()
+ };
+ cvsWriter.writeNext(nextLine);
+ }
+
+ // write index (default to 0)
+ File indexFile = new File(mailStorageDirectory, id + EXTENSION_INDEX);
+ FileUtil.writeString(indexFile, "0");
+ } finally {
+ if (cvsWriter != null) {
+ cvsWriter.close();
+ }
+ IOUtils.closeQuietly(fileWriter);
+ }
+
+ }
+
+// public void prepareMails(String id, List<Map<String, String>> mailData) throws IOException {
+//
+// Writer fileWriter = null;
+// CSVWriter cvsWriter = null;
+// try {
+//
+// // write CSV datas
+// File emailFile = new File(mailStorageDirectory, id + EXTENSION_MAIL);
+// fileWriter = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(emailFile)));
+// cvsWriter = new CSVWriter(fileWriter);
+//
+// for (Map<String, String> singleMailData : mailData) {
+// String[] nextLine = new String[] {
+// singleMailData.get("receiver"),
+// singleMailData.get("subject"),
+// singleMailData.get("body")
+// };
+// cvsWriter.writeNext(nextLine);
+// }
+//
+// // write index (default to 0)
+// File indexFile = new File(mailStorageDirectory, id + EXTENSION_INDEX);
+// FileUtil.writeString(indexFile, "0");
+// }
+// finally {
+// if (cvsWriter != null) {
+// cvsWriter.close();
+// }
+// IOUtils.closeSilently(fileWriter);
+// }
+//
+// }
+}
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java 2012-03-07 16:43:44 UTC (rev 3165)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java 2012-03-07 16:44:51 UTC (rev 3166)
@@ -106,6 +106,7 @@
// let's generate the new password
password = RandomStringUtils.randomAlphanumeric(8);
+ user.setPassword(password);
}
String encodedPassword = encodePassword(password);
@@ -116,29 +117,35 @@
user.setTopiaId(userAccount.getTopiaId());
copyUserAccount(user, userAccount);
+ commitTransaction("Could not create user");
+
} catch (TopiaException e) {
throw new PollenTechnicalException(e);
}
- URL url = serviceContext.getApplicationURL();
+ // send a email to user
+ EmailService emailService = newService(EmailService.class);
+ emailService.onUserCreated(user);
- if (url != null && StringUtil.isEmail(user.getEmail())) {
+// URL url = serviceContext.getApplicationURL();
+//
+// if (url != null && StringUtil.isEmail(user.getEmail())) {
+//
+// Locale locale = getLocale();
+// String subject = l_(locale, "pollen.email.userRegister.subject",
+// user.getLogin());
+// String content = l_(locale, "pollen.email.userRegister.content",
+// user.getDisplayName(),
+// user.getLogin(), password, url);
+//
+// EmailService emailService = newService(EmailService.class);
+//
+// emailService.sendEmail(
+// user.getEmail(),
+// subject,
+// content);
+// }
- Locale locale = getLocale();
- String subject = l_(locale, "pollen.email.userRegister.subject",
- user.getLogin());
- String content = l_(locale, "pollen.email.userRegister.content",
- user.getDisplayName(),
- user.getLogin(), password, url);
-
- EmailService emailService = newService(EmailService.class);
-
- emailService.sendEmail(
- user.getEmail(),
- subject,
- content);
- }
-
return userAccount;
}
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties 2012-03-07 16:43:44 UTC (rev 3165)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties 2012-03-07 16:44:51 UTC (rev 3166)
@@ -8,8 +8,16 @@
pollen.common.numberVote-blank-votes=Number of blank votes
pollen.common.numberVote-total=Sum of numbers
pollen.common.numberVote-total-votes=Total votes
+pollen.email.creatorEmail.content=You had just created the new poll\: "%s".\nYou can access to this poll by following the links below.\n\nVote page\: \n%s\nEdit page\: \n%s
+pollen.email.creatorEmail.subject=[Pollen] Poll creation (%s)
+pollen.email.reminderEmail.content=You have not yet voted for the poll "%s".\nYou can still participate with the identifier %s by following this link\: \n%s
+pollen.email.reminderEmail.subject=[Pollen] Reminder (%s)
pollen.email.userRegister.content=Welcome %1$s. You had just created an account on the web application Pollen.\n\nLogin\: %2$s\nPassword\: %3$s\n\nYou can now manage your polls by logging on the website \: \n%4$s
pollen.email.userRegister.subject=[Pollen] Confirmation of account creation %s
+pollen.email.voteEmail.content=A vote has been submitted for the poll "%s". There are now %d votes for this poll.\nYou can access to this poll by following the links below.\n\nVote page\: \n%s\nEdit page\: \n%s
+pollen.email.voteEmail.subject=[Pollen] Vote reporting (%s)
+pollen.email.votingEmail.content=A new poll has been created\: "%s".\nYou can participate with the identifier %s by following this link\: \n%s
+pollen.email.votingEmail.subject=[Pollen] Invitation to vote (%s)
pollen.feed.addChoiceContent=
pollen.feed.addChoiceTitle=
pollen.feed.addCommentContent=%s
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties 2012-03-07 16:43:44 UTC (rev 3165)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties 2012-03-07 16:44:51 UTC (rev 3166)
@@ -10,8 +10,16 @@
pollen.common.numberVote-total-votes=Nombre total de votes
pollen.email.createPoll.content=Vous venez de créer le sondage "%1$s".\nVous pouvez y accéder en suivant les liens ci-dessous.\n\nPage de vote \: \n%2$s\nModération des votes \: \n%3$s\nPage de modification \: \n%4$s
pollen.email.createPoll.subject=[Pollen] Création d'un sondage (%1$s)
+pollen.email.creatorEmail.content=Vous venez de créer le sondage "%s".\nVous pouvez y accéder en suivant les liens ci-dessous.\n\nPage de vote \: \n%s\nPage de modification \: \n%s
+pollen.email.creatorEmail.subject=[Pollen] Création d'un sondage (%s)
+pollen.email.reminderEmail.content=Vous n'avez pas encore voté pour le sondage "%s".\nVous pouvez encore y participer avec l'identifiant %s à l'adresse suivante \: \n%s
+pollen.email.reminderEmail.subject=[Pollen] Rappel (%s)
pollen.email.userRegister.content=Bienvenue %1$s. Vous venez de créer un compte sur l'application de sondage en ligne Pollen.\n\nIdentifiant \: %2$s\nMot de passe \: %3$s\n\nVous pouvez dès maintenant gérer vos sondages en vous identifiant sur le site \: \n%4$s
pollen.email.userRegister.subject=[Pollen] Confirmation de création du compte %s
+pollen.email.voteEmail.content=Un vote vient d'être enregistré pour le sondage "%s". Ce sondage compte désormais %d votes.\nVous pouvez accéder à ce sondage en suivant les liens ci-dessous.\n\nPage de vote \: \n%s\nPage de modification \: \n%s
+pollen.email.voteEmail.subject=[Pollen] Notification de vote (%s)
+pollen.email.votingEmail.content=Un nouveau sondage a été créé \: "%s".\nVous pouvez y participer avec l'identifiant %s à l'adresse suivante \: \n%s
+pollen.email.votingEmail.subject=[Pollen] Invitation au vote (%s)
pollen.feed.addChoiceContent=
pollen.feed.addChoiceTitle=
pollen.feed.addCommentContent=%s
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/test/java/org/chorem/pollen/services/FakeServiceContext.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/test/java/org/chorem/pollen/services/FakeServiceContext.java 2012-03-07 16:43:44 UTC (rev 3165)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/test/java/org/chorem/pollen/services/FakeServiceContext.java 2012-03-07 16:44:51 UTC (rev 3166)
@@ -28,6 +28,7 @@
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.PolleIOUtil;
import org.chorem.pollen.PollenConfiguration;
+import org.chorem.pollen.PollenConfigurationOption;
import org.chorem.pollen.PollenTopiaRootContextFactory;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
@@ -39,9 +40,7 @@
import java.io.File;
import java.net.URL;
import java.util.Date;
-import java.util.HashMap;
import java.util.Locale;
-import java.util.Map;
import java.util.Properties;
import java.util.UUID;
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/test/resources/log4j.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/test/resources/log4j.properties 2012-03-07 16:43:44 UTC (rev 3165)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/test/resources/log4j.properties 2012-03-07 16:44:51 UTC (rev 3166)
@@ -21,17 +21,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# #L%
###
-# Default to info level output; this is very handy if you eventually use Hibernate as well.
-log4j.rootCategory=warn, A1
+log4j.rootCategory=WARN, A1
# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
-log4j.appender.A1.layout.ConversionPattern=%d [%p] %c{2} %m%n
+log4j.appender.A1.layout.ConversionPattern=%d [%p] %c %m%n
-log4j.logger.org.chorem.pollen=debug
-
-log4j.logger.org.chorem.pollen.business.PollenContextImpl=warn
-log4j.logger.org.chorem.pollen.business.services.SendMail=warn
+log4j.logger.org.chorem.pollen=INFO
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/test/resources/pollen-fake.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/test/resources/pollen-fake.properties 2012-03-07 16:43:44 UTC (rev 3165)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/test/resources/pollen-fake.properties 2012-03-07 16:44:51 UTC (rev 3166)
@@ -34,6 +34,7 @@
topia.service.migration.callback=org.chorem.pollen.entities.migration.PollenMigrationCallback
topia.service.migration.showSql=true
+siteUrl=http://meFake/pollen
upImgDir=${testDirectory}/.pollen/uploadedImages
feedDir=${testDirectory}/.pollen/feeds
pollen.emails.directory=${testDirectory}/.pollen/emails
1
0
r3165 - in branches/pollen-1.2.6-struts2/pollen-persistence/src: main/java/org/chorem/pollen test/resources
by tchemit@users.chorem.org 07 Mar '12
by tchemit@users.chorem.org 07 Mar '12
07 Mar '12
Author: tchemit
Date: 2012-03-07 17:43:44 +0100 (Wed, 07 Mar 2012)
New Revision: 3165
Url: http://chorem.org/repositories/revision/pollen/3165
Log:
reuse the siteUrl applicationUrl, safer than using url from request...
Modified:
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfiguration.java
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfigurationOption.java
branches/pollen-1.2.6-struts2/pollen-persistence/src/test/resources/log4j.properties
branches/pollen-1.2.6-struts2/pollen-persistence/src/test/resources/pollen-fake.properties
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfiguration.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfiguration.java 2012-03-07 11:35:46 UTC (rev 3164)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfiguration.java 2012-03-07 16:43:44 UTC (rev 3165)
@@ -37,6 +37,7 @@
import java.io.File;
import java.io.IOException;
+import java.net.URL;
import java.util.Map;
import java.util.Properties;
@@ -84,6 +85,14 @@
"Could not parse configuration", e);
}
+ // check application url is ok
+ URL applicationUrl = getApplicationUrl();
+ if (applicationUrl == null) {
+ throw new IllegalStateException(
+ "No application url defined in configuration, please fill the property '" +
+ PollenConfigurationOption.APPLICATION_URL.key + "'");
+ }
+
createDirectory(PollenConfigurationOption.EMAIL_DIR);
createDirectory(PollenConfigurationOption.FEED_DIR);
createDirectory(PollenConfigurationOption.IMG_DIR);
@@ -93,6 +102,13 @@
}
}
+ public URL getApplicationUrl() {
+ URL result = applicationConfig.getOptionAsURL(
+ PollenConfigurationOption.APPLICATION_URL.key
+ );
+ return result;
+ }
+
public ChoiceType getDefaultChoiceType() {
ChoiceType result = applicationConfig.getOption(
ChoiceType.class,
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfigurationOption.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfigurationOption.java 2012-03-07 11:35:46 UTC (rev 3164)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/PollenConfigurationOption.java 2012-03-07 16:43:44 UTC (rev 3165)
@@ -30,6 +30,7 @@
import org.nuiton.util.Version;
import java.io.File;
+import java.net.URL;
/**
* All Pollen configuration options.
@@ -40,6 +41,8 @@
public enum PollenConfigurationOption implements ApplicationConfig.OptionDef {
/** login for default admin. */
+ APPLICATION_URL("siteUrl", "Application url", "", URL.class),
+ /** login for default admin. */
DATA_DIR("pollen.dataDirectory", "Default directory where to put datas", "${HOME}/.pollen", File.class),
/** login for default admin. */
ADMIN_LOGIN("adminLogin", "login for default admin", "admin", String.class),
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/test/resources/log4j.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/test/resources/log4j.properties 2012-03-07 11:35:46 UTC (rev 3164)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/test/resources/log4j.properties 2012-03-07 16:43:44 UTC (rev 3165)
@@ -21,17 +21,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# #L%
###
-# Default to info level output; this is very handy if you eventually use Hibernate as well.
-log4j.rootCategory=warn, A1
+log4j.rootCategory=WARN, A1
# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
-log4j.appender.A1.layout.ConversionPattern=%d [%p] %c{2} %m%n
+log4j.appender.A1.layout.ConversionPattern=%d [%p] %c %m%n
-log4j.logger.org.chorem.pollen=debug
-
-log4j.logger.org.chorem.pollen.business.PollenContextImpl=warn
-log4j.logger.org.chorem.pollen.business.services.SendMail=warn
+log4j.logger.org.chorem.pollen=INFO
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/test/resources/pollen-fake.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/test/resources/pollen-fake.properties 2012-03-07 11:35:46 UTC (rev 3164)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/test/resources/pollen-fake.properties 2012-03-07 16:43:44 UTC (rev 3165)
@@ -33,6 +33,7 @@
topia.service.migration.callback=org.chorem.pollen.entities.migration.PollenMigrationCallback
topia.service.migration.showSql=true
+siteUrl=http://meFake/pollen
upImgDir=${testDirectory}/.pollen/uploadedImages
feedDir=${testDirectory}/.pollen/feeds
pollen.emails.directory=${testDirectory}/.pollen/emails
1
0
r3164 - in branches/pollen-1.2.6-struts2/pollen-persistence/src/main: java/org/chorem/pollen/entities/migration xmi
by tchemit@users.chorem.org 07 Mar '12
by tchemit@users.chorem.org 07 Mar '12
07 Mar '12
Author: tchemit
Date: 2012-03-07 12:35:46 +0100 (Wed, 07 Mar 2012)
New Revision: 3164
Url: http://chorem.org/repositories/revision/pollen/3164
Log:
Evolution #480: Change all field in model to primitive type
Modified:
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_2_6.java
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/xmi/pollen.zargo
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_2_6.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_2_6.java 2012-03-06 10:39:17 UTC (rev 3163)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_2_6.java 2012-03-07 11:35:46 UTC (rev 3164)
@@ -78,11 +78,11 @@
migrateVoteCountingTypes(tx, queries);
// change all Boolean properties to boolean
- migrateBoolean(tx, queries);
+ migrateToPrimitiveTypes(tx, queries);
}
- private void migrateBoolean(TopiaContextImplementor tx,
- List<String> queries) throws TopiaException {
+ private void migrateToPrimitiveTypes(TopiaContextImplementor tx,
+ List<String> queries) throws TopiaException {
migrateBoolean(queries, "useraccount", "administrator");
migrateBoolean(queries, "choice", "validate");
@@ -98,19 +98,38 @@
migrateBoolean(queries, "preventRule", "oneTime");
migrateBoolean(queries, "result", "byGroup");
migrateBoolean(queries, "vote", "anonymous");
+
+ migrateNumber(queries, "poll", "maxChoiceNb");
+ migrateNumber(queries, "preventRule", "sensibility");
+
+ migrateNumber(queries, "PersonToList", "weight");
+ migrateNumber(queries, "VotingList", "weight");
+ migrateNumber(queries, "Vote", "weight");
}
- public static final String UPDATE_BOOLEAN_VALUE = "UPDATE %1$s SET %2$s = false where %2$s IS NULL";
+ public static final String UPDATE_PRIMITIVE_TO_DEFAULT_VALUE = "UPDATE %1$s SET %2$s = %3$s where %2$s IS NULL;";
- public static final String UPDATE_BOOLEAN_CONSTRAINST = "ALTER TABLE %s ALTER COLUMN %s SET NOT NULL";
+ public static final String ADD_PRIMITIVE_NOT_NULL_CONSTRAINST = "ALTER TABLE %s ALTER COLUMN %s SET NOT NULL;";
+ public static final String ADD_PRIMITIVE_DEFAULT_VALUE = "ALTER TABLE %s ALTER COLUMN %s SET DEFAULT %s;";
+
private void migrateBoolean(List<String> queries, String tableName, String field) {
- queries.add(String.format(UPDATE_BOOLEAN_VALUE, tableName, field));
- queries.add(String.format(UPDATE_BOOLEAN_CONSTRAINST, tableName, field));
+ Object defaultValue = false;
+ queries.add(String.format(UPDATE_PRIMITIVE_TO_DEFAULT_VALUE, tableName, field, defaultValue));
+ queries.add(String.format(ADD_PRIMITIVE_NOT_NULL_CONSTRAINST, tableName, field));
+ queries.add(String.format(ADD_PRIMITIVE_DEFAULT_VALUE, tableName, field, defaultValue));
}
+ private void migrateNumber(List<String> queries, String tableName, String field) {
+
+ Object defaultValue = 0;
+ queries.add(String.format(UPDATE_PRIMITIVE_TO_DEFAULT_VALUE, tableName, field, defaultValue));
+ queries.add(String.format(ADD_PRIMITIVE_NOT_NULL_CONSTRAINST, tableName, field));
+ queries.add(String.format(ADD_PRIMITIVE_DEFAULT_VALUE, tableName, field, defaultValue));
+ }
+
private void migrateChoiceTypes(TopiaContextImplementor tx,
List<String> queries) throws TopiaException {
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/xmi/pollen.zargo
===================================================================
(Binary files differ)
1
0
Author: tchemit
Date: 2012-03-06 11:39:17 +0100 (Tue, 06 Mar 2012)
New Revision: 3163
Url: http://chorem.org/repositories/revision/pollen/3163
Log:
Evolution #480: Change all Boolean field in model to boolean
Modified:
branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataChoiceConverter.java
branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollAccountConverter.java
branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollConverter.java
branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPreventRuleConverter.java
branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataResultConverter.java
branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataVoteCountingConverter.java
branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_2_6.java
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/xmi/pollen.properties
branches/pollen-1.2.6-struts2/pollen-persistence/src/main/xmi/pollen.zargo
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetCreatedPolls.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPolls.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java
Modified: branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataChoiceConverter.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataChoiceConverter.java 2012-03-05 23:39:29 UTC (rev 3162)
+++ branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataChoiceConverter.java 2012-03-06 10:39:17 UTC (rev 3163)
@@ -70,7 +70,7 @@
choiceDTO.setHidden(eChoiceName != null
&& eChoiceName.startsWith(NumberMethod.HIDDEN_PREFIX));
choiceDTO.setDescription(eChoice.getDescription());
- choiceDTO.setValidate(eChoice.getValidate());
+ choiceDTO.setValidate(eChoice.isValidate());
if (eChoice.getPoll() != null) {
choiceDTO.setPollId(eChoice.getPoll().getTopiaId());
Modified: branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollAccountConverter.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollAccountConverter.java 2012-03-05 23:39:29 UTC (rev 3162)
+++ branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollAccountConverter.java 2012-03-06 10:39:17 UTC (rev 3163)
@@ -133,7 +133,7 @@
//VotingListDTO votingListDTO = votingListConverter.createVotingListDTO(personToList.getVotingList());
dto.setWeight(personToList.getWeight());
- dto.setHasVoted(personToList.getHasVoted());
+ dto.setHasVoted(personToList.isHasVoted());
//dto.setVotingListId(votingListDTO.getId());
}
}
Modified: branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollConverter.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollConverter.java 2012-03-05 23:39:29 UTC (rev 3162)
+++ branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollConverter.java 2012-03-06 10:39:17 UTC (rev 3163)
@@ -102,11 +102,11 @@
pollDTO.setBeginDate(ePoll.getBeginDate());
pollDTO.setEndDate(ePoll.getEndDate());
pollDTO.setAnonymous(ePoll.getAnonymous());
- pollDTO.setAnonymousVoteAllowed(ePoll.getAnonymousVoteAllowed());
- pollDTO.setPublicResults(ePoll.getPublicResults());
- pollDTO.setContinuousResults(ePoll.getContinuousResults());
- pollDTO.setChoiceAddAllowed(ePoll.getChoiceAddAllowed());
- pollDTO.setClosed(ePoll.getClosed());
+ pollDTO.setAnonymousVoteAllowed(ePoll.isAnonymousVoteAllowed());
+ pollDTO.setPublicResults(ePoll.isPublicResults());
+ pollDTO.setContinuousResults(ePoll.isContinuousResults());
+ pollDTO.setChoiceAddAllowed(ePoll.isChoiceAddAllowed());
+ pollDTO.setClosed(ePoll.isClosed());
pollDTO.setMaxChoiceNb(ePoll.getMaxChoiceNb());
pollDTO.setChoiceType(EnumController.getChoiceType(ePoll));
pollDTO.setPollType(EnumController.getPollType(ePoll));
Modified: branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPreventRuleConverter.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPreventRuleConverter.java 2012-03-05 23:39:29 UTC (rev 3162)
+++ branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPreventRuleConverter.java 2012-03-06 10:39:17 UTC (rev 3163)
@@ -70,9 +70,9 @@
preventRuleDTO.setId(preventRule.getTopiaId());
preventRuleDTO.setScope(preventRule.getScope());
preventRuleDTO.setSensibility(preventRule.getSensibility());
- preventRuleDTO.setActive(preventRule.getActive());
- preventRuleDTO.setOneTime(preventRule.getOneTime());
- preventRuleDTO.setRepeated(preventRule.getRepeated());
+ preventRuleDTO.setActive(preventRule.isActive());
+ preventRuleDTO.setOneTime(preventRule.isOneTime());
+ preventRuleDTO.setRepeated(preventRule.isRepeated());
preventRuleDTO.setMethod(preventRule.getMethod());
if (preventRule.getPoll() != null) {
Modified: branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataResultConverter.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataResultConverter.java 2012-03-05 23:39:29 UTC (rev 3162)
+++ branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataResultConverter.java 2012-03-06 10:39:17 UTC (rev 3163)
@@ -93,7 +93,7 @@
dto.setHidden(resName != null &&
resName.startsWith(NumberMethod.HIDDEN_PREFIX));
dto.setValue(res.getResultValue());
- dto.setByGroup(res.getByGroup());
+ dto.setByGroup(res.isByGroup());
dto.setChoiceType(EnumController.getChoiceType(ePoll));
dto.setVoteCounting(EnumController.getVoteCountingType(ePoll));
results.add(dto);
Modified: branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataVoteCountingConverter.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataVoteCountingConverter.java 2012-03-05 23:39:29 UTC (rev 3162)
+++ branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataVoteCountingConverter.java 2012-03-06 10:39:17 UTC (rev 3163)
@@ -58,11 +58,11 @@
pollDTO.setBeginDate(ePoll.getBeginDate());
pollDTO.setEndDate(ePoll.getEndDate());
pollDTO.setAnonymous(ePoll.getAnonymous());
- pollDTO.setAnonymousVoteAllowed(ePoll.getAnonymousVoteAllowed());
- pollDTO.setPublicResults(ePoll.getPublicResults());
- pollDTO.setContinuousResults(ePoll.getContinuousResults());
- pollDTO.setChoiceAddAllowed(ePoll.getChoiceAddAllowed());
- pollDTO.setClosed(ePoll.getClosed());
+ pollDTO.setAnonymousVoteAllowed(ePoll.isAnonymousVoteAllowed());
+ pollDTO.setPublicResults(ePoll.isPublicResults());
+ pollDTO.setContinuousResults(ePoll.isContinuousResults());
+ pollDTO.setChoiceAddAllowed(ePoll.isChoiceAddAllowed());
+ pollDTO.setClosed(ePoll.isClosed());
pollDTO.setCreatorId(ePoll.getCreator().getVotingId());
pollDTO.setCreatorEmail(ePoll.getCreator().getEmail());
pollDTO.setMaxChoiceNb(ePoll.getMaxChoiceNb());
Modified: branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java 2012-03-05 23:39:29 UTC (rev 3162)
+++ branches/pollen-1.2.6-struts2/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java 2012-03-06 10:39:17 UTC (rev 3163)
@@ -390,7 +390,7 @@
for (VotingList votingList : poll.getVotingList()) {
for (PersonToList personToList : votingList
.getPollAccountPersonToList()) {
- if (!personToList.getHasVoted()) {
+ if (!personToList.isHasVoted()) {
PollAccount pollAccount = personToList
.getPollAccount();
if (pollAccount != null
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_2_6.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_2_6.java 2012-03-05 23:39:29 UTC (rev 3162)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/java/org/chorem/pollen/entities/migration/PollenMigrationCallbackV1_2_6.java 2012-03-06 10:39:17 UTC (rev 3163)
@@ -68,9 +68,6 @@
// } else if (dialect instanceof H2Dialect) {
// }
- // let's use a primitive boolean
- queries.add("update useraccount set administrator = false where administrator is null;");
-
// change choice type to use enumeration
migrateChoiceTypes(tx, queries);
@@ -79,9 +76,41 @@
// change vote counting type to use enumeration
migrateVoteCountingTypes(tx, queries);
+
+ // change all Boolean properties to boolean
+ migrateBoolean(tx, queries);
}
+ private void migrateBoolean(TopiaContextImplementor tx,
+ List<String> queries) throws TopiaException {
+ migrateBoolean(queries, "useraccount", "administrator");
+ migrateBoolean(queries, "choice", "validate");
+ migrateBoolean(queries, "personToList", "hasVoted");
+ migrateBoolean(queries, "poll", "closed");
+ migrateBoolean(queries, "poll", "choiceAddAllowed");
+ migrateBoolean(queries, "poll", "anonymousVoteAllowed");
+ migrateBoolean(queries, "poll", "anonymous");
+ migrateBoolean(queries, "poll", "publicResults");
+ migrateBoolean(queries, "poll", "continuousResults");
+ migrateBoolean(queries, "preventRule", "repeated");
+ migrateBoolean(queries, "preventRule", "active");
+ migrateBoolean(queries, "preventRule", "oneTime");
+ migrateBoolean(queries, "result", "byGroup");
+ migrateBoolean(queries, "vote", "anonymous");
+ }
+
+ public static final String UPDATE_BOOLEAN_VALUE = "UPDATE %1$s SET %2$s = false where %2$s IS NULL";
+
+ public static final String UPDATE_BOOLEAN_CONSTRAINST = "ALTER TABLE %s ALTER COLUMN %s SET NOT NULL";
+
+ private void migrateBoolean(List<String> queries, String tableName, String field) {
+
+ queries.add(String.format(UPDATE_BOOLEAN_VALUE, tableName, field));
+ queries.add(String.format(UPDATE_BOOLEAN_CONSTRAINST, tableName, field));
+
+ }
+
private void migrateChoiceTypes(TopiaContextImplementor tx,
List<String> queries) throws TopiaException {
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/xmi/pollen.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-persistence/src/main/xmi/pollen.properties 2012-03-05 23:39:29 UTC (rev 3162)
+++ branches/pollen-1.2.6-struts2/pollen-persistence/src/main/xmi/pollen.properties 2012-03-06 10:39:17 UTC (rev 3163)
@@ -26,3 +26,4 @@
model.tagvalue.constantPrefix=PROPERTY_
model.tagvalue.java.lang.String=text
model.tagvalue.version=1.2.6
+model.tagvalue.doNotGenerateBooleanGetMethods=true
Modified: branches/pollen-1.2.6-struts2/pollen-persistence/src/main/xmi/pollen.zargo
===================================================================
(Binary files differ)
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java 2012-03-05 23:39:29 UTC (rev 3162)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java 2012-03-06 10:39:17 UTC (rev 3163)
@@ -195,7 +195,7 @@
dto.setHidden(resName != null &&
resName.startsWith(NumberMethod.HIDDEN_PREFIX));
dto.setValue(res.getResultValue());
- dto.setByGroup(res.getByGroup());
+ dto.setByGroup(res.isByGroup());
dto.setChoiceType(poll.getChoiceType());
dto.setVoteCountingType(poll.getVoteCountingType());
results.add(dto);
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-05 23:39:29 UTC (rev 3162)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-06 10:39:17 UTC (rev 3163)
@@ -120,19 +120,19 @@
PollDAO pollDAO = getDAO(Poll.class);
Poll result = create(pollDAO);
- result.setAnonymous(poll.getAnonymous());
- result.setAnonymousVoteAllowed(poll.getAnonymousVoteAllowed());
+ result.setAnonymous(poll.isAnonymous());
+ result.setAnonymousVoteAllowed(poll.isAnonymousVoteAllowed());
result.setBeginChoiceDate(poll.getBeginChoiceDate());
result.setBeginDate(poll.getBeginDate());
result.setChoiceType(poll.getChoiceType());
- result.setContinuousResults(poll.getContinuousResults());
+ result.setContinuousResults(poll.isContinuousResults());
result.setDescription(poll.getDescription());
result.setEndDate(poll.getEndDate());
result.setEndChoiceDate(poll.getEndChoiceDate());
result.setPollId(poll.getPollId());
result.setPollType(poll.getPollType());
result.setMaxChoiceNb(poll.getMaxChoiceNb());
- result.setPublicResults(poll.getPublicResults());
+ result.setPublicResults(poll.isPublicResults());
result.setTitle(poll.getTitle());
result.setVoteCountingType(poll.getVoteCountingType());
@@ -155,10 +155,10 @@
for (PreventRule preventRule : poll.getPreventRule()) {
PreventRule preventRuleCreated = create(preventRuleDAO);
- preventRuleCreated.setActive(preventRule.getActive());
+ preventRuleCreated.setActive(preventRule.isActive());
preventRuleCreated.setMethod(preventRule.getMethod());
- preventRuleCreated.setOneTime(preventRule.getOneTime());
- preventRuleCreated.setRepeated(preventRule.getRepeated());
+ preventRuleCreated.setOneTime(preventRule.isOneTime());
+ preventRuleCreated.setRepeated(preventRule.isRepeated());
preventRuleCreated.setScope(preventRule.getScope());
preventRuleCreated.setSensibility(preventRule.getSensibility());
result.addPreventRule(preventRule);
@@ -185,7 +185,7 @@
for (PersonToList personToList : votingList.getPollAccountPersonToList()) {
PersonToList personToListCreated = create(personToListDAO);
- personToListCreated.setHasVoted(personToList.getHasVoted());
+ personToListCreated.setHasVoted(personToList.isHasVoted());
personToListCreated.setWeight(personToList.getWeight());
votingListCreated.addPollAccountPersonToList(personToListCreated);
@@ -215,7 +215,7 @@
Choice choiceCreated = create(choiceDAO);
choiceCreated.setDescription(choice.getDescription());
choiceCreated.setName(choice.getName());
- choiceCreated.setValidate(choice.getValidate());
+ choiceCreated.setValidate(choice.isValidate());
result.addChoice(choiceCreated);
if (choiceType == ChoiceType.IMAGE) {
@@ -314,7 +314,7 @@
for (VotingList votingList : poll.getVotingList()) {
for (PersonToList personToList : votingList
.getPollAccountPersonToList()) {
- if (!personToList.getHasVoted()) {
+ if (!personToList.isHasVoted()) {
PollAccount pollAccount = personToList
.getPollAccount();
@@ -512,12 +512,12 @@
result.setBeginChoiceDate(poll.getBeginChoiceDate());
result.setBeginDate(poll.getBeginDate());
result.setEndDate(poll.getEndDate());
- result.setAnonymous(poll.getAnonymous());
- result.setAnonymousVoteAllowed(poll.getAnonymousVoteAllowed());
- result.setPublicResults(poll.getPublicResults());
- result.setContinuousResults(poll.getContinuousResults());
- result.setChoiceAddAllowed(poll.getChoiceAddAllowed());
- result.setClosed(poll.getClosed());
+ result.setAnonymous(poll.isAnonymous());
+ result.setAnonymousVoteAllowed(poll.isAnonymousVoteAllowed());
+ result.setPublicResults(poll.isPublicResults());
+ result.setContinuousResults(poll.isContinuousResults());
+ result.setChoiceAddAllowed(poll.isChoiceAddAllowed());
+ result.setClosed(poll.isClosed());
result.setCreatorId(poll.getCreator().getVotingId());
result.setCreatorEmail(poll.getCreator().getEmail());
result.setMaxChoiceNb(poll.getMaxChoiceNb());
Modified: branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-03-05 23:39:29 UTC (rev 3162)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-03-06 10:39:17 UTC (rev 3163)
@@ -163,7 +163,7 @@
List<Vote> results = new ArrayList<Vote>();
try {
// No need to load votes for an anonymous poll
- if (poll.getAnonymous()) {
+ if (poll.isAnonymous()) {
return results;
}
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetCreatedPolls.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetCreatedPolls.java 2012-03-05 23:39:29 UTC (rev 3162)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetCreatedPolls.java 2012-03-06 10:39:17 UTC (rev 3163)
@@ -103,8 +103,7 @@
Set<String> result = Sets.newHashSet();
result.add("vote");
result.add("result");
- Boolean closed = poll.getClosed();
- if (closed == null || !closed) {
+ if (!poll.isClosed()) {
// poll is not closed
result.add("edit");
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPolls.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPolls.java 2012-03-05 23:39:29 UTC (rev 3162)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/json/GetPolls.java 2012-03-06 10:39:17 UTC (rev 3163)
@@ -104,8 +104,7 @@
Set<String> result = Sets.newHashSet();
result.add("vote");
result.add("result");
- Boolean closed = poll.getClosed();
- if (closed == null || !closed) {
+ if (!poll.isClosed()) {
// poll is not closed
result.add("edit");
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-03-05 23:39:29 UTC (rev 3162)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-03-06 10:39:17 UTC (rev 3163)
@@ -201,7 +201,7 @@
Date currentTime = serviceContext.getCurrentTime();
- accountFieldDisplayed = !poll.getAnonymous() || isRestrictedPoll() || isGroupPoll();
+ accountFieldDisplayed = !poll.isAnonymous() || isRestrictedPoll() || isGroupPoll();
boolean choicestarted = poll.getBeginChoiceDate() == null || poll.getBeginChoiceDate().before(currentTime);
boolean choiceended = poll.getEndChoiceDate() != null && poll.getEndChoiceDate().before(currentTime);
@@ -210,10 +210,9 @@
//TODO Move this is poll entity
pollChoiceOrVoteStarted = pollChoiceStarted || isPollStarted();
- pollChoiceRunning = poll.getChoiceAddAllowed() && pollChoiceStarted;
+ pollChoiceRunning = poll.isChoiceAddAllowed() && pollChoiceStarted;
- pollRunning = !(poll.getClosed() != null && poll.getClosed()) &&
- isPollStarted() && !isPollFinished();
+ pollRunning = !poll.isClosed() && isPollStarted() && !isPollFinished();
//TODO Deal the case of the not loggued poll (using the pollAccountId
creatorUser = getPollenSession().getUserAccount() != null &&
@@ -327,7 +326,7 @@
}
// Génération d'un identifiant de vote (si le sondage est libre et anonyme)
- if (poll.getAnonymous()) {
+ if (poll.isAnonymous()) {
anonymousVote = true;
if (isFreePoll()) {
getPollAccount().setVotingId(
@@ -437,7 +436,7 @@
if (poll == null) {
addActionError(_("pollen.error.poll.notfound"));
} else {
- if (poll.getClosed() != null && poll.getClosed()) {
+ if (poll.isClosed()) {
addActionMessage(_("pollen.information.pollClosed"));
} else if (!isPollStarted()) {
addActionMessage(_("pollen.information.pollNotStarted"));
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-03-05 23:39:29 UTC (rev 3162)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-03-06 10:39:17 UTC (rev 3163)
@@ -170,7 +170,7 @@
DateFormat.SHORT,
DateFormat.SHORT, getLocale()));
- if (poll.getPublicResults()) {
+ if (poll.isPublicResults()) {
userAllowed = true;
} else if (StringUtils.isNotEmpty(accountId)) {
@@ -182,7 +182,7 @@
if (!userAllowed) {
addActionError(_("pollen.error.userNotAllowed"));
- } else if (!poll.getClosed()) {
+ } else if (!poll.isClosed()) {
addActionMessage(_("pollen.error.pollNotClosed"));
loadResults();
} else {
1
0
r3162 - in branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main: resources/config webapp/WEB-INF/jsp
by tchemit@users.chorem.org 05 Mar '12
by tchemit@users.chorem.org 05 Mar '12
05 Mar '12
Author: tchemit
Date: 2012-03-06 00:39:29 +0100 (Tue, 06 Mar 2012)
New Revision: 3162
Url: http://chorem.org/repositories/revision/pollen/3162
Log:
fix urls
Modified:
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/pollListHelper.jsp
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-03-05 23:26:09 UTC (rev 3161)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-03-05 23:39:29 UTC (rev 3162)
@@ -66,8 +66,9 @@
</action>
<!-- edit poll -->
- <action name="edit"
+ <action name="modification/*"
class="org.chorem.pollen.ui.actions.poll.Edit">
+ <param name="uriId">{1}</param>
<result name="input">/WEB-INF/jsp/poll/edit.jsp</result>
<result>/WEB-INF/jsp/poll/resume.jsp</result>
</action>
@@ -88,29 +89,33 @@
</action>
<!-- clone poll -->
- <action name="clone"
+ <action name="clone/*"
class="org.chorem.pollen.ui.actions.poll.Clone">
+ <param name="uriId">{1}</param>
<result name="input">/WEB-INF/jsp/poll/clone.jsp</result>
<result>/WEB-INF/jsp/home.jsp</result>
</action>
<!-- export poll -->
- <action name="export"
+ <action name="export/*"
class="org.chorem.pollen.ui.actions.poll.Export">
+ <param name="uriId">{1}</param>
<result name="input">/WEB-INF/jsp/poll/export.jsp</result>
<result>/WEB-INF/jsp/home.jsp</result>
</action>
<!-- close poll -->
- <action name="close"
+ <action name="close/*"
class="org.chorem.pollen.ui.actions.poll.Close">
+ <param name="uriId">{1}</param>
<result name="input">/WEB-INF/jsp/poll/close.jsp</result>
<result>/WEB-INF/jsp/home.jsp</result>
</action>
<!-- delete poll -->
- <action name="delete"
+ <action name="delete/*"
class="org.chorem.pollen.ui.actions.poll.Delete">
+ <param name="uriId">{1}</param>
<result name="input">/WEB-INF/jsp/poll/delete.jsp</result>
<result>/WEB-INF/jsp/home.jsp</result>
</action>
Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/pollListHelper.jsp
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/pollListHelper.jsp 2012-03-05 23:26:09 UTC (rev 3161)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/pollListHelper.jsp 2012-03-05 23:39:29 UTC (rev 3162)
@@ -37,23 +37,23 @@
<s:url id='resultImg' value='/img/count.png'/>
<s:set id='resultTitle'><s:text name="pollen.action.pollResult"/></s:set>
-<s:url id="editUrl" action="edit" namespace="/poll" method="input"/>
+<s:url id="editUrl" action="modification/" namespace="/poll" method="input"/>
<s:url id='editImg' value='/img/edit.png'/>
<s:set id='editTitle'><s:text name="pollen.action.pollEdit"/></s:set>
-<s:url id="closeUrl" action="close" namespace="/poll" method="input"/>
+<s:url id="closeUrl" action="close/" namespace="/poll" method="input"/>
<s:url id='closeImg' value='/img/close.png'/>
<s:set id='closeTitle'><s:text name="pollen.action.pollClose"/></s:set>
-<s:url id="exportUrl" action="export" namespace="/poll" method="input"/>
+<s:url id="exportUrl" action="export/" namespace="/poll" method="input"/>
<s:url id='exportImg' value='/img/export.png'/>
<s:set id='exportTitle'><s:text name="pollen.action.pollExport"/></s:set>
-<s:url id="cloneUrl" action="clone" namespace="/poll" method="input"/>
+<s:url id="cloneUrl" action="clone/" namespace="/poll" method="input"/>
<s:url id='cloneImg' value='/img/copy.png'/>
<s:set id='cloneTitle'><s:text name="pollen.action.pollClone"/></s:set>
-<s:url id="deleteUrl" action="delete" namespace="/poll" method="input"/>
+<s:url id="deleteUrl" action="delete/" namespace="/poll" method="input"/>
<s:url id='deleteImg' value='/img/delete.png'/>
<s:set id='deleteTitle'><s:text name="pollen.action.pollDelete"/></s:set>
@@ -65,37 +65,34 @@
var result = "";
+ if (rowObject['voteId']) {
+ id = rowObject['voteId'];
+ }
+
if (cellvalue.indexOf('vote') > -1) {
- if (rowObject['voteId']) {
- id = rowObject['voteId'];
- }
- result += formatLink(null, "${voteUrl}"+id, "${voteImg}", "Vote", "${voteTitle}")
+ result += formatLink("${voteUrl}" + id, "${voteImg}", "Vote", "${voteTitle}")
}
if (cellvalue.indexOf('result') > -1) {
- result += formatLink(null, "${resultUrl}"+id, "${resultImg}", "Result", "${resultTitle}")
+ result += formatLink("${resultUrl}" + id, "${resultImg}", "Result", "${resultTitle}")
}
if (cellvalue.indexOf('edit') > -1) {
- result += formatLink(id, "${editUrl}", "${editImg}", "Edit", "${editTitle}")
+ result += formatLink("${editUrl}" + id, "${editImg}", "Edit", "${editTitle}")
}
if (cellvalue.indexOf('close') > -1) {
- result += formatLink(id, "${closeUrl}", "${closeImg}", "Close", "${closeTitle}")
+ result += formatLink("${closeUrl}" + id, "${closeImg}", "Close", "${closeTitle}")
}
if (cellvalue.indexOf('export') > -1) {
- result += formatLink(id, "${exportUrl}", "${exportImg}", "Export", "${exportTitle}")
+ result += formatLink("${exportUrl}" + id, "${exportImg}", "Export", "${exportTitle}")
}
if (cellvalue.indexOf('clone') > -1) {
- result += formatLink(id, "${cloneUrl}", "${cloneImg}", "Clone", "${cloneTitle}")
+ result += formatLink("${cloneUrl}" + id, "${cloneImg}", "Clone", "${cloneTitle}")
}
if (cellvalue.indexOf('delete') > -1) {
- result += formatLink(id, "${deleteUrl}", "${deleteImg}", "Delete", "${deleteTitle}")
+ result += formatLink("${deleteUrl}" + id, "${deleteImg}", "Delete", "${deleteTitle}")
}
return result;
}
- function formatLink(id, baseUrl, image, imageAlt, imageTitle) {
- var url = baseUrl;
- if (id) {
- url = $.prepareUrl(baseUrl, {pollId:id});
- }
+ function formatLink(url, image, imageAlt, imageTitle) {
return "<a href='" + url + "'><image alt='" + imageAlt + "' title='" + imageTitle + "' src='" + image + "'> </a>";
}
</script>
1
0