Pollen-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
March 2010
- 5 participants
- 71 discussions
Author: fdesbois
Date: 2010-03-20 19:42:04 +0100 (Sat, 20 Mar 2010)
New Revision: 2953
Log:
- Improve context managment : no more static. Use inject in Tapestry
- Idem in PollenConverter use as a unique service managed by PollenContext
Added:
trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContextImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContextImplementor.java
trunk/pollen-business/src/test/resources/log4j.properties
Modified:
trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContext.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenConverter.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenProperty.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollConverter.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/SendMail.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceAuthImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoiceImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceListImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccountImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePreventRuleImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceResultsImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceUserImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils/ContextUtil.java
trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestData.java
trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestManager.java
trunk/pollen-business/src/test/java/org/chorem/pollen/business/scaling/ScalingVote.java
trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/SendMailTest.java
trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceAuthImplTest.java
trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceChoiceImplTest.java
trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceListImplTest.java
trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java
trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePreventRuleImplTest.java
trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceUserImplTest.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/FeedContextLink.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ImageContextLink.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/UsersAdmin.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollModification.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/Register.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/BackgroundWorkerImpl.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PropertiesFileSymbolProvider.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContext.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContext.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContext.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -3,27 +3,13 @@
import java.util.Date;
import java.util.Properties;
-import java.util.UUID;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.business.persistence.PollenModelDAOHelper;
import org.chorem.pollen.business.services.SendMail;
-import org.chorem.pollen.business.services.ServiceUserImpl;
-import org.nuiton.i18n.I18n;
-import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaContextFactory;
-import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.TopiaNotFoundException;
import org.nuiton.util.ApplicationConfig;
-import org.nuiton.util.ArgumentsParserException;
-import static org.nuiton.i18n.I18n._;
-import static org.nuiton.i18n.I18n.n_;
-import org.nuiton.i18n.init.DefaultI18nInitializer;
/**
* PollenContext
*
- * Created: 24 févr. 2010
+ * Created: 20 mars 2010
*
* @author fdesbois
* @version $Revision$
@@ -31,45 +17,9 @@
* Mise a jour: $Date$
* par : $Author$
*/
-public class PollenContext {
+public interface PollenContext {
- /** log. */
- private static final Log log = LogFactory.getLog(PollenContext.class);
-
- public static final String DEFAULT_FILENAME = "pollen.properties";
-
- private static ApplicationConfig configuration;
-
- private static Date currentDate;
-
- private static SendMail sendMail;
-
/**
- * Default configuration file will be loaded using
- * {@link org.nuiton.util.ApplicationConfig }.
- * Then the other configuration initialization will be done in
- * {@link #loadConfiguration(ApplicationConfig)} method.
- */
- private static void loadDefaultConfiguration() {
- try {
- if (log.isInfoEnabled()) {
- log.info("load default configuration from " +
- PollenContext.DEFAULT_FILENAME);
- }
- ApplicationConfig conf = new ApplicationConfig();
- conf.setConfigFileName(PollenContext.DEFAULT_FILENAME);
- conf.parse(new String[]{});
-
- conf.printConfig();
-
- loadConfiguration(conf);
- } catch (ArgumentsParserException eee) {
- doCatch(eee, n_("pollen.error.context.parse"),
- PollenContext.DEFAULT_FILENAME);
- }
- }
-
- /**
* Load the application configuration :
* <pre>
* - Add entities implementation classes for Topia-persistence
@@ -78,13 +28,7 @@
*
* @param conf ApplicationConfig
*/
- public static void loadConfiguration(ApplicationConfig conf) {
- configuration = conf;
- configuration.setOption("topia.persistence.classes",
- PollenModelDAOHelper.getImplementationClassesAsString());
- configuration.setOption("topia.service.migration.version",
- PollenModelDAOHelper.getModelVersion());
- }
+ void loadConfiguration(ApplicationConfig conf);
/**
* Start of the application. The application configuration will be loaded
@@ -96,194 +40,51 @@
* - Initialize i18n for error messages
* - Create default admin if needed (this will load the topiaRootContext).
* </pre>
- *
+ *
*/
- public static void start() {
- try {
- if (log.isInfoEnabled()) {
- log.info("Initialize i18n bundle");
- }
- I18n.setInitializer(new DefaultI18nInitializer("pollen-business"));
- I18n.init();
+ void start();
- ServiceUserImpl serviceUser = new ServiceUserImpl();
- serviceUser.createDefaultAdmin(
- PollenProperty.ADMIN_LOGIN.getValue(),
- PollenProperty.ADMIN_PASSWORD.getValue(),
- PollenProperty.ADMIN_EMAIL.getValue()
- );
-
- sendMail = new SendMail();
- sendMail.start();
-
- if (log.isInfoEnabled()) {
- log.info("pollen is started !");
- }
-
- } catch (Exception eee) {
- doCatch(eee, n_("pollen.error.context.start"));
- }
- }
-
/**
* Stop the application. Close the Topia rootContext.
*/
- public static void stop() {
- try {
- getRootContext().closeContext();
- sendMail.stopExec();
- } catch (Exception eee) {
- doCatch(eee, n_("pollen.error.context.stop"));
- }
- }
+ void stop();
- public static SendMail getSendMail() {
- return sendMail;
- }
-
/**
- * Get a property from the configuration.
+ * Get the SendMail thread to manage emails.
*
- * @param property PollenProperty
- * @return value of this property
- * @
+ * @return the SendMail running thread
*/
- public static String getProperty(PollenProperty property) {
- return getConfiguration().getOption(property.getKey());
- }
+ SendMail getSendMail();
/**
* Get a property from the configuration.
*
- * @param key of the property
+ * @param property PollenProperty
* @return value of this property
- * @
*/
- public static String getProperty(String key) {
- return getConfiguration().getOption(key);
- }
+ String getProperty(PollenProperty property);
/**
- * Get all properties from the configuration
+ * Test if the property is defined in this context
*
- * @return the Properties of the application
- * @
+ * @param property PollenProperty
+ * @return value of this property
*/
- public static Properties getProperties() {
- return getConfiguration().getOptions();
- }
+ boolean hasProperty(PollenProperty property);
/**
- * Get the configuration of the application.
+ * Get the configuration of the application. Instantiate the default one
+ * if needed.
*
* @return the ApplicationConfig
- * @
*/
- public static ApplicationConfig getConfiguration() {
- if (configuration == null) {
- loadDefaultConfiguration();
- }
- return configuration;
- }
+ ApplicationConfig getConfiguration();
/**
- * Get the Topia rootContext.
+ * Return the current date from context
*
- * @return the main TopiaContext needed to begin new transaction
- * @
+ * @return a date
*/
- public static TopiaContext getRootContext() {
- try {
- return TopiaContextFactory.getContext(getProperties());
- } catch (TopiaNotFoundException eee) {
- doCatch(eee, n_("pollen.error.context.getRootContext"));
- }
- return null;
- }
+ Date getCurrentDate();
- /**
- * Manage exceptions. The {@code exception} will be embedded in a
- * PollenException with the {@code message} provided.
- * Used in catch statement in services.
- *
- * @param eee the exception to manage
- * @param message the message to add to the new PollenException
- * @param args for message
- * @throws PollenException which contains the exception as the cause
- */
- public static void doCatch(Exception eee, String message, Object... args) throws PollenException {
- doCatch(null, eee, message);
- }
-
- /**
- * Manage exceptions. The {@code exception} will be embedded in a
- * PollenException with the {@code message} provided. Also, the current
- * {@code transaction} will be rollback.
- * Used in catch statement in services.
- *
- * @param transaction the current TopiaContext
- * @param eee the exception to manage
- * @param message the message to add to the new PollenException
- * @param args for message
- * @throws PollenException
- */
- public static void doCatch(TopiaContext transaction, Exception eee, String message, Object... args) throws PollenException {
- if (log.isErrorEnabled()) {
- log.error(_(message, args), eee);
- }
-
- // rollback de la transaction courante
- if (transaction != null) {
- try {
- transaction.rollbackTransaction();
- } catch (TopiaException ex) {
- if (log.isErrorEnabled()) {
- log.error(_("pollen.error.context.rollback"), ex);
- }
- }
- }
- // PollenBusinessException must be managed (catch and throw) when needed
-// if (! (eee instanceof PollenBusinessException)) {
- throw new PollenException(eee, message, args);
-// }
- }
-
- /**
- * Close current TopiaContext.
- * Used in finally statement in services.
- *
- * @param transaction current TopiaContext
- */
- public static void doFinally(TopiaContext transaction) {
- if (transaction != null) {
- try {
- transaction.closeContext();
- } catch (TopiaException eee) {
- if (log.isErrorEnabled()) {
- log.error(_("pollen.error.context.close"), eee);
- }
- }
- }
- }
-
- /**
- * Create an id to easily managed polls using urls.
- *
- * @return a fresh generated String
- */
- public static String createPollenUrlId() {
- return UUID.randomUUID().toString().replaceAll("-", "");
- }
-
- public static void setCurrentDate(Date currentDate) {
- PollenContext.currentDate = currentDate;
- }
-
- public static Date getCurrentDate() {
- if (currentDate == null) {
- currentDate = new Date();
- }
- return currentDate;
- }
-
}
Copied: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContextImpl.java (from rev 2951, trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContext.java)
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContextImpl.java (rev 0)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContextImpl.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -0,0 +1,342 @@
+
+package org.chorem.pollen.business;
+
+import java.util.Date;
+import java.util.Properties;
+import java.util.UUID;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.business.persistence.PollenModelDAOHelper;
+import org.chorem.pollen.business.services.SendMail;
+import org.chorem.pollen.business.services.ServiceUserImpl;
+import org.nuiton.i18n.I18n;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaContextFactory;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.TopiaNotFoundException;
+import org.nuiton.util.ApplicationConfig;
+import org.nuiton.util.ArgumentsParserException;
+import static org.nuiton.i18n.I18n._;
+import static org.nuiton.i18n.I18n.n_;
+import org.nuiton.i18n.init.DefaultI18nInitializer;
+
+/**
+ * PollenContext
+ *
+ * Created: 24 févr. 2010
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class PollenContextImpl implements PollenContextImplementor {
+
+ /** log. */
+ private static final Log log = LogFactory.getLog(PollenContextImpl.class);
+
+ public static final String DEFAULT_FILENAME = "pollen.properties";
+
+ private ApplicationConfig configuration;
+
+ private Date currentDate;
+
+ private SendMail sendMail;
+
+ /** Conversion service for services **/
+ private PollenConverter converter;
+
+ public PollenContextImpl() {
+
+ }
+
+ @Override
+ public void finalize() {
+ stop();
+ }
+
+ /**
+ * Default configuration file will be loaded using
+ * {@link org.nuiton.util.ApplicationConfig }.
+ * Then the other configuration initialization will be done in
+ * {@link #loadConfiguration(ApplicationConfig)} method.
+ */
+ private void loadDefaultConfiguration() {
+ try {
+ if (log.isInfoEnabled()) {
+ log.info("load default configuration from " +
+ PollenContextImpl.DEFAULT_FILENAME);
+ }
+ ApplicationConfig conf = new ApplicationConfig();
+ conf.setConfigFileName(PollenContextImpl.DEFAULT_FILENAME);
+ conf.parse(new String[]{});
+
+ conf.printConfig();
+
+ loadConfiguration(conf);
+ } catch (ArgumentsParserException eee) {
+ doCatch(eee, n_("pollen.error.context.parse"),
+ PollenContextImpl.DEFAULT_FILENAME);
+ }
+ }
+
+ /**
+ * Load the application configuration :
+ * <pre>
+ * - Add entities implementation classes for Topia-persistence
+ * - Add model version for Topia-migration-service
+ * </pre>
+ *
+ * @param conf ApplicationConfig
+ */
+ @Override
+ public void loadConfiguration(ApplicationConfig conf) {
+ configuration = conf;
+ configuration.setOption("topia.persistence.classes",
+ PollenModelDAOHelper.getImplementationClassesAsString());
+ configuration.setOption("topia.service.migration.version",
+ PollenModelDAOHelper.getModelVersion());
+ }
+
+ /**
+ * Start of the application. The application configuration will be loaded
+ * automatically if needed using {@link #loadDefaultConfiguration }. Also
+ * you can manually load the configuration using
+ * {@link #loadConfiguration(ApplicationConfig)}
+ * This start does :
+ * <pre>
+ * - Initialize i18n for error messages
+ * - Create default admin if needed (this will load the topiaRootContext).
+ * </pre>
+ *
+ */
+ @Override
+ public void start() {
+ try {
+ if (log.isInfoEnabled()) {
+ log.info("Start Pollen");
+ log.info("Initialize i18n bundle");
+ }
+ I18n.setInitializer(new DefaultI18nInitializer("pollen-business"));
+ I18n.init();
+
+ ServiceUserImpl serviceUser = new ServiceUserImpl(this);
+ serviceUser.createDefaultAdmin(
+ getProperty(PollenProperty.ADMIN_LOGIN),
+ getProperty(PollenProperty.ADMIN_PASSWORD),
+ getProperty(PollenProperty.ADMIN_EMAIL)
+ );
+
+ sendMail = new SendMail(this);
+ sendMail.start();
+
+ if (log.isInfoEnabled()) {
+ log.info("pollen is started !");
+ }
+
+ } catch (Exception eee) {
+ doCatch(eee, n_("pollen.error.context.start"));
+ }
+ }
+
+ /**
+ * Stop the application. Close the Topia rootContext.
+ */
+ @Override
+ public void stop() {
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Stop Pollen");
+ }
+ getRootContext().closeContext();
+ sendMail.stopExec();
+ } catch (Exception eee) {
+ doCatch(eee, n_("pollen.error.context.stop"));
+ }
+ }
+
+ @Override
+ public SendMail getSendMail() {
+ return sendMail;
+ }
+
+ /**
+ * Get a property from the configuration.
+ *
+ * @param property PollenProperty
+ * @return value of this property
+ */
+ @Override
+ public String getProperty(PollenProperty property) {
+ return getConfiguration().getOption(property.getKey());
+ }
+
+ /**
+ * Test if the property is defined in this context
+ *
+ * @param property PollenProperty
+ * @return value of this property
+ */
+ @Override
+ public boolean hasProperty(PollenProperty property) {
+ return !getProperty(property).equals("");
+ }
+
+ /**
+ * Get a property from the configuration.
+ *
+ * @param key of the property
+ * @return value of this property
+ */
+ public String getProperty(String key) {
+ return getConfiguration().getOption(key);
+ }
+
+ /**
+ * Get all properties from the configuration
+ *
+ * @return the Properties of the application
+ */
+ public Properties getProperties() {
+ return getConfiguration().getOptions();
+ }
+
+ /**
+ * Get the configuration of the application.
+ *
+ * @return the ApplicationConfig
+ */
+ @Override
+ public ApplicationConfig getConfiguration() {
+ if (configuration == null) {
+ loadDefaultConfiguration();
+ }
+ return configuration;
+ }
+
+ /**
+ * Get the Topia rootContext.
+ *
+ * @return the main TopiaContext needed to begin new transaction
+ */
+ @Override
+ public TopiaContext getRootContext() {
+ try {
+ return TopiaContextFactory.getContext(getProperties());
+ } catch (TopiaNotFoundException eee) {
+ doCatch(eee, n_("pollen.error.context.getRootContext"));
+ }
+ return null;
+ }
+
+ @Override
+ public PollenConverter getConverter() {
+ if (converter == null) {
+ converter = new PollenConverter();
+ }
+ return converter;
+ }
+
+ /**
+ * Manage exceptions. The {@code exception} will be embedded in a
+ * PollenException with the {@code message} provided.
+ * Used in catch statement in services.
+ *
+ * @param eee the exception to manage
+ * @param message the message to add to the new PollenException
+ * @param args for message
+ * @throws PollenException which contains the exception as the cause
+ */
+ @Override
+ public void doCatch(Exception eee, String message, Object... args)
+ throws PollenException {
+ doCatch(null, eee, message);
+ }
+
+ /**
+ * Manage exceptions. The {@code exception} will be embedded in a
+ * PollenException with the {@code message} provided. Also, the current
+ * {@code transaction} will be rollback.
+ * Used in catch statement in services.
+ *
+ * @param transaction the current TopiaContext
+ * @param eee the exception to manage
+ * @param message the message to add to the new PollenException
+ * @param args for message
+ * @throws PollenException
+ */
+ @Override
+ public void doCatch(TopiaContext transaction, Exception eee, String message,
+ Object... args) throws PollenException {
+ if (log.isErrorEnabled()) {
+ log.error(_(message, args), eee);
+ }
+
+ // rollback de la transaction courante
+ if (transaction != null) {
+ try {
+ transaction.rollbackTransaction();
+ } catch (TopiaException ex) {
+ if (log.isErrorEnabled()) {
+ log.error(_("pollen.error.context.rollback"), ex);
+ }
+ }
+ }
+ // PollenBusinessException must be managed (catch and throw) when needed
+// if (! (eee instanceof PollenBusinessException)) {
+ throw new PollenException(eee, message, args);
+// }
+ }
+
+ /**
+ * Close current TopiaContext.
+ * Used in finally statement in services.
+ *
+ * @param transaction current TopiaContext
+ */
+ @Override
+ public void doFinally(TopiaContext transaction) {
+ if (transaction != null) {
+ try {
+ transaction.closeContext();
+ } catch (TopiaException eee) {
+ if (log.isErrorEnabled()) {
+ log.error(_("pollen.error.context.close"), eee);
+ }
+ }
+ }
+ }
+
+ /**
+ * Create an id to easily managed polls using urls.
+ *
+ * @return a fresh generated String
+ */
+ @Override
+ public String createPollenUrlId() {
+ return UUID.randomUUID().toString().replaceAll("-", "");
+ }
+
+// public void setCurrentDate(Date currentDate) {
+// PollenContextBusiness.currentDate = currentDate;
+// }
+
+ @Override
+ public Date getCurrentDate() {
+ if (currentDate == null) {
+ currentDate = new Date();
+ }
+ return currentDate;
+ }
+
+ /**
+ * Set the current date in context. Used for test
+ *
+ * @param currentDate to set in the context
+ */
+ public void setCurrentDate(Date currentDate) {
+ this.currentDate = currentDate;
+ }
+
+}
Property changes on: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContextImpl.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: svn:mergeinfo
+
Added: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContextImplementor.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContextImplementor.java (rev 0)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContextImplementor.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -0,0 +1,78 @@
+
+package org.chorem.pollen.business;
+
+import org.nuiton.topia.TopiaContext;
+
+/**
+ * PollenContextImplementor
+ *
+ * Created: 20 mars 2010
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public interface PollenContextImplementor extends PollenContext {
+
+ /**
+ * Topia main context used to open new transaction.
+ *
+ * @return the topia root context
+ */
+ TopiaContext getRootContext();
+
+ /**
+ * Pollen converter used to convert entities to DTO.
+ *
+ * @return the current pollen converter
+ */
+ PollenConverter getConverter();
+
+ /**
+ * Manage exceptions. The {@code exception} will be embedded in a
+ * PollenException with the {@code message} provided.
+ * Used in catch statement in services.
+ *
+ * @param eee the exception to manage
+ * @param message the message to add to the new PollenException
+ * @param args for message
+ * @throws PollenException which contains the exception as the cause
+ */
+ void doCatch(Exception eee, String message, Object... args)
+ throws PollenException;
+
+ /**
+ * Manage exceptions. The {@code exception} will be embedded in a
+ * PollenException with the {@code message} provided. Also, the current
+ * {@code transaction} will be rollback.
+ * Used in catch statement in services.
+ *
+ * @param transaction the current TopiaContext
+ * @param eee the exception to manage
+ * @param message the message to add to the new PollenException
+ * @param args for message
+ * @throws PollenException
+ */
+ void doCatch(TopiaContext transaction, Exception eee, String message,
+ Object... args) throws PollenException;
+
+ /**
+ * Close current TopiaContext.
+ * Used in finally statement in services.
+ *
+ * @param transaction current TopiaContext
+ */
+ void doFinally(TopiaContext transaction);
+
+ /**
+ * Create a unique UId for entities which need it (PollAccount, Poll).
+ * This UId represent the entity in UI module.
+ *
+ * @return a new pollenUrlId (UId)
+ */
+ String createPollenUrlId();
+
+
+}
Property changes on: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContextImplementor.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenConverter.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenConverter.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenConverter.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -1,6 +1,8 @@
package org.chorem.pollen.business;
+import java.util.ArrayList;
+import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.business.dto.ChoiceDTO;
@@ -28,7 +30,7 @@
import org.nuiton.util.beans.BinderProvider;
/**
- * ConverterFactory
+ * PollenConverter
*
* Created: 22 févr. 2010
*
@@ -42,9 +44,22 @@
private static final Log log = LogFactory.getLog(PollenConverter.class);
- private static BinderBuilder builder = new BinderBuilder();
+ private BinderBuilder builder;
- private static final void prepare(Class<? extends TopiaEntity> entityClass, Class<?> dtoClass, String... properties) {
+ private List<Class<? extends TopiaEntity>> prepareLoaded;
+
+ public PollenConverter() {
+ builder = new BinderBuilder();
+ prepareLoaded = new ArrayList<Class<? extends TopiaEntity>>();
+ }
+
+ private final void prepare(Class<? extends TopiaEntity> entityClass,
+ Class<?> dtoClass, String... properties) {
+
+ if (prepareLoaded.contains(entityClass)) {
+ return;
+ }
+
// Binder DTO -> Entity
builder.createBinderModel(dtoClass, entityClass).
addSimpleProperties(properties);
@@ -57,9 +72,11 @@
//builder.addProperty(TopiaEntity.TOPIA_ID, "id");
BinderProvider.registerBinder(builder);
+
+ prepareLoaded.add(entityClass);
}
- public static void preparePollConverters() {
+ public void preparePollConverters() {
String[] properties = new String[] {
Poll.TITLE,
Poll.DESCRIPTION,
@@ -79,7 +96,7 @@
prepare(Poll.class, PollDTO.class, properties);
}
- public static void prepareChoiceConverters() {
+ public void prepareChoiceConverters() {
String[] properties = new String[] {
Choice.NAME,
Choice.DESCRIPTION,
@@ -89,7 +106,7 @@
prepare(Choice.class, ChoiceDTO.class, properties);
}
- public static void prepareVotingListConverters() {
+ public void prepareVotingListConverters() {
String[] properties = new String[] {
VotingList.NAME,
VotingList.WEIGHT
@@ -98,7 +115,7 @@
prepare(VotingList.class, VotingListDTO.class, properties);
}
- public static void preparePollAccountConverters() {
+ public void preparePollAccountConverters() {
String[] properties = new String[] {
PollAccount.VOTING_ID,
PollAccount.EMAIL
@@ -107,7 +124,7 @@
prepare(PollAccount.class, PollAccountDTO.class, properties);
}
- public static void preparePreventRuleConverters() {
+ public void preparePreventRuleConverters() {
String[] properties = new String[] {
PreventRule.ACTIVE,
PreventRule.METHOD,
@@ -120,7 +137,7 @@
prepare(PreventRule.class, PreventRuleDTO.class, properties);
}
- public static void prepareVoteConverters() {
+ public void prepareVoteConverters() {
String[] properties = new String[] {
Vote.WEIGHT,
Vote.COMMENT,
@@ -130,7 +147,7 @@
prepare(Vote.class, VoteDTO.class, properties);
}
- public static void prepareCommentConverters() {
+ public void prepareCommentConverters() {
String[] properties = new String[] {
Comment.TEXT,
Comment.POST_DATE,
@@ -140,13 +157,15 @@
prepare(Comment.class, CommentDTO.class, properties);
}
- public static Choice convert(ChoiceDTO dto, Choice entity) {
- BinderProvider.getBinder(ChoiceDTO.class, Choice.class).copy(dto, entity);
+ public Choice convert(ChoiceDTO dto, Choice entity) {
+ BinderProvider.getBinder(
+ ChoiceDTO.class, Choice.class).copy(dto, entity);
return entity;
}
- public static ChoiceDTO convert(Choice entity, ChoiceDTO dto) {
- BinderProvider.getBinder(Choice.class, ChoiceDTO.class).copy(entity, dto);
+ public ChoiceDTO convert(Choice entity, ChoiceDTO dto) {
+ BinderProvider.getBinder(
+ Choice.class, ChoiceDTO.class).copy(entity, dto);
dto.setId(entity.getTopiaId());
String name = entity.getName();
dto.setHidden(name != null
@@ -155,7 +174,7 @@
return dto;
}
- public static Poll convert(PollDTO dto, Poll entity) {
+ public Poll convert(PollDTO dto, Poll entity) {
BinderProvider.getBinder(PollDTO.class, Poll.class).copy(dto, entity);
entity.setChoiceType(dto.getChoiceType().name());
entity.setPollType(dto.getPollType().name());
@@ -163,7 +182,7 @@
return entity;
}
- public static PollDTO convert(Poll entity, PollDTO dto) {
+ public PollDTO convert(Poll entity, PollDTO dto) {
BinderProvider.getBinder(Poll.class, PollDTO.class).copy(entity, dto);
dto.setId(entity.getTopiaId());
dto.setPollUId(entity.getPollId());
@@ -182,43 +201,49 @@
return dto;
}
- public static VotingList convert(VotingListDTO dto, VotingList entity) {
- BinderProvider.getBinder(VotingListDTO.class, VotingList.class).copy(dto, entity);
+ public VotingList convert(VotingListDTO dto, VotingList entity) {
+ BinderProvider.getBinder(
+ VotingListDTO.class, VotingList.class).copy(dto, entity);
return entity;
}
- public static VotingListDTO convert(VotingList entity, VotingListDTO dto) {
- BinderProvider.getBinder(VotingList.class, VotingListDTO.class).copy(entity, dto);
+ public VotingListDTO convert(VotingList entity, VotingListDTO dto) {
+ BinderProvider.getBinder(
+ VotingList.class, VotingListDTO.class).copy(entity, dto);
dto.setId(entity.getTopiaId());
return dto;
}
- public static PollAccount convert(PollAccountDTO dto, PollAccount entity) {
- BinderProvider.getBinder(PollAccountDTO.class, PollAccount.class).copy(dto, entity);
+ public PollAccount convert(PollAccountDTO dto, PollAccount entity) {
+ BinderProvider.getBinder(
+ PollAccountDTO.class, PollAccount.class).copy(dto, entity);
return entity;
}
- public static PollAccountDTO convert(PollAccount entity, PollAccountDTO dto) {
- BinderProvider.getBinder(PollAccount.class, PollAccountDTO.class).copy(entity, dto);
+ public PollAccountDTO convert(PollAccount entity, PollAccountDTO dto) {
+ BinderProvider.getBinder(
+ PollAccount.class, PollAccountDTO.class).copy(entity, dto);
dto.setId(entity.getTopiaId());
dto.setAccountId(entity.getAccountId());
return dto;
}
- public static PreventRule convert(PreventRuleDTO dto, PreventRule entity) {
- BinderProvider.getBinder(PreventRuleDTO.class, PreventRule.class).copy(dto, entity);
+ public PreventRule convert(PreventRuleDTO dto, PreventRule entity) {
+ BinderProvider.getBinder(
+ PreventRuleDTO.class, PreventRule.class).copy(dto, entity);
return entity;
}
- public static PreventRuleDTO convert(PreventRule entity, PreventRuleDTO dto) {
- BinderProvider.getBinder(PreventRule.class, PreventRuleDTO.class).copy(entity, dto);
+ public PreventRuleDTO convert(PreventRule entity, PreventRuleDTO dto) {
+ BinderProvider.getBinder(
+ PreventRule.class, PreventRuleDTO.class).copy(entity, dto);
dto.setId(entity.getTopiaId());
Poll poll = entity.getPoll();
dto.setPollId(poll.getTopiaId());
return dto;
}
- public static Vote convert(VoteDTO dto, Vote entity) {
+ public Vote convert(VoteDTO dto, Vote entity) {
BinderProvider.getBinder(VoteDTO.class, Vote.class).copy(dto, entity);
return entity;
}
@@ -234,7 +259,7 @@
* @param dto VoteDTO
* @return VoteDTO
*/
- public static VoteDTO convert(Vote entity, VoteDTO dto) {
+ public VoteDTO convert(Vote entity, VoteDTO dto) {
BinderProvider.getBinder(Vote.class, VoteDTO.class).copy(entity, dto);
dto.setId(entity.getTopiaId());
Poll poll = entity.getPoll();
@@ -268,13 +293,15 @@
return dto;
}
- public static Comment convert(CommentDTO dto, Comment entity) {
- BinderProvider.getBinder(CommentDTO.class, Comment.class).copy(dto, entity);
+ public Comment convert(CommentDTO dto, Comment entity) {
+ BinderProvider.getBinder(
+ CommentDTO.class, Comment.class).copy(dto, entity);
return entity;
}
- public static CommentDTO convert(Comment entity, CommentDTO dto) {
- BinderProvider.getBinder(Comment.class, CommentDTO.class).copy(entity, dto);
+ public CommentDTO convert(Comment entity, CommentDTO dto) {
+ BinderProvider.getBinder(
+ Comment.class, CommentDTO.class).copy(entity, dto);
dto.setId(entity.getTopiaId());
return dto;
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenProperty.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenProperty.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenProperty.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -50,11 +50,11 @@
return key;
}
- public String getValue() {
- return PollenContext.getProperty(this);
- }
+// public String getValue() {
+// return PollenContexImpl.getProperty(this);
+// }
- public boolean hasValue() {
- return !getValue().equals("");
- }
+// public boolean hasValue() {
+// return !getValue().equals("");
+// }
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollConverter.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollConverter.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollConverter.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -24,6 +24,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.business.PollenBusinessException;
+import org.chorem.pollen.business.PollenContextImplementor;
import org.chorem.pollen.business.dto.ChoiceDTO;
import org.chorem.pollen.business.dto.CommentDTO;
import org.chorem.pollen.business.dto.PollDTO;
@@ -61,8 +62,8 @@
* @deprecated use {@link ConverterHelper}
*/
@Deprecated
- public PollDTO createPollDTO(Poll ePoll) {
- PollDTO pollDTO = PollenConverter.convert(ePoll, new PollDTO());
+ public PollDTO createPollDTO(Poll ePoll, PollenConverter converter) {
+ PollDTO pollDTO = converter.convert(ePoll, new PollDTO());
// pollDTO.setId(ePoll.getTopiaId());
// pollDTO.setPollId(ePoll.getPollId());
@@ -96,7 +97,7 @@
// }
for (Comment comment : ePoll.getComment()) {
CommentDTO dto =
- PollenConverter.convert(comment, new CommentDTO());
+ converter.convert(comment, new CommentDTO());
pollDTO.addComment(dto);
}
// if (ePoll.getComment().size() > 0) {
@@ -119,15 +120,16 @@
* Retourne une liste de dtos sondage à partir d'une liste d'entités.
*
* @param lPolls liste de entités sondages
+ * @param converter
* @return la liste des dtos sondages
* @deprecated use {@link ConverterHelper}
*/
@Deprecated
- public List<PollDTO> createPollDTOs(List<Poll> lPolls) {
+ public List<PollDTO> createPollDTOs(List<Poll> lPolls, PollenConverter converter) {
ArrayList<PollDTO> results = new ArrayList<PollDTO>();
PollDTO dto;
for (Poll p : lPolls) {
- dto = this.createPollDTO(p);
+ dto = this.createPollDTO(p, converter);
results.add(dto);
}
return results;
@@ -141,11 +143,11 @@
* @deprecated use dao managment instead
*/
@Deprecated
- public void persistChoices(PollDTO pollDTO, Poll ePoll)
+ public void persistChoices(PollDTO pollDTO, Poll ePoll, PollenContextImplementor context)
throws TopiaException, PollenBusinessException {
// mise à jour ou création des choix
- ServiceChoice sChoice = new ServiceChoiceImpl();
+ ServiceChoice sChoice = new ServiceChoiceImpl(context);
for (ChoiceDTO choiceDTO : pollDTO.getChoices()) {
boolean updated = sChoice.updateChoice(choiceDTO);
if (!updated) {
@@ -182,11 +184,11 @@
* @param pollDTO le dto sondage
* @param ePoll l'entité sondage
*/
- public void persistPreventRules(PollDTO pollDTO, Poll ePoll)
+ public void persistPreventRules(PollDTO pollDTO, Poll ePoll, PollenContextImplementor context)
throws TopiaException, PollenBusinessException {
// mise à jour ou création des règles de notification
- ServicePreventRule sPreventRule = new ServicePreventRuleImpl();
+ ServicePreventRule sPreventRule = new ServicePreventRuleImpl(context);
for (PreventRuleDTO preventRuleDTO : pollDTO.getPreventRuleDTOs()) {
boolean updated = sPreventRule.updatePreventRule(preventRuleDTO);
if (!updated) {
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/SendMail.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/SendMail.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/SendMail.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -37,6 +37,7 @@
import au.com.bytecode.opencsv.CSVReader;
import au.com.bytecode.opencsv.CSVWriter;
import org.apache.commons.io.IOUtils;
+import org.chorem.pollen.business.PollenContextImplementor;
import org.chorem.pollen.business.PollenProperty;
/**
@@ -63,6 +64,8 @@
/** logger. */
private static final Logger log = LoggerFactory.getLogger(SendMail.class);
+ protected PollenContextImplementor context;
+
public static final String EXTENSION_MAIL = ".mail";
public static final String EXTENSION_INDEX = ".index";
@@ -71,11 +74,14 @@
protected volatile boolean stop;
- public SendMail() {
-
+ public SendMail(PollenContextImplementor context) {
+ this.context = context;
+ if (log.isInfoEnabled()) {
+ log.info("P:[ SendMail ] init");
+ }
// get email directory in configuration
// create it if not exists
- String filename = PollenProperty.EMAIL_DIR.getValue();
+ String filename = context.getProperty(PollenProperty.EMAIL_DIR);
mailStorageDirectory = new File(filename);
if (!mailStorageDirectory.exists()) {
if (mailStorageDirectory.mkdirs()) {
@@ -95,6 +101,9 @@
*/
@Override
public void run() {
+ if (log.isInfoEnabled()) {
+ log.info("P:[ SendMail ] start");
+ }
// try to find existing files
while (!stop) {
@@ -162,10 +171,12 @@
// index contains next index to treat so == is ok
if (currentIndex >= index) {
- String host = PollenProperty.EMAIL_HOST.getValue();
+ String host =
+ context.getProperty(PollenProperty.EMAIL_HOST);
int port = Integer.parseInt(
- PollenProperty.EMAIL_PORT.getValue());
- String from = PollenProperty.EMAIL_FROM.getValue();
+ context.getProperty(PollenProperty.EMAIL_PORT));
+ String from =
+ context.getProperty(PollenProperty.EMAIL_FROM);
MailUtil.sendMail(host, port, from,
receiver, subject, body);
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceAuthImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceAuthImpl.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceAuthImpl.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -18,8 +18,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.business.PollenBusinessException;
-import org.chorem.pollen.business.PollenContext;
+import org.chorem.pollen.business.PollenContextImpl;
+import org.chorem.pollen.business.PollenContextImplementor;
import org.chorem.pollen.business.converters.DataUserConverter;
import org.chorem.pollen.business.dto.UserDTO;
import org.chorem.pollen.business.persistence.PollenModelDAOHelper;
@@ -37,15 +37,15 @@
*/
public class ServiceAuthImpl implements ServiceAuth {
- private TopiaContext rootContext;
+ private PollenContextImplementor context;
private UserAccountDAO userDAO = null;
private DataUserConverter converter = new DataUserConverter();
/** log. */
private static final Log log = LogFactory.getLog(ServiceAuthImpl.class);
- public ServiceAuthImpl() {
- rootContext = PollenContext.getRootContext();
+ public ServiceAuthImpl(PollenContextImplementor context) {
+ this.context = context;
}
@Override
@@ -53,7 +53,7 @@
TopiaContext transaction = null;
boolean result = false;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction);
@@ -84,7 +84,7 @@
TopiaContext transaction = null;
UserDTO result = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction);
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoiceImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoiceImpl.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoiceImpl.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -16,15 +16,14 @@
package org.chorem.pollen.business.services;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.business.PollenBusinessException;
-import org.chorem.pollen.business.PollenContext;
+import org.chorem.pollen.business.PollenContextImpl;
+import org.chorem.pollen.business.PollenContextImplementor;
import org.chorem.pollen.business.converters.DataChoiceConverter;
import org.chorem.pollen.business.dto.ChoiceDTO;
import org.chorem.pollen.business.persistence.Choice;
@@ -41,15 +40,15 @@
*/
public class ServiceChoiceImpl implements ServiceChoice {
- private TopiaContext rootContext;
+ private PollenContextImplementor context;
private ChoiceDAO choiceDAO = null;
private DataChoiceConverter converter = new DataChoiceConverter();
/** log. */
private static final Log log = LogFactory.getLog(ServiceChoiceImpl.class);
- public ServiceChoiceImpl() {
- rootContext = PollenContext.getRootContext();
+ public ServiceChoiceImpl(PollenContextImplementor context) {
+ this.context = context;
}
@Override
@@ -57,7 +56,7 @@
TopiaContext transaction = null;
String topiaId = "";
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction);
@@ -114,7 +113,7 @@
TopiaContext transaction = null;
boolean resu = false;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction);
@@ -145,7 +144,7 @@
public boolean deleteChoice(String choiceId) {
TopiaContext transaction = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction);
@@ -172,7 +171,7 @@
TopiaContext transaction = null;
ChoiceDTO result = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction);
@@ -205,7 +204,7 @@
List<ChoiceDTO> results = null;
List<Choice> choiceEntities = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction);
@@ -240,7 +239,7 @@
List<ChoiceDTO> results = null;
List<Choice> choiceEntities = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction);
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceListImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceListImpl.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceListImpl.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -18,12 +18,10 @@
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.business.PollenContext;
-import org.chorem.pollen.business.PollenConverter;
+import org.chorem.pollen.business.PollenContextImplementor;
import org.chorem.pollen.business.converters.DataPersonListConverter;
import org.chorem.pollen.business.converters.DataVotingListConverter;
import org.chorem.pollen.business.dto.PersonListDTO;
@@ -51,7 +49,7 @@
*/
public class ServiceListImpl implements ServiceList {
- private TopiaContext rootContext;
+ private PollenContextImplementor context;
private VotingListDAO votingListDAO = null;
private PersonListDAO personListDAO = null;
private DataVotingListConverter votingListConverter = new DataVotingListConverter();
@@ -60,11 +58,11 @@
/** log. */
private static final Log log = LogFactory.getLog(ServiceListImpl.class);
- public ServiceListImpl() {
- rootContext = PollenContext.getRootContext();
+ public ServiceListImpl(PollenContextImplementor context) {
+ this.context = context;
- PollenConverter.preparePollAccountConverters();
- PollenConverter.prepareVotingListConverters();
+ context.getConverter().preparePollAccountConverters();
+ context.getConverter().prepareVotingListConverters();
}
@Override
@@ -72,7 +70,7 @@
TopiaContext transaction = null;
String topiaId = "";
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
votingListDAO = PollenModelDAOHelper.getVotingListDAO(transaction);
@@ -84,7 +82,7 @@
// Création des pollAccount de la liste si nécessaire
// FIXME do not call a Service from an other one
- ServicePollAccount spa = new ServicePollAccountImpl();
+ ServicePollAccount spa = new ServicePollAccountImpl(context);
//spa.createPollAccounts(votingList.getPollAccountDTOs(), transaction);
for (PollAccountDTO account : votingList.getPollAccountDTOs()) {
if (spa.findPollAccountById(account.getId()) == null) {
@@ -117,7 +115,7 @@
public boolean updateVotingList(VotingListDTO votingList) {
TopiaContext transaction = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
votingListDAO = PollenModelDAOHelper.getVotingListDAO(transaction);
@@ -147,7 +145,7 @@
TopiaContext transaction = null;
String topiaId = "";
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
personListDAO = PollenModelDAOHelper.getPersonListDAO(transaction);
PersonList entity = personListDAO.create();
@@ -157,7 +155,7 @@
// Création des comptes de la liste
// FIXME do not call a Service from an other one
- ServicePollAccount spa = new ServicePollAccountImpl();
+ ServicePollAccount spa = new ServicePollAccountImpl(context);
for (PollAccountDTO account : personList.getPollAccounts()) {
account.setPersonListId(entity.getTopiaId());
}
@@ -185,7 +183,7 @@
public void createAccountInPersonList(PersonListDTO personList, PollAccountDTO account) {
TopiaContext transaction = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
personListDAO = PollenModelDAOHelper.getPersonListDAO(transaction);
@@ -195,9 +193,9 @@
PollenModelDAOHelper.getPollAccountDAO(transaction);
// Create new pollAccount
- String accountUID = PollenContext.createPollenUrlId();
+ String accountUID = context.createPollenUrlId();
PollAccount eAccount = accountDAO.create(accountUID);
- PollenConverter.convert(account, eAccount);
+ context.getConverter().convert(account, eAccount);
// Add the account into the list
eList.addPollAccount(eAccount);
@@ -210,11 +208,11 @@
personList.addPollAccount(account);
} catch (Exception eee) {
- PollenContext.doCatch(transaction, eee,
+ context.doCatch(transaction, eee,
n_("pollen.error.serviceList.createAccountForPersonList"),
personList.getName(), account.getVotingId());
} finally {
- PollenContext.doFinally(transaction);
+ context.doFinally(transaction);
}
}
@@ -222,7 +220,7 @@
public void deleteAccountFromPersonList(PersonListDTO personList, String accountId) {
TopiaContext transaction = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
// Find the account
PollAccountDAO accountDAO =
@@ -245,11 +243,11 @@
personList.removePollAccount(accountId);
} catch (Exception eee) {
- PollenContext.doCatch(transaction, eee,
+ context.doCatch(transaction, eee,
n_("pollen.error.serviceList.deleteAccountFromPersonList"),
accountId, personList.getName(), personList.getId());
} finally {
- PollenContext.doFinally(transaction);
+ context.doFinally(transaction);
}
}
@@ -257,7 +255,7 @@
public boolean deletePersonList(String personListId) {
TopiaContext transaction = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
personListDAO = PollenModelDAOHelper.getPersonListDAO(transaction);
@@ -285,7 +283,7 @@
List<PersonList> personListEntities = null;
UserAccountDAO userDAO = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction);
UserAccount user = userDAO.findByTopiaId(userId);
@@ -320,7 +318,7 @@
TopiaContext transaction = null;
PersonListDTO result = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
personListDAO = PollenModelDAOHelper.getPersonListDAO(transaction);
@@ -356,7 +354,7 @@
List<PersonList> personListEntities = null;
UserAccountDAO userDAO = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction);
UserAccount user = userDAO.findByTopiaId(userId);
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccountImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccountImpl.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccountImpl.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -22,10 +22,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.business.PollenContext;
+import org.chorem.pollen.business.PollenContextImpl;
+import org.chorem.pollen.business.PollenContextImplementor;
import org.chorem.pollen.business.converters.DataPollAccountConverter;
import org.chorem.pollen.business.dto.PollAccountDTO;
-import org.chorem.pollen.business.dto.UserDTO;
import org.chorem.pollen.business.persistence.PollAccount;
import org.chorem.pollen.business.persistence.PollAccountDAO;
import org.chorem.pollen.business.persistence.PollenModelDAOHelper;
@@ -41,7 +41,7 @@
*/
public class ServicePollAccountImpl implements ServicePollAccount {
- private TopiaContext rootContext;
+ private PollenContextImplementor context;
private PollAccountDAO pollAccountDAO = null;
private DataPollAccountConverter converter = new DataPollAccountConverter();
@@ -49,8 +49,8 @@
private static final Log log = LogFactory
.getLog(ServicePollAccountImpl.class);
- public ServicePollAccountImpl() {
- rootContext = PollenContext.getRootContext();
+ public ServicePollAccountImpl(PollenContextImplementor context) {
+ this.context = context;
}
@Override
@@ -58,7 +58,7 @@
TopiaContext transaction = null;
String topiaId;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
pollAccountDAO = PollenModelDAOHelper
.getPollAccountDAO(transaction);
@@ -123,7 +123,7 @@
public boolean deletePollAccount(String pollAccountId) {
TopiaContext transaction = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
pollAccountDAO = PollenModelDAOHelper
.getPollAccountDAO(transaction);
@@ -150,7 +150,7 @@
TopiaContext transaction = null;
boolean resu = false;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
pollAccountDAO = PollenModelDAOHelper
.getPollAccountDAO(transaction);
@@ -185,7 +185,7 @@
TopiaContext transaction = null;
PollAccountDTO result = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
pollAccountDAO = PollenModelDAOHelper
.getPollAccountDAO(transaction);
@@ -219,7 +219,7 @@
TopiaContext transaction = null;
PollAccountDTO result = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
pollAccountDAO = PollenModelDAOHelper
.getPollAccountDAO(transaction);
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -25,7 +25,6 @@
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.business.PollenConverter;
import org.chorem.pollen.business.converters.DataPollConverter;
import org.chorem.pollen.business.converters.DataVotingListConverter;
import org.chorem.pollen.business.dto.ChoiceDTO;
@@ -52,7 +51,8 @@
import org.chorem.pollen.business.persistence.VotingList;
import org.chorem.pollen.business.persistence.VotingListDAO;
import org.chorem.pollen.business.utils.ContextUtil;
-import org.chorem.pollen.business.PollenContext;
+import org.chorem.pollen.business.PollenContextImpl;
+import org.chorem.pollen.business.PollenContextImplementor;
import org.chorem.pollen.business.persistence.PersonToListDAO;
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.common.VoteCountingType;
@@ -73,22 +73,22 @@
*/
public class ServicePollImpl implements ServicePoll {
- private TopiaContext rootContext;
+ private PollenContextImplementor context;
private PollDAO pollDAO = null;
private DataPollConverter converter = new DataPollConverter();
/** log. */
private static final Log log = LogFactory.getLog(ServicePollImpl.class);
- public ServicePollImpl() {
- rootContext = PollenContext.getRootContext();
+ public ServicePollImpl(PollenContextImplementor context) {
+ this.context = context;
- PollenConverter.preparePollConverters();
- PollenConverter.prepareChoiceConverters();
- PollenConverter.prepareVotingListConverters();
- PollenConverter.preparePollAccountConverters();
- PollenConverter.preparePreventRuleConverters();
- PollenConverter.prepareVoteConverters();
- PollenConverter.prepareCommentConverters();
+ context.getConverter().preparePollConverters();
+ context.getConverter().prepareChoiceConverters();
+ context.getConverter().prepareVotingListConverters();
+ context.getConverter().preparePollAccountConverters();
+ context.getConverter().preparePreventRuleConverters();
+ context.getConverter().prepareVoteConverters();
+ context.getConverter().prepareCommentConverters();
}
@Override
@@ -101,14 +101,14 @@
log.info("P:[ createPoll ] : " + pollDTO);
}
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
pollDAO = PollenModelDAOHelper.getPollDAO(transaction);
// Create with the pollId from dto
String pollId = pollDTO.getPollUId();
Poll entity = pollDAO.create(pollId);
- PollenConverter.convert(pollDTO, entity);
+ context.getConverter().convert(pollDTO, entity);
// ** Manage the poll creator
PollAccount creator = prepareCreator(transaction, pollDTO);
@@ -118,7 +118,7 @@
ChoiceDAO choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction);
for (ChoiceDTO choiceDTO : pollDTO.getChoices()) {
Choice choice =
- PollenConverter.convert(choiceDTO, choiceDAO.create());
+ context.getConverter().convert(choiceDTO, choiceDAO.create());
choice.setPoll(entity);
}
@@ -133,7 +133,7 @@
PollenModelDAOHelper.getPreventRuleDAO(transaction);
for (PreventRuleDTO ruleDTO : pollDTO.getPreventRuleDTOs()) {
PreventRule rule =
- PollenConverter.convert(ruleDTO, ruleDAO.create());
+ context.getConverter().convert(ruleDTO, ruleDAO.create());
rule.setPoll(entity);
}
@@ -148,14 +148,14 @@
// Update dto : need creator and id update
// WARN : Update for choices, preventRules and
// votingLists is not needed in this case
- PollenConverter.convert(entity, pollDTO);
+ context.getConverter().convert(entity, pollDTO);
} catch (Exception eee) {
- PollenContext.doCatch(transaction, eee,
+ context.doCatch(transaction, eee,
n_("pollen.error.servicePoll.createPoll"),
pollDTO.getTitle(), pollDTO.getCreatorId());
} finally {
- PollenContext.doFinally(transaction);
+ context.doFinally(transaction);
}
return result;
}
@@ -172,7 +172,7 @@
* @return the PollAccount used as creator for this poll
* @throws TopiaException
*/
- private static final PollAccount prepareCreator(TopiaContext transaction,
+ private final PollAccount prepareCreator(TopiaContext transaction,
PollDTO poll) throws TopiaException {
// Search user from database
@@ -196,7 +196,7 @@
// Create new account if account properties changed or no user found
if (creator == null) {
accountProperties.put(
- PollAccount.ACCOUNT_ID, PollenContext.createPollenUrlId());
+ PollAccount.ACCOUNT_ID, context.createPollenUrlId());
creator = accountDAO.create(accountProperties);
}
return creator;
@@ -213,12 +213,12 @@
* @return VotingList entity created
* @throws TopiaException
*/
- private static final VotingList createVotingList(TopiaContext transaction,
+ private final VotingList createVotingList(TopiaContext transaction,
VotingListDTO listDTO) throws TopiaException {
VotingListDAO dao = PollenModelDAOHelper.getVotingListDAO(transaction);
VotingList votingList =
- PollenConverter.convert(listDTO, dao.create());
+ context.getConverter().convert(listDTO, dao.create());
PollAccountDAO pollAccountDAO =
PollenModelDAOHelper.getPollAccountDAO(transaction);
@@ -230,9 +230,9 @@
// Create a new PollAccount if not already exists
if (account == null) {
- String accountId = PollenContext.createPollenUrlId();
+ String accountId = context.createPollenUrlId();
account = pollAccountDAO.create(accountId);
- PollenConverter.convert(accountDTO, account);
+ context.getConverter().convert(accountDTO, account);
}
// Create association between VotingList and PollAccount
@@ -254,26 +254,26 @@
log.info("P:[ updatePoll ] : " + pollDTO);
}
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
pollDAO = PollenModelDAOHelper.getPollDAO(transaction);
Poll pollEntity = pollDAO.findByTopiaId(pollDTO.getId());
- PollenConverter.convert(pollDTO, pollEntity);
+ context.getConverter().convert(pollDTO, pollEntity);
ChoiceDAO choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction);
// ** Update choices (no add, no remove)
for (ChoiceDTO choiceDTO : pollDTO.getChoices()) {
Choice choice = choiceDAO.findByTopiaId(choiceDTO.getId());
- PollenConverter.convert(choiceDTO, choice);
+ context.getConverter().convert(choiceDTO, choice);
choice.update();
}
// Les règles de notifications restent mystérieuses
// Y a t-il un besoin de suppression ?
- converter.persistPreventRules(pollDTO, pollEntity);
+ converter.persistPreventRules(pollDTO, pollEntity, context);
pollDAO.update(pollEntity);
@@ -285,12 +285,12 @@
return true;
} catch (Exception eee) {
- PollenContext.doCatch(transaction, eee,
+ context.doCatch(transaction, eee,
n_("pollen.error.servicePoll.updatePoll"),
pollDTO.getTitle(), pollDTO.getPollUId());
return false;
} finally {
- PollenContext.doFinally(transaction);
+ context.doFinally(transaction);
}
}
@@ -299,7 +299,7 @@
PollDTO newPoll = new PollDTO();
newPoll.setVoteCounting(VoteCountingType.NORMAL);
newPoll.setPollType(PollType.FREE);
- newPoll.setPollUId(PollenContext.createPollenUrlId());
+ newPoll.setPollUId(context.createPollenUrlId());
return newPoll;
}
@@ -318,7 +318,7 @@
log.info("P:[ deletePoll ] : pollId = " + pollId);
}
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
pollDAO = PollenModelDAOHelper.getPollDAO(transaction);
@@ -333,11 +333,11 @@
return true;
} catch (Exception eee) {
- PollenContext.doCatch(transaction, eee,
+ context.doCatch(transaction, eee,
n_("pollen.error.servicePoll.deletePoll"), pollId);
return false;
} finally {
- PollenContext.doFinally(transaction);
+ context.doFinally(transaction);
}
}
@@ -350,19 +350,19 @@
log.info("P:[ getPoll ] : pollUId = " + pollId);
}
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
pollDAO = PollenModelDAOHelper.getPollDAO(transaction);
Poll pollEntity = pollDAO.findByPollId(pollId);
if (pollEntity != null) {
- result = PollenConverter.convert(pollEntity, new PollDTO());
+ result = context.getConverter().convert(pollEntity, new PollDTO());
// Load choices
for (Choice choice : pollEntity.getChoice()) {
ChoiceDTO dto =
- PollenConverter.convert(choice, new ChoiceDTO());
+ context.getConverter().convert(choice, new ChoiceDTO());
result.addChoice(dto);
}
@@ -387,21 +387,21 @@
// Load votes
// for (Vote vote : pollEntity.getVote()) {
// VoteDTO dto =
-// PollenConverter.convert(vote, new VoteDTO());
+// context.getConverter().convert(vote, new VoteDTO());
// result.addVote(dto);
// }
// Load comments
// for (Comment comment : pollEntity.getComment()) {
// CommentDTO dto =
-// PollenConverter.convert(comment, new CommentDTO());
+// context.getConverter().convert(comment, new CommentDTO());
// result.addComment(dto);
// }
// Load preventRules
for (PreventRule rule : pollEntity.getPreventRule()) {
PreventRuleDTO dto =
- PollenConverter.convert(rule, new PreventRuleDTO());
+ context.getConverter().convert(rule, new PreventRuleDTO());
result.addPreventRule(dto);
}
@@ -420,11 +420,11 @@
return result;
} catch (Exception eee) {
- PollenContext.doCatch(transaction, eee,
+ context.doCatch(transaction, eee,
n_("pollen.error.servicePoll.getPoll"), pollId);
return null;
} finally {
- PollenContext.doFinally(transaction);
+ context.doFinally(transaction);
}
}
@@ -434,7 +434,7 @@
List<PollDTO> results = null;
UserAccountDAO userDAO = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction);
UserAccount user = userDAO.findByTopiaId(userId);
@@ -445,7 +445,8 @@
}
converter.setTransaction(transaction);
- results = converter.createPollDTOs(pollEntities);
+ results = converter.createPollDTOs(pollEntities,
+ context.getConverter());
transaction.commitTransaction();
@@ -458,7 +459,7 @@
ContextUtil.doCatch(e, transaction);
return null;
} finally {
- PollenContext.doFinally(transaction);
+ context.doFinally(transaction);
}
}
@@ -468,7 +469,7 @@
List<PollDTO> results = null;
UserAccountDAO userDAO = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction);
UserAccount user = userDAO.findByTopiaId(userId);
@@ -481,7 +482,8 @@
}
converter.setTransaction(transaction);
- results = converter.createPollDTOs(new ArrayList<Poll>(pollEntities));
+ results = converter.createPollDTOs(
+ new ArrayList<Poll>(pollEntities), context.getConverter());
transaction.commitTransaction();
@@ -494,7 +496,7 @@
ContextUtil.doCatch(e, transaction);
return null;
} finally {
- PollenContext.doFinally(transaction);
+ context.doFinally(transaction);
}
}
@@ -504,7 +506,7 @@
List<PollDTO> results = null;
UserAccountDAO userDAO = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction);
UserAccount user = userDAO.findByTopiaId(userId);
@@ -528,7 +530,9 @@
}
converter.setTransaction(transaction);
- results = converter.createPollDTOs(new ArrayList<Poll>(pollEntities));
+ results = converter.createPollDTOs(
+ new ArrayList<Poll>(pollEntities),
+ context.getConverter());
transaction.commitTransaction();
@@ -541,7 +545,7 @@
ContextUtil.doCatch(e, transaction);
return null;
} finally {
- PollenContext.doFinally(transaction);
+ context.doFinally(transaction);
}
}
@@ -550,13 +554,13 @@
TopiaContext transaction = null;
List<PollDTO> results = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
PollDAO dao = PollenModelDAOHelper.getPollDAO(transaction);
String beginDate = Poll.BEGIN_DATE;
String endDate = Poll.END_DATE;
- Date currentDate = PollenContext.getCurrentDate();
+ Date currentDate = context.getCurrentDate();
TopiaQuery query = dao.createQuery().
addNullOr(beginDate, Op.LT, currentDate);
@@ -585,7 +589,8 @@
// }
converter.setTransaction(transaction);
- results = converter.createPollDTOs(entities);
+ results = converter.createPollDTOs(entities,
+ context.getConverter());
transaction.commitTransaction();
@@ -598,7 +603,7 @@
ContextUtil.doCatch(e, transaction);
return null;
} finally {
- PollenContext.doFinally(transaction);
+ context.doFinally(transaction);
}
}
@@ -608,7 +613,7 @@
List<PollDTO> results = null;
List<Poll> pollEntities = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
pollDAO = PollenModelDAOHelper.getPollDAO(transaction);
@@ -621,7 +626,8 @@
pollEntities = pollDAO.findAllByProperties(properties);
}
converter.setTransaction(transaction);
- results = converter.createPollDTOs(pollEntities);
+ results = converter.createPollDTOs(pollEntities,
+ context.getConverter());
transaction.commitTransaction();
@@ -635,7 +641,7 @@
_("pollen.error.servicePoll.getAllPolls"));
return null;
} finally {
- PollenContext.doFinally(transaction);
+ context.doFinally(transaction);
}
}
@@ -647,12 +653,12 @@
log.info("P:[ createComment ] : pollUId = " + poll.getPollUId() +
" _ comment = " + comment);
}
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
// Create the new comment
CommentDAO dao = PollenModelDAOHelper.getCommentDAO(transaction);
Comment eComment =
- PollenConverter.convert(comment, dao.create());
+ context.getConverter().convert(comment, dao.create());
// Get the poll entity corresponding
Poll ePoll = PollenModelDAOHelper.getPollDAO(transaction).
@@ -668,11 +674,11 @@
poll.addComment(comment);
} catch (Exception eee) {
- PollenContext.doCatch(transaction, eee,
+ context.doCatch(transaction, eee,
n_("pollen.error.servicePoll.addComment"),
comment.getAuthor(), poll.getTitle(), poll.getId());
} finally {
- PollenContext.doFinally(transaction);
+ context.doFinally(transaction);
}
}
@@ -684,7 +690,7 @@
log.info("P:[ deleteComment ] : pollUId = " + poll.getPollUId() +
" _ commentId = " + commentId);
}
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
// Find the comment
CommentDAO dao = PollenModelDAOHelper.getCommentDAO(transaction);
@@ -704,11 +710,11 @@
poll.removeComment(commentId);
} catch (Exception eee) {
- PollenContext.doCatch(transaction, eee,
+ context.doCatch(transaction, eee,
n_("pollen.error.servicePoll.deleteComment"), commentId,
poll.getTitle(), poll.getId());
} finally {
- PollenContext.doFinally(transaction);
+ context.doFinally(transaction);
}
}
@@ -720,7 +726,7 @@
if (log.isInfoEnabled()) {
log.info("P:[ getComments ] : pollUId = " + poll.getPollUId());
}
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
CommentDAO dao = PollenModelDAOHelper.getCommentDAO(transaction);
TopiaQuery query = dao.createQuery().
@@ -730,16 +736,16 @@
for (Comment entity : entities) {
CommentDTO dto =
- PollenConverter.convert(entity, new CommentDTO());
+ context.getConverter().convert(entity, new CommentDTO());
results.add(dto);
}
} catch (Exception eee) {
- PollenContext.doCatch(transaction, eee,
+ context.doCatch(transaction, eee,
n_("pollen.error.servicePoll.getComments"),
poll.getTitle(), poll.getId());
} finally {
- PollenContext.doFinally(transaction);
+ context.doFinally(transaction);
}
return results;
}
@@ -749,7 +755,7 @@
TopiaContext transaction = null;
PollAccountDTO result = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
if (log.isInfoEnabled()) {
log.info("P:[ getRestrictedAccount ] : accountUId = " + accountUId +
@@ -777,15 +783,15 @@
if (assoc != null) {
PollAccount account = assoc.getPollAccount();
- PollenConverter.convert(account, result);
+ context.getConverter().convert(account, result);
}
} catch (Exception eee) {
- PollenContext.doCatch(transaction, eee,
+ context.doCatch(transaction, eee,
n_("pollen.error.servicePoll.getRestrictedAccount"),
accountUId, poll.getPollUId());
} finally {
- PollenContext.doFinally(transaction);
+ context.doFinally(transaction);
}
return result;
}
@@ -811,7 +817,7 @@
log.info("P:[ deleteChoice ] : pollUId = " + poll.getPollUId() +
" _ choiceId = " + choiceId);
}
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
// Find the comment
ChoiceDAO dao = PollenModelDAOHelper.getChoiceDAO(transaction);
@@ -831,11 +837,11 @@
poll.removeChoice(choiceId);
} catch (Exception eee) {
- PollenContext.doCatch(transaction, eee,
+ context.doCatch(transaction, eee,
n_("pollen.error.servicePoll.deleteChoice"), choiceId,
poll.getTitle(), poll.getId());
} finally {
- PollenContext.doFinally(transaction);
+ context.doFinally(transaction);
}
}
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePreventRuleImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePreventRuleImpl.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePreventRuleImpl.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -22,8 +22,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.business.PollenBusinessException;
-import org.chorem.pollen.business.PollenContext;
+import org.chorem.pollen.business.PollenContextImpl;
+import org.chorem.pollen.business.PollenContextImplementor;
import org.chorem.pollen.business.converters.DataPreventRuleConverter;
import org.chorem.pollen.business.dto.PreventRuleDTO;
import org.chorem.pollen.business.persistence.PollenModelDAOHelper;
@@ -40,7 +40,7 @@
*/
public class ServicePreventRuleImpl implements ServicePreventRule {
- private TopiaContext rootContext;
+ private PollenContextImplementor context;
private PreventRuleDAO preventRuleDAO = null;
private DataPreventRuleConverter converter = new DataPreventRuleConverter();
@@ -48,8 +48,8 @@
private static final Log log = LogFactory
.getLog(ServicePreventRuleImpl.class);
- public ServicePreventRuleImpl() {
- rootContext = PollenContext.getRootContext();
+ public ServicePreventRuleImpl(PollenContextImplementor context) {
+ this.context = context;
}
@Override
@@ -57,7 +57,7 @@
TopiaContext transaction = null;
String topiaId = "";
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
preventRuleDAO = PollenModelDAOHelper
.getPreventRuleDAO(transaction);
@@ -117,7 +117,7 @@
TopiaContext transaction = null;
boolean resu = false;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
preventRuleDAO = PollenModelDAOHelper
.getPreventRuleDAO(transaction);
@@ -151,7 +151,7 @@
public boolean deletePreventRule(String preventRuleId) {
TopiaContext transaction = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
preventRuleDAO = PollenModelDAOHelper
.getPreventRuleDAO(transaction);
@@ -180,7 +180,7 @@
TopiaContext transaction = null;
PreventRuleDTO result = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
preventRuleDAO = PollenModelDAOHelper
.getPreventRuleDAO(transaction);
@@ -216,7 +216,7 @@
List<PreventRuleDTO> results = null;
List<PreventRule> preventRuleEntities = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
preventRuleDAO = PollenModelDAOHelper
.getPreventRuleDAO(transaction);
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceResultsImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceResultsImpl.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceResultsImpl.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -23,8 +23,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.business.PollenBusinessException;
-import org.chorem.pollen.business.PollenContext;
+import org.chorem.pollen.business.PollenContextImpl;
+import org.chorem.pollen.business.PollenContextImplementor;
import org.chorem.pollen.business.converters.DataResultConverter;
import org.chorem.pollen.business.converters.DataVoteCountingConverter;
import org.chorem.pollen.business.dto.ResultDTO;
@@ -56,13 +56,13 @@
*/
public class ServiceResultsImpl implements ServiceResults {
- private TopiaContext rootContext;
+ private PollenContextImplementor context;
/** log. */
private static final Log log = LogFactory.getLog(ServiceResultsImpl.class);
- public ServiceResultsImpl() {
- rootContext = PollenContext.getRootContext();
+ public ServiceResultsImpl(PollenContextImplementor context) {
+ this.context = context;
}
@Override
@@ -99,7 +99,7 @@
VoteCountingType voteCounting, boolean byGroup, boolean groupOnly) {
TopiaContext transaction = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
PollDAO daoPoll = PollenModelDAOHelper.getPollDAO(transaction);
Poll ePoll = daoPoll.findByPollId(pollId);
@@ -212,7 +212,7 @@
public String exportPoll(String pollId) {
TopiaContext transaction = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
// Recherche du sondage
PollDAO daoPoll = PollenModelDAOHelper.getPollDAO(transaction);
@@ -281,7 +281,7 @@
// Transformation du sondage
// FIXME do not call a Service from an other one
ServicePoll servicePoll;
- servicePoll = new ServicePollImpl();
+ servicePoll = new ServicePollImpl(context);
org.chorem.pollen.business.dto.PollDTO poll = DataVoteCountingConverter
.createPollDTO(pollExportDTO.getPoll());
@@ -296,7 +296,7 @@
}
} catch (Exception eee) {
- PollenContext.doCatch(eee,
+ context.doCatch(eee,
n_("pollen.error.serviceResults.importPoll"));
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceUserImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceUserImpl.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceUserImpl.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -21,8 +21,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.business.PollenBusinessException;
-import org.chorem.pollen.business.PollenContext;
+import org.chorem.pollen.business.PollenContextImplementor;
import org.chorem.pollen.business.converters.DataUserConverter;
import org.chorem.pollen.business.dto.UserDTO;
import org.chorem.pollen.business.persistence.PollenModelDAOHelper;
@@ -31,6 +30,7 @@
import org.chorem.pollen.business.utils.ContextUtil;
import org.chorem.pollen.business.utils.MD5;
import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.framework.TopiaQuery;
import static org.nuiton.i18n.I18n.n_;
/**
@@ -41,15 +41,15 @@
* @version $Id$
*/
public class ServiceUserImpl implements ServiceUser {
- private TopiaContext rootContext;
+ private PollenContextImplementor context;
private UserAccountDAO userDAO = null;
private DataUserConverter converter = new DataUserConverter();
/** log. */
private static final Log log = LogFactory.getLog(ServiceUserImpl.class);
- public ServiceUserImpl() {
- rootContext = PollenContext.getRootContext();
+ public ServiceUserImpl(PollenContextImplementor context) {
+ this.context = context;
}
@Override
@@ -57,7 +57,7 @@
TopiaContext transaction = null;
String topiaId = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction);
if (userDAO.findByLogin(user.getLogin()) != null
@@ -89,7 +89,7 @@
public boolean deleteUser(String login) {
TopiaContext transaction = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction);
@@ -115,7 +115,7 @@
public boolean deleteUser(UserDTO user) {
TopiaContext transaction = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction);
@@ -141,7 +141,7 @@
TopiaContext transaction = null;
UserDTO result = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction);
@@ -174,7 +174,7 @@
List<UserDTO> results = null;
List<UserAccount> userEntities = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction);
@@ -210,7 +210,7 @@
public boolean updateUser(UserDTO user) {
TopiaContext transaction = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction);
@@ -239,7 +239,7 @@
public boolean updatePasswordUser(UserDTO user, String newPassword) {
TopiaContext transaction = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction);
@@ -267,7 +267,7 @@
TopiaContext transaction = null;
boolean userExists = true;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction);
if (userDAO.findByLogin(login) == null) {
@@ -292,7 +292,7 @@
TopiaContext transaction = null;
boolean userExists = true;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction);
if (userDAO.findByEmail(email) == null) {
@@ -315,12 +315,16 @@
public void createDefaultAdmin(String login, String password, String email) {
TopiaContext transaction = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
+
UserAccountDAO dao =
PollenModelDAOHelper.getUserAccountDAO(transaction);
- if (dao.findAllByAdministrator(true).size() == 0) {
+ int nbAdmin = dao.createQuery().
+ add(UserAccount.ADMINISTRATOR, Boolean.TRUE).executeCount();
+
+ if (nbAdmin == 0) {
UserAccount userEntity = dao.create();
userEntity.setLogin(login);
String encodedPassword = MD5.encode(password);
@@ -335,11 +339,11 @@
transaction.commitTransaction();
}
} catch (Exception eee) {
- PollenContext.doCatch(transaction, eee,
+ context.doCatch(transaction, eee,
n_("pollen.error.serviceUser.createDefaultAdmin"),
login, email);
} finally {
- PollenContext.doFinally(transaction);
+ context.doFinally(transaction);
}
}
}
\ No newline at end of file
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -22,8 +22,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.business.PollenContext;
-import org.chorem.pollen.business.PollenConverter;
+import org.chorem.pollen.business.PollenContextImplementor;
import org.chorem.pollen.business.converters.DataPollAccountConverter;
import org.chorem.pollen.business.converters.DataVoteConverter;
import org.chorem.pollen.business.dto.PollAccountDTO;
@@ -50,16 +49,16 @@
*/
public class ServiceVoteImpl implements ServiceVote {
- private TopiaContext rootContext;
+ private PollenContextImplementor context;
private DataVoteConverter converter = new DataVoteConverter();
/** log. */
private static final Log log = LogFactory.getLog(ServiceVoteImpl.class);
- public ServiceVoteImpl() {
- rootContext = PollenContext.getRootContext();
+ public ServiceVoteImpl(PollenContextImplementor context) {
+ this.context = context;
- PollenConverter.prepareVoteConverters();
+ context.getConverter().prepareVoteConverters();
}
@Override
@@ -67,7 +66,7 @@
TopiaContext transaction = null;
String topiaId = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
// création du compte associé au vote s'il n'existe pas
// sinon mise à jour du compte
@@ -84,7 +83,7 @@
if (pollAccountEntity == null) {
log.debug("Nouveau compte associé au vote");
pollAccountEntity = pollAccountDAO.create(
- PollenContext.createPollenUrlId());
+ context.createPollenUrlId());
// EVO #108 : Migration to ToPIA 2.3, the entity must be
// commited because an other findBy is called in the
// converter (wtf ?! :/). This behavior doesn't work
@@ -144,7 +143,7 @@
public boolean updateVote(VoteDTO voteDTO) {
TopiaContext transaction = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
VoteDAO voteDAO = PollenModelDAOHelper.getVoteDAO(transaction);
Vote voteEntity = voteDAO.findByTopiaId(voteDTO.getId());
@@ -171,7 +170,7 @@
public boolean deleteVote(String voteId) {
TopiaContext transaction = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
VoteDAO voteDAO = PollenModelDAOHelper.getVoteDAO(transaction);
Vote voteEntity = voteDAO.findByTopiaId(voteId);
@@ -213,7 +212,7 @@
// FIXME-FD20100309 : change dto to suppress link from poll to vote
// It's not necessary to have votes when retrieving the poll, this
// method do this job only when it's needed
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
// List<Vote> votes = transaction.find(
// "FROM " + Vote.class.getName() +
@@ -236,18 +235,18 @@
log.debug("Nb votes found : " + eVotes.size());
}
for (Vote eVote : eVotes) {
- VoteDTO vote = PollenConverter.convert(eVote, new VoteDTO());
+ VoteDTO vote = context.getConverter().convert(eVote, new VoteDTO());
results.add(vote);
}
// converter.setTransaction(transaction);
// results = converter.createVoteDTOs(votes);
} catch (Exception eee) {
- PollenContext.doCatch(transaction, eee,
+ context.doCatch(transaction, eee,
n_("pollen.error.serviceVote.getVotesByPoll"),
poll.getPollUId());
} finally {
- PollenContext.doFinally(transaction);
+ context.doFinally(transaction);
}
return results;
}
@@ -281,7 +280,7 @@
" _ pollUId = " + poll.getPollUId());
}
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
// List<Long> tmp = transaction.find(
// "SELECT COUNT(*)" +
@@ -304,11 +303,11 @@
result = count > 0;
} catch (Exception eee) {
- PollenContext.doCatch(transaction, eee,
+ context.doCatch(transaction, eee,
n_("pollen.error.serviceVote.hasAlreadyVoted"),
votingId, poll.getPollUId());
} finally {
- PollenContext.doFinally(transaction);
+ context.doFinally(transaction);
}
return result;
}
@@ -319,7 +318,7 @@
List<VoteDTO> results = null;
List<Vote> voteEntities = null;
try {
- transaction = rootContext.beginTransaction();
+ transaction = context.getRootContext().beginTransaction();
VoteDAO voteDAO = PollenModelDAOHelper.getVoteDAO(transaction);
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils/ContextUtil.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils/ContextUtil.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils/ContextUtil.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -26,7 +26,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.business.PollenBusinessException;
-import org.chorem.pollen.business.PollenContext;
+import org.chorem.pollen.business.PollenContextImpl;
import org.chorem.pollen.business.PollenException;
import org.chorem.pollen.business.persistence.PollenModelDAOHelper;
import org.chorem.pollen.business.persistence.UserAccount;
@@ -76,21 +76,21 @@
* @
* @deprecated use {@link #getRootContext } instead
*/
- @Deprecated
- public TopiaContext getContext() {
- return PollenContext.getRootContext();
- }
-
+// @Deprecated
+// public TopiaContext getContext() {
+// return PollenContexImpl.getRootContext();
+// }
+//
+// /**
+// * Retourne la configuration de la base de données.
+// *
+// * @return la configuration
+// * @
+// */
+// public Properties getConf() {
+// return PollenContexImpl.getProperties();
+// }
/**
- * Retourne la configuration de la base de données.
- *
- * @return la configuration
- * @
- */
- public Properties getConf() {
- return PollenContext.getProperties();
- }
- /**
* Construction du contexte global
* @deprecated use directly {@link #getRootContext} method
*/
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestData.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestData.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestData.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -21,7 +21,8 @@
public void execute() throws Exception {
transaction = null;
try {
- transaction = PollenContext.getRootContext().beginTransaction();
+ transaction = TestManager.getContext().
+ getRootContext().beginTransaction();
test();
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestManager.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestManager.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestManager.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -9,6 +9,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Ignore;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
import org.nuiton.util.ApplicationConfig;
/**
@@ -27,6 +29,8 @@
private static final Log log = LogFactory.getLog(TestManager.class);
+ private static PollenContextImplementor context;
+
public static void start(String dbname) throws IOException {
log.info("## START ## : " + dbname);
@@ -43,16 +47,27 @@
"jdbc:h2:file:target/surefire-data/" + dbname
);
- PollenContext.loadConfiguration(config);
- PollenContext.start();
+ getContext().loadConfiguration(config);
+ getContext().start();
// Set currentDate to 23/02/2010 for tests
Calendar calendar = new GregorianCalendar(2010, 1, 23, 0, 0, 0);
- PollenContext.setCurrentDate(calendar.getTime());
+ ((PollenContextImpl)getContext()).setCurrentDate(calendar.getTime());
}
public static void stop() throws IOException {
- PollenContext.stop();
+ getContext().stop();
}
+ public static PollenContextImplementor getContext() {
+ if (context == null) {
+ context = new PollenContextImpl();
+ }
+ return context;
+ }
+
+ public static TopiaContext beginTransaction() throws TopiaException {
+ return getContext().getRootContext().beginTransaction();
+ }
+
}
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/scaling/ScalingVote.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/business/scaling/ScalingVote.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/scaling/ScalingVote.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -16,13 +16,14 @@
package org.chorem.pollen.business.scaling;
-import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.business.TestManager;
import org.chorem.pollen.business.persistence.Choice;
import org.chorem.pollen.business.persistence.PersonToList;
import org.chorem.pollen.business.persistence.Poll;
@@ -35,7 +36,6 @@
import org.chorem.pollen.business.persistence.VoteToChoice;
import org.chorem.pollen.business.persistence.VoteToChoiceDAO;
import org.chorem.pollen.business.persistence.VotingList;
-import org.chorem.pollen.business.utils.ContextUtil;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaContextFactory;
import org.nuiton.topia.TopiaException;
@@ -55,8 +55,8 @@
private static final Log log = LogFactory.getLog(ScalingVote.class);
/** Adresse de la base de données (surchage l'adresse dans src/test/resources) */
- public static final String DB_URL = "jdbc:h2:" + System.getProperty("user.home") +
- File.separator + ".pollen" + File.separator + "pollendb";
+// public static final String DB_URL = "jdbc:h2:" + System.getProperty("user.home") +
+// File.separator + ".pollen" + File.separator + "pollendb";
/** La config en cours. */
protected static Properties config;
@@ -66,14 +66,16 @@
*
* @param args
*/
- public static void main(String args[]) {
- System.out.println("Using database at : " + DB_URL);
+ public static void main(String args[]) throws IOException {
+// System.out.println("Using database at : " + DB_URL);
- ContextUtil contextUtil = ContextUtil.getInstance();
- config = contextUtil.getConf();
- config.setProperty("hibernate.connection.url", DB_URL);
- config.remove("hibernate.hbm2ddl.auto");
+// ContextUtil contextUtil = ContextUtil.getInstance();
+// config = contextUtil.getConf();
+ TestManager.start("ScalingVote");
+// config.setProperty("hibernate.connection.url", DB_URL);
+// config.remove("hibernate.hbm2ddl.auto");
+
try {
new ScalingVote().doInsertFixedNumber();
}
@@ -92,9 +94,8 @@
*
* @throws TopiaException
*/
- public void doInsertWithVotingList() throws TopiaException {
- TopiaContext rootContext = TopiaContextFactory.getContext(config);
- TopiaContext context = rootContext.beginTransaction();
+ public void doInsertWithVotingList() throws TopiaException, IOException {
+ TopiaContext context = TestManager.beginTransaction();
PollDAO pollDAO = PollenModelDAOHelper.getPollDAO(context);
VoteDAO voteDAO = PollenModelDAOHelper.getVoteDAO(context);
@@ -151,7 +152,7 @@
context.commitTransaction();
context.closeContext();
- rootContext.closeContext();
+ TestManager.stop();
}
/**
@@ -162,9 +163,8 @@
*
* @throws TopiaException
*/
- public void doInsertFixedNumber() throws TopiaException {
- TopiaContext rootContext = TopiaContextFactory.getContext(config);
- TopiaContext context = rootContext.beginTransaction();
+ public void doInsertFixedNumber() throws TopiaException, IOException {
+ TopiaContext context = TestManager.beginTransaction();
PollDAO pollDAO = PollenModelDAOHelper.getPollDAO(context);
VoteDAO voteDAO = PollenModelDAOHelper.getVoteDAO(context);
@@ -218,6 +218,6 @@
context.commitTransaction();
context.closeContext();
- rootContext.closeContext();
+ TestManager.stop();
}
}
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/SendMailTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/SendMailTest.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/SendMailTest.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -24,7 +24,7 @@
import java.util.List;
import java.util.Map;
-import org.chorem.pollen.business.PollenContext;
+import org.chorem.pollen.business.PollenContextImpl;
import org.chorem.pollen.business.PollenProperty;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -46,6 +46,8 @@
protected static SendMail sendMail;
+ protected static PollenContextImpl context;
+
@BeforeClass
public static void init() throws InterruptedException {
@@ -55,9 +57,9 @@
config.setOption(PollenProperty.EMAIL_PORT.getKey(), "25");
config.setOption(PollenProperty.EMAIL_FROM.getKey(), "pollenreminder(a)codelutin.com");
- PollenContext.loadConfiguration(config);
+ context.loadConfiguration(config);
- sendMail = new SendMail();
+ sendMail = new SendMail(context);
sendMail.start();
Thread.sleep(3000);
}
@@ -89,7 +91,7 @@
sendMail.prepareMails("test", mailList);
- String emailDir = PollenProperty.EMAIL_DIR.getValue();
+ String emailDir = context.getProperty(PollenProperty.EMAIL_DIR);
Assert.assertTrue(new File(emailDir, "test.mail").exists());
Assert.assertTrue(new File(emailDir, "test.index").exists());
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceAuthImplTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceAuthImplTest.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceAuthImplTest.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -52,7 +52,7 @@
@Before
public void setUp() {
- instance = new ServiceAuthImpl();
+ instance = new ServiceAuthImpl(TestManager.getContext());
}
@After
@@ -71,7 +71,7 @@
UserDTO dto = new UserDTO();
dto.setLogin(login);
- ServiceUser smu = new ServiceUserImpl();
+ ServiceUser smu = new ServiceUserImpl(TestManager.getContext());
smu.createUser(dto, password);
boolean result2 = instance.isLoginRight(login, password);
assertTrue(result2);
@@ -89,7 +89,7 @@
UserDTO dto = new UserDTO();
dto.setLogin(login);
- ServiceUser smu = new ServiceUserImpl();
+ ServiceUser smu = new ServiceUserImpl(TestManager.getContext());
smu.createUser(dto, password);
UserDTO result2 = instance.getUser(login, password);
assertEquals(login, result2.getLogin());
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceChoiceImplTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceChoiceImplTest.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceChoiceImplTest.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -61,7 +61,7 @@
@Before
public void setUp() {
- instance = new ServiceChoiceImpl();
+ instance = new ServiceChoiceImpl(TestManager.getContext());
}
@After
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceListImplTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceListImplTest.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceListImplTest.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -68,7 +68,7 @@
@Before
public void setUp() {
- instance = new ServiceListImpl();
+ instance = new ServiceListImpl(TestManager.getContext());
}
@After
@@ -124,7 +124,7 @@
// temp stop, must refactor all tests from this class
TestManager.stop();
TestManager.start("createAccountInPersonList");
- instance = new ServiceListImpl();
+ instance = new ServiceListImpl(TestManager.getContext());
/** PREPARE DATA **/
PersonListDTO dto = new PersonListDTO();
@@ -173,7 +173,7 @@
// temp stop, must refactor all tests from this class
TestManager.stop();
TestManager.start("deleteAccountFromPersonList");
- instance = new ServiceListImpl();
+ instance = new ServiceListImpl(TestManager.getContext());
/** PREPARE DATA **/
PersonListDTO dto = new PersonListDTO();
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -26,7 +26,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.business.PollenContext;
+import org.chorem.pollen.business.PollenContextImpl;
import org.chorem.pollen.business.TestData;
import org.chorem.pollen.business.TestManager;
import org.chorem.pollen.business.dto.ChoiceDTO;
@@ -79,7 +79,7 @@
@After
public void tearDown() throws IOException {
TestManager.stop();
- BinderProvider.clear();
+ //BinderProvider.clear();
}
/**
@@ -89,7 +89,7 @@
@Test
public void testCreatePoll() throws Exception {
TestManager.start("testCreatePoll");
- instance = new ServicePollImpl();
+ instance = new ServicePollImpl(TestManager.getContext());
PollDTO dto = instance.getNewPoll();
dto.setBeginChoiceDate(new Date());
@@ -150,7 +150,7 @@
@Test
public void testUpdatePoll() throws Exception {
TestManager.start("testUpdatePoll");
- instance = new ServicePollImpl();
+ instance = new ServicePollImpl(TestManager.getContext());
String pollId = "";
PollDTO dto = instance.getNewPoll();
@@ -174,7 +174,7 @@
@Test
public void testDeletePoll() throws Exception {
TestManager.start("testDeletePoll");
- instance = new ServicePollImpl();
+ instance = new ServicePollImpl(TestManager.getContext());
PollDTO dto = instance.getNewPoll();
dto.setDescription("Test_deletePoll");
@@ -194,7 +194,7 @@
@Test
public void testFindPollByPollId() throws Exception {
TestManager.start("testFindPollByPollId");
- instance = new ServicePollImpl();
+ instance = new ServicePollImpl(TestManager.getContext());
String pollId = "";
PollDTO dto = instance.getNewPoll();
@@ -240,13 +240,13 @@
@Test
public void testFindPollsByUser() throws Exception {
TestManager.start("testFindPollsByUser");
- instance = new ServicePollImpl();
+ instance = new ServicePollImpl(TestManager.getContext());
// création de l'utilisateur
UserDTO user = new UserDTO();
user.setLogin("login_findPollsByUser");
user.setEmail("email_findPollsByUser");
- ServiceUser su = new ServiceUserImpl();
+ ServiceUser su = new ServiceUserImpl(TestManager.getContext());
String userId = su.createUser(user, "password");
// création du sondage
@@ -269,19 +269,19 @@
@Test
public void testFindParticipatedPolls() throws Exception {
TestManager.start("testFindParticipatedPolls");
- instance = new ServicePollImpl();
+ instance = new ServicePollImpl(TestManager.getContext());
// création de l'utilisateur
UserDTO user = new UserDTO();
user.setLogin("login_findParticipatedPolls");
user.setEmail("email_findParticipatedPolls");
- ServiceUser su = new ServiceUserImpl();
+ ServiceUser su = new ServiceUserImpl(TestManager.getContext());
String userId = su.createUser(user, "password");
// création du compte associé à l'utilisateur
PollAccountDTO account = new PollAccountDTO();
account.setUserId(userId);
- ServicePollAccount spa = new ServicePollAccountImpl();
+ ServicePollAccount spa = new ServicePollAccountImpl(TestManager.getContext());
String accountId = spa.createPollAccount(account);
// création du sondage
@@ -294,7 +294,7 @@
// création du vote
VoteDTO vote = new VoteDTO(accountId, pollId, null);
- ServiceVote sv = new ServiceVoteImpl();
+ ServiceVote sv = new ServiceVoteImpl(TestManager.getContext());
sv.createVote(vote, account);
// recherche des sondages de l'utilisateur
@@ -308,9 +308,9 @@
@Test
public void testFindRunningPolls() throws Exception {
TestManager.start("testFindRunningPolls");
- instance = new ServicePollImpl();
+ instance = new ServicePollImpl(TestManager.getContext());
- Date now = PollenContext.getCurrentDate();
+ Date now = TestManager.getContext().getCurrentDate();
// sondage en cours sans date de fin
PollDTO poll1 = instance.getNewPoll();
@@ -359,7 +359,7 @@
@Test
public void testSelectPolls() throws Exception {
TestManager.start("testSelectPolls");
- instance = new ServicePollImpl();
+ instance = new ServicePollImpl(TestManager.getContext());
PollDTO dto = instance.getNewPoll();
dto.setDescription("test selectPolls");
@@ -395,7 +395,7 @@
@Test
public void testCreateComment() throws Exception {
TestManager.start("testCreateComment");
- instance = new ServicePollImpl();
+ instance = new ServicePollImpl(TestManager.getContext());
/** PREPARE DATA **/
PollDTO poll = instance.getNewPoll();
@@ -440,7 +440,7 @@
@Test
public void testDeleteComment() throws Exception {
TestManager.start("testDeleteComment");
- instance = new ServicePollImpl();
+ instance = new ServicePollImpl(TestManager.getContext());
/** PREPARE DATA **/
PollDTO poll = instance.getNewPoll();
@@ -483,7 +483,7 @@
//@Test
public void testGetRestrictedAccount() throws IOException {
TestManager.start("testGetRestrictedAccount");
- instance = new ServicePollImpl();
+ instance = new ServicePollImpl(TestManager.getContext());
/** PREPARE DATA **/
PollDTO poll = instance.getNewPoll();
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePreventRuleImplTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePreventRuleImplTest.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePreventRuleImplTest.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -63,7 +63,7 @@
@Before
public void setUp() throws Exception {
- instance = new ServicePreventRuleImpl();
+ instance = new ServicePreventRuleImpl(TestManager.getContext());
}
@After
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceUserImplTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceUserImplTest.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceUserImplTest.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -54,7 +54,7 @@
@Before
public void setUp() {
- instance = new ServiceUserImpl();
+ instance = new ServiceUserImpl(TestManager.getContext());
}
@After
@@ -142,7 +142,7 @@
user.setId(instance.createUser(user, "password"));
instance.updatePasswordUser(user, "newPassword");
- ServiceAuth sa = new ServiceAuthImpl();
+ ServiceAuth sa = new ServiceAuthImpl(TestManager.getContext());
UserDTO result = sa.getUser(user.getLogin(), "newPassword");
assertNotNull(result);
}
Added: trunk/pollen-business/src/test/resources/log4j.properties
===================================================================
--- trunk/pollen-business/src/test/resources/log4j.properties (rev 0)
+++ trunk/pollen-business/src/test/resources/log4j.properties 2010-03-20 18:42:04 UTC (rev 2953)
@@ -0,0 +1,14 @@
+# Default to info level output; this is very handy if you eventually use Hibernate as well.
+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.logger.org.chorem.pollen=debug
+
+log4j.logger.org.chorem.pollen.business.PollenContextImpl=warn
+log4j.logger.org.chorem.pollen.business.services.SendMail=warn
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -24,7 +24,6 @@
import java.util.Locale;
import org.apache.tapestry5.BindingConstants;
-import org.apache.tapestry5.Link;
import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.IncludeStylesheet;
import org.apache.tapestry5.annotations.InjectComponent;
@@ -35,7 +34,7 @@
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.PersistentLocale;
import org.apache.tapestry5.services.Request;
-import org.chorem.pollen.business.PollenBusinessException;
+import org.chorem.pollen.business.PollenContext;
import org.chorem.pollen.business.PollenProperty;
import org.chorem.pollen.business.dto.UserDTO;
import org.chorem.pollen.business.services.ServiceAuth;
@@ -159,6 +158,9 @@
@Inject
private Request request;
+ @Inject
+ private PollenContext pollen;
+
/**
* Accès aux messages
*/
@@ -231,7 +233,7 @@
* @return current application version
*/
public String getVersion() {
- return PollenProperty.APP_VERSION.getValue();
+ return pollen.getProperty(PollenProperty.APP_VERSION);
}
public int getCurrentYear() {
@@ -240,7 +242,7 @@
}
public String getContactEmail() {
- return PollenProperty.CONTACT_EMAIL.getValue();
+ return pollen.getProperty(PollenProperty.CONTACT_EMAIL);
}
/**
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/FeedContextLink.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/FeedContextLink.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/FeedContextLink.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -2,7 +2,8 @@
package org.chorem.pollen.ui.components;
import java.io.File;
-import org.chorem.pollen.business.PollenBusinessException;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.chorem.pollen.business.PollenContext;
import org.chorem.pollen.ui.base.ContextLink;
import org.chorem.pollen.business.PollenProperty;
@@ -19,9 +20,12 @@
*/
public class FeedContextLink implements ContextLink {
+ @Inject
+ private PollenContext pollen;
+
@Override
public String getContextPath() {
- return PollenProperty.FEED_DIR.getValue();
+ return pollen.getProperty(PollenProperty.FEED_DIR);
}
@Override
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ImageContextLink.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ImageContextLink.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ImageContextLink.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -17,10 +17,9 @@
package org.chorem.pollen.ui.components;
import java.io.File;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import org.apache.tapestry5.annotations.Parameter;
-import org.chorem.pollen.business.PollenBusinessException;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.chorem.pollen.business.PollenContext;
import org.chorem.pollen.business.PollenProperty;
import org.chorem.pollen.ui.base.ContextLink;
@@ -41,6 +40,9 @@
public static final String THUMB_PREFIX = "thumb_";
+ @Inject
+ private PollenContext pollen;
+
/**
* Directory for files getting or saving from this context
* (ie. subdirectory where images are uploaded, main directory is defined by contextPath)
@@ -56,7 +58,7 @@
@Override
public String getContextPath() {
- return PollenProperty.IMG_DIR.getValue();
+ return pollen.getProperty(PollenProperty.IMG_DIR);
}
@Override
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/UsersAdmin.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/UsersAdmin.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/UsersAdmin.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -31,7 +31,7 @@
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
-import org.chorem.pollen.business.PollenBusinessException;
+import org.chorem.pollen.business.PollenContext;
import org.chorem.pollen.business.PollenProperty;
import org.chorem.pollen.business.business.PreventRuleManager;
import org.chorem.pollen.business.dto.UserDTO;
@@ -199,12 +199,15 @@
};
}
+ @Inject
+ private PollenContext pollen;
+
/** Envoi du mail de notification */
private void sendMailNotification(UserDTO newUser, String password) {
Map<String, String> data = new HashMap<String, String>();
- data.put("host", PollenProperty.EMAIL_HOST.getValue());
- data.put("port", PollenProperty.EMAIL_PORT.getValue());
- data.put("from", PollenProperty.EMAIL_FROM.getValue());
+ data.put("host", pollen.getProperty(PollenProperty.EMAIL_HOST));
+ data.put("port", pollen.getProperty(PollenProperty.EMAIL_PORT));
+ data.put("from", pollen.getProperty(PollenProperty.EMAIL_FROM));
data.put("to", newUser.getEmail());
data.put("title", messages.format("registerEmail_subject", newUser
.getLogin()));
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -49,6 +49,7 @@
import org.apache.tapestry5.json.JSONObject;
import org.apache.tapestry5.upload.services.UploadSymbols;
import org.chorem.pollen.business.PollenContext;
+import org.chorem.pollen.business.PollenContextImpl;
import org.chorem.pollen.business.PollenProperty;
import org.chorem.pollen.business.business.PreventRuleManager;
import org.chorem.pollen.business.dto.ChoiceDTO;
@@ -815,6 +816,9 @@
creator.getVotingId()), voteURL, messages.get("pollFeed_createContent"));
}
+ @Inject
+ private PollenContext pollen;
+
/** Envoi du mail de notification */
private void sendMailNotification(String siteURL, ServicePollAccount servicePollAccount,
PollDTO poll, Messages messages) {
@@ -822,9 +826,9 @@
String voteURL = siteURL + "poll/VoteFor/" + poll.getPollUId();
String modifURL = siteURL + "poll/Modification/" + poll.getPollUId() + ":" + creator.getAccountId();
Map<String, String> data = new HashMap<String, String>();
- data.put("host", PollenProperty.EMAIL_HOST.getValue());
- data.put("port", PollenProperty.EMAIL_PORT.getValue());
- data.put("from", PollenProperty.EMAIL_FROM.getValue());
+ data.put("host", pollen.getProperty(PollenProperty.EMAIL_HOST));
+ data.put("port", pollen.getProperty(PollenProperty.EMAIL_PORT));
+ data.put("from", pollen.getProperty(PollenProperty.EMAIL_FROM));
// Mail au créateur
if (poll.getCreatorEmail() != null) {
@@ -867,8 +871,8 @@
// send mail preparation
try {
- PollenContext.getSendMail().prepareMails(poll.getId(), mailList);
- PollenContext.getSendMail().wakeUp();
+ pollen.getSendMail().prepareMails(poll.getId(), mailList);
+ pollen.getSendMail().wakeUp();
} catch (IOException ex) {
if (log.isErrorEnabled()) {
log.error("Can't prepare send mail on disk, mail won't be send !!!", ex);
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollModification.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollModification.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollModification.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -38,7 +38,6 @@
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.chenillekit.tapestry.core.components.DateTimeField;
-import org.chorem.pollen.business.PollenBusinessException;
import org.chorem.pollen.business.PollenContext;
import org.chorem.pollen.business.PollenProperty;
import org.chorem.pollen.business.business.PreventRuleManager;
@@ -530,13 +529,16 @@
return poll.getChoiceType() == ChoiceType.IMAGE;
}
+ @Inject
+ private PollenContext pollen;
+
/** Envoi du mail de notification */
private void sendMailNotification(List<PollAccountDTO> modifiedAccounts) {
String voteURL = siteURL + "poll/VoteFor/" + poll.getPollUId();
Map<String, String> data = new HashMap<String, String>();
- data.put("host", PollenProperty.EMAIL_HOST.getValue());
- data.put("port", PollenProperty.EMAIL_PORT.getValue());
- data.put("from", PollenProperty.EMAIL_FROM.getValue());
+ data.put("host", pollen.getProperty(PollenProperty.EMAIL_HOST));
+ data.put("port", pollen.getProperty(PollenProperty.EMAIL_PORT));
+ data.put("from", pollen.getProperty(PollenProperty.EMAIL_FROM));
// Mails aux votants
for (PollAccountDTO account : modifiedAccounts) {
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -53,6 +53,7 @@
import org.chorem.pollen.business.PollenBusinessException;
import org.chorem.pollen.business.PollenBusinessException.PollenExceptionType;
import org.chorem.pollen.business.PollenProperty;
+import org.chorem.pollen.business.PollenContext;
import org.chorem.pollen.business.business.PreventRuleManager;
import org.chorem.pollen.business.dto.ChoiceDTO;
import org.chorem.pollen.business.dto.CommentDTO;
@@ -587,9 +588,9 @@
String modifURL = siteURL + "poll/Modification/" + getPoll().getPollUId()
+ ":" + MD5.encode(getPoll().getCreatorId());
Map<String, String> data = new HashMap<String, String>();
- data.put("host", PollenProperty.EMAIL_HOST.getValue());
- data.put("port", PollenProperty.EMAIL_PORT.getValue());
- data.put("from", PollenProperty.EMAIL_FROM.getValue());
+ data.put("host", pollen.getProperty(PollenProperty.EMAIL_HOST));
+ data.put("port", pollen.getProperty(PollenProperty.EMAIL_PORT));
+ data.put("from", pollen.getProperty(PollenProperty.EMAIL_FROM));
// Mail au créateur
data.put("to", getPoll().getCreatorEmail());
@@ -975,8 +976,9 @@
+ @Inject
+ private PollenContext pollen;
-
@Property
private PollUri uri;
@@ -1319,7 +1321,8 @@
}
public int getPagerRange() {
- return Integer.parseInt(PollenProperty.NB_VOTES_PER_PAGE.getValue());
+ return Integer.parseInt(
+ pollen.getProperty(PollenProperty.NB_VOTES_PER_PAGE));
}
public String getNoPagerText() throws PollenBusinessException {
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/Register.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/Register.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/Register.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -30,7 +30,7 @@
import org.apache.tapestry5.corelib.components.TextField;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
-import org.chorem.pollen.business.PollenBusinessException;
+import org.chorem.pollen.business.PollenContext;
import org.chorem.pollen.business.PollenProperty;
import org.chorem.pollen.business.business.PreventRuleManager;
import org.chorem.pollen.business.dto.UserDTO;
@@ -149,13 +149,16 @@
return this;
}
+
+ @Inject
+ private PollenContext pollen;
/** Envoi du mail de notification */
private void sendMailNotification() {
Map<String, String> data = new HashMap<String, String>();
- data.put("host", PollenProperty.EMAIL_HOST.getValue());
- data.put("port", PollenProperty.EMAIL_PORT.getValue());
- data.put("from", PollenProperty.EMAIL_FROM.getValue());
+ data.put("host", pollen.getProperty(PollenProperty.EMAIL_HOST));
+ data.put("port", pollen.getProperty(PollenProperty.EMAIL_PORT));
+ data.put("from", pollen.getProperty(PollenProperty.EMAIL_FROM));
data.put("to", newUser.getEmail());
data.put("title", messages.format("registerEmail_subject", newUser
.getLogin()));
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -16,8 +16,6 @@
package org.chorem.pollen.ui.services;
-import java.math.BigDecimal;
-import org.chorem.pollen.business.services.SendMail;
import org.apache.tapestry5.SymbolConstants;
import org.apache.tapestry5.ioc.Configuration;
import org.apache.tapestry5.ioc.MappedConfiguration;
@@ -28,21 +26,29 @@
import org.apache.tapestry5.ioc.annotations.InjectService;
import org.apache.tapestry5.ioc.services.Coercion;
import org.apache.tapestry5.ioc.services.CoercionTuple;
-import org.apache.tapestry5.ioc.services.RegistryShutdownHub;
-import org.apache.tapestry5.ioc.services.RegistryShutdownListener;
import org.apache.tapestry5.ioc.services.SymbolProvider;
import org.apache.tapestry5.services.ComponentSource;
import org.apache.tapestry5.upload.services.UploadSymbols;
+import org.chorem.pollen.business.PollenContext;
+import org.chorem.pollen.business.PollenContextImpl;
+import org.chorem.pollen.business.PollenContextImplementor;
import org.chorem.pollen.business.services.ServiceAuth;
+import org.chorem.pollen.business.services.ServiceAuthImpl;
import org.chorem.pollen.business.services.ServiceChoice;
+import org.chorem.pollen.business.services.ServiceChoiceImpl;
import org.chorem.pollen.business.services.ServiceList;
+import org.chorem.pollen.business.services.ServiceListImpl;
import org.chorem.pollen.business.services.ServicePoll;
import org.chorem.pollen.business.services.ServicePollAccount;
+import org.chorem.pollen.business.services.ServicePollAccountImpl;
+import org.chorem.pollen.business.services.ServicePollImpl;
import org.chorem.pollen.business.services.ServiceResults;
+import org.chorem.pollen.business.services.ServiceResultsImpl;
import org.chorem.pollen.business.services.ServiceUser;
+import org.chorem.pollen.business.services.ServiceUserImpl;
import org.chorem.pollen.business.services.ServiceVote;
+import org.chorem.pollen.business.services.ServiceVoteImpl;
import org.chorem.pollen.ui.data.PollUri;
-import org.slf4j.Logger;
/**
* This module is automatically included as part of the Tapestry IoC Registry,
@@ -53,28 +59,81 @@
*/
public class AppModule {
- private static final String CONFIGURATION_FILE = "pollen.properties";
-
public static void bind(ServiceBinder binder) {
- // binder.bind(MyServiceInterface.class, MyServiceImpl.class);
+ // Pollen-Business services
+// binder.bind(ServiceAuth.class);
+// binder.bind(ServiceList.class);
+// binder.bind(ServiceUser.class);
+// binder.bind(ServicePoll.class);
+// binder.bind(ServicePollAccount.class);
+// binder.bind(ServiceResults.class);
+// binder.bind(ServiceVote.class);
+// binder.bind(ServiceChoice.class);
+// binder.bind(ServiceImage.class);
+// binder.bind(PollenContext.class, PollenContextImpl.class);
+ }
- // Make bind() calls on the binder object to define most IoC services.
- // Use service builder methods (example below) when the implementation
- // is provided inline, or requires more initialization than simply
- // invoking the constructor.
+ /**
+ * Build the main application context PollenContext.
+ *
+ * @return PollenContextImplementor type to use injection in services build
+ */
+ public static PollenContextImplementor buildPollenContext() {
+ PollenContextImplementor context = new PollenContextImpl();
+ context.start();
+ return context;
+ }
- // Pollen-Business services
- binder.bind(ServiceAuth.class);
- binder.bind(ServiceList.class);
- binder.bind(ServiceUser.class);
- binder.bind(ServicePoll.class);
- binder.bind(ServicePollAccount.class);
- binder.bind(ServiceResults.class);
- binder.bind(ServiceVote.class);
- binder.bind(ServiceChoice.class);
- binder.bind(ServiceImage.class);
+ /** Will be merged with serviceUser **/
+ public static ServiceAuth buildServiceAuth(
+ @InjectService("PollenContext") PollenContextImplementor context) {
+ return new ServiceAuthImpl(context);
}
+ /** Will be divided between servicePoll and serviceUser, maybe other
+ * services for LDAP or CSV
+ **/
+ public static ServiceList buildServiceList(
+ @InjectService("PollenContext") PollenContextImplementor context) {
+ return new ServiceListImpl(context);
+ }
+ public static ServiceUser buildServiceUser(
+ @InjectService("PollenContext") PollenContextImplementor context) {
+ return new ServiceUserImpl(context);
+ }
+
+ public static ServicePoll buildServicePoll(
+ @InjectService("PollenContext") PollenContextImplementor context) {
+ return new ServicePollImpl(context);
+ }
+
+ /** Will be divided between serviceVote, serviceUser and servicePoll **/
+ public static ServicePollAccount buildServicePollAccount(
+ @InjectService("PollenContext") PollenContextImplementor context) {
+ return new ServicePollAccountImpl(context);
+ }
+
+ public static ServiceResults buildServiceResults(
+ @InjectService("PollenContext") PollenContextImplementor context) {
+ return new ServiceResultsImpl(context);
+ }
+
+ public static ServiceVote buildServiceVote(
+ @InjectService("PollenContext") PollenContextImplementor context) {
+ return new ServiceVoteImpl(context);
+ }
+
+ /** Will be divided between serviceVote and servicePoll **/
+ public static ServiceChoice buildServiceChoice(
+ @InjectService("PollenContext") PollenContextImplementor context) {
+ return new ServiceChoiceImpl(context);
+ }
+
+ public static ServiceImage buildServiceImage(
+ @InjectService("PollenContext") PollenContextImplementor context) {
+ return new ServiceImageImpl(context);
+ }
+
public static void contributeApplicationDefaults(
MappedConfiguration<String, String> configuration) {
// Contributions to ApplicationDefaults will override any contributions to
@@ -96,63 +155,15 @@
configuration.add(UploadSymbols.REQUESTSIZE_MAX, "10485760");
}
- /*
- * This is a service definition, the service will be named "TimingFilter".
- * The interface, RequestFilter, is used within the RequestHandler service
- * pipeline, which is built from the RequestHandler service configuration.
- * Tapestry IoC is responsible for passing in an appropriate Logger
- * instance. Requests for static resources are handled at a higher level, so
- * this filter will only be invoked for Tapestry related requests.
- *
- * <p>
- * Service builder methods are useful when the implementation is inline as
- * an inner class (as here) or require some other kind of special
- * initialization. In most cases, use the static bind() method instead.
- *
- * <p>
- * If this method was named "build", then the service id would be taken from
- * the service interface and would be "RequestFilter". Since Tapestry
- * already defines a service named "RequestFilter" we use an explicit
- * service id that we can reference inside the contribution method.
- *
- public RequestFilter buildTimingFilter(final Logger log) {
- return new RequestFilter() {
- public boolean service(Request request, Response response,
- RequestHandler handler) throws IOException {
- long startTime = System.currentTimeMillis();
-
- try {
- // The responsibility of a filter is to invoke the corresponding method
- // in the handler. When you chain multiple filters together, each filter
- // received a handler that is a bridge to the next filter.
-
- return handler.service(request, response);
- } finally {
- long elapsed = System.currentTimeMillis() - startTime;
-
- log.info(String.format("Request time: %d ms", elapsed));
- }
- }
- };
- }*/
-
/**
- * This is the Shutdown service definition. This service is used when the
- * server shutdown. It detects the Tapestry registry shutdown.
+ * TypeCoercion for PollUri. This will convert automatically between String
+ * and PollUri. So pollUri can be used in activation/passivation page
+ * context.
+ *
+ * @param configuration
*/
- @EagerLoad
- public RegistryShutdownListener buildPollenShutdown(
- @InjectService("RegistryShutdownHub") RegistryShutdownHub hub) {
- RegistryShutdownListener listener = new PollenManager();
- hub.addRegistryShutdownListener(listener);
- return listener;
- }
-
- public static void contributeRegistryStartup(OrderedConfiguration<Runnable> configuration) {
- configuration.add("PollenStartup", new PollenManager());
- }
-
- public static void contributeTypeCoercer(Configuration<CoercionTuple> configuration) {
+ public static void contributeTypeCoercer(
+ Configuration<CoercionTuple> configuration) {
Coercion<String, PollUri> coercion1 = new Coercion<String, PollUri>() {
@Override
@@ -169,8 +180,12 @@
}
};
- configuration.add(new CoercionTuple<String, PollUri>(String.class, PollUri.class, coercion1));
- configuration.add(new CoercionTuple<PollUri, String>(PollUri.class, String.class, coercion2));
+ configuration.add(
+ new CoercionTuple<String, PollUri>(
+ String.class, PollUri.class, coercion1));
+ configuration.add(
+ new CoercionTuple<PollUri, String>(
+ PollUri.class, String.class, coercion2));
}
/**
@@ -180,42 +195,20 @@
@EagerLoad
public static BackgroundWorker buildBackgroundWorker(
ComponentSource componentSource,
- ServicePoll servicePoll) {
+ ServicePoll servicePoll, PollenContext context) {
Messages messages = componentSource.getPage("LocalMessages")
.getComponentResources().getMessages();
- return new BackgroundWorkerImpl(messages, servicePoll);
+ return new BackgroundWorkerImpl(messages, servicePoll, context);
}
- /*
- * Contribution au démarrage de services tapestry.
- *
- * Ajout de SendMail
- *
- * @param configuration configuration tapestry
- * @param conf configuration pollen
- *
- public static void contributeRegistryStartup(OrderedConfiguration<Runnable> configuration, Configuration conf) {
- configuration.add("SendMail", new SendMail(conf));
- }*/
-
/**
- * Init send mail service.
- *
- * @param conf
+ * Make configuration from a Properties file available as symbols.
+ * @param context
* @return
*/
- @EagerLoad
- public SendMail buildSendMail() {
- SendMail res = new SendMail();
- return res;
- }
-
- /**
- * Make configuration from a Properties file available as symbols.
- */
public PropertiesFileSymbolProvider buildConfigPropertiesFileSymbolProvider(
- Logger logger) {
- return new PropertiesFileSymbolProvider(logger, CONFIGURATION_FILE);
+ @InjectService("PollenContext") PollenContext context) {
+ return new PropertiesFileSymbolProvider(context);
}
/**
@@ -229,22 +222,4 @@
configPropertiesFileSymbolProvider, "after:SystemProperties",
"before:ApplicationDefaults");
}
-
- /*
- * This is a contribution to the RequestHandler service configuration. This
- * is how we extend Tapestry using the timing filter. A common use for this
- * kind of filter is transaction management or security. The @Local
- * annotation selects the desired service by type, but only from the same
- * module. Without @Local, there would be an error due to the other
- * service(s) that implement RequestFilter (defined in other modules).
- *
- public void contributeRequestHandler(
- OrderedConfiguration<RequestFilter> configuration,
- @Local RequestFilter filter) {
- // Each contribution to an ordered configuration has a name, When necessary, you may
- // set constraints to precisely control the invocation order of the contributed filter
- // within the pipeline.
-
- //configuration.add("Timing", filter);
- }*/
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/BackgroundWorkerImpl.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/BackgroundWorkerImpl.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/BackgroundWorkerImpl.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -23,10 +23,11 @@
import java.util.Timer;
import java.util.TimerTask;
-import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tapestry5.ioc.Messages;
+import org.chorem.pollen.business.PollenContext;
+import org.chorem.pollen.business.PollenContextImplementor;
import org.chorem.pollen.business.PollenProperty;
import org.chorem.pollen.business.business.PreventRuleManager;
import org.chorem.pollen.business.dto.PollAccountDTO;
@@ -58,11 +59,14 @@
/** Injection du service de gestion de sondages. */
private ServicePoll servicePoll;
+ private PollenContext context;
+
/**
* Constructeur exécuté au lancement de l'application.
*/
public BackgroundWorkerImpl(Messages messages,
- ServicePoll servicePoll) {
+ ServicePoll servicePoll, PollenContext context) {
+ this.context = context;
this.messages = messages;
this.servicePoll = servicePoll;
@@ -74,7 +78,7 @@
* Lancement des tâches en arrière-plan.
*/
public void executeTasks() {
- if (!PollenProperty.SERVER_URL.hasValue()) {
+ if (!context.hasProperty(PollenProperty.SERVER_URL)) {
log.warn("No property siteUrl. Reminder emails would not contain it");
}
@@ -126,12 +130,12 @@
* @param poll sondage concerné
*/
private void sendMailNotification(PollDTO poll, Long timeValue) {
- String voteURL = PollenProperty.SERVER_URL.getValue() + "/poll/VoteFor/"
- + poll.getPollUId();
+ String voteURL = context.getProperty(PollenProperty.SERVER_URL) +
+ "/poll/VoteFor/" + poll.getPollUId();
Map<String, String> data = new HashMap<String, String>();
- data.put("host", PollenProperty.EMAIL_HOST.getValue());
- data.put("port", PollenProperty.EMAIL_PORT.getValue());
- data.put("from", PollenProperty.EMAIL_FROM.getValue());
+ data.put("host", context.getProperty(PollenProperty.EMAIL_HOST));
+ data.put("port", context.getProperty(PollenProperty.EMAIL_PORT));
+ data.put("from", context.getProperty(PollenProperty.EMAIL_FROM));
// Mails aux votants
for (PreventRuleDTO rule : poll.getPreventRuleDTOs()) {
@@ -162,7 +166,7 @@
// désactivation de la règle de rappel pour éviter qu'elle soit réexécutée
if (hasRun) {
rule.setActive(false);
- ServicePreventRule spr = new ServicePreventRuleImpl();
+ ServicePreventRule spr = new ServicePreventRuleImpl((PollenContextImplementor)context);
spr.updatePreventRule(rule);
}
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -20,6 +20,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.tapestry5.ioc.services.RegistryShutdownListener;
import org.chorem.pollen.business.PollenContext;
+import org.chorem.pollen.business.PollenContextImpl;
/**
* Service de gestion de l'arrêt du serveur. Ce service exécute une action à la
@@ -28,24 +29,30 @@
* @author rannou
* @version $Id$
*/
-public class PollenManager implements RegistryShutdownListener, Runnable {
+public class PollenManager implements RegistryShutdownListener /*, Runnable */{
private static final Log log = LogFactory.getLog(PollenManager.class);
- @Override
- public void run() {
- if (log.isInfoEnabled()) {
- log.info("Start Pollen");
- }
- PollenContext.start();
+ private PollenContext context;
+
+ public PollenManager(PollenContext context) {
+ this.context = context;
}
+// @Override
+// public void run() {
+// if (log.isInfoEnabled()) {
+// log.info("Start Pollen");
+// }
+// context.start();
+// }
+
@Override
public void registryDidShutdown() {
if (log.isInfoEnabled()) {
log.info("Stop Pollen");
}
- PollenContext.stop();
+ context.stop();
}
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PropertiesFileSymbolProvider.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PropertiesFileSymbolProvider.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PropertiesFileSymbolProvider.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -17,6 +17,8 @@
private final Map<String, String> propertiesMap = new CaseInsensitiveMap<String>();
+ private PollenContext context;
+
/**
* Instantiate a new PropertiesFileSymbolProvider using a given resource
* name
@@ -55,11 +57,10 @@
* Instantiate a new PropertiesFileSymbolProvider using a given resource
* name (looking in filesystem and classpath)
*
- * @param logger the logger to log error messages to
- * @param resourceName the name of the resource to load
+ * @param context PollenContext
*/
- public PropertiesFileSymbolProvider(Logger logger, String resourceName) {
- Properties conf = PollenContext.getProperties();
+ public PropertiesFileSymbolProvider(PollenContext context) {
+ Properties conf = context.getConfiguration().getOptions();
initializeProperties(conf);
}
@@ -129,6 +130,7 @@
}
}
+ @Override
public String valueForSymbol(String arg0) {
return propertiesMap.get(arg0);
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java 2010-03-20 15:30:29 UTC (rev 2952)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java 2010-03-20 18:42:04 UTC (rev 2953)
@@ -41,13 +41,15 @@
private static final Logger logger = LoggerFactory.getLogger(ServiceImageImpl.class);
- public ServiceImageImpl() {
-
+ private PollenContext context;
+
+ public ServiceImageImpl(PollenContext context) {
+ this.context = context;
}
@Override
public String getContextPath() {
- return PollenContext.getProperty(PollenProperty.IMG_DIR);
+ return context.getProperty(PollenProperty.IMG_DIR);
}
/**
@@ -75,6 +77,7 @@
@Override
public StreamResponse createImageStream(String filename, String filedir, boolean thumb) {
+ // security : src containing .. are filtered, to not access to full system
if (StringUtils.isEmpty(filename) || filename.contains("..")) {
return null;
}
1
0
Author: fdesbois
Date: 2010-03-20 16:30:29 +0100 (Sat, 20 Mar 2010)
New Revision: 2952
Log:
- Rename pollId by pollUId in PollDTO
- Evo #151 : using i18n tapestry-bundle and use keys from i18n
- Evo #150 : place image managment in a new service
- Refactor VoteForPoll page (70%)
Added:
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/mixins/Confirm.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImage.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java
trunk/pollen-ui/src/main/webapp/js/confirm.js
trunk/pollen-ui/src/main/webapp/js/zoneUpdater.js
Removed:
trunk/pollen-ui/src/main/webapp/js/ZoneUpdater.js
Modified:
trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenConverter.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataChoiceConverter.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/ChoiceDTO.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/PollDTO.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoice.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoiceImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePoll.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccount.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccountImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVote.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java
trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties
trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties
trunk/pollen-business/src/main/resources/pollen.properties
trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/ContextLink.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/Polls.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Image.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ImageContextLink.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Pager.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/mixins/ZoneUpdater.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/CloseValidation.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/CreationValidation.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/ModificationValidation.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollModification.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserPollsParticipated.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/BackgroundWorkerImpl.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/ImageUtil.java
trunk/pollen-ui/src/main/resources/i18n/pollen-ui-en_GB.properties
trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties
trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_en.properties
trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_fr.properties
trunk/pollen-ui/src/main/webapp/WEB-INF/web.xml
trunk/pollen-ui/src/main/webapp/img/1leftarrow.png
trunk/pollen-ui/src/main/webapp/img/1rightarrow.png
trunk/pollen-ui/src/main/webapp/img/2leftarrow.png
trunk/pollen-ui/src/main/webapp/img/2rightarrow.png
trunk/pollen-ui/src/main/webapp/poll/CreationValidation.tml
trunk/pollen-ui/src/main/webapp/poll/PollCreation.tml
trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenConverter.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenConverter.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenConverter.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -151,7 +151,7 @@
String name = entity.getName();
dto.setHidden(name != null
&& name.startsWith(NumberMethod.HIDDEN_PREFIX));
- dto.setPollId(entity.getPoll().getTopiaId());
+ dto.setPollUId(entity.getPoll().getPollId());
return dto;
}
@@ -166,7 +166,7 @@
public static PollDTO convert(Poll entity, PollDTO dto) {
BinderProvider.getBinder(Poll.class, PollDTO.class).copy(entity, dto);
dto.setId(entity.getTopiaId());
- dto.setPollId(entity.getPollId());
+ dto.setPollUId(entity.getPollId());
dto.setChoiceType(ChoiceType.valueOf(entity.getChoiceType()));
dto.setPollType(PollType.valueOf(entity.getPollType()));
dto.setVoteCounting(VoteCountingType.valueOf(entity.getVoteCounting()));
@@ -244,12 +244,17 @@
//if (!entity.getAnonymous()) {
PollAccount account = entity.getPollAccount();
VotingList list = entity.getVotingList();
+ // Set references
// vote for a list
if (list != null) {
dto.setVotingListId(list.getTopiaId());
// vote for a person (pollAccount)
- } else if (account != null) {
+ } else {/*if (account != null) { must have a pollaccount */
dto.setPollAccountId(account.getTopiaId());
+ dto.setName(account.getVotingId());
+// if (account.getUserAccount() != null) {
+// dto.setUserId(account.getUserAccount().getTopiaId());
+// }
}
//}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataChoiceConverter.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataChoiceConverter.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataChoiceConverter.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -41,13 +41,16 @@
*
* @param choiceDTO Le dto choix
* @param eChoice L'entité choix
+ * @deprecated use {@link org.chorem.pollen.business.PollenConverter}
*/
+ @Deprecated
public void populateChoiceEntity(ChoiceDTO choiceDTO, Choice eChoice)
throws TopiaException {
eChoice.setName(choiceDTO.getName());
eChoice.setDescription(choiceDTO.getDescription());
eChoice.setValidate(choiceDTO.isValidate());
+ // Very bad, must create the choice on the poll not the inverse
if (choiceDTO.getPollId().length() > 0) {
PollDAO pollDAO = PollenModelDAOHelper
.getPollDAO(super.transaction);
@@ -61,7 +64,7 @@
*
* @param eChoice L'entité choix
* @return Le dto choix
- * @deprecated use {@link ConverterHelper}
+ * @deprecated use {@link org.chorem.pollen.business.PollenConverter}
*/
@Deprecated
public ChoiceDTO createChoiceDTO(Choice eChoice) {
@@ -75,7 +78,7 @@
choiceDTO.setValidate(eChoice.getValidate());
if (eChoice.getPoll() != null) {
- choiceDTO.setPollId(eChoice.getPoll().getTopiaId());
+ choiceDTO.setPollUId(eChoice.getPoll().getPollId());
}
return choiceDTO;
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/ChoiceDTO.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/ChoiceDTO.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/ChoiceDTO.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -61,6 +61,11 @@
*/
private String pollId = "";
+ /**
+ * pollUId of the poll owner of this choice
+ */
+ private String pollUId;
+
/** used for specific choice in Number VoteCounting **/
private Boolean hidden = false;
@@ -68,14 +73,16 @@
}
+ @Deprecated
public ChoiceDTO(String id) {
this.id = id;
}
+ @Deprecated
public ChoiceDTO(String name, String voteId, String pollId) {
this.name = name;
this.voteId = voteId;
- this.pollId = pollId;
+ //this.pollId = pollId;
}
public String getId() {
@@ -138,6 +145,14 @@
this.pollId = pollId;
}
+ public String getPollUId() {
+ return pollUId;
+ }
+
+ public void setPollUId(String pollUId) {
+ this.pollUId = pollUId;
+ }
+
public Boolean isHidden() {
return hidden;
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/PollDTO.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/PollDTO.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/PollDTO.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -37,7 +37,7 @@
private String id = "";
- private String pollId = "";
+ private String pollUId;
private String title = "";
@@ -90,7 +90,7 @@
private List<PreventRuleDTO> preventRuleDTOs = new ArrayList<PreventRuleDTO>();
- private List<ChoiceDTO> choiceDTOs = new ArrayList<ChoiceDTO>();
+ private List<ChoiceDTO> choices = new ArrayList<ChoiceDTO>();
private List<ResultDTO> resultDTOs = new ArrayList<ResultDTO>();
@@ -120,12 +120,12 @@
this.id = id;
}
- public String getPollId() {
- return pollId;
+ public String getPollUId() {
+ return pollUId;
}
- public void setPollId(String pollId) {
- this.pollId = pollId;
+ public void setPollUId(String pollId) {
+ this.pollUId = pollId;
}
public String getTitle() {
@@ -384,20 +384,35 @@
}
public List<ChoiceDTO> getChoices() {
- return choiceDTOs;
+ return choices;
}
public void setChoices(List<ChoiceDTO> choiceDTOs) {
- this.choiceDTOs = choiceDTOs;
+ this.choices = choiceDTOs;
}
public void addChoice(ChoiceDTO choice) {
- if (choiceDTOs == null) {
- choiceDTOs = new ArrayList<ChoiceDTO>();
+ if (choices == null) {
+ choices = new ArrayList<ChoiceDTO>();
}
- choiceDTOs.add(choice);
+ choices.add(choice);
}
+ public boolean removeChoice(String choiceId) {
+ if (choices == null) {
+ return false;
+ }
+ Iterator<ChoiceDTO> it = choices.iterator();
+ while (it.hasNext()) {
+ ChoiceDTO choice = it.next();
+ if (choiceId.equals(choice.getId())) {
+ it.remove();
+ return true;
+ }
+ }
+ return false;
+ }
+
public List<ResultDTO> getResultDTOs() {
return resultDTOs;
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoice.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoice.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoice.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -40,17 +40,6 @@
public String createChoice(ChoiceDTO choice);
/**
- * Création des choix du sondage
- *
- * @param choices les dtos choix
- * @param pollId l'identifiant du sondage
- * @param transaction la transaction du sondage
- * @return les choix créés
- */
- public List<Choice> createChoices(List<ChoiceDTO> choices, String pollId,
- TopiaContext transaction);
-
- /**
* Mise à jour d'un choix pour un sondage
*
* @param choiceDTO
@@ -63,7 +52,9 @@
*
* @param choiceId l'identifiant du choix
* @return true si le choix a été mis à jours
+ * @deprecated use {@link org.chorem.pollen.business.services.ServicePoll#deleteChoice(org.chorem.pollen.business.dto.PollDTO, java.lang.String) }
*/
+ @Deprecated
public boolean deleteChoice(String choiceId);
/**
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoiceImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoiceImpl.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoiceImpl.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -81,34 +81,34 @@
}
}
- @Override
- public List<Choice> createChoices(List<ChoiceDTO> choices, String pollId,
- TopiaContext transaction) {
- if (choices.isEmpty() || pollId.length() == 0) {
- return null;
- }
+// @Override
+// public List<Choice> createChoices(List<ChoiceDTO> choices, String pollId,
+// TopiaContext transaction) {
+// if (choices.isEmpty() || pollId.length() == 0) {
+// return null;
+// }
+//
+// List<Choice> result = null;
+// try {
+// choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction);
+// converter.setTransaction(transaction);
+//
+// result = new ArrayList<Choice>();
+// for (ChoiceDTO choice : choices) {
+// Choice choiceEntity = choiceDAO.create();
+// choice.setId(choiceEntity.getTopiaId());
+// //choice.setPollUId(pollId);
+// converter.populateChoiceEntity(choice, choiceEntity);
+// result.add(choiceEntity);
+// }
+//
+// return result;
+// } catch (Exception e) {
+// ContextUtil.doCatch(e, transaction);
+// return null;
+// }
+// }
- List<Choice> result = null;
- try {
- choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction);
- converter.setTransaction(transaction);
-
- result = new ArrayList<Choice>();
- for (ChoiceDTO choice : choices) {
- Choice choiceEntity = choiceDAO.create();
- choice.setId(choiceEntity.getTopiaId());
- choice.setPollId(pollId);
- converter.populateChoiceEntity(choice, choiceEntity);
- result.add(choiceEntity);
- }
-
- return result;
- } catch (Exception e) {
- ContextUtil.doCatch(e, transaction);
- return null;
- }
- }
-
@Override
public boolean updateChoice(ChoiceDTO choiceDTO) {
TopiaContext transaction = null;
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePoll.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePoll.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePoll.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -18,6 +18,7 @@
import java.util.List;
import java.util.Map;
+import org.chorem.pollen.business.dto.ChoiceDTO;
import org.chorem.pollen.business.dto.CommentDTO;
import org.chorem.pollen.business.dto.PollAccountDTO;
import org.chorem.pollen.business.dto.PollDTO;
@@ -75,7 +76,7 @@
* @param pollId identifiant du sondage (différent du topiaId)
* @return le sondage
*/
- public PollDTO findPollByPollId(String pollId);
+ public PollDTO getPoll(String pollId);
/**
* Récupération des sondages d'un utilisateur
@@ -154,4 +155,8 @@
* pollAccount in poll restriction for the accountUId in argument
*/
public PollAccountDTO getRestrictedAccount(String accountUId, PollDTO poll);
+
+ public ChoiceDTO getNewHiddenChoice(ChoiceDTO choice, String votingId);
+
+ public void deleteChoice(PollDTO poll, String choiceId);
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccount.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccount.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccount.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -17,9 +17,9 @@
package org.chorem.pollen.business.services;
import java.util.List;
-import java.util.Map;
import org.chorem.pollen.business.dto.PollAccountDTO;
+import org.chorem.pollen.business.dto.UserDTO;
import org.chorem.pollen.business.persistence.PollAccount;
import org.nuiton.topia.TopiaContext;
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccountImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccountImpl.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccountImpl.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -18,20 +18,17 @@
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
import java.util.UUID;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.business.PollenBusinessException;
import org.chorem.pollen.business.PollenContext;
import org.chorem.pollen.business.converters.DataPollAccountConverter;
import org.chorem.pollen.business.dto.PollAccountDTO;
+import org.chorem.pollen.business.dto.UserDTO;
import org.chorem.pollen.business.persistence.PollAccount;
import org.chorem.pollen.business.persistence.PollAccountDAO;
import org.chorem.pollen.business.persistence.PollenModelDAOHelper;
-import org.chorem.pollen.business.persistence.UserAccount;
-import org.chorem.pollen.business.persistence.UserAccountDAO;
import org.chorem.pollen.business.utils.ContextUtil;
import org.nuiton.topia.TopiaContext;
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -56,6 +56,7 @@
import org.chorem.pollen.business.persistence.PersonToListDAO;
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.common.VoteCountingType;
+import org.chorem.pollen.votecounting.business.NumberMethod;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaQuery;
@@ -77,7 +78,7 @@
private DataPollConverter converter = new DataPollConverter();
/** log. */
private static final Log log = LogFactory.getLog(ServicePollImpl.class);
-
+
public ServicePollImpl() {
rootContext = PollenContext.getRootContext();
@@ -95,12 +96,17 @@
TopiaContext transaction = null;
String result = null;
try {
+
+ if (log.isInfoEnabled()) {
+ log.info("P:[ createPoll ] : " + pollDTO);
+ }
+
transaction = rootContext.beginTransaction();
pollDAO = PollenModelDAOHelper.getPollDAO(transaction);
// Create with the pollId from dto
- String pollId = pollDTO.getPollId();
+ String pollId = pollDTO.getPollUId();
Poll entity = pollDAO.create(pollId);
PollenConverter.convert(pollDTO, entity);
@@ -243,6 +249,11 @@
public boolean updatePoll(PollDTO pollDTO) {
TopiaContext transaction = null;
try {
+
+ if (log.isInfoEnabled()) {
+ log.info("P:[ updatePoll ] : " + pollDTO);
+ }
+
transaction = rootContext.beginTransaction();
pollDAO = PollenModelDAOHelper.getPollDAO(transaction);
@@ -276,7 +287,7 @@
} catch (Exception eee) {
PollenContext.doCatch(transaction, eee,
n_("pollen.error.servicePoll.updatePoll"),
- pollDTO.getTitle(), pollDTO.getPollId());
+ pollDTO.getTitle(), pollDTO.getPollUId());
return false;
} finally {
PollenContext.doFinally(transaction);
@@ -288,7 +299,7 @@
PollDTO newPoll = new PollDTO();
newPoll.setVoteCounting(VoteCountingType.NORMAL);
newPoll.setPollType(PollType.FREE);
- newPoll.setPollId(PollenContext.createPollenUrlId());
+ newPoll.setPollUId(PollenContext.createPollenUrlId());
return newPoll;
}
@@ -302,6 +313,11 @@
public boolean deletePoll(String pollId) {
TopiaContext transaction = null;
try {
+
+ if (log.isInfoEnabled()) {
+ log.info("P:[ deletePoll ] : pollId = " + pollId);
+ }
+
transaction = rootContext.beginTransaction();
pollDAO = PollenModelDAOHelper.getPollDAO(transaction);
@@ -326,12 +342,12 @@
}
@Override
- public PollDTO findPollByPollId(String pollId) {
+ public PollDTO getPoll(String pollId) {
TopiaContext transaction = null;
PollDTO result = null;
try {
if (log.isInfoEnabled()) {
- log.info("findPollByPollId : pollUId = " + pollId);
+ log.info("P:[ getPoll ] : pollUId = " + pollId);
}
transaction = rootContext.beginTransaction();
@@ -628,7 +644,7 @@
TopiaContext transaction = null;
try {
if (log.isInfoEnabled()) {
- log.info("createComment : pollUId = " + poll.getPollId() +
+ log.info("P:[ createComment ] : pollUId = " + poll.getPollUId() +
" _ comment = " + comment);
}
transaction = rootContext.beginTransaction();
@@ -665,7 +681,7 @@
TopiaContext transaction = null;
try {
if (log.isInfoEnabled()) {
- log.info("deleteComment : pollUId = " + poll.getPollId() +
+ log.info("P:[ deleteComment ] : pollUId = " + poll.getPollUId() +
" _ commentId = " + commentId);
}
transaction = rootContext.beginTransaction();
@@ -702,13 +718,13 @@
List<CommentDTO> results = new ArrayList<CommentDTO>();
try {
if (log.isInfoEnabled()) {
- log.info("getComments : pollUId = " + poll.getPollId());
+ log.info("P:[ getComments ] : pollUId = " + poll.getPollUId());
}
transaction = rootContext.beginTransaction();
CommentDAO dao = PollenModelDAOHelper.getCommentDAO(transaction);
TopiaQuery query = dao.createQuery().
- add(Comment.POLL + "." + Poll.POLL_ID, poll.getPollId());
+ add(Comment.POLL + "." + Poll.POLL_ID, poll.getPollUId());
List<Comment> entities = dao.findAllByQuery(query);
@@ -736,8 +752,8 @@
transaction = rootContext.beginTransaction();
if (log.isInfoEnabled()) {
- log.info("getRestrictedAccount : accountUId = " + accountUId +
- " _ pollUId = " + poll.getPollId());
+ log.info("P:[ getRestrictedAccount ] : accountUId = " + accountUId +
+ " _ pollUId = " + poll.getPollUId());
}
// Use PersonToList association entity to find coherence between
@@ -755,7 +771,7 @@
add(PersonToList.POLL_ACCOUNT + "." +
PollAccount.ACCOUNT_ID, accountUId).
add(PersonToList.VOTING_LIST + "." +
- VotingList.POLL + "." + Poll.POLL_ID, poll.getPollId());
+ VotingList.POLL + "." + Poll.POLL_ID, poll.getPollUId());
PersonToList assoc = dao.findByQuery(query);
@@ -767,10 +783,59 @@
} catch (Exception eee) {
PollenContext.doCatch(transaction, eee,
n_("pollen.error.servicePoll.getRestrictedAccount"),
- accountUId, poll.getPollId());
+ accountUId, poll.getPollUId());
} finally {
PollenContext.doFinally(transaction);
}
return result;
}
+
+ @Override
+ public ChoiceDTO getNewHiddenChoice(ChoiceDTO choice, String votingId) {
+ ChoiceDTO hiddenChoice = new ChoiceDTO();
+ hiddenChoice.setName(NumberMethod.HIDDEN_PREFIX +
+ choice.getName() + "#" + votingId);
+ hiddenChoice.setHidden(true);
+ hiddenChoice.setValue(choice.getValue()); // ??
+ hiddenChoice.setPollUId(choice.getPollUId());
+ hiddenChoice.setVoteId(choice.getVoteId()); // ??
+ hiddenChoice.setValidate(false);
+ return hiddenChoice;
+ }
+
+ @Override
+ public void deleteChoice(PollDTO poll, String choiceId) {
+ TopiaContext transaction = null;
+ try {
+ if (log.isInfoEnabled()) {
+ log.info("P:[ deleteChoice ] : pollUId = " + poll.getPollUId() +
+ " _ choiceId = " + choiceId);
+ }
+ transaction = rootContext.beginTransaction();
+
+ // Find the comment
+ ChoiceDAO dao = PollenModelDAOHelper.getChoiceDAO(transaction);
+ Choice eChoice = dao.findByTopiaId(choiceId);
+
+ // Get the poll entity corresponding
+ Poll ePoll = PollenModelDAOHelper.getPollDAO(transaction).
+ findByTopiaId(poll.getId());
+
+ // The remove will delete the choice because no poll will be
+ // attached to him (delete-orphan)
+ ePoll.removeChoice(eChoice);
+
+ transaction.commitTransaction();
+
+ // Update change in dto
+ poll.removeChoice(choiceId);
+
+ } catch (Exception eee) {
+ PollenContext.doCatch(transaction, eee,
+ n_("pollen.error.servicePoll.deleteChoice"), choiceId,
+ poll.getTitle(), poll.getId());
+ } finally {
+ PollenContext.doFinally(transaction);
+ }
+ }
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVote.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVote.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVote.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -21,6 +21,7 @@
import org.chorem.pollen.business.dto.PollAccountDTO;
import org.chorem.pollen.business.dto.PollDTO;
+import org.chorem.pollen.business.dto.UserDTO;
import org.chorem.pollen.business.dto.VoteDTO;
/**
@@ -68,6 +69,8 @@
public List<VoteDTO> getVotesByPoll(PollDTO poll,
int startIndex, int endIndex);
+ public PollAccountDTO getNewPollAccount(UserDTO user);
+
/**
* Test if the {@code votingId} has already voted for the {@code poll}.
*
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -23,10 +23,12 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.business.PollenContext;
+import org.chorem.pollen.business.PollenConverter;
import org.chorem.pollen.business.converters.DataPollAccountConverter;
import org.chorem.pollen.business.converters.DataVoteConverter;
import org.chorem.pollen.business.dto.PollAccountDTO;
import org.chorem.pollen.business.dto.PollDTO;
+import org.chorem.pollen.business.dto.UserDTO;
import org.chorem.pollen.business.dto.VoteDTO;
import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.PollAccount;
@@ -56,6 +58,8 @@
public ServiceVoteImpl() {
rootContext = PollenContext.getRootContext();
+
+ PollenConverter.prepareVoteConverters();
}
@Override
@@ -195,7 +199,8 @@
List<VoteDTO> results = new ArrayList<VoteDTO>();
try {
if (log.isInfoEnabled()) {
- log.info("getVotesByPoll : pollUId = " + poll.getPollId() +
+ log.info("P:[ getVotesByPoll ] : " +
+ "pollUId = " + poll.getPollUId() +
" _ startIndex = " + startIndex +
" _ endIndex = " + endIndex);
}
@@ -221,22 +226,26 @@
// Order the results by creation date (the last vote done will be
// at the end of the list)
TopiaQuery query = voteDAO.createQuery().
- add(Vote.POLL + "." + Poll.POLL_ID, poll.getPollId()).
+ add(Vote.POLL + "." + Poll.POLL_ID, poll.getPollUId()).
addOrder(TopiaEntity.TOPIA_CREATE_DATE).
setLimit(startIndex, endIndex);
- List<Vote> votes = voteDAO.findAllByQuery(query);
+ List<Vote> eVotes = voteDAO.findAllByQuery(query);
if (log.isDebugEnabled()) {
- log.debug("Nb votes found : " + votes.size());
+ log.debug("Nb votes found : " + eVotes.size());
}
- converter.setTransaction(transaction);
- results = converter.createVoteDTOs(votes);
+ for (Vote eVote : eVotes) {
+ VoteDTO vote = PollenConverter.convert(eVote, new VoteDTO());
+ results.add(vote);
+ }
+// converter.setTransaction(transaction);
+// results = converter.createVoteDTOs(votes);
} catch (Exception eee) {
PollenContext.doCatch(transaction, eee,
n_("pollen.error.serviceVote.getVotesByPoll"),
- poll.getPollId());
+ poll.getPollUId());
} finally {
PollenContext.doFinally(transaction);
}
@@ -244,13 +253,32 @@
}
@Override
+ public PollAccountDTO getNewPollAccount(UserDTO user) {
+ PollAccountDTO result = new PollAccountDTO();
+ if (user == null) {
+ return result;
+ }
+ if (user.getFirstName() != null && user.getLastName() != null) {
+ result.setVotingId(
+ user.getFirstName() + " " + user.getLastName());
+
+ } else if (user.getFirstName() != null) {
+ result.setVotingId(user.getFirstName());
+
+ } else if (user.getLastName() != null) {
+ result.setVotingId(user.getLastName());
+ }
+ return result;
+ }
+
+ @Override
public boolean hasAlreadyVoted(String votingId, PollDTO poll) {
TopiaContext transaction = null;
boolean result = false;
try {
if (log.isInfoEnabled()) {
- log.info("hasAlreadyVoted : votingId = " + votingId +
- " _ pollUId = " + poll.getPollId());
+ log.info("P:[ hasAlreadyVoted ] : votingId = " + votingId +
+ " _ pollUId = " + poll.getPollUId());
}
transaction = rootContext.beginTransaction();
@@ -265,7 +293,7 @@
// Test using a count on votes
TopiaQuery query = new TopiaQuery(Vote.class).
- add(Vote.POLL + "." + Poll.POLL_ID, poll.getPollId()).
+ add(Vote.POLL + "." + Poll.POLL_ID, poll.getPollUId()).
add(Vote.POLL_ACCOUNT + "." + PollAccount.VOTING_ID,
votingId);
@@ -278,7 +306,7 @@
} catch (Exception eee) {
PollenContext.doCatch(transaction, eee,
n_("pollen.error.serviceVote.hasAlreadyVoted"),
- votingId, poll.getPollId());
+ votingId, poll.getPollUId());
} finally {
PollenContext.doFinally(transaction);
}
@@ -298,8 +326,7 @@
if (properties == null) {
voteEntities = voteDAO.findAll();
if (log.isWarnEnabled()) {
- log
- .warn("Attention : tous les votes ont été sélectionnés !");
+ log.warn("Attention : tous les votes ont été sélectionnés !");
}
} else {
voteEntities = voteDAO.findAllByProperties(properties);
Modified: trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties
===================================================================
--- trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties 2010-03-20 15:30:29 UTC (rev 2952)
@@ -9,6 +9,7 @@
pollen.error.servicePoll.addComment=
pollen.error.servicePoll.createPoll=
pollen.error.servicePoll.delete=
+pollen.error.servicePoll.deleteChoice=
pollen.error.servicePoll.deleteComment=
pollen.error.servicePoll.deletePoll=
pollen.error.servicePoll.getAllPolls=
Modified: trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties
===================================================================
--- trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties 2010-03-20 15:30:29 UTC (rev 2952)
@@ -8,6 +8,7 @@
pollen.error.serviceList.deleteAccountFromPersonList=
pollen.error.servicePoll.addComment=Impossible d'ajouter un nouveau commentaire cr\u00E9\u00E9 par %1$s pour le sondage %2$s (%3$s)
pollen.error.servicePoll.createPoll=Impossible d'enregistrer le sondage %1$s cr\u00E9\u00E9 par %2$s
+pollen.error.servicePoll.deleteChoice=
pollen.error.servicePoll.deleteComment=Impossible de supprimer le commentaire ayant pour identifiant "%1$s", appartenenant au sondage %2$s (%3$s)
pollen.error.servicePoll.deletePoll=Impossible de supprimer le sondage ayant pou identifiant "%1$s"
pollen.error.servicePoll.getAllPolls=
Modified: trunk/pollen-business/src/main/resources/pollen.properties
===================================================================
--- trunk/pollen-business/src/main/resources/pollen.properties 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-business/src/main/resources/pollen.properties 2010-03-20 15:30:29 UTC (rev 2952)
@@ -20,7 +20,7 @@
topia.service.migration.mappingsdir=oldmappings
topia.service.migration.modelnames=pollen
-## Initialisation de la base de donn\u00C3\u00A9es
+## Initialisation de la base de donn\u00E9es
#choiceType=DATE,IMAGE,TEXT
#pollType=RESTRICTED,FREE,GROUP
#voteCounting=NORMAL,PERCENTAGE,CONDORCET,NUMBER
@@ -31,7 +31,7 @@
adminEmail=admin(a)domain.com
## R\u00C3\u00A9pertoire des images transf\u00C3\u00A9r\u00C3\u00A9es
-upImgDir=.pollen/uploadedImages
+upImgDir=${HOME}/.pollen/uploadedImages
## Taille maximal des images transf\u00C3\u00A9r\u00C3\u00A9es (en octets)
upload.filesize-max=1048576
@@ -42,11 +42,11 @@
email_port=25
email_from=bot(a)pollen.org
-## R\u00C3\u00A9pertoire des flux de syndication (Atom)
-feedDir=.pollen/feeds
+## R\u00E9pertoire des flux de syndication (Atom)
+feedDir=${HOME}/.pollen/feeds
## Repertoire de stockage des mails a envoyer
-pollen.emails.directory=.pollen/emails
+pollen.emails.directory=${HOME}/.pollen/emails
## Nombre de votes a afficher par page
pollen.ui.nbVotesPerPage=25
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -47,6 +47,7 @@
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.nuiton.util.beans.BinderProvider;
/**
* Tests du service de gestion des sondages.
@@ -78,6 +79,7 @@
@After
public void tearDown() throws IOException {
TestManager.stop();
+ BinderProvider.clear();
}
/**
@@ -203,9 +205,9 @@
dto.setChoiceType(ChoiceType.TEXT);
dto.setVoteCounting(VoteCountingType.NORMAL);
pollId = instance.createPoll(dto);
- String pollUID = dto.getPollId();
+ String pollUID = dto.getPollUId();
log.debug("pollUID : " + pollUID);
- PollDTO result = instance.findPollByPollId(pollUID);
+ PollDTO result = instance.getPoll(pollUID);
log.debug("title : " + result.getTitle());
assertEquals(pollId, result.getId());
assertEquals(VoteCountingType.NORMAL, result.getVoteCounting());
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/ContextLink.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/ContextLink.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/ContextLink.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -21,16 +21,16 @@
/**
* ContextPath for the link
+ *
* @return a String contextPath
- * @
*/
public String getContextPath() ;
/**
* Get a file from context with name defined by filename.
+ *
* @param filename name of the file to get
* @return a File with absolutePath corresponding to contextPath + filename
- * @
*/
public File getFile(String filename) ;
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/Polls.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/Polls.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/Polls.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -135,7 +135,7 @@
public String getAdminId() {
PollAccountDTO creator = servicePollAccount.findPollAccountById(poll
.getCreatorId());
- return poll.getPollId() + ":" + creator.getAccountId();
+ return poll.getPollUId() + ":" + creator.getAccountId();
}
/**
@@ -170,7 +170,7 @@
}
confirmPoll.setBackPage(backPage);
confirmPoll.setAction(pollAction);
- confirmPoll.setPoll(servicePoll.findPollByPollId(pollId));
+ confirmPoll.setPoll(servicePoll.getPoll(pollId));
return confirmPoll;
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Image.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Image.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Image.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -49,7 +49,9 @@
*
* @author rannou
* @version $Id$
+ * @deprecated use links + event + serviceImage depends on page
*/
+@Deprecated
public class Image extends ImageContextLink {
/** Chemin de l'image */
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ImageContextLink.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ImageContextLink.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ImageContextLink.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -34,7 +34,9 @@
*
* Mise a jour: $Date$
* par : $Author$
+ * @deprecated use {@link org.chorem.pollen.ui.services.ServiceImage } instead
*/
+@Deprecated
public class ImageContextLink implements ContextLink {
public static final String THUMB_PREFIX = "thumb_";
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Pager.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Pager.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Pager.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -92,6 +92,7 @@
void beginRender(MarkupWriter writer) {
if (log.isDebugEnabled()) {
log.debug("pager from : " + getFirstValue() + " to " + getLastValue());
+ log.debug("nb rows per page : " + nbRowsPerPage);
log.debug("current page : " + currentPage);
log.debug("max nb rows : " + nbTotalRows);
log.debug("has previous : " + hasPrevious());
@@ -101,7 +102,7 @@
}
writer.element("div", "class", "p-pager");
// If firstPage and lastPage are the same, no need to use the pager
- if (getFirstPage() == getLastPage()) {
+ if (getFirstPage() >= getLastPage()) {
writer.write(noPagerText);
} else {
if (hasPrevious()) {
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/ChoiceField.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -7,11 +7,13 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.fileupload.FileUploadException;
+import org.apache.tapestry5.StreamResponse;
import org.apache.tapestry5.upload.services.UploadedFile;
import org.chorem.pollen.business.PollenProperty;
import org.chorem.pollen.business.dto.ChoiceDTO;
import org.chorem.pollen.common.ChoiceType;
import org.chorem.pollen.ui.utils.ImageUtil;
+import org.nuiton.util.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,6 +35,7 @@
*
* @author fdesbois
* @version $Revision$
+ * @since 1.3
*
* Mise a jour: $Date$
* par : $Author$
@@ -43,26 +46,57 @@
protected ChoiceType type;
- protected DateFormat dateFormat;
-
protected Date date;
protected UploadedFile image;
+ protected String imageFileName;
+
protected String imageDir;
protected String text;
+ public ChoiceField() {
+
+ }
+
+ public ChoiceField(ChoiceDTO dto, ChoiceType type) {
+ if (log.isDebugEnabled()) {
+ log.debug("Instanciate ChoiceField : type = " + type +
+ " _ name = " + dto.getName());
+ }
+ switch (type) {
+ case DATE:
+ setDateType();
+ setDate(new Date(Long.parseLong(dto.getName())));
+ break;
+ case TEXT:
+ setTextType();
+ setText(dto.getName());
+ break;
+ case IMAGE:
+ setImageType(dto.getPollUId());
+ setImageFileName(dto.getName());
+ }
+ setDescription(dto.getDescription());
+ setHidden(dto.getHidden());
+ setId(dto.getId());
+ setValidate(dto.getValidate());
+ setPollUId(dto.getPollUId());
+ setName(dto.getName());
+ //setValue(dto.getValue());
+ //setVoteId(dto.getVoteId());
+ }
+
/**
* Instantiate a new choiceField for a Date ChoiceType.
*
- * @param pattern date pattern to format the date when name will be saved
* @return the ChoiceField which is date typed
* @see #setDateType(java.lang.String)
*/
- public static ChoiceField getChoiceDate(String pattern) {
+ public static ChoiceField getChoiceDate() {
ChoiceField result = new ChoiceField();
- result.setDateType(pattern);
+ result.setDateType();
return result;
}
@@ -96,12 +130,10 @@
* Change type of the choice to date type. The date type need a
* {@code pattern} to format the date when saving the choice.
*
- * @param pattern
* @see #saveName()
*/
- public void setDateType(String pattern) {
+ public void setDateType() {
this.type = ChoiceType.DATE;
- dateFormat = new SimpleDateFormat(pattern);
image = null;
}
@@ -149,6 +181,21 @@
return image;
}
+ public void setImageFileName(String filename) {
+ this.imageFileName = filename;
+ }
+
+ public String getImageFileName() {
+ if (imageFileName == null && image != null) {
+ imageFileName = image.getFileName();
+ }
+ return imageFileName;
+ }
+
+ public String getImageDir() {
+ return imageDir;
+ }
+
public void setText(String text) {
this.text = text;
}
@@ -160,7 +207,7 @@
/**
* Save name of the choice depends on ChoiceType :
* <pre>
- * - DATE : the date will be formated ;
+ * - DATE : the date will be formated (only full time is used) ;
* - IMAGE : the image file will be saved and the choice name will
* correspond to the image file name ;
* - TEXT : the text becomes the choice name.
@@ -169,29 +216,29 @@
public void saveName() {
String name = "";
switch (type) {
- case DATE:
- name = dateFormat.format(getDate());
+ case DATE:
+ name = String.valueOf(date.getTime());
break;
case IMAGE:
- // Get directory to save the image using the context from
- // pollen properties.
- File dir = new File(PollenProperty.IMG_DIR.getValue(), imageDir);
- if (!dir.exists()) {
- dir.mkdirs();
- }
- // Save the image file
- File file = new File(dir, image.getFileName());
- image.write(file);
- if (log.isDebugEnabled()) {
- log.debug("Image saved: " + image.getFileName() +
- " (size=" + image.getSize() + ")");
- }
- // Create image thumbnail
- ImageUtil.createThumbnail(dir, file, 100);
- if (log.isDebugEnabled()) {
- log.debug("save name for image : " + file.getName());
- }
- name = file.getName();
+// // Get directory to save the image using the context from
+// // pollen properties.
+// File dir = new File(PollenProperty.IMG_DIR.getValue(), imageDir);
+// if (!dir.exists()) {
+// dir.mkdirs();
+// }
+// // Save the image file
+// File file = new File(dir, getImageFileName());
+// image.write(file);
+// if (log.isDebugEnabled()) {
+// log.debug("Image saved: " + getImageFileName() +
+// " (size=" + image.getSize() + ")");
+// }
+// // Create image thumbnail
+// ImageUtil.createThumbnail(dir, file, 100);
+// if (log.isDebugEnabled()) {
+// log.debug("save name for image : " + file.getName());
+// }
+ //name = serviceImage.saveImage(getImage(), getImageDir());
break;
case TEXT:
name = getText();
Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/mixins/Confirm.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/mixins/Confirm.java (rev 0)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/mixins/Confirm.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -0,0 +1,47 @@
+package org.chorem.pollen.ui.mixins;
+
+import org.apache.tapestry5.BindingConstants;
+import org.apache.tapestry5.ClientElement;
+import org.apache.tapestry5.RenderSupport;
+import org.apache.tapestry5.annotations.AfterRender;
+import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary;
+import org.apache.tapestry5.annotations.InjectContainer;
+import org.apache.tapestry5.annotations.Parameter;
+import org.apache.tapestry5.ioc.annotations.Inject;
+
+/**
+ * Confirm.java
+ *
+ * A simple mixin for attaching a javascript confirmation box to the onclick
+ * event of any component that implements ClientElement.
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author: fdesbois $
+ */
+@IncludeJavaScriptLibrary("context:js/confirm.js")
+public class Confirm {
+
+ @Parameter(value = "Are you sure?", defaultPrefix = BindingConstants.MESSAGE)
+ private String message;
+
+ @Inject
+ private RenderSupport renderSupport;
+
+ @InjectContainer
+ private ClientElement element;
+
+ @Parameter
+ private boolean wDisabled;
+
+ @AfterRender
+ public void afterRender() {
+ if (!wDisabled) {
+ renderSupport.addScript(String.format("new Confirm('%s', '%s');",
+ element.getClientId(), message));
+ }
+ }
+
+}
Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/mixins/Confirm.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/mixins/ZoneUpdater.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/mixins/ZoneUpdater.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/mixins/ZoneUpdater.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -43,7 +43,7 @@
* Last update: $Date$
* by : $Author: fdesbois $
*/
-@IncludeJavaScriptLibrary("context:js/ZoneUpdater.js")
+@IncludeJavaScriptLibrary("context:js/zoneUpdater.js")
public class ZoneUpdater {
public static final String PLACEHOLDER = "XXX";
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/CloseValidation.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/CloseValidation.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/CloseValidation.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -103,7 +103,7 @@
* @return l'identifiant.
*/
public String getAdminId() {
- return poll.getPollId() + ":" + creator.getAccountId();
+ return poll.getPollUId() + ":" + creator.getAccountId();
}
void onActivate() {
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/CreationValidation.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/CreationValidation.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/CreationValidation.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -103,7 +103,7 @@
* @return l'identifiant.
*/
public String getAdminId() {
- return poll.getPollId() + ":" + creator.getAccountId();
+ return poll.getPollUId() + ":" + creator.getAccountId();
}
void onActivate() {
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/ModificationValidation.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/ModificationValidation.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/ModificationValidation.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -103,7 +103,7 @@
* @return l'identifiant.
*/
public String getAdminId() {
- return poll.getPollId() + ":" + creator.getAccountId();
+ return poll.getPollUId() + ":" + creator.getAccountId();
}
void onActivate() {
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -73,8 +73,8 @@
import org.chorem.pollen.ui.data.PollStep;
import org.chorem.pollen.ui.data.uio.DateChoiceUIO;
import org.chorem.pollen.ui.data.uio.ImageChoiceUIO;
+import org.chorem.pollen.ui.services.ServiceImage;
import org.chorem.pollen.ui.utils.FeedUtil;
-import org.chorem.pollen.ui.utils.ImageUtil;
import org.chorem.pollen.ui.utils.UnitConverter;
import org.slf4j.Logger;
@@ -371,7 +371,7 @@
/**
* Méthode appelée lorsqu'on souhaite valider la création du sondage.
*/
- Object onSuccessFromChoicesCreationForm() {
+ Object onSuccessFromChoicesCreationForm() throws FileUploadException {
if (!addChoiceSelected) {
// Préparation et création du sondage
@@ -741,13 +741,14 @@
return true;
}
+ @Inject
+ private ServiceImage serviceImage;
+
/**
* Création du sondage.
*/
- private void createPoll() {
+ private void createPoll() throws FileUploadException {
- // Création du sondage
- servicePoll.createPoll(poll);
// FD-20100226 : Can't be null, an exception will be thrown if a
// problem comes from createPoll
@@ -755,10 +756,24 @@
// Création des images
if (poll.getChoiceType() == ChoiceType.IMAGE) {
- File dir = imgContext.getImageDir();
- ImageUtil.saveImages(imgTypeChoices, dir);
+ for (ImageChoiceUIO image : imgTypeChoices) {
+ if (image.getImg() != null) {
+// String contentType = image.getImg().getContentType();
+// if (!contentType.equals("image") ||
+// !contentType.equals("IMAGE")) {
+// throw new FileUploadException("wrong type for image upload");
+// }
+ serviceImage.saveImage(image.getImg(), poll.getPollUId());
+ }
+ }
+ //File dir = imgContext.getImageDir();
+ //ImageUtil.saveImages(imgTypeChoices, dir);
}
+
+ // Création du sondage
+ servicePoll.createPoll(poll);
+
// FD-20100226 : not necessary, the service will update
// automatically the poll when it was created
// Mise à jour du sondage :
@@ -790,8 +805,8 @@
/** Ajout d'une entrée dans le flux de syndication */
private void addFeedEntry() {
PollAccountDTO creator = servicePollAccount.findPollAccountById(poll.getCreatorId());
- String voteURL = siteURL + "poll/votefor/" + poll.getPollId();
- File feedFile = feedContext.getFile(poll.getPollId());
+ String voteURL = siteURL + "poll/votefor/" + poll.getPollUId();
+ File feedFile = feedContext.getFile(poll.getPollUId());
FeedUtil.createFeed(feedFile, "atom_1.0", messages.format(
"pollFeed_title", poll.getTitle()), siteURL, messages.format(
@@ -804,8 +819,8 @@
private void sendMailNotification(String siteURL, ServicePollAccount servicePollAccount,
PollDTO poll, Messages messages) {
PollAccountDTO creator = servicePollAccount.findPollAccountById(poll.getCreatorId());
- String voteURL = siteURL + "poll/VoteFor/" + poll.getPollId();
- String modifURL = siteURL + "poll/Modification/" + poll.getPollId() + ":" + creator.getAccountId();
+ String voteURL = siteURL + "poll/VoteFor/" + poll.getPollUId();
+ String modifURL = siteURL + "poll/Modification/" + poll.getPollUId() + ":" + creator.getAccountId();
Map<String, String> data = new HashMap<String, String>();
data.put("host", PollenProperty.EMAIL_HOST.getValue());
data.put("port", PollenProperty.EMAIL_PORT.getValue());
@@ -1161,8 +1176,8 @@
// Réinitialisation des variables de session
// Si l'ancien sondage n'existe pas ou est différent de celui fourni
- if (oldPoll == null || !id.equals(oldPoll.getPollId())) {
- oldPoll = servicePoll.findPollByPollId(id);
+ if (oldPoll == null || !id.equals(oldPoll.getPollUId())) {
+ oldPoll = servicePoll.getPoll(id);
if (oldPoll != null) {
initWithExistingPoll(oldPoll);
oldPoll = null;
@@ -1198,7 +1213,8 @@
private void initPoll() {
// Initialisation du sondage
- poll = new PollDTO();
+ //poll = new PollDTO();
+ poll = servicePoll.getNewPoll();
if (userExists) {
poll.setCreatorName(user.getLogin());
poll.setCreatorEmail(user.getEmail());
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -108,7 +108,7 @@
if (log.isDebugEnabled()) {
log.debug("Get existing poll with pollUID = " + pollUID);
}
- poll = servicePoll.findPollByPollId(pollUID);
+ poll = servicePoll.getPoll(pollUID);
// TODO : init advancedOptions
} else {
if (log.isDebugEnabled()) {
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollModification.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollModification.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollModification.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -532,7 +532,7 @@
/** Envoi du mail de notification */
private void sendMailNotification(List<PollAccountDTO> modifiedAccounts) {
- String voteURL = siteURL + "poll/VoteFor/" + poll.getPollId();
+ String voteURL = siteURL + "poll/VoteFor/" + poll.getPollUId();
Map<String, String> data = new HashMap<String, String>();
data.put("host", PollenProperty.EMAIL_HOST.getValue());
data.put("port", PollenProperty.EMAIL_PORT.getValue());
@@ -592,8 +592,8 @@
String pollId = id.split(":", 2)[0];
// Réinitialisation des variables de session
- if (poll == null || !pollId.equals(poll.getPollId())) {
- poll = servicePoll.findPollByPollId(pollId);
+ if (poll == null || !pollId.equals(poll.getPollUId())) {
+ poll = servicePoll.getPoll(pollId);
creator = null;
newRule = null;
}
@@ -649,7 +649,7 @@
// Réinitialisation des variables de session
if (poll != null) {
- poll = servicePoll.findPollByPollId(poll.getPollId());
+ poll = servicePoll.getPoll(poll.getPollUId());
creator = servicePollAccount.findPollAccountById(poll
.getCreatorId());
initNotificationRule();
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -366,9 +366,9 @@
ResultListDTO resultListDTO = null;
if (byGroup) {
- resultListDTO = serviceResults.getGroupResults(poll.getPollId());
+ resultListDTO = serviceResults.getGroupResults(poll.getPollUId());
} else {
- resultListDTO = serviceResults.getNormalResults(poll.getPollId());
+ resultListDTO = serviceResults.getNormalResults(poll.getPollUId());
}
results = resultListDTO.getResultDTOs();
@@ -471,7 +471,7 @@
if (id != null && !"".equals(id)) {
pollId = id.split(":", 2)[0];
- poll = servicePoll.findPollByPollId(pollId);
+ poll = servicePoll.getPoll(pollId);
if (poll != null) {
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -25,10 +25,13 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.UUID;
import org.apache.tapestry5.BindingConstants;
+import org.apache.tapestry5.Block;
+import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.EventContext;
+import org.apache.tapestry5.Link;
+import org.apache.tapestry5.StreamResponse;
import org.apache.tapestry5.ValidationException;
import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary;
@@ -42,11 +45,9 @@
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.beaneditor.BeanModel;
import org.apache.tapestry5.corelib.components.Form;
-import org.apache.tapestry5.corelib.components.TextField;
import org.apache.tapestry5.corelib.components.Zone;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
-import org.apache.tapestry5.ioc.util.AbstractMessages;
import org.apache.tapestry5.upload.services.UploadedFile;
import org.chenillekit.tapestry.core.components.DateTimeField;
import org.chorem.pollen.business.PollenBusinessException;
@@ -77,14 +78,15 @@
import org.chorem.pollen.ui.components.ImageContextLink;
import org.chorem.pollen.ui.components.Pager;
import org.chorem.pollen.ui.data.AddressBar;
+import org.chorem.pollen.ui.data.ChoiceField;
import org.chorem.pollen.ui.data.EvenOdd;
import org.chorem.pollen.ui.data.PollAction;
import org.chorem.pollen.ui.data.PollUri;
import org.chorem.pollen.ui.data.uio.DateChoiceUIO;
import org.chorem.pollen.ui.data.uio.ImageChoiceUIO;
+import org.chorem.pollen.ui.services.ServiceImage;
import org.chorem.pollen.ui.utils.FeedUtil;
import org.chorem.pollen.ui.utils.ImageUtil;
-import org.chorem.pollen.votecounting.business.NumberMethod;
import org.slf4j.Logger;
/**
@@ -112,13 +114,6 @@
@Component(id = "feedback")
private FeedBack feedback;
- /**
- * Objet de session représentant l'utilisateur identifié.
- */
- @SessionState
- private UserDTO user;
- @Property
- private boolean userExists;
/**
* Objet de session représentant l'url du site.
@@ -130,8 +125,8 @@
@Component
private Form voteForm;
- @Component(id = "pollAccountName")
- private TextField nameField;
+// @Component(id = "pollAccountName")
+// private TextField nameField;
/** Composant DateTimeField pour les choix du sondage */
@SuppressWarnings("unused")
@@ -176,8 +171,8 @@
/*@InjectPage
private ImageDisplay imageDisplay;*/
- @InjectComponent
- private Zone pollZone;
+// @InjectComponent
+// private Zone pollZone;
/**
* Objet servant à changer la couleur à chaque ligne de la liste des
@@ -201,11 +196,11 @@
// private List<ChoiceDTO> voteChoices = new ArrayList<ChoiceDTO>();
/** Identifiant du compte correspondant à l'adresse forgée */
- private String pollAccountId;
+// private String pollAccountId;
/** Compte du votant */
- @Property
- private PollAccountDTO pollAccount;
+// @Property
+// private PollAccountDTO pollAccount;
/** Nouveau choix de type texte */
@Property
@@ -275,239 +270,236 @@
}
/** Méthode appelée après la soumission du vote. */
- @Log
- Object onSuccessFromVoteForm() throws PollenBusinessException {
- if (initPollAccount()) {
- List<ChoiceDTO> choiceDTOs = new ArrayList<ChoiceDTO>();
- if (getPoll().getVoteCounting() == VoteCountingType.NORMAL) {
- int nbChoices = 0;
- for (ChoiceDTO choice : getPoll().getChoices()) {
- if (choice.getValue() == 1) {
- nbChoices++;
- }
- choiceDTOs.add(choice);
- }
- if (nbChoices > getPoll().getMaxChoiceNb()) {
- voteForm.recordError(messages.format(("tooManyChoices"),
- getPoll().getMaxChoiceNb()));
- return pollZone.getBody();
- }
-
- } else if (getPoll().getVoteCounting() == VoteCountingType.PERCENTAGE) {
- int total = 0;
- for (ChoiceDTO choice : getPoll().getChoices()) {
- total = total + choice.getValue();
- choiceDTOs.add(choice);
- }
- if (total != 100) {
- voteForm.recordError(messages.get("not100percent"));
- return pollZone.getBody();
- }
-
- } else if (getPoll().getVoteCounting() == VoteCountingType.CONDORCET) {
- for (ChoiceDTO choice : getPoll().getChoices()) {
- if (choice.getValue() == 0) {
- choice.setValue(100);
- }
- choiceDTOs.add(choice);
- }
-
- } else if (getPoll().getVoteCounting() == VoteCountingType.NUMBER) {
- String votingId = pollAccount.getVotingId();
- if (anonymousVote) {
- votingId = "anonymous" + UUID.randomUUID().toString().replaceAll("-", "");
- }
-
- for (ChoiceDTO choice : getPoll().getChoices()) {
- if (!choice.isHidden()) {
- choiceDTOs.add(choice);
-
- // creates a new hidden choice
- ChoiceDTO hiddenChoice = new ChoiceDTO();
- hiddenChoice.setName(NumberMethod.HIDDEN_PREFIX +
- choice.getName() + "#" + votingId);
- hiddenChoice.setHidden(true);
- hiddenChoice.setValue(choice.getValue());
- hiddenChoice.setPollId(choice.getPollId());
- hiddenChoice.setVoteId(choice.getVoteId());
- hiddenChoice.setValidate(false);
-
- String choiceId = serviceChoice.createChoice(hiddenChoice);
- hiddenChoice.setId(choiceId);
- choiceDTOs.add(hiddenChoice);
- }
- }
- }
-
- VoteDTO vote = new VoteDTO(null, getPoll().getId(), null);
- vote.setChoiceDTOs(choiceDTOs);
- vote.setWeight(pollAccount.getWeight());
- vote.setAnonymous(anonymousVote);
-
- // mise à jour du vote ou création d'un nouveau vote
- if (alreadyVoted) {
- for (VoteDTO v : getVotes()) {
- PollAccountDTO voteAccount = servicePollAccount
- .findPollAccountById(v.getPollAccountId());
-
- if (voteAccount.getVotingId().equals(pollAccount.getVotingId())) {
- vote.setId(v.getId());
- deleteVote(vote.getId());
- serviceVote.createVote(vote, pollAccount);
- }
- }
- } else {
- serviceVote.createVote(vote, pollAccount);
- }
-
- // Mise à jour du sondage et des résultats
- //poll = servicePoll.findPollByPollId(getPoll().getPollId());
- poll = null;
- countPoll();
-
- addFeedEntry(PollAction.ADDVOTE, pollAccount.getVotingId(),
- getResultsAsString());
- sendMailNotification();
- voteFeedback.addInfo(messages.get("vote-success"));
- page = pager.getLastPage();
- // Reset votes to reload them depends on page change.
- votes = null;
- return this;
- }
-// voteChoices.clear();
- return pollZone.getBody();
- }
+// @Log
+// Object onSuccessFromVoteForm() throws PollenBusinessException {
+// if (initPollAccount()) {
+// List<ChoiceDTO> choiceDTOs = new ArrayList<ChoiceDTO>();
+// if (getPoll().getVoteCounting() == VoteCountingType.NORMAL) {
+// int nbChoices = 0;
+// for (ChoiceDTO choice : getPoll().getChoices()) {
+// if (choice.getValue() == 1) {
+// nbChoices++;
+// }
+// choiceDTOs.add(choice);
+// }
+// if (nbChoices > getPoll().getMaxChoiceNb()) {
+// voteForm.recordError(messages.format(("tooManyChoices"),
+// getPoll().getMaxChoiceNb()));
+// return pollZone.getBody();
+// }
+//
+// } else if (getPoll().getVoteCounting() == VoteCountingType.PERCENTAGE) {
+// int total = 0;
+// for (ChoiceDTO choice : getPoll().getChoices()) {
+// total = total + choice.getValue();
+// choiceDTOs.add(choice);
+// }
+// if (total != 100) {
+// voteForm.recordError(messages.get("not100percent"));
+// return pollZone.getBody();
+// }
+//
+// } else if (getPoll().getVoteCounting() == VoteCountingType.CONDORCET) {
+// for (ChoiceDTO choice : getPoll().getChoices()) {
+// if (choice.getValue() == 0) {
+// choice.setValue(100);
+// }
+// choiceDTOs.add(choice);
+// }
+//
+// } else if (getPoll().getVoteCounting() == VoteCountingType.NUMBER) {
+// String votingId = pollAccount.getVotingId();
+// if (anonymousVote) {
+// votingId = "anonymous" + UUID.randomUUID().toString().replaceAll("-", "");
+// }
+//
+// for (ChoiceDTO choice : getPoll().getChoices()) {
+// if (!choice.isHidden()) {
+// choiceDTOs.add(choice);
+//
+// // creates a new hidden choice
+//// ChoiceDTO hiddenChoice = new ChoiceDTO();
+//// hiddenChoice.setName(NumberMethod.HIDDEN_PREFIX +
+//// choice.getName() + "#" + votingId);
+//// hiddenChoice.setHidden(true);
+//// hiddenChoice.setValue(choice.getValue());
+//// hiddenChoice.setPollId(choice.getPollId());
+//// hiddenChoice.setVoteId(choice.getVoteId());
+//// hiddenChoice.setValidate(false);
+// ChoiceDTO hiddenChoice =
+// servicePoll.getNewHiddenChoice(choice, votingId);
+//
+// String choiceId =
+// serviceChoice.createChoice(hiddenChoice);
+// hiddenChoice.setId(choiceId);
+// choiceDTOs.add(hiddenChoice);
+// }
+// }
+// }
+//
+// VoteDTO vote = new VoteDTO(null, getPoll().getId(), null);
+// vote.setChoiceDTOs(choiceDTOs);
+// vote.setWeight(pollAccount.getWeight());
+// vote.setAnonymous(anonymousVote);
+//
+// // mise à jour du vote ou création d'un nouveau vote
+// if (alreadyVoted) {
+// for (VoteDTO v : getVotes()) {
+// PollAccountDTO voteAccount = servicePollAccount
+// .findPollAccountById(v.getPollAccountId());
+//
+// if (voteAccount.getVotingId().equals(getPollAccount().getVotingId())) {
+// vote.setId(v.getId());
+// deleteVote(vote.getId());
+// serviceVote.createVote(vote, getPollAccount());
+// }
+// }
+// } else {
+// serviceVote.createVote(vote, getPollAccount());
+// }
+//
+// // Mise à jour du sondage et des résultats
+// //poll = servicePoll.findPollByPollId(getPoll().getPollId());
+// poll = null;
+// countPoll();
+//
+// addFeedEntry(PollAction.ADDVOTE, getPollAccount().getVotingId(),
+// getResultsAsString());
+// sendMailNotification();
+// voteFeedback.addInfo(messages.get("vote-success"));
+// page = pager.getLastPage();
+// // Reset votes to reload them depends on page change.
+// votes = null;
+// return this;
+// }
+//// voteChoices.clear();
+// return pollZone.getBody();
+// }
- private void deleteVote(String voteId) throws PollenBusinessException {
- for (VoteDTO vote : getVotes()) {
- if (vote.getId().equals(voteId)) {
+// private void deleteVote(String voteId) throws PollenBusinessException {
+// for (VoteDTO vote : getVotes()) {
+// if (vote.getId().equals(voteId)) {
+//
+// List<ChoiceDTO> choiceDTOs = vote.getChoiceDTOs();
+// for (ChoiceDTO choiceDTO : choiceDTOs) {
+//
+// if (choiceDTO.isHidden()) {
+// serviceChoice.deleteChoice(choiceDTO.getId());
+// }
+// }
+//
+// break;
+// }
+// }
+//
+// serviceVote.deleteVote(voteId);
+// }
+//
+// /** Méthode appelée lors de la suppression d'un vote. */
+// Object onActionFromDeleteVote(String voteId) throws PollenBusinessException {
+// deleteVote(voteId);
+//
+// // Mise à jour du sondage et des résultats
+//// poll = servicePoll.findPollByPollId(poll.getPollId());
+// poll = null;
+// countPoll();
+//
+// return pollZone.getBody();
+// }
- List<ChoiceDTO> choiceDTOs = vote.getChoiceDTOs();
- for (ChoiceDTO choiceDTO : choiceDTOs) {
-
- if (choiceDTO.isHidden()) {
- serviceChoice.deleteChoice(choiceDTO.getId());
- }
- }
-
- break;
- }
- }
-
- serviceVote.deleteVote(voteId);
- }
-
- /** Méthode appelée lors de la suppression d'un vote. */
- Object onActionFromDeleteVote(String voteId) throws PollenBusinessException {
- deleteVote(voteId);
-
- // Mise à jour du sondage et des résultats
-// poll = servicePoll.findPollByPollId(poll.getPollId());
- poll = null;
- countPoll();
-
- return pollZone.getBody();
- }
-
- /** Méthode appelée lors de l'édition d'un vote. */
- Object onActionFromEditVote(String votingId) {
- pollAccount.setVotingId(votingId);
- return pollZone.getBody();
- }
-
/** Initialisation du pollAccount et contrôle du nom. */
- private boolean initPollAccount() throws PollenBusinessException {
-
- //// Contrôle et définition du votingId
- alreadyVoted = false;
- boolean modifAllowed = false;
- boolean restrictedListsForbidden = false;
-
- // Suppression des espaces pouvant provoquer un double vote
- String votingId = pollAccount.getVotingId().trim();
- pollAccount.setVotingId(votingId);
-
- // Contrôle de la présence du votant dans les listes de votants
- // du sondage (si le sondage n'est pas libre)
-// if (!isFreePoll()) {
-// restrictedListsForbidden = true;
-// for (VotingListDTO list : poll.getVotingListDTOs()) {
-// for (PollAccountDTO account : list.getPollAccountDTOs()) {
-// if (pollAccount.getVotingId().equals(account.getVotingId())) {
-// restrictedListsForbidden = false;
-// pollAccount = servicePollAccount
-// .findPollAccountById(account.getId());
-// pollAccount.setVotingListId(list.getId());
-// pollAccount.setWeight(account.getWeight());
-// logger.debug("Compte \"" + account.getVotingId()
-// + "\" présent dans la liste \""
-// + list.getName() + "\" (poids="
-// + account.getWeight() + ")");
-// }
+// private boolean initPollAccount() throws PollenBusinessException {
+//
+// //// Contrôle et définition du votingId
+// alreadyVoted = false;
+// boolean modifAllowed = false;
+// boolean restrictedListsForbidden = false;
+//
+// // Suppression des espaces pouvant provoquer un double vote
+// String votingId = getPollAccount().getVotingId().trim();
+// getPollAccount().setVotingId(votingId);
+//
+// // Contrôle de la présence du votant dans les listes de votants
+// // du sondage (si le sondage n'est pas libre)
+//// if (!isFreePoll()) {
+//// restrictedListsForbidden = true;
+//// for (VotingListDTO list : poll.getVotingListDTOs()) {
+//// for (PollAccountDTO account : list.getPollAccountDTOs()) {
+//// if (pollAccount.getVotingId().equals(account.getVotingId())) {
+//// restrictedListsForbidden = false;
+//// pollAccount = servicePollAccount
+//// .findPollAccountById(account.getId());
+//// pollAccount.setVotingListId(list.getId());
+//// pollAccount.setWeight(account.getWeight());
+//// logger.debug("Compte \"" + account.getVotingId()
+//// + "\" présent dans la liste \""
+//// + list.getName() + "\" (poids="
+//// + account.getWeight() + ")");
+//// }
+//// }
+//// }
+//// }
+//
+// // The calcul of alreadyVoted will be needed for no double votingId
+// // Carefull, not correct for an anonymous vote
+// alreadyVoted = serviceVote.hasAlreadyVoted(votingId, getPoll());
+//
+// // Check for restricted poll
+// if (!alreadyVoted && !isFreePoll()) {
+// if (uri.getAccountUId() != null) {
+// // The accountUId must be valid for the poll
+// PollAccountDTO restrictedAccount =
+// servicePoll.getRestrictedAccount(uri.getAccountUId(), getPoll());
+//
+// if (restrictedAccount != null) {
+// // PollAccount is replaced by the good account from db
+// pollAccount = restrictedAccount;
+// // Refresh alreadyVoted value depends on getPollAccount()
+// alreadyVoted = getPollAccount().isHasVoted();
+// // Existing account is null is forbidden for a restricted poll
+// } else {
+// restrictedListsForbidden = true;
// }
+// // Not allowed to vote without an accountUId
+// } else {
+// restrictedListsForbidden = true;
// }
+//
+// if (restrictedListsForbidden) {
+//// voteForm.recordError(nameField,
+//// messages.get("restrictedListsForbidden"));
+// }
// }
+//
+// // Génération d'un identifiant de vote (si le sondage est libre et anonyme)
+// if (getPoll().isAnonymous()) {
+// anonymousVote = true;
+// if (isFreePoll()) {
+// getPollAccount().setVotingId("anonymous"
+// + UUID.randomUUID().toString().replaceAll("-", ""));
+// }
+// }
+//
+// //// Définition de l'userId
+// if (userExists) {
+// getPollAccount().setUserId(user.getId());
+// } else {
+// getPollAccount().setUserId("");
+// }
+//
+// modifAllowed = isModifAllowed(getPollAccount().getVotingId());
+// if (alreadyVoted && !modifAllowed) {
+//// voteForm.recordError(nameField, messages.format("alreadyVoted",
+//// getPollAccount().getVotingId()));
+// }
+//
+// logger.debug("votingId: " + getPollAccount().getVotingId());
+// logger.debug("alreadyVoted: " + alreadyVoted);
+// logger.debug("modifAllowed: " + modifAllowed);
+// logger.debug("restrictedListsForbidden: " + restrictedListsForbidden);
+// return ((!alreadyVoted || modifAllowed) && !restrictedListsForbidden);
+// }
- // The calcul of alreadyVoted will be needed for no double votingId
- // Carefull, not correct for an anonymous vote
- alreadyVoted = serviceVote.hasAlreadyVoted(votingId, getPoll());
-
- // Check for restricted poll
- if (!alreadyVoted && !isFreePoll()) {
- if (uri.getAccountUId() != null) {
- // The accountUId must be valid for the poll
- PollAccountDTO restrictedAccount =
- servicePoll.getRestrictedAccount(uri.getAccountUId(), getPoll());
-
- if (restrictedAccount != null) {
- // PollAccount is replaced by the good account from db
- pollAccount = restrictedAccount;
- // Refresh alreadyVoted value depends on pollAccount
- alreadyVoted = pollAccount.isHasVoted();
- // Existing account is null is forbidden for a restricted poll
- } else {
- restrictedListsForbidden = true;
- }
- // Not allowed to vote without an accountUId
- } else {
- restrictedListsForbidden = true;
- }
-
- if (restrictedListsForbidden) {
- voteForm.recordError(nameField,
- messages.get("restrictedListsForbidden"));
- }
- }
-
- // Génération d'un identifiant de vote (si le sondage est libre et anonyme)
- if (getPoll().isAnonymous()) {
- anonymousVote = true;
- if (isFreePoll()) {
- pollAccount.setVotingId("anonymous"
- + UUID.randomUUID().toString().replaceAll("-", ""));
- }
- }
-
- //// Définition de l'userId
- if (userExists) {
- pollAccount.setUserId(user.getId());
- } else {
- pollAccount.setUserId("");
- }
-
- modifAllowed = isModifAllowed(pollAccount.getVotingId());
- if (alreadyVoted && !modifAllowed) {
- voteForm.recordError(nameField, messages.format("alreadyVoted",
- pollAccount.getVotingId()));
- }
-
- logger.debug("votingId: " + pollAccount.getVotingId());
- logger.debug("alreadyVoted: " + alreadyVoted);
- logger.debug("modifAllowed: " + modifAllowed);
- logger.debug("restrictedListsForbidden: " + restrictedListsForbidden);
- return ((!alreadyVoted || modifAllowed) && !restrictedListsForbidden);
- }
-
/**
* Retourne vrai si la modification du vote est autorisée. C'est à dire si
* l'utilisateur connecté est l'auteur du vote ou si le votant défini par
@@ -516,50 +508,50 @@
* @param votingId le votant a rechercher
* @return vrai si la modification du vote est autorisée
*/
- public boolean isModifAllowed(String votingId) throws PollenBusinessException {
- boolean modifAllowed = false;
- int i = 0;
+// public boolean isModifAllowed(String votingId) throws PollenBusinessException {
+// boolean modifAllowed = false;
+// int i = 0;
+//
+// // parcours des votes pour trouver celui correspondant au votingId
+// // et contrôle du droit de modification
+// while (i < getVotes().size() && !modifAllowed) {
+//
+// // account : compte associé au vote courant
+// //String id = getVotes().get(i).getPollAccountId();
+// //PollAccountDTO account = servicePollAccount.findPollAccountById(id);
+// VoteDTO curr = getVotes().get(i);
+//
+// // si le votant du vote correspond au votingId
+// if (curr.getName().equals(votingId)) {
+// if (logger.isDebugEnabled()) {
+// logger.debug("vote name: " + curr.getName());
+// logger.debug("vote account: " + curr.getPollAccountId());
+//// logger.debug("voting account: " + pollAccountId);
+// }
+//
+// // si le votant du vote correspond au votant actuel (pollAccountId)
+//// if (pollAccountId != null
+//// && pollAccountId.equals(curr.getPollAccountId())) {
+//// modifAllowed = true;
+//// }
+//
+// // si l'utilisateur du vote correspond à l'utilisateur actuel (user)
+// if (userExists && user.getId().length() > 0) {
+// modifAllowed = user.getId().equals(curr.getUserId());
+// }
+// }
+//
+// i++;
+// }
+//
+// return modifAllowed;
+// }
- // parcours des votes pour trouver celui correspondant au votingId
- // et contrôle du droit de modification
- while (i < getVotes().size() && !modifAllowed) {
-
- // account : compte associé au vote courant
- //String id = getVotes().get(i).getPollAccountId();
- //PollAccountDTO account = servicePollAccount.findPollAccountById(id);
- VoteDTO curr = getVotes().get(i);
-
- // si le votant du vote correspond au votingId
- if (curr.getName().equals(votingId)) {
- if (logger.isDebugEnabled()) {
- logger.debug("vote name: " + curr.getName());
- logger.debug("vote account: " + curr.getPollAccountId());
- logger.debug("voting account: " + pollAccountId);
- }
-
- // si le votant du vote correspond au votant actuel (pollAccountId)
- if (pollAccountId != null
- && pollAccountId.equals(curr.getPollAccountId())) {
- modifAllowed = true;
- }
-
- // si l'utilisateur du vote correspond à l'utilisateur actuel (user)
- if (userExists && user.getId().length() > 0) {
- modifAllowed = user.getId().equals(curr.getUserId());
- }
- }
-
- i++;
- }
-
- return modifAllowed;
- }
-
/** Ajout d'une entrée dans le flux de syndication */
private void addFeedEntry(PollAction pollAction, String titleStr,
String contentStr) throws PollenBusinessException {
- String voteURL = siteURL + "poll/VoteFor/" + getPoll().getPollId();
- File feedFile = getFeedContext().getFile(getPoll().getPollId());
+ String voteURL = siteURL + "poll/VoteFor/" + getPoll().getPollUId();
+ File feedFile = getFeedContext().getFile(getPoll().getPollUId());
String title = null;
String content = null;
@@ -591,8 +583,8 @@
/** Envoi du mail de notification */
private void sendMailNotification() throws PollenBusinessException {
- String voteURL = siteURL + "poll/VoteFor/" + getPoll().getPollId();
- String modifURL = siteURL + "poll/Modification/" + getPoll().getPollId()
+ String voteURL = siteURL + "poll/VoteFor/" + getPoll().getPollUId();
+ String modifURL = siteURL + "poll/Modification/" + getPoll().getPollUId()
+ ":" + MD5.encode(getPoll().getCreatorId());
Map<String, String> data = new HashMap<String, String>();
data.put("host", PollenProperty.EMAIL_HOST.getValue());
@@ -702,7 +694,7 @@
*/
@Log
public boolean isFeedFileExisting() throws PollenBusinessException {
- File feedFile = getFeedContext().getFile(getPoll().getPollId());
+ File feedFile = getFeedContext().getFile(getPoll().getPollUId());
if (log.isDebugEnabled()) {
log.debug("feed context path : " + getFeedContext().getContextPath());
log.debug("feed absolute path : " + feedFile.getAbsolutePath());
@@ -810,7 +802,7 @@
if (isTextType()) {
if (newChoice.getName() != null) {
newChoice.setValidate(true);
- newChoice.setPollId(getPoll().getId());
+ newChoice.setPollUId(getPoll().getPollUId());
getPoll().getChoices().add(newChoice);
choiceName = newChoice.getName();
choiceDesc = newChoice.getDescription();
@@ -818,7 +810,7 @@
} else if (isDateType()) {
if (newDateChoice.getDate() != null) {
newDateChoice.setValidate(true);
- newDateChoice.setPollId(getPoll().getId());
+ newDateChoice.setPollUId(getPoll().getPollUId());
newDateChoice.setName(String.valueOf(newDateChoice.getDate()
.getTime()));
getPoll().getChoices().add(newDateChoice);
@@ -829,7 +821,7 @@
} else if (isImageType()) {
if (newImageChoice.getImg() != null) {
newImageChoice.setValidate(true);
- newImageChoice.setPollId(getPoll().getId());
+ newImageChoice.setPollUId(getPoll().getPollUId());
newImageChoice.setName(newImageChoice.getImg().getFileName()
.replace(' ', '_'));
getPoll().getChoices().add(newImageChoice);
@@ -851,32 +843,10 @@
return this;
}
- /** Méthode appelée lors de la suppression d'un choix. */
- Object onActionFromDeleteChoice(String choiceId) throws PollenBusinessException {
- Iterator<ChoiceDTO> itChoice = getPoll().getChoices().iterator();
- while (itChoice.hasNext()) {
- ChoiceDTO choice = itChoice.next();
- if (choiceId.equals(choice.getId())) {
- itChoice.remove();
- }
- }
- servicePoll.updatePoll(getPoll());
- poll = null;
-// poll = servicePoll.findPollByPollId(poll.getPollId());
- return pollZone.getBody();
- }
-
// public boolean isPollNull() {
// return poll == null;
// }
- public boolean isPollChoiceStarted() throws PollenBusinessException {
- Date now = new Date();
- boolean started = getPoll().getBeginChoiceDate() == null || getPoll().getBeginChoiceDate().before(now);
- boolean ended = getPoll().getEndChoiceDate() != null && getPoll().getEndChoiceDate().before(now);
- return started && !ended;
- }
-
public boolean isPollStarted() throws PollenBusinessException {
Date now = new Date();
return getPoll().getBeginDate() == null || getPoll().getBeginDate().before(now);
@@ -891,19 +861,14 @@
return isPollChoiceStarted() || isPollStarted();
}
- public boolean isPollChoiceRunning() throws PollenBusinessException {
- return getPoll().isChoiceAddAllowed() && isPollChoiceStarted();
- //&& !isPollStarted();
- }
-
public boolean isPollRunning() throws PollenBusinessException {
return isPollStarted() && !isPollFinished() && !getPoll().isClosed();
}
- public boolean isDescNull() {
- return choiceOfPoll.getDescription() == null
- || "".equals(choiceOfPoll.getDescription());
- }
+// public boolean isDescNull() {
+// return choiceOfPoll.getDescription() == null
+// || "".equals(choiceOfPoll.getDescription());
+// }
/** Retourne vrai si le champs pollAccount doit apparaître. */
public boolean isAccountFieldDisplayed() throws PollenBusinessException {
@@ -949,14 +914,6 @@
public boolean isNumberVoteCounting() throws PollenBusinessException {
return getPoll().getVoteCounting() == VoteCountingType.NUMBER;
}
-
- /** retourne vrai si l'utilisateur est le créateur du sondage */
- public boolean isCreatorUser() throws PollenBusinessException {
- if (userExists && user.getId().equals(getPoll().getUserId())) {
- return true;
- }
- return false;
- }
/** Retourne le message d'aide correspondant au type de sondage. */
public String getHelpMessage() throws PollenBusinessException {
@@ -989,9 +946,9 @@
if (getPoll().getContinuousResults()) {
if (isGroupPoll()) {
- resultListDTO = serviceResults.getGroupResults(getPoll().getPollId());
+ resultListDTO = serviceResults.getGroupResults(getPoll().getPollUId());
} else {
- resultListDTO = serviceResults.getNormalResults(getPoll().getPollId());
+ resultListDTO = serviceResults.getNormalResults(getPoll().getPollUId());
}
results = resultListDTO.getResultDTOs();
@@ -1006,9 +963,26 @@
}
}
+
+
+
+
+
+
+
+
+ ////////////////// NEW IMPLEMENTATION
+
+
+
+
+
@Property
private PollUri uri;
+ @InjectComponent
+ private Border border;
+
/**
* Sondage pour lequel l'utilisateur vote
*/
@@ -1017,9 +991,17 @@
@Property
private boolean pollNull;
+
+ /**
+ * Objet de session représentant l'utilisateur identifié.
+ */
+ @SessionState
+ private UserDTO user;
+ @Property
+ private boolean userExists;
- @InjectComponent
- private Border border;
+ /** Compte du votant */
+ private PollAccountDTO pollAccount;
/** Format des dates */
private DateFormat dateFormat;
@@ -1029,7 +1011,6 @@
*
* @param id l'identifiant du sondage et du votant
*/
- @Log
void onActivate(EventContext ec) throws PollenBusinessException {
uri = ec.get(PollUri.class, 0);
if (ec.getCount() > 1) {
@@ -1079,8 +1060,6 @@
* @return the address bar of the page.
*/
public AddressBar getAddress() {
-// address = new AddressBarItem[] { new AddressBarItem("Pollen", "Index"),
-// new AddressBarItem(title, null) };
return new AddressBar().appendCurrent(title);
}
@@ -1099,33 +1078,10 @@
public PollDTO getPoll() throws PollenBusinessException {
if (poll == null) {
- poll = servicePoll.findPollByPollId(uri.getPollUId());
+ poll = servicePoll.getPoll(uri.getPollUId());
if (poll != null) {
- // Identification du votant
- if (uri.getAccountUId() != null) {
- pollAccount = servicePollAccount
- .findPollAccountByAccountId(uri.getAccountUId());
- pollAccountId = pollAccount.getId();
- }
-
- if (pollAccount == null) {
- pollAccount = new PollAccountDTO();
- if (userExists) {
- if (user.getFirstName() != null && user.getLastName() != null) {
- pollAccount.setVotingId(
- user.getFirstName() + " " + user.getLastName());
-
- } else if (user.getFirstName() != null) {
- pollAccount.setVotingId(user.getFirstName());
-
- } else if (user.getLastName() != null) {
- pollAccount.setVotingId(user.getLastName());
- }
- }
- }
-
// Initialisations pour les formulaires
newChoice = new ChoiceDTO();
newDateChoice = new DateChoiceUIO();
@@ -1138,13 +1094,197 @@
return poll;
}
- /************** PAGER AND VOTES MANAGMENT *********************************/
+ /**
+ * Use a PollAccount to represent the current session user.
+ * The existing account is used if accountUId is present in the uri.
+ * Otherwise a new account is instanciate with user properties
+ * (for vote name).
+ *
+ * @return
+ */
+ public PollAccountDTO getPollAccount() {
+ if (pollAccount == null) {
+ // Identification du votant
+ if (uri.getAccountUId() != null) {
+ pollAccount = servicePollAccount
+ .findPollAccountByAccountId(uri.getAccountUId());
+// pollAccountId = pollAccount.getId();
+ }
+ if (pollAccount == null) {
+ pollAccount = serviceVote.getNewPollAccount(user);//new PollAccountDTO();
+// if (userExists) {
+// if (user.getFirstName() != null && user.getLastName() != null) {
+// pollAccount.setVotingId(
+// user.getFirstName() + " " + user.getLastName());
+//
+// } else if (user.getFirstName() != null) {
+// pollAccount.setVotingId(user.getFirstName());
+//
+// } else if (user.getLastName() != null) {
+// pollAccount.setVotingId(user.getLastName());
+// }
+// }
+ }
+ }
+ return pollAccount;
+ }
+
+ /**
+ * Test if the current connected user is the poll creator.
+ *
+ * @return true if connected user is the poll creator
+ * @throws PollenBusinessException
+ */
+ public boolean isCreatorUser() throws PollenBusinessException {
+ return userExists && user.getId().equals(getPoll().getUserId());
+ }
+
+ /************** CHOICES ***************************************************/
+
+ private List<ChoiceField> choices;
+
+ @Property
+ private ChoiceField choice;
+
+ @Inject
+ private Block choiceText;
+
+ @Inject
+ private Block choiceImage;
+
+ @Inject
+ private Block choiceDate;
+
+ @Inject
+ private ComponentResources resources;
+
+ @Inject
+ private ServiceImage serviceImage;
+
+ /**
+ * Get choices of the poll. The ChoiceDTO from poll will be converted
+ * to ChoiceField to easily managed different type of choice (image,
+ * date, text).
+ *
+ * @return a list of ChoiceField corresponding to poll choices
+ * @throws PollenBusinessException
+ */
+ public List<ChoiceField> getChoices() throws PollenBusinessException {
+ if (choices == null) {
+ if (log.isInfoEnabled()) {
+ log.info("Prepare choices for render");
+ }
+ choices = new ArrayList<ChoiceField>();
+ for (ChoiceDTO curr : getPoll().getChoices()) {
+ ChoiceField field = new ChoiceField(curr,
+ getPoll().getChoiceType());
+ choices.add(field);
+ }
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("nb choices loaded : " + choices.size());
+ }
+ return choices;
+ }
+
+ /**
+ * Delegator : return the correct choice block depends on poll choiceType.
+ *
+ * @return the choice block to display
+ * @throws PollenBusinessException
+ */
+ public Block getChoiceBlock() throws PollenBusinessException {
+ switch(getPoll().getChoiceType()) {
+ case IMAGE:
+ return choiceImage;
+ case DATE:
+ return choiceDate;
+ case TEXT:
+ default:
+ return choiceText;
+ }
+ }
+
+ /**
+ * Image link to show the miniature (thumb) of current choice image.
+ *
+ * @return the image link for current choice image.
+ */
+ public Link getImageThumb() {
+ return getImageLink(true);
+ }
+
+ /**
+ * Image link to show the normal (not thumb) image of current choice image.
+ *
+ * @return the image link for current choice image.
+ */
+ public Link getImageLink() {
+ return getImageLink(false);
+ }
+
+ private Link getImageLink(boolean thumb) {
+ return resources.createEventLink("showImage",
+ choice.getImageFileName(), choice.getImageDir(), thumb);
+ }
+
+ /**
+ * Event for showing image.
+ *
+ * @param src of the image
+ * @param imageDir directory of the image
+ * @param thumb to show the thumb image or not
+ * @return the streamResponse to display
+ * @see ServiceImage#createImageStream(String, String, boolean)
+ */
+ @Log
+ public StreamResponse onShowImage(String src, String imageDir,
+ boolean thumb) {
+ return serviceImage.createImageStream(src, imageDir, thumb);
+ }
+
+ public boolean isPollChoiceRunning() throws PollenBusinessException {
+ return getPoll().isChoiceAddAllowed() && isPollChoiceStarted();
+ }
+
+ /**
+ * TODO : whithout DTO, this method can be place in PollEntity
+ *
+ * @return true if adding choice is started, false otherwise
+ * @throws PollenBusinessException
+ */
+ public boolean isPollChoiceStarted() throws PollenBusinessException {
+ Date now = new Date();
+ boolean started = getPoll().getBeginChoiceDate() == null
+ || getPoll().getBeginChoiceDate().before(now);
+ boolean ended = getPoll().getEndChoiceDate() != null
+ && getPoll().getEndChoiceDate().before(now);
+ return started && !ended;
+ }
+
+ public boolean canDeleteChoice() throws PollenBusinessException {
+ return isPollChoiceRunning() && isCreatorUser();
+ }
+
+ /**
+ * ACTION EVENT :: delete selected choice
+ */
+ void onActionFromDeleteChoice(String choiceId)
+ throws PollenBusinessException {
+ if (canDeleteChoice()) {
+ servicePoll.deleteChoice(getPoll(), choiceId);
+ // Reset choices (ChoiceField list) to retrieve the updated one
+ // from poll
+ choices = null;
+ }
+ }
+
+ /************** PAGER *****************************************************/
+
@InjectComponent
private Pager pager;
- private List<VoteDTO> votes;
-
private Integer page;
@Persist
@@ -1183,9 +1323,20 @@
}
public String getNoPagerText() throws PollenBusinessException {
- return messages.format("vote-noPagerText", getPoll().getNbVotes());
+ if (getPoll().getNbVotes() == 0) {
+ return messages.get("pollen.ui.vote.noVotes");
+ }
+ return messages.format("pollen.ui.vote.noPager",
+ getPoll().getNbVotes());
}
+ /************** VOTES *****************************************************/
+
+ private List<VoteDTO> votes;
+
+ @Property
+ private int voteIndex;
+
/**
* Retrieve votes of the current poll from business module.
* The votes are ordered by creation date, only the ones to display are
@@ -1202,6 +1353,28 @@
return votes;
}
+ public boolean canEditVote() throws PollenBusinessException {
+ // If the current account exist from uri and equals to the current vote
+ String newAccountId = getPollAccount().getId();
+ if (newAccountId != null && newAccountId.equals(vote.getPollAccountId())) {
+ return true;
+ // If the connected user is an admin
+ } else if (userExists && user.isAdministrator()) {
+ return true;
+ // If the connected user is the poll creator
+ } else if (isCreatorUser()) {
+ return true;
+ }
+ return false;
+ }
+
+ /** Méthode appelée lors de l'édition d'un vote. */
+// Object onActionFromEditVote(int voteIndex) throws PollenBusinessException {
+//// getPollAccount().setVotingId(votingId);
+// vote = getVotes().get(voteIndex);
+// return pollZone.getBody();
+// }
+
/************** COMMENTS **************************************************/
@InjectComponent
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserPollsParticipated.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserPollsParticipated.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserPollsParticipated.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -74,11 +74,11 @@
for (VotingListDTO list : poll.getVotingListDTOs()) {
for (PollAccountDTO account : list.getPollAccountDTOs()) {
if (account.getEmail().equals(user.getEmail())) {
- return poll.getPollId() + ":" + account.getAccountId();
+ return poll.getPollUId() + ":" + account.getAccountId();
}
}
}
- return poll.getPollId();
+ return poll.getPollUId();
}
/**
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -72,6 +72,7 @@
binder.bind(ServiceResults.class);
binder.bind(ServiceVote.class);
binder.bind(ServiceChoice.class);
+ binder.bind(ServiceImage.class);
}
public static void contributeApplicationDefaults(
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/BackgroundWorkerImpl.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/BackgroundWorkerImpl.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/BackgroundWorkerImpl.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -127,7 +127,7 @@
*/
private void sendMailNotification(PollDTO poll, Long timeValue) {
String voteURL = PollenProperty.SERVER_URL.getValue() + "/poll/VoteFor/"
- + poll.getPollId();
+ + poll.getPollUId();
Map<String, String> data = new HashMap<String, String>();
data.put("host", PollenProperty.EMAIL_HOST.getValue());
data.put("port", PollenProperty.EMAIL_PORT.getValue());
Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImage.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImage.java (rev 0)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImage.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -0,0 +1,63 @@
+
+package org.chorem.pollen.ui.services;
+
+import org.apache.tapestry5.StreamResponse;
+import org.apache.tapestry5.upload.services.UploadedFile;
+
+/**
+ * This service is used to manage images in pollen application.
+ *
+ * Saving process :
+ * <pre>
+ * - Use the upload component of Tapestry to retrieve the uploaded file
+ * - After file type validation use saveImage method to create the image,
+ * folders and thumbnail
+ * </pre>
+ * Display process :
+ * <pre>
+ * - Create eventLink for the src property of an img tag
+ * (<img src=${myLink}... />)
+ * - On event method, return the streamResponse created by createImageStream
+ * method
+ * </pre>
+ *
+ * Created: 20 mars 2010
+ *
+ * @author fdesbois
+ * @version $Revision$
+ * @since 1.3
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public interface ServiceImage {
+
+ /**
+ * Return the context path for pollen image managment.
+ *
+ * @return the context path for images
+ */
+ String getContextPath();
+
+ /**
+ * Create a StreamResponse represent the image to display.
+ *
+ * @param filename the filename of the image
+ * @param filedir the directory where the image is defined
+ * @param thumb to return a stream for the thumb image
+ * @return the StreamResponse to display (using eventLink)
+ */
+ StreamResponse createImageStream(String filename, String filedir,
+ boolean thumb);
+
+ /**
+ * Save an image in {@code filedir} from uploaded {@code tmpfile}.
+ *
+ * @param tmpfile which contains the image stream
+ * @param filedir where the image will be saved (not need to precise
+ * the context)
+ * @return the filename of the saved file
+ */
+ String saveImage(UploadedFile tmpfile, String filedir);
+
+}
Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImage.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java (rev 0)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -0,0 +1,162 @@
+
+package org.chorem.pollen.ui.services;
+
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import javax.activation.MimetypesFileTypeMap;
+import javax.imageio.ImageIO;
+import javax.swing.ImageIcon;
+import org.apache.commons.lang.StringUtils;
+import org.apache.tapestry5.StreamResponse;
+import org.apache.tapestry5.services.Response;
+import org.apache.tapestry5.upload.services.UploadedFile;
+import org.chorem.pollen.business.PollenContext;
+import org.chorem.pollen.business.PollenProperty;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ServiceImageImpl
+ *
+ * Created: 20 mars 2010
+ *
+ * @author fdesbois
+ * @version $Revision$
+ * @since 1.3
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class ServiceImageImpl implements ServiceImage {
+
+ private static final String THUMB_PREFIX = "thumb_";
+
+ private static final int THUMB_WIDTH = 100;
+
+ private static final Logger logger = LoggerFactory.getLogger(ServiceImageImpl.class);
+
+ public ServiceImageImpl() {
+
+ }
+
+ @Override
+ public String getContextPath() {
+ return PollenContext.getProperty(PollenProperty.IMG_DIR);
+ }
+
+ /**
+ * Get the directory where are uploaded the images from the context.
+ *
+ * @param imageDir
+ * @return a File corresponding to the image directory
+ */
+ public File getImagePathDir(String imageDir) {
+ File result = null;
+ if (StringUtils.isNotEmpty(imageDir)) {
+ result = new File(getContextPath(), imageDir);
+ } else {
+ result = new File(getContextPath());
+ }
+ return result;
+ }
+
+ public File getImageFile(String filename, String imageDir, boolean thumb) {
+ if (thumb) {
+ filename = THUMB_PREFIX + filename;
+ }
+ return new File(getImagePathDir(imageDir), filename);
+ }
+
+ @Override
+ public StreamResponse createImageStream(String filename, String filedir, boolean thumb) {
+ if (StringUtils.isEmpty(filename) || filename.contains("..")) {
+ return null;
+ }
+
+ final File file = getImageFile(filename, filedir, thumb);
+ if (!file.exists()) {
+ logger.error("Fichier inexistant : " + file.getAbsolutePath());
+ }
+
+ return new StreamResponse() {
+
+ @Override
+ public String getContentType() {
+ MimetypesFileTypeMap mimes = new MimetypesFileTypeMap();
+ return mimes.getContentType(file);
+ }
+
+ @Override
+ public InputStream getStream() throws IOException {
+ return new FileInputStream(file);
+ }
+
+ @Override
+ public void prepareResponse(Response response) {
+
+ }
+ };
+ }
+
+ @Override
+ public String saveImage(UploadedFile tmpfile, String filedir) {
+ File dir = getImagePathDir(filedir);
+ if (!dir.exists()) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Create image directory : " +
+ dir.getAbsolutePath());
+ }
+ dir.mkdirs();
+ }
+ String filename = tmpfile.getFileName();
+
+ File image = new File(dir, filename);
+ tmpfile.write(image);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Image saved: " + filename +
+ " (size=" + tmpfile.getSize() + ")");
+ }
+
+ createThumbnail(image, dir);
+ return image.getName();
+ }
+
+ /**
+ * Création d'une miniature.
+ *
+ * @param img
+ * @param dir Le répertoire de destination.
+ */
+ public void createThumbnail(File img, File dir) {
+
+ ImageIcon ii = new ImageIcon(img.getAbsolutePath());
+ Image image = ii.getImage();
+ double imageRatio = (double) image.getHeight(null)
+ / (double) image.getWidth(null);
+ int height = (int) (THUMB_WIDTH * imageRatio);
+
+ BufferedImage thumbImage = new BufferedImage(THUMB_WIDTH, height,
+ BufferedImage.TYPE_INT_RGB);
+ Graphics2D graphics2D = thumbImage.createGraphics();
+ graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
+ RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+ graphics2D.drawImage(image, 0, 0, THUMB_WIDTH, height, null);
+ File thumbCopied = new File(dir, THUMB_PREFIX + img.getName());
+ try {
+ ImageIO.write(thumbImage, "jpg", thumbCopied);
+ } catch (IOException e) {
+ logger.error("Erreur à l'enregistrement de la miniature", e);
+ }
+ if (logger.isDebugEnabled()) {
+ logger.debug("Thumbnail created: " + thumbCopied.getName() + " " +
+ "(size=" + thumbCopied.length() + ")");
+ }
+ }
+
+}
Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/ImageUtil.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/ImageUtil.java 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/ImageUtil.java 2010-03-20 15:30:29 UTC (rev 2952)
@@ -39,7 +39,9 @@
*
* @author rannou
* @version $Id$
+ * @deprecated use {@link org.chorem.pollen.ui.services.ServiceImage} instead
*/
+@Deprecated
public class ImageUtil {
/** log. */
Modified: trunk/pollen-ui/src/main/resources/i18n/pollen-ui-en_GB.properties
===================================================================
--- trunk/pollen-ui/src/main/resources/i18n/pollen-ui-en_GB.properties 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/resources/i18n/pollen-ui-en_GB.properties 2010-03-20 15:30:29 UTC (rev 2952)
@@ -39,4 +39,9 @@
validate=Validate
cancel=Cancel
return=Return
-help=Help
\ No newline at end of file
+help=Help
+
+pollen.ui.choice.delete.confirm=Are you sure you want to delete this choice ?
+pollen.ui.choice.delete.title=Delete this choice
+pollen.ui.vote.noVotes=Aucune personne n'a encore particip\u00E9 au sondage
+pollen.ui.vote.noPager=%d existing votes
\ No newline at end of file
Modified: trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties
===================================================================
--- trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties 2010-03-20 15:30:29 UTC (rev 2952)
@@ -1,35 +1,35 @@
# User registration emails
-registerEmail_subject=[Pollen] Confirmation de cr\u00e9ation du compte %s
-registerEmail_msg=Bienvenue %s %s. Vous venez de cr\u00e9er un compte sur l'application de sondage en ligne Pollen.\n\nIdentifiant : %s\nMot de passe : %s\n\nVous pouvez d\u00e8s maintenant g\u00e9rer vos sondages en vous identifiant sur le site : \n%s
+registerEmail_subject=[Pollen] Confirmation de cr\u00E9ation du compte %s
+registerEmail_msg=Bienvenue %s %s. Vous venez de cr\u00E9er un compte sur l'application de sondage en ligne Pollen.\n\nIdentifiant : %s\nMot de passe : %s\n\nVous pouvez d\u00E8s maintenant g\u00E9rer vos sondages en vous identifiant sur le site : \n%s
# Poll creation emails
-creatorEmail_subject=[Pollen] Cr\u00e9ation d'un sondage (%s)
-creatorEmail_msg=Vous venez de cr\u00e9er le sondage "%s".\nVous pouvez y acc\u00e9der en suivant les liens ci-dessous.\n\nPage de vote : \n%s\nPage de modification : \n%s
+creatorEmail_subject=[Pollen] Cr\u00E9ation d'un sondage (%s)
+creatorEmail_msg=Vous venez de cr\u00E9er le sondage "%s".\nVous pouvez y acc\u00E9der en suivant les liens ci-dessous.\n\nPage de vote : \n%s\nPage de modification : \n%s
votingEmail_subject=[Pollen] Invitation au vote (%s)
-votingEmail_msg=Un nouveau sondage a \u00e9t\u00e9 cr\u00e9\u00e9 : "%s".\nVous pouvez y participer avec l'identifiant %s \u00e0 l'adresse suivante : \n%s
+votingEmail_msg=Un nouveau sondage a \u00E9t\u00E9 cr\u00E9\u00E9 : "%s".\nVous pouvez y participer avec l'identifiant %s \u00E0 l'adresse suivante : \n%s
# Notification emails
voteEmail_subject=[Pollen] Notification de vote (%s)
-voteEmail_msg=Un vote vient d'\u00eatre enregistr\u00e9 pour le sondage "%s". Ce sondage compte d\u00e9sormais %d votes.\nVous pouvez acc\u00e9der \u00e0 ce sondage en suivant les liens ci-dessous.\n\nPage de vote : \n%s\nPage de modification : \n%s
+voteEmail_msg=Un vote vient d'\u00EAtre enregistr\u00E9 pour le sondage "%s". Ce sondage compte d\u00E9sormais %d votes.\nVous pouvez acc\u00E9der \u00E0 ce sondage en suivant les liens ci-dessous.\n\nPage de vote : \n%s\nPage de modification : \n%s
# Reminder emails
reminderEmail_subject=[Pollen] Rappel (%s)
-reminderEmail_msg=Vous n'avez pas encore vot\u00e9 pour le sondage "%s".\nVous pouvez encore y participer avec l'identifiant %s \u00e0 l'adresse suivante : \n%s
+reminderEmail_msg=Vous n'avez pas encore vot\u00E9 pour le sondage "%s".\nVous pouvez encore y participer avec l'identifiant %s \u00E0 l'adresse suivante : \n%s
# Poll feed
pollFeed_title=Pollen : %s
pollFeed_desc=%s
-pollFeed_createTitle=Sondage cr\u00e9\u00e9 par %s
+pollFeed_createTitle=Sondage cr\u00E9\u00E9 par %s
pollFeed_createContent=
pollFeed_voteTitle=Nouveau vote de %s
-pollFeed_voteContent=\u00c9tat du sondage : %s
+pollFeed_voteContent=\u00C9tat du sondage : %s
pollFeed_choiceTitle=Nouveau choix : %s
pollFeed_choiceContent=%s
pollFeed_commentTitle=Nouveau commentaire de %s
pollFeed_commentContent=%s
# Actions
-create=Cr\u00e9er
+create=Cr\u00E9er
edit=Modifier
delete=Supprimer
add=Ajouter
@@ -40,3 +40,8 @@
cancel=Annuler
return=Retour
help=Aide
+
+pollen.ui.choice.delete.confirm=Etes-vous s\u00FBr de vouloir d\u00E9finitivement supprimer ce choix ?
+pollen.ui.choice.delete.title=Supprimer ce choix
+pollen.ui.vote.noVotes=Aucune personne n'a encore particip\u00E9 au sondage
+pollen.ui.vote.noPager=%d votes existants
Modified: trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_en.properties
===================================================================
--- trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_en.properties 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_en.properties 2010-03-20 15:30:29 UTC (rev 2952)
@@ -20,7 +20,7 @@
anonymousVote-label=Anonymous vote
submitVote=Vote
vote-success=Your vote has been correctly saved
-vote-noPagerText=%d existing votes
+#vote-noPagerText=%d existing votes
#choices
addChoice=Adding a choice
@@ -59,4 +59,4 @@
pollNotStarted=This poll has not started yet.
pollFinished=This poll is finished. You can not vote anymore.
pollClosed=This poll is closed. You can not vote anymore.
-pollChoiceRunning=Adding choices is allowed.
\ No newline at end of file
+pollChoiceRunning=Adding choices is allowed.
Modified: trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_fr.properties
===================================================================
--- trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_fr.properties 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_fr.properties 2010-03-20 15:30:29 UTC (rev 2952)
@@ -20,7 +20,7 @@
anonymousVote-label=Vote anonyme
submitVote=Voter
vote-success=Votre vote a bien \u00E9t\u00E9 enregistr\u00E9
-vote-noPagerText=%d votes existants
+#vote-noPagerText=%d votes existants
#choices
addChoice=Ajout d'un choix
@@ -59,4 +59,4 @@
pollNotStarted=Ce sondage n'a pas encore commenc\u00E9.
pollFinished=Ce sondage est termin\u00E9. Vous ne pouvez plus voter.
pollClosed=Ce sondage est clos. Vous ne pouvez plus voter.
-pollChoiceRunning=L'ajout de choix est possible.
\ No newline at end of file
+pollChoiceRunning=L'ajout de choix est possible.
Modified: trunk/pollen-ui/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/pollen-ui/src/main/webapp/WEB-INF/web.xml 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/webapp/WEB-INF/web.xml 2010-03-20 15:30:29 UTC (rev 2952)
@@ -30,14 +30,14 @@
<filter-name>app</filter-name>
<filter-class>org.apache.tapestry5.TapestryFilter</filter-class>
</filter>
- <filter>
+<!-- <filter>
<filter-name>appExceptions</filter-name>
<filter-class>org.chorem.pollen.ui.filters.PollenExceptionsFilter</filter-class>
- </filter>
- <filter-mapping>
+ </filter>-->
+<!-- <filter-mapping>
<filter-name>appExceptions</filter-name>
<url-pattern>/*</url-pattern>
- </filter-mapping>
+ </filter-mapping>-->
<filter-mapping>
<filter-name>app</filter-name>
<url-pattern>/*</url-pattern>
Modified: trunk/pollen-ui/src/main/webapp/img/1leftarrow.png
===================================================================
(Binary files differ)
Modified: trunk/pollen-ui/src/main/webapp/img/1rightarrow.png
===================================================================
(Binary files differ)
Modified: trunk/pollen-ui/src/main/webapp/img/2leftarrow.png
===================================================================
(Binary files differ)
Modified: trunk/pollen-ui/src/main/webapp/img/2rightarrow.png
===================================================================
(Binary files differ)
Deleted: trunk/pollen-ui/src/main/webapp/js/ZoneUpdater.js
===================================================================
--- trunk/pollen-ui/src/main/webapp/js/ZoneUpdater.js 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/webapp/js/ZoneUpdater.js 2010-03-20 15:30:29 UTC (rev 2952)
@@ -1,103 +0,0 @@
-var ZoneUpdater = Class.create();
-
-ZoneUpdater.prototype = {
-
- initialize: function(zoneElementId, listeningElement, event, link, zone, placeholder) {
-
- this.zoneElement = $(zoneElementId);
-
- this.event = event;
-
- this.link = link;
-
- this.placeholder = placeholder;
-
- $T(this.zoneElement).zoneId = zone;
-
- listeningElement.observe(this.event, this.updateZone.bindAsEventListener(this));
-
- },
-
- updateZone: function(event) {
-
- var zoneObject = Tapestry.findZoneManager(this.zoneElement);
-
- if ( !zoneObject ) return;
-
- var param;
-
- if (this.zoneElement.value) {
-
- param = this.zoneElement.value;
-
- }
-
- if (!param) param = ' ';
-
- param = this.encodeForUrl(param);
-
- var updatedLink = this.link.gsub(this.placeholder, param);
-
- zoneObject.updateFromURL(updatedLink);
-
- },
-
- encodeForUrl: function(string) {
-
- /**
-
- * See equanda.js for updated version of this
-
- */
-
- string = string.replace(/\r\n/g,"\n");
-
- var res = "";
-
- for (var n = 0; n < string.length; n++)
-
- {
-
- var c = string.charCodeAt( n );
-
- if ( '$' == string.charAt( n ) )
-
- {
-
- res += '$$';
-
- }
-
- else if ( this.inRange( c, "AZ" ) || this.inRange( c, "az" ) || this.inRange( c, "09" ) || this.inRange( c, ".." ) )
-
- {
-
- res += string.charAt( n )
-
- }
-
- else
-
- {
-
- var tmp = c.toString(16);
-
- while ( tmp.length < 4 ) tmp = "0" + tmp;
-
- res += '$' + tmp;
-
- }
-
- }
-
- return res;
-
- },
-
- inRange: function(code, range) {
-
- return code >= range.charCodeAt( 0 ) && code <= range.charCodeAt( 1 );
-
- }
-
-}
\ No newline at end of file
Added: trunk/pollen-ui/src/main/webapp/js/confirm.js
===================================================================
--- trunk/pollen-ui/src/main/webapp/js/confirm.js (rev 0)
+++ trunk/pollen-ui/src/main/webapp/js/confirm.js 2010-03-20 15:30:29 UTC (rev 2952)
@@ -0,0 +1,20 @@
+/**
+ * Dialogue de confirmation
+ */
+var Confirm = Class.create({
+ /**
+ * element : Element DOM depuis lequel le dialogue de confirmation va s'ouvrir
+ * message : Message à afficher dans la boîte de dialogue
+ */
+ initialize: function(element, message) {
+ this.message = message;
+ Event.observe($(element), 'click', this.doConfirm.bindAsEventListener(this));
+ },
+ doConfirm: function(e) {
+ //Tapestry.debug('click ' + element);
+ if(! confirm(this.message)) {
+ //Tapestry.debug('STOP ' + e);
+ Event.stop(e);
+ }
+ }
+});
\ No newline at end of file
Copied: trunk/pollen-ui/src/main/webapp/js/zoneUpdater.js (from rev 2950, trunk/pollen-ui/src/main/webapp/js/ZoneUpdater.js)
===================================================================
--- trunk/pollen-ui/src/main/webapp/js/zoneUpdater.js (rev 0)
+++ trunk/pollen-ui/src/main/webapp/js/zoneUpdater.js 2010-03-20 15:30:29 UTC (rev 2952)
@@ -0,0 +1,103 @@
+var ZoneUpdater = Class.create();
+
+ZoneUpdater.prototype = {
+
+ initialize: function(zoneElementId, listeningElement, event, link, zone, placeholder) {
+
+ this.zoneElement = $(zoneElementId);
+
+ this.event = event;
+
+ this.link = link;
+
+ this.placeholder = placeholder;
+
+ $T(this.zoneElement).zoneId = zone;
+
+ listeningElement.observe(this.event, this.updateZone.bindAsEventListener(this));
+
+ },
+
+ updateZone: function(event) {
+
+ var zoneObject = Tapestry.findZoneManager(this.zoneElement);
+
+ if ( !zoneObject ) return;
+
+ var param;
+
+ if (this.zoneElement.value) {
+
+ param = this.zoneElement.value;
+
+ }
+
+ if (!param) param = ' ';
+
+ param = this.encodeForUrl(param);
+
+ var updatedLink = this.link.gsub(this.placeholder, param);
+
+ zoneObject.updateFromURL(updatedLink);
+
+ },
+
+ encodeForUrl: function(string) {
+
+ /**
+
+ * See equanda.js for updated version of this
+
+ */
+
+ string = string.replace(/\r\n/g,"\n");
+
+ var res = "";
+
+ for (var n = 0; n < string.length; n++)
+
+ {
+
+ var c = string.charCodeAt( n );
+
+ if ( '$' == string.charAt( n ) )
+
+ {
+
+ res += '$$';
+
+ }
+
+ else if ( this.inRange( c, "AZ" ) || this.inRange( c, "az" ) || this.inRange( c, "09" ) || this.inRange( c, ".." ) )
+
+ {
+
+ res += string.charAt( n )
+
+ }
+
+ else
+
+ {
+
+ var tmp = c.toString(16);
+
+ while ( tmp.length < 4 ) tmp = "0" + tmp;
+
+ res += '$' + tmp;
+
+ }
+
+ }
+
+ return res;
+
+ },
+
+ inRange: function(code, range) {
+
+ return code >= range.charCodeAt( 0 ) && code <= range.charCodeAt( 1 );
+
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/pollen-ui/src/main/webapp/js/zoneUpdater.js
___________________________________________________________________
Added: svn:mergeinfo
+
Modified: trunk/pollen-ui/src/main/webapp/poll/CreationValidation.tml
===================================================================
--- trunk/pollen-ui/src/main/webapp/poll/CreationValidation.tml 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/webapp/poll/CreationValidation.tml 2010-03-20 15:30:29 UTC (rev 2952)
@@ -8,8 +8,8 @@
<img src="${asset:context:img/vote.png}" alt="${message:vote}" style="margin-right: 18px;"/>
${message:votePage}
<br />
- <t:PageLink t:context="poll.pollId" t:page="poll/VoteForPoll" style="margin-left:50px;">
- ${siteURL}poll/VoteFor/${poll.pollId}
+ <t:PageLink t:context="poll.pollUId" t:page="poll/VoteForPoll" style="margin-left:50px;">
+ ${siteURL}poll/VoteFor/${poll.pollUId}
</t:PageLink>
</div>
<div style="margin-top: 10px;">
Modified: trunk/pollen-ui/src/main/webapp/poll/PollCreation.tml
===================================================================
--- trunk/pollen-ui/src/main/webapp/poll/PollCreation.tml 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/webapp/poll/PollCreation.tml 2010-03-20 15:30:29 UTC (rev 2952)
@@ -275,7 +275,7 @@
</div>
</t:formfragment>
<t:formfragment t:id="imgChoiceFragment" visible="isImgChoices()">
- <t:ImageContextLink t:id="imgContext" t:dir="poll.pollId" />
+ <t:ImageContextLink t:id="imgContext" t:dir="poll.pollUId" />
<div t:type="loop" t:source="imgTypeChoices" t:value="imgTypeChoice" t:volatile="true">
<div class="fleft choiceName">
<t:label for="imgFile" />
Modified: trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml
===================================================================
--- trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml 2010-03-19 15:05:04 UTC (rev 2951)
+++ trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml 2010-03-20 15:30:29 UTC (rev 2952)
@@ -14,13 +14,13 @@
<legend>${message:about}</legend>
<div style="float: right">
<t:if test="poll.publicResults">
- <t:PageLink t:page="poll/Results" t:context="poll.pollId">
+ <t:PageLink t:page="poll/Results" t:context="poll.pollUId">
<img src="${asset:context:img/count.png}" title="${message:results-help}" alt="${message:results}"/>
</t:PageLink>
</t:if>
<t:FeedContextLink t:id="feedContext" />
<t:if test="feedFileExisting">
- <t:FileLink filename="${poll.pollId}" type="literal:application/atom+xml" t:context="feedContext">
+ <t:FileLink filename="${poll.pollUId}" type="literal:application/atom+xml" t:context="feedContext">
<img src="${asset:context:img/feed.png}" title="Atom" alt="Atom"/>
</t:FileLink>
</t:if>
@@ -44,7 +44,7 @@
<!-- Sondage -->
- <t:zone t:id="pollZone" t:show="show" t:update="show">
+ <!--<t:zone t:id="pollZone" t:show="show" t:update="show">-->
<t:if t:test="poll.anonymous">
<p>${voteSizeMessage}</p>
<t:feedback t:id="voteFeedback"/>
@@ -63,72 +63,42 @@
<th></th>
</p:else>
</t:if>
- <t:if test="textType">
- <t:loop t:source="poll.choices" t:value="choiceOfPoll" volatile="true">
- <t:if test="!isChoiceHidden()">
- <th>
- <t:unless test="isDescNull()">
- <span t:type="ck/Tooltip" title="${message:description}" value="${choiceOfPoll.description}" effect="blind">
- <span class="desc">${choiceOfPoll.name}</span>
- </span>
- <p:else>
- ${choiceOfPoll.name}
- </p:else>
- </t:unless>
- <t:if test="${pollChoiceRunning}">
- <t:if test="creatorUser">
- <t:actionlink t:id="deleteChoice" context="choiceOfPoll.id" t:zone="pollZone">
- <img src="${asset:context:img/delete.png}" title="${message:delete}" alt="${message:delete}"/>
- </t:actionlink>
- </t:if>
- </t:if>
- </th>
- </t:if>
- </t:loop>
- </t:if>
- <t:if test="dateType">
- <t:loop t:source="poll.choices" t:value="choiceOfPoll" volatile="true">
- <t:unless test="choiceHidden">
- <t:unless test="isDescNull()">
- <th class="desc">
- <span t:type="ck/Tooltip" t:value="choiceOfPoll.description" t:effect="blind">
- <t:output value="choiceNameAsDate" format="dateFormat"/>
- </span>
- </th>
- <p:else>
- <th>
- <t:output value="choiceNameAsDate" format="dateFormat"/>
- </th>
- </p:else>
- </t:unless>
- </t:unless>
- </t:loop>
- </t:if>
- <t:if test="imageType">
-
- <t:loop t:source="poll.choices" t:value="choiceOfPoll" volatile="true">
- <t:if test="!isChoiceHidden()">
- <t:unless test="isDescNull()">
- <th class="desc">
- <span t:type="ck/Tooltip" title="${message:description}" value="${choiceOfPoll.description}" effect="blind">
- <t:image t:src="choiceOfPoll.name" alt="choiceOfPoll.description" t:dir="poll.pollId"/>
- </span>
- </th>
- <p:else>
- <th>
- <t:image t:src="choiceOfPoll.name" alt="choiceOfPoll.name" t:dir="poll.pollId"/>
- </th>
- </p:else>
- </t:unless>
- </t:if>
- </t:loop>
- </t:if>
+ <th t:type="loop" t:source="choices" t:value="choice" t:volatile="true">
+ <t:unless test="choice.hidden">
+ <t:block t:id="choiceText">
+ <span class="desc">${choice.text}</span>
+ </t:block>
+ <t:block t:id="choiceImage">
+ <a rel="lightbox[pollChoiceImages]" href="${imageLink}">
+ <img src="${imageThumb}" alt="${choice.description}"/>
+ </a>
+ </t:block>
+ <t:block t:id="choiceDate">
+ <t:output value="choice.date" format="dateFormat"/>
+ </t:block>
+ <t:if t:test="choice.description">
+ <span t:type="ck/Tooltip" t:value="choice.description" t:effect="blind">
+ <t:delegate to="choiceBlock" />
+ </span>
+ <p:else>
+ <t:delegate to="choiceBlock" />
+ </p:else>
+ </t:if>
+ <t:if test="canDeleteChoice()">
+ <t:actionlink t:id="deleteChoice" context="choice.id"
+ t:mixins="confirm" t:message="message:pollen.ui.choice.delete.confirm">
+ <img src="${asset:context:img/delete.png}" title="message:pollen.ui.choice.delete.title"
+ alt="message:pollen.ui.choice.delete.title"/>
+ </t:actionlink>
+ </t:if>
+ </t:unless>
+ </th>
</tr>
- </thead>
- <t:if test="pollRunning">
- <tfoot>
+ </thead><!--
+ <t:if test="pollRunning">-->
+<!-- <tfoot>
<tr>
- <t:if test="${accountFieldDisplayed}">
+ <t:if test="accountFieldDisplayed">
<th id="voterName">
<t:textField t:value="pollAccount.votingId" t:id="pollAccountName" t:validate="required"/>
</th>
@@ -136,7 +106,7 @@
<th></th>
</p:else>
</t:if>
- <t:loop t:source="poll.choices" t:value="choiceOfVote" volatile="true">
+ <t:loop t:source="choices" t:value="choice" volatile="true">
<t:if test="!choiceOfVote.hidden">
<th>
<t:if test="isNormalVoteCounting()">
@@ -155,24 +125,24 @@
</t:if>
</t:loop>
</tr>
- </tfoot>
- </t:if>
+ </tfoot>-->
+ <!--</t:if>-->
<tbody>
<t:unless t:test="poll.anonymous">
- <t:loop t:source="votes" t:value="vote" volatile="true">
+ <t:loop t:source="votes" t:value="vote" t:rowIndex="voteIndex" volatile="true">
<tr>
<td class="${evenodd.next}">
<t:if test="${AccountFieldDisplayed}">
<t:unless test="${currentVoteAnonymous}">
- ${currentVotingId}
+ ${vote.name}
<p:else>
?
</p:else>
</t:unless>
</t:if>
<t:unless test="${poll.anonymous}">
- <t:if test="isModifAllowed(currentVotingId)">
- <t:actionlink t:id="editVote" context="${currentVotingId}" t:zone="pollZone">
+ <t:if test="canEditVote()">
+ <t:actionlink t:id="editVote" context="voteIndex" t:zone="pollZone">
<img src="${asset:context:img/editSmall.png}" title="${message:edit}" alt="${message:edit}"/>
</t:actionlink>
</t:if>
@@ -231,7 +201,7 @@
<t:if test="poll.continuousResults">
<tr>
<td>
- <t:PageLink t:page="poll/results" t:context="${poll.pollId}">${message:results}</t:PageLink>
+ <t:PageLink t:page="poll/results" t:context="${poll.pollUId}">${message:results}</t:PageLink>
</td>
<t:loop t:source="poll.choices" t:value="choiceOfPoll" volatile="true">
<t:if test="!isChoiceHidden()">
@@ -256,11 +226,11 @@
</div>
</t:if>
</t:form>
- </t:zone>
+ <!--</t:zone>-->
<!-- Ajout de choix -->
- <t:ImageContextLink t:id="imgContext" t:thumb="true" t:dir="poll.pollId"/>
+ <t:ImageContextLink t:id="imgContext" t:thumb="true" t:dir="poll.pollUId"/>
<t:if test="${pollChoiceRunning}">
<h4>${message:addChoice}</h4>
<div id="choiceFormDiv">
1
0
Author: fdesbois
Date: 2010-03-19 16:05:04 +0100 (Fri, 19 Mar 2010)
New Revision: 2951
Log:
- Move SendMail thread in business module (started from PollenContext)
- Evo #148 : improve pager (with icons)
- Improve i18n managment for Tapestry integration (using tapestry-bundle goal from i18n plugin)
- Continue refactor of VoteForPoll page
Added:
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/SendMail.java
trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/SendMailTest.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollUri.java
trunk/pollen-ui/src/main/webapp/img/1leftarrow.png
trunk/pollen-ui/src/main/webapp/img/1rightarrow.png
trunk/pollen-ui/src/main/webapp/img/2leftarrow.png
trunk/pollen-ui/src/main/webapp/img/2rightarrow.png
Removed:
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java.orig
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/SendMail.java
trunk/pollen-ui/src/test/java/org/chorem/pollen/ui/utils/SendMailTest.java
Modified:
trunk/
trunk/doc/presentation-2010-03-11/Presentation-Pollen.odp
trunk/pollen-business/pom.xml
trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenBusinessException.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContext.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenException.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollConverter.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataVoteCountingConverter.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/PollDTO.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceListImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePoll.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceResultsImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceUserImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java
trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils/ContextUtil.java
trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties
trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties
trunk/pollen-business/src/main/resources/pollen.properties
trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java
trunk/pollen-business/src/test/resources/pollen.properties
trunk/pollen-ui/pom.xml
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Pager.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollHelper.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/ConfirmPoll.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/ImageDisplay.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollModification.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java
trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/Pager_en.properties
trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/Pager_fr.properties
trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_en.properties
trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_fr.properties
trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml
trunk/pom.xml
Property changes on: trunk
___________________________________________________________________
Modified: svn:ignore
- target
nbactions.xml
.settings
.classpath
.project
*.ipr
*.iws
*.iml
+ target
nbactions.xml
.settings
.classpath
.project
*.ipr
*.iws
*.iml
.pollen
Modified: trunk/doc/presentation-2010-03-11/Presentation-Pollen.odp
===================================================================
(Binary files differ)
Modified: trunk/pollen-business/pom.xml
===================================================================
--- trunk/pollen-business/pom.xml 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-business/pom.xml 2010-03-19 15:05:04 UTC (rev 2951)
@@ -27,6 +27,10 @@
<artifactId>commons-logging</artifactId>
</dependency>
<dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
+ <dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
@@ -38,6 +42,10 @@
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils</artifactId>
</dependency>
+ <dependency>
+ <groupId>net.sf.opencsv</groupId>
+ <artifactId>opencsv</artifactId>
+ </dependency>
<!-- <dependency>
<groupId>org.chorem</groupId>
<artifactId>chorem-commons</artifactId>
@@ -138,6 +146,15 @@
<goal>gen</goal>
</goals>
</execution>
+ <execution>
+ <id>make-bundle</id>
+ <goals>
+ <goal>bundle</goal>
+ </goals>
+ <configuration>
+ <bundleOutputName>pollen-business</bundleOutputName>
+ </configuration>
+ </execution>
</executions>
</plugin>
<!--<plugin>
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenBusinessException.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenBusinessException.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenBusinessException.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -1,6 +1,7 @@
package org.chorem.pollen.business;
import static org.nuiton.i18n.I18n._;
+import static org.nuiton.i18n.I18n.n_;
/**
* PollenBusinessException
@@ -18,13 +19,21 @@
private static final long serialVersionUID = 1L;
protected PollenExceptionType type;
+
+ protected Object[] args;
public PollenBusinessException(PollenExceptionType type) {
super(type.getMessage());
}
+ public PollenBusinessException(PollenExceptionType type, Object... args) {
+ super(type.getMessage());
+ this.args = args;
+ }
+
public enum PollenExceptionType {
- LOAD_CONFIGURATION(_("pollen.exception.load_configuration"));
+ //LOAD_CONFIGURATION(n_("pollen.exception.load_configuration")),
+ POLL_NOT_EXIST(n_("pollen.exception.poll_not_exist"));
private String message;
@@ -35,6 +44,9 @@
public String getMessage() {
return message;
}
+ }
+ public Object[] getArgs() {
+ return args;
}
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContext.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContext.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContext.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -7,6 +7,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.business.persistence.PollenModelDAOHelper;
+import org.chorem.pollen.business.services.SendMail;
import org.chorem.pollen.business.services.ServiceUserImpl;
import org.nuiton.i18n.I18n;
import org.nuiton.topia.TopiaContext;
@@ -16,6 +17,8 @@
import org.nuiton.util.ApplicationConfig;
import org.nuiton.util.ArgumentsParserException;
import static org.nuiton.i18n.I18n._;
+import static org.nuiton.i18n.I18n.n_;
+import org.nuiton.i18n.init.DefaultI18nInitializer;
/**
* PollenContext
@@ -39,6 +42,8 @@
private static Date currentDate;
+ private static SendMail sendMail;
+
/**
* Default configuration file will be loaded using
* {@link org.nuiton.util.ApplicationConfig }.
@@ -59,8 +64,8 @@
loadConfiguration(conf);
} catch (ArgumentsParserException eee) {
- doCatch(eee,
- _("pollen.error.context.parse", PollenContext.DEFAULT_FILENAME));
+ doCatch(eee, n_("pollen.error.context.parse"),
+ PollenContext.DEFAULT_FILENAME);
}
}
@@ -94,7 +99,11 @@
*
*/
public static void start() {
- try {
+ try {
+ if (log.isInfoEnabled()) {
+ log.info("Initialize i18n bundle");
+ }
+ I18n.setInitializer(new DefaultI18nInitializer("pollen-business"));
I18n.init();
ServiceUserImpl serviceUser = new ServiceUserImpl();
@@ -104,12 +113,15 @@
PollenProperty.ADMIN_EMAIL.getValue()
);
+ sendMail = new SendMail();
+ sendMail.start();
+
if (log.isInfoEnabled()) {
log.info("pollen is started !");
}
} catch (Exception eee) {
- doCatch(eee, _("pollen.error.context.start"));
+ doCatch(eee, n_("pollen.error.context.start"));
}
}
@@ -119,11 +131,16 @@
public static void stop() {
try {
getRootContext().closeContext();
+ sendMail.stopExec();
} catch (Exception eee) {
- doCatch(eee, _("pollen.error.context.stop"));
+ doCatch(eee, n_("pollen.error.context.stop"));
}
}
+ public static SendMail getSendMail() {
+ return sendMail;
+ }
+
/**
* Get a property from the configuration.
*
@@ -179,7 +196,7 @@
try {
return TopiaContextFactory.getContext(getProperties());
} catch (TopiaNotFoundException eee) {
- doCatch(eee, _("pollen.error.context.getRootContext"));
+ doCatch(eee, n_("pollen.error.context.getRootContext"));
}
return null;
}
@@ -191,10 +208,11 @@
*
* @param eee the exception to manage
* @param message the message to add to the new PollenException
+ * @param args for message
* @throws PollenException which contains the exception as the cause
*/
- public static void doCatch(Exception eee, String message) throws PollenException {
- doCatch(eee, message, null);
+ public static void doCatch(Exception eee, String message, Object... args) throws PollenException {
+ doCatch(null, eee, message);
}
/**
@@ -203,14 +221,15 @@
* {@code transaction} will be rollback.
* Used in catch statement in services.
*
+ * @param transaction the current TopiaContext
* @param eee the exception to manage
* @param message the message to add to the new PollenException
- * @param transaction the current TopiaContext
+ * @param args for message
* @throws PollenException
*/
- public static void doCatch(Exception eee, String message, TopiaContext transaction) throws PollenException {
+ public static void doCatch(TopiaContext transaction, Exception eee, String message, Object... args) throws PollenException {
if (log.isErrorEnabled()) {
- log.error(message, eee);
+ log.error(_(message, args), eee);
}
// rollback de la transaction courante
@@ -225,7 +244,7 @@
}
// PollenBusinessException must be managed (catch and throw) when needed
// if (! (eee instanceof PollenBusinessException)) {
- throw new PollenException(message, eee);
+ throw new PollenException(eee, message, args);
// }
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenException.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenException.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenException.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -16,8 +16,19 @@
private static final long serialVersionUID = 1L;
- public PollenException(String message, Throwable eee) {
+ protected Object[] args;
+
+// public PollenException(Throwable eee, String message) {
+// super(message, eee);
+// }
+
+ public PollenException(Throwable eee, String message, Object... args) {
super(message, eee);
+ this.args = args;
}
+ public Object[] getArgs() {
+ return args;
+ }
+
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollConverter.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollConverter.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollConverter.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -88,7 +88,7 @@
pollDTO.setCreatorEmail(ePoll.getCreator().getEmail());
}
if (ePoll.getChoice().size() > 0) {
- pollDTO.setChoiceDTOs(choiceConverter.createChoiceDTOs(ePoll
+ pollDTO.setChoices(choiceConverter.createChoiceDTOs(ePoll
.getChoice()));
}
// if (ePoll.getVote().size() > 0) {
@@ -146,7 +146,7 @@
// mise à jour ou création des choix
ServiceChoice sChoice = new ServiceChoiceImpl();
- for (ChoiceDTO choiceDTO : pollDTO.getChoiceDTOs()) {
+ for (ChoiceDTO choiceDTO : pollDTO.getChoices()) {
boolean updated = sChoice.updateChoice(choiceDTO);
if (!updated) {
choiceDTO.setId(sChoice.createChoice(choiceDTO));
@@ -163,7 +163,7 @@
Iterator<Choice> itChoice = ePoll.getChoice().iterator();
while (itChoice.hasNext()) {
Choice currentChoice = itChoice.next();
- for (ChoiceDTO choiceDTO : pollDTO.getChoiceDTOs()) {
+ for (ChoiceDTO choiceDTO : pollDTO.getChoices()) {
if (currentChoice.getTopiaId().equals(choiceDTO.getId())) {
validChoice = true;
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataVoteCountingConverter.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataVoteCountingConverter.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataVoteCountingConverter.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -188,7 +188,7 @@
bPollDTO.getComments().add(createPollCommentDTO(comment));
}
for (PollChoiceDTO choice : pollDTO.getChoices()) {
- bPollDTO.getChoiceDTOs().add(createPollChoiceDTO(choice));
+ bPollDTO.getChoices().add(createPollChoiceDTO(choice));
}
// TODO conversion des groupes et des votes
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/PollDTO.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/PollDTO.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/PollDTO.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -86,8 +86,6 @@
private List<VotingListDTO> votingListDTOs = new ArrayList<VotingListDTO>();
- private List<VoteDTO> voteDTOs = new ArrayList<VoteDTO>();
-
private int nbVotes;
private List<PreventRuleDTO> preventRuleDTOs = new ArrayList<PreventRuleDTO>();
@@ -362,14 +360,6 @@
this.votingListDTOs = votingListDTOs;
}
- public List<VoteDTO> getVoteDTOs() {
- return voteDTOs;
- }
-
- public void setVoteDTOs(List<VoteDTO> voteDTOs) {
- this.voteDTOs = voteDTOs;
- }
-
public int getNbVotes() {
return nbVotes;
}
@@ -378,13 +368,6 @@
this.nbVotes = nbVotes;
}
- public void addVote(VoteDTO vote) {
- if (voteDTOs == null) {
- voteDTOs = new ArrayList<VoteDTO>();
- }
- voteDTOs.add(vote);
- }
-
public List<PreventRuleDTO> getPreventRuleDTOs() {
return preventRuleDTOs;
}
@@ -400,11 +383,11 @@
preventRuleDTOs.add(rule);
}
- public List<ChoiceDTO> getChoiceDTOs() {
+ public List<ChoiceDTO> getChoices() {
return choiceDTOs;
}
- public void setChoiceDTOs(List<ChoiceDTO> choiceDTOs) {
+ public void setChoices(List<ChoiceDTO> choiceDTOs) {
this.choiceDTOs = choiceDTOs;
}
Copied: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/SendMail.java (from rev 2943, trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/SendMail.java)
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/SendMail.java (rev 0)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/SendMail.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -0,0 +1,248 @@
+/* *##% 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.business.services;
+
+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;
+import java.util.Map;
+
+import org.apache.commons.io.FileUtils;
+import org.chorem.pollen.business.utils.MailUtil;
+import org.nuiton.util.FileUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import au.com.bytecode.opencsv.CSVReader;
+import au.com.bytecode.opencsv.CSVWriter;
+import org.apache.commons.io.IOUtils;
+import org.chorem.pollen.business.PollenProperty;
+
+/**
+ * Mass mail management class.
+ *
+ * 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.
+ *
+ * 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$
+ *
+ * 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";
+
+ /** Mail storage directory. */
+ protected File mailStorageDirectory;
+
+ protected volatile boolean stop;
+
+ public SendMail() {
+
+ // get email directory in configuration
+ // create it if not exists
+ String filename = PollenProperty.EMAIL_DIR.getValue();
+ mailStorageDirectory = new File(filename);
+ if (!mailStorageDirectory.exists()) {
+ if (mailStorageDirectory.mkdirs()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Email storage directory created in : " + mailStorageDirectory.getAbsolutePath());
+ }
+ }
+ }
+ }
+
+ public synchronized void stopExec() {
+ stop = true;
+ }
+
+ /*
+ * @see java.lang.Runnable#run()
+ */
+ @Override
+ public void run() {
+
+ // try to find existing files
+ while (!stop) {
+ 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.
+ *
+ * After execution, delete mail and index file.
+ * @throws IOException
+ */
+ 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];
+
+ // index contains next index to treat so == is ok
+ if (currentIndex >= index) {
+ String host = PollenProperty.EMAIL_HOST.getValue();
+ int port = Integer.parseInt(
+ PollenProperty.EMAIL_PORT.getValue());
+ String from = PollenProperty.EMAIL_FROM.getValue();
+ MailUtil.sendMail(host, port, 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 woth 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.
+ *
+ * TODO : improve configuration reading
+ *
+ * @param id
+ * @param mailData
+ * @throws IOException
+ */
+ 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.closeQuietly(fileWriter);
+ }
+
+ }
+}
Property changes on: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/SendMail.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: svn:mergeinfo
+
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceListImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceListImpl.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceListImpl.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -40,7 +40,7 @@
import org.chorem.pollen.business.persistence.VotingListDAO;
import org.chorem.pollen.business.utils.ContextUtil;
import org.nuiton.topia.TopiaContext;
-import static org.nuiton.i18n.I18n._;
+import static org.nuiton.i18n.I18n.n_;
/**
* Implémentation du service de gestion des listes.
@@ -210,11 +210,9 @@
personList.addPollAccount(account);
} catch (Exception eee) {
- PollenContext.doCatch(eee,
- _("pollen.error.serviceList.createAccountForPersonList",
- personList.getName(), account.getVotingId()),
- transaction
- );
+ PollenContext.doCatch(transaction, eee,
+ n_("pollen.error.serviceList.createAccountForPersonList"),
+ personList.getName(), account.getVotingId());
} finally {
PollenContext.doFinally(transaction);
}
@@ -247,11 +245,9 @@
personList.removePollAccount(accountId);
} catch (Exception eee) {
- PollenContext.doCatch(eee,
- _("pollen.error.serviceList.deleteAccountFromPersonList",
- accountId, personList.getName(), personList.getId()),
- transaction
- );
+ PollenContext.doCatch(transaction, eee,
+ n_("pollen.error.serviceList.deleteAccountFromPersonList"),
+ accountId, personList.getName(), personList.getId());
} finally {
PollenContext.doFinally(transaction);
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePoll.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePoll.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePoll.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -78,16 +78,6 @@
public PollDTO findPollByPollId(String pollId);
/**
- * Récupération d'un sondage par son nom
- *
- * @param pollName nom du sondage
- * @return liste de sondages
- * @deprecated useless method : only used in tests
- */
- @Deprecated
- public List<PollDTO> findPollsByName(String pollName);
-
- /**
* Récupération des sondages d'un utilisateur
*
* @param userId Le créateur du sondage
@@ -137,7 +127,7 @@
public void createComment(PollDTO poll, CommentDTO comment);
/**
- * Delete a comment from a poll.
+ * Delete a comment from a {@code poll}.
*
* @param poll owner of the comment
* @param commentId id of the comment to delete
@@ -145,6 +135,15 @@
public void deleteComment(PollDTO poll, String commentId);
/**
+ * Retrieve all comments for the {@code poll}
+ *
+ * @param poll owner of the comment
+ * @return the list of comments of the poll
+ */
+ public List<CommentDTO> getComments(PollDTO poll);
+
+
+ /**
* Return the pollAccount corresponding to the {@code accountUId} for the
* restricted {@code poll}.
* TODO : need JUnit test, must be done for 1.3
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -53,6 +53,7 @@
import org.chorem.pollen.business.persistence.VotingListDAO;
import org.chorem.pollen.business.utils.ContextUtil;
import org.chorem.pollen.business.PollenContext;
+import org.chorem.pollen.business.persistence.PersonToListDAO;
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.common.VoteCountingType;
import org.nuiton.topia.TopiaContext;
@@ -60,6 +61,7 @@
import org.nuiton.topia.framework.TopiaQuery;
import org.nuiton.topia.framework.TopiaQuery.Op;
import static org.nuiton.i18n.I18n._;
+import static org.nuiton.i18n.I18n.n_;
/**
* Implémentation du service de gestion des sondages.
@@ -108,7 +110,7 @@
// ** Create new choices
ChoiceDAO choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction);
- for (ChoiceDTO choiceDTO : pollDTO.getChoiceDTOs()) {
+ for (ChoiceDTO choiceDTO : pollDTO.getChoices()) {
Choice choice =
PollenConverter.convert(choiceDTO, choiceDAO.create());
choice.setPoll(entity);
@@ -143,9 +145,9 @@
PollenConverter.convert(entity, pollDTO);
} catch (Exception eee) {
- PollenContext.doCatch(eee,
- _("pollen.error.servicePoll.createPoll",
- pollDTO.getTitle(), pollDTO.getCreatorId()), transaction);
+ PollenContext.doCatch(transaction, eee,
+ n_("pollen.error.servicePoll.createPoll"),
+ pollDTO.getTitle(), pollDTO.getCreatorId());
} finally {
PollenContext.doFinally(transaction);
}
@@ -252,7 +254,7 @@
ChoiceDAO choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction);
// ** Update choices (no add, no remove)
- for (ChoiceDTO choiceDTO : pollDTO.getChoiceDTOs()) {
+ for (ChoiceDTO choiceDTO : pollDTO.getChoices()) {
Choice choice = choiceDAO.findByTopiaId(choiceDTO.getId());
PollenConverter.convert(choiceDTO, choice);
choice.update();
@@ -272,9 +274,9 @@
return true;
} catch (Exception eee) {
- PollenContext.doCatch(eee,
- _("pollen.error.servicePoll.updatePoll",
- pollDTO.getTitle(), pollDTO.getPollId()), transaction);
+ PollenContext.doCatch(transaction, eee,
+ n_("pollen.error.servicePoll.updatePoll"),
+ pollDTO.getTitle(), pollDTO.getPollId());
return false;
} finally {
PollenContext.doFinally(transaction);
@@ -315,9 +317,8 @@
return true;
} catch (Exception eee) {
- PollenContext.doCatch(eee,
- _("pollen.error.servicePoll.deletePoll", pollId),
- transaction);
+ PollenContext.doCatch(transaction, eee,
+ n_("pollen.error.servicePoll.deletePoll"), pollId);
return false;
} finally {
PollenContext.doFinally(transaction);
@@ -329,6 +330,10 @@
TopiaContext transaction = null;
PollDTO result = null;
try {
+ if (log.isInfoEnabled()) {
+ log.info("findPollByPollId : pollUId = " + pollId);
+ }
+
transaction = rootContext.beginTransaction();
pollDAO = PollenModelDAOHelper.getPollDAO(transaction);
@@ -371,11 +376,11 @@
// }
// Load comments
- for (Comment comment : pollEntity.getComment()) {
- CommentDTO dto =
- PollenConverter.convert(comment, new CommentDTO());
- result.addComment(dto);
- }
+// for (Comment comment : pollEntity.getComment()) {
+// CommentDTO dto =
+// PollenConverter.convert(comment, new CommentDTO());
+// result.addComment(dto);
+// }
// Load preventRules
for (PreventRule rule : pollEntity.getPreventRule()) {
@@ -399,8 +404,8 @@
return result;
} catch (Exception eee) {
- PollenContext.doCatch(eee,
- _("pollen.error.servicePoll.getPoll", pollId), transaction);
+ PollenContext.doCatch(transaction, eee,
+ n_("pollen.error.servicePoll.getPoll"), pollId);
return null;
} finally {
PollenContext.doFinally(transaction);
@@ -408,36 +413,6 @@
}
@Override
- public List<PollDTO> findPollsByName(String pollName) {
- TopiaContext transaction = null;
- List<PollDTO> results = null;
- List<Poll> pollEntities = null;
- try {
- transaction = rootContext.beginTransaction();
-
- pollDAO = PollenModelDAOHelper.getPollDAO(transaction);
-
- pollEntities = pollDAO.findAllByTitle(pollName);
-
- converter.setTransaction(transaction);
- results = converter.createPollDTOs(pollEntities);
-
- transaction.commitTransaction();
-
- if (log.isDebugEnabled()) {
- log.debug("Entities found: " + ((results == null) ? "null" : results.size()));
- }
-
- return results;
- } catch (Exception e) {
- ContextUtil.doCatch(e, transaction);
- return null;
- } finally {
- PollenContext.doFinally(transaction);
- }
- }
-
- @Override
public List<PollDTO> findPollsByUser(String userId) {
TopiaContext transaction = null;
List<PollDTO> results = null;
@@ -640,8 +615,8 @@
return results;
} catch (Exception eee) {
- PollenContext.doCatch(eee,
- _("pollen.error.servicePoll.getAllPolls"), transaction);
+ ContextUtil.doCatch(eee, transaction,
+ _("pollen.error.servicePoll.getAllPolls"));
return null;
} finally {
PollenContext.doFinally(transaction);
@@ -652,6 +627,10 @@
public void createComment(PollDTO poll, CommentDTO comment) {
TopiaContext transaction = null;
try {
+ if (log.isInfoEnabled()) {
+ log.info("createComment : pollUId = " + poll.getPollId() +
+ " _ comment = " + comment);
+ }
transaction = rootContext.beginTransaction();
// Create the new comment
@@ -673,10 +652,9 @@
poll.addComment(comment);
} catch (Exception eee) {
- PollenContext.doCatch(eee,
- _("pollen.error.servicePoll.addComment",
- comment.getAuthor(), poll.getTitle(), poll.getId()),
- transaction);
+ PollenContext.doCatch(transaction, eee,
+ n_("pollen.error.servicePoll.addComment"),
+ comment.getAuthor(), poll.getTitle(), poll.getId());
} finally {
PollenContext.doFinally(transaction);
}
@@ -686,6 +664,10 @@
public void deleteComment(PollDTO poll, String commentId) {
TopiaContext transaction = null;
try {
+ if (log.isInfoEnabled()) {
+ log.info("deleteComment : pollUId = " + poll.getPollId() +
+ " _ commentId = " + commentId);
+ }
transaction = rootContext.beginTransaction();
// Find the comment
@@ -706,15 +688,47 @@
poll.removeComment(commentId);
} catch (Exception eee) {
- PollenContext.doCatch(eee,
- _("pollen.error.servicePoll.deleteComment", commentId,
- poll.getTitle(), poll.getId()), transaction);
+ PollenContext.doCatch(transaction, eee,
+ n_("pollen.error.servicePoll.deleteComment"), commentId,
+ poll.getTitle(), poll.getId());
} finally {
PollenContext.doFinally(transaction);
}
}
@Override
+ public List<CommentDTO> getComments(PollDTO poll) {
+ TopiaContext transaction = null;
+ List<CommentDTO> results = new ArrayList<CommentDTO>();
+ try {
+ if (log.isInfoEnabled()) {
+ log.info("getComments : pollUId = " + poll.getPollId());
+ }
+ transaction = rootContext.beginTransaction();
+
+ CommentDAO dao = PollenModelDAOHelper.getCommentDAO(transaction);
+ TopiaQuery query = dao.createQuery().
+ add(Comment.POLL + "." + Poll.POLL_ID, poll.getPollId());
+
+ List<Comment> entities = dao.findAllByQuery(query);
+
+ for (Comment entity : entities) {
+ CommentDTO dto =
+ PollenConverter.convert(entity, new CommentDTO());
+ results.add(dto);
+ }
+
+ } catch (Exception eee) {
+ PollenContext.doCatch(transaction, eee,
+ n_("pollen.error.servicePoll.getComments"),
+ poll.getTitle(), poll.getId());
+ } finally {
+ PollenContext.doFinally(transaction);
+ }
+ return results;
+ }
+
+ @Override
public PollAccountDTO getRestrictedAccount(String accountUId, PollDTO poll) {
TopiaContext transaction = null;
PollAccountDTO result = null;
@@ -728,26 +742,34 @@
// Use PersonToList association entity to find coherence between
// the poll and votingId
- List<PersonToList> tmp = transaction.find(
- "FROM " + PersonToList.class.getName() +
- " WHERE pollAccount.accountId = :accountUId" +
- " AND votingList.poll.pollId = :pollUId",
- "accountUId", accountUId,
- "pollUId", poll.getPollId());
+// List<PersonToList> tmp = transaction.find(
+// "FROM " + PersonToList.class.getName() +
+// " WHERE pollAccount.accountId = :accountUId" +
+// " AND votingList.poll.pollId = :pollUId",
+// "accountUId", accountUId,
+// "pollUId", poll.getPollId());
- //PersonToListDAO dao = PollenModel
+ PersonToListDAO dao =
+ PollenModelDAOHelper.getPersonToListDAO(transaction);
+ TopiaQuery query = dao.createQuery().
+ add(PersonToList.POLL_ACCOUNT + "." +
+ PollAccount.ACCOUNT_ID, accountUId).
+ add(PersonToList.VOTING_LIST + "." +
+ VotingList.POLL + "." + Poll.POLL_ID, poll.getPollId());
- if (tmp.size() > 0) {
- PollAccount account = tmp.get(0).getPollAccount();
+ PersonToList assoc = dao.findByQuery(query);
+
+ if (assoc != null) {
+ PollAccount account = assoc.getPollAccount();
PollenConverter.convert(account, result);
}
} catch (Exception eee) {
- ContextUtil.doCatch(eee, transaction,
- "Unable to retrieve restricted account with accountUId = " +
- accountUId + " and poll with uid = " + poll.getPollId());
+ PollenContext.doCatch(transaction, eee,
+ n_("pollen.error.servicePoll.getRestrictedAccount"),
+ accountUId, poll.getPollId());
} finally {
- ContextUtil.doFinally(transaction);
+ PollenContext.doFinally(transaction);
}
return result;
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceResultsImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceResultsImpl.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceResultsImpl.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -45,7 +45,7 @@
import org.chorem.pollen.votecounting.services.ServiceVoteCounting;
import org.chorem.pollen.votecounting.services.ServiceVoteCountingImpl;
import org.nuiton.topia.TopiaContext;
-import static org.nuiton.i18n.I18n._;
+import static org.nuiton.i18n.I18n.n_;
/**
* Implémentation du service de gestion des résultats.
@@ -297,7 +297,7 @@
} catch (Exception eee) {
PollenContext.doCatch(eee,
- _("pollen.error.serviceResults.importPoll"));
+ n_("pollen.error.serviceResults.importPoll"));
}
return topiaId;
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceUserImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceUserImpl.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceUserImpl.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -31,7 +31,7 @@
import org.chorem.pollen.business.utils.ContextUtil;
import org.chorem.pollen.business.utils.MD5;
import org.nuiton.topia.TopiaContext;
-import static org.nuiton.i18n.I18n._;
+import static org.nuiton.i18n.I18n.n_;
/**
* Implémentation du service de gestion des utilisateurs.
@@ -335,9 +335,9 @@
transaction.commitTransaction();
}
} catch (Exception eee) {
- PollenContext.doCatch(eee,
- _("pollen.error.serviceUser.createDefaultAdmin",
- login, email), transaction);
+ PollenContext.doCatch(transaction, eee,
+ n_("pollen.error.serviceUser.createDefaultAdmin"),
+ login, email);
} finally {
PollenContext.doFinally(transaction);
}
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -22,13 +22,13 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.business.PollenBusinessException;
import org.chorem.pollen.business.PollenContext;
import org.chorem.pollen.business.converters.DataPollAccountConverter;
import org.chorem.pollen.business.converters.DataVoteConverter;
import org.chorem.pollen.business.dto.PollAccountDTO;
import org.chorem.pollen.business.dto.PollDTO;
import org.chorem.pollen.business.dto.VoteDTO;
+import org.chorem.pollen.business.persistence.Poll;
import org.chorem.pollen.business.persistence.PollAccount;
import org.chorem.pollen.business.persistence.PollAccountDAO;
import org.chorem.pollen.business.persistence.PollenModelDAOHelper;
@@ -36,6 +36,9 @@
import org.chorem.pollen.business.persistence.VoteDAO;
import org.chorem.pollen.business.utils.ContextUtil;
import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.topia.persistence.TopiaEntity;
+import static org.nuiton.i18n.I18n.n_;
/**
* Implémentation du service de gestion des votes.
@@ -46,7 +49,6 @@
public class ServiceVoteImpl implements ServiceVote {
private TopiaContext rootContext;
- private VoteDAO voteDAO = null;
private DataVoteConverter converter = new DataVoteConverter();
/** log. */
@@ -77,7 +79,8 @@
// .getId());
if (pollAccountEntity == null) {
log.debug("Nouveau compte associé au vote");
- pollAccountEntity = pollAccountDAO.create(ContextUtil.createPollenUrlId());
+ pollAccountEntity = pollAccountDAO.create(
+ PollenContext.createPollenUrlId());
// EVO #108 : Migration to ToPIA 2.3, the entity must be
// commited because an other findBy is called in the
// converter (wtf ?! :/). This behavior doesn't work
@@ -107,7 +110,7 @@
voteDTO.setPollAccountId(null);
}
- voteDAO = PollenModelDAOHelper.getVoteDAO(transaction);
+ VoteDAO voteDAO = PollenModelDAOHelper.getVoteDAO(transaction);
Vote voteEntity = voteDAO.create();
converter.setTransaction(transaction);
@@ -139,7 +142,7 @@
try {
transaction = rootContext.beginTransaction();
- voteDAO = PollenModelDAOHelper.getVoteDAO(transaction);
+ VoteDAO voteDAO = PollenModelDAOHelper.getVoteDAO(transaction);
Vote voteEntity = voteDAO.findByTopiaId(voteDTO.getId());
converter.setTransaction(transaction);
converter.populateVoteEntity(voteDTO, voteEntity);
@@ -166,7 +169,7 @@
try {
transaction = rootContext.beginTransaction();
- voteDAO = PollenModelDAOHelper.getVoteDAO(transaction);
+ VoteDAO voteDAO = PollenModelDAOHelper.getVoteDAO(transaction);
Vote voteEntity = voteDAO.findByTopiaId(voteId);
voteEntity.delete();
@@ -191,33 +194,39 @@
TopiaContext transaction = null;
List<VoteDTO> results = new ArrayList<VoteDTO>();
try {
+ if (log.isInfoEnabled()) {
+ log.info("getVotesByPoll : pollUId = " + poll.getPollId() +
+ " _ startIndex = " + startIndex +
+ " _ endIndex = " + endIndex);
+ }
+
// No need to load votes for an anonymous poll
if (poll.isAnonymous()) {
return results;
}
- // FIXME-FD20100309 : change model to suppress link from poll to vote
+ // FIXME-FD20100309 : change dto to suppress link from poll to vote
// It's not necessary to have votes when retrieving the poll, this
// method do this job only when it's needed
+ transaction = rootContext.beginTransaction();
- if (log.isDebugEnabled()) {
- log.debug("Load votes for poll with uid = " + poll.getPollId());
- log.debug("LIMIT : startIndex = " + startIndex + " _ " +
- "endIndex = " + endIndex);
- }
+// List<Vote> votes = transaction.find(
+// "FROM " + Vote.class.getName() +
+// " WHERE poll.pollId = :pollUId" +
+// " ORDER BY topiaCreateDate",
+// startIndex, endIndex,
+// "pollUId", poll.getPollId());
- transaction = rootContext.beginTransaction();
-
- // FIXME : refactor this to use TopiaQuery from ToPIA 2.3
+ VoteDAO voteDAO = PollenModelDAOHelper.getVoteDAO(transaction);
// Order the results by creation date (the last vote done will be
// at the end of the list)
- List<Vote> votes = transaction.find(
- "FROM " + Vote.class.getName() +
- " WHERE poll.pollId = :pollUId" +
- " ORDER BY topiaCreateDate",
- startIndex, endIndex,
- "pollUId", poll.getPollId());
+ TopiaQuery query = voteDAO.createQuery().
+ add(Vote.POLL + "." + Poll.POLL_ID, poll.getPollId()).
+ addOrder(TopiaEntity.TOPIA_CREATE_DATE).
+ setLimit(startIndex, endIndex);
+ List<Vote> votes = voteDAO.findAllByQuery(query);
+
if (log.isDebugEnabled()) {
log.debug("Nb votes found : " + votes.size());
}
@@ -225,11 +234,11 @@
results = converter.createVoteDTOs(votes);
} catch (Exception eee) {
- ContextUtil.doCatch(eee, transaction,
- "Unable to load votes from poll with uid = " +
+ PollenContext.doCatch(transaction, eee,
+ n_("pollen.error.serviceVote.getVotesByPoll"),
poll.getPollId());
} finally {
- ContextUtil.doFinally(transaction);
+ PollenContext.doFinally(transaction);
}
return results;
}
@@ -239,30 +248,39 @@
TopiaContext transaction = null;
boolean result = false;
try {
+ if (log.isInfoEnabled()) {
+ log.info("hasAlreadyVoted : votingId = " + votingId +
+ " _ pollUId = " + poll.getPollId());
+ }
transaction = rootContext.beginTransaction();
+
+// List<Long> tmp = transaction.find(
+// "SELECT COUNT(*)" +
+// " FROM " + Vote.class.getName() +
+// " WHERE poll.pollId = :pollUId" +
+// " AND pollAccount.votingId = :votingId",
+// "pollUId", poll.getPollId(),
+// "votingId", votingId);
- // Test using a count(*) on votes
- List<Long> tmp = transaction.find(
- "SELECT COUNT(*)" +
- " FROM " + Vote.class.getName() +
- " WHERE poll.pollId = :pollUId" +
- " AND pollAccount.votingId = :votingId",
- "pollUId", poll.getPollId(),
- "votingId", votingId);
+ // Test using a count on votes
+ TopiaQuery query = new TopiaQuery(Vote.class).
+ add(Vote.POLL + "." + Poll.POLL_ID, poll.getPollId()).
+ add(Vote.POLL_ACCOUNT + "." + PollAccount.VOTING_ID,
+ votingId);
- int count = tmp.get(0).intValue();
+ int count = query.executeCount(transaction);
// If the count is greater than 0, there is an existing votingId
// who has already voted for the poll
result = count > 0;
} catch (Exception eee) {
- ContextUtil.doCatch(eee, transaction,
- "Unable test vote existing for account with votingId = " +
- votingId + " and poll with uid = " + poll.getPollId());
+ PollenContext.doCatch(transaction, eee,
+ n_("pollen.error.serviceVote.hasAlreadyVoted"),
+ votingId, poll.getPollId());
} finally {
- ContextUtil.doFinally(transaction);
+ PollenContext.doFinally(transaction);
}
return result;
}
@@ -275,7 +293,7 @@
try {
transaction = rootContext.beginTransaction();
- voteDAO = PollenModelDAOHelper.getVoteDAO(transaction);
+ VoteDAO voteDAO = PollenModelDAOHelper.getVoteDAO(transaction);
if (properties == null) {
voteEntities = voteDAO.findAll();
Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils/ContextUtil.java
===================================================================
--- trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils/ContextUtil.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils/ContextUtil.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -353,7 +353,7 @@
}
// PollenBusinessException must be managed (catch and throw) when needed
// if (! (eee instanceof PollenBusinessException)) {
- throw new PollenException(message, eee);
+ throw new PollenException(eee, message);
// }
}
Modified: trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties
===================================================================
--- trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties 2010-03-19 15:05:04 UTC (rev 2951)
@@ -12,8 +12,13 @@
pollen.error.servicePoll.deleteComment=
pollen.error.servicePoll.deletePoll=
pollen.error.servicePoll.getAllPolls=
+pollen.error.servicePoll.getComments=
pollen.error.servicePoll.getPoll=
+pollen.error.servicePoll.getRestrictedAccount=Unable to retrieve restricted account with accountUId \= %1$s and poll with uid \= %2$s
pollen.error.servicePoll.updatePoll=
pollen.error.serviceResults.importPoll=
pollen.error.serviceUser.createDefaultAdmin=
+pollen.error.serviceVote.getVotesByPoll=Unable to load votes from poll with uid \= %1$s
+pollen.error.serviceVote.hasAlreadyVoted=Unable test vote existing for account with votingId \= %1$s and poll with uid \= %2$s
pollen.exception.load_configuration=
+pollen.exception.poll_not_exist=No such poll exists. Please make sure that you are using the correct link and copy it completely into your browser's address field.
Modified: trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties
===================================================================
--- trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties 2010-03-19 15:05:04 UTC (rev 2951)
@@ -9,10 +9,15 @@
pollen.error.servicePoll.addComment=Impossible d'ajouter un nouveau commentaire cr\u00E9\u00E9 par %1$s pour le sondage %2$s (%3$s)
pollen.error.servicePoll.createPoll=Impossible d'enregistrer le sondage %1$s cr\u00E9\u00E9 par %2$s
pollen.error.servicePoll.deleteComment=Impossible de supprimer le commentaire ayant pour identifiant "%1$s", appartenenant au sondage %2$s (%3$s)
-pollen.error.servicePoll.deletePoll=Impossible de supprimer le sondage ayant pour identifiant "%1$s"
+pollen.error.servicePoll.deletePoll=Impossible de supprimer le sondage ayant pou identifiant "%1$s"
pollen.error.servicePoll.getAllPolls=
+pollen.error.servicePoll.getComments=
pollen.error.servicePoll.getPoll=
+pollen.error.servicePoll.getRestrictedAccount=Unable to retrieve restricted account with accountUId \= %1$s and poll with uid \= %2$s
pollen.error.servicePoll.updatePoll=Impossible de mettre \u00E0 jour le sondage %1$s (%2$s)
pollen.error.serviceResults.importPoll=
pollen.error.serviceUser.createDefaultAdmin=Impossible de cr\u00E9er l'administrateur par d\u00E9faut \: %1$s (%2$s)
+pollen.error.serviceVote.getVotesByPoll=
+pollen.error.serviceVote.hasAlreadyVoted=
pollen.exception.load_configuration=La configuration n'a pas \u00E9t\u00E9 charg\u00E9e correctement \! Veuillez v\u00E9rifier le d\u00E9marrage de l'application.
+pollen.exception.poll_not_exist=Il n'y a pas de sondage \u00E0 cette adresse. Veuillez verifier que vous utilisez le lien correcte et copiez-le compl\u00E8tement dans le champ d'adresse de votre navigateur.
Modified: trunk/pollen-business/src/main/resources/pollen.properties
===================================================================
--- trunk/pollen-business/src/main/resources/pollen.properties 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-business/src/main/resources/pollen.properties 2010-03-19 15:05:04 UTC (rev 2951)
@@ -49,7 +49,7 @@
pollen.emails.directory=.pollen/emails
## Nombre de votes a afficher par page
-pollen.ui.nbVotesPerPage=50
+pollen.ui.nbVotesPerPage=25
## Adresse du site (utilis\u00C3\u00A9e pour les emails de rappel)
siteUrl=
Copied: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/SendMailTest.java (from rev 2943, trunk/pollen-ui/src/test/java/org/chorem/pollen/ui/utils/SendMailTest.java)
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/SendMailTest.java (rev 0)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/SendMailTest.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -0,0 +1,103 @@
+/* *##% Pollen
+ * Copyright (C) 2010 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.business.services;
+
+import org.chorem.pollen.business.services.SendMail;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.chorem.pollen.business.PollenContext;
+import org.chorem.pollen.business.PollenProperty;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.nuiton.util.ApplicationConfig;
+
+/**
+ * Class for send mail storage class.
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+@Ignore
+public class SendMailTest {
+
+ protected static SendMail sendMail;
+
+ @BeforeClass
+ public static void init() throws InterruptedException {
+
+ ApplicationConfig config = new ApplicationConfig();
+ config.setOption(PollenProperty.EMAIL_DIR.getKey(), "target" + File.separator + "massmail");
+ config.setOption(PollenProperty.EMAIL_HOST.getKey(), "smtp");
+ config.setOption(PollenProperty.EMAIL_PORT.getKey(), "25");
+ config.setOption(PollenProperty.EMAIL_FROM.getKey(), "pollenreminder(a)codelutin.com");
+
+ PollenContext.loadConfiguration(config);
+
+ sendMail = new SendMail();
+ sendMail.start();
+ Thread.sleep(3000);
+ }
+
+ /**
+ * Test to add mail and send mail.
+ *
+ * WARNING : This test really send mail, don't set it automatic.
+ *
+ * @throws IOException
+ * @throws InterruptedException
+ */
+ @Test
+ public void testAddMail() throws IOException, InterruptedException {
+ List<Map<String, String>> mailList = new ArrayList<Map<String,String>>();
+
+ Map<String, String> mailMap = new HashMap<String, String>();
+ mailMap.put("receiver", "chatellier+test(a)codelutin.com");
+ mailMap.put("subject", "Test 18:00");
+ mailMap.put("body", "Test body");
+
+ Map<String, String> mailMap2 = new HashMap<String, String>();
+ mailMap2.put("receiver", "chorlet+test(a)codelutin.com");
+ mailMap2.put("subject", "CR, CR CR !!! 18:00");
+ mailMap2.put("body", "Des cr, encore des \"CRs\" !!!");
+
+ mailList.add(mailMap);
+ mailList.add(mailMap2);
+
+ sendMail.prepareMails("test", mailList);
+
+ String emailDir = PollenProperty.EMAIL_DIR.getValue();
+
+ Assert.assertTrue(new File(emailDir, "test.mail").exists());
+ Assert.assertTrue(new File(emailDir, "test.index").exists());
+ sendMail.wakeUp();
+
+ // TODO , en 5 secondes, il aura le temps d'envoyer 2 mails ?
+ Thread.sleep(5000);
+ Assert.assertFalse(new File(emailDir, "test.mail").exists());
+ Assert.assertFalse(new File(emailDir, "test.index").exists());
+ }
+}
Property changes on: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/SendMailTest.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: svn:mergeinfo
+
Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java
===================================================================
--- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -116,7 +116,7 @@
choice3.setName("choice3");
choices.add(choice3);
- dto.setChoiceDTOs(choices);
+ dto.setChoices(choices);
final String result = instance.createPoll(dto);
if (log.isDebugEnabled()) {
@@ -214,24 +214,24 @@
/**
* Test of findPollsByName method, of class ServicePollImpl.
*/
- @Test
- public void testFindPollsByName() throws Exception {
- TestManager.start("testFindPollsByName");
- instance = new ServicePollImpl();
+// @Test
+// public void testFindPollsByName() throws Exception {
+// TestManager.start("testFindPollsByName");
+// instance = new ServicePollImpl();
+//
+// PollDTO dto = instance.getNewPoll();
+// dto.setDescription("Test_findPollsByName");
+// dto.setCreatorId("erwan");
+// dto.setAnonymous(false);
+// dto.setPollType(PollType.FREE);
+// dto.setChoiceType(ChoiceType.TEXT);
+// dto.setVoteCounting(VoteCountingType.NORMAL);
+// dto.setTitle("Test_findPollsByName");
+// String pollId = instance.createPoll(dto);
+// List<PollDTO> result = instance.findPollsByName("Test_findPollsByName");
+// assertEquals(result.size(), 1);
+// }
- PollDTO dto = instance.getNewPoll();
- dto.setDescription("Test_findPollsByName");
- dto.setCreatorId("erwan");
- dto.setAnonymous(false);
- dto.setPollType(PollType.FREE);
- dto.setChoiceType(ChoiceType.TEXT);
- dto.setVoteCounting(VoteCountingType.NORMAL);
- dto.setTitle("Test_findPollsByName");
- String pollId = instance.createPoll(dto);
- List<PollDTO> result = instance.findPollsByName("Test_findPollsByName");
- assertEquals(result.size(), 1);
- }
-
/**
* Test of findPollsByUser method, of class ServicePollImpl.
*/
@@ -474,4 +474,28 @@
test.execute();
}
+
+ /**
+ * Test of getRestrictedAccount method, of class ServicePollImpl.
+ */
+ //@Test
+ public void testGetRestrictedAccount() throws IOException {
+ TestManager.start("testGetRestrictedAccount");
+ instance = new ServicePollImpl();
+
+ /** PREPARE DATA **/
+ PollDTO poll = instance.getNewPoll();
+ poll.setTitle("restrictedAccount");
+ poll.setPollType(PollType.RESTRICTED);
+ poll.setChoiceType(ChoiceType.TEXT);
+ poll.setVoteCounting(VoteCountingType.NORMAL);
+ String id = instance.createPoll(poll);
+ poll.setId(id);
+
+ PollAccountDTO account = new PollAccountDTO();
+ account.setVotingId("toto");
+
+ // TODO
+
+ }
}
Modified: trunk/pollen-business/src/test/resources/pollen.properties
===================================================================
--- trunk/pollen-business/src/test/resources/pollen.properties 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-business/src/test/resources/pollen.properties 2010-03-19 15:05:04 UTC (rev 2951)
@@ -1,4 +1,4 @@
-# Configuration de la base de données
+# Configuration de la base de donn\u00C3\u00A9es
hibernate.hbm2ddl.auto=update
hibernate.show_sql=false
hibernate.dialect=org.hibernate.dialect.H2Dialect
@@ -7,9 +7,11 @@
hibernate.connection.driver_class=org.h2.Driver
hibernate.connection.url=jdbc:h2:file:target/test-base/pollen
-# Initialisation de la base de données
+# Initialisation de la base de donn\u00C3\u00A9es
choiceType=DATE,IMAGE,TEXT
pollType=RESTRICTED,FREE,GROUP
voteCounting=NORMAL,PERCENTAGE,CONDORCET
adminLogin=admin
-adminPassword=admin
\ No newline at end of file
+adminPassword=admin
+
+pollen.emails.directory=target/test-emails
\ No newline at end of file
Modified: trunk/pollen-ui/pom.xml
===================================================================
--- trunk/pollen-ui/pom.xml 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-ui/pom.xml 2010-03-19 15:05:04 UTC (rev 2951)
@@ -132,7 +132,6 @@
<goal>tapestry-bundle</goal>
</goals>
</execution>
-
</executions>
</plugin>
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Pager.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Pager.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Pager.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -1,13 +1,13 @@
package org.chorem.pollen.ui.components;
+import org.apache.tapestry5.Asset;
import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.ComponentResources;
-import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.Link;
import org.apache.tapestry5.MarkupWriter;
-import org.apache.tapestry5.annotations.Log;
import org.apache.tapestry5.annotations.Parameter;
+import org.apache.tapestry5.annotations.Path;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.slf4j.Logger;
@@ -42,11 +42,21 @@
private int currentPage;
/**
- * Number of rows to show per page.
+ * Number of rows to show per page, the page which contains the pager have
+ * to manage this property (using @Persist for exemple) to ensure that
+ * the pager will done its work correctly.
*/
@Parameter(required = true)
private int nbRowsPerPage;
+ /**
+ * Number of rows for each range. Static value different from variable
+ * nbRowsPerPage. This parameter is used to show some links to change
+ * nbRowsPerPage.
+ */
+ @Parameter("25")
+ private int range;
+
@Parameter(defaultPrefix = BindingConstants.LITERAL)
private String noPagerText;
@@ -59,6 +69,26 @@
@Inject
private Logger log;
+ @Inject
+ @Path("context:img/1leftarrow.png")
+ private Asset leftarrow1;
+
+ @Inject
+ @Path("context:img/2leftarrow.png")
+ private Asset leftarrow2;
+
+ @Inject
+ @Path("context:img/1rightarrow.png")
+ private Asset rightarrow1;
+
+ @Inject
+ @Path("context:img/2rightarrow.png")
+ private Asset rightarrow2;
+
+ private static final String ACTION_CHANGE_PAGE = "changePage";
+
+ private static final String ACTION_CHANGE_NB_ROWS = "changeNbRows";
+
void beginRender(MarkupWriter writer) {
if (log.isDebugEnabled()) {
log.debug("pager from : " + getFirstValue() + " to " + getLastValue());
@@ -77,10 +107,12 @@
if (hasPrevious()) {
int previousPage = currentPage - 1;
if (previousPage != getFirstPage()) {
- writeLink(writer, getFirstPage(), "<<", "p-pager-first");
+ writeChangePageLink(writer, getFirstPage(), leftarrow2,
+ "p-pager-first");
writer.write(" ");
}
- writeLink(writer, previousPage, "<", "p-pager-previous");
+ writeChangePageLink(writer, previousPage, leftarrow1,
+ "p-pager-previous");
writer.write(" ");
}
// Text display for current page
@@ -88,19 +120,32 @@
messages.format("rows-title",
getFirstValue(), getLastValue(), nbTotalRows));
writer.element("strong");
- writer.write(messages.format("page", currentPage));
+ writer.write(messages.format("page", currentPage, getLastPage()));
writer.end();
writer.end();
if (hasNext()) {
int nextPage = currentPage + 1;
writer.write(" ");
- writeLink(writer, nextPage, ">", "p-pager-next");
+ writeChangePageLink(writer, nextPage, rightarrow1, "p-pager-next");
if (nextPage != getLastPage()) {
writer.write(" ");
- writeLink(writer, getLastPage(), ">>", "p-pager-last");
+ writeChangePageLink(writer, getLastPage(),
+ rightarrow2, "p-pager-last");
}
}
+
+ int doubleNbPerPage = range * 2;
+ int quadrupleNbPerPage = range * 4;
+ writer.element("div", "class", "p-pager-nbrows");
+ writer.write(messages.format("showPerPage"));
+ writer.write(" ");
+ writeChangeNbRowsLink(writer, range);
+ writer.write(", ");
+ writeChangeNbRowsLink(writer, doubleNbPerPage);
+ writer.write(", ");
+ writeChangeNbRowsLink(writer, quadrupleNbPerPage);
+ writer.end();
}
writer.end();
}
@@ -110,25 +155,43 @@
}
/**
- * Use an action event to change the current page. The link refresh the
+ * Use an changePage event to change the current page. The link refresh the
* entire page, no zone is managed yet.
*
- * @param writer used to write a element
+ * @param writer used to write an element
* @param index new page to change (argument of onAction method)
- * @param text to write inside the a tag
+ * @param asset for action
* @param style of the css (class) for the a tag
*/
- protected void writeLink(MarkupWriter writer, int index,
- String text, String style) {
- Link link = resources.createEventLink(EventConstants.ACTION,
+ protected void writeChangePageLink(MarkupWriter writer, int index,
+ Asset asset, String style) {
+ Link link = resources.createEventLink(ACTION_CHANGE_PAGE,
new Object[] {index});
String title = messages.format("go-to", index);
writer.element("a", "href", link, "class", style, "title", title);
- writer.write(text);
+ writer.element("img", "src", asset,
+ "alt", style);
writer.end();
+ writer.end();
}
/**
+ * Use an changeNbRows event to change the number of rows per page. The link
+ * refresh the entire page, no zone is managed yet.
+ *
+ * @param writer used to write an element
+ * @param nbRows to show and needed for the link
+ */
+ protected void writeChangeNbRowsLink(MarkupWriter writer, int nbRows) {
+ Link link = resources.createEventLink(ACTION_CHANGE_NB_ROWS,
+ new Object[] {nbRows});
+ String title = messages.format("change-nbrows", nbRows);
+ writer.element("a", "href", link, "title", title);
+ writer.write(String.valueOf(nbRows));
+ writer.end();
+ }
+
+ /**
* Get the start index of the range shown.
*
* @return the start index for elements to show
@@ -190,8 +253,20 @@
*
* @param newPage to set
*/
- void onAction(int newPage) {
+ void onChangePage(int newPage) {
currentPage = newPage;
}
+ /**
+ * Action event for changing nb rows. The nbRowsPerPage is changed to
+ * {@code nbRows}.
+ *
+ * @param nbRows to set
+ */
+ void onChangeNbRows(int nbRows) {
+ nbRowsPerPage = nbRows;
+ // Reset to first page to avoid strange text like (Page 8/2)
+ currentPage = getFirstPage();
+ }
+
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollHelper.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollHelper.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollHelper.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -101,7 +101,7 @@
public static List<ChoiceDTO> getTextChoices(PollDTO oldPoll) {
List<ChoiceDTO> choices = new ArrayList<ChoiceDTO>();
if (oldPoll.getChoiceType() == ChoiceType.TEXT) {
- for (ChoiceDTO oldChoice : oldPoll.getChoiceDTOs()) {
+ for (ChoiceDTO oldChoice : oldPoll.getChoices()) {
ChoiceDTO choice = new ChoiceDTO();
choice.setName(oldChoice.getName());
choice.setDescription(oldChoice.getDescription());
@@ -120,7 +120,7 @@
public static List<DateChoiceUIO> getDateChoices(PollDTO oldPoll) {
List<DateChoiceUIO> choices = new ArrayList<DateChoiceUIO>();
if (oldPoll.getChoiceType() == ChoiceType.DATE) {
- for (ChoiceDTO oldChoice : oldPoll.getChoiceDTOs()) {
+ for (ChoiceDTO oldChoice : oldPoll.getChoices()) {
DateChoiceUIO choice = new DateChoiceUIO();
choice.setName(oldChoice.getName());
choice.setDescription(oldChoice.getDescription());
Added: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollUri.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollUri.java (rev 0)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollUri.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -0,0 +1,49 @@
+
+package org.chorem.pollen.ui.data;
+
+import org.apache.tapestry5.ValueEncoder;
+
+/**
+ * PollUri
+ *
+ * Created: 15 mars 2010
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class PollUri {
+
+ private static final String SEPARATOR = ":";
+
+ protected String pollUId;
+
+ protected String accountUId;
+
+ public PollUri(String uri) {
+ String[] tab = uri.split(SEPARATOR);
+ pollUId = tab[0];
+ if (tab.length == 2) {
+ accountUId = tab[1];
+ }
+ }
+
+ public String getAccountUId() {
+ return accountUId;
+ }
+
+ public String getPollUId() {
+ return pollUId;
+ }
+
+ public String getUri() {
+ String uri = getPollUId();
+ if (getAccountUId() != null) {
+ uri += SEPARATOR + getAccountUId();
+ }
+ return uri;
+ }
+
+}
Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/data/PollUri.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/ConfirmPoll.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/ConfirmPoll.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/ConfirmPoll.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -114,7 +114,7 @@
* @return la page de validation de cloture
*/
private Object closePoll() {
- for (ChoiceDTO choice : poll.getChoiceDTOs()) {
+ for (ChoiceDTO choice : poll.getChoices()) {
choice.setValidate(true);
}
Date now = new Date();
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/ImageDisplay.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/ImageDisplay.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/ImageDisplay.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -106,7 +106,7 @@
*/
void onActivate() {
choice = new ChoiceDTO();
- for (ChoiceDTO c : poll.getChoiceDTOs()) {
+ for (ChoiceDTO c : poll.getChoices()) {
if (choiceId.equals(c.getId())) {
choice = c;
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -48,6 +48,7 @@
import org.apache.tapestry5.ioc.services.PropertyAccess;
import org.apache.tapestry5.json.JSONObject;
import org.apache.tapestry5.upload.services.UploadSymbols;
+import org.chorem.pollen.business.PollenContext;
import org.chorem.pollen.business.PollenProperty;
import org.chorem.pollen.business.business.PreventRuleManager;
import org.chorem.pollen.business.dto.ChoiceDTO;
@@ -74,7 +75,6 @@
import org.chorem.pollen.ui.data.uio.ImageChoiceUIO;
import org.chorem.pollen.ui.utils.FeedUtil;
import org.chorem.pollen.ui.utils.ImageUtil;
-import org.chorem.pollen.ui.utils.SendMail;
import org.chorem.pollen.ui.utils.UnitConverter;
import org.slf4j.Logger;
@@ -315,9 +315,6 @@
@Inject
private ServiceList serviceList;
-// @Inject
-// private SendMail sendMailService;
-
/**
* Méthode appelée lorsqu'on souhaite accéder à l'étape suivante de la
* création de sondage.
@@ -700,7 +697,7 @@
for (ChoiceDTO choice : choices) {
if (choice.getName() != null) {
choice.setValidate(true);
- poll.getChoiceDTOs().add(choice);
+ poll.getChoices().add(choice);
}
}
} else if (isDateChoices()) {
@@ -708,7 +705,7 @@
if (choice.getDate() != null) {
choice.setValidate(true);
choice.setName(String.valueOf(choice.getDate().getTime()));
- poll.getChoiceDTOs().add(choice);
+ poll.getChoices().add(choice);
}
}
} else if (isImgChoices()) {
@@ -719,7 +716,7 @@
"IMAGE")) {
imgChoice.setValidate(true);
imgChoice.setName(imgChoice.getImg().getFileName().replace(' ', '_'));
- poll.getChoiceDTOs().add(imgChoice);
+ poll.getChoices().add(imgChoice);
} else {
return false;
}
@@ -737,8 +734,8 @@
if (poll.isContinuousResults()) {
poll.setPublicResults(true);
}
- if (poll.getMaxChoiceNb() < 1 || poll.getMaxChoiceNb() > poll.getChoiceDTOs().size()) {
- poll.setMaxChoiceNb(poll.getChoiceDTOs().size());
+ if (poll.getMaxChoiceNb() < 1 || poll.getMaxChoiceNb() > poll.getChoices().size()) {
+ poll.setMaxChoiceNb(poll.getChoices().size());
}
return true;
@@ -854,14 +851,14 @@
}
// 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);
-// }
-// }
+ try {
+ PollenContext.getSendMail().prepareMails(poll.getId(), mailList);
+ PollenContext.getSendMail().wakeUp();
+ } catch (IOException ex) {
+ if (log.isErrorEnabled()) {
+ log.error("Can't prepare send mail on disk, mail won't be send !!!", ex);
+ }
+ }
}
}
Deleted: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java.orig
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java.orig 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java.orig 2010-03-19 15:05:04 UTC (rev 2951)
@@ -1,1252 +0,0 @@
-/* *##% 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.ui.pages.poll;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.fileupload.FileUploadException;
-import org.apache.commons.lang.StringUtils;
-import org.apache.tapestry5.BindingConstants;
-import org.apache.tapestry5.ComponentResources;
-import org.apache.tapestry5.Link;
-import org.apache.tapestry5.ValidationException;
-import org.apache.tapestry5.annotations.Component;
-import org.apache.tapestry5.annotations.IncludeStylesheet;
-import org.apache.tapestry5.annotations.InjectComponent;
-import org.apache.tapestry5.annotations.InjectPage;
-import org.apache.tapestry5.annotations.Log;
-import org.apache.tapestry5.annotations.Parameter;
-import org.apache.tapestry5.annotations.Persist;
-import org.apache.tapestry5.annotations.Property;
-import org.apache.tapestry5.annotations.SessionState;
-import org.apache.tapestry5.corelib.components.Form;
-import org.apache.tapestry5.corelib.components.Select;
-import org.apache.tapestry5.corelib.components.Zone;
-import org.apache.tapestry5.ioc.Messages;
-import org.apache.tapestry5.ioc.annotations.Inject;
-import org.apache.tapestry5.ioc.annotations.Symbol;
-import org.apache.tapestry5.ioc.services.PropertyAccess;
-import org.apache.tapestry5.json.JSONObject;
-import org.apache.tapestry5.upload.services.UploadSymbols;
-import org.chorem.pollen.business.PollenProperty;
-import org.chorem.pollen.business.business.PreventRuleManager;
-import org.chorem.pollen.business.dto.ChoiceDTO;
-import org.chorem.pollen.business.dto.PersonListDTO;
-import org.chorem.pollen.business.dto.PollAccountDTO;
-import org.chorem.pollen.business.dto.PollDTO;
-import org.chorem.pollen.business.dto.PreventRuleDTO;
-import org.chorem.pollen.business.dto.UserDTO;
-import org.chorem.pollen.business.dto.VotingListDTO;
-import org.chorem.pollen.business.services.ServiceList;
-import org.chorem.pollen.business.services.ServicePoll;
-import org.chorem.pollen.business.services.ServicePollAccount;
-import org.chorem.pollen.common.ChoiceType;
-import org.chorem.pollen.common.PollType;
-import org.chorem.pollen.common.VoteCountingType;
-import org.chorem.pollen.ui.base.ContextLink;
-import org.chorem.pollen.ui.components.FeedBack;
-import org.chorem.pollen.ui.components.ImageContextLink;
-import org.chorem.pollen.ui.data.GenericSelectModel;
-import org.chorem.pollen.ui.data.AddressBarItem;
-import org.chorem.pollen.ui.data.PollHelper;
-import org.chorem.pollen.ui.data.PollStep;
-import org.chorem.pollen.ui.data.uio.DateChoiceUIO;
-import org.chorem.pollen.ui.data.uio.ImageChoiceUIO;
-import org.chorem.pollen.ui.utils.FeedUtil;
-import org.chorem.pollen.ui.utils.ImageUtil;
-import org.chorem.pollen.ui.utils.UnitConverter;
-import org.slf4j.Logger;
-
-/**
- * Classe de la page de création d'un sondage.
- *
- * @author kmorin
- * @author rannou
- * @version $Id: PollCreation.java 2893 2010-03-02 20:14:34Z fdesbois $
- */
-@IncludeStylesheet("context:css/pollCreation.css")
-public class PollCreation {
-
- @Inject
- private Logger log;
-
- /** Étape courante du formulaire */
- @Persist
- private PollStep step;
-
- /**
- * Objet de session représentant l'utilisateur identifié.
- */
- @SessionState
- private UserDTO user;
- @Property
- private boolean userExists;
-
- /**
- * Objet de session représentant l'url du site.
- */
- @SessionState
- @Property
- private String siteURL;
-
- /** Date de début du sondage (utilisée pour la validation). */
- private Date beginDateValidation;
-
- /** Date de début d'ajout des choix (utilisée pour la validation). */
- private Date beginChoiceDateValidation;
-
- /** Mixin de selection de liste de favoris */
- @SuppressWarnings("unused")
- private Select listSelect;
-
- @InjectComponent
- private Zone pollCreationZone;
-
- /**
- * Sondage créé par le formulaire
- */
- @Property
- @Persist
- private PollDTO poll;
-
- /**
- * Sondage copié pour créer un nouveau sondage
- */
- @Persist
- private PollDTO oldPoll;
-
- /**
- * Sondage copié existe.
- */
- private boolean oldPollExists = false;
-
- /**
- * variable utilisée pour déterminer si le bouton cliqué mène à l'étape
- * suivante
- */
- private boolean noStepSubmitSelected = false;
-
- /**
- * variable utilisée pour déterminer si le bouton d'ajout de choix a été
- * cliqué
- */
- @Persist
- private boolean addChoiceSelected;
-
- /**
- * variable utilisée pour déterminer le groupe à supprimer
- */
- private int deleteGroupId = -1;
-
- /**
- * variable utilisée pour déterminer s'il y a eu une exception lors de
- * l'upload des images
- */
- @Persist
- private boolean uploadExceptionCatched;
-
- /** variable utilisée pour l'affichage de la choiceNbCheckBox */
- @Property
- @Persist
- private boolean choiceNbCheckBox;
-
- /** variable utilisée pour l'affichage de la notificationCheckBox */
- @Property
- @Persist
- private boolean notificationCheckBox;
-
- /** variable utilisée pour l'affichage de la reminderCheckBox */
- @Property
- @Persist
- private boolean reminderCheckBox;
-
- /** Règle de notification de vote */
- @Property
- @Persist
- private PreventRuleDTO notificationPreventRule;
-
- /** Règle de notification pour le rappel des votants */
- @Property
- @Persist
- private PreventRuleDTO reminderPreventRule;
-
- /**
- * Groupes de votants à créer
- */
- @Property
- @Persist
- private List<VotingListDTO> votingLists;
-
- /**
- * Objet utilisé dans la boucle de parcours des listes de votants
- */
- @Property
- private VotingListDTO votingList;
-
- /**
- * Objet utilisé dans la boucle de parcours de la liste de votants courante
- */
- @SuppressWarnings("unused")
- @Property
- private PollAccountDTO votingListPerson;
-
- /**
- * Nombre de votants affichés initialement
- */
- @Property
- private int nbVotingListPersons = 5;
-
- /**
- * Liste modifiée actuellement
- */
- @Persist
- private int currentList;
-
- /**
- * Listes de favoris de l'utilisateur.
- */
- @Property
- @Persist
- private GenericSelectModel<PersonListDTO> personLists;
-
- /**
- * Liste de favoris sélectionnée.
- */
- @Property
- private PersonListDTO personList;
-
- /**
- * Nombre de choix affichés initialement
- */
- @Property
- private int nbChoices = 5;
-
- /**
- * Objet utilisé dans la boucle de parcours de la liste des choix
- */
- @SuppressWarnings("unused")
- @Property
- private ChoiceDTO choice;
-
- /**
- * Objet utilisé dans la boucle de parcours de la liste des choix
- */
- @SuppressWarnings("unused")
- @Property
- private DateChoiceUIO dateTypeChoice;
-
- /**
- * Objet utilisé dans la boucle de parcours de la liste des choix
- */
- @SuppressWarnings("unused")
- @Property
- private ImageChoiceUIO imgTypeChoice;
-
- /**
- * Liste des choix à créer
- */
- @Property
- @Persist
- private List<ChoiceDTO> choices;
-
- /**
- * Liste des choix à créer
- */
- @Property
- @Persist
- private List<DateChoiceUIO> dateTypeChoices;
-
- /**
- * Liste des choix à créer
- */
- @Property
- @Persist
- private List<ImageChoiceUIO> imgTypeChoices;
-
- /**
- * Contexte pour l'upload des images (parametres definis dans .tml)
- */
- @InjectComponent
- private ImageContextLink imgContext;
-
- /**
- * Contexte pour la gestion du flux RSS
- */
- @InjectComponent
- private ContextLink feedContext;
-
- /**
- * Formulaire de création de sondage
- */
- @Component(id = "pollCreationForm")
- private Form pollCreationForm;
- @Component(id = "choicesCreationForm")
- private Form choicesCreationForm;
-
- @InjectPage
- private CreationValidation creationValidation;
-
- @Parameter(defaultPrefix = BindingConstants.MESSAGE, value = "title")
- @Property
- private String title;
-
- @SuppressWarnings("unused")
- @Property
- private AddressBarItem[] address;
-
- @Inject
- private PropertyAccess _propertyAccess;
-
- @Inject
- private ComponentResources resources;
-
- /** Affichage des messages pour l'utilisateur */
- @Component(id = "feedback")
- private FeedBack feedback;
-
- /** Tailles maximales des fichiers uploadés */
- @Inject
- @Symbol(UploadSymbols.FILESIZE_MAX)
- private int fileSizeMax;
- @Inject
- @Symbol(UploadSymbols.REQUESTSIZE_MAX)
- private int requestSizeMax;
-
- @Inject
- private Messages messages;
-
- @Inject
- private Logger logger;
-
- /** Injection des services */
- @Inject
- private ServicePoll servicePoll;
- @Inject
- private ServicePollAccount servicePollAccount;
- @Inject
- private ServiceList serviceList;
-
- /**
- * Méthode appelée lorsqu'on souhaite accéder à l'étape suivante de la
- * création de sondage.
- */
- @Log
- Object onSuccessFromPollCreationForm() {
- if (log.isDebugEnabled()) {
- log.debug("Step : " + step);
- }
- switch (step) {
- case POLL:
- adaptStepPoll();
- step = PollStep.OPTIONS;
- break;
- case OPTIONS:
- adaptStepOptions();
- if (isFreePoll()) {
- step = PollStep.CHOICES;
- } else {
- step = PollStep.LISTS;
- }
- break;
- case LISTS:
- if (deleteGroupId >= 0) {
- votingLists.remove(deleteGroupId);
- }
- if (!noStepSubmitSelected) {
- step = PollStep.CHOICES;
- }
- break;
- case CHOICES:
- break;
- default:
- step = PollStep.POLL;
- break;
- }
- // Cas particulier, autre formulaire pour les choix
- if (step.equals(PollStep.CHOICES)) {
- return choicesCreationForm;
- }
- return pollCreationForm;
- }
-
- /**
- * Méthode appelée que le formulaire soit valide ou non. Il est nécessaire
- * de la redéfinir pour qu'en cas d'erreur de validation, la zone soit tout
- * de même mise à jour pour afficher l'erreur.
- */
- @Log
- Object onSubmitFromPollCreationForm() {
- return pollCreationForm;
- }
-
- /**
- * Méthode appelée lorsqu'on souhaite valider la création du sondage.
- */
- Object onSuccessFromChoicesCreationForm() {
- if (!addChoiceSelected) {
-
- // Préparation et création du sondage
- if (!preparePoll()) {
- return this;
- }
- createPoll();
-
- creationValidation.setPoll(poll);
- return creationValidation;
- }
-
- return this;
- }
-
- /**
- * Méthode appelée lorsqu'on souhaite accéder à l'étape précédente de la
- * création de sondage.
- */
- Object onPrevious() {
- switch (step) {
- case OPTIONS:
- step = PollStep.POLL;
- break;
- case LISTS:
- step = PollStep.OPTIONS;
- break;
- case CHOICES:
- if (isFreePoll()) {
- step = PollStep.OPTIONS;
- } else {
- step = PollStep.LISTS;
- }
- break;
- default:
- step = PollStep.POLL;
- break;
- }
- return pollCreationForm; // Pas de gestion du formulaire des choix car derniere etape
- }
-
- /**
- * Méthode appelée lors de la validation du formulaire. Validation du champs
- * beginDate.
- *
- * @throws ValidationException
- */
- void onValidateFromBeginDate(Date value) throws ValidationException {
- beginDateValidation = value;
- if (value != null && value.before(new Date())) {
- throw new ValidationException(messages.get("beginDate-validate"));
- }
- }
-
- /**
- * Méthode appelée lors de la validation du formulaire. Validation du champs
- * endDate.
- *
- * @throws ValidationException
- */
- void onValidateFromEndDate(Date value) throws ValidationException {
- if (beginDateValidation == null) {
- beginDateValidation = new Date();
- }
-
- if (value != null && value.before(beginDateValidation)) {
- throw new ValidationException(messages.get("endDate-validate"));
- }
- }
-
- /**
- * Méthode appelée lors de la validation du formulaire. Validation du champs
- * beginChoiceDate.
- *
- * @throws ValidationException
- */
- void onValidateFromBeginChoiceDate(Date value) throws ValidationException {
- if (beginDateValidation == null) {
- beginDateValidation = new Date();
- }
- beginChoiceDateValidation = value;
- if (value != null && value.after(beginDateValidation)) {
- throw new ValidationException(messages
- .get("beginChoiceDate-validate"));
- }
- }
- /**
- * Méthode appelée lors de la validation du formulaire. Validation du champs
- * endChoiceDate.
- *
- * @throws ValidationException
- */
- void onValidateFromEndChoiceDate(Date value) throws ValidationException {
- if (beginChoiceDateValidation == null) {
- beginChoiceDateValidation = new Date();
- }
-
- if (value != null && value.before(beginChoiceDateValidation)) {
- throw new ValidationException(messages.get("endChoiceDate-validate"));
- }
- }
-
- /**
- * Méthode appelée lors de la validation du formulaire. Validation des
- * listes de votants.
- *
- * @throws ValidationException
- */
- void onValidateFormFromPollCreationForm() throws ValidationException {
- if (noStepSubmitSelected) {
- return;
- }
-
- // Validation des votants
- if (step == PollStep.LISTS) {
- int nbListEqual = 0;
- int nbEqual = 0;
- int nbNotNull = 0;
-
- // Repérage des doublons (listes)
- for (VotingListDTO list1 : votingLists) {
- for (VotingListDTO list2 : votingLists) {
- if (list1.getName().equals(list2.getName())) {
- nbListEqual++;
- }
- }
- }
-
- if (nbListEqual > votingLists.size()) {
- throw new ValidationException(messages.get("lists-validate"));
- }
-
- // Repérage des doublons (votants)
- for (VotingListDTO list1 : votingLists) {
- int nbLocalNotNull = 0;
- for (PollAccountDTO account1 : list1.getPollAccountDTOs()) {
- if (account1.getVotingId() != null
- && account1.getVotingId() != "") {
- nbNotNull++;
- nbLocalNotNull++;
-
- // comparaison avec les autres votants
- for (VotingListDTO list2 : votingLists) {
- for (PollAccountDTO account2 : list2
- .getPollAccountDTOs()) {
- if (account2.getVotingId() != null
- && account1.getVotingId() != "") {
- if (account1.getVotingId().equals(
- account2.getVotingId())) {
- nbEqual++;
- }
- }
- }
- }
- }
- }
- if (nbLocalNotNull == 0) {
- throw new ValidationException(messages
- .get("noList-validate"));
- }
- }
-
- if (logger.isDebugEnabled()) {
- logger.debug("Votants (equal/notNull) : " + nbEqual + "/"
- + nbNotNull);
- }
- if (nbEqual > nbNotNull) {
- throw new ValidationException(messages.get("list-validate"));
- }
- }
- }
-
- /**
- * Méthode appelée lors de la validation du formulaire. Validation de la
- * liste de choix.
- *
- * @throws ValidationException
- */
- void onValidateFormFromChoicesCreationForm() throws ValidationException {
- int nbEqual = 0;
- int nbNotNull = 0;
-
- // Validation des choix
- if (step == PollStep.CHOICES) {
-
- // Repérage des doublons (type Texte)
- if (isTextChoices()) {
- for (ChoiceDTO choice1 : choices) {
- if (choice1.getName() != null) {
- nbNotNull++;
- for (ChoiceDTO choice2 : choices) {
- if (choice2.getName() != null) {
- if (choice1.getName().equals(choice2.getName())) {
- nbEqual++;
- }
- }
- }
- }
- }
- // Repérage des doublons (type Date)
- } else if (isDateChoices()) {
- for (DateChoiceUIO choice1 : dateTypeChoices) {
- if (choice1.getDate() != null) {
- nbNotNull++;
- for (DateChoiceUIO choice2 : dateTypeChoices) {
- if (choice2.getDate() != null) {
- if (choice1.getDate().equals(choice2.getDate())) {
- nbEqual++;
- }
- }
- }
- }
- }
- // Repérage des doublons (type Image)
- } else if (isImgChoices()) {
- for (ImageChoiceUIO choice1 : imgTypeChoices) {
- if (choice1.getImg() != null) {
- nbNotNull++;
- for (ImageChoiceUIO choice2 : imgTypeChoices) {
- if (choice2.getImg() != null) {
- if (choice1.getImg().getFileName().equals(
- choice2.getImg().getFileName())) {
- nbEqual++;
- }
- }
- }
- }
- }
- }
-
- if (nbNotNull == 0) {
- throw new ValidationException(messages.get("noChoice-validate"));
- }
- if (nbEqual > nbNotNull) {
- throw new ValidationException(messages.get("choice-validate"));
- }
- }
- }
-
- /** Echec lors du téléchargement */
- Object onUploadException(FileUploadException e) {
- logger.error(e.getMessage());
- String fSize = UnitConverter.getFormattedFileSize(fileSizeMax);
- String rSize = UnitConverter.getFormattedFileSize(requestSizeMax);
- feedback.addError(messages.format("uploadError", fSize, rSize));
- uploadExceptionCatched = true;
- return this;
- }
-
- /**
- * Réinitialisation des options en fonction des autres options.
- */
- private void adaptStepOptions() {
- if (poll.isAnonymous()) {
- poll.setAnonymousVoteAllowed(true);
- }
- if (poll.isContinuousResults()) {
- poll.setPublicResults(true);
- }
- }
-
- /**
- * Réinitialisation des listes de votants en fonction du type de sondage.
- */
- @Log
- private void adaptStepPoll() {
-
- // Sondage libre : suppression de toutes les listes
- if (isFreePoll()) {
- votingLists.clear();
- }
-
- // Sondage restreint : suppression des listes supplémentaires
- else if (isRestrictedPoll() && votingLists.size() > 1) {
- for (int i = 1; i < votingLists.size(); i++) {
- votingLists.remove(i);
- }
- currentList = 0;
- }
-
- // Sondage non libre : création d'une liste initiale
- else if (votingLists.isEmpty()) {
- votingList = new VotingListDTO();
- for (int i = 0; i < nbVotingListPersons; i++) {
- votingList.getPollAccountDTOs().add(new PollAccountDTO());
- }
- votingLists.add(votingList);
- currentList = getVotingListIndex();
- }
-
- if (poll.getBeginDate() != null) {
- poll.setEndChoiceDate(poll.getBeginDate());
- }
- }
-
- /**
- * Préparation du sondage.
- */
- @Log
- private boolean preparePoll() {
-
- // Ajout de l'identifiant du créateur
- if (userExists) {
- poll.setUserId(user.getId());
- }
-
- // Ajout des règles de notification au sondage
- if (notificationCheckBox) {
- poll.getPreventRuleDTOs().add(notificationPreventRule);
- }
- if (reminderCheckBox) {
- poll.getPreventRuleDTOs().add(reminderPreventRule);
- }
-
- // Ajout des groupes de votants au sondage
- // après suppression des entrées vides
- if (!isFreePoll()) {
- for (VotingListDTO list : votingLists) {
- Iterator<PollAccountDTO> it = list.getPollAccountDTOs()
- .iterator();
- while (it.hasNext()) {
- if (it.next().getVotingId() == null) {
- it.remove();
- }
- }
- }
- poll.setVotingListDTOs(votingLists);
- }
-
-
- // Ajout des choix au sondage
- if (isTextChoices()) {
- for (ChoiceDTO choice : choices) {
- if (choice.getName() != null) {
- choice.setValidate(true);
- poll.getChoiceDTOs().add(choice);
- }
- }
- } else if (isDateChoices()) {
- for (DateChoiceUIO choice : dateTypeChoices) {
- if (choice.getDate() != null) {
- choice.setValidate(true);
- choice.setName(String.valueOf(choice.getDate().getTime()));
- poll.getChoiceDTOs().add(choice);
- }
- }
- } else if (isImgChoices()) {
- for (ImageChoiceUIO imgChoice : imgTypeChoices) {
- if (imgChoice.getImg() != null) {
- logger.debug("Image: " + imgChoice.getImg().getFileName()
- + ", type: " + imgChoice.getImg().getContentType());
- if (imgChoice.getImg().getContentType().contains("image")
- || imgChoice.getImg().getContentType().contains(
- "IMAGE")) {
- imgChoice.setValidate(true);
- imgChoice.setName(imgChoice.getImg().getFileName()
- .replace(' ', '_'));
- poll.getChoiceDTOs().add(imgChoice);
- } else {
- return false;
- }
- }
- }
- }
-
- // Retouche des attributs dépendants l'un de l'autre
- if (poll.getBeginDate() == null) {
- poll.setBeginDate(new Date());
- }
- if (poll.isAnonymous()) {
- poll.setAnonymousVoteAllowed(true);
- }
- if (poll.isContinuousResults()) {
- poll.setPublicResults(true);
- }
- if (poll.getMaxChoiceNb() < 1
- || poll.getMaxChoiceNb() > poll.getChoiceDTOs().size()) {
- poll.setMaxChoiceNb(poll.getChoiceDTOs().size());
- }
-
- return true;
- }
-
- /**
- * Création du sondage.
- */
- private void createPoll() {
-
- // Création du sondage
- servicePoll.createPoll(poll);
-
- // FD-20100226 : Can't be null, an exception will be thrown if a
- // problem comes from createPoll
- //if (poll.getId() != null) {
-
- // Création des images
- if (poll.getChoiceType() == ChoiceType.IMAGE) {
- File dir = imgContext.getImageDir();
- ImageUtil.saveImages(imgTypeChoices, dir);
- }
-
- // FD-20100226 : not necessary, the service will update
- // automatically the poll when it was created
- // Mise à jour du sondage :
- //poll = servicePoll.findPollById(poll.getId());
-
- // Mise à jour du flux Atom et envoi d'un mail de confirmation
- addFeedEntry();
- sendMailNotification();
- //}
- }
-
- /** Ajout d'une entrée dans le flux de syndication */
- 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"));
- }
-
- /** Envoi du mail de notification */
- private void sendMailNotification() {
- PollAccountDTO creator = servicePollAccount.findPollAccountById(poll
- .getCreatorId());
- String voteURL = siteURL + "poll/VoteFor/" + poll.getPollId();
- String modifURL = siteURL + "poll/Modification/" + poll.getPollId()
- + ":" + creator.getAccountId();
- Map<String, String> data = new HashMap<String, String>();
- data.put("host", PollenProperty.EMAIL_HOST.getValue());
- data.put("port", PollenProperty.EMAIL_PORT.getValue());
- data.put("from", PollenProperty.EMAIL_FROM.getValue());
-
- // Mail au créateur
- if (poll.getCreatorEmail() != null) {
- data.put("to", poll.getCreatorEmail());
- data.put("title", messages.format("creatorEmail_subject", poll
- .getTitle()));
- data.put("msg", messages.format("creatorEmail_msg",
- poll.getTitle(), voteURL, modifURL));
-
- PreventRuleManager.emailAction(data);
- }
-
- // Mails aux votants
- for (VotingListDTO list : poll.getVotingListDTOs()) {
- for (PollAccountDTO account : list.getPollAccountDTOs()) {
- if (account.getEmail() != null) {
- String accountVoteURL = voteURL + ":"
- + account.getAccountId();
-
- data.put("to", account.getEmail());
- data.put("title", messages.format("votingEmail_subject",
- poll.getTitle()));
- data
- .put("msg", messages.format("votingEmail_msg", poll
- .getTitle(), account.getVotingId(),
- accountVoteURL));
-
- PreventRuleManager.emailAction(data);
- }
- }
- }
- }
-
- public String getChoiceDateDisplay() {
- return poll.isChoiceAddAllowed() ? "display: block;" : "display: none;";
- }
-
- public String getChoiceNbDisplay() {
- return choiceNbCheckBox ? "display: block;" : "display: none;";
- }
-
- public String getNotificationDisplay() {
- return notificationCheckBox ? "display: block;" : "display: none;";
- }
-
- public String getReminderDisplay() {
- return reminderCheckBox ? "display: block;" : "display: none;";
- }
-
- /** Retourne l'index de la liste courante */
- public int getVotingListIndex() {
- return votingLists.indexOf(votingList);
- }
-
- /** Retourne le numéro de la liste courante (index+1) */
- public int getVotingListNumber() {
- return votingLists.indexOf(votingList) + 1;
- }
-
- /** Retourne la chaîne correspondant à l'étape courante */
- public String getStepLegend() {
- Integer index = step.getIndex();
-
- // corrections selon le type de sondage
- if (isFreePoll()) {
- if (step == PollStep.CHOICES) {
- index--;
- }
- }
-
- // mise en forme du message
- switch (step) {
- case POLL:
- return messages.format("pollLegend", index);
- case OPTIONS:
- return messages.format("optionsLegend", index);
- case LISTS:
- return messages.format("listsLegend", index);
- case CHOICES:
- return messages.format("choicesLegend", index);
- default:
- return "";
- }
- }
-
- /** Retourne la classe CSS correspondant au groupe courant */
- public String getCurrentListClass() {
- if (votingLists.size() > 1 && getVotingListIndex() == currentList) {
- return "currentGroupDiv";
- }
- return "groupDiv";
- }
-
- /**
- * Retourne s'il existe plusieurs groupes.
- */
- public boolean isSeveralGroups() {
- return votingLists.size() > 1;
- }
-
- public boolean isInPoll() {
- return step == PollStep.POLL;
- }
-
- public boolean isInLists() {
- return step == PollStep.LISTS;
- }
-
- public boolean isInChoices() {
- return step == PollStep.CHOICES;
- }
-
- public boolean isInOptions() {
- return step == PollStep.OPTIONS;
- }
-
- public boolean isNormalVoteCounting() {
- return poll.getVoteCounting() == VoteCountingType.NORMAL;
- }
-
- public boolean isPercentageVoteCounting() {
- return poll.getVoteCounting() == VoteCountingType.PERCENTAGE;
- }
-
- public boolean isCondorcetVoteCounting() {
- return poll.getVoteCounting() == VoteCountingType.CONDORCET;
- }
-
- public boolean isNumberVoteCounting() {
- return poll.getVoteCounting() == VoteCountingType.NUMBER;
- }
-
- public boolean isFreePoll() {
- return poll.getPollType() == PollType.FREE;
- }
-
- public boolean isRestrictedPoll() {
- return poll.getPollType() == PollType.RESTRICTED;
- }
-
- public boolean isGroupPoll() {
- return poll.getPollType() == PollType.GROUP;
- }
-
- public boolean isTextChoices() {
- return poll.getChoiceType() == ChoiceType.TEXT;
- }
-
- public boolean isDateChoices() {
- return poll.getChoiceType() == ChoiceType.DATE;
- }
-
- public boolean isImgChoices() {
- return poll.getChoiceType() == ChoiceType.IMAGE;
- }
-
- /**
- * Méthode appelée à la sélection d'une liste de votants. Le mixin
- * ck/OnEvent ne permet pas de retourner le contenu d'une zone. Il faut donc
- * passer par une fonction JavaScript pour activer un event link. Un lien
- * est créé. Il sera retourné à la fonction JavaScript onCompleteCallback
- * pour mettre à jour la zone.
- *
- * @param value
- * @return un JSONObject contenant l'url de l'évènement mettant à jour la
- * zone.
- */
- public JSONObject onChangeFromListSelect(String value) {
- if (StringUtils.isNotEmpty(value)) {
- personList = serviceList.findPersonListById(value);
-
- // Copie des personnes de la liste de favoris dans la liste de votants
- for (PollAccountDTO account : personList.getPollAccounts()) {
- account.setId("");
- account.setPersonListId("");
- }
-
- votingLists.get(currentList).setPollAccountDTOs(
- personList.getPollAccounts());
- }
- return createParamsForCallback();
- }
-
- /**
- * Méthode appelée à la sélection d'un type de choix. Le mixin ck/OnEvent ne
- * permet pas de retourner le contenu d'une zone. Il faut donc passer par
- * une fonction JavaScript pour activer un event link. Un lien est créé. Il
- * sera retourné à la fonction JavaScript onCompleteCallback pour mettre à
- * jour la zone.
- *
- * @return un JSONObject contenant l'url de l'évènement mettant à jour la
- * zone.
- */
- public JSONObject onChangeFromChoiceType(String value) {
- poll.setChoiceType(ChoiceType.valueOf(value));
- return createParamsForCallback();
- }
-
- /**
- * Création d'un JSONObject contenant un identifiant de zone et une url pour
- * un évènement.
- *
- * @return un JSONObject contenant un zoneId et une url.
- */
- private JSONObject createParamsForCallback() {
- JSONObject json = new JSONObject();
- Link link = resources.createEventLink("updatePollCreationZone");
- json.put("link", link.toAbsoluteURI());
- json.put("zoneId", "pollCreationZone");
- return json;
- }
-
- /**
- * Méthode appelée par le callback JavaScript pour mettre à jour la zone.
- *
- * @return le contenu mis à jour de la zone.
- */
- public Object onUpdatePollCreationZone() {
- return pollCreationZone.getBody();
- }
-
- /**
- * Méthode appelée pour l'ajout d'une ligne supplémentaire dans le
- * formulaire des listes de votants.
- */
- void onSelectedFromAddPerson(int i) {
- votingLists.get(i).getPollAccountDTOs().add(new PollAccountDTO());
- noStepSubmitSelected = true;
- }
-
- /**
- * Méthode appelée pour l'ajout d'un groupe dans le formulaire des listes de
- * votants.
- */
- void onSelectedFromAddGroup() {
- votingList = new VotingListDTO();
- for (int i = 0; i < nbVotingListPersons; i++) {
- votingList.getPollAccountDTOs().add(new PollAccountDTO());
- }
- votingLists.add(votingList);
- currentList = getVotingListIndex();
- noStepSubmitSelected = true;
- }
-
- /**
- * Méthode appelée lors de la suppression d'un groupe dans le formulaire des
- * listes de votants.
- */
- void onSelectedFromDeleteGroup(int i) {
- //votingLists.remove(i);
- if (currentList == i) {
- currentList = votingLists.size() - 1;
- } else if (currentList > i) {
- currentList--;
- }
- deleteGroupId = i;
- noStepSubmitSelected = true;
- }
-
- /**
- * Méthode appelée à la selection d'un groupe dans le formulaire des listes
- * de votants.
- */
- void onSelectedFromEditGroup(int i) {
- currentList = i;
- noStepSubmitSelected = true;
- }
-
- /**
- * Méthode appelée pour l'ajout d'une ligne supplémentaire dans le
- * formulaire des choix.
- */
- void onSelectedFromAddChoice() {
- if (poll.getChoiceType() == ChoiceType.DATE) {
- dateTypeChoices.add(new DateChoiceUIO());
- } else if (poll.getChoiceType() == ChoiceType.IMAGE) {
- imgTypeChoices.add(new ImageChoiceUIO());
- } else {
- choices.add(new ChoiceDTO());
- }
- addChoiceSelected = true;
- }
-
- /** Retourne vrai si des listes de favoris existent */
- public boolean isPersonListsExists() {
- return personLists != null && !personLists.getList().isEmpty();
- }
-
- /**
- * Activation de la page
- */
- void onActivate(String id) {
-
- // Si un sondage est fourni (copie de sondage)
- if (id != null && !"".equals(id)) {
-
- // Réinitialisation des variables de session
- // Si l'ancien sondage n'existe pas ou est différent de celui fourni
- if (oldPoll == null || !id.equals(oldPoll.getPollId())) {
- oldPoll = servicePoll.findPollByPollId(id);
- if (oldPoll != null) {
- initWithExistingPoll(oldPoll);
- oldPoll = null;
- oldPollExists = true;
- }
- }
- }
- }
-
- /**
- * Initialisation de l'affichage
- */
- void setupRender() {
- address = new AddressBarItem[] { new AddressBarItem("Pollen", "Index"),
- new AddressBarItem(title, null) };
-
- if (!addChoiceSelected && !uploadExceptionCatched
- && !choicesCreationForm.getHasErrors()) {
- step = PollStep.POLL;
- if (!oldPollExists) {
- oldPoll = null;
- initPoll();
- }
- initPersonLists();
- }
-
- addChoiceSelected = false;
- uploadExceptionCatched = false;
- }
-
- /**
- * Initialisation du sondage.
- */
- private void initPoll() {
-
- // Initialisation du sondage
- poll = new PollDTO();
- if (userExists) {
- poll.setCreatorName(user.getLogin());
- poll.setCreatorEmail(user.getEmail());
- }
-
- // Initialisation des règles de notification
- notificationPreventRule = new PreventRuleDTO("vote", 0, true,
- PreventRuleManager.EMAIL_ACTION);
- reminderPreventRule = new PreventRuleDTO("rappel", 0, false,
- PreventRuleManager.EMAIL_ACTION);
-
- notificationCheckBox = false;
- reminderCheckBox = false;
- choiceNbCheckBox = false;
-
- // Initialisation des choix
- choices = new ArrayList<ChoiceDTO>();
- dateTypeChoices = new ArrayList<DateChoiceUIO>();
- imgTypeChoices = new ArrayList<ImageChoiceUIO>();
- for (int i = 0; i < nbChoices; i++) {
- choices.add(new ChoiceDTO());
- dateTypeChoices.add(new DateChoiceUIO());
- imgTypeChoices.add(new ImageChoiceUIO());
- }
-
- // Initialisation des listes de votants
- votingLists = new ArrayList<VotingListDTO>();
- }
-
- /**
- * Initialisation du sondage à partir d'un sondage existant.
- */
- private void initWithExistingPoll(PollDTO oldPoll) {
-
- // Initialisation du sondage
- poll = PollHelper.getPoll(oldPoll);
-
- // Initialisation du créateur du sondage
-// PollAccountDTO creator = servicePollAccount.findPollAccountById(oldPoll
-// .getCreatorId());
- //poll.setCreatorId(oldPoll.getCreatorId());
- poll.setCreatorName(oldPoll.getCreatorName());
- poll.setCreatorEmail(oldPoll.getCreatorEmail());
-
- // Initialisation des règles de notification
- notificationPreventRule = PollHelper
- .getNotificationPreventRule(oldPoll);
- notificationCheckBox = !"".equals(notificationPreventRule.getScope());
- reminderPreventRule = PollHelper.getReminderPreventRule(oldPoll);
- reminderCheckBox = !"".equals(reminderPreventRule.getScope());
-
- // Initialisation des choix
- choices = PollHelper.getTextChoices(oldPoll);
- dateTypeChoices = PollHelper.getDateChoices(oldPoll);
- imgTypeChoices = PollHelper.getImageChoices(oldPoll);
-
- // Initialisation des listes de votants
- votingLists = PollHelper.getVotingLists(oldPoll);
- }
-
- /**
- * Initialisation de la liste de favoris.
- */
- private void initPersonLists() {
- if (userExists) {
- List<PersonListDTO> _personLists = serviceList
- .findPersonListByUser(user.getId());
- personLists = new GenericSelectModel<PersonListDTO>(_personLists,
- PersonListDTO.class, "name", "id", _propertyAccess);
- }
- }
-}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollForm.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -243,7 +243,7 @@
choices.add(ChoiceField.getChoiceText());
}
} else {
- for (ChoiceDTO current : getPoll().getChoiceDTOs()) {
+ for (ChoiceDTO current : getPoll().getChoices()) {
choices.add((ChoiceField)current);
}
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollModification.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollModification.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollModification.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -262,7 +262,7 @@
poll.setPublicResults(true);
}
- for (ChoiceDTO choice : poll.getChoiceDTOs()) {
+ for (ChoiceDTO choice : poll.getChoices()) {
choice.setValidate(true);
}
servicePoll.updatePoll(poll);
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -349,7 +349,7 @@
String choiceId = "";
// Récupération du choix correspondant au résultat
- for (ChoiceDTO choice : poll.getChoiceDTOs()) {
+ for (ChoiceDTO choice : poll.getChoices()) {
if (resultName.equals(choice.getName())) {
choiceId = choice.getId();
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -46,9 +46,11 @@
import org.apache.tapestry5.corelib.components.Zone;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.ioc.util.AbstractMessages;
import org.apache.tapestry5.upload.services.UploadedFile;
import org.chenillekit.tapestry.core.components.DateTimeField;
import org.chorem.pollen.business.PollenBusinessException;
+import org.chorem.pollen.business.PollenBusinessException.PollenExceptionType;
import org.chorem.pollen.business.PollenProperty;
import org.chorem.pollen.business.business.PreventRuleManager;
import org.chorem.pollen.business.dto.ChoiceDTO;
@@ -70,12 +72,14 @@
import org.chorem.pollen.common.PollType;
import org.chorem.pollen.common.VoteCountingType;
import org.chorem.pollen.ui.base.ContextLink;
+import org.chorem.pollen.ui.components.Border;
import org.chorem.pollen.ui.components.FeedBack;
import org.chorem.pollen.ui.components.ImageContextLink;
import org.chorem.pollen.ui.components.Pager;
+import org.chorem.pollen.ui.data.AddressBar;
import org.chorem.pollen.ui.data.EvenOdd;
-import org.chorem.pollen.ui.data.AddressBarItem;
import org.chorem.pollen.ui.data.PollAction;
+import org.chorem.pollen.ui.data.PollUri;
import org.chorem.pollen.ui.data.uio.DateChoiceUIO;
import org.chorem.pollen.ui.data.uio.ImageChoiceUIO;
import org.chorem.pollen.ui.utils.FeedUtil;
@@ -101,10 +105,6 @@
@Property
private String title;
- @SuppressWarnings("unused")
- @Property
- private AddressBarItem[] address;
-
/** Paramètres de la page */
private String param;
@@ -138,11 +138,6 @@
@Component(parameters = { "timePicker=true", "timePickerAdjacent=true" })
private DateTimeField dateDTF;
- /** Format des dates */
- @Persist
- @Property
- private DateFormat dateFormat;
-
/** Locale courante */
@Inject
private Locale currentLocale;
@@ -154,13 +149,6 @@
private Messages messages;
/**
- * Sondage pour lequel l'utilisateur vote
- */
- @Property
- @Persist
- private PollDTO poll;
-
- /**
* Vote courant de l'utilisateur
*/
@Property
@@ -191,9 +179,6 @@
@InjectComponent
private Zone pollZone;
- @InjectComponent
- private Zone commentZone;
-
/**
* Objet servant à changer la couleur à chaque ligne de la liste des
* sondages
@@ -237,17 +222,6 @@
@Persist
private ImageChoiceUIO newImageChoice;
- /** Commentaire courant pour l'affichage des commentaires */
- @SuppressWarnings("unused")
- @Property
- @Persist
- private CommentDTO comment;
-
- /** Nouveau commentaire posté */
- @Property
- @Persist
- private CommentDTO newComment;
-
/** Injection des services */
@Inject
private ServicePoll servicePoll;
@@ -292,36 +266,36 @@
@InjectComponent
private FeedBack voteFeedback;
- public String getVoteSizeMessage() {
+ public String getVoteSizeMessage() throws PollenBusinessException {
if (log.isDebugEnabled()) {
log.debug("poll voteDTOs list size : " + getVotes().size());
- log.debug("poll nbVotes : " + poll.getNbVotes());
+ log.debug("poll nbVotes : " + getPoll().getNbVotes());
}
- return messages.format("vote-size", poll.getNbVotes());
+ return messages.format("vote-size", getPoll().getNbVotes());
}
/** Méthode appelée après la soumission du vote. */
@Log
- Object onSuccessFromVoteForm() {
+ Object onSuccessFromVoteForm() throws PollenBusinessException {
if (initPollAccount()) {
List<ChoiceDTO> choiceDTOs = new ArrayList<ChoiceDTO>();
- if (poll.getVoteCounting() == VoteCountingType.NORMAL) {
+ if (getPoll().getVoteCounting() == VoteCountingType.NORMAL) {
int nbChoices = 0;
- for (ChoiceDTO choice : poll.getChoiceDTOs()) {
+ for (ChoiceDTO choice : getPoll().getChoices()) {
if (choice.getValue() == 1) {
nbChoices++;
}
choiceDTOs.add(choice);
}
- if (nbChoices > poll.getMaxChoiceNb()) {
+ if (nbChoices > getPoll().getMaxChoiceNb()) {
voteForm.recordError(messages.format(("tooManyChoices"),
- poll.getMaxChoiceNb()));
+ getPoll().getMaxChoiceNb()));
return pollZone.getBody();
}
- } else if (poll.getVoteCounting() == VoteCountingType.PERCENTAGE) {
+ } else if (getPoll().getVoteCounting() == VoteCountingType.PERCENTAGE) {
int total = 0;
- for (ChoiceDTO choice : poll.getChoiceDTOs()) {
+ for (ChoiceDTO choice : getPoll().getChoices()) {
total = total + choice.getValue();
choiceDTOs.add(choice);
}
@@ -330,21 +304,21 @@
return pollZone.getBody();
}
- } else if (poll.getVoteCounting() == VoteCountingType.CONDORCET) {
- for (ChoiceDTO choice : poll.getChoiceDTOs()) {
+ } else if (getPoll().getVoteCounting() == VoteCountingType.CONDORCET) {
+ for (ChoiceDTO choice : getPoll().getChoices()) {
if (choice.getValue() == 0) {
choice.setValue(100);
}
choiceDTOs.add(choice);
}
- } else if (poll.getVoteCounting() == VoteCountingType.NUMBER) {
+ } else if (getPoll().getVoteCounting() == VoteCountingType.NUMBER) {
String votingId = pollAccount.getVotingId();
if (anonymousVote) {
votingId = "anonymous" + UUID.randomUUID().toString().replaceAll("-", "");
}
- for (ChoiceDTO choice : poll.getChoiceDTOs()) {
+ for (ChoiceDTO choice : getPoll().getChoices()) {
if (!choice.isHidden()) {
choiceDTOs.add(choice);
@@ -365,7 +339,7 @@
}
}
- VoteDTO vote = new VoteDTO(null, poll.getId(), null);
+ VoteDTO vote = new VoteDTO(null, getPoll().getId(), null);
vote.setChoiceDTOs(choiceDTOs);
vote.setWeight(pollAccount.getWeight());
vote.setAnonymous(anonymousVote);
@@ -387,7 +361,8 @@
}
// Mise à jour du sondage et des résultats
- poll = servicePoll.findPollByPollId(poll.getPollId());
+ //poll = servicePoll.findPollByPollId(getPoll().getPollId());
+ poll = null;
countPoll();
addFeedEntry(PollAction.ADDVOTE, pollAccount.getVotingId(),
@@ -403,7 +378,7 @@
return pollZone.getBody();
}
- private void deleteVote(String voteId) {
+ private void deleteVote(String voteId) throws PollenBusinessException {
for (VoteDTO vote : getVotes()) {
if (vote.getId().equals(voteId)) {
@@ -423,11 +398,12 @@
}
/** Méthode appelée lors de la suppression d'un vote. */
- Object onActionFromDeleteVote(String voteId) {
+ Object onActionFromDeleteVote(String voteId) throws PollenBusinessException {
deleteVote(voteId);
// Mise à jour du sondage et des résultats
- poll = servicePoll.findPollByPollId(poll.getPollId());
+// poll = servicePoll.findPollByPollId(poll.getPollId());
+ poll = null;
countPoll();
return pollZone.getBody();
@@ -440,7 +416,7 @@
}
/** Initialisation du pollAccount et contrôle du nom. */
- private boolean initPollAccount() {
+ private boolean initPollAccount() throws PollenBusinessException {
//// Contrôle et définition du votingId
alreadyVoted = false;
@@ -474,14 +450,14 @@
// The calcul of alreadyVoted will be needed for no double votingId
// Carefull, not correct for an anonymous vote
- alreadyVoted = serviceVote.hasAlreadyVoted(votingId, poll);
+ alreadyVoted = serviceVote.hasAlreadyVoted(votingId, getPoll());
// Check for restricted poll
if (!alreadyVoted && !isFreePoll()) {
- if (getAccountUId() != null) {
+ if (uri.getAccountUId() != null) {
// The accountUId must be valid for the poll
PollAccountDTO restrictedAccount =
- servicePoll.getRestrictedAccount(getAccountUId(), poll);
+ servicePoll.getRestrictedAccount(uri.getAccountUId(), getPoll());
if (restrictedAccount != null) {
// PollAccount is replaced by the good account from db
@@ -504,7 +480,7 @@
}
// Génération d'un identifiant de vote (si le sondage est libre et anonyme)
- if (poll.isAnonymous()) {
+ if (getPoll().isAnonymous()) {
anonymousVote = true;
if (isFreePoll()) {
pollAccount.setVotingId("anonymous"
@@ -540,19 +516,12 @@
* @param votingId le votant a rechercher
* @return vrai si la modification du vote est autorisée
*/
- public boolean isModifAllowed(String votingId) {
+ public boolean isModifAllowed(String votingId) throws PollenBusinessException {
boolean modifAllowed = false;
int i = 0;
// parcours des votes pour trouver celui correspondant au votingId
// et contrôle du droit de modification
-
- if (log.isDebugEnabled()) {
- log.debug("Nb votes : " + getVotes().size());
- log.debug("Nb votes in poll : " + poll.getNbVotes());
- }
-
- // FIXME !!!!!! SEEMS TO BE INDEFINITE
while (i < getVotes().size() && !modifAllowed) {
// account : compte associé au vote courant
@@ -588,9 +557,9 @@
/** Ajout d'une entrée dans le flux de syndication */
private void addFeedEntry(PollAction pollAction, String titleStr,
- String contentStr) {
- String voteURL = siteURL + "poll/VoteFor/" + poll.getPollId();
- File feedFile = getFeedContext().getFile(poll.getPollId());
+ String contentStr) throws PollenBusinessException {
+ String voteURL = siteURL + "poll/VoteFor/" + getPoll().getPollId();
+ File feedFile = getFeedContext().getFile(getPoll().getPollId());
String title = null;
String content = null;
@@ -614,29 +583,29 @@
if (!feedFile.exists()) {
FeedUtil.createFeed(feedFile, "atom_1.0", messages.format(
- "pollFeed_title", poll.getTitle()), siteURL, messages
- .format("pollFeed_desc", poll.getDescription()));
+ "pollFeed_title", getPoll().getTitle()), siteURL, messages
+ .format("pollFeed_desc", getPoll().getDescription()));
}
FeedUtil.feedFeed(feedFile, title, voteURL, content);
}
/** Envoi du mail de notification */
- private void sendMailNotification() {
- String voteURL = siteURL + "poll/VoteFor/" + poll.getPollId();
- String modifURL = siteURL + "poll/Modification/" + poll.getPollId()
- + ":" + MD5.encode(poll.getCreatorId());
+ private void sendMailNotification() throws PollenBusinessException {
+ String voteURL = siteURL + "poll/VoteFor/" + getPoll().getPollId();
+ String modifURL = siteURL + "poll/Modification/" + getPoll().getPollId()
+ + ":" + MD5.encode(getPoll().getCreatorId());
Map<String, String> data = new HashMap<String, String>();
data.put("host", PollenProperty.EMAIL_HOST.getValue());
data.put("port", PollenProperty.EMAIL_PORT.getValue());
data.put("from", PollenProperty.EMAIL_FROM.getValue());
// Mail au créateur
- data.put("to", poll.getCreatorEmail());
- data.put("title", messages.format("voteEmail_subject", poll.getTitle()));
- data.put("msg", messages.format("voteEmail_msg", poll.getTitle(), poll
- .getVoteDTOs().size(), voteURL, modifURL));
+ data.put("to", getPoll().getCreatorEmail());
+ data.put("title", messages.format("voteEmail_subject", getPoll().getTitle()));
+ data.put("msg", messages.format("voteEmail_msg", getPoll().getTitle(), getPoll()
+ .getNbVotes(), voteURL, modifURL));
- for (PreventRuleDTO rule : poll.getPreventRuleDTOs()) {
+ for (PreventRuleDTO rule : getPoll().getPreventRuleDTOs()) {
PreventRuleManager manager = new PreventRuleManager(rule);
manager.execute("vote", getVotes().size(), data);
}
@@ -671,9 +640,9 @@
* @param choice le choix concerné
* @return true si le choix est dans le vote
*/
- public Boolean isChoiceInVote(ChoiceDTO choice) {
+ public Boolean isChoiceInVote(ChoiceDTO choice) throws PollenBusinessException {
if (choice != null) {
- switch (poll.getVoteCounting()) {
+ switch (getPoll().getVoteCounting()) {
case NORMAL:
return choice.getValue() > 0;
case PERCENTAGE:
@@ -732,8 +701,8 @@
* @return vrai si le fichier existe
*/
@Log
- public boolean isFeedFileExisting() {
- File feedFile = getFeedContext().getFile(poll.getPollId());
+ public boolean isFeedFileExisting() throws PollenBusinessException {
+ File feedFile = getFeedContext().getFile(getPoll().getPollId());
if (log.isDebugEnabled()) {
log.debug("feed context path : " + getFeedContext().getContextPath());
log.debug("feed absolute path : " + feedFile.getAbsolutePath());
@@ -760,7 +729,7 @@
*
* @return les résultats
*/
- public String getResultsAsString() {
+ public String getResultsAsString() throws PollenBusinessException {
StringBuffer res = new StringBuffer("");
Iterator<ResultDTO> it = results.iterator();
while (it.hasNext()) {
@@ -785,8 +754,8 @@
*
* @return true si le vote est anonyme
*/
- public boolean isVoteAnonymous() {
- return poll.isAnonymous() || anonymousVote;
+ public boolean isVoteAnonymous() throws PollenBusinessException {
+ return getPoll().isAnonymous() || anonymousVote;
}
/**
@@ -795,42 +764,38 @@
*
* @return true si le vote est anonyme
*/
- public boolean isCurrentVoteAnonymous() {
- return poll.isAnonymous() || vote.isAnonymous();
+ public boolean isCurrentVoteAnonymous() throws PollenBusinessException {
+ return getPoll().isAnonymous() || vote.isAnonymous();
}
/** Retourne vrai si la checkbox anonymousVote doit être affichée. */
- public boolean isAnonymousVoteDisplayed() {
- return poll.isAnonymousVoteAllowed() && !poll.isAnonymous();
+ public boolean isAnonymousVoteDisplayed() throws PollenBusinessException {
+ return getPoll().isAnonymousVoteAllowed() && !getPoll().isAnonymous();
}
/** Retourne l'identifiant du votant du vote courant */
- // FIXME !!!!!! DON'T DO A QUERY FOR THAT
public String getCurrentVotingId() {
-// String id = vote.getPollAccountId();
-// String votingId = servicePollAccount.findPollAccountById(id)
-// .getVotingId();
return vote.getName();
}
/** Validation du champs de saisie du choix (texte). */
- void onValidateFromTextName(String value) throws ValidationException {
+ void onValidateFromTextName(String value) throws ValidationException, PollenBusinessException {
validateNewChoice(value);
}
/** Validation du champs de saisie du choix (date). */
- void onValidateFromDateDTF(Date value) throws ValidationException {
+ void onValidateFromDateDTF(Date value) throws ValidationException, PollenBusinessException {
validateNewChoice(String.valueOf(value.getTime()));
}
/** Validation du champs de saisie du choix (image). */
- void onValidateFromImgFile(UploadedFile value) throws ValidationException {
+ void onValidateFromImgFile(UploadedFile value) throws ValidationException, PollenBusinessException {
validateNewChoice(value.getFileName().replace(' ', '_'));
}
/** Validation du champs de saisie du choix. */
- private void validateNewChoice(String value) throws ValidationException {
- for (ChoiceDTO choice : poll.getChoiceDTOs()) {
+ private void validateNewChoice(String value) throws ValidationException, PollenBusinessException {
+ for (ChoiceDTO choice : getPoll().getChoices()) {
if (value.equals(choice.getName())) {
throw new ValidationException(messages.format("choiceExists",
value));
@@ -839,24 +804,24 @@
}
/** Méthode appelée lors de l'ajout d'un choix. */
- Object onSuccessFromChoiceForm() {
+ Object onSuccessFromChoiceForm() throws PollenBusinessException {
String choiceName = null;
String choiceDesc = null;
if (isTextType()) {
if (newChoice.getName() != null) {
newChoice.setValidate(true);
- newChoice.setPollId(poll.getId());
- poll.getChoiceDTOs().add(newChoice);
+ newChoice.setPollId(getPoll().getId());
+ getPoll().getChoices().add(newChoice);
choiceName = newChoice.getName();
choiceDesc = newChoice.getDescription();
}
} else if (isDateType()) {
if (newDateChoice.getDate() != null) {
newDateChoice.setValidate(true);
- newDateChoice.setPollId(poll.getId());
+ newDateChoice.setPollId(getPoll().getId());
newDateChoice.setName(String.valueOf(newDateChoice.getDate()
.getTime()));
- poll.getChoiceDTOs().add(newDateChoice);
+ getPoll().getChoices().add(newDateChoice);
Date date = new Date(Long.parseLong(newDateChoice.getName()));
choiceName = dateFormat.format(date);
choiceDesc = newDateChoice.getDescription();
@@ -864,10 +829,10 @@
} else if (isImageType()) {
if (newImageChoice.getImg() != null) {
newImageChoice.setValidate(true);
- newImageChoice.setPollId(poll.getId());
+ newImageChoice.setPollId(getPoll().getId());
newImageChoice.setName(newImageChoice.getImg().getFileName()
.replace(' ', '_'));
- poll.getChoiceDTOs().add(newImageChoice);
+ getPoll().getChoices().add(newImageChoice);
//File imgFile = getImgContext().getImageDir(); // dir set in getImgContext()
File imgFile = getImgContext().getImageDir(); // dir set in getImgContext()
ImageUtil.saveImage(newImageChoice, imgFile);
@@ -876,82 +841,63 @@
}
}
- servicePoll.updatePoll(poll);
- poll = servicePoll.findPollByPollId(poll.getPollId());
+ servicePoll.updatePoll(getPoll());
+ poll = null;
+ //poll = servicePoll.findPollByPollId(getPoll().getPollId());
addFeedEntry(PollAction.ADDCHOICE, choiceName, choiceDesc);
- newChoice = new ChoiceDTO();
- newDateChoice = new DateChoiceUIO();
- newImageChoice = new ImageChoiceUIO();
+// newChoice = new ChoiceDTO();
+// newDateChoice = new DateChoiceUIO();
+// newImageChoice = new ImageChoiceUIO();
return this;
}
/** Méthode appelée lors de la suppression d'un choix. */
- Object onActionFromDeleteChoice(String choiceId) {
- Iterator<ChoiceDTO> itChoice = poll.getChoiceDTOs().iterator();
+ Object onActionFromDeleteChoice(String choiceId) throws PollenBusinessException {
+ Iterator<ChoiceDTO> itChoice = getPoll().getChoices().iterator();
while (itChoice.hasNext()) {
ChoiceDTO choice = itChoice.next();
if (choiceId.equals(choice.getId())) {
itChoice.remove();
}
}
- servicePoll.updatePoll(poll);
- poll = servicePoll.findPollByPollId(poll.getPollId());
+ servicePoll.updatePoll(getPoll());
+ poll = null;
+// poll = servicePoll.findPollByPollId(poll.getPollId());
return pollZone.getBody();
}
- /** Méthode appelée lors de l'ajout d'un commentaire. */
- Object onSuccessFromCommentForm() {
- //newComment.setPollId(poll.getId());
- newComment.setPostDate(new Date());
- servicePoll.createComment(poll, newComment);
- //serviceComment.createComment(newComment);
- //poll = servicePoll.findPollByPollId(poll.getPollId());
- addFeedEntry(PollAction.ADDCOMMENT, newComment.getAuthor(),
- newComment.getText());
- newComment = new CommentDTO();
- return commentZone.getBody();
- }
+// public boolean isPollNull() {
+// return poll == null;
+// }
- /** Méthode appelée lors de la suppression d'un commentaire. */
- Object onActionFromDeleteComment(String commentId) {
- //serviceComment.deleteComment(commentId);
- //poll = servicePoll.findPollByPollId(poll.getPollId());
- servicePoll.deleteComment(poll, commentId);
- return commentZone.getBody();
- }
-
- public boolean isPollNull() {
- return poll == null;
- }
-
- public boolean isPollChoiceStarted() {
+ public boolean isPollChoiceStarted() throws PollenBusinessException {
Date now = new Date();
- boolean started = poll.getBeginChoiceDate() == null || poll.getBeginChoiceDate().before(now);
- boolean ended = poll.getEndChoiceDate() != null && poll.getEndChoiceDate().before(now);
+ boolean started = getPoll().getBeginChoiceDate() == null || getPoll().getBeginChoiceDate().before(now);
+ boolean ended = getPoll().getEndChoiceDate() != null && getPoll().getEndChoiceDate().before(now);
return started && !ended;
}
- public boolean isPollStarted() {
+ public boolean isPollStarted() throws PollenBusinessException {
Date now = new Date();
- return poll.getBeginDate() == null || poll.getBeginDate().before(now);
+ return getPoll().getBeginDate() == null || getPoll().getBeginDate().before(now);
}
- public boolean isPollFinished() {
+ public boolean isPollFinished() throws PollenBusinessException {
Date now = new Date();
- return poll.getEndDate() != null && poll.getEndDate().before(now);
+ return getPoll().getEndDate() != null && getPoll().getEndDate().before(now);
}
- public boolean isPollChoiceOrVoteStarted() {
+ public boolean isPollChoiceOrVoteStarted() throws PollenBusinessException {
return isPollChoiceStarted() || isPollStarted();
}
- public boolean isPollChoiceRunning() {
- return poll.isChoiceAddAllowed() && isPollChoiceStarted();
+ public boolean isPollChoiceRunning() throws PollenBusinessException {
+ return getPoll().isChoiceAddAllowed() && isPollChoiceStarted();
//&& !isPollStarted();
}
- public boolean isPollRunning() {
- return isPollStarted() && !isPollFinished() && !poll.isClosed();
+ public boolean isPollRunning() throws PollenBusinessException {
+ return isPollStarted() && !isPollFinished() && !getPoll().isClosed();
}
public boolean isDescNull() {
@@ -960,74 +906,61 @@
}
/** Retourne vrai si le champs pollAccount doit apparaître. */
- public boolean isAccountFieldDisplayed() {
- return !poll.isAnonymous() || isRestrictedPoll() || isGroupPoll();
+ public boolean isAccountFieldDisplayed() throws PollenBusinessException {
+ return !getPoll().isAnonymous() || isRestrictedPoll() || isGroupPoll();
}
- public boolean isFreePoll() {
- return poll.getPollType() == PollType.FREE;
+ public boolean isFreePoll() throws PollenBusinessException {
+ return getPoll().getPollType() == PollType.FREE;
}
- public boolean isRestrictedPoll() {
- return poll.getPollType() == PollType.RESTRICTED;
+ public boolean isRestrictedPoll() throws PollenBusinessException {
+ return getPoll().getPollType() == PollType.RESTRICTED;
}
- public boolean isGroupPoll() {
- return poll.getPollType() == PollType.GROUP;
+ public boolean isGroupPoll() throws PollenBusinessException {
+ return getPoll().getPollType() == PollType.GROUP;
}
- public boolean isTextType() {
- return poll.getChoiceType() == ChoiceType.TEXT;
+ public boolean isTextType() throws PollenBusinessException {
+ return getPoll().getChoiceType() == ChoiceType.TEXT;
}
- public boolean isDateType() {
- return poll.getChoiceType() == ChoiceType.DATE;
+ public boolean isDateType() throws PollenBusinessException {
+ return getPoll().getChoiceType() == ChoiceType.DATE;
}
- public boolean isImageType() {
- return poll.getChoiceType() == ChoiceType.IMAGE;
+ public boolean isImageType() throws PollenBusinessException {
+ return getPoll().getChoiceType() == ChoiceType.IMAGE;
}
- public boolean isNormalVoteCounting() {
- return poll.getVoteCounting() == VoteCountingType.NORMAL;
+ public boolean isNormalVoteCounting() throws PollenBusinessException {
+ return getPoll().getVoteCounting() == VoteCountingType.NORMAL;
}
- public boolean isPercentageVoteCounting() {
- return poll.getVoteCounting() == VoteCountingType.PERCENTAGE;
+ public boolean isPercentageVoteCounting() throws PollenBusinessException {
+ return getPoll().getVoteCounting() == VoteCountingType.PERCENTAGE;
}
- public boolean isCondorcetVoteCounting() {
- return poll.getVoteCounting() == VoteCountingType.CONDORCET;
+ public boolean isCondorcetVoteCounting() throws PollenBusinessException {
+ return getPoll().getVoteCounting() == VoteCountingType.CONDORCET;
}
- public boolean isNumberVoteCounting() {
- return poll.getVoteCounting() == VoteCountingType.NUMBER;
+ public boolean isNumberVoteCounting() throws PollenBusinessException {
+ return getPoll().getVoteCounting() == VoteCountingType.NUMBER;
}
/** retourne vrai si l'utilisateur est le créateur du sondage */
- public boolean isCreatorUser() {
- PollAccountDTO creator = servicePollAccount.findPollAccountById(poll
- .getCreatorId());
- if (userExists && user.getId().equals(creator.getUserId())) {
+ public boolean isCreatorUser() throws PollenBusinessException {
+ if (userExists && user.getId().equals(getPoll().getUserId())) {
return true;
}
return false;
}
- /**
- * Récupération du créateur du sondage.
- *
- * @return le nom du créateur du sondage.
- */
- public String getCreatorName() {
- PollAccountDTO pollAccount = servicePollAccount
- .findPollAccountById(poll.getCreatorId());
- return pollAccount.getVotingId();
- }
-
/** Retourne le message d'aide correspondant au type de sondage. */
- public String getHelpMessage() {
- switch (poll.getVoteCounting()) {
+ public String getHelpMessage() throws PollenBusinessException {
+ switch (getPoll().getVoteCounting()) {
case NORMAL:
return messages.get("normalVote-help");
case PERCENTAGE:
@@ -1041,89 +974,152 @@
}
}
- /** Retourne la date correspondant au choix courant */
+ /**
+ * Retourne la date correspondant au choix courant
+ *
+ * @return date
+ */
public Date getChoiceNameAsDate() {
return new Date(Long.valueOf(choiceOfPoll.getName()));
}
- /** Action réalisée lorsqu'on clique sur l'image */
- /*Object onDisplayImage(String choiceId) {
- imageDisplay.setPoll(poll);
- imageDisplay.setChoiceId(choiceId);
- imageDisplay.setPageStyle("Vote");
- return imageDisplay;
- }*/
-
- /** Affichage de "" plutôt que 0 pour le Condorcet */
- /*String onToClientFromCondorcetInput() {
- if (choiceOfVote.getValue() == 0) {
- return "";
- }
- return null;
- }*/
-
- /** Récupération d'un entier plutôt que "" pour le Condorcet */
- /*Object onParseClientFromCondorcetInput(String input) {
- if ("".equals(input)) return 0; //ne fonctionne pas
- return null;
- }*/
-
/** Dépouillement du sondage. Mise à jour des résultats. */
- private void countPoll() {
+ private void countPoll() throws PollenBusinessException {
ResultListDTO resultListDTO = null;
-
- if (isGroupPoll()) {
- resultListDTO = serviceResults.getGroupResults(poll.getPollId());
- } else {
- resultListDTO = serviceResults.getNormalResults(poll.getPollId());
- }
+ if (getPoll().getContinuousResults()) {
- results = resultListDTO.getResultDTOs();
+ if (isGroupPoll()) {
+ resultListDTO = serviceResults.getGroupResults(getPoll().getPollId());
+ } else {
+ resultListDTO = serviceResults.getNormalResults(getPoll().getPollId());
+ }
- if (logger.isDebugEnabled()) {
- for (ResultDTO res : results) {
- logger.debug(res.getName() + ": " + res.getValue()
- + ", (voteCounting=" + res.getVoteCounting()
- + ", byGroup=" + res.isByGroup() + ")");
+ results = resultListDTO.getResultDTOs();
+
+ if (logger.isDebugEnabled()) {
+ for (ResultDTO res : results) {
+ logger.debug(res.getName() + ": " + res.getValue()
+ + ", (voteCounting=" + res.getVoteCounting()
+ + ", byGroup=" + res.isByGroup() + ")");
+ }
}
}
}
+ @Property
+ private PollUri uri;
+
/**
+ * Sondage pour lequel l'utilisateur vote
+ */
+ @Persist
+ private PollDTO poll;
+
+ @Property
+ private boolean pollNull;
+
+ @InjectComponent
+ private Border border;
+
+ /** Format des dates */
+ private DateFormat dateFormat;
+
+ /**
* Méthode appelée au moment de l'activation de la page
*
* @param id l'identifiant du sondage et du votant
*/
- void onActivate(EventContext ec) {
- param = ec.get(String.class, 0);
+ @Log
+ void onActivate(EventContext ec) throws PollenBusinessException {
+ uri = ec.get(PollUri.class, 0);
if (ec.getCount() > 1) {
page = ec.get(Integer.class, 1);
}
+ }
- // Initialisation du sondage
- if (param != null && !"".equals(param)) {
- String pollId = param.split(":", 2)[0];
- poll = servicePoll.findPollByPollId(pollId);
+ /**
+ * Méthode appelée au moment de la désactivation de la page
+ *
+ * @return l'identifiant du sondage et du votant
+ */
+ Object[] onPassivate() {
+ return new Object[]{uri, page};
+ }
+ /**
+ * Initialisation de l'affichage
+ */
+ @Log
+ void setupRender() {
+ try {
+ poll = null;
+ getPoll();
+
+ if (getPoll().isClosed()) {
+ feedback.addInfo(messages.get("pollClosed"));
+ } else if (!isPollStarted()) {
+ feedback.addInfo(messages.get("pollNotStarted"));
+ } else if (isPollFinished()) {
+ feedback.addInfo(messages.get("pollFinished"));
+ }
+ if (isPollChoiceRunning()) {
+ feedback.addInfo(messages.get("pollChoiceRunning"));
+ }
+
+ countPoll();
+ } catch (PollenBusinessException eee) {
+ feedback.addError(messages.get(eee.getMessage()));
+ pollNull = true;
+ }
+ }
+
+ /**
+ * Address bar of the page. Display in Border layout component.
+ *
+ * @return the address bar of the page.
+ */
+ public AddressBar getAddress() {
+// address = new AddressBarItem[] { new AddressBarItem("Pollen", "Index"),
+// new AddressBarItem(title, null) };
+ return new AddressBar().appendCurrent(title);
+ }
+
+ /**
+ * DateFormat used in the page.
+ *
+ * @return the DateFormat needed.
+ */
+ public DateFormat getDateFormat() {
+ if (dateFormat == null) {
+ dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT,
+ DateFormat.SHORT, currentLocale);
+ }
+ return dateFormat;
+ }
+
+ public PollDTO getPoll() throws PollenBusinessException {
+ if (poll == null) {
+ poll = servicePoll.findPollByPollId(uri.getPollUId());
+
if (poll != null) {
// Identification du votant
- if (getAccountUId() != null) {
+ if (uri.getAccountUId() != null) {
pollAccount = servicePollAccount
- .findPollAccountByAccountId(getAccountUId());
+ .findPollAccountByAccountId(uri.getAccountUId());
pollAccountId = pollAccount.getId();
}
-
+
if (pollAccount == null) {
pollAccount = new PollAccountDTO();
if (userExists) {
if (user.getFirstName() != null && user.getLastName() != null) {
pollAccount.setVotingId(
user.getFirstName() + " " + user.getLastName());
-
+
} else if (user.getFirstName() != null) {
pollAccount.setVotingId(user.getFirstName());
-
+
} else if (user.getLastName() != null) {
pollAccount.setVotingId(user.getLastName());
}
@@ -1134,59 +1130,14 @@
newChoice = new ChoiceDTO();
newDateChoice = new DateChoiceUIO();
newImageChoice = new ImageChoiceUIO();
- newComment = new CommentDTO();
-
- //newComment.setPollId(poll.getId());
+ } else {
+ throw new PollenBusinessException(
+ PollenExceptionType.POLL_NOT_EXIST);
}
}
-
- // Affichage des erreurs
- if (poll == null) {
- feedback.addError(messages.get("pollNotFound"));
- } else {
- if (poll.isClosed()) {
- feedback.addInfo(messages.get("pollClosed"));
- } else if (!isPollStarted()) {
- feedback.addInfo(messages.get("pollNotStarted"));
- } else if (isPollFinished()) {
- feedback.addInfo(messages.get("pollFinished"));
- }
- if (isPollChoiceRunning()) {
- feedback.addInfo(messages.get("pollChoiceRunning"));
- }
- }
+ return poll;
}
- private String accountUId;
-
- public String getAccountUId() {
- if (accountUId == null && param.split(":", 2).length == 2) {
- accountUId = param.split(":", 2)[1];
- }
- return accountUId;
- }
-
- /**
- * Méthode appelée au moment de la désactivation de la page
- *
- * @return l'identifiant du sondage et du votant
- */
- Object[] onPassivate() {
- return new Object[]{param, page};
- }
-
- /**
- * Initialisation de l'affichage
- */
- void setupRender() {
- address = new AddressBarItem[] { new AddressBarItem("Pollen", "Index"),
- new AddressBarItem(title, null) };
- dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT,
- DateFormat.SHORT, currentLocale);
-
- countPoll();
- }
-
/************** PAGER AND VOTES MANAGMENT *********************************/
@InjectComponent
@@ -1196,6 +1147,9 @@
private Integer page;
+ @Persist
+ private Integer nbVotesPerPage;
+
public int getPage() {
if (page == null) {
page = pager.getFirstPage();
@@ -1214,11 +1168,22 @@
* @return the number of votes to display per page
*/
public int getNbVotesPerPage() {
+ if (nbVotesPerPage == null) {
+ nbVotesPerPage = getPagerRange();
+ }
+ return nbVotesPerPage;
+ }
+
+ public void setNbVotesPerPage(int nbVotesPerPage) {
+ this.nbVotesPerPage = nbVotesPerPage;
+ }
+
+ public int getPagerRange() {
return Integer.parseInt(PollenProperty.NB_VOTES_PER_PAGE.getValue());
}
- public String getNoPagerText() {
- return messages.format("vote-noPagerText", poll.getNbVotes());
+ public String getNoPagerText() throws PollenBusinessException {
+ return messages.format("vote-noPagerText", getPoll().getNbVotes());
}
/**
@@ -1227,15 +1192,80 @@
* loaded depends on current page using pager component.
*
* @return the list of votes to display
+ * @throws PollenBusinessException
*/
- public List<VoteDTO> getVotes() {
+ public List<VoteDTO> getVotes() throws PollenBusinessException {
if (votes == null) {
- if (log.isInfoEnabled()) {
- log.info("BUSINESS REQUEST [getVotesByPoll]");
- }
- votes = serviceVote.getVotesByPoll(poll,
+ votes = serviceVote.getVotesByPoll(getPoll(),
pager.getStartIndex(), pager.getEndIndex());
}
return votes;
}
+
+ /************** COMMENTS **************************************************/
+
+ @InjectComponent
+ private Zone commentZone;
+
+ private List<CommentDTO> comments;
+
+ /** Commentaire courant pour l'affichage des commentaires */
+ @SuppressWarnings("unused")
+ @Property
+ @Persist
+ private CommentDTO comment;
+
+ /** Nouveau commentaire posté */
+ private CommentDTO newComment;
+
+ public List<CommentDTO> getComments() throws PollenBusinessException {
+ if (comments == null) {
+ comments = servicePoll.getComments(poll);
+ }
+ return comments;
+ }
+
+ /**
+ * Accessor for newComment property. Instantiate a new comment if needed.
+ *
+ * @return the current newComment.
+ */
+ public CommentDTO getNewComment() {
+ if (newComment == null) {
+ newComment = new CommentDTO();
+ }
+ return newComment;
+ }
+
+ /**
+ * ACTION EVENT :: delete a comment.
+ *
+ * @param commentId id of the comment to delete
+ * @return the commentZone
+ * @throws PollenBusinessException
+ */
+ Object onActionFromDeleteComment(String commentId) throws PollenBusinessException {
+ servicePoll.deleteComment(getPoll(), commentId);
+ return commentZone.getBody();
+ }
+
+ /**
+ * SUCCESS EVENT :: submit form for adding a new comment.
+ *
+ * @return the commentZone
+ * @throws PollenBusinessException
+ */
+ @Log
+ Object onSuccessFromCommentForm() throws PollenBusinessException {
+ if (log.isDebugEnabled()) {
+ log.debug("newComment author : " + getNewComment().getAuthor());
+ log.debug("newComment text : " + getNewComment().getText());
+ }
+ getNewComment().setPostDate(new Date());
+ servicePoll.createComment(getPoll(), getNewComment());
+ addFeedEntry(PollAction.ADDCOMMENT,
+ getNewComment().getAuthor(),
+ getNewComment().getText());
+ return commentZone.getBody();
+ }
}
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -16,13 +16,18 @@
package org.chorem.pollen.ui.services;
+import java.math.BigDecimal;
+import org.chorem.pollen.business.services.SendMail;
import org.apache.tapestry5.SymbolConstants;
+import org.apache.tapestry5.ioc.Configuration;
import org.apache.tapestry5.ioc.MappedConfiguration;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.OrderedConfiguration;
import org.apache.tapestry5.ioc.ServiceBinder;
import org.apache.tapestry5.ioc.annotations.EagerLoad;
import org.apache.tapestry5.ioc.annotations.InjectService;
+import org.apache.tapestry5.ioc.services.Coercion;
+import org.apache.tapestry5.ioc.services.CoercionTuple;
import org.apache.tapestry5.ioc.services.RegistryShutdownHub;
import org.apache.tapestry5.ioc.services.RegistryShutdownListener;
import org.apache.tapestry5.ioc.services.SymbolProvider;
@@ -36,7 +41,7 @@
import org.chorem.pollen.business.services.ServiceResults;
import org.chorem.pollen.business.services.ServiceUser;
import org.chorem.pollen.business.services.ServiceVote;
-import org.chorem.pollen.ui.utils.SendMail;
+import org.chorem.pollen.ui.data.PollUri;
import org.slf4j.Logger;
/**
@@ -146,6 +151,27 @@
configuration.add("PollenStartup", new PollenManager());
}
+ public static void contributeTypeCoercer(Configuration<CoercionTuple> configuration) {
+ Coercion<String, PollUri> coercion1 = new Coercion<String, PollUri>() {
+
+ @Override
+ public PollUri coerce(String input) {
+ return new PollUri(input);
+ }
+ };
+
+ Coercion<PollUri, String> coercion2 = new Coercion<PollUri, String>() {
+
+ @Override
+ public String coerce(PollUri input) {
+ return input.getUri();
+ }
+ };
+
+ configuration.add(new CoercionTuple<String, PollUri>(String.class, PollUri.class, coercion1));
+ configuration.add(new CoercionTuple<PollUri, String>(PollUri.class, String.class, coercion2));
+ }
+
/**
* This is the BackgroundWorker service definition. It build the service
* giving a Messages object for localization in the service.
@@ -177,12 +203,11 @@
* @param conf
* @return
*/
-// @EagerLoad
-// public SendMail buildSendMail(Configuration conf) {
-// SendMail res = new SendMail(conf);
-// res.start();
-// return res;
-// }
+ @EagerLoad
+ public SendMail buildSendMail() {
+ SendMail res = new SendMail();
+ return res;
+ }
/**
* Make configuration from a Properties file available as symbols.
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -20,7 +20,6 @@
import org.apache.commons.logging.LogFactory;
import org.apache.tapestry5.ioc.services.RegistryShutdownListener;
import org.chorem.pollen.business.PollenContext;
-import org.chorem.pollen.ui.utils.SendMail;
/**
* Service de gestion de l'arrêt du serveur. Ce service exécute une action à la
@@ -33,16 +32,12 @@
private static final Log log = LogFactory.getLog(PollenManager.class);
- protected SendMail sendMail;
-
@Override
public void run() {
if (log.isInfoEnabled()) {
log.info("Start Pollen");
}
PollenContext.start();
- sendMail = new SendMail();
- sendMail.start();
}
@Override
@@ -51,7 +46,6 @@
log.info("Stop Pollen");
}
PollenContext.stop();
- sendMail.stopExec();
}
}
Deleted: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/SendMail.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/SendMail.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/SendMail.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -1,248 +0,0 @@
-/* *##% 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.ui.utils;
-
-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;
-import java.util.Map;
-
-import org.apache.commons.io.FileUtils;
-import org.chorem.pollen.business.utils.MailUtil;
-import org.nuiton.util.FileUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import au.com.bytecode.opencsv.CSVReader;
-import au.com.bytecode.opencsv.CSVWriter;
-import org.apache.commons.io.IOUtils;
-import org.chorem.pollen.business.PollenProperty;
-
-/**
- * Mass mail management class.
- *
- * 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.
- *
- * 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$
- *
- * 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";
-
- /** Mail storage directory. */
- protected File mailStorageDirectory;
-
- protected volatile boolean stop;
-
- public SendMail() {
-
- // get email directory in configuration
- // create it if not exists
- String filename = PollenProperty.EMAIL_DIR.getValue();
- mailStorageDirectory = new File(filename);
- if (!mailStorageDirectory.exists()) {
- if (mailStorageDirectory.mkdirs()) {
- if (log.isDebugEnabled()) {
- log.debug("Email storage directory created in : " + mailStorageDirectory.getAbsolutePath());
- }
- }
- }
- }
-
- public synchronized void stopExec() {
- stop = true;
- }
-
- /*
- * @see java.lang.Runnable#run()
- */
- @Override
- public void run() {
-
- // try to find existing files
- while (!stop) {
- 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.
- *
- * After execution, delete mail and index file.
- * @throws IOException
- */
- 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];
-
- // index contains next index to treat so == is ok
- if (currentIndex >= index) {
- String host = PollenProperty.EMAIL_HOST.getValue();
- int port = Integer.parseInt(
- PollenProperty.EMAIL_PORT.getValue());
- String from = PollenProperty.EMAIL_FROM.getValue();
- MailUtil.sendMail(host, port, 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 woth 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.
- *
- * TODO : improve configuration reading
- *
- * @param id
- * @param mailData
- * @throws IOException
- */
- 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.closeQuietly(fileWriter);
- }
-
- }
-}
Modified: trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/Pager_en.properties
===================================================================
--- trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/Pager_en.properties 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/Pager_en.properties 2010-03-19 15:05:04 UTC (rev 2951)
@@ -1,3 +1,5 @@
-page=Page %d
+page=Page %d/%d
go-to=Go to page %d
-rows-title=Rows %d - %d over %d
\ No newline at end of file
+rows-title=Rows %d - %d over %d
+showPerPage=Show on each page:
+change-nbrows=Change to %d rows per page
\ No newline at end of file
Modified: trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/Pager_fr.properties
===================================================================
--- trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/Pager_fr.properties 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/components/Pager_fr.properties 2010-03-19 15:05:04 UTC (rev 2951)
@@ -1,3 +1,5 @@
-page=Page %d
+page=Page %d/%d
go-to=Aller \u00E0 la page %d
rows-title=Lignes %d - %d sur %d
+showPerPage=Afficher par page :
+change-nbrows=Afficher %d lignes par page
Modified: trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_en.properties
===================================================================
--- trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_en.properties 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_en.properties 2010-03-19 15:05:04 UTC (rev 2951)
@@ -19,8 +19,8 @@
pollAccountName-required-message=You must provide your name.
anonymousVote-label=Anonymous vote
submitVote=Vote
-vote-success=Your vote has been correctly saved.
-vote-noPagerText=%d existing votes.
+vote-success=Your vote has been correctly saved
+vote-noPagerText=%d existing votes
#choices
addChoice=Adding a choice
@@ -49,7 +49,7 @@
submitComment=Add a comment
#messages
-pollNotFound=No such poll exists. Please make sure that you are using the correct link and copy it completely into your browser's address field.
+#pollNotFound=No such poll exists. Please make sure that you are using the correct link and copy it completely into your browser's address field.
anonymousForbidden=Anonymous vote is forbidden for this poll. Enter a name.
restrictedListsForbidden=The poll is restricted and you are not allowed to vote. Check if you have correctly used the link sent to you by email.
alreadyVoted=Someone has already used the name %s to vote.
Modified: trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_fr.properties
===================================================================
--- trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_fr.properties 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/poll/VoteForPoll_fr.properties 2010-03-19 15:05:04 UTC (rev 2951)
@@ -20,7 +20,7 @@
anonymousVote-label=Vote anonyme
submitVote=Voter
vote-success=Votre vote a bien \u00E9t\u00E9 enregistr\u00E9
-vote-noPagerText=%d votes existants.
+vote-noPagerText=%d votes existants
#choices
addChoice=Ajout d'un choix
@@ -49,7 +49,7 @@
submitComment=Ajouter un commentaire
#messages
-pollNotFound=Il n'y a pas de sondage \u00E0 cette adresse. Veuillez verifier que vous utilisez le lien correcte et copiez-le compl\u00E8tement dans le champ d'adresse de votre navigateur.
+#pollNotFound=Il n'y a pas de sondage \u00E0 cette adresse. Veuillez verifier que vous utilisez le lien correcte et copiez-le compl\u00E8tement dans le champ d'adresse de votre navigateur.
anonymousForbidden=Le vote anonyme est interdit pour ce sondage. Saisissez un nom.
restrictedListsForbidden=Le sondage est restreint et vous n'\u00EAtes pas autoris\u00E9 \u00E0 voter. V\u00E9rifiez que vous avez bien utiliser le lien qui vous a \u00E9t\u00E9 envoy\u00E9.
alreadyVoted=Une personne a d\u00E9j\u00E0 vot\u00E9 sous le nom %s.
Added: trunk/pollen-ui/src/main/webapp/img/1leftarrow.png
===================================================================
(Binary files differ)
Property changes on: trunk/pollen-ui/src/main/webapp/img/1leftarrow.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/pollen-ui/src/main/webapp/img/1rightarrow.png
===================================================================
(Binary files differ)
Property changes on: trunk/pollen-ui/src/main/webapp/img/1rightarrow.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/pollen-ui/src/main/webapp/img/2leftarrow.png
===================================================================
(Binary files differ)
Property changes on: trunk/pollen-ui/src/main/webapp/img/2leftarrow.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/pollen-ui/src/main/webapp/img/2rightarrow.png
===================================================================
(Binary files differ)
Property changes on: trunk/pollen-ui/src/main/webapp/img/2rightarrow.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml
===================================================================
--- trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-ui/src/main/webapp/poll/VoteForPoll.tml 2010-03-19 15:05:04 UTC (rev 2951)
@@ -1,5 +1,5 @@
-<t:border t:address="address" t:pageLogo="literal:Vote" t:feedFilename="${poll.pollId}"
+<t:border t:address="address.items" t:pageLogo="literal:Vote" t:feedFilename="prop:uri.pollUId"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter">
<t:feedback t:id="feedback"/>
@@ -8,7 +8,6 @@
<!-- Informations sur le sondage -->
-
<div id="pollTop">
${poll.description}
<fieldset>
@@ -26,7 +25,7 @@
</t:FileLink>
</t:if>
</div>
- <label>${message:creator-label}</label> ${creatorName}
+ <label>${message:creator-label}</label> ${poll.creatorName}
<br/>
<label>${message:beginDate-label}</label>
<t:output value="poll.beginDate" format="dateFormat"/>
@@ -51,7 +50,7 @@
<t:feedback t:id="voteFeedback"/>
<p:else>
<t:pager t:nbRowsPerPage="nbVotesPerPage" t:nbTotalRows="poll.nbVotes"
- t:currentPage="page" t:noPagerText="prop:noPagerText"/>
+ t:currentPage="page" t:noPagerText="prop:noPagerText" t:range="pagerRange"/>
</p:else>
</t:if>
<t:form t:id="voteForm" t:zone="pollZone">
@@ -65,7 +64,7 @@
</p:else>
</t:if>
<t:if test="textType">
- <t:loop t:source="poll.choiceDTOs" t:value="choiceOfPoll" volatile="true">
+ <t:loop t:source="poll.choices" t:value="choiceOfPoll" volatile="true">
<t:if test="!isChoiceHidden()">
<th>
<t:unless test="isDescNull()">
@@ -88,26 +87,26 @@
</t:loop>
</t:if>
<t:if test="dateType">
- <t:loop t:source="poll.choiceDTOs" t:value="choiceOfPoll" volatile="true">
- <t:if test="!isChoiceHidden()">
- <t:unless test="isDescNull()">
- <th class="desc">
- <span t:type="ck/Tooltip" title="${message:description}" value="${choiceOfPoll.description}" effect="blind">
- <t:output value="choiceNameAsDate" format="dateFormat"/>
- </span>
- </th>
- <p:else>
- <th>
- <t:output value="choiceNameAsDate" format="dateFormat"/>
- </th>
- </p:else>
- </t:unless>
- </t:if>
+ <t:loop t:source="poll.choices" t:value="choiceOfPoll" volatile="true">
+ <t:unless test="choiceHidden">
+ <t:unless test="isDescNull()">
+ <th class="desc">
+ <span t:type="ck/Tooltip" t:value="choiceOfPoll.description" t:effect="blind">
+ <t:output value="choiceNameAsDate" format="dateFormat"/>
+ </span>
+ </th>
+ <p:else>
+ <th>
+ <t:output value="choiceNameAsDate" format="dateFormat"/>
+ </th>
+ </p:else>
+ </t:unless>
+ </t:unless>
</t:loop>
</t:if>
<t:if test="imageType">
- <t:loop t:source="poll.choiceDTOs" t:value="choiceOfPoll" volatile="true">
+ <t:loop t:source="poll.choices" t:value="choiceOfPoll" volatile="true">
<t:if test="!isChoiceHidden()">
<t:unless test="isDescNull()">
<th class="desc">
@@ -137,7 +136,7 @@
<th></th>
</p:else>
</t:if>
- <t:loop t:source="poll.choiceDTOs" t:value="choiceOfVote" volatile="true">
+ <t:loop t:source="poll.choices" t:value="choiceOfVote" volatile="true">
<t:if test="!choiceOfVote.hidden">
<th>
<t:if test="isNormalVoteCounting()">
@@ -184,7 +183,7 @@
</t:if>
</t:unless>
</td>
- <t:loop t:source="poll.choiceDTOs" t:value="choiceOfPoll" volatile="true">
+ <t:loop t:source="poll.choices" t:value="choiceOfPoll" volatile="true">
<t:unless t:test="choiceHidden">
${setCurrentVoteChoice()}
<t:if t:test="poll.anonymous">
@@ -234,7 +233,7 @@
<td>
<t:PageLink t:page="poll/results" t:context="${poll.pollId}">${message:results}</t:PageLink>
</td>
- <t:loop t:source="poll.choiceDTOs" t:value="choiceOfPoll" volatile="true">
+ <t:loop t:source="poll.choices" t:value="choiceOfPoll" volatile="true">
<t:if test="!isChoiceHidden()">
<td class="result">${currentChoiceResult}</td>
</t:if>
@@ -304,7 +303,7 @@
<h3>${message:comments}</h3>
<t:zone t:id="commentZone" show="show" update="show">
<div id="commentsDiv">
- <div t:type="loop" t:source="poll.comments" t:value="comment" class="${evenodd.next}">
+ <div t:type="loop" t:source="comments" t:value="comment" class="${evenodd.next}">
<t:if test="creatorUser">
<span class="cmd">
<t:actionlink t:id="deleteComment" context="comment.id" t:zone="commentZone">
Deleted: trunk/pollen-ui/src/test/java/org/chorem/pollen/ui/utils/SendMailTest.java
===================================================================
--- trunk/pollen-ui/src/test/java/org/chorem/pollen/ui/utils/SendMailTest.java 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pollen-ui/src/test/java/org/chorem/pollen/ui/utils/SendMailTest.java 2010-03-19 15:05:04 UTC (rev 2951)
@@ -1,102 +0,0 @@
-/* *##% Pollen
- * Copyright (C) 2010 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.ui.utils;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.chorem.pollen.business.PollenContext;
-import org.chorem.pollen.business.PollenProperty;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.nuiton.util.ApplicationConfig;
-
-/**
- * Class for send mail storage class.
- *
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$
- * By : $Author$
- */
-@Ignore
-public class SendMailTest {
-
- protected static SendMail sendMail;
-
- @BeforeClass
- public static void init() throws InterruptedException {
-
- ApplicationConfig config = new ApplicationConfig();
- config.setOption(PollenProperty.EMAIL_DIR.getKey(), "target" + File.separator + "massmail");
- config.setOption(PollenProperty.EMAIL_HOST.getKey(), "smtp");
- config.setOption(PollenProperty.EMAIL_PORT.getKey(), "25");
- config.setOption(PollenProperty.EMAIL_FROM.getKey(), "pollenreminder(a)codelutin.com");
-
- PollenContext.loadConfiguration(config);
-
- sendMail = new SendMail();
- sendMail.start();
- Thread.sleep(3000);
- }
-
- /**
- * Test to add mail and send mail.
- *
- * WARNING : This test really send mail, don't set it automatic.
- *
- * @throws IOException
- * @throws InterruptedException
- */
- @Test
- public void testAddMail() throws IOException, InterruptedException {
- List<Map<String, String>> mailList = new ArrayList<Map<String,String>>();
-
- Map<String, String> mailMap = new HashMap<String, String>();
- mailMap.put("receiver", "chatellier+test(a)codelutin.com");
- mailMap.put("subject", "Test 18:00");
- mailMap.put("body", "Test body");
-
- Map<String, String> mailMap2 = new HashMap<String, String>();
- mailMap2.put("receiver", "chorlet+test(a)codelutin.com");
- mailMap2.put("subject", "CR, CR CR !!! 18:00");
- mailMap2.put("body", "Des cr, encore des \"CRs\" !!!");
-
- mailList.add(mailMap);
- mailList.add(mailMap2);
-
- sendMail.prepareMails("test", mailList);
-
- String emailDir = PollenProperty.EMAIL_DIR.getValue();
-
- Assert.assertTrue(new File(emailDir, "test.mail").exists());
- Assert.assertTrue(new File(emailDir, "test.index").exists());
- sendMail.wakeUp();
-
- // TODO , en 5 secondes, il aura le temps d'envoyer 2 mails ?
- Thread.sleep(5000);
- Assert.assertFalse(new File(emailDir, "test.mail").exists());
- Assert.assertFalse(new File(emailDir, "test.index").exists());
- }
-}
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-03-19 10:17:45 UTC (rev 2950)
+++ trunk/pom.xml 2010-03-19 15:05:04 UTC (rev 2951)
@@ -41,6 +41,11 @@
<artifactId>commons-email</artifactId>
<version>1.2</version>
</dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.4</version>
+ </dependency>
<!-- <dependency>
<groupId>org.chorem</groupId>
<artifactId>chorem-commons</artifactId>
1
0
r2950 - in branches/pollen-1.2.5-1.2.x/pollen-ui/src: main/java/org/chorem/pollen/ui/pages/user main/java/org/chorem/pollen/ui/utils main/resources/org/chorem/pollen/ui/pages/user test/java/org/chorem/pollen/ui/utils
by echatellier@users.chorem.org 19 Mar '10
by echatellier@users.chorem.org 19 Mar '10
19 Mar '10
Author: echatellier
Date: 2010-03-19 11:17:45 +0100 (Fri, 19 Mar 2010)
New Revision: 2950
Log:
#147 : CSV import fail on content type check
Added:
branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/CSVParseException.java
Modified:
branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserLists.java
branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/CSVAccountUtil.java
branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/user/UserLists_en.properties
branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/user/UserLists_fr.properties
branches/pollen-1.2.5-1.2.x/pollen-ui/src/test/java/org/chorem/pollen/ui/utils/CSVAccountUtilTest.java
Modified: branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserLists.java
===================================================================
--- branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserLists.java 2010-03-16 10:22:18 UTC (rev 2949)
+++ branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/UserLists.java 2010-03-19 10:17:45 UTC (rev 2950)
@@ -46,7 +46,9 @@
import org.chorem.pollen.ui.data.EvenOdd;
import org.chorem.pollen.ui.data.Lien;
import org.chorem.pollen.ui.utils.CSVAccountUtil;
+import org.chorem.pollen.ui.utils.CSVParseException;
import org.chorem.pollen.ui.utils.LDAPAccountUtil;
+import org.slf4j.Logger;
/**
* Classe de la page d'affichage des listes de votants favorites de
@@ -59,6 +61,9 @@
@IncludeStylesheet("context:css/lists.css")
public class UserLists {
+ @Inject
+ private Logger log;
+
/**
* Objet de session représentant l'utilisateur identifié.
*/
@@ -196,19 +201,36 @@
// Import CVS des comptes
if (accountsFile != null) {
- if (!accountsFile.getContentType().equals("text/csv")) {
+ /*
+ Ce test n'est pas sur, c'est à l'appreciation du client, par
+ exemple, chromium envoi 'application/octet-stream'
+
+ if (!"text/csv".equals(accountsFile.getContentType())) {
createListForm.recordError(messages.format("invalidCsv",
accountsFile.getFileName()));
+ if (log.isWarnEnabled()) {
+ log.warn("Uploaded csv file content type : " + accountsFile.getContentType());
+ }
return this;
+ }*/
+ try {
+ List<PollAccountDTO> accounts = CSVAccountUtil
+ .importList(accountsFile);
+ if (accounts.size() == 0) {
+ createListForm.recordError(messages.format("noAccountCsv",
+ accountsFile.getFileName()));
+ return this;
+ }
+ newList.getPollAccountDTOs().addAll(accounts);
}
- List<PollAccountDTO> accounts = CSVAccountUtil
- .importList(accountsFile);
- if (accounts.size() == 0) {
- createListForm.recordError(messages.format("noAccountCsv",
+ catch (CSVParseException ex) {
+ if (log.isErrorEnabled()) {
+ log.error("Can't import uploaded file", ex);
+ }
+ createListForm.recordError(messages.format("invalidCsv",
accountsFile.getFileName()));
return this;
}
- newList.getPollAccountDTOs().addAll(accounts);
}
// Import LDAP des comptes
Modified: branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/CSVAccountUtil.java
===================================================================
--- branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/CSVAccountUtil.java 2010-03-16 10:22:18 UTC (rev 2949)
+++ branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/CSVAccountUtil.java 2010-03-19 10:17:45 UTC (rev 2950)
@@ -18,9 +18,11 @@
import java.io.InputStreamReader;
import java.io.Reader;
+import java.text.ParseException;
import java.util.Iterator;
import java.util.List;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tapestry5.upload.services.UploadedFile;
@@ -47,33 +49,39 @@
*
* @param reader which contains the input stream
* @return the new PollAccountDTO list from results imported
+ *
+ * @throws CSVParseException if file can't be read (not csv file)
*/
- public static List<PollAccountDTO> importList(Reader reader) {
+ public static List<PollAccountDTO> importList(Reader reader) throws CSVParseException {
List<PollAccountDTO> accounts = null;
- // Définition de la stratégie de mapping
- ColumnPositionMappingStrategy<PollAccountDTO> strat =
- new ColumnPositionMappingStrategy<PollAccountDTO>();
- String[] columns = new String[] { "votingId", "email", "weight" };
- strat.setType(PollAccountDTO.class);
- strat.setColumnMapping(columns);
-
- // Parsing du fichier CSV
- CsvToBean<PollAccountDTO> csv = new CsvToBean<PollAccountDTO>();
- accounts = csv.parse(strat, reader);
-
- // Suppression des comptes null
- Iterator<PollAccountDTO> it = accounts.iterator();
- while (it.hasNext()) {
- if ("".equals(it.next().getVotingId())) {
- it.remove();
+ try {
+ // Définition de la stratégie de mapping
+ ColumnPositionMappingStrategy<PollAccountDTO> strat =
+ new ColumnPositionMappingStrategy<PollAccountDTO>();
+ String[] columns = new String[] { "votingId", "email", "weight" };
+ strat.setType(PollAccountDTO.class);
+ strat.setColumnMapping(columns);
+
+ // Parsing du fichier CSV
+ CsvToBean<PollAccountDTO> csv = new CsvToBean<PollAccountDTO>();
+ accounts = csv.parse(strat, reader);
+
+ // Suppression des comptes null
+ Iterator<PollAccountDTO> it = accounts.iterator();
+ while (it.hasNext()) {
+ if ("".equals(it.next().getVotingId())) {
+ it.remove();
+ }
}
+
+ if (log.isInfoEnabled()) {
+ log.info(accounts.size() + " comptes importés.");
+ }
+ } catch (Exception ex) {
+ throw new CSVParseException("Error during csv import", ex);
}
- if (log.isInfoEnabled()) {
- log.info(accounts.size() + " comptes importés.");
- }
-
return accounts;
}
@@ -83,14 +91,25 @@
* @param file le fichier CSV
* @return a PollAccountDTO list
* @see #importList(java.io.Reader)
+ *
+ * @throws CSVParseException if file can't be read (not csv file)
*/
- public static List<PollAccountDTO> importList(UploadedFile file) {
+ public static List<PollAccountDTO> importList(UploadedFile file) throws CSVParseException {
if (log.isInfoEnabled()) {
log.info("Import du fichier " + file.getFileName() + " ("
+ file.getContentType() + ")...");
}
- InputStreamReader reader = new InputStreamReader(file.getStream());
- return importList(reader);
+ // make sure that reader is closed after parse
+ List<PollAccountDTO> result = null;
+ InputStreamReader reader = null;
+ try {
+ reader = new InputStreamReader(file.getStream());
+ result = importList(reader);
+ }
+ finally {
+ IOUtils.closeQuietly(reader);
+ }
+ return result;
}
}
Added: branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/CSVParseException.java
===================================================================
--- branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/CSVParseException.java (rev 0)
+++ branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/CSVParseException.java 2010-03-19 10:17:45 UTC (rev 2950)
@@ -0,0 +1,43 @@
+/* *##% Pollen
+ * Copyright (C) 2010 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.ui.utils;
+
+/**
+ * CVS excpetion thrown during bad file parsing.
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class CSVParseException extends Exception {
+
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 1717187553275691080L;
+
+ /**
+ * Constructor with message and cause.
+ *
+ * @param message message
+ * @param cause cause
+ */
+ public CSVParseException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
Property changes on: branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/utils/CSVParseException.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/user/UserLists_en.properties
===================================================================
--- branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/user/UserLists_en.properties 2010-03-16 10:22:18 UTC (rev 2949)
+++ branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/user/UserLists_en.properties 2010-03-19 10:17:45 UTC (rev 2950)
@@ -1,7 +1,7 @@
title=Your voting lists
accountExists=%s already exists in this list.
listExists=%s list already exists.
-invalidCsv=%s is not a CSV file.
+invalidCsv=%s is not a valid CSV file !
noAccountCsv=%s file contains no valid entry.
noAccountLdap=%s URL can not obtain valid entries.
noUser=You must be logged to access to your polls.\n Please fill the form below.
Modified: branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/user/UserLists_fr.properties
===================================================================
--- branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/user/UserLists_fr.properties 2010-03-16 10:22:18 UTC (rev 2949)
+++ branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/resources/org/chorem/pollen/ui/pages/user/UserLists_fr.properties 2010-03-19 10:17:45 UTC (rev 2950)
@@ -1,7 +1,7 @@
title=Vos listes de votants
accountExists=L'identifiant de vote %s existe d\u00E9j\u00E0 dans cette liste.
listExists=La liste %s existe d\u00E9j\u00E0.
-invalidCsv=Le fichier %s n'est pas un fichier CSV.
+invalidCsv=Le fichier %s n'est pas un fichier CSV valide !
noAccountCsv=Le fichier %s ne contient aucune entr\u00E9e valide.
noAccountLdap=L'URL %s ne permet pas d'obtenir d'entr\u00E9es valides.
noUser=Vous devez \u00EAtre identifi\u00E9 pour pouvoir acc\u00E9der \u00E0 vos listes de votants.\n Veuillez remplir le formulaire ci-dessous.
Modified: branches/pollen-1.2.5-1.2.x/pollen-ui/src/test/java/org/chorem/pollen/ui/utils/CSVAccountUtilTest.java
===================================================================
--- branches/pollen-1.2.5-1.2.x/pollen-ui/src/test/java/org/chorem/pollen/ui/utils/CSVAccountUtilTest.java 2010-03-16 10:22:18 UTC (rev 2949)
+++ branches/pollen-1.2.5-1.2.x/pollen-ui/src/test/java/org/chorem/pollen/ui/utils/CSVAccountUtilTest.java 2010-03-19 10:17:45 UTC (rev 2950)
@@ -39,9 +39,10 @@
/**
* Test of importList method, of class CSVAccountUtil.
+ * @throws CSVParseException
*/
@Test
- public void testImportList_Reader() {
+ public void testImportList_Reader() throws CSVParseException {
System.out.println("importList");
InputStream input = getClass().getResourceAsStream("/import.csv");
1
0
r2949 - in branches/pollen-1.2.5-1.2.x/pollen-ui/src/main: java/org/chorem/pollen/ui/pages/poll webapp/poll
by echatellier@users.chorem.org 16 Mar '10
by echatellier@users.chorem.org 16 Mar '10
16 Mar '10
Author: echatellier
Date: 2010-03-16 11:22:18 +0100 (Tue, 16 Mar 2010)
New Revision: 2949
Log:
Fix poll description format.
Fix line break in chenillekit tooltips.
Modified:
branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java
branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/webapp/poll/VoteForPoll.tml
Modified: branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java
===================================================================
--- branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-03-16 08:59:17 UTC (rev 2948)
+++ branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-03-16 10:22:18 UTC (rev 2949)
@@ -27,6 +27,8 @@
import java.util.Map;
import java.util.UUID;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.EventContext;
import org.apache.tapestry5.ValidationException;
@@ -1244,4 +1246,24 @@
}
return votes;
}
+
+ /**
+ * This method is used in tapestry template to escape line break string.
+ *
+ * Used for chenillekit tooltip for example.
+ *
+ * @param nonEscapedString non escaped string
+ * @return html escaped string
+ */
+ public String escapeLineBreak(String nonEscapedString) {
+
+ if (nonEscapedString == null) {
+ return null;
+ }
+
+ String localStr = nonEscapedString.replaceAll("\n", "<br />");
+ localStr = localStr.replaceAll("\r", "");
+
+ return localStr;
+ }
}
Modified: branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/webapp/poll/VoteForPoll.tml
===================================================================
--- branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/webapp/poll/VoteForPoll.tml 2010-03-16 08:59:17 UTC (rev 2948)
+++ branches/pollen-1.2.5-1.2.x/pollen-ui/src/main/webapp/poll/VoteForPoll.tml 2010-03-16 10:22:18 UTC (rev 2949)
@@ -10,7 +10,7 @@
<!-- Informations sur le sondage -->
<div id="pollTop">
- ${poll.description}
+ <div style="white-space:pre-wrap; text-align: start;">${poll.description}</div>
<fieldset>
<legend>${message:about}</legend>
<div style="float: right">
@@ -69,7 +69,7 @@
<t:if test="!isChoiceHidden()">
<th>
<t:unless test="isDescNull()">
- <span t:type="ck/Tooltip" title="${message:description}" value="${choiceOfPoll.description}" effect="blind">
+ <span t:type="ck/Tooltip" title="${message:description}" value="${escapeLineBreak(choiceOfPoll.description)}" effect="blind">
<span class="desc">${choiceOfPoll.name}</span>
</span>
<p:else>
@@ -92,7 +92,7 @@
<t:if test="!isChoiceHidden()">
<t:unless test="isDescNull()">
<th class="desc">
- <span t:type="ck/Tooltip" title="${message:description}" value="${choiceOfPoll.description}" effect="blind">
+ <span t:type="ck/Tooltip" title="${message:description}" value="${escapeLineBreak(choiceOfPoll.description)}" effect="blind">
<t:output value="choiceNameAsDate" format="dateFormat"/>
</span>
</th>
@@ -111,7 +111,7 @@
<t:if test="!isChoiceHidden()">
<t:unless test="isDescNull()">
<th class="desc">
- <span t:type="ck/Tooltip" title="${message:description}" value="${choiceOfPoll.description}" effect="blind">
+ <span t:type="ck/Tooltip" title="${message:description}" value="${escapeLineBreak(choiceOfPoll.description)}" effect="blind">
<t:image t:src="choiceOfPoll.name" alt="choiceOfPoll.description" t:dir="poll.pollId"/>
</span>
</th>
1
0
r2948 - in branches/pollen-1.2.5-1.2.x: . pollen-business pollen-ui pollen-votecounting
by echatellier@users.chorem.org 16 Mar '10
by echatellier@users.chorem.org 16 Mar '10
16 Mar '10
Author: echatellier
Date: 2010-03-16 09:59:17 +0100 (Tue, 16 Mar 2010)
New Revision: 2948
Log:
Prepare next snapshot version
Modified:
branches/pollen-1.2.5-1.2.x/pollen-business/pom.xml
branches/pollen-1.2.5-1.2.x/pollen-ui/pom.xml
branches/pollen-1.2.5-1.2.x/pollen-votecounting/pom.xml
branches/pollen-1.2.5-1.2.x/pom.xml
Modified: branches/pollen-1.2.5-1.2.x/pollen-business/pom.xml
===================================================================
--- branches/pollen-1.2.5-1.2.x/pollen-business/pom.xml 2010-03-16 08:53:19 UTC (rev 2947)
+++ branches/pollen-1.2.5-1.2.x/pollen-business/pom.xml 2010-03-16 08:59:17 UTC (rev 2948)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.chorem</groupId>
<artifactId>pollen</artifactId>
- <version>1.2.5</version>
+ <version>1.2.6-SNAPSHOT</version>
</parent>
<groupId>org.chorem.pollen</groupId>
Modified: branches/pollen-1.2.5-1.2.x/pollen-ui/pom.xml
===================================================================
--- branches/pollen-1.2.5-1.2.x/pollen-ui/pom.xml 2010-03-16 08:53:19 UTC (rev 2947)
+++ branches/pollen-1.2.5-1.2.x/pollen-ui/pom.xml 2010-03-16 08:59:17 UTC (rev 2948)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.chorem</groupId>
<artifactId>pollen</artifactId>
- <version>1.2.5</version>
+ <version>1.2.6-SNAPSHOT</version>
</parent>
<groupId>org.chorem.pollen</groupId>
Modified: branches/pollen-1.2.5-1.2.x/pollen-votecounting/pom.xml
===================================================================
--- branches/pollen-1.2.5-1.2.x/pollen-votecounting/pom.xml 2010-03-16 08:53:19 UTC (rev 2947)
+++ branches/pollen-1.2.5-1.2.x/pollen-votecounting/pom.xml 2010-03-16 08:59:17 UTC (rev 2948)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.chorem</groupId>
<artifactId>pollen</artifactId>
- <version>1.2.5</version>
+ <version>1.2.6-SNAPSHOT</version>
</parent>
<groupId>org.chorem.pollen</groupId>
Modified: branches/pollen-1.2.5-1.2.x/pom.xml
===================================================================
--- branches/pollen-1.2.5-1.2.x/pom.xml 2010-03-16 08:53:19 UTC (rev 2947)
+++ branches/pollen-1.2.5-1.2.x/pom.xml 2010-03-16 08:59:17 UTC (rev 2948)
@@ -15,7 +15,7 @@
<groupId>org.chorem</groupId>
<artifactId>pollen</artifactId>
- <version>1.2.5</version>
+ <version>1.2.6-SNAPSHOT</version>
<modules>
<module>pollen-ui</module>
@@ -345,9 +345,9 @@
<!-- ************************************************************* -->
<scm>
- <connection>scm:svn:http://svn.chorem.org/svn/pollen/tags/pollen-1.2.5</connection>
- <developerConnection>scm:svn:http://svn.chorem.org/svn/pollen/tags/pollen-1.2.5</developerConnection>
- <url>http://www.chorem.org/repositories/browse/pollen/tags/pollen-1.2.5</url>
+ <connection>scm:svn:http://svn.chorem.org/svn/pollen/branches/pollen-1.2.5-1.2.x</connection>
+ <developerConnection>scm:svn:http://svn.chorem.org/svn/pollen/branches/pollen-1.2.5-1.2.x</developerConnection>
+ <url>http://www.chorem.org/repositories/browse/pollen/branches/pollen-1.2.5-1.2.x</url>
</scm>
<repositories>
1
0
Author: echatellier
Date: 2010-03-16 09:53:19 +0100 (Tue, 16 Mar 2010)
New Revision: 2947
Log:
Create maintenance branche from 1.2.5
Added:
branches/pollen-1.2.5-1.2.x/
Property changes on: branches/pollen-1.2.5-1.2.x
___________________________________________________________________
Added: svn:ignore
+ target
nbactions.xml
.settings
.classpath
.project
*.ipr
*.iws
*.iml
Added: svn:mergeinfo
+
1
0
Author: tchemit
Date: 2010-03-15 23:25:29 +0100 (Mon, 15 Mar 2010)
New Revision: 2946
Log:
final bundle are now generated and should not be stored in vcs
Modified:
trunk/pollen-ui/src/main/webapp/WEB-INF/
Property changes on: trunk/pollen-ui/src/main/webapp/WEB-INF
___________________________________________________________________
Added: svn:ignore
+ app_fr.properties
app_en.properties
1
0
r2945 - in trunk/pollen-ui: . src/main/java/org/chorem/pollen/ui/pages/poll src/main/resources src/main/resources/i18n src/main/webapp/WEB-INF
by tchemit@users.chorem.org 15 Mar '10
by tchemit@users.chorem.org 15 Mar '10
15 Mar '10
Author: tchemit
Date: 2010-03-15 23:23:55 +0100 (Mon, 15 Mar 2010)
New Revision: 2945
Log:
- application does not run with SendEmail as service (floarian has forgot something...)
- use tapestry-bundle from i18n plugin
Added:
trunk/pollen-ui/src/main/resources/i18n/
trunk/pollen-ui/src/main/resources/i18n/pollen-ui-en_GB.properties
trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties
Removed:
trunk/pollen-ui/src/main/webapp/WEB-INF/app_en.properties
trunk/pollen-ui/src/main/webapp/WEB-INF/app_fr.properties
Modified:
trunk/pollen-ui/pom.xml
trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java
Modified: trunk/pollen-ui/pom.xml
===================================================================
--- trunk/pollen-ui/pom.xml 2010-03-15 22:20:47 UTC (rev 2944)
+++ trunk/pollen-ui/pom.xml 2010-03-15 22:23:55 UTC (rev 2945)
@@ -97,6 +97,9 @@
<properties>
<redmine.releaseFiles>target/${project.build.finalName}.war</redmine.releaseFiles>
+
+ <i18n.collectOutputName>app</i18n.collectOutputName>
+ <i18n.bundleOutputName>app</i18n.bundleOutputName>
</properties>
<reporting>
@@ -119,6 +122,20 @@
<!-- Add main class into war to make it executable -->
<plugins>
+
+ <plugin>
+ <groupId>org.nuiton.i18n</groupId>
+ <artifactId>maven-i18n-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>tapestry-bundle</goal>
+ </goals>
+ </execution>
+
+ </executions>
+ </plugin>
+
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java
===================================================================
--- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java 2010-03-15 22:20:47 UTC (rev 2944)
+++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java 2010-03-15 22:23:55 UTC (rev 2945)
@@ -315,8 +315,8 @@
@Inject
private ServiceList serviceList;
- @Inject
- private SendMail sendMailService;
+// @Inject
+// private SendMail sendMailService;
/**
* Méthode appelée lorsqu'on souhaite accéder à l'étape suivante de la
@@ -854,14 +854,14 @@
}
// 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);
- }
- }
+// 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);
+// }
+// }
}
}
Copied: trunk/pollen-ui/src/main/resources/i18n/pollen-ui-en_GB.properties (from rev 2943, trunk/pollen-ui/src/main/webapp/WEB-INF/app_en.properties)
===================================================================
--- trunk/pollen-ui/src/main/resources/i18n/pollen-ui-en_GB.properties (rev 0)
+++ trunk/pollen-ui/src/main/resources/i18n/pollen-ui-en_GB.properties 2010-03-15 22:23:55 UTC (rev 2945)
@@ -0,0 +1,42 @@
+# User registration emails
+registerEmail_subject=[Pollen] Confirmation of account creation %s
+registerEmail_msg=Welcome %s %s. You had just created an account on the web application Pollen.\n\nLogin: %s\nPassword: %s\n\nYou can now manage your polls by logging on the website : \n%s
+
+# Poll creation emails
+creatorEmail_subject=[Pollen] Poll creation (%s)
+creatorEmail_msg=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
+votingEmail_subject=[Pollen] Invitation to vote (%s)
+votingEmail_msg=A new poll has been created: "%s".\nYou can participate with the identifier %s by following this link: \n%s
+
+# Notification emails
+voteEmail_subject=[Pollen] Vote reporting (%s)
+voteEmail_msg=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
+
+# Reminder emails
+reminderEmail_subject=[Pollen] Reminder (%s)
+reminderEmail_msg=You have not yet voted for the poll "%s".\nYou can still participate with the identifier %s by following this link: \n%s
+
+# Poll feed
+pollFeed_title=Pollen : %s
+pollFeed_desc=%s
+pollFeed_createTitle=Poll created by %s
+pollFeed_createContent=
+pollFeed_voteTitle=New vote from %s
+pollFeed_voteContent=Poll state : %s
+pollFeed_choiceTitle=New choice : %s
+pollFeed_choiceContent=%s
+pollFeed_commentTitle=New comment from %s
+pollFeed_commentContent=%s
+
+# Actions
+create=Create
+edit=Edit
+delete=Delete
+add=Add
+save=Save
+load=Load
+ok=Ok
+validate=Validate
+cancel=Cancel
+return=Return
+help=Help
\ No newline at end of file
Copied: trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties (from rev 2943, trunk/pollen-ui/src/main/webapp/WEB-INF/app_fr.properties)
===================================================================
--- trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties (rev 0)
+++ trunk/pollen-ui/src/main/resources/i18n/pollen-ui-fr_FR.properties 2010-03-15 22:23:55 UTC (rev 2945)
@@ -0,0 +1,42 @@
+# User registration emails
+registerEmail_subject=[Pollen] Confirmation de cr\u00e9ation du compte %s
+registerEmail_msg=Bienvenue %s %s. Vous venez de cr\u00e9er un compte sur l'application de sondage en ligne Pollen.\n\nIdentifiant : %s\nMot de passe : %s\n\nVous pouvez d\u00e8s maintenant g\u00e9rer vos sondages en vous identifiant sur le site : \n%s
+
+# Poll creation emails
+creatorEmail_subject=[Pollen] Cr\u00e9ation d'un sondage (%s)
+creatorEmail_msg=Vous venez de cr\u00e9er le sondage "%s".\nVous pouvez y acc\u00e9der en suivant les liens ci-dessous.\n\nPage de vote : \n%s\nPage de modification : \n%s
+votingEmail_subject=[Pollen] Invitation au vote (%s)
+votingEmail_msg=Un nouveau sondage a \u00e9t\u00e9 cr\u00e9\u00e9 : "%s".\nVous pouvez y participer avec l'identifiant %s \u00e0 l'adresse suivante : \n%s
+
+# Notification emails
+voteEmail_subject=[Pollen] Notification de vote (%s)
+voteEmail_msg=Un vote vient d'\u00eatre enregistr\u00e9 pour le sondage "%s". Ce sondage compte d\u00e9sormais %d votes.\nVous pouvez acc\u00e9der \u00e0 ce sondage en suivant les liens ci-dessous.\n\nPage de vote : \n%s\nPage de modification : \n%s
+
+# Reminder emails
+reminderEmail_subject=[Pollen] Rappel (%s)
+reminderEmail_msg=Vous n'avez pas encore vot\u00e9 pour le sondage "%s".\nVous pouvez encore y participer avec l'identifiant %s \u00e0 l'adresse suivante : \n%s
+
+# Poll feed
+pollFeed_title=Pollen : %s
+pollFeed_desc=%s
+pollFeed_createTitle=Sondage cr\u00e9\u00e9 par %s
+pollFeed_createContent=
+pollFeed_voteTitle=Nouveau vote de %s
+pollFeed_voteContent=\u00c9tat du sondage : %s
+pollFeed_choiceTitle=Nouveau choix : %s
+pollFeed_choiceContent=%s
+pollFeed_commentTitle=Nouveau commentaire de %s
+pollFeed_commentContent=%s
+
+# Actions
+create=Cr\u00e9er
+edit=Modifier
+delete=Supprimer
+add=Ajouter
+save=Enregistrer
+load=Charger
+ok=Ok
+validate=Valider
+cancel=Annuler
+return=Retour
+help=Aide
Deleted: trunk/pollen-ui/src/main/webapp/WEB-INF/app_en.properties
===================================================================
--- trunk/pollen-ui/src/main/webapp/WEB-INF/app_en.properties 2010-03-15 22:20:47 UTC (rev 2944)
+++ trunk/pollen-ui/src/main/webapp/WEB-INF/app_en.properties 2010-03-15 22:23:55 UTC (rev 2945)
@@ -1,42 +0,0 @@
-# User registration emails
-registerEmail_subject=[Pollen] Confirmation of account creation %s
-registerEmail_msg=Welcome %s %s. You had just created an account on the web application Pollen.\n\nLogin: %s\nPassword: %s\n\nYou can now manage your polls by logging on the website : \n%s
-
-# Poll creation emails
-creatorEmail_subject=[Pollen] Poll creation (%s)
-creatorEmail_msg=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
-votingEmail_subject=[Pollen] Invitation to vote (%s)
-votingEmail_msg=A new poll has been created: "%s".\nYou can participate with the identifier %s by following this link: \n%s
-
-# Notification emails
-voteEmail_subject=[Pollen] Vote reporting (%s)
-voteEmail_msg=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
-
-# Reminder emails
-reminderEmail_subject=[Pollen] Reminder (%s)
-reminderEmail_msg=You have not yet voted for the poll "%s".\nYou can still participate with the identifier %s by following this link: \n%s
-
-# Poll feed
-pollFeed_title=Pollen : %s
-pollFeed_desc=%s
-pollFeed_createTitle=Poll created by %s
-pollFeed_createContent=
-pollFeed_voteTitle=New vote from %s
-pollFeed_voteContent=Poll state : %s
-pollFeed_choiceTitle=New choice : %s
-pollFeed_choiceContent=%s
-pollFeed_commentTitle=New comment from %s
-pollFeed_commentContent=%s
-
-# Actions
-create=Create
-edit=Edit
-delete=Delete
-add=Add
-save=Save
-load=Load
-ok=Ok
-validate=Validate
-cancel=Cancel
-return=Return
-help=Help
\ No newline at end of file
Deleted: trunk/pollen-ui/src/main/webapp/WEB-INF/app_fr.properties
===================================================================
--- trunk/pollen-ui/src/main/webapp/WEB-INF/app_fr.properties 2010-03-15 22:20:47 UTC (rev 2944)
+++ trunk/pollen-ui/src/main/webapp/WEB-INF/app_fr.properties 2010-03-15 22:23:55 UTC (rev 2945)
@@ -1,42 +0,0 @@
-# User registration emails
-registerEmail_subject=[Pollen] Confirmation de création du compte %s
-registerEmail_msg=Bienvenue %s %s. Vous venez de créer un compte sur l'application de sondage en ligne Pollen.\n\nIdentifiant : %s\nMot de passe : %s\n\nVous pouvez dès maintenant gérer vos sondages en vous identifiant sur le site : \n%s
-
-# Poll creation emails
-creatorEmail_subject=[Pollen] Création d'un sondage (%s)
-creatorEmail_msg=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
-votingEmail_subject=[Pollen] Invitation au vote (%s)
-votingEmail_msg=Un nouveau sondage a été créé : "%s".\nVous pouvez y participer avec l'identifiant %s à l'adresse suivante : \n%s
-
-# Notification emails
-voteEmail_subject=[Pollen] Notification de vote (%s)
-voteEmail_msg=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
-
-# Reminder emails
-reminderEmail_subject=[Pollen] Rappel (%s)
-reminderEmail_msg=Vous n'avez pas encore voté pour le sondage "%s".\nVous pouvez encore y participer avec l'identifiant %s à l'adresse suivante : \n%s
-
-# Poll feed
-pollFeed_title=Pollen : %s
-pollFeed_desc=%s
-pollFeed_createTitle=Sondage créé par %s
-pollFeed_createContent=
-pollFeed_voteTitle=Nouveau vote de %s
-pollFeed_voteContent=État du sondage : %s
-pollFeed_choiceTitle=Nouveau choix : %s
-pollFeed_choiceContent=%s
-pollFeed_commentTitle=Nouveau commentaire de %s
-pollFeed_commentContent=%s
-
-# Actions
-create=Créer
-edit=Modifier
-delete=Supprimer
-add=Ajouter
-save=Enregistrer
-load=Charger
-ok=Ok
-validate=Valider
-cancel=Annuler
-return=Retour
-help=Aide
\ No newline at end of file
1
0
Author: tchemit
Date: 2010-03-15 23:20:47 +0100 (Mon, 15 Mar 2010)
New Revision: 2944
Log:
use i18n 1.1.1 + nuiton-utils 1.2
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-03-15 14:48:49 UTC (rev 2943)
+++ trunk/pom.xml 2010-03-15 22:20:47 UTC (rev 2944)
@@ -301,9 +301,9 @@
<!--javadoc.version>2.4</javadoc.version-->
<topia.version>2.3</topia.version>
<eugene.version>2.0</eugene.version>
- <i18n.version>1.0.1</i18n.version>
+ <i18n.version>1.1.1-SNAPSHOT</i18n.version>
<tapestry.version>5.1.0.5</tapestry.version>
- <nuiton-utils.version>1.1.5-SNAPSHOT</nuiton-utils.version>
+ <nuiton-utils.version>1.2</nuiton-utils.version>
<!-- <chorem-commons.version>1.0.0-alpha-2-SNAPSHOT</chorem-commons.version>-->
<!--Multilanguage maven-site -->
1
0