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
- 3196 discussions
r3175 - in branches/pollen-1.2.6-struts2/pollen-domain: . src/main/java/org/chorem/poll/domain src/main/java/org/chorem/poll/domain/poll src/main/java/org/chorem/poll/domain/strategy src/main/resources/i18n src/test/java/org/chorem/poll/domain src/test/java/org/chorem/poll/domain/strategy
by tchemit@users.chorem.org 13 Mar '12
by tchemit@users.chorem.org 13 Mar '12
13 Mar '12
Author: tchemit
Date: 2012-03-13 14:59:45 +0100 (Tue, 13 Mar 2012)
New Revision: 3175
Url: http://chorem.org/repositories/revision/pollen/3175
Log:
add svn properties
Modified:
branches/pollen-1.2.6-struts2/pollen-domain/LICENSE.txt
branches/pollen-1.2.6-struts2/pollen-domain/README.txt
branches/pollen-1.2.6-struts2/pollen-domain/changelog.txt
branches/pollen-1.2.6-struts2/pollen-domain/pom.xml
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/PollenDomainFunctions.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/ChoiceType.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/I18nAble.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollType.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/VoteCountingType.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/VoteCountingStrategy.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_en_GB.properties
branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_fr_FR.properties
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/ImportExportServiceTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/VoteCountingServiceTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/CondorcetVoteCountingStrategyTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/NumberVoteCountingStrategyTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/PercentageVoteCountingStrategyTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategyTest.java
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/LICENSE.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/README.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/changelog.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/pom.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/PollenDomainFunctions.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/ChoiceType.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/ChoiceType.java 2012-03-12 08:37:14 UTC (rev 3174)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/ChoiceType.java 2012-03-13 13:59:45 UTC (rev 3175)
@@ -2,8 +2,8 @@
* #%L
* Pollen :: Vote Counting
*
- * $Id: ChoiceType.java 3122 2012-01-30 20:43:30Z tchemit $
- * $HeadURL: http://svn.chorem.org/svn/pollen/branches/pollen-1.2.6-struts2/pollen-votec… $
+ * $Id$
+ * $HeadURL$
* %%
* Copyright (C) 2009 - 2012 CodeLutin
* %%
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/ChoiceType.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/I18nAble.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/I18nAble.java 2012-03-12 08:37:14 UTC (rev 3174)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/I18nAble.java 2012-03-13 13:59:45 UTC (rev 3175)
@@ -2,8 +2,8 @@
* #%L
* Pollen :: Vote Counting
*
- * $Id: I18nAble.java 3122 2012-01-30 20:43:30Z tchemit $
- * $HeadURL: http://svn.chorem.org/svn/pollen/branches/pollen-1.2.6-struts2/pollen-votec… $
+ * $Id$
+ * $HeadURL$
* %%
* Copyright (C) 2009 - 2012 CodeLutin
* %%
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/I18nAble.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollType.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollType.java 2012-03-12 08:37:14 UTC (rev 3174)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollType.java 2012-03-13 13:59:45 UTC (rev 3175)
@@ -2,8 +2,8 @@
* #%L
* Pollen :: Vote Counting
*
- * $Id: PollType.java 3122 2012-01-30 20:43:30Z tchemit $
- * $HeadURL: http://svn.chorem.org/svn/pollen/branches/pollen-1.2.6-struts2/pollen-votec… $
+ * $Id$
+ * $HeadURL$
* %%
* Copyright (C) 2009 - 2012 CodeLutin
* %%
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollType.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/VoteCountingType.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/VoteCountingType.java 2012-03-12 08:37:14 UTC (rev 3174)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/VoteCountingType.java 2012-03-13 13:59:45 UTC (rev 3175)
@@ -2,8 +2,8 @@
* #%L
* Pollen :: Vote Counting
*
- * $Id: VoteCountingType.java 3122 2012-01-30 20:43:30Z tchemit $
- * $HeadURL: http://svn.chorem.org/svn/pollen/branches/pollen-1.2.6-struts2/pollen-votec… $
+ * $Id$
+ * $HeadURL$
* %%
* Copyright (C) 2009 - 2012 CodeLutin
* %%
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/VoteCountingType.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/VoteCountingStrategy.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_en_GB.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_fr_FR.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/ImportExportServiceTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/VoteCountingServiceTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/CondorcetVoteCountingStrategyTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/NumberVoteCountingStrategyTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/PercentageVoteCountingStrategyTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategyTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
Author: tchemit
Date: 2012-03-12 09:37:14 +0100 (Mon, 12 Mar 2012)
New Revision: 3174
Url: http://chorem.org/repositories/revision/pollen/3174
Log:
domain NG module (will be used with version 1.3
Added:
branches/pollen-1.2.6-struts2/pollen-domain/
branches/pollen-1.2.6-struts2/pollen-domain/LICENSE.txt
branches/pollen-1.2.6-struts2/pollen-domain/README.txt
branches/pollen-1.2.6-struts2/pollen-domain/changelog.txt
branches/pollen-1.2.6-struts2/pollen-domain/pom.xml
branches/pollen-1.2.6-struts2/pollen-domain/src/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/ImportExportService.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/PollenDomainFunctions.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/VoteCountingService.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/VoteCountingUtils.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/ChoiceType.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/I18nAble.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/Poll.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollChoice.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollComment.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollType.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVoteCountingChoice.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVoteCountingResult.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingChoice.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingGroup.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingPerson.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/VoteCountingType.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/CondorcetVoteCountingStrategy.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/NumberVoteCountingStrategy.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/PercentageVoteCountingStrategy.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategy.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/VoteCountingStrategy.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Choice.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Group.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/PercentageBehavior.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Vote.java
branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/
branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_en_GB.properties
branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_fr_FR.properties
branches/pollen-1.2.6-struts2/pollen-domain/src/site/
branches/pollen-1.2.6-struts2/pollen-domain/src/site/rst/
branches/pollen-1.2.6-struts2/pollen-domain/src/test/
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/ImportExportServiceTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/VoteCountingServiceTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/CondorcetVoteCountingStrategyTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/NumberVoteCountingStrategyTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/PercentageVoteCountingStrategyTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategyTest.java
branches/pollen-1.2.6-struts2/pollen-domain/src/test/resources/
branches/pollen-1.2.6-struts2/pollen-domain/src/test/resources/log4j.properties
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain
___________________________________________________________________
Added: svn:ignore
+ target
*.iml
*.ipr
*.iws
*.log
.project
.classpath
.settings.xml
Added: branches/pollen-1.2.6-struts2/pollen-domain/pom.xml
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/pom.xml (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/pom.xml 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.chorem</groupId>
+ <artifactId>pollen</artifactId>
+ <version>1.2.6-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.chorem.pollen</groupId>
+ <artifactId>pollen-domain</artifactId>
+
+ <name>Pollen :: Domain</name>
+ <description>Pollen Domain</description>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jdom</groupId>
+ <artifactId>jdom</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.nuiton.i18n</groupId>
+ <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>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.nuiton.i18n</groupId>
+ <artifactId>maven-i18n-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>parserJava</goal>
+ <goal>gen</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/ImportExportService.java (from rev 3173, 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-domain/src/main/java/org/chorem/poll/domain/ImportExportService.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/ImportExportService.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,605 @@
+/*
+ * #%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.poll.domain;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.poll.domain.poll.ChoiceType;
+import org.chorem.poll.domain.poll.Poll;
+import org.chorem.poll.domain.poll.PollChoice;
+import org.chorem.poll.domain.poll.PollComment;
+import org.chorem.poll.domain.poll.PollType;
+import org.chorem.poll.domain.poll.PollVoteCountingChoice;
+import org.chorem.poll.domain.poll.PollVoteCountingResult;
+import org.chorem.poll.domain.poll.PollVotingChoice;
+import org.chorem.poll.domain.poll.PollVotingGroup;
+import org.chorem.poll.domain.poll.PollVotingPerson;
+import org.chorem.poll.domain.poll.VoteCountingType;
+import org.chorem.poll.domain.strategy.NumberVoteCountingStrategy;
+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(Poll 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 Poll} 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 Poll 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();
+
+ Poll result = toDTO(racine);
+
+ return result;
+ }
+
+ protected Poll toDTO(Element racine) {
+
+ // Création du sondage
+ Element pollElm = racine.getChild(POLL);
+
+ Poll poll = new Poll();
+ poll.setPollId(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<PollChoice> 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<PollVoteCountingResult> vectorVoteCountingResults =
+ toVoteCountingResults(listVoteCountingResults);
+
+ // Création du sondage PollExportDTO
+ poll.setVoteCountingResult(vectorVoteCountingResults);
+
+ return poll;
+ }
+
+ protected List<PollComment> toComments(List<Element> listComments) {
+ List<PollComment> vectorComments = Lists.newArrayList();
+
+ for (Element commentElm : listComments) {
+ PollComment comment = new PollComment();
+ comment.setVotingID(commentElm.getAttributeValue(VOTING_ID));
+ comment.setText(commentElm.getText());
+ vectorComments.add(comment);
+ }
+
+ return vectorComments;
+ }
+
+ protected List<PollVotingGroup> toVotingGroups(List<Element> listGroups) {
+ List<PollVotingGroup> vectorGroups = Lists.newArrayList();
+
+ for (Element groupElm : listGroups) {
+ PollVotingGroup group = new PollVotingGroup();
+
+ group.setIdGroup(groupElm.getAttributeValue(ID_GROUP));
+ group.setWeight(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<PollVotingPerson> toVotingPersons(List<Element> listVotingPersons) {
+ List<PollVotingPerson> vectorVotingPersons = Lists.newArrayList();
+
+ for (Element votingPersonElm : listVotingPersons) {
+ PollVotingPerson votingPerson = new PollVotingPerson();
+ votingPerson.setVotingId(votingPersonElm.getAttributeValue(VOTING_ID));
+ votingPerson.setWeight(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<PollVotingChoice> toVoteToChoices(List<Element> listVoteToChoices) {
+ List<PollVotingChoice> vectorVoteToChoices = Lists.newArrayList();
+
+ for (Element voteToChoiceElm : listVoteToChoices) {
+ PollVotingChoice voteToChoice = new PollVotingChoice(
+ voteToChoiceElm.getAttributeValue(ID_CHOICE),
+ Double.parseDouble(voteToChoiceElm.getAttributeValue(VALUE)));
+ vectorVoteToChoices.add(voteToChoice);
+ }
+ return vectorVoteToChoices;
+ }
+
+ protected List<PollChoice> toPollChoices(List<Element> listPollChoices) {
+ List<PollChoice> vectorPollChoices = Lists.newArrayList();
+
+ for (Element pollChoiceElm : listPollChoices) {
+ PollChoice pollChoice = new PollChoice();
+ pollChoice.setIdChoice(pollChoiceElm.getAttributeValue(ID_CHOICE));
+
+ String pollChoiceName = pollChoiceElm.getChild(NAME).getValue();
+ pollChoice.setName(pollChoiceName);
+ pollChoice.setHidden(pollChoiceName != null
+ && pollChoiceName.startsWith(NumberVoteCountingStrategy.HIDDEN_PREFIX));
+
+ pollChoice.setDescription(pollChoiceElm.getChild(DESCRIPTION)
+ .getValue());
+
+ vectorPollChoices.add(pollChoice);
+ }
+
+ return vectorPollChoices;
+ }
+
+ protected List<PollVoteCountingResult> toVoteCountingResults(List<Element> listVoteCountingResults) {
+ List<PollVoteCountingResult> vectorVoteCountingResults = Lists.newArrayList();
+
+ for (Element voteCountingResultElm : listVoteCountingResults) {
+ PollVoteCountingResult voteCountingResult = new PollVoteCountingResult();
+ 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<PollVoteCountingChoice> toChoices(List<Element> listChoices) {
+ List<PollVoteCountingChoice> vectorChoices = Lists.newArrayList();
+
+ for (Element choiceElm : listChoices) {
+ PollVoteCountingChoice choice = new PollVoteCountingChoice(
+ 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(Poll poll) {
+
+ List<PollVoteCountingResult> voteCountingResults =
+ poll.getVoteCountingResult();
+
+ // 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 (PollComment 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 (PollVotingGroup votingGroupDTO : poll.getVotingGroups()) {
+ Element groupElm = toDOM(votingGroupDTO);
+ groupsElm.addContent(groupElm);
+ }
+
+ pollElm.addContent(groupsElm);
+
+ // Création des choix
+ Element pollChoicesElm = new Element(POLL_CHOICES);
+
+ for (PollChoice 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 (PollVoteCountingResult 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(PollComment comment) {
+ Element commentElm = new Element(COMMENT);
+
+ commentElm.setAttribute(VOTING_ID, comment.getVotingID());
+ commentElm.setText(comment.getText());
+
+ return commentElm;
+ }
+
+ protected Element toDOM(PollVotingGroup 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 (PollVotingPerson votingPersonDTO : group.getVotingPersons()) {
+ Element votingPersonElm = toDOM(votingPersonDTO);
+ votingPersonsElm.addContent(votingPersonElm);
+ }
+ groupElm.addContent(votingPersonsElm);
+
+ return groupElm;
+ }
+
+ protected Element toDOM(PollVotingPerson 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 (PollVotingChoice 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(PollChoice 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(PollVoteCountingResult 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 (PollVoteCountingChoice choiceDTO : voteCountingResults.getChoices()) {
+ Element choiceElm = toDOM(choiceDTO);
+ choicesElm.addContent(choiceElm);
+ }
+
+ voteCountingResultElm.addContent(choicesElm);
+
+ return voteCountingResultElm;
+ }
+
+ protected Element toDOM(PollVoteCountingChoice 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;
+ }
+
+}
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/PollenDomainFunctions.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/PollenDomainFunctions.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/PollenDomainFunctions.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,11 @@
+package org.chorem.poll.domain;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class PollenDomainFunctions {
+
+}
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/VoteCountingService.java (from rev 3173, 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-domain/src/main/java/org/chorem/poll/domain/VoteCountingService.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/VoteCountingService.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,392 @@
+/*
+ * #%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.poll.domain;
+
+import com.google.common.collect.Iterables;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.poll.domain.poll.Poll;
+import org.chorem.poll.domain.poll.PollChoice;
+import org.chorem.poll.domain.poll.PollType;
+import org.chorem.poll.domain.poll.PollVoteCountingChoice;
+import org.chorem.poll.domain.poll.PollVoteCountingResult;
+import org.chorem.poll.domain.poll.PollVotingChoice;
+import org.chorem.poll.domain.poll.PollVotingGroup;
+import org.chorem.poll.domain.poll.PollVotingPerson;
+import org.chorem.poll.domain.strategy.CondorcetVoteCountingStrategy;
+import org.chorem.poll.domain.strategy.NumberVoteCountingStrategy;
+import org.chorem.poll.domain.strategy.PercentageVoteCountingStrategy;
+import org.chorem.poll.domain.strategy.StandardVoteCountingStrategy;
+import org.chorem.poll.domain.strategy.VoteCountingStrategy;
+import org.chorem.poll.domain.vote.Choice;
+import org.chorem.poll.domain.vote.Group;
+
+import java.util.ArrayList;
+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 PollVoteCountingResult execute(Poll poll) {
+ boolean byGroup = poll.getPollType() == PollType.GROUP;
+ PollVoteCountingResult result = execute(poll, byGroup);
+ return result;
+ }
+
+ public PollVoteCountingResult executeVoteCounting(Poll poll) {
+ return execute(poll, false);
+ }
+
+ public PollVoteCountingResult executeGroupCounting(Poll poll) {
+ return execute(poll, true);
+ }
+
+ /**
+ * Execution du dépouillement
+ *
+ * @param poll : sondage
+ * @return resultat
+ */
+ private PollVoteCountingResult execute(Poll poll, boolean isByGroup) {
+ if (log.isInfoEnabled()) {
+ log.info("Dépouillement (byGroup=" + isByGroup + ") du sondage "
+ + poll.getPollId());
+ }
+
+ // Création et remplissage du contexte
+ VoteCountingContext context = VoteCountingContext.create(poll,
+ isByGroup);
+
+ // Execution
+ if (!context.executeCounting()) {
+ //FIXME tchemit ? Why returning null, prefer use an exception
+ return null;
+ }
+ List<PollVoteCountingChoice> resChoices = context.executeStats();
+
+ PollVoteCountingResult result = new PollVoteCountingResult();
+ result.setNbVotes(calculateNbVotes(poll, isByGroup));
+ result.setTypeVoteCounting(poll.getVoteCounting());
+ result.setByGroup(isByGroup);
+ result.setIdPoll(poll.getPollId());
+ result.setChoices(resChoices);
+ return result;
+ }
+
+ /**
+ * Contexte du dépouillement du sondage (PATTERN STRATEGY).
+ *
+ * @author fdesbois
+ * @version $Id$
+ */
+ public static class VoteCountingContext {
+
+ /**
+ * Booléen permettant de savoir si la méthode doit calculer la valeur des
+ * choix en fonction des groupes
+ */
+ private boolean groupCounting;
+
+ /** Liste des choix liés au contexte et résultats */
+ private List<Choice> choices, hiddenChoices, results;
+
+ /** Méthode de dépouillement choisie pour ce contexte */
+ private VoteCountingStrategy method;
+
+
+ /**
+ * Constructeur
+ *
+ * @param method : Méthode de dépouillement
+ * @param groupCounting : Dépouillement pour les groupes ou non
+ */
+ VoteCountingContext(VoteCountingStrategy method, boolean groupCounting) {
+ this.groupCounting = groupCounting;
+ this.choices = new ArrayList<Choice>();
+ this.hiddenChoices = new ArrayList<Choice>();
+ this.results = new ArrayList<Choice>();
+ this.method = method;
+ }
+
+ /**
+ * Création du contexte en fonction du type de dépouillement
+ *
+ * @param poll
+ * @param isByGroup
+ * @return
+ */
+ public static VoteCountingContext create(Poll poll, boolean isByGroup) {
+
+ VoteCountingStrategy method;
+ switch (poll.getVoteCounting()) {
+ case NORMAL:
+ method = new StandardVoteCountingStrategy();
+ break;
+ case PERCENTAGE:
+ method = new PercentageVoteCountingStrategy();
+ break;
+ case CONDORCET:
+ method = new CondorcetVoteCountingStrategy();
+ break;
+ case NUMBER:
+ method = new NumberVoteCountingStrategy();
+ break;
+ default:
+ method = new StandardVoteCountingStrategy();
+ }
+ VoteCountingContext result = new VoteCountingContext(method,
+ isByGroup);
+
+ for (PollChoice choice : poll.getChoices()) {
+ if (choice.isHidden()) {
+ result.addHiddenChoice(choice);
+ } else {
+ result.addChoice(choice);
+ }
+ }
+ for (PollVotingGroup votingGroup : poll.getVotingGroups()) {
+ result.addGroup(votingGroup.getIdGroup(), votingGroup.getWeight());
+ for (PollVotingPerson person : votingGroup.getVotingPersons()) {
+ String currentIdGroup = votingGroup.getIdGroup();
+ for (PollVotingChoice vote : person.getChoices()) {
+
+ Choice choice = result.getChoice(vote.getIdChoice());
+
+ Group group = choice.getGroup(currentIdGroup);
+
+ group.addVote(vote.getValue(),
+ person.getWeight(),
+ person.getVotingId());
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Renvoie un choix de la map
+ *
+ * @param idChoice : identifiant du choix
+ * @return choix
+ */
+ public Choice getChoice(String idChoice) {
+ for (Choice choice : this.choices) {
+ if (choice.getIdChoice().equals(idChoice)) {
+ return choice;
+ }
+ }
+ for (Choice choice : this.hiddenChoices) {
+ if (choice.getIdChoice().equals(idChoice)) {
+ return choice;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Renvoie la liste des choix
+ *
+ * @return liste des choix
+ */
+ public List<Choice> getChoices() {
+ return this.choices;
+ }
+
+ /**
+ * Renvoie la liste des choix cachés
+ *
+ * @return liste des choix cachés
+ */
+ public List<Choice> getHiddenChoices() {
+ return this.hiddenChoices;
+ }
+
+ /**
+ * Renvoie la liste des résultats
+ *
+ * @return liste des choix résultats
+ */
+ public List<Choice> getResults() {
+ return this.results;
+ }
+
+ /**
+ * Ajout d'un nouveau choix au contexte
+ *
+ * @param choice choix à ajouter
+ */
+ public void addChoice(PollChoice choice) {
+ this.choices.add(new Choice(choice.getIdChoice(), choice.getName()));
+ }
+
+ /**
+ * Ajout d'un nouveau choix au contexte
+ *
+ * @param choice choix à ajouter
+ */
+ public void addHiddenChoice(PollChoice choice) {
+ this.hiddenChoices.add(new Choice(choice.getIdChoice(), choice.getName()));
+ }
+
+ /**
+ * Ajout d'un groupe pour l'ensemble des choix du contexte
+ *
+ * @param idGroup : identifiant du groupe
+ * @param weight : poids du groupe
+ */
+ public void addGroup(String idGroup, double weight) {
+ for (Choice choice : this.choices) {
+ choice.addGroup(idGroup, weight);
+ }
+ for (Choice choice : this.hiddenChoices) {
+ choice.addGroup(idGroup, weight);
+ }
+ }
+
+ /**
+ * Test si le choix est un résultat d'après le contexte A utiliser après
+ * dépouillement sinon aucun résultat
+ *
+ * @param choice : choix à tester
+ * @return true si le choix est un résultat, false sinon
+ */
+ private boolean isChoiceResult(Choice choice) {
+ for (Choice res : results) {
+ if (choice.getIdChoice().equals(res.getIdChoice())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Execution de la méthode de dépouillement et calcul des choix résultats
+ *
+ * @return liste de choix résultats
+ */
+ public boolean executeCounting() {
+
+ 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;
+ this.results.clear();
+ } else if (curr.value() == result.value()) {
+ this.results.add(curr);
+ }
+ }
+
+ this.results.add(result);
+ return true;
+ }
+
+ public List<PollVoteCountingChoice> executeStats() {
+ List<PollVoteCountingChoice> resChoices = new ArrayList<PollVoteCountingChoice>();
+
+ try {
+ for (Choice choice : choices) {
+ PollVoteCountingChoice choiceDTO = new PollVoteCountingChoice();
+
+ choiceDTO.setIdChoice(choice.getIdChoice());
+ choiceDTO.setName(choice.getName());
+ choiceDTO.setValue(choice.getValue());
+ choiceDTO.setResult(isChoiceResult(choice));
+ choiceDTO.setNbVotes(calculateNbVotes(choice, groupCounting));
+
+ method.executeStats(choices, groupCounting, choice, choiceDTO);
+ resChoices.add(choiceDTO);
+ }
+
+ for (Choice choice : hiddenChoices) {
+ PollVoteCountingChoice choiceDTO = new PollVoteCountingChoice();
+ choiceDTO.setIdChoice(choice.getIdChoice());
+ choiceDTO.setName(choice.getName());
+ choiceDTO.setValue(choice.getValue());
+ resChoices.add(choiceDTO);
+ }
+
+ } catch (Exception e) {
+ log.error("L'exécution des statistiques a échoué", e);
+ resChoices = new ArrayList<PollVoteCountingChoice>();
+ }
+
+ return resChoices;
+ }
+ }
+
+ /**
+ * Calcul le nombre de votes d'une liste
+ *
+ * @param poll
+ * @param byGroup
+ * @return nombre de votes
+ */
+ public static int calculateNbVotes(Poll poll, boolean byGroup) {
+ int result;
+ List<PollVotingGroup> list = poll.getVotingGroups();
+ if (byGroup) {
+ result = 0;
+ for (PollVotingGroup curr : list) {
+ result += Iterables.size(curr);
+ }
+ } else {
+ result = list.size();
+ }
+ return result;
+ }
+
+ /**
+ * Calcul le nombre de votes d'une liste
+ *
+ * @param choice
+ * @param byGroup
+ * @return nombre de votes
+ */
+ public static int calculateNbVotes(Choice choice, boolean byGroup) {
+ int result;
+ List<Group> list = choice.getGroups();
+ if (byGroup) {
+ result = 0;
+ for (Group curr : list) {
+ result += Iterables.size(curr);
+ }
+ } else {
+ result = list.size();
+ }
+ return result;
+ }
+}
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/VoteCountingUtils.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/utils/Utils.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/VoteCountingUtils.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/VoteCountingUtils.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,88 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain;
+
+import org.chorem.poll.domain.vote.PercentageBehavior;
+
+import java.util.List;
+
+/**
+ * Classe utilitaire pour les algorithmes de dépouillement.
+ *
+ * @version $Id$
+ */
+public class VoteCountingUtils {
+
+ public static double calculatePercentage(PercentageBehavior in,
+ List<PercentageBehavior> list) {
+ double total = 0.;
+ for (PercentageBehavior curr : list) {
+ total += curr.value();
+ }
+ return (in.value() / total * 100);
+ }
+
+// /**
+// * Calcul le nombre de votes d'une liste
+// *
+// * @param poll
+// * @param byGroup
+// * @return nombre de votes
+// */
+// public static int calculateNbVotes(Poll poll, boolean byGroup) {
+// int result;
+// List<PollVotingGroup> list = poll.getVotingGroups();
+// if (byGroup) {
+// result = 0;
+// for (PollVotingGroup curr : list) {
+// result += Iterables.size(curr);
+// }
+// } else {
+// result = list.size();
+// }
+// return result;
+// }
+//
+// /**
+// * Calcul le nombre de votes d'une liste
+// *
+// * @param choice
+// * @param byGroup
+// * @return nombre de votes
+// */
+// public static int calculateNbVotes(Choice choice, boolean byGroup) {
+// int result;
+// List<Group> list = choice.getGroups();
+// if (byGroup) {
+// result = 0;
+// for (Group curr : list) {
+// result += Iterables.size(curr);
+// }
+// } else {
+// result = list.size();
+// }
+// return result;
+// }
+
+}
\ No newline at end of file
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/ChoiceType.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/ChoiceType.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/ChoiceType.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,55 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id: ChoiceType.java 3122 2012-01-30 20:43:30Z tchemit $
+ * $HeadURL: http://svn.chorem.org/svn/pollen/branches/pollen-1.2.6-struts2/pollen-votec… $
+ * %%
+ * 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.poll.domain.poll;
+
+import static org.nuiton.i18n.I18n.n_;
+
+public enum ChoiceType implements I18nAble {
+ TEXT(n_("pollen.choiceType.text")),
+ DATE(n_("pollen.choiceType.date")),
+ IMAGE(n_("pollen.choiceType.image"));
+
+ private final String i18nKey;
+
+ ChoiceType(String i18nKey) {
+ this.i18nKey = i18nKey;
+ }
+
+ @Override
+ public String getI18nKey() {
+ return i18nKey;
+ }
+
+ public static ChoiceType valueOf(int ordinal) {
+
+ ChoiceType result = null;
+ for (ChoiceType curr : ChoiceType.values()) {
+ if (curr.ordinal() == ordinal) {
+ result = curr;
+ break;
+ }
+ }
+ return result;
+ }
+}
\ No newline at end of file
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/I18nAble.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/I18nAble.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/I18nAble.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,35 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id: I18nAble.java 3122 2012-01-30 20:43:30Z tchemit $
+ * $HeadURL: http://svn.chorem.org/svn/pollen/branches/pollen-1.2.6-struts2/pollen-votec… $
+ * %%
+ * 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.poll.domain.poll;
+
+/**
+ * Contract to expose a i18n key.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public interface I18nAble {
+
+ String getI18nKey();
+}
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/Poll.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/PollDTO.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/Poll.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/Poll.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,257 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.poll;
+
+import com.google.common.collect.Lists;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Classe DTO représentant un sondage.
+ *
+ * @version $Id$
+ */
+public class Poll {
+
+ private String pollId = "";
+
+ private String title = "";
+
+ private String description = "";
+
+ private Date beginDate = new Date();
+
+ private Date endDate = null;
+
+ private Date beginChoiceDate = null;
+
+ private int maxChoiceNb = 0;
+
+ private boolean closed = true;
+
+ private boolean choiceAddAllowed = false;
+
+ private boolean anonymousVoteAllowed = false;
+
+ private boolean anonymous = false;
+
+ private boolean publicResults = false;
+
+ private boolean continuousResults = false;
+
+ private PollType pollType = null;
+
+ private VoteCountingType voteCounting = null;
+
+ private ChoiceType choiceType = null;
+
+ private String creatorId = "";
+
+ private String creatorEmail = "";
+
+ private List<PollVotingGroup> votingGroups = Lists.newArrayList();
+
+ private List<PollChoice> choices = Lists.newArrayList();
+
+ private List<PollComment> comments = Lists.newArrayList();
+
+ private List<PollVoteCountingResult> voteCountingResult;
+
+ public String getPollId() {
+ return pollId;
+ }
+
+ public void setPollId(String pollId) {
+ this.pollId = pollId;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public Date getBeginDate() {
+ return beginDate;
+ }
+
+ public void setBeginDate(Date beginDate) {
+ this.beginDate = beginDate;
+ }
+
+ public Date getEndDate() {
+ return endDate;
+ }
+
+ public void setEndDate(Date endDate) {
+ this.endDate = endDate;
+ }
+
+ public Date getBeginChoiceDate() {
+ return beginChoiceDate;
+ }
+
+ public void setBeginChoiceDate(Date beginChoiceDate) {
+ this.beginChoiceDate = beginChoiceDate;
+ }
+
+ public int getMaxChoiceNb() {
+ return maxChoiceNb;
+ }
+
+ public void setMaxChoiceNb(int maxChoiceNb) {
+ this.maxChoiceNb = maxChoiceNb;
+ }
+
+ public boolean isClosed() {
+ return closed;
+ }
+
+ public void setClosed(boolean closed) {
+ this.closed = closed;
+ }
+
+ public boolean isChoiceAddAllowed() {
+ return choiceAddAllowed;
+ }
+
+ public void setChoiceAddAllowed(boolean choiceAddAllowed) {
+ this.choiceAddAllowed = choiceAddAllowed;
+ }
+
+ public boolean isAnonymousVoteAllowed() {
+ return anonymousVoteAllowed;
+ }
+
+ public void setAnonymousVoteAllowed(boolean anonymousVoteAllowed) {
+ this.anonymousVoteAllowed = anonymousVoteAllowed;
+ }
+
+ public boolean isAnonymous() {
+ return anonymous;
+ }
+
+ public void setAnonymous(boolean anonymous) {
+ this.anonymous = anonymous;
+ }
+
+ public boolean isPublicResults() {
+ return publicResults;
+ }
+
+ public void setPublicResults(boolean publicResults) {
+ this.publicResults = publicResults;
+ }
+
+ public boolean isContinuousResults() {
+ return continuousResults;
+ }
+
+ public void setContinuousResults(boolean continuousResults) {
+ this.continuousResults = continuousResults;
+ }
+
+ public PollType getPollType() {
+ return pollType;
+ }
+
+ public void setPollType(PollType pollType) {
+ this.pollType = pollType;
+ }
+
+ public VoteCountingType getVoteCounting() {
+ return voteCounting;
+ }
+
+ public void setVoteCounting(VoteCountingType voteCounting) {
+ this.voteCounting = voteCounting;
+ }
+
+ public ChoiceType getChoiceType() {
+ return choiceType;
+ }
+
+ public void setChoiceType(ChoiceType choiceType) {
+ this.choiceType = choiceType;
+ }
+
+ public String getCreatorId() {
+ return creatorId;
+ }
+
+ public void setCreatorId(String creatorId) {
+ this.creatorId = creatorId;
+ }
+
+ public String getCreatorEmail() {
+ return creatorEmail;
+ }
+
+ public void setCreatorEmail(String creatorEmail) {
+ this.creatorEmail = creatorEmail;
+ }
+
+ public List<PollVotingGroup> getVotingGroups() {
+ return votingGroups;
+ }
+
+ public void setVotingGroups(List<PollVotingGroup> votingGroups) {
+ this.votingGroups = votingGroups;
+ }
+
+ public List<PollChoice> getChoices() {
+ return choices;
+ }
+
+ public void setChoices(List<PollChoice> choices) {
+ this.choices = choices;
+ }
+
+ public List<PollComment> getComments() {
+ return comments;
+ }
+
+ public void setComments(List<PollComment> comments) {
+ this.comments = comments;
+ }
+
+ public List<PollVoteCountingResult> getVoteCountingResult() {
+ return voteCountingResult;
+ }
+
+ public void setVoteCountingResult(List<PollVoteCountingResult> voteCountingResult) {
+ this.voteCountingResult = voteCountingResult;
+ }
+}
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/Poll.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollChoice.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/PollChoiceDTO.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollChoice.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollChoice.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,72 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.poll;
+
+/**
+ * Classe DTO représentant un choix de vote.
+ *
+ * @version $Id$
+ */
+public class PollChoice {
+
+ private String idChoice;
+
+ private String name;
+
+ private String description;
+
+ private boolean hidden;
+
+ public String getIdChoice() {
+ return idChoice;
+ }
+
+ public void setIdChoice(String idChoice) {
+ this.idChoice = idChoice;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public boolean isHidden() {
+ return hidden;
+ }
+
+ public void setHidden(boolean hidden) {
+ this.hidden = hidden;
+ }
+}
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollChoice.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollComment.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/CommentDTO.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollComment.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollComment.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,52 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.poll;
+
+/**
+ * Classe DTO représentant un commentaire.
+ *
+ * @version $Id$
+ */
+public class PollComment {
+
+ private String votingID;
+
+ private String text;
+
+ public String getVotingID() {
+ return votingID;
+ }
+
+ public void setVotingID(String votingID) {
+ this.votingID = votingID;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+}
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollComment.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollType.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollType.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollType.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,55 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id: PollType.java 3122 2012-01-30 20:43:30Z tchemit $
+ * $HeadURL: http://svn.chorem.org/svn/pollen/branches/pollen-1.2.6-struts2/pollen-votec… $
+ * %%
+ * 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.poll.domain.poll;
+
+import static org.nuiton.i18n.I18n.n_;
+
+public enum PollType implements I18nAble {
+
+ FREE(n_("pollen.pollType.free")),
+ RESTRICTED(n_("pollen.pollType.restricted")),
+ GROUP(n_("pollen.pollType.group"));
+
+ private final String i18nKey;
+
+ PollType(String i18nKey) {
+ this.i18nKey = i18nKey;
+ }
+
+ @Override
+ public String getI18nKey() {
+ return i18nKey;
+ }
+
+ public static PollType valueOf(int ordinal) {
+ PollType result = null;
+ for (PollType curr : PollType.values()) {
+ if (curr.ordinal() == ordinal) {
+ result = curr;
+ break;
+ }
+ }
+ return result;
+ }
+}
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVoteCountingChoice.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/ChoiceDTO.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVoteCountingChoice.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVoteCountingChoice.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,124 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+package org.chorem.poll.domain.poll;
+
+/**
+ * Classe DTO représentant un choix et les valeurs du vote correspondant.
+ *
+ * @version $Id$
+ */
+public class PollVoteCountingChoice {
+
+ private String idChoice;
+
+ private String name;
+
+ private double value;
+
+ private double percentage;
+
+ private double average;
+
+ private int nbVotes;
+
+ private int nbBlankVotes;
+
+ private boolean result;
+
+ public PollVoteCountingChoice() {
+ }
+
+ public PollVoteCountingChoice(String idChoice, double value, double percentage,
+ int nbVotes) {
+ this.idChoice = idChoice;
+ this.value = value;
+ this.percentage = percentage;
+ this.nbVotes = nbVotes;
+ }
+
+ public String getIdChoice() {
+ return idChoice;
+ }
+
+ public void setIdChoice(String idChoice) {
+ this.idChoice = idChoice;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public double getValue() {
+ return value;
+ }
+
+ public void setValue(double value) {
+ this.value = value;
+ }
+
+ public double getPercentage() {
+ return percentage;
+ }
+
+ public void setPercentage(double percentage) {
+ this.percentage = percentage;
+ }
+
+ public double getAverage() {
+ return average;
+ }
+
+ public void setAverage(double average) {
+ this.average = average;
+ }
+
+ public int getNbVotes() {
+ return nbVotes;
+ }
+
+ public void setNbVotes(int nbVotes) {
+ this.nbVotes = nbVotes;
+ }
+
+ public int getNbBlankVotes() {
+ return nbBlankVotes;
+ }
+
+ public void setNbBlankVotes(int nbBlankVotes) {
+ this.nbBlankVotes = nbBlankVotes;
+ }
+
+ public boolean isResult() {
+ return result;
+ }
+
+ public void setResult(boolean result) {
+ this.result = result;
+ }
+}
\ No newline at end of file
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVoteCountingResult.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/VoteCountingResultDTO.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVoteCountingResult.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVoteCountingResult.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,99 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.poll;
+
+import java.util.List;
+
+/**
+ * Classe DTO représentant un résultat de sondage.
+ *
+ * @version $Id$
+ */
+public class PollVoteCountingResult {
+
+ private int nbVotes;
+
+ private String choiceResult;
+
+ private String idPoll;
+
+ private VoteCountingType typeVoteCounting;
+
+ private boolean byGroup;
+
+ private List<PollVoteCountingChoice> choices;
+
+ public PollVoteCountingResult() {
+
+ }
+
+ public int getNbVotes() {
+ return nbVotes;
+ }
+
+ public void setNbVotes(int nbVotes) {
+ this.nbVotes = nbVotes;
+ }
+
+ public String getChoiceResult() {
+ return choiceResult;
+ }
+
+ public void setChoiceResult(String choiceResult) {
+ this.choiceResult = choiceResult;
+ }
+
+ public String getIdPoll() {
+ return idPoll;
+ }
+
+ public void setIdPoll(String idPoll) {
+ this.idPoll = idPoll;
+ }
+
+ public VoteCountingType getTypeVoteCounting() {
+ return typeVoteCounting;
+ }
+
+ public void setTypeVoteCounting(VoteCountingType typeVoteCounting) {
+ this.typeVoteCounting = typeVoteCounting;
+ }
+
+ public boolean isByGroup() {
+ return byGroup;
+ }
+
+ public void setByGroup(boolean byGroup) {
+ this.byGroup = byGroup;
+ }
+
+ public List<PollVoteCountingChoice> getChoices() {
+ return choices;
+ }
+
+ public void setChoices(List<PollVoteCountingChoice> choices) {
+ this.choices = choices;
+ }
+
+}
\ No newline at end of file
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingChoice.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/VoteToChoiceDTO.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingChoice.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingChoice.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,63 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.poll;
+
+/**
+ * Classe DTO représentant un vote.
+ *
+ * @version $Id$
+ */
+public class PollVotingChoice {
+
+ private double value;
+
+ private String idChoice;
+
+ public PollVotingChoice(int idChoice, double value) {
+ this.idChoice = String.valueOf(idChoice);
+ this.value = value;
+ }
+
+ public PollVotingChoice(String idChoice, double value) {
+ this.idChoice = idChoice;
+ this.value = value;
+ }
+
+ public double getValue() {
+ return value;
+ }
+
+ public void setValue(double value) {
+ this.value = value;
+ }
+
+ public String getIdChoice() {
+ return idChoice;
+ }
+
+ public void setIdChoice(String idChoice) {
+ this.idChoice = idChoice;
+ }
+
+}
\ No newline at end of file
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingGroup.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/VotingGroupDTO.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingGroup.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingGroup.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,83 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.poll;
+
+import com.google.common.collect.Lists;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Classe DTO représentant un groupe de votants.
+ *
+ * @version $Id$
+ */
+public class PollVotingGroup implements Iterable<PollVotingPerson> {
+
+ private String name;
+
+ private double weight;
+
+ private String idGroup;
+
+ private List<PollVotingPerson> votingPersons = Lists.newArrayList();
+
+ @Override
+ public Iterator<PollVotingPerson> iterator() {
+ return votingPersons.iterator();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public double getWeight() {
+ return weight;
+ }
+
+ public void setWeight(double weight) {
+ this.weight = weight;
+ }
+
+ public String getIdGroup() {
+ return idGroup;
+ }
+
+ public void setIdGroup(String idGroup) {
+ this.idGroup = idGroup;
+ }
+
+ public List<PollVotingPerson> getVotingPersons() {
+ return votingPersons;
+ }
+
+ public void setVotingPersons(List<PollVotingPerson> votingPersons) {
+ this.votingPersons = votingPersons;
+ }
+
+}
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingGroup.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingPerson.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/dto/VotingPersonDTO.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingPerson.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingPerson.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,108 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.poll;
+
+import com.google.common.collect.Lists;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Classe DTO représentant un votant.
+ *
+ * @version $Id$
+ */
+public class PollVotingPerson {
+
+ private String votingId;
+
+ private double weight;
+
+ private String comment;
+
+ private String email;
+
+ private String login;
+
+ private Date votingDate;
+
+ private List<PollVotingChoice> choices = Lists.newArrayList();
+
+ public String getVotingId() {
+ return votingId;
+ }
+
+ public void setVotingId(String votingId) {
+ this.votingId = votingId;
+ }
+
+ public double getWeight() {
+ return weight;
+ }
+
+ public void setWeight(double weight) {
+ this.weight = weight;
+ }
+
+ public String getComment() {
+ return comment;
+ }
+
+ public void setComment(String comment) {
+ this.comment = comment;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getLogin() {
+ return login;
+ }
+
+ public void setLogin(String login) {
+ this.login = login;
+ }
+
+ public Date getVotingDate() {
+ return votingDate;
+ }
+
+ public void setVotingDate(Date votingDate) {
+ this.votingDate = votingDate;
+ }
+
+ public List<PollVotingChoice> getChoices() {
+ return choices;
+ }
+
+ public void setChoices(List<PollVotingChoice> choices) {
+ this.choices = choices;
+ }
+
+}
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/PollVotingPerson.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/VoteCountingType.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/VoteCountingType.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/poll/VoteCountingType.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,55 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id: VoteCountingType.java 3122 2012-01-30 20:43:30Z tchemit $
+ * $HeadURL: http://svn.chorem.org/svn/pollen/branches/pollen-1.2.6-struts2/pollen-votec… $
+ * %%
+ * 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.poll.domain.poll;
+
+import static org.nuiton.i18n.I18n.n_;
+
+public enum VoteCountingType implements I18nAble {
+ NORMAL(n_("pollen.voteCountingType.normal")),
+ PERCENTAGE(n_("pollen.voteCountingType.percentage")),
+ CONDORCET(n_("pollen.voteCountingType.condorcet")),
+ NUMBER(n_("pollen.voteCountingType.number"));
+
+ private final String i18nKey;
+
+ VoteCountingType(String i18nKey) {
+ this.i18nKey = i18nKey;
+ }
+
+ @Override
+ public String getI18nKey() {
+ return i18nKey;
+ }
+
+ public static VoteCountingType valueOf(int ordinal) {
+ VoteCountingType result = null;
+ for (VoteCountingType curr : VoteCountingType.values()) {
+ if (curr.ordinal() == ordinal) {
+ result = curr;
+ break;
+ }
+ }
+ return result;
+ }
+}
\ No newline at end of file
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/CondorcetVoteCountingStrategy.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/CondorcetMethod.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/CondorcetVoteCountingStrategy.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/CondorcetVoteCountingStrategy.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,337 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.strategy;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.poll.domain.VoteCountingUtils;
+import org.chorem.poll.domain.poll.PollVoteCountingChoice;
+import org.chorem.poll.domain.vote.Choice;
+import org.chorem.poll.domain.vote.Group;
+import org.chorem.poll.domain.vote.PercentageBehavior;
+import org.chorem.poll.domain.vote.Vote;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+/**
+ * Méthode de dépouillement Condorcet.
+ *
+ * @author rannou
+ * @version $Id$
+ */
+public class CondorcetVoteCountingStrategy implements VoteCountingStrategy {
+
+ /** Victoires pour chaque choix. */
+ private Map<Choice, Double> victories;
+
+ /** Choix de chaque personne. (personne >> choix >> classement) */
+ private Map<String, Map<Choice, Double>> personVotes;
+
+ /** Choix de chaque groupe. (groupe >> choix >> classement) */
+ private Map<String, Map<Choice, Double>> groupVotes;
+
+ /** log. */
+ private static final Log log =
+ LogFactory.getLog(CondorcetVoteCountingStrategy.class);
+
+ @Override
+ public void executeCounting(List<Choice> choices, boolean byGroup) {
+ if (byGroup) {
+ initPersonVotes(choices);
+ initGroupVotes(choices);
+ calculateVictories(choices, groupVotes, byGroup);
+ updateChoices(choices);
+ } else {
+ initPersonVotes(choices);
+ calculateVictories(choices, personVotes, byGroup);
+ updateChoices(choices);
+ }
+ }
+
+ /**
+ * Initialisation des votes par personne. Les votes sont initialisés avec
+ * les valeurs des choix.
+ *
+ * @param choices Les choix utilisés pour le dépouillement.
+ */
+ private void initPersonVotes(List<Choice> choices) {
+ personVotes = new HashMap<String, Map<Choice, Double>>();
+ for (Choice choice : choices) {
+ for (Group group : choice.getGroups()) {
+ for (Vote vote : group.getVotes()) {
+ Map<Choice, Double> choicesMap = personVotes.get(vote
+ .getVotingID());
+ if (choicesMap == null) {
+ choicesMap = new HashMap<Choice, Double>();
+ }
+ choicesMap.put(choice, vote.getValue());
+ personVotes.put(vote.getVotingID(), choicesMap);
+ }
+ }
+ }
+ }
+
+ /**
+ * Initialisation des votes par groupes. Les votes sont initialisés avec les
+ * victoires des membres du groupe. Des dépouillements sont donc effectués
+ * au sein de chaque groupe avant d'effectuer le dépouillement global.
+ *
+ * @param choices Les choix utilisés pour le dépouillement.
+ */
+ private void initGroupVotes(List<Choice> choices) {
+ groupVotes = new HashMap<String, Map<Choice, Double>>();
+
+ // Initialisation de la liste des membres de chaque groupe (groupMembers)
+ Map<String, Set<String>> groupMembers = new HashMap<String, Set<String>>();
+ for (Choice choice : choices) {
+ for (Group group : choice.getGroups()) {
+ Set<String> members = groupMembers.get(group.getIdGroup());
+ if (members == null) {
+ members = new HashSet<String>();
+ }
+ for (Vote vote : group.getVotes()) {
+ members.add(vote.getVotingID());
+ }
+ groupMembers.put(group.getIdGroup(), members);
+ }
+ }
+
+ // Initialisation des votes de chaque groupe (groupVotes)
+ for (String groupID : groupMembers.keySet()) {
+
+ // Initialisation des votes par membre à partir des personVotes
+ // membersVotes : liste des votes de chaque votant du groupe courant
+ Map<String, Map<Choice, Double>> membersVotes = new HashMap<String, Map<Choice, Double>>();
+ for (String votingID : groupMembers.get(groupID)) {
+ Map<Choice, Double> choicesMap = personVotes.get(votingID);
+ membersVotes.put(votingID, choicesMap);
+ }
+
+ // Calcul des victoires pour le groupe
+ calculateVictories(choices, membersVotes, false);
+ groupVotes.put(groupID, victories2votes(victories));
+
+ //TODO joindre ce résultat (Map) au group.value (Double) ???
+ TreeSet<Double> treeVictories = new TreeSet<Double>(victories
+ .values());
+ for (Choice choice : choices) {
+ for (Group group : choice.getGroups()) {
+ if (group.getIdGroup().equals(groupID)) {
+ group.setValue(treeVictories.last());
+ }
+ }
+ }
+
+ // Affichage des victoires et des groupVotes
+ if (log.isDebugEnabled()) {
+ log.debug("> groupe " + groupID);
+ for (Choice choice : victories.keySet()) {
+ log.debug(">> choix= " + choice.getIdChoice()
+ + " _ victoires= " + victories.get(choice)
+ + " _ classement= "
+ + groupVotes.get(groupID).get(choice));
+ }
+ }
+ }
+ }
+
+ /**
+ * Calcul des victoires. Parcours des votants (personnes ou groupes) et de
+ * leurs votes. Pour chaque vote, calcul des victoires par rapport aux
+ * autres votes du votant et mise à jour du nombre de victoires pour ce
+ * vote.
+ *
+ * @param choices Les choix utilisés pour le dépouillement.
+ * @param votes Les votes de chaque votant.
+ * @param byGroup Calcul sur des groupes.
+ * @see #getVictories(String, Choice, Map)
+ */
+ private void calculateVictories(List<Choice> choices,
+ Map<String, Map<Choice, Double>> votes, boolean byGroup) {
+ // Initialisation des victoires à 0.
+ victories = new HashMap<Choice, Double>();
+ for (Choice choice : choices) {
+ victories.put(choice, 0.);
+ }
+
+ // Calcul des victoires
+ for (String keyVotant : votes.keySet()) {
+ for (Choice keyChoice : votes.get(keyVotant).keySet()) {
+
+ // Victoires pour le votant + application du poids du votant
+ Double v = getVictories(keyVotant, keyChoice, votes)
+ .doubleValue();
+ if (byGroup) {
+ v *= getGroupWeight(choices, keyVotant);
+ } else {
+ v *= getPersonWeight(choices, keyVotant);
+ }
+
+ victories.put(keyChoice, victories.get(keyChoice) + v);
+ }
+ }
+ }
+
+ /**
+ * Calcul du nombre de duels gagnés par un choix par rapport aux autres
+ * choix d'un votant (personne ou groupe).
+ *
+ * @param id L'identifiant du votant
+ * @param choice Le choix de référence pour le calcul
+ * @param votes Les votes de chaque votant.
+ * @return Le nombre de duels gagnés
+ */
+ private Integer getVictories(String id, Choice choice,
+ Map<String, Map<Choice, Double>> votes) {
+ int res = 0; // résultat : nombre de victoires
+
+ Double ref = votes.get(id).get(choice); // valeur de référence
+ Double val; // valeur courante
+
+ for (Choice keyChoice : victories.keySet()) {
+ if (votes.get(id).containsKey(keyChoice)) {
+ val = votes.get(id).get(keyChoice);
+ if (ref < val) {
+ res++;
+ }
+ } else { // val == null (choix non renseigné par le votant)
+ res++;
+ }
+ }
+ return res;
+ }
+
+ /**
+ * Transformation des victoires en votes. Les victoires listent le nombre de
+ * duels gagnés pour chaque choix alors que les votes donnent leur
+ * classement.
+ *
+ * @param victories Les victoires.
+ * @return Les votes.
+ */
+ private Map<Choice, Double> victories2votes(Map<Choice, Double> victories) {
+ Map<Choice, Double> victories_ = new HashMap<Choice, Double>(victories);
+ Map<Choice, Double> votes_ = new HashMap<Choice, Double>();
+
+ Integer d = 1;
+ Map<Choice, Double> victoriesMax = getMax(victories_);
+ while (!victoriesMax.isEmpty()) {
+ for (Choice choice : victoriesMax.keySet()) {
+ votes_.put(choice, d.doubleValue());
+ victories_.remove(choice);
+ }
+ d++;
+ victoriesMax = getMax(victories_);
+ }
+
+ return votes_;
+ }
+
+ /**
+ * Retourne le ou les couples choix-valeur de valeur maxmimale.
+ *
+ * @param victories Les victoires.
+ * @return Le ou les choix de valeur maximale.
+ */
+ private Map<Choice, Double> getMax(Map<Choice, Double> victories) {
+ Map<Choice, Double> result = new HashMap<Choice, Double>();
+ if (victories.isEmpty()) {
+ return result;
+ }
+
+ TreeSet<Double> treeVictories = new TreeSet<Double>(victories.values());
+ Double max = treeVictories.last();
+ for (Choice choice : victories.keySet()) {
+ if (victories.get(choice).equals(max)) {
+ result.put(choice, victories.get(choice));
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Récupération du poids d'une personne.
+ *
+ * @param choices Les choix utilisés pour le dépouillement.
+ * @param id L'identifiant de la personne.
+ * @return Le poids de la personne.
+ */
+ private Double getPersonWeight(List<Choice> choices, String id) {
+ for (Choice choice : choices) {
+ for (Group group : choice.getGroups()) {
+ for (Vote vote : group.getVotes()) {
+ if (id.equals(vote.getVotingID())) {
+ return vote.getWeight();
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Récupération du poids d'un groupe.
+ *
+ * @param choices Les choix utilisés pour le dépouillement.
+ * @param id L'identifiant du groupe.
+ * @return Le poids du groupe.
+ */
+ private Double getGroupWeight(List<Choice> choices, String id) {
+ for (Choice choice : choices) {
+ for (Group group : choice.getGroups()) {
+ if (id.equals(group.getIdGroup())) {
+ return group.getWeight();
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Mise à jour des valeurs des choix.
+ *
+ * @param choices Les choix utilisés pour le dépouillement.
+ */
+ private void updateChoices(List<Choice> choices) {
+ for (Choice choice : choices) {
+ choice.setValue(victories.get(choice));
+ /*for (Group group : choice.getGroups()) {
+ group.setValue(victories.get(choice));
+ }*/
+ }
+ }
+
+ @Override
+ public void executeStats(List<Choice> choices, boolean groupCounting,
+ Choice choice, PollVoteCountingChoice choiceDTO) {
+ List<PercentageBehavior> list = new ArrayList<PercentageBehavior>(choices);
+ choiceDTO.setPercentage(VoteCountingUtils.calculatePercentage(choice, list));
+ }
+}
\ No newline at end of file
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/NumberVoteCountingStrategy.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/NumberMethod.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/NumberVoteCountingStrategy.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/NumberVoteCountingStrategy.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,97 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.strategy;
+
+import org.chorem.poll.domain.poll.PollVoteCountingChoice;
+import org.chorem.poll.domain.vote.Choice;
+import org.chorem.poll.domain.vote.Group;
+import org.chorem.poll.domain.vote.Vote;
+
+import java.util.List;
+
+/**
+ * Méthode de dépouillement pour vote de type number.
+ *
+ * @version $Revision$ $Date$
+ * @since 1.2.2
+ */
+public class NumberVoteCountingStrategy implements VoteCountingStrategy {
+
+ /** Permet de rajouter des choix cachés */
+ public static final String HIDDEN_PREFIX = "HIDDEN_";
+
+ @Override
+ public void executeCounting(List<Choice> choices, boolean byGroup) {
+
+ for (Choice choice : choices) {
+ double totalChoice = 0.;
+
+ for (Group group : choice.getGroups()) {
+ double totalGroup = 0.;
+
+ for (Vote vote : group.getVotes()) {
+ double value = vote.getValue();
+
+ if (value >= 0) {
+ if (byGroup) {
+ totalGroup += vote.getValue() * vote.getWeight() * group.getWeight();
+ } else {
+ totalGroup += vote.getValue() * vote.getWeight();
+ }
+ }
+ }
+
+ group.setValue(totalGroup);
+ totalChoice += totalGroup;
+ }
+
+ choice.setValue(totalChoice);
+ }
+ }
+
+ @Override
+ public void executeStats(List<Choice> choices, boolean groupCounting,
+ Choice choice, PollVoteCountingChoice choiceDTO) {
+
+ int nbBlankVotes = 0;
+ double average = 0;
+ int nbVotes = 0;
+
+ for (Group group : choice.getGroups()) {
+ for (Vote vote : group.getVotes()) {
+ nbVotes = nbVotes + 1;
+ if (vote.getValue() < 0) {
+ nbBlankVotes = nbBlankVotes + 1;
+ }
+ }
+ }
+
+ if (nbVotes - nbBlankVotes > 0) {
+ average = choice.value() / (nbVotes - nbBlankVotes);
+ }
+
+ choiceDTO.setAverage(average);
+ choiceDTO.setNbBlankVotes(nbBlankVotes);
+ }
+}
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/PercentageVoteCountingStrategy.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/PercentageMethod.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/PercentageVoteCountingStrategy.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/PercentageVoteCountingStrategy.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,52 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.strategy;
+
+import org.chorem.poll.domain.vote.Choice;
+
+import java.util.List;
+
+/**
+ * Méthode de dépouillement par pourcentage (pondération des choix). Cette
+ * méthode étend la méthode standard en ajoutant la pondération des choix.
+ *
+ * @author rannou
+ * @version $Id$
+ */
+
+public class PercentageVoteCountingStrategy extends StandardVoteCountingStrategy {
+
+ @Override
+ public double getValueForChoiceByGroup(Choice choice, String idGroup,
+ List<String> choicesId) {
+ for (String idChoice : choicesId) {
+ if (choice.getIdChoice().equals(idChoice)) {
+ return choice.getGroup(idGroup).getValue()
+ * choice.getGroup(idGroup).getWeight(); // choice.getGroup(idGroup).getValue() remplace 1
+
+ }
+ }
+ return 0;
+ }
+}
\ No newline at end of file
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategy.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/StandardMethod.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategy.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategy.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,132 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.strategy;
+
+import org.chorem.poll.domain.VoteCountingUtils;
+import org.chorem.poll.domain.poll.PollVoteCountingChoice;
+import org.chorem.poll.domain.vote.Choice;
+import org.chorem.poll.domain.vote.Group;
+import org.chorem.poll.domain.vote.PercentageBehavior;
+import org.chorem.poll.domain.vote.Vote;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Méthode de dépouillement standard.
+ *
+ * @version $Id$
+ */
+public class StandardVoteCountingStrategy implements VoteCountingStrategy {
+
+ @Override
+ public void executeCounting(List<Choice> choices, boolean byGroup) {
+ calculateGroups(choices);
+ if (byGroup) {
+ calculateChoicesByGroup(choices);
+ }
+ }
+
+ // Pre traitement de la valeur des groupes + totalChoice (tout le monde)
+ public void calculateGroups(List<Choice> choices) {
+ for (Choice choice : choices) {
+ double totalChoice = 0.;
+ for (Group group : choice.getGroups()) {
+ this.getValueForGroup(group);
+ totalChoice += group.getValue();
+ }
+ choice.setValue(totalChoice);
+ }
+ }
+
+ public void getValueForGroup(Group group) {
+ double total = 0.;
+ for (Vote vote : group.getVotes()) {
+ total += vote.getValue() * vote.getWeight();
+ }
+ group.setValue(total);
+ }
+
+ // Calcul avec prise en compte des groupes
+ public void calculateChoicesByGroup(List<Choice> choices) {
+ Map<String, List<String>> mapGroupsChoosenChoices = this
+ .getChoosenChoicesByGroup(choices);
+
+ for (Choice choice : choices) {
+ double totalChoice = 0.;
+ for (String idGroup : mapGroupsChoosenChoices.keySet()) {
+ totalChoice += this.getValueForChoiceByGroup(choice, idGroup,
+ mapGroupsChoosenChoices.get(idGroup));
+ }
+ choice.setValue(totalChoice);
+ }
+ }
+
+ // Récupération du choix de chaque groupe (plusieurs choix si égalité)
+ public Map<String, List<String>> getChoosenChoicesByGroup(
+ List<Choice> choices) {
+ Map<String, List<String>> mapGroupsChoosenChoices = new HashMap<String, List<String>>();
+
+ if (choices != null && choices.size() > 0) {
+ for (Group group : choices.get(0).getGroups()) {
+ double maxValue = 0.;
+ List<String> choosenChoicesId = new ArrayList<String>();
+
+ for (Choice choice : choices) {
+ Group curr = choice.getGroup(group.getIdGroup());
+ if (curr.getValue() > maxValue) {
+ maxValue = curr.getValue();
+ choosenChoicesId.clear();
+ }
+ if (curr.getValue() != 0 && maxValue == curr.getValue()) {
+ choosenChoicesId.add(choice.getIdChoice());
+ }
+ }
+
+ mapGroupsChoosenChoices.put(group.getIdGroup(), choosenChoicesId);
+ }
+ }
+
+ return mapGroupsChoosenChoices;
+ }
+
+ public double getValueForChoiceByGroup(Choice choice, String idGroup,
+ List<String> choicesId) {
+ for (String idChoice : choicesId) {
+ if (choice.getIdChoice().equals(idChoice)) {
+ return 1 * choice.getGroup(idGroup).getWeight(); // 1 a remplacer suivant l'algo
+ }
+ }
+ return 0;
+ }
+
+ @Override
+ public void executeStats(List<Choice> choices, boolean groupCounting,
+ Choice choice, PollVoteCountingChoice choiceDTO) {
+ List<PercentageBehavior> list = new ArrayList<PercentageBehavior>(choices);
+ choiceDTO.setPercentage(VoteCountingUtils.calculatePercentage(choice, list));
+ }
+}
\ No newline at end of file
Property changes on: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategy.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/VoteCountingStrategy.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/VoteCountingStrategy.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/strategy/VoteCountingStrategy.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,37 @@
+package org.chorem.poll.domain.strategy;
+
+import org.chorem.poll.domain.poll.PollVoteCountingChoice;
+import org.chorem.poll.domain.vote.Choice;
+
+import java.util.List;
+
+/**
+ * Contract of a strategy of a vote countig.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public interface VoteCountingStrategy {
+
+ /**
+ * Execute le dépouillement de l'ensemble des choix spécifiés.
+ *
+ * @param pollchoices les choix à dépouiller
+ * @param groupCounting si le dépouillement doit être groupé
+ */
+ public void executeCounting(List<Choice> pollchoices, boolean groupCounting);
+
+ /**
+ * Effectue des statistiques sur le <code>choice</code> specifié.
+ *
+ * La fonction <code>executeCounting</code> doit avoir été
+ * executée avant d'appeler cette fonction.
+ *
+ * @param choices l'ensemble des choix du dépouillement
+ * @param groupCounting si le dépouillement doit être groupé
+ * @param choice le choix sur lequel effectuer des statistiques
+ * @param choiceDTO le choix contenant les resultats statistiques
+ */
+ public void executeStats(List<Choice> choices, boolean groupCounting,
+ Choice choice, PollVoteCountingChoice choiceDTO);
+}
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Choice.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/Choice.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Choice.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Choice.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,157 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.vote;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Cette classe décrit le choix d'un sondage. Sa valeur sera modifiée au moment
+ * de l'exécution de la méthode de dépouillement.
+ *
+ * @author fdesbois
+ * @version $Id$
+ */
+public class Choice implements Iterable<Group>, PercentageBehavior {
+ /** identifiant du choix */
+ private String idChoice;
+
+ /** nom du choix */
+ private String name;
+
+ /** valeur du choix déterminé par le dépouillement */
+ private double value;
+
+ /** Map des groupes liés au choix */
+ private List<Group> groups;
+
+ /**
+ * Constructeur
+ *
+ * @param id : identifiant du choix
+ */
+ public Choice(String id) {
+ this.idChoice = id;
+ this.groups = new ArrayList<Group>();
+ this.value = 0.;
+ }
+
+ /**
+ * Constructeur
+ *
+ * @param id : identifiant du choix
+ * @param name : nom du choix
+ */
+ public Choice(String id, String name) {
+ this(id);
+ this.name = name;
+ }
+
+ /**
+ * setValue : Mise à jour de la valeur du choix
+ *
+ * @param value : nouvelle valeur
+ */
+ public void setValue(double value) {
+ this.value = value;
+ }
+
+ /**
+ * getValue : Renvoie la valeur du choix
+ *
+ * @return valeur courante du choix
+ */
+ public double getValue() {
+ return this.value;
+ }
+
+ /**
+ * getId : Renvoie l'identifiant du choix
+ *
+ * @return identifiant du choix
+ */
+ public String getIdChoice() {
+ return this.idChoice;
+ }
+
+ /**
+ * getName : Renvoie le nom du choix
+ *
+ * @return nom du choix
+ */
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * getGroups : Renvoie la map des groupes
+ *
+ * @return map des groupes pour ce choix
+ */
+ public List<Group> getGroups() {
+ return this.groups;
+ }
+
+ /**
+ * addGroup : Ajout d'un groupe lié au choix
+ *
+ * @param weight : poids du groupe dans le sondage
+ * @param idGroup : identifiant du groupe
+ */
+ public void addGroup(String idGroup, double weight) {
+ this.groups.add(new Group(idGroup, weight));
+ }
+
+ /**
+ * getGroup : Renvoie un groupe existant dans la map
+ *
+ * @param idGroup : identifiant du groupe dans la map
+ * @return le groupe ayant l'identifiant idGroup
+ */
+ public Group getGroup(String idGroup) {
+ for (Group g : this.groups) {
+ if (g.getIdGroup().equals(idGroup)) {
+ return g;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public double value() {
+ return getValue();
+ }
+
+
+ @Override
+ public Iterator<Group> iterator() {
+ return groups.iterator();
+ }
+
+ @Override
+ public String toString() {
+ return "Choice id=" + idChoice + " _ value=" + value;
+ }
+}
\ No newline at end of file
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Group.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/Group.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Group.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Group.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,122 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.vote;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Cette classe décrit un groupe du sondage. Sa valeur dépend du choix et sera
+ * calculée au moment du dépouillement.
+ *
+ * @author fdesbois
+ * @version $Id$
+ */
+public class Group implements Iterable<Vote> {
+ /** Identifiant du groupe */
+ private String idGroup;
+
+ /** Poids du groupe */
+ private double weight;
+
+ /** Valeur du groupe pour le choix dans lequel il appartient */
+ private double value;
+
+ /** Liste des votes liés au groupe */
+ private List<Vote> votes;
+
+ /**
+ * Constructeur
+ *
+ * @param id : identifiant du groupe
+ * @param weight : poids du groupe
+ */
+ public Group(String id, double weight) {
+ this.idGroup = id;
+ this.weight = weight;
+ this.value = 0.;
+ this.votes = new ArrayList<Vote>();
+ }
+
+ /**
+ * getIdGroup : Identifiant du groupe
+ *
+ * @return identifiant du groupe
+ */
+ public String getIdGroup() {
+ return this.idGroup;
+ }
+
+ /**
+ * getWeight : Renvoie le poids du groupe
+ *
+ * @return poids du groupe
+ */
+ public double getWeight() {
+ return this.weight;
+ }
+
+ /**
+ * setValue : Mise à jour de la valeur du groupe
+ *
+ * @param value : nouvelle valeur du groupe
+ */
+ public void setValue(double value) {
+ this.value = value;
+ }
+
+ /**
+ * getValue : Renvoie la valeur du groupe pour le choix auquel il appartient
+ *
+ * @return la valeur du groupe
+ */
+ public double getValue() {
+ return this.value;
+ }
+
+ /**
+ * getVotes : Renvoie la liste des votes liés au groupe
+ *
+ * @return liste des votes
+ */
+ public List<Vote> getVotes() {
+ return this.votes;
+ }
+
+ /**
+ * addVote : Ajout d'un nouveau vote au groupe
+ *
+ * @param value : valeur du vote
+ * @param weight : poids du vote
+ */
+ public void addVote(double value, double weight, String votingID) {
+ this.votes.add(new Vote(value, weight, votingID));
+ }
+
+ @Override
+ public Iterator<Vote> iterator() {
+ return votes.iterator();
+ }
+}
\ No newline at end of file
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/PercentageBehavior.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/utils/PercentageBehavior.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/PercentageBehavior.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/PercentageBehavior.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,33 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.vote;
+
+/**
+ * Interface pour le comportement pourcentage.
+ *
+ * @version $Id$
+ */
+public interface PercentageBehavior {
+ public double value();
+}
\ No newline at end of file
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Vote.java (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/business/Vote.java)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Vote.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/java/org/chorem/poll/domain/vote/Vote.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,82 @@
+/*
+ * #%L
+ * Pollen :: Vote Counting
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2012 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package org.chorem.poll.domain.vote;
+
+/**
+ * Cette classe décrit un vote du sondage. Le vote récupère l'id et le poids du
+ * votant.
+ *
+ * @author fdesbois
+ * @version $Id$
+ */
+public class Vote {
+ /** Valeur du vote (ex : 1, 2, 3 pour condorcet ou 15 pour pourcentage) */
+ private double value;
+
+ /** Poids du vote dans le sondage */
+ private double weight;
+
+ /** Identifiant du votant */
+ private String votingID;
+
+ /**
+ * Constructeur
+ *
+ * @param value : valeur du vote connue pour le choix
+ * @param weight : poids du vote
+ * @param votingID : identifiant du votant
+ */
+ public Vote(double value, double weight, String votingID) {
+ this.value = value;
+ this.weight = weight;
+ this.votingID = votingID;
+ }
+
+ /**
+ * getValue : Renvoie la valeur du vote
+ *
+ * @return valeur du vote
+ */
+ public double getValue() {
+ return this.value;
+ }
+
+ /**
+ * getWeight : Renvoie le poids du vote
+ *
+ * @return poids du vote
+ */
+ public double getWeight() {
+ return this.weight;
+ }
+
+ /**
+ * getVotingID : Renvoie l'identifiant du votant
+ *
+ * @return identifiant du votant
+ */
+ public String getVotingID() {
+ return this.votingID;
+ }
+}
\ No newline at end of file
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_en_GB.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_en_GB.properties (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_en_GB.properties 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,10 @@
+pollen.choiceType.date=Date
+pollen.choiceType.image=Image
+pollen.choiceType.text=Text
+pollen.pollType.free=Free
+pollen.pollType.group=Group
+pollen.pollType.restricted=Restricted
+pollen.voteCountingType.condorcet=Condorcet
+pollen.voteCountingType.normal=Normal
+pollen.voteCountingType.number=Number
+pollen.voteCountingType.percentage=Percentage
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_fr_FR.properties
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_fr_FR.properties (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/main/resources/i18n/pollen-domain_fr_FR.properties 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,10 @@
+pollen.choiceType.date=Date
+pollen.choiceType.image=Image
+pollen.choiceType.text=Texte
+pollen.pollType.free=Libre
+pollen.pollType.group=Groupe
+pollen.pollType.restricted=Restreint
+pollen.voteCountingType.condorcet=Condorcet
+pollen.voteCountingType.normal=Normal
+pollen.voteCountingType.number=Nombre
+pollen.voteCountingType.percentage=Pourcentage
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/ImportExportServiceTest.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/ImportExportServiceTest.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/ImportExportServiceTest.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,22 @@
+package org.chorem.poll.domain;
+
+import org.junit.Test;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class ImportExportServiceTest {
+
+ @Test
+ public void exportToXml() throws Exception {
+
+ }
+
+ @Test
+ public void importFromXml() throws Exception {
+
+ }
+}
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/VoteCountingServiceTest.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/VoteCountingServiceTest.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/VoteCountingServiceTest.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,21 @@
+package org.chorem.poll.domain;
+
+import org.junit.Test;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class VoteCountingServiceTest {
+ @Test
+ public void executeVoteCounting() throws Exception {
+
+ }
+
+ @Test
+ public void executeGroupCounting() throws Exception {
+
+ }
+}
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/CondorcetVoteCountingStrategyTest.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/CondorcetVoteCountingStrategyTest.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/CondorcetVoteCountingStrategyTest.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,22 @@
+package org.chorem.poll.domain.strategy;
+
+import org.junit.Test;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class CondorcetVoteCountingStrategyTest {
+
+ @Test
+ public void executeCounting() throws Exception {
+
+ }
+
+ @Test
+ public void executeStats() throws Exception {
+
+ }
+}
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/NumberVoteCountingStrategyTest.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/NumberVoteCountingStrategyTest.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/NumberVoteCountingStrategyTest.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,22 @@
+package org.chorem.poll.domain.strategy;
+
+import org.junit.Test;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class NumberVoteCountingStrategyTest {
+
+ @Test
+ public void executeCounting() throws Exception {
+
+ }
+
+ @Test
+ public void executeStats() throws Exception {
+
+ }
+}
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/PercentageVoteCountingStrategyTest.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/PercentageVoteCountingStrategyTest.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/PercentageVoteCountingStrategyTest.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,22 @@
+package org.chorem.poll.domain.strategy;
+
+import org.junit.Test;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class PercentageVoteCountingStrategyTest {
+
+ @Test
+ public void executeCounting() throws Exception {
+
+ }
+
+ @Test
+ public void executeStats() throws Exception {
+
+ }
+}
Added: branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategyTest.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategyTest.java (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/test/java/org/chorem/poll/domain/strategy/StandardVoteCountingStrategyTest.java 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,22 @@
+package org.chorem.poll.domain.strategy;
+
+import org.junit.Test;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.2.6
+ */
+public class StandardVoteCountingStrategyTest {
+
+ @Test
+ public void executeCounting() throws Exception {
+
+ }
+
+ @Test
+ public void executeStats() throws Exception {
+
+ }
+}
Copied: branches/pollen-1.2.6-struts2/pollen-domain/src/test/resources/log4j.properties (from rev 3173, branches/pollen-1.2.6-struts2/pollen-votecounting/src/main/resources/log4j.properties)
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-domain/src/test/resources/log4j.properties (rev 0)
+++ branches/pollen-1.2.6-struts2/pollen-domain/src/test/resources/log4j.properties 2012-03-12 08:37:14 UTC (rev 3174)
@@ -0,0 +1,8 @@
+# Global logging configuration
+log4j.rootLogger=WARN, stdout
+# Console output...
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d %5p [%t] (%F:%L) %M - %m%n
+# package level
+log4j.logger.org.chorem.pollen=INFO
1
0
r3173 - in branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main: java/org/chorem/pollen/ui/actions/poll resources/config webapp/WEB-INF/jsp
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:50 +0100 (Thu, 08 Mar 2012)
New Revision: 3173
Url: http://chorem.org/repositories/revision/pollen/3173
Log:
export is working + use service api
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/ExportPoll.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/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/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-08 00:20:21 UTC (rev 3172)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-03-08 00:20:50 UTC (rev 3173)
@@ -92,8 +92,6 @@
private PollAccount pollAccount;
-// private String pollAccountId;
-
private List<PollResult> results;
private List<Comment> comments;
@@ -253,18 +251,13 @@
comments = service.getAllComments(poll.getPollId());
}
- protected void loadPollResults() {
+ protected void loadPollResults() throws PollNotFoundException {
PollResultsService service = getPollResultsService();
- PollResultList resultListDTO;
- if (isGroupPoll()) {
- resultListDTO = service.getGroupResults(poll.getPollId());
- } else {
- resultListDTO = service.getNormalResults(poll.getPollId());
- }
+ PollResultList pollResultList = service.getResults(poll.getPollId());
- results = resultListDTO.getPollResults();
+ results = pollResultList.getPollResults();
if (log.isDebugEnabled()) {
for (PollResult res : results) {
@@ -425,8 +418,6 @@
protected void loadPoll() throws PollNotFoundException {
-// Preconditions.checkNotNull(pollId);
-
PollService service = newService(PollService.class);
if (StringUtils.isNotEmpty(pollId)) {
Modified: 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/ExportPoll.java 2012-03-08 00:20:21 UTC (rev 3172)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ExportPoll.java 2012-03-08 00:20:50 UTC (rev 3173)
@@ -23,8 +23,12 @@
*/
package org.chorem.pollen.ui.actions.poll;
-import org.chorem.pollen.ui.actions.PollenActionSupport;
+import com.google.common.base.Preconditions;
+import org.apache.commons.io.IOUtils;
+import org.chorem.pollen.services.impl.PollResultsService;
+import java.io.InputStream;
+
/**
* Exports an existing poll.
*
@@ -34,4 +38,40 @@
public class ExportPoll extends AbstractPollUriIdAction {
private static final long serialVersionUID = 1L;
+
+ protected String filename;
+
+ protected long contentLength;
+
+ protected transient InputStream inputStream;
+
+ public long getContentLength() {
+ return contentLength;
+ }
+
+ public InputStream getInputStream() {
+ return inputStream;
+ }
+
+ public String getFilename() {
+ return filename;
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ Preconditions.checkNotNull(pollId);
+
+ PollResultsService service = newService(PollResultsService.class);
+
+ String exportContent = service.exportPolltoXml(pollId);
+
+ filename = "exportPoll-" + pollId + ".xml";
+
+ contentLength = exportContent.length() * 2;
+
+ inputStream = IOUtils.toInputStream(exportContent);
+
+ return SUCCESS;
+ }
}
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-08 00:20:21 UTC (rev 3172)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/ResultForPoll.java 2012-03-08 00:20:50 UTC (rev 3173)
@@ -41,6 +41,7 @@
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.common.VoteCountingType;
+import org.chorem.pollen.services.exceptions.PollNotFoundException;
import org.chorem.pollen.services.impl.PollResultsService;
import org.chorem.pollen.services.impl.PollService;
import org.nuiton.util.StringUtil;
@@ -246,17 +247,12 @@
this.byGroup = byGroup;
}
- protected void loadResults() {
+ protected void loadResults() throws PollNotFoundException {
- PollResultsService pollResultService =
- newService(PollResultsService.class);
+ PollResultsService service = newService(PollResultsService.class);
- PollResultList resultListDTO;
- if (byGroup) {
- resultListDTO = pollResultService.getGroupResults(poll.getPollId());
- } else {
- resultListDTO = pollResultService.getNormalResults(poll.getPollId());
- }
+ PollResultList resultListDTO =
+ service.getResults(poll.getPollId());
results = resultListDTO.getPollResults();
@@ -276,13 +272,13 @@
// sous-titres des vrais choix (les choix pas cachés)
subtitles = ArrayListMultimap.create();
- results = pollResultService.createNumberVoteCountingResult(
+ results = service.createNumberVoteCountingResult(
resultListDTO,
choicesResults,
subtitles);
}
- topRanking = pollResultService.getTopRanking(results);
+ topRanking = service.getTopRanking(results);
if (log.isInfoEnabled()) {
log.info("topRanking = " + topRanking);
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-08 00:20:21 UTC (rev 3172)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/config/struts-poll.xml 2012-03-08 00:20:50 UTC (rev 3173)
@@ -100,8 +100,13 @@
<action name="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>
+ <result type="stream">
+ <param name="contentCharSet">UTF-8</param>
+ <param name="contentType">application/xml</param>
+ <param name="contentDisposition">attachment;filename="${filename}"</param>
+ <param name="encode">true</param>
+ <param name="bufferSize">4096</param>
+ </result>
</action>
<!-- close poll -->
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-08 00:20:21 UTC (rev 3172)
+++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/pollListHelper.jsp 2012-03-08 00:20:50 UTC (rev 3173)
@@ -45,7 +45,7 @@
<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"/>
<s:url id='exportImg' value='/img/export.png'/>
<s:set id='exportTitle'><s:text name="pollen.action.pollExport"/></s:set>
1
0
r3172 - branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl
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:21 +0100 (Thu, 08 Mar 2012)
New Revision: 3172
Url: http://chorem.org/repositories/revision/pollen/3172
Log:
continue to clean
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/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/PreventRuleService.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/java/org/chorem/pollen/services/impl/VoteService.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-08 00:20:00 UTC (rev 3171)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollCommentService.java 2012-03-08 00:20:21 UTC (rev 3172)
@@ -76,7 +76,7 @@
// add it to poll
pollToUpdate.addComment(commentCreated);
- commitTransaction("Could not create comment "+comment.getText());
+ commitTransaction("Could not create comment " + comment.getText());
// feed notification
@@ -109,7 +109,7 @@
//FIXME Should we also delete the associated pollAccount ?
dao.delete(comment);
- commitTransaction("Could not delete comment "+comment.getText());
+ 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/PollResultsService.java
===================================================================
--- branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java 2012-03-08 00:20:00 UTC (rev 3171)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollResultsService.java 2012-03-08 00:20:21 UTC (rev 3172)
@@ -29,25 +29,32 @@
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.PollenFunctions;
import org.chorem.pollen.bean.PollResult;
import org.chorem.pollen.bean.PollResultList;
import org.chorem.pollen.business.persistence.Choice;
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.Result;
import org.chorem.pollen.business.persistence.ResultDAO;
+import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.common.VoteCountingType;
import org.chorem.pollen.services.PollenServiceSupport;
+import org.chorem.pollen.services.exceptions.PollNotFoundException;
import org.chorem.pollen.votecounting.business.NumberMethod;
import org.chorem.pollen.votecounting.dto.ChoiceDTO;
import org.chorem.pollen.votecounting.dto.PollDTO;
+import org.chorem.pollen.votecounting.dto.PollExportDTO;
import org.chorem.pollen.votecounting.dto.VoteCountingResultDTO;
-import org.chorem.pollen.votecounting.services.ServiceVoteCounting;
-import org.chorem.pollen.votecounting.services.ServiceVoteCountingImpl;
+import org.chorem.pollen.votecounting.services.ImportExportService;
+import org.chorem.pollen.votecounting.services.VoteCountingService;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
+import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
@@ -65,32 +72,38 @@
/** log. */
private static final Log log = LogFactory.getLog(PollResultsService.class);
- public PollResultList getGroupResults(String pollId) {
- return generateResults(pollId, null, true, true);
- }
+ public PollResultList getResults(String pollId) throws PollNotFoundException {
- public PollResultList getNormalResults(String pollId) {
- return generateResults(pollId, null, true, false);
+ PollService pollService = newService(PollService.class);
+ Poll poll = pollService.getPollByPollId(pollId);
+
+ if (poll == null) {
+ throw new PollNotFoundException();
+ }
+ PollResultList result;
+ if (poll.getPollType() == PollType.GROUP) {
+ result = generateResults(poll, null, true, true);
+ } else {
+ result = generateResults(poll, null, true, false);
+ }
+ return result;
}
/**
* Génère les résultats d'un sondage (= un dépouillement).
*
- * @param pollId le sondage
+ * @param poll le sondage
* @param voteCounting type de dépouillement
* @param byGroup résultats par groupe
* @param groupOnly résultats uniquement par groupe
* @return les résultats du sondage
*/
- private PollResultList generateResults(String pollId,
+ private PollResultList generateResults(Poll poll,
VoteCountingType voteCounting,
boolean byGroup,
boolean groupOnly) {
- PollService pollService = newService(PollService.class);
- Poll poll = pollService.getPollByPollId(pollId);
-// DataResultConverter converter = new DataResultConverter(transaction);
if (log.isDebugEnabled()) {
log.debug(poll.getPollId() + " (" + voteCounting
+ ") has results: " + hasResults(poll, voteCounting));
@@ -99,7 +112,7 @@
// Dépouillement du sondage.
// S'il n'existe pas de résultats ou si le sondage est encore ouvert.
//if (!hasResults(ePoll, voteCounting) || !ePoll.getIsClosed()) {
- PollDTO dto = pollService.createPollDTOForVoteCounting(poll);
+ PollDTO dto = PollenFunctions.POLL_TO_BEAN.apply(poll);
if (voteCounting != null) {
dto.setVoteCounting(voteCounting);
@@ -108,15 +121,10 @@
// clear result (they will be regenerated ! (a big shame))
poll.clearResult();
- ServiceVoteCounting service = new ServiceVoteCountingImpl();
+ VoteCountingService service = new VoteCountingService();
- VoteCountingResultDTO result;
+ VoteCountingResultDTO result = service.execute(dto);
- if (PollType.GROUP == poll.getPollType()) {
- result = service.executeGroupCounting(dto);
- } else {
- result = service.executeVoteCounting(dto);
- }
ResultDAO daoResult = getDAO(Result.class);
for (ChoiceDTO choice : result.getChoices()) {
@@ -178,6 +186,47 @@
return resultList;
}
+ public String exportPolltoXml(String pollId) throws PollNotFoundException {
+
+ // Recherche du sondage
+
+ PollService pollService = newService(PollService.class);
+
+ Poll poll = pollService.getPollByPollId(pollId);
+
+ if (poll == null) {
+ throw new PollNotFoundException();
+ }
+
+ PollDTO dto = PollenFunctions.POLL_TO_BEAN.apply(poll);
+
+ VoteCountingService service = new VoteCountingService();
+
+ List<VoteCountingResultDTO> results = Lists.newArrayList();
+
+ VoteCountingResultDTO result = service.executeVoteCounting(dto);
+
+ results.add(result);
+
+ if (poll.getPollType() == PollType.GROUP) {
+ VoteCountingResultDTO groupResult =
+ service.executeGroupCounting(dto);
+ results.add(groupResult);
+ }
+
+ // Transformation du sondage
+ PollExportDTO pollExport = new PollExportDTO();
+ pollExport.setPollId(dto.getPollId());
+ pollExport.setPoll(dto);
+ pollExport.setVoteCountingResults(results);
+
+ // Export du sondage
+ ImportExportService serviceExport = new ImportExportService();
+ String content = serviceExport.exportToXml(pollExport);
+
+ return content;
+ }
+
/**
* Retourne la liste des résultats d'un sondage sous forme de DTOs.
*
@@ -203,7 +252,8 @@
return results;
}
- public String getResultValue(Choice choice, Collection<PollResult> results) {
+ public String getResultValue(Choice choice,
+ Collection<PollResult> results) {
String val = "";
for (PollResult result : results) {
@@ -215,9 +265,10 @@
return val;
}
- public List<PollResult> createNumberVoteCountingResult(PollResultList resultListDTO,
- Multimap<String, String> choicesResults,
- Multimap<String, String> subtitles) {
+ public List<PollResult> createNumberVoteCountingResult(
+ PollResultList resultListDTO,
+ Multimap<String, String> choicesResults,
+ Multimap<String, String> subtitles) {
Preconditions.checkNotNull(resultListDTO);
Preconditions.checkNotNull(choicesResults);
Preconditions.checkNotNull(subtitles);
@@ -347,31 +398,32 @@
return val;
}
- /**
- * Création des résultats de sondage à partir d'un dto de résultats de
- * sondage.
- *
- * @param ePoll poll à remplir
- * @param dto le dto des résultats de sondage.
- */
- protected void populateResultEntities(Poll ePoll, VoteCountingResultDTO dto) {
- for (ChoiceDTO choice : dto.getChoices()) {
+// /**
+// * Création des résultats de sondage à partir d'un dto de résultats de
+// * sondage.
+// *
+// * @param ePoll poll à remplir
+// * @param dto le dto des résultats de sondage.
+// */
+// protected void populateResultEntities(Poll ePoll,
+// VoteCountingResultDTO dto) {
+// for (ChoiceDTO choice : dto.getChoices()) {
+//
+// ResultDAO daoResult = getDAO(Result.class);
+// Result eResult = create(daoResult);
+//
+// Choice eChoice = ePoll.getChoiceByTopiaId(choice.getIdChoice());
+//
+// ePoll.addResult(eResult);
+//
+// eResult.setName(eChoice.getName());
+// eResult.setByGroup(dto.isByGroup());
+// eResult.setPoll(ePoll);
+// eResult.setResultValue(String.valueOf(choice.getValue()));
+// eResult.setVoteCountingType(dto.getTypeVoteCounting());
+// }
+// }
- ResultDAO daoResult = getDAO(Result.class);
- Result eResult = create(daoResult);
-
- Choice eChoice = ePoll.getChoiceByTopiaId(choice.getIdChoice());
-
- ePoll.addResult(eResult);
-
- eResult.setName(eChoice.getName());
- eResult.setByGroup(dto.isByGroup());
- eResult.setPoll(ePoll);
- eResult.setResultValue(String.valueOf(choice.getValue()));
- eResult.setVoteCountingType(dto.getTypeVoteCounting());
- }
- }
-
/**
* Retourne vrai si le sondage a des résultats.
*
@@ -398,166 +450,6 @@
return hasresult;
}
-// public PollResultList getAllResults(String pollId) {
-// return getResults(pollId, null, false, false);
-// }
-//
-// public PollResultList getResultsByVoteCounting(String pollId,
-// VoteCountingType voteCounting) {
-// return getResults(pollId, voteCounting, false, false);
-// }
-//
-// /**
-// * Récupère les résultats d'un sondage (sans rien dépouiller).
-// *
-// * @param pollId le sondage
-// * @param voteCounting type de dépouillement
-// * @param byGroup résultats par groupe
-// * @param groupOnly résultats uniquement par groupe
-// * @return les résultats du sondage
-// */
-// private PollResultList getResults(String pollId,
-// VoteCountingType voteCounting,
-// boolean byGroup,
-// boolean groupOnly) {
-//
-// PollService pollService = newService(PollService.class);
-// Poll poll = pollService.getPollByPollId(pollId);
-//
-//// DataResultConverter converter = new DataResultConverter(transaction);
-// if (log.isDebugEnabled()) {
-// log.debug(poll.getPollId() + " (" + voteCounting
-// + ") has results: " + hasResults(poll, voteCounting));
-// }
-//
-// // Dépouillement du sondage.
-// // S'il n'existe pas de résultats ou si le sondage est encore ouvert.
-// //if (!hasResults(ePoll, voteCounting) || !ePoll.getIsClosed()) {
-// PollDTO dto = pollService.createPollDTOForVoteCounting(poll);
-//
-// if (voteCounting != null) {
-// dto.setVoteCounting(voteCounting);
-// }
-//
-//// // clear result (they will be regenerated ! (a big shame))
-//// poll.clearResult();
-//
-//// ServiceVoteCounting service = new ServiceVoteCountingImpl();
-////
-//// VoteCountingResultDTO result;
-////
-//// if (PollType.GROUP == poll.getPollType()) {
-//// result = service.executeGroupCounting(dto);
-//// } else {
-//// result = service.executeVoteCounting(dto);
-//// }
-//// for (ChoiceDTO choice : result.getChoices()) {
-////
-//// ResultDAO daoResult = getDAO(Result.class);
-//// Result eResult = create(daoResult);
-////
-//// Choice eChoice = poll.getChoiceByTopiaId(choice.getIdChoice());
-////
-//// poll.addResult(eResult);
-////
-//// eResult.setName(eChoice.getName());
-//// eResult.setByGroup(result.isByGroup());
-//// eResult.setPoll(poll);
-//// eResult.setResultValue(String.valueOf(choice.getValue()));
-//// eResult.setVoteCountingType(result.getTypeVoteCounting());
-//// }
-//
-// // Conversion et trie des résultats
-// List<PollResult> list = createPollResults(poll);
-//
-// VoteCountingType voteCountingType = poll.getVoteCountingType();
-//
-// Iterator<PollResult> it = list.iterator();
-// while (it.hasNext()) {
-// PollResult currentResult = it.next();
-//
-// // Cas d'un dépouillement particulier
-// // Suppression des resultats qui ne sont pas de se dépouillement
-// if (voteCounting != null
-// && currentResult.getVoteCountingType() != voteCounting) {
-// it.remove();
-// }
-//
-// // Cas d'un sondage de type GROUP avec filtre
-// if (byGroup) {
-//
-// // Filtre group : Suppression resultats non group
-// if (groupOnly && !currentResult.isByGroup()) {
-// it.remove();
-// }
-//
-// // Filtre non group : Suppression resultats group
-// else if (!groupOnly && currentResult.isByGroup()) {
-// it.remove();
-// }
-//
-// // Suppression des autres resultats de depouillements differents
-// if (currentResult.getVoteCountingType() != voteCountingType) {
-// it.remove();
-// }
-// }
-// }
-//
-// PollResultList resultListDTO = new PollResultList();
-// resultListDTO.setPollResults(list);
-// resultListDTO.setVoteCountingResult(null);
-//
-// return resultListDTO;
-// }
-//
-// public String exportPoll(String pollId) {
-// TopiaContext transaction = getTransaction();
-// try {
-//
-// // Recherche du sondage
-// PollDAO daoPoll = PollenDAOHelper.getPollDAO(transaction);
-// Poll ePoll = daoPoll.findByPollId(pollId);
-//
-// // Dépouillement du sondage.
-// DataResultConverter converter = new DataResultConverter(transaction);
-// PollDTO dto = DataVoteCountingConverter
-// .createPollDTOForVoteCounting(ePoll);
-//
-// ePoll.clearResult();
-//
-// ServiceVoteCounting service = new ServiceVoteCountingImpl();
-// List<VoteCountingResultDTO> results = new ArrayList<VoteCountingResultDTO>();
-// VoteCountingResultDTO result = service.executeVoteCounting(dto);
-// converter.populateResultEntities(result);
-// results.add(result);
-//
-// if (EnumController.isGroupType(ePoll)) {
-// VoteCountingResultDTO groupResult = service
-// .executeGroupCounting(dto);
-// converter.populateResultEntities(groupResult);
-// results.add(groupResult);
-// }
-//
-// // Transformation du sondage
-// PollExportDTO pollExport = new PollExportDTO();
-// pollExport.setPollId(pollId);
-// pollExport.setPoll(dto);
-// pollExport.setVoteCountingResults(results);
-//
-// // Export du sondage
-// ServiceExport serviceExport = new ServiceExportImpl();
-// String filename = serviceExport.executeExport(pollExport);
-//
-// if (log.isInfoEnabled()) {
-// log.info("Poll exported: " + pollId);
-// }
-//
-// return filename;
-// } catch (Exception e) {
-// throw new PollenTechnicalException("Could not export results", e);
-// }
-// }
-
// public String importPoll(String filePath) {
// return importPoll(filePath, null);
// }
@@ -588,31 +480,31 @@
// return topiaId;
// }
-// /**
-// * Retourne une chaîne contenant les résultats du sondage.
-// *
-// * @param poll le sondage
-// * @param results les résultats du sondage
-// * @return les résultats sous forme de chaine de caractères
-// */
-// public String getResultsAsString(Poll poll, Collection<Result> results) {
-//
-// DateFormat dateFormat = new SimpleDateFormat();
-// StringBuilder res = new StringBuilder("");
-// Iterator<Result> it = results.iterator();
-// while (it.hasNext()) {
-// Result result = it.next();
-// if (poll.getChoiceType() == ChoiceType.DATE) {
-// Date date = new Date(Long.parseLong(result.getName()));
-// res.append(dateFormat.format(date));
-// } else {
-// res.append(result.getName());
-// }
-// res.append("=").append(removeTrailing0(result.getResultValue()));
-// if (it.hasNext()) {
-// res.append(", ");
-// }
-// }
-// return res.toString();
-// }
+ /**
+ * Retourne une chaîne contenant les résultats du sondage.
+ *
+ * @param poll le sondage
+ * @param results les résultats du sondage
+ * @return les résultats sous forme de chaine de caractères
+ */
+ public String getResultsAsString(Poll poll, Collection<Result> results) {
+
+ DateFormat dateFormat = new SimpleDateFormat();
+ StringBuilder res = new StringBuilder("");
+ Iterator<Result> it = results.iterator();
+ while (it.hasNext()) {
+ Result result = it.next();
+ if (poll.getChoiceType() == ChoiceType.DATE) {
+ Date date = new Date(Long.parseLong(result.getName()));
+ res.append(dateFormat.format(date));
+ } else {
+ res.append(result.getName());
+ }
+ res.append("=").append(removeTrailing0(result.getResultValue()));
+ if (it.hasNext()) {
+ res.append(", ");
+ }
+ }
+ return res.toString();
+ }
}
Modified: 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-08 00:20:00 UTC (rev 3171)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PollService.java 2012-03-08 00:20:21 UTC (rev 3172)
@@ -34,7 +34,6 @@
import org.chorem.pollen.bean.PollImageChoice;
import org.chorem.pollen.business.persistence.Choice;
import org.chorem.pollen.business.persistence.ChoiceDAO;
-import org.chorem.pollen.business.persistence.Comment;
import org.chorem.pollen.business.persistence.PersonToList;
import org.chorem.pollen.business.persistence.PersonToListDAO;
import org.chorem.pollen.business.persistence.Poll;
@@ -46,7 +45,6 @@
import org.chorem.pollen.business.persistence.UserAccount;
import org.chorem.pollen.business.persistence.Vote;
import org.chorem.pollen.business.persistence.VoteDAO;
-import org.chorem.pollen.business.persistence.VoteToChoice;
import org.chorem.pollen.business.persistence.VotingList;
import org.chorem.pollen.business.persistence.VotingListDAO;
import org.chorem.pollen.common.ChoiceType;
@@ -55,13 +53,6 @@
import org.chorem.pollen.services.exceptions.PollChoiceNotFoundException;
import org.chorem.pollen.services.exceptions.PollNotFoundException;
import org.chorem.pollen.services.exceptions.PollVoteNotFoundException;
-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.TopiaException;
import org.nuiton.topia.framework.TopiaQuery;
import org.nuiton.web.struts2.FilterPagerUtil;
@@ -82,11 +73,6 @@
/** 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
*
@@ -261,12 +247,13 @@
commitTransaction("Could not create poll " + poll.getTitle());
String pollVoteUrl = getPollVoteUrl(poll);
+ String pollEditUrl = getPollEditUrl(poll);
// email notification
EmailService emailService = newService(EmailService.class);
emailService.onPollCreated(poll,
pollVoteUrl,
- getPollEditUrl(poll));
+ pollEditUrl);
// feed notification
PollFeedService pollFeedService = newService(PollFeedService.class);
@@ -295,21 +282,7 @@
url.append(':').append(poll.getCreator().getAccountId());
return url.toString();
}
- /*
- private void addFeedEntry() {
- PollAccountDTO creator = servicePollAccount.findPollAccountById(poll.getCreatorId());
- String voteURL = siteURL + "poll/votefor/" + poll.getPollId();
- File feedFile = feedContext.getFile(poll.getPollId());
- FeedUtil.createFeed(feedFile, "atom_1.0", messages.format(
- "pollFeed_title", poll.getTitle()), siteURL, messages.format(
- "pollFeed_desc", poll.getDescription()));
- FeedUtil.feedFeed(feedFile, messages.format("pollFeed_createTitle",
- creator.getVotingId()), voteURL, messages
- .get("pollFeed_createContent"));
- }
- */
-
public List<Poll> getPolls(FilterPagerUtil.FilterPagerBean pager) {
Preconditions.checkNotNull(pager);
@@ -331,7 +304,8 @@
}
}
- public List<Poll> getCreatedPolls(FilterPagerUtil.FilterPagerBean pager, UserAccount user) {
+ public List<Poll> getCreatedPolls(FilterPagerUtil.FilterPagerBean pager,
+ UserAccount user) {
Preconditions.checkNotNull(pager);
Preconditions.checkNotNull(user);
@@ -354,13 +328,15 @@
}
}
- public List<Poll> getInvitedPolls(FilterPagerUtil.FilterPagerBean pager, UserAccount user) {
+ public List<Poll> getInvitedPolls(FilterPagerUtil.FilterPagerBean pager,
+ UserAccount user) {
Preconditions.checkNotNull(pager);
Preconditions.checkNotNull(user);
UserService userService = newService(UserService.class);
- UserAccount userToUse = userService.getEntityById(UserAccount.class, user.getTopiaId());
+ UserAccount userToUse = userService.getEntityById(UserAccount.class,
+ user.getTopiaId());
//FIXME Use a query to do this to avoid in memory pagination
String email = userToUse.getEmail();
@@ -423,22 +399,6 @@
UserAccount userToUse =
userService.getEntityById(UserAccount.class, user.getTopiaId());
-// List<Poll> allPolls = Lists.newArraPagerUtil.computeRecordIndexesAndPagesNumber(pager);yList();
-// for (PollAccount pollAccount : userToUse.getPollAccount()) {
-// for (Vote vote : pollAccount.getVote()) {
-// Poll poll = vote.getPoll();
-// if (!allPolls.contains(poll)) {
-// allPolls.add(poll);
-// }
-// }
-// }
-// int records = allPolls.size();
-// pager.setRecords(records);
-// PagerUtil.computeRecordIndexesAndPagesNumber(pager);
-// List<Poll> result = FilterPagerUtil.getPageFromList(allPolls, pager);
-// return result;
-
-
PollDAO pollDao = getDAO(Poll.class);
VoteDAO voteDao = getDAO(Vote.class);
@@ -454,10 +414,6 @@
TopiaQuery query = FilterPagerUtil.addPagerToQuery(countQuery, pager);
-// query.addDistinct();
-// query.setSelect("e." + Vote.PROPERTY_POLL);
-// query.addWhere("e." + Vote.PROPERTY_POLL_ACCOUNT + "." + PollAccount.PROPERTY_USER_ACCOUNT, TopiaQuery.Op.EQ, userToUse);
-
List<Poll> result = pollDao.findAllByQuery(query);
return result;
} catch (TopiaException e) {
@@ -609,111 +565,6 @@
}
}
- public PollDTO createPollDTOForVoteCounting(Poll poll) {
- PollDTO result = new PollDTO(poll.getPollId());
- result.setTitle(poll.getTitle());
- result.setDescription(poll.getDescription());
- result.setBeginChoiceDate(poll.getBeginChoiceDate());
- result.setBeginDate(poll.getBeginDate());
- result.setEndDate(poll.getEndDate());
- 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());
- result.setPollType(poll.getPollType());
- result.setChoiceType(poll.getChoiceType());
- result.setVoteCounting(poll.getVoteCountingType());
-
- for (Comment comment : poll.getComment()) {
- result.getComments().add(createPollCommentDTO(comment));
- }
- for (Choice choice : poll.getChoice()) {
- result.getChoices().add(createPollChoiceDTO(choice));
- }
- if (poll.getVotingList() != null && !poll.getVotingList().isEmpty()) {
- for (VotingList list : poll.getVotingList()) {
- result.getVotingGroups().add(createVotingGroupDTO(list));
- }
- } else {
- // un groupe par défaut si il y en a pas
- VotingGroupDTO group = new VotingGroupDTO("unique", 1);
- group.setName("unique");
- for (Vote vote : poll.getVote()) {
- group.getVotingPersons().add(createVotingPersonDTO(vote));
- }
- result.getVotingGroups().add(group);
- }
- return result;
- }
-
- private CommentDTO createPollCommentDTO(Comment comment) {
- CommentDTO commentDTO = new CommentDTO(
- comment.getPollAccount().getVotingId(), comment.getText());
- return commentDTO;
- }
-
- private PollChoiceDTO createPollChoiceDTO(Choice choice) {
- PollChoiceDTO choiceDTO = new PollChoiceDTO(choice.getTopiaId());
- String choiceName = choice.getName();
- choiceDTO.setName(choiceName);
- choiceDTO.setHidden(choiceName != null &&
- choiceName.startsWith(NumberMethod.HIDDEN_PREFIX));
- choiceDTO.setDescription(choice.getDescription());
- return choiceDTO;
- }
-
- private VotingGroupDTO createVotingGroupDTO(VotingList list) {
- VotingGroupDTO group = new VotingGroupDTO(list.getTopiaId(), list
- .getWeight());
- group.setName(list.getName());
-
- for (PersonToList pToList : list.getPollAccountPersonToList()) {
- Vote vote = getPollVoteByPollAccount(list.getPoll(), pToList
- .getPollAccount());
- if (vote != null) {
- // Pas de vote pour cette personne : doit engendrer erreur ?!?
- group.getVotingPersons().add(createVotingPersonDTO(vote));
- }
- }
- return group;
- }
-
- private VotingPersonDTO createVotingPersonDTO(Vote vote) {
- VotingPersonDTO votingPerson = new VotingPersonDTO(vote
- .getPollAccount().getVotingId(), vote.getWeight());
- votingPerson.setEmail(vote.getPollAccount().getEmail());
-
- for (VoteToChoice vToChoice : vote.getChoiceVoteToChoice()) {
- if (vToChoice != null && vToChoice.getChoice() != null) {
- votingPerson.getChoices().add(createVoteToChoiceDTO(vToChoice));
- }
- }
- return votingPerson;
- }
-
- private VoteToChoiceDTO createVoteToChoiceDTO(VoteToChoice vToChoice) {
- String topiaId = vToChoice.getChoice().getTopiaId();
- VoteToChoiceDTO vote = new VoteToChoiceDTO(topiaId, vToChoice
- .getVoteValue());
-
- return vote;
- }
-
- /* A Deplacer au bon endroit (PollImpl) si c'est possible */
- private static Vote getPollVoteByPollAccount(Poll poll, PollAccount account) {
- for (Vote vote : poll.getVote()) {
- if (account.getTopiaId().equals(vote.getPollAccount().getTopiaId())) {
- return vote;
- }
- }
- return null;
- }
-
public File getPollChoiceImageFile(String pollId,
String choiceId,
boolean thumb) {
@@ -742,9 +593,12 @@
String location = choice.getLocation();
- File pollChoiceImage = getPollChoiceImageFile(poll.getPollId(), choice.getName(), false);
- File pollChoiceImageThumb = getPollChoiceImageFile(poll.getPollId(), choice.getName(), true);
+ String pollId = poll.getPollId();
+ String name = choice.getName();
+ File pollChoiceImage = getPollChoiceImageFile(pollId, name, false);
+ File pollChoiceImageThumb = getPollChoiceImageFile(pollId, name, true);
+
FileUtils.copyFile(new File(location), pollChoiceImage);
createThumbnail(pollChoiceImage, pollChoiceImageThumb, 100);
}
Modified: 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 2012-03-08 00:20:00 UTC (rev 3171)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/PreventRuleService.java 2012-03-08 00:20:21 UTC (rev 3172)
@@ -28,7 +28,6 @@
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;
@@ -45,8 +44,7 @@
private static final Log log = LogFactory.getLog(PreventRuleService.class);
public PreventRule createAddVotePreventRule() {
- PreventRuleDAO dao = getDAO(PreventRule.class);
- PreventRule rule = newInstance(dao);
+ PreventRule rule = newInstance(getDAO(PreventRule.class));
rule.setScope("vote");
rule.setSensibility(1);
rule.setRepeated(true);
@@ -54,8 +52,7 @@
}
public PreventRule createRemindPreventRule(int sensibility) {
- PreventRuleDAO dao = getDAO(PreventRule.class);
- PreventRule rule = newInstance(dao);
+ PreventRule rule = newInstance(getDAO(PreventRule.class));
rule.setScope("rappel");
rule.setSensibility(sensibility);
rule.setRepeated(false);
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-08 00:20:00 UTC (rev 3171)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/UserService.java 2012-03-08 00:20:21 UTC (rev 3172)
@@ -44,12 +44,9 @@
import org.nuiton.util.beans.Binder;
import org.nuiton.web.struts2.FilterPagerUtil;
-import java.net.URL;
import java.util.List;
-import java.util.Locale;
import static org.nuiton.i18n.I18n._;
-import static org.nuiton.i18n.I18n.l_;
public class UserService extends PollenServiceSupport {
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-08 00:20:00 UTC (rev 3171)
+++ branches/pollen-1.2.6-struts2/pollen-services/src/main/java/org/chorem/pollen/services/impl/VoteService.java 2012-03-08 00:20:21 UTC (rev 3172)
@@ -47,114 +47,103 @@
/** Logger. */
private static final Log log = LogFactory.getLog(VoteService.class);
- public String createVote(Vote vote, PollAccount pollAccount) {
- TopiaContext transaction = getTransaction();
+ public void createVote(Vote vote, PollAccount pollAccount) {
- String topiaId;
- try {
-
- // création du compte associé au vote s'il n'existe pas
- // sinon mise à jour du compte
- //ServicePollAccount spa = new ServicePollAccountImpl();
- if (pollAccount == null) {
- vote.setPollAccount(null);
- } else {
+ // création du compte associé au vote s'il n'existe pas
+ // sinon mise à jour du compte
+ //ServicePollAccount spa = new ServicePollAccountImpl();
+ if (pollAccount == null) {
+ vote.setPollAccount(null);
+ } else {
// pollAccount.setHasVoted(true);
- PollAccountDAO pollAccountDAO =
- PollenDAOHelper.getPollAccountDAO(transaction);
+ PollAccountDAO pollAccountDAO =
+ getDAO(PollAccount.class);
- PollAccount pollAccountEntity =
- pollAccountDAO.findByTopiaId(pollAccount.getTopiaId());
+ PollAccount pollAccountEntity =
+ getEntityById(PollAccount.class, pollAccount.getTopiaId());
// PollAccountDTO account = spa.findPollAccountById(pollAccountDTO
// .getId());
- if (pollAccountEntity == null) {
- log.debug("Nouveau compte associé au vote");
- pollAccountEntity = pollAccountDAO.create();
+ if (pollAccountEntity == null) {
+ log.debug("Nouveau compte associé au vote");
+ pollAccountEntity = create(pollAccountDAO);
// voteDTO.setPollAccountId(spa
// .createPollAccount(pollAccountDTO));
- } else {
- log.debug("Compte associé au vote : " + pollAccountEntity.getTopiaId());
- //spa.updatePollAccount(pollAccountDTO);
- //voteDTO.setPollAccountId(account.getId());
+ } else {
+ log.debug("Compte associé au vote : " + pollAccountEntity.getTopiaId());
+ //spa.updatePollAccount(pollAccountDTO);
+ //voteDTO.setPollAccountId(account.getId());
- }
- // Fill pollAccountEntity from DTO in argument
+ }
+ // Fill pollAccountEntity from DTO in argument
// DataPollAccountConverter pollAccountConverter = new DataPollAccountConverter();
// pollAccountConverter.setTransaction(transaction);
// pollAccountConverter.populatePollAccountEntity(pollAccountDTO,
// pollAccountEntity);
- // Update pollAccountEntity
- pollAccountDAO.update(pollAccountEntity);
+ // Update pollAccountEntity
+// pollAccountDAO.update(pollAccountEntity);
- vote.setPollAccount(pollAccountEntity);
+ vote.setPollAccount(pollAccountEntity);
// vote.setVotingListId(pollAccount.getVotingListId());
// vote.setWeight(pollAccount.getWeight());
- log.debug("Poids du vote : " + vote.getWeight());
- }
+ log.debug("Poids du vote : " + vote.getWeight());
+ }
- VoteDAO voteDAO = PollenDAOHelper.getVoteDAO(transaction);
+ VoteDAO voteDAO = getDAO(Vote.class);
- Vote voteEntity = voteDAO.create();
+ Vote voteEntity = create(voteDAO);
// converter.setTransaction(transaction);
// converter.populateVoteEntity(vote, voteEntity);
// converter.populateChoiceVote(vote, voteEntity);
- topiaId = voteEntity.getTopiaId();
- if (log.isDebugEnabled()) {
- log.debug("Entity created: " + topiaId);
- }
-
- return topiaId;
- } catch (Exception e) {
- throw new PollenTechnicalException("Could not obtain votes", e);
+ if (log.isDebugEnabled()) {
+ log.debug("Entity created: " + voteEntity.getTopiaId());
}
+
+ commitTransaction("Could not create vote");
+
+ // email notification
+
+ // feed notification
+
+
}
- public boolean updateVote(Vote vote) {
- TopiaContext transaction = getTransaction();
- try {
+ public void updateVote(Vote vote) throws VoteNotFoundException {
- VoteDAO voteDAO = PollenDAOHelper.getVoteDAO(transaction);
- Vote voteEntity = voteDAO.findByTopiaId(vote.getTopiaId());
+ Vote entityToUpdate = getEntityById(Vote.class, vote.getTopiaId());
+
+ if (entityToUpdate == null) {
+ throw new VoteNotFoundException();
+ }
// converter.setTransaction(transaction);
// converter.populateVoteEntity(voteDTO, voteEntity);
- voteDAO.update(voteEntity);
- if (log.isDebugEnabled()) {
- log.debug("Entity updated: " + vote.getTopiaId());
- }
-
- return true;
- } catch (Exception e) {
- throw new PollenTechnicalException("Could not update vote", e);
+ if (log.isDebugEnabled()) {
+ log.debug("Entity updated: " + vote.getTopiaId());
}
+ commitTransaction("Could not update vote");
+
}
- public boolean deleteVote(String voteId) {
- TopiaContext transaction = getTransaction();
- try {
+ public void deleteVote(String voteId) throws VoteNotFoundException {
- VoteDAO voteDAO = PollenDAOHelper.getVoteDAO(transaction);
- Vote voteEntity = voteDAO.findByTopiaId(voteId);
+ Vote entityToDelete = getEntityById(Vote.class, voteId);
- if (voteEntity == null) {
- throw new VoteNotFoundException();
- }
+ if (entityToDelete == null) {
+ throw new VoteNotFoundException();
+ }
- voteDAO.delete(voteEntity);
+ delete(getDAO(Vote.class), entityToDelete);
- if (log.isDebugEnabled()) {
- log.debug("Entity deleted: " + voteId);
- }
-
- return true;
- } catch (Exception e) {
- throw new PollenTechnicalException("Could not obtain votes", e);
+ if (log.isDebugEnabled()) {
+ log.debug("Entity deleted: " + voteId);
}
+
+ commitTransaction("Could not delete vote");
}
public List<Vote> getVotesByPoll(Poll poll,
1
0
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