Author: fdesbois Date: 2010-02-25 13:07:51 +0100 (Thu, 25 Feb 2010) New Revision: 2884 Added: 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/PollenProperty.java trunk/pollen-business/src/main/resources/pollen.properties trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestManager.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java Removed: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/Configuration.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ConfigurationImpl.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenShutdown.java trunk/pollen-ui/src/main/resources/pollen.properties Modified: trunk/pollen-business/pom.xml trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollConverter.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/ServicePoll.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/main/resources/i18n/pollen-business-en_GB.properties trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestData.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/base/ContextLink.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/FileLink.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/HeadLink.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/pages/admin/UsersAdmin.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/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/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/PropertiesFileSymbolProvider.java Log: - Move pollen.properties from UI to Business - Add PollenContext to replace ContextUtil deprecated - Add PollenProperty enum to easily get existing properties in configuration file - Refactor UI to use PollenContext to get properties - Refactor services to use PollenContext to get root context - Add TestManager to start and stop tests (use different configuration than default one) Modified: trunk/pollen-business/pom.xml =================================================================== --- trunk/pollen-business/pom.xml 2010-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/pom.xml 2010-02-25 12:07:51 UTC (rev 2884) @@ -137,19 +137,6 @@ <goal>parserJava</goal> <goal>gen</goal> </goals> - <!-- restrict parsing beacause this is expensive --> - <!-- if you want to parse more, add your package in includes --> - <configuration> - <treateDefaultEntry>false</treateDefaultEntry> - <entries> - <entry> - <basedir>${maven.src.dir}/main/java</basedir> - <includes> - <include>org/nuiton/topia/framework/*.java</include> - </includes> - </entry> - </entries> - </configuration> </execution> </executions> </plugin> Added: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenBusinessException.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenBusinessException.java (rev 0) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenBusinessException.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -0,0 +1,41 @@ + +package org.chorem.pollen.business; +import static org.nuiton.i18n.I18n._; + +/** + * PollenBusinessException + * + * Created: 24 févr. 2010 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class PollenBusinessException extends Exception { + + private static final long serialVersionUID = 1L; + + protected PollenExceptionType type; + + public PollenBusinessException(PollenExceptionType type) { + super(type.toString()); + } + + public enum PollenExceptionType { + LOAD_CONFIGURATION(_("pollen.exception.load_configuration")); + + private String name; + + PollenExceptionType(String name) { + this.name = name; + } + + @Override + public String toString() { + return name; + } + + } +} Property changes on: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenBusinessException.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL" Added: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContext.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContext.java (rev 0) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContext.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -0,0 +1,257 @@ + +package org.chorem.pollen.business; + +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.PollenBusinessException.PollenExceptionType; +import org.chorem.pollen.business.persistence.PollenModelDAOHelper; +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._; + +/** + * PollenContext + * + * Created: 24 févr. 2010 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class PollenContext { + + /** log. */ + private static final Log log = LogFactory.getLog(PollenContext.class); + + public static final String DEFAULT_FILENAME = "pollen.properties"; + + private static ApplicationConfig configuration; + + /** + * 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, + _("pollen.error.context.parse", PollenContext.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 + */ + public static 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> + * + */ + public static void start() { + try { + I18n.init(); + + ServiceUserImpl serviceUser = new ServiceUserImpl(); + serviceUser.createDefaultAdmin( + PollenProperty.ADMIN_LOGIN.getValue(), + PollenProperty.ADMIN_PASSWORD.getValue(), + PollenProperty.ADMIN_EMAIL.getValue() + ); + + if (log.isInfoEnabled()) { + log.info("pollen is started !"); + } + + } catch (Exception eee) { + doCatch(eee, _("pollen.error.context.start")); + } + } + + /** + * Stop the application. Close the Topia rootContext. + */ + public static void stop() { + try { + getRootContext().closeContext(); + } catch (Exception eee) { + doCatch(eee, _("pollen.error.context.stop")); + } + } + + /** + * Get a property from the configuration. + * + * @param property PollenProperty + * @return value of this property + * @ + */ + public static String getProperty(PollenProperty property) { + return getConfiguration().getOption(property.getKey()); + } + + /** + * Get a property from the configuration. + * + * @param key of the property + * @return value of this property + * @ + */ + public static String getProperty(String key) { + return getConfiguration().getOption(key); + } + + /** + * Get all properties from the configuration + * + * @return the Properties of the application + * @ + */ + public static Properties getProperties() { + return getConfiguration().getOptions(); + } + + /** + * Get the configuration of the application. + * + * @return the ApplicationConfig + * @ + */ + public static ApplicationConfig getConfiguration() { + if (configuration == null) { + loadDefaultConfiguration(); + } + return configuration; + } + + /** + * Get the Topia rootContext. + * + * @return the main TopiaContext needed to begin new transaction + * @ + */ + public static TopiaContext getRootContext() { + try { + return TopiaContextFactory.getContext(getProperties()); + } catch (TopiaNotFoundException eee) { + doCatch(eee, _("pollen.error.context.getRootContext")); + } + return null; + } + + /** + * 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 + * @throws PollenException which contains the exception as the cause + */ + public static void doCatch(Exception eee, String message) throws PollenException { + doCatch(eee, message, null); + } + + /** + * 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 eee the exception to manage + * @param message the message to add to the new PollenException + * @param transaction the current TopiaContext + * @throws PollenException + */ + public static void doCatch(Exception eee, String message, TopiaContext transaction) throws PollenException { + if (log.isErrorEnabled()) { + log.error(message, 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(message, eee); +// } + } + + /** + * 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("-", ""); + } + +} Property changes on: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContext.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL" Added: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenProperty.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenProperty.java (rev 0) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenProperty.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -0,0 +1,56 @@ + +package org.chorem.pollen.business; + +/** + * PollenProp + * + * Created: 25 févr. 2010 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public enum PollenProperty { + /** version of the application (maven version) **/ + APP_VERSION("version"), + /** url of the server **/ + SERVER_URL("siteUrl"), + /** login for default admin **/ + ADMIN_LOGIN("adminLogin"), + /** password for default admin **/ + ADMIN_PASSWORD("adminPassword"), + /** email for default admin **/ + ADMIN_EMAIL("adminEmail"), + /** email for contact link **/ + CONTACT_EMAIL(ADMIN_EMAIL.getKey()), + /** host for email sending configuration **/ + EMAIL_HOST("email_host"), + /** port for email sending configuration **/ + EMAIL_PORT("email_port"), + /** from for email sending configuration **/ + EMAIL_FROM("email_from"), + /** path for feed directory **/ + FEED_DIR("feedDir"), + /** path for uploaded images directory **/ + IMG_DIR("upImgDir"); + + String key; + + PollenProperty(String key) { + this.key = key; + } + + public String getKey() { + return key; + } + + public String getValue() { + return PollenContext.getProperty(this); + } + + public boolean hasValue() { + return !getValue().equals(""); + } +} Property changes on: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenProperty.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL" 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollConverter.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -22,6 +22,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.business.PollenBusinessException; import org.chorem.pollen.business.dto.ChoiceDTO; import org.chorem.pollen.business.dto.CommentDTO; import org.chorem.pollen.business.dto.PollDTO; @@ -140,7 +141,7 @@ */ @Deprecated public void persistChoices(PollDTO pollDTO, Poll ePoll) - throws TopiaException { + throws TopiaException, PollenBusinessException { // mise à jour ou création des choix ServiceChoice sChoice = new ServiceChoiceImpl(); @@ -181,7 +182,7 @@ * @param ePoll l'entité sondage */ public void persistPreventRules(PollDTO pollDTO, Poll ePoll) - throws TopiaException { + throws TopiaException, PollenBusinessException { // mise à jour ou création des règles de notification ServicePreventRule sPreventRule = new ServicePreventRuleImpl(); 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceAuthImpl.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -18,6 +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.converters.DataUserConverter; import org.chorem.pollen.business.dto.UserDTO; import org.chorem.pollen.business.persistence.PollenModelDAOHelper; @@ -34,7 +36,8 @@ * @version $Id$ */ public class ServiceAuthImpl implements ServiceAuth { - private TopiaContext rootContext = ContextUtil.getInstance().getContext(); + + private TopiaContext rootContext; private UserAccountDAO userDAO = null; private DataUserConverter converter = new DataUserConverter(); @@ -42,6 +45,7 @@ private static final Log log = LogFactory.getLog(ServiceAuthImpl.class); public ServiceAuthImpl() { + rootContext = PollenContext.getRootContext(); } @Override 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoiceImpl.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -23,6 +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.converters.DataChoiceConverter; import org.chorem.pollen.business.dto.ChoiceDTO; import org.chorem.pollen.business.persistence.Choice; @@ -30,7 +32,6 @@ import org.chorem.pollen.business.persistence.PollenModelDAOHelper; import org.chorem.pollen.business.utils.ContextUtil; import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; /** * Gestion des choix d'un sondage. @@ -38,9 +39,9 @@ * @author enema * @version $Id$ */ -public class ServiceChoiceImpl implements - org.chorem.pollen.business.services.ServiceChoice { - private TopiaContext rootContext = ContextUtil.getInstance().getContext(); +public class ServiceChoiceImpl implements ServiceChoice { + + private TopiaContext rootContext; private ChoiceDAO choiceDAO = null; private DataChoiceConverter converter = new DataChoiceConverter(); @@ -48,6 +49,7 @@ private static final Log log = LogFactory.getLog(ServiceChoiceImpl.class); public ServiceChoiceImpl() { + rootContext = PollenContext.getRootContext(); } @Override 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceListImpl.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -22,6 +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.converters.DataPersonListConverter; import org.chorem.pollen.business.converters.DataVotingListConverter; import org.chorem.pollen.business.dto.PersonListDTO; @@ -45,7 +47,8 @@ * @version $Id$ */ public class ServiceListImpl implements ServiceList { - private TopiaContext rootContext = ContextUtil.getInstance().getContext(); + + private TopiaContext rootContext; private VotingListDAO votingListDAO = null; private PersonListDAO personListDAO = null; private DataVotingListConverter votingListConverter = new DataVotingListConverter(); @@ -55,6 +58,7 @@ private static final Log log = LogFactory.getLog(ServiceListImpl.class); public ServiceListImpl() { + rootContext = PollenContext.getRootContext(); } @Override 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePoll.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -59,13 +59,15 @@ * * @param pollId identifiant topia du sondage * @return le sondage + * @deprecated use {@link #findPollByPollId } with the correct id instead */ + @Deprecated public PollDTO findPollById(String pollId); /** * Récupération d'un sondage à partir de son identifiant. * - * @param pollId identifiant du sondage + * @param pollId identifiant du sondage (différent du topiaId) * @return le sondage */ public PollDTO findPollByPollId(String pollId); @@ -122,18 +124,18 @@ public List<PollDTO> selectPolls(Map<String, Object> properties); /** - * Ajout d'un vote à un sondage + * Create a comment for the poll. * - * @param pollId identifiant topia du sondage - * @param voteId l'identiiant topiaId du vote - * @return true si le vote a été ajouté - * @deprecated useless method : used nowhere + * @param poll owner of the comment + * @param comment to create */ - @Deprecated - public boolean addVoteToPoll(String pollId, String voteId); - - public void createComment(PollDTO poll, CommentDTO comment); + /** + * Delete a comment from a poll. + * + * @param poll owner of the comment + * @param commentId id of the comment to delete + */ public void deleteComment(PollDTO poll, String commentId); } \ No newline at end of file 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccountImpl.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -23,6 +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.converters.DataPollAccountConverter; import org.chorem.pollen.business.dto.PollAccountDTO; import org.chorem.pollen.business.persistence.PollAccount; @@ -41,7 +43,8 @@ * @version $Id$ */ public class ServicePollAccountImpl implements ServicePollAccount { - private TopiaContext rootContext = ContextUtil.getInstance().getContext(); + + private TopiaContext rootContext; private PollAccountDAO pollAccountDAO = null; private DataPollAccountConverter converter = new DataPollAccountConverter(); @@ -50,6 +53,7 @@ .getLog(ServicePollAccountImpl.class); public ServicePollAccountImpl() { + rootContext = PollenContext.getRootContext(); } @Override 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -25,6 +25,8 @@ import java.util.Set; 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.ConverterHelper; import org.chorem.pollen.business.converters.DataPollConverter; import org.chorem.pollen.business.converters.DataVotingListConverter; @@ -50,10 +52,10 @@ import org.chorem.pollen.business.persistence.UserAccount; import org.chorem.pollen.business.persistence.UserAccountDAO; import org.chorem.pollen.business.persistence.Vote; -import org.chorem.pollen.business.persistence.VoteDAO; 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.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import static org.nuiton.i18n.I18n._; @@ -66,14 +68,17 @@ * @version $Id$ */ public class ServicePollImpl implements ServicePoll { - private TopiaContext rootContext = ContextUtil.getInstance().getContext(); + + private TopiaContext rootContext; private PollDAO pollDAO = null; private DataPollConverter converter = new DataPollConverter(); /** log. */ private static final Log log = LogFactory.getLog(ServicePollImpl.class); - public ServicePollImpl() { + public ServicePollImpl() { + rootContext = PollenContext.getRootContext(); + ConverterHelper.preparePollConverters(); ConverterHelper.prepareChoiceConverters(); ConverterHelper.prepareVotingListConverters(); @@ -93,7 +98,7 @@ pollDAO = PollenModelDAOHelper.getPollDAO(transaction); // Create with a new pollId generated for links - Poll entity = pollDAO.create(ContextUtil.createPollenUrlId()); + Poll entity = pollDAO.create(PollenContext.createPollenUrlId()); ConverterHelper.convert(pollDTO, entity); // ** Manage the poll creator @@ -131,11 +136,11 @@ result = entity.getTopiaId(); } catch (Exception eee) { - ContextUtil.doCatch(eee, transaction, + PollenContext.doCatch(eee, _("pollen.error.servicePoll.createPoll", - pollDTO.getTitle(), pollDTO.getCreatorId())); + pollDTO.getTitle(), pollDTO.getCreatorId()), transaction); } finally { - ContextUtil.doFinally(transaction); + PollenContext.doFinally(transaction); } return result; } @@ -177,7 +182,7 @@ // Create new account if account properties changed or no user found if (creator == null) { accountProperties.put( - PollAccount.ACCOUNT_ID, ContextUtil.createPollenUrlId()); + PollAccount.ACCOUNT_ID, PollenContext.createPollenUrlId()); creator = accountDAO.create(accountProperties); } return creator; @@ -211,7 +216,7 @@ // Create a new PollAccount if not already exists if (account == null) { - String accountId = ContextUtil.createPollenUrlId(); + String accountId = PollenContext.createPollenUrlId(); account = pollAccountDAO.create(accountId); ConverterHelper.convert(accountDTO, account); } @@ -260,13 +265,13 @@ } return true; - } catch (Exception e) { - ContextUtil.doCatch(e, transaction, + } catch (Exception eee) { + PollenContext.doCatch(eee, _("pollen.error.servicePoll.updatePoll", - pollDTO.getTitle(), pollDTO.getPollId())); + pollDTO.getTitle(), pollDTO.getPollId()), transaction); return false; } finally { - ContextUtil.doFinally(transaction); + PollenContext.doFinally(transaction); } } @@ -288,11 +293,12 @@ } return true; - } catch (Exception e) { - ContextUtil.doCatch(e, transaction); + } catch (Exception eee) { + PollenContext.doCatch(eee, + _("pollen.error.servicePoll.delete", pollId), transaction); return false; } finally { - ContextUtil.doFinally(transaction); + PollenContext.doFinally(transaction); } } @@ -337,7 +343,7 @@ ContextUtil.doCatch(e, transaction); return null; } finally { - ContextUtil.doFinally(transaction); + PollenContext.doFinally(transaction); } } @@ -353,9 +359,6 @@ Poll pollEntity = pollDAO.findByPollId(pollId); if (pollEntity != null) { -// converter.setTransaction(transaction); -// result = converter.createPollDTO(pollEntity); - result = ConverterHelper.convert(pollEntity, new PollDTO()); // Load choices @@ -386,24 +389,7 @@ result.addPreventRule(dto); } -// if (ePoll.getChoice().size() > 0) { -// pollDTO.setChoiceDTOs(choiceConverter.createChoiceDTOs(ePoll -// .getChoice())); -// } -// if (pollEntity.getVote().size() > 0) { -// DataVoteConverter voteConverter = new DataVoteConverter(); -// result.setVoteDTOs(voteConverter.createVoteDTOs(pollEntity.getVote())); -// } -// if (pollEntity.getComment().size() > 0) { -// DataCommentConverter commentConverter = new DataCommentConverter(); -// result.setCommentDTOs(commentConverter.createCommentDTOs(pollEntity -// .getComment())); -// } -// if (pollEntity.getPreventRule().size() > 0) { -// DataPreventRuleConverter preventRuleConverter = new DataPreventRuleConverter(); -// result.setPreventRuleDTOs(preventRuleConverter -// .createPreventRuleDTOs(pollEntity.getPreventRule())); -// } + // TODO Refactor this if (pollEntity.getVotingList().size() > 0) { DataVotingListConverter votingListConverter = new DataVotingListConverter(); result.setVotingListDTOs(votingListConverter @@ -419,11 +405,12 @@ } return result; - } catch (Exception e) { - ContextUtil.doCatch(e, transaction); + } catch (Exception eee) { + PollenContext.doCatch(eee, + _("pollen.error.servicePoll.getPoll", pollId), transaction); return null; } finally { - ContextUtil.doFinally(transaction); + PollenContext.doFinally(transaction); } } @@ -454,7 +441,7 @@ ContextUtil.doCatch(e, transaction); return null; } finally { - ContextUtil.doFinally(transaction); + PollenContext.doFinally(transaction); } } @@ -489,7 +476,7 @@ ContextUtil.doCatch(e, transaction); return null; } finally { - ContextUtil.doFinally(transaction); + PollenContext.doFinally(transaction); } } @@ -527,7 +514,7 @@ ContextUtil.doCatch(e, transaction); return null; } finally { - ContextUtil.doFinally(transaction); + PollenContext.doFinally(transaction); } } @@ -580,7 +567,7 @@ ContextUtil.doCatch(e, transaction); return null; } finally { - ContextUtil.doFinally(transaction); + PollenContext.doFinally(transaction); } } @@ -622,7 +609,7 @@ ContextUtil.doCatch(e, transaction); return null; } finally { - ContextUtil.doFinally(transaction); + PollenContext.doFinally(transaction); } } @@ -656,48 +643,16 @@ } return results; - } catch (Exception e) { - ContextUtil.doCatch(e, transaction); + } catch (Exception eee) { + PollenContext.doCatch(eee, + _("pollen.error.servicePoll.getAllPolls"), transaction); return null; } finally { - ContextUtil.doFinally(transaction); + PollenContext.doFinally(transaction); } } @Override - public boolean addVoteToPoll(String pollId, String voteId) { - TopiaContext transaction = null; - try { - transaction = rootContext.beginTransaction(); - - pollDAO = PollenModelDAOHelper.getPollDAO(transaction); - Poll pollEntity = pollDAO.findByTopiaId(pollId); - VoteDAO voteDAO = PollenModelDAOHelper.getVoteDAO(transaction); - Vote voteEntity = voteDAO.findByTopiaId(voteId); - - if (log.isDebugEnabled()) { - log.debug(pollEntity + " " + voteEntity); - } - - pollEntity.addVote(voteEntity); - pollEntity.update(); - - transaction.commitTransaction(); - - if (log.isDebugEnabled()) { - log.debug("Entity updated: " + pollId); - } - - return true; - } catch (Exception e) { - ContextUtil.doCatch(e, transaction); - return false; - } finally { - ContextUtil.doFinally(transaction); - } - } - - @Override public void createComment(PollDTO poll, CommentDTO comment) { TopiaContext transaction = null; try { @@ -722,10 +677,13 @@ poll.addComment(comment); } catch (Exception eee) { - ContextUtil.doCatch(eee, transaction, - _("pollen.error.servicePoll.addComment")); + PollenContext.doCatch(eee, + _("pollen.error.servicePoll.addComment", + comment.getAuthor(), poll.getTitle(), poll.getId()), + transaction + ); } finally { - ContextUtil.doFinally(transaction); + PollenContext.doFinally(transaction); } } @@ -745,19 +703,16 @@ ePoll.removeComment(eComment); - // test if the comment is deleted, must be because of the composition - // (delete-orphan) - transaction.commitTransaction(); // Update change in dto poll.removeComment(commentId); } catch (Exception eee) { - ContextUtil.doCatch(eee, transaction, - _("pollen.error.servicePoll.addComment")); + PollenContext.doCatch(eee, + _("pollen.error.servicePoll.deleteComment"), transaction); } finally { - ContextUtil.doFinally(transaction); + PollenContext.doFinally(transaction); } } } \ No newline at end of file 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePreventRuleImpl.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -22,6 +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.converters.DataPreventRuleConverter; import org.chorem.pollen.business.dto.PreventRuleDTO; import org.chorem.pollen.business.persistence.PollenModelDAOHelper; @@ -36,9 +38,9 @@ * @author rannou * @version $Id$ */ -public class ServicePreventRuleImpl implements - org.chorem.pollen.business.services.ServicePreventRule { - private TopiaContext rootContext = ContextUtil.getInstance().getContext(); +public class ServicePreventRuleImpl implements ServicePreventRule { + + private TopiaContext rootContext; private PreventRuleDAO preventRuleDAO = null; private DataPreventRuleConverter converter = new DataPreventRuleConverter(); @@ -47,6 +49,7 @@ .getLog(ServicePreventRuleImpl.class); public ServicePreventRuleImpl() { + rootContext = PollenContext.getRootContext(); } @Override 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceResultsImpl.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -23,6 +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.converters.DataResultConverter; import org.chorem.pollen.business.converters.DataVoteCountingConverter; import org.chorem.pollen.business.dto.ResultDTO; @@ -43,6 +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._; /** * Implémentation du service de gestion des résultats. @@ -52,12 +55,14 @@ * @version $Id$ */ public class ServiceResultsImpl implements ServiceResults { - private TopiaContext rootContext = ContextUtil.getInstance().getContext(); + private TopiaContext rootContext; + /** log. */ private static final Log log = LogFactory.getLog(ServiceResultsImpl.class); public ServiceResultsImpl() { + rootContext = PollenContext.getRootContext(); } @Override @@ -267,24 +272,32 @@ public String importPoll(String filePath, UserDTO user) { String topiaId = ""; - // Import du sondage - ServiceExport serviceExport = new ServiceExportImpl(); - PollExportDTO pollExportDTO = serviceExport.executeImport(filePath); + try { - // Transformation du sondage - // FIXME do not call a Service from an other one - ServicePoll servicePoll = new ServicePollImpl(); - org.chorem.pollen.business.dto.PollDTO poll = DataVoteCountingConverter - .createPollDTO(pollExportDTO.getPoll()); + // Import du sondage + ServiceExport serviceExport = new ServiceExportImpl(); + PollExportDTO pollExportDTO = serviceExport.executeImport(filePath); - // Enregistrement du sondage - if (user != null) { - poll.setUserId(user.getId()); - } - topiaId = servicePoll.createPoll(poll); + // Transformation du sondage + // FIXME do not call a Service from an other one + ServicePoll servicePoll; + servicePoll = new ServicePollImpl(); + org.chorem.pollen.business.dto.PollDTO poll = DataVoteCountingConverter + .createPollDTO(pollExportDTO.getPoll()); - if (log.isInfoEnabled()) { - log.info("Poll imported: " + topiaId); + // Enregistrement du sondage + if (user != null) { + poll.setUserId(user.getId()); + } + topiaId = servicePoll.createPoll(poll); + + if (log.isInfoEnabled()) { + log.info("Poll imported: " + topiaId); + } + + } catch (Exception eee) { + PollenContext.doCatch(eee, + _("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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceUserImpl.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -21,13 +21,17 @@ 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.DataUserConverter; import org.chorem.pollen.business.dto.UserDTO; 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.chorem.pollen.business.utils.MD5; import org.nuiton.topia.TopiaContext; +import static org.nuiton.i18n.I18n._; /** * Implémentation du service de gestion des utilisateurs. @@ -37,7 +41,7 @@ * @version $Id$ */ public class ServiceUserImpl implements ServiceUser { - private TopiaContext rootContext = ContextUtil.getInstance().getContext(); + private TopiaContext rootContext; private UserAccountDAO userDAO = null; private DataUserConverter converter = new DataUserConverter(); @@ -45,6 +49,7 @@ private static final Log log = LogFactory.getLog(ServiceUserImpl.class); public ServiceUserImpl() { + rootContext = PollenContext.getRootContext(); } @Override @@ -306,4 +311,35 @@ } return userExists; } + + public void createDefaultAdmin(String login, String password, String email) { + TopiaContext transaction = null; + try { + transaction = rootContext.beginTransaction(); + + UserAccountDAO dao = + PollenModelDAOHelper.getUserAccountDAO(transaction); + + if (dao.findAllByAdministrator(true).size() == 0) { + UserAccount userEntity = dao.create(); + userEntity.setLogin(login); + String encodedPassword = MD5.encode(password); + userEntity.setPassword(encodedPassword); + userEntity.setEmail(email); + userEntity.setAdministrator(true); + + if (log.isInfoEnabled()) { + log.info("Utilisateur " + userEntity.getLogin() + " créé."); + } + + transaction.commitTransaction(); + } + } catch (Exception eee) { + PollenContext.doCatch(eee, + _("pollen.error.serviceUser.createDefaultAdmin", + login, email), transaction); + } finally { + PollenContext.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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -21,6 +21,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.converters.DataPollAccountConverter; import org.chorem.pollen.business.converters.DataVoteConverter; import org.chorem.pollen.business.dto.PollAccountDTO; @@ -40,7 +42,8 @@ * @version $Id$ */ public class ServiceVoteImpl implements ServiceVote { - private TopiaContext rootContext = ContextUtil.getInstance().getContext(); + + private TopiaContext rootContext; private VoteDAO voteDAO = null; private DataVoteConverter converter = new DataVoteConverter(); @@ -48,6 +51,7 @@ private static final Log log = LogFactory.getLog(ServiceVoteImpl.class); public ServiceVoteImpl() { + rootContext = PollenContext.getRootContext(); } @Override 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils/ContextUtil.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -25,10 +25,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.PollenException; 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.services.ServiceUserImpl; import org.hibernate.exception.SQLGrammarException; import org.nuiton.i18n.I18n; import org.nuiton.topia.TopiaContext; @@ -43,8 +46,14 @@ * * @author rannou * @version $Id$ + * @deprecated use class {@link org.chorem.pollen.business.PollenContext} */ +@Deprecated public class ContextUtil { + + /** log. */ + private static final Log log = LogFactory.getLog(ContextUtil.class); + /** * Instance de la classe (patron singleton) */ @@ -58,32 +67,34 @@ /** * Propriétés de la base de données. */ + @Deprecated private Properties conf; - - /** log. */ - private static final Log log = LogFactory.getLog(ContextUtil.class); - /** * Retourne le contexte global. * * @return le contexte global + * @ + * @deprecated use {@link #getRootContext } instead */ - public TopiaContext getContext() { - return context; + @Deprecated + public TopiaContext getContext() { + return PollenContext.getRootContext(); } /** * Retourne la configuration de la base de données. * * @return la configuration + * @ */ - public Properties getConf() { - return conf; + public Properties getConf() { + return PollenContext.getProperties(); } - /** * Construction du contexte global + * @deprecated use directly {@link #getRootContext} method */ + @Deprecated public void buildContext() { if (context == null || context.isClosed()) { try { @@ -102,7 +113,9 @@ /** * Fermeture du contexte global + * @deprecated not necessary, the close will be done in PollenRunner */ + @Deprecated public void closeContext() { if (context != null && !context.isClosed()) { try { @@ -123,7 +136,9 @@ * Retourne l'instance unique de la classe (patron singleton) * * @return L'instance de la classe + * @deprecated ContextUtil methods are static */ + @Deprecated public static ContextUtil getInstance() { if (instance == null) { instance = new ContextUtil(); @@ -137,7 +152,10 @@ * Usefull to use un different war in embedded war context. * * @return properties filename found in JNDI (or a default one) + * @deprecated not usefull anymore, the default properties file is loaded + * even if the application is embedded. */ + @Deprecated protected String getPropertiesFileName() { String filename = null; @@ -173,14 +191,15 @@ */ private ContextUtil() { - String propertiesFilename = getPropertiesFileName(); +// String propertiesFilename = getPropertiesFileName(); + String propertiesFilename = "pollen.properties"; // Chargement du fichier de configuration conf = PropertiesLoader.loadPropertiesFile(propertiesFilename); - conf.setProperty("topia.persistence.classes", PollenModelDAOHelper - .getImplementationClassesAsString()); - conf.setProperty("topia.service.migration.version", PollenModelDAOHelper - .getModelVersion()); + conf.setProperty("topia.persistence.classes", + PollenModelDAOHelper.getImplementationClassesAsString()); + conf.setProperty("topia.service.migration.version", + PollenModelDAOHelper.getModelVersion()); I18n.init(); @@ -210,7 +229,11 @@ * Chargement des valeurs initiales dans la base de données. * * @throws TopiaException + * @deprecated use + * {@link ServiceUserImpl#createDefaultAdmin(String, String, String) } + * method to create the default admin */ + @Deprecated protected void initDB() throws TopiaException { TopiaContext transaction = null; transaction = context.beginTransaction(); @@ -291,6 +314,14 @@ } } + /** + * + * @param e + * @param transaction + * @throws PollenException + * @deprecated must defined a message using {@link PollenContext#doCatch(Exception, TopiaContext, String) } + */ + @Deprecated public static void doCatch(Exception e, TopiaContext transaction) throws PollenException { doCatch(e, transaction, "Échec lors du déroulement de la transaction"); } @@ -302,7 +333,9 @@ * @param message * @param transaction la transaction courante * @throws PollenException + * @deprecated must defined a message using {@link PollenContext#doCatch(Exception, TopiaContext, String) } */ + @Deprecated public static void doCatch(Exception eee, TopiaContext transaction, String message) throws PollenException { if (log.isErrorEnabled()) { log.error(message, eee); @@ -328,7 +361,9 @@ * Méthode exécutée dans tous les cas pour libérer la transaction. * * @param transaction transaction en cours + * @deprecated must defined a message using {@link PollenContext#doFinally(TopiaContext) } */ + @Deprecated public static void doFinally(TopiaContext transaction) { if (transaction != null) { try { @@ -341,6 +376,11 @@ } } + /** + * @return generated string for urlId + * @deprecated must defined a message using {@link PollenContext#createPollenUrlId() } + */ + @Deprecated public static String createPollenUrlId() { return UUID.randomUUID().toString().replaceAll("-", ""); } 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/src/main/resources/i18n/pollen-business-en_GB.properties 2010-02-25 12:07:51 UTC (rev 2884) @@ -1 +1,16 @@ +pollen.error.context.close= +pollen.error.context.getRootContext= +pollen.error.context.parse= +pollen.error.context.rollback= +pollen.error.context.start= +pollen.error.context.stop= +pollen.error.servicePoll.addComment= pollen.error.servicePoll.createPoll= +pollen.error.servicePoll.delete= +pollen.error.servicePoll.deleteComment= +pollen.error.servicePoll.getAllPolls= +pollen.error.servicePoll.getPoll= +pollen.error.servicePoll.updatePoll= +pollen.error.serviceResults.importPoll= +pollen.error.serviceUser.createDefaultAdmin= +pollen.exception.load_configuration= 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/src/main/resources/i18n/pollen-business-fr_FR.properties 2010-02-25 12:07:51 UTC (rev 2884) @@ -1,2 +1,17 @@ +pollen.error.context.close=Erreur lors de la fermeture de la transaction +pollen.error.context.getRootContext=Erreur lors de la r\u00E9cup\u00E9ration du contexte principale +pollen.error.context.parse=Erreur lors du parse du fichier de configuration %1$s +pollen.error.context.rollback=Erreur lors de l'annulation de la transaction +pollen.error.context.start=Erreur lors du d\u00E9marrage de l'application +pollen.error.context.stop=Erreur lors de l'arr\u00EAt de l'application +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.delete= +pollen.error.servicePoll.deleteComment= +pollen.error.servicePoll.deletePoll=Impossible de supprimer le sondage ayant pour identifiant ToPIA \: %1$s +pollen.error.servicePoll.getAllPolls= +pollen.error.servicePoll.getPoll= 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.exception.load_configuration=La configuration n'a pas \u00E9t\u00E9 charg\u00E9e correctement \! Veuillez v\u00E9rifier le d\u00E9marrage de l'application. Copied: trunk/pollen-business/src/main/resources/pollen.properties (from rev 2876, trunk/pollen-ui/src/main/resources/pollen.properties) =================================================================== --- trunk/pollen-business/src/main/resources/pollen.properties (rev 0) +++ trunk/pollen-business/src/main/resources/pollen.properties 2010-02-25 12:07:51 UTC (rev 2884) @@ -0,0 +1,52 @@ +## Configuration de la base de donn\u00C3\u00A9es +#hibernate.hbm2ddl.auto=update +hibernate.show_sql=false +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.connection.username=sa +hibernate.connection.password= +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:file:~/.pollen/pollendb + +#hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect +#hibernate.connection.username=pollen +#hibernate.connection.password=pollen +#hibernate.connection.driver_class=org.postgresql.Driver +#hibernate.connection.url=jdbc:postgresql://intranet/pollen +#hibernate.default_schema=public + +## Configuration de topia-migration +topia.service.migration=org.nuiton.topia.migration.TopiaMigrationServiceImpl +topia.service.migration.callbackhandlers=org.chorem.pollen.business.migration.PollenMigrationCallbackHandler +topia.service.migration.mappingsdir=oldmappings +topia.service.migration.modelnames=pollen + +## Initialisation de la base de donn\u00C3\u00A9es +#choiceType=DATE,IMAGE,TEXT +#pollType=RESTRICTED,FREE,GROUP +#voteCounting=NORMAL,PERCENTAGE,CONDORCET,NUMBER + +## Utilisateur par d\u00C3\u00A9faut +adminLogin=admin +adminPassword=pollen +adminEmail=admin@domain.com + +## R\u00C3\u00A9pertoire des images transf\u00C3\u00A9r\u00C3\u00A9es +upImgDir=.pollen/uploadedImages + +## Taille maximal des images transf\u00C3\u00A9r\u00C3\u00A9es (en octets) +upload.filesize-max=1048576 +upload.requestsize-max=10485760 + +## Configuration de l'envoi d'emails automatiques +email_host=smtp.free.fr +email_port=25 +email_from=bot@pollen.org + +## R\u00C3\u00A9pertoire des flux de syndication (Atom) +feedDir=.pollen/feeds + +## Adresse du site (utilis\u00C3\u00A9e pour les emails de rappel) +siteUrl= + +## Version de l'application +version=${project.version} \ No newline at end of file Property changes on: trunk/pollen-business/src/main/resources/pollen.properties ___________________________________________________________________ Added: svn:mergeinfo + 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestData.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -21,7 +21,7 @@ public void execute() throws Exception { transaction = null; try { - transaction = ContextUtil.getInstance().getContext().beginTransaction(); + transaction = PollenContext.getRootContext().beginTransaction(); test(); Added: trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestManager.java =================================================================== --- trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestManager.java (rev 0) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestManager.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -0,0 +1,52 @@ + +package org.chorem.pollen.business; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Ignore; +import org.nuiton.util.ApplicationConfig; + +/** + * TestManager + * + * Created: 24 févr. 2010 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +@Ignore +public class TestManager { + + private static final Log log = LogFactory.getLog(TestManager.class); + + public static void start(String dbname) throws IOException { + log.info("## START ## : " + dbname); + + InputStream input = TestManager.class. + getResourceAsStream("/pollen.properties"); + + Properties options = new Properties(); + options.load(input); + + ApplicationConfig config = new ApplicationConfig(); + config.setOptions(options); + config.setOption( + "hibernate.connection.url", + "jdbc:h2:file:target/surefire-data/" + dbname + ); + + PollenContext.loadConfiguration(config); + PollenContext.start(); + } + + public static void stop() throws IOException { + PollenContext.stop(); + } + +} Property changes on: trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestManager.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL" 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceAuthImplTest.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -16,6 +16,8 @@ package org.chorem.pollen.business.services; +import org.chorem.pollen.business.PollenBusinessException; +import org.chorem.pollen.business.TestManager; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; @@ -40,16 +42,16 @@ @BeforeClass public static void setUpClass() throws Exception { - ContextUtil.getInstance().buildContext(); + TestManager.start("ServiceAuthImplTest"); } @AfterClass public static void tearDownClass() throws Exception { - ContextUtil.getInstance().getContext().clear(false); + TestManager.stop(); } @Before - public void setUp() { + public void setUp() { instance = new ServiceAuthImpl(); } @@ -61,7 +63,7 @@ * Test of isLoginRight method, of class ServiceAuthImpl. */ @Test - public void testIsLoginRight() { + public void testIsLoginRight() { String login = "login_isLoginRight"; String password = "password_isLoginRight"; boolean result1 = instance.isLoginRight(login, password); @@ -79,7 +81,7 @@ * Test of getUser method, of class ServiceAuthImpl. */ @Test - public void testGetUser() { + public void testGetUser() { String login = "login_getUser"; String password = "password_getUser"; UserDTO result1 = instance.getUser(login, password); 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceChoiceImplTest.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -16,6 +16,7 @@ package org.chorem.pollen.business.services; +import org.chorem.pollen.business.PollenBusinessException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -23,8 +24,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.business.TestManager; import org.chorem.pollen.business.dto.ChoiceDTO; -import org.chorem.pollen.business.services.ServiceChoiceImpl; import org.chorem.pollen.business.utils.ContextUtil; import org.junit.After; import org.junit.AfterClass; @@ -50,16 +51,16 @@ @BeforeClass public static void setUpClass() throws Exception { - ContextUtil.getInstance().buildContext(); + TestManager.start("ServiceChoiceImplTest"); } @AfterClass public static void tearDownClass() throws Exception { - ContextUtil.getInstance().getContext().clear(false); + TestManager.stop(); } @Before - public void setUp() { + public void setUp() { instance = new ServiceChoiceImpl(); } 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceListImplTest.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -16,6 +16,7 @@ package org.chorem.pollen.business.services; +import org.chorem.pollen.business.PollenBusinessException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -23,9 +24,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.business.TestManager; import org.chorem.pollen.business.dto.PersonListDTO; import org.chorem.pollen.business.dto.VotingListDTO; -import org.chorem.pollen.business.services.ServiceListImpl; import org.chorem.pollen.business.utils.ContextUtil; import org.junit.After; import org.junit.AfterClass; @@ -51,16 +52,16 @@ @BeforeClass public static void setUpClass() throws Exception { - ContextUtil.getInstance().buildContext(); + TestManager.start("ServiceListImplTest"); } @AfterClass public static void tearDownClass() throws Exception { - ContextUtil.getInstance().getContext().clear(false); + TestManager.stop(); } @Before - public void setUp() { + public void setUp() { instance = new ServiceListImpl(); } 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -15,7 +15,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. ##%*/ package org.chorem.pollen.business.services; +import java.io.IOException; import java.util.ArrayList; +import org.chorem.pollen.business.PollenBusinessException; import org.chorem.pollen.business.dto.CommentDTO; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -26,6 +28,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.pollen.business.TestData; +import org.chorem.pollen.business.TestManager; import org.chorem.pollen.business.dto.ChoiceDTO; import org.chorem.pollen.business.dto.PollAccountDTO; import org.chorem.pollen.business.dto.PollDTO; @@ -55,7 +58,7 @@ */ public class ServicePollImplTest { - private static ServicePollImpl instance; + private ServicePollImpl instance; /** log. */ private static final Log log = LogFactory.getLog(ServicePollImplTest.class); @@ -64,13 +67,10 @@ @BeforeClass public static void setUpClass() throws Exception { - ContextUtil.getInstance().buildContext(); - instance = new ServicePollImpl(); } @AfterClass public static void tearDownClass() throws Exception { - ContextUtil.getInstance().getContext().clear(false); } @Before @@ -78,7 +78,8 @@ } @After - public void tearDown() { + public void tearDown() throws IOException { + TestManager.stop(); } /** @@ -87,7 +88,9 @@ */ @Test public void testCreatePoll() throws Exception { - log.info("## START ##"); + TestManager.start("testCreatePoll"); + instance = new ServicePollImpl(); + PollDTO dto = new PollDTO(); dto.setBeginChoiceDate(new Date()); dto.setBeginDate(new Date()); @@ -117,42 +120,38 @@ dto.setChoiceDTOs(choices); - String result = instance.createPoll(dto); + final String result = instance.createPoll(dto); if (log.isDebugEnabled()) { log.debug("result: " + result); } Assert.assertNotNull(result); - TopiaContext transaction = null; - try { - transaction = ContextUtil.getInstance().getContext().beginTransaction(); + TestData test = new TestData() { - Poll entity = PollenModelDAOHelper.getPollDAO(transaction).findByTopiaId(result); - Assert.assertNotNull(entity); + @Override + protected void test() throws Exception { + Poll entity = PollenModelDAOHelper.getPollDAO(transaction). + findByTopiaId(result); + Assert.assertNotNull(entity); - Assert.assertEquals(3, entity.getChoice().size()); - Assert.assertNotNull(entity.getCreator()); - Assert.assertEquals("erwan", entity.getCreator().getVotingId()); - Assert.assertNotNull(entity.getCreator().getAccountId()); + Assert.assertEquals(3, entity.getChoice().size()); + Assert.assertNotNull(entity.getCreator()); + Assert.assertEquals("erwan", entity.getCreator().getVotingId()); + Assert.assertNotNull(entity.getCreator().getAccountId()); + } + }; - } catch (Exception eee) { - if (transaction != null) { - transaction.rollbackTransaction(); - } - throw eee; - } finally { - if (transaction != null) { - transaction.closeContext(); - } - } + test.execute(); } /** * Test of updatePoll method, of class ServicePollImpl. */ @Test - public void testUpdatePoll() { - log.info("## START ##"); + public void testUpdatePoll() throws Exception { + TestManager.start("testUpdatePoll"); + instance = new ServicePollImpl(); + String pollId = ""; PollDTO dto = new PollDTO(); dto.setDescription("Test_updatePoll"); @@ -173,8 +172,10 @@ * Test of deletePoll method, of class ServicePollImpl. */ @Test - public void testDeletePoll() { - log.info("## START ##"); + public void testDeletePoll() throws Exception { + TestManager.start("testDeletePoll"); + instance = new ServicePollImpl(); + PollDTO dto = new PollDTO(); dto.setDescription("Test_deletePoll"); dto.setCreatorId("erwan"); @@ -191,8 +192,10 @@ * Test of findPollById method, of class ServicePollImpl. */ @Test - public void testFindPollById() { - log.info("## START ##"); + public void testFindPollById() throws Exception { + TestManager.start("testFindPollById"); + instance = new ServicePollImpl(); + String pollId = ""; PollDTO dto = new PollDTO(); dto.setDescription("Test_findPollById"); @@ -210,8 +213,10 @@ * Test of findPollByPollId method, of class ServicePollImpl. */ @Test - public void testFindPollByPollId() { - log.info("## START ##"); + public void testFindPollByPollId() throws Exception { + TestManager.start("testFindPollByPollId"); + instance = new ServicePollImpl(); + String pollId = ""; PollDTO dto = new PollDTO(); dto.setDescription("Test_findPollByPollId"); @@ -233,8 +238,10 @@ * Test of findPollsByName method, of class ServicePollImpl. */ @Test - public void testFindPollsByName() { - log.info("## START ##"); + public void testFindPollsByName() throws Exception { + TestManager.start("testFindPollsByName"); + instance = new ServicePollImpl(); + PollDTO dto = new PollDTO(); dto.setDescription("Test_findPollsByName"); dto.setCreatorId("erwan"); @@ -252,8 +259,10 @@ * Test of findPollsByUser method, of class ServicePollImpl. */ @Test - public void testFindPollsByUser() { - log.info("## START ##"); + public void testFindPollsByUser() throws Exception { + TestManager.start("testFindPollsByUser"); + instance = new ServicePollImpl(); + // création de l'utilisateur UserDTO user = new UserDTO(); user.setLogin("login_findPollsByUser"); @@ -279,8 +288,10 @@ * Test of findParticipatedPolls method, of class ServicePollImpl. */ @Test - public void testFindParticipatedPolls() { - log.info("## START ##"); + public void testFindParticipatedPolls() throws Exception { + TestManager.start("testFindParticipatedPolls"); + instance = new ServicePollImpl(); + // création de l'utilisateur UserDTO user = new UserDTO(); user.setLogin("login_findParticipatedPolls"); @@ -316,8 +327,10 @@ * Test of findRunningPolls method, of class ServicePollImpl. */ @Test - public void testFindRunningPolls() { - log.info("## START ##"); + public void testFindRunningPolls() throws Exception { + TestManager.start("testFindRunningPolls"); + instance = new ServicePollImpl(); + Date now = new Date(); // sondage en cours sans date de fin @@ -365,8 +378,10 @@ * Test of selectPolls method, of class ServicePollImpl. */ @Test - public void testSelectPolls() { - log.info("## START ##"); + public void testSelectPolls() throws Exception { + TestManager.start("testSelectPolls"); + instance = new ServicePollImpl(); + PollDTO dto = new PollDTO(); dto.setDescription("test selectPolls"); dto.setTitle("selectPolls"); @@ -400,7 +415,8 @@ */ @Test public void testCreateComment() throws Exception { - log.info("## START ##"); + TestManager.start("testCreateComment"); + instance = new ServicePollImpl(); /** PREPARE DATA **/ PollDTO poll = new PollDTO(); @@ -444,7 +460,8 @@ */ @Test public void testDeleteComment() throws Exception { - log.info("## START ##"); + TestManager.start("testDeleteComment"); + instance = new ServicePollImpl(); /** PREPARE DATA **/ PollDTO poll = new PollDTO(); 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePreventRuleImplTest.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -16,6 +16,8 @@ package org.chorem.pollen.business.services; +import java.io.IOException; +import org.chorem.pollen.business.PollenBusinessException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -23,8 +25,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.business.TestManager; import org.chorem.pollen.business.dto.PreventRuleDTO; -import org.chorem.pollen.business.services.ServicePreventRuleImpl; import org.chorem.pollen.business.utils.ContextUtil; import org.junit.After; import org.junit.AfterClass; @@ -51,16 +53,16 @@ @BeforeClass public static void setUpClass() throws Exception { - ContextUtil.getInstance().buildContext(); + TestManager.start("ServicePreventRuleImplTest"); } @AfterClass public static void tearDownClass() throws Exception { - ContextUtil.getInstance().getContext().clear(false); + TestManager.stop(); } @Before - public void setUp() { + public void setUp() throws Exception { instance = new ServicePreventRuleImpl(); } 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceUserImplTest.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -16,6 +16,7 @@ package org.chorem.pollen.business.services; +import org.chorem.pollen.business.PollenBusinessException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -23,6 +24,7 @@ import java.util.List; +import org.chorem.pollen.business.TestManager; import org.chorem.pollen.business.dto.UserDTO; import org.chorem.pollen.business.utils.ContextUtil; import org.junit.After; @@ -42,16 +44,16 @@ @BeforeClass public static void setUpClass() throws Exception { - ContextUtil.getInstance().buildContext(); + TestManager.start("ServiceUserImplTest"); } @AfterClass public static void tearDownClass() throws Exception { - ContextUtil.getInstance().getContext().clear(false); + TestManager.stop(); } @Before - public void setUp() { + public void setUp() { instance = new ServiceUserImpl(); } @@ -134,7 +136,7 @@ * Test of updatePasswordUser method, of class ServiceUserImpl. */ @Test - public void testUpdatePasswordUser() { + public void testUpdatePasswordUser() { UserDTO user = new UserDTO(); user.setLogin("login_UpdatePasswordUser"); user.setId(instance.createUser(user, "password")); 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/base/ContextLink.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -2,6 +2,7 @@ package org.chorem.pollen.ui.base; import java.io.File; +import org.chorem.pollen.business.PollenBusinessException; /** * ContextLink @@ -21,13 +22,15 @@ /** * ContextPath for the link * @return a String contextPath + * @ */ - public String getContextPath(); + 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); + public File getFile(String filename) ; } 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -34,12 +34,13 @@ 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.PollenProperty; import org.chorem.pollen.business.dto.UserDTO; import org.chorem.pollen.business.services.ServiceAuth; import org.chorem.pollen.business.utils.MD5; import org.chorem.pollen.ui.base.ContextLink; import org.chorem.pollen.ui.data.Lien; -import org.chorem.pollen.ui.services.Configuration; /** * Classe du Layout Component Border. @@ -154,12 +155,6 @@ @Inject private Messages messages; - /** - * Service contenant la configuration de l'application. - */ - @Inject - private Configuration conf; - /** Injection des services */ @Inject private ServiceAuth serviceAuth; @@ -225,8 +220,8 @@ * Version de l'application. * @return current application version */ - public String getVersion() { - return conf.getProperty(Configuration.PROP_APP_VERSION); + public String getVersion() { + return PollenProperty.APP_VERSION.getValue(); } public int getCurrentYear() { @@ -234,8 +229,8 @@ return current.get(Calendar.YEAR); } - public String getContactEmail() { - return conf.getProperty(Configuration.PROP_CONTACT_EMAIL); + public String getContactEmail() { + return PollenProperty.CONTACT_EMAIL.getValue(); } /** @@ -249,8 +244,9 @@ * Vérifie que le fichier de flux de syndication existe. * * @return vrai si le fichier existe + * @ */ - public boolean isFeedFileExisting() { + public boolean isFeedFileExisting() { if (feedFilename == null) { return false; } 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/FeedContextLink.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -1,12 +1,10 @@ package org.chorem.pollen.ui.components; -import org.chorem.pollen.ui.base.ContextLink; import java.io.File; -import org.chorem.pollen.ui.base.*; -import org.apache.tapestry5.MarkupWriter; -import org.apache.tapestry5.ioc.annotations.Inject; -import org.chorem.pollen.ui.services.Configuration; +import org.chorem.pollen.business.PollenBusinessException; +import org.chorem.pollen.ui.base.ContextLink; +import org.chorem.pollen.business.PollenProperty; /** * FeedLink @@ -21,16 +19,13 @@ */ public class FeedContextLink implements ContextLink { - @Inject - private Configuration conf; - @Override - public String getContextPath() { - return conf.getProperty(Configuration.FEED_DIR); + public String getContextPath() { + return PollenProperty.FEED_DIR.getValue(); } @Override - public File getFile(String filename) { + public File getFile(String filename) { return new File(getContextPath(), filename + ".xml"); } } Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/FileLink.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/FileLink.java 2010-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/FileLink.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -16,6 +16,7 @@ package org.chorem.pollen.ui.components; +import org.chorem.pollen.business.PollenBusinessException; import org.chorem.pollen.ui.base.ContextLink; import java.io.File; import java.io.FileInputStream; @@ -84,7 +85,7 @@ } /** Affichage du fichier */ - public StreamResponse onCreateLink(final String filename, String type) { + public StreamResponse onCreateLink(final String filename, String type) { // security : src containing .. are filtered, to not access to full system if (StringUtils.isEmpty(filename) || filename.contains("..")) { Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/HeadLink.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/HeadLink.java 2010-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/HeadLink.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -31,6 +31,7 @@ import org.apache.tapestry5.annotations.Parameter; import org.apache.tapestry5.ioc.annotations.Inject; import org.apache.tapestry5.services.Response; +import org.chorem.pollen.business.PollenBusinessException; import org.chorem.pollen.ui.base.ContextLink; import org.slf4j.Logger; @@ -82,7 +83,7 @@ } /** Affichage du fichier */ - public StreamResponse onFileLink(final String href, final String type) { + public StreamResponse onFileLink(final String href, final String type) { // security : src containing .. are filtered, to not access to full system if (StringUtils.isEmpty(href) || href.contains("..")) { 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Image.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -31,6 +31,7 @@ import org.apache.tapestry5.annotations.Parameter; import org.apache.tapestry5.ioc.annotations.Inject; import org.apache.tapestry5.services.Response; +import org.chorem.pollen.business.PollenBusinessException; import org.slf4j.Logger; /** @@ -123,7 +124,7 @@ /** Affichage de l'image */ public StreamResponse onImageLink(final String src, final int width, - final int height, boolean thumb) { + final int height, boolean thumb) { // security : src containing .. are filtered, to not access to full system if (StringUtils.isEmpty(src) || src.contains("..")) { 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ImageContextLink.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -17,10 +17,12 @@ 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.apache.tapestry5.ioc.annotations.Inject; +import org.chorem.pollen.business.PollenBusinessException; +import org.chorem.pollen.business.PollenProperty; import org.chorem.pollen.ui.base.ContextLink; -import org.chorem.pollen.ui.services.Configuration; /** * ImageContextLink @@ -37,9 +39,6 @@ public static final String THUMB_PREFIX = "thumb_"; - @Inject - private Configuration config; - /** * Directory for files getting or saving from this context * (ie. subdirectory where images are uploaded, main directory is defined by contextPath) @@ -54,16 +53,16 @@ private boolean thumb; @Override - public String getContextPath() { - return config.getProperty(Configuration.IMG_DIR); + public String getContextPath() { + return PollenProperty.IMG_DIR.getValue(); } @Override - public File getFile(String filename) { + public File getFile(String filename) { return getFile(filename, thumb); } - public File getFile(String filename, boolean thumb) { + public File getFile(String filename, boolean thumb) { if (thumb) { filename = THUMB_PREFIX + filename; } @@ -73,8 +72,9 @@ /** * Get the directory where are uploaded the images from the context. * @return a File corresponding to the image directory + * @ */ - public File getImageDir() { + public File getImageDir() { File result = null; if (dir != null && !dir.isEmpty()) { result = new File(getContextPath(), dir); 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/UsersAdmin.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -31,6 +31,8 @@ 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.PollenProperty; import org.chorem.pollen.business.business.PreventRuleManager; import org.chorem.pollen.business.dto.UserDTO; import org.chorem.pollen.business.services.ServiceList; @@ -38,7 +40,6 @@ import org.chorem.pollen.business.utils.MD5; import org.chorem.pollen.ui.components.FeedBack; import org.chorem.pollen.ui.data.Lien; -import org.chorem.pollen.ui.services.Configuration; import org.chorem.pollen.ui.utils.PasswordGenerator; /** @@ -109,12 +110,6 @@ @Inject private Messages messages; - /** - * Service contenant la configuration de l'application. - */ - @Inject - private Configuration conf; - /** Injection des services */ @Inject private ServiceUser serviceUser; @@ -133,7 +128,7 @@ /** * Méthode appelée lors de la soumission du formulaire. */ - public Object onSuccessFromUsersForm() { + public Object onSuccessFromUsersForm() { for (UserDTO usr : accounts) { if (serviceUser.findUserById(usr.getId()) != null) { serviceUser.updateUser(usr); @@ -205,11 +200,11 @@ } /** Envoi du mail de notification */ - private void sendMailNotification(UserDTO newUser, String password) { + private void sendMailNotification(UserDTO newUser, String password) { Map<String, String> data = new HashMap<String, String>(); - data.put("host", conf.getProperty("email_host")); - data.put("port", conf.getProperty("email_port")); - data.put("from", conf.getProperty("email_from")); + data.put("host", PollenProperty.EMAIL_HOST.getValue()); + data.put("port", PollenProperty.EMAIL_PORT.getValue()); + data.put("from", PollenProperty.EMAIL_FROM.getValue()); 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/ImageDisplay.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/ImageDisplay.java 2010-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/ImageDisplay.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -29,7 +29,6 @@ import org.chorem.pollen.business.dto.PollDTO; import org.chorem.pollen.ui.components.ImageContextLink; import org.chorem.pollen.ui.data.Lien; -import org.chorem.pollen.ui.services.Configuration; /** * Classe de la page de visualisation d'une image. @@ -52,12 +51,6 @@ @Inject private Messages messages; - /** - * Service contenant la configuration de l'application. - */ - @Inject - private Configuration conf; - /** Sondage */ @Persist private PollDTO poll; 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -48,6 +48,8 @@ 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.PollenBusinessException; +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; @@ -71,7 +73,6 @@ 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.Configuration; import org.chorem.pollen.ui.utils.FeedUtil; import org.chorem.pollen.ui.utils.ImageUtil; import org.chorem.pollen.ui.utils.UnitConverter; @@ -338,13 +339,7 @@ @Inject private Messages messages; - /** - * Service contenant la configuration de l'application. - */ @Inject - private Configuration conf; - - @Inject private Logger logger; /** Injection des services */ @@ -411,7 +406,7 @@ /** * Méthode appelée lorsqu'on souhaite valider la création du sondage. */ - Object onSuccessFromChoicesCreationForm() { + Object onSuccessFromChoicesCreationForm() { if (!addChoiceSelected) { // Préparation et création du sondage @@ -798,7 +793,7 @@ /** * Création du sondage. */ - private void createPoll() { + private void createPoll() { // Création du sondage poll.setId(servicePoll.createPoll(poll)); @@ -821,7 +816,7 @@ } /** Ajout d'une entrée dans le flux de syndication */ - private void addFeedEntry() { + private void addFeedEntry() { PollAccountDTO creator = servicePollAccount.findPollAccountById(poll .getCreatorId()); String voteURL = siteURL + "poll/VoteFor/" + poll.getPollId(); @@ -836,16 +831,16 @@ } /** Envoi du mail de notification */ - private void sendMailNotification() { + 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", conf.getProperty("email_host")); - data.put("port", conf.getProperty("email_port")); - data.put("from", conf.getProperty("email_from")); + 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) { 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollModification.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -38,6 +38,9 @@ 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; import org.chorem.pollen.business.dto.ChoiceDTO; import org.chorem.pollen.business.dto.PollAccountDTO; @@ -54,7 +57,6 @@ import org.chorem.pollen.ui.data.Lien; import org.chorem.pollen.ui.data.PollAction; import org.chorem.pollen.ui.data.PollStep; -import org.chorem.pollen.ui.services.Configuration; /** * Classe de la page de modification d'un sondage. @@ -193,12 +195,6 @@ @Inject private Messages messages; - /** - * Service contenant la configuration de l'application. - */ - @Inject - private Configuration conf; - /** Injection des services */ @Inject private ServicePoll servicePoll; @@ -211,7 +207,7 @@ * Méthode appelée lorsqu'on souhaite accéder à l'étape suivante de la * modification de sondage. */ - Object onSuccessFromPollCreationForm() { + Object onSuccessFromPollCreationForm() { switch (step) { case POLL: step = PollStep.OPTIONS; @@ -530,12 +526,12 @@ } /** Envoi du mail de notification */ - private void sendMailNotification(List<PollAccountDTO> modifiedAccounts) { + private void sendMailNotification(List<PollAccountDTO> modifiedAccounts) { String voteURL = siteURL + "poll/VoteFor/" + poll.getPollId(); Map<String, String> data = new HashMap<String, String>(); - data.put("host", conf.getProperty("email_host")); - data.put("port", conf.getProperty("email_port")); - data.put("from", conf.getProperty("email_from")); + data.put("host", PollenProperty.EMAIL_HOST.getValue()); + data.put("port", PollenProperty.EMAIL_PORT.getValue()); + data.put("from", PollenProperty.EMAIL_FROM.getValue()); // Mails aux votants for (PollAccountDTO account : modifiedAccounts) { 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/Results.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -55,7 +55,6 @@ import org.chorem.pollen.ui.components.FeedBack; import org.chorem.pollen.ui.components.ImageContextLink; import org.chorem.pollen.ui.data.Lien; -import org.chorem.pollen.ui.services.Configuration; import org.chorem.pollen.votecounting.business.NumberMethod; import org.chorem.pollen.votecounting.dto.VoteCountingResultDTO; import org.slf4j.Logger; @@ -162,12 +161,6 @@ private Locale currentLocale; /** - * Service contenant la configuration de l'application. - */ - @Inject - private Configuration conf; - - /** * Logs. */ @Inject 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -47,6 +47,8 @@ import org.apache.tapestry5.ioc.annotations.Inject; 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.PollenProperty; import org.chorem.pollen.business.business.PreventRuleManager; import org.chorem.pollen.business.dto.ChoiceDTO; import org.chorem.pollen.business.dto.CommentDTO; @@ -75,7 +77,6 @@ import org.chorem.pollen.ui.data.PollAction; import org.chorem.pollen.ui.data.uio.DateChoiceUIO; import org.chorem.pollen.ui.data.uio.ImageChoiceUIO; -import org.chorem.pollen.ui.services.Configuration; import org.chorem.pollen.ui.utils.FeedUtil; import org.chorem.pollen.ui.utils.ImageUtil; import org.chorem.pollen.votecounting.business.NumberMethod; @@ -152,12 +153,6 @@ private Messages messages; /** - * Service contenant la configuration de l'application. - */ - @Inject - private Configuration conf; - - /** * Sondage pour lequel l'utilisateur vote */ @Property @@ -295,7 +290,7 @@ /** Méthode appelée après la soumission du vote. */ @Log - Object onSuccessFromVoteForm() { + Object onSuccessFromVoteForm() { if (initPollAccount()) { List<ChoiceDTO> choiceDTOs = new ArrayList<ChoiceDTO>(); if (poll.getVoteCounting() == VoteCountingType.NORMAL) { @@ -563,7 +558,7 @@ /** Ajout d'une entrée dans le flux de syndication */ private void addFeedEntry(PollAction pollAction, String titleStr, - String contentStr) { + String contentStr) { String voteURL = siteURL + "poll/VoteFor/" + poll.getPollId(); File feedFile = getFeedContext().getFile(poll.getPollId()); String title = null; @@ -596,14 +591,14 @@ } /** Envoi du mail de notification */ - private void sendMailNotification() { + private void sendMailNotification() { String voteURL = siteURL + "poll/VoteFor/" + poll.getPollId(); String modifURL = siteURL + "poll/Modification/" + poll.getPollId() + ":" + MD5.encode(poll.getCreatorId()); Map<String, String> data = new HashMap<String, String>(); - data.put("host", conf.getProperty("email_host")); - data.put("port", conf.getProperty("email_port")); - data.put("from", conf.getProperty("email_from")); + 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()); @@ -709,7 +704,7 @@ * @return vrai si le fichier existe */ @Log - public boolean isFeedFileExisting() { + public boolean isFeedFileExisting() { File feedFile = getFeedContext().getFile(poll.getPollId()); if (log.isDebugEnabled()) { log.debug("feed context path : " + getFeedContext().getContextPath()); @@ -815,7 +810,7 @@ } /** Méthode appelée lors de l'ajout d'un choix. */ - Object onSuccessFromChoiceForm() { + Object onSuccessFromChoiceForm() { String choiceName = null; String choiceDesc = null; if (isTextType()) { @@ -876,7 +871,7 @@ } /** Méthode appelée lors de l'ajout d'un commentaire. */ - Object onSuccessFromCommentForm() { + Object onSuccessFromCommentForm() { //newComment.setPollId(poll.getId()); newComment.setPostDate(new Date()); servicePoll.createComment(poll, newComment); 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/Register.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -30,13 +30,14 @@ 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.PollenProperty; import org.chorem.pollen.business.business.PreventRuleManager; import org.chorem.pollen.business.dto.UserDTO; import org.chorem.pollen.business.services.ServiceAuth; import org.chorem.pollen.business.services.ServiceUser; import org.chorem.pollen.business.utils.MD5; import org.chorem.pollen.ui.data.Lien; -import org.chorem.pollen.ui.services.Configuration; /** * Classe de la page d'enregistrement d'un utilisateur. @@ -96,12 +97,6 @@ @Inject private Messages messages; - /** - * Service contenant la configuration de l'application. - */ - @Inject - private Configuration conf; - @Parameter(defaultPrefix = BindingConstants.MESSAGE, value = "title") @Property private String title; @@ -121,7 +116,7 @@ * * @return la page d'accueil */ - Object onSuccessFromRegisterForm() { + Object onSuccessFromRegisterForm() { // L'utilisateur s'est pas trompé en répétant son mot de passe if (!password1.equals(password2)) { @@ -156,11 +151,11 @@ } /** Envoi du mail de notification */ - private void sendMailNotification() { + private void sendMailNotification() { Map<String, String> data = new HashMap<String, String>(); - data.put("host", conf.getProperty("email_host")); - data.put("port", conf.getProperty("email_port")); - data.put("from", conf.getProperty("email_from")); + data.put("host", PollenProperty.EMAIL_HOST.getValue()); + data.put("port", PollenProperty.EMAIL_PORT.getValue()); + data.put("from", PollenProperty.EMAIL_FROM.getValue()); 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -136,17 +136,13 @@ @EagerLoad public RegistryShutdownListener buildPollenShutdown( @InjectService("RegistryShutdownHub") RegistryShutdownHub hub) { - RegistryShutdownListener listener = new PollenShutdown(); + RegistryShutdownListener listener = new PollenManager(); hub.addRegistryShutdownListener(listener); return listener; } - /** - * This is the Configuration service definition. It manage the file - * properties. - */ - public static Configuration buildConfiguration() { - return new ConfigurationImpl(CONFIGURATION_FILE); + public static void contributeRegistryStartup(OrderedConfiguration<Runnable> configuration) { + configuration.add("PollenStartup", new PollenManager()); } /** @@ -155,11 +151,11 @@ */ @EagerLoad public static BackgroundWorker buildBackgroundWorker( - ComponentSource componentSource, Configuration configuration, + ComponentSource componentSource, ServicePoll servicePoll) { Messages messages = componentSource.getPage("LocalMessages") .getComponentResources().getMessages(); - return new BackgroundWorkerImpl(messages, configuration, servicePoll); + return new BackgroundWorkerImpl(messages, servicePoll); } /** 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/BackgroundWorkerImpl.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -26,6 +26,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.tapestry5.ioc.Messages; +import org.chorem.pollen.business.PollenProperty; import org.chorem.pollen.business.business.PreventRuleManager; import org.chorem.pollen.business.dto.PollAccountDTO; import org.chorem.pollen.business.dto.PollDTO; @@ -53,19 +54,15 @@ /** Messages internationalisés **/ private final Messages messages; - /** Service contenant la configuration de l'application. */ - private Configuration conf; - /** Injection du service de gestion de sondages. */ private ServicePoll servicePoll; /** * Constructeur exécuté au lancement de l'application. */ - public BackgroundWorkerImpl(Messages messages, Configuration conf, + public BackgroundWorkerImpl(Messages messages, ServicePoll servicePoll) { this.messages = messages; - this.conf = conf; this.servicePoll = servicePoll; timer = new Timer(); @@ -76,9 +73,8 @@ * Lancement des tâches en arrière-plan. */ public void executeTasks() { - if ("".equals(conf.getProperty("siteUrl"))) { - log - .warn("No property siteUrl. Reminder emails would not contain it"); + if (!PollenProperty.SERVER_URL.hasValue()) { + log.warn("No property siteUrl. Reminder emails would not contain it"); } // Exécution de la tâche toutes les 10 min @@ -129,12 +125,12 @@ * @param poll sondage concerné */ private void sendMailNotification(PollDTO poll, Long timeValue) { - String voteURL = conf.getProperty("siteUrl") + "/poll/VoteFor/" + String voteURL = PollenProperty.SERVER_URL.getValue() + "/poll/VoteFor/" + poll.getPollId(); Map<String, String> data = new HashMap<String, String>(); - data.put("host", conf.getProperty("email_host")); - data.put("port", conf.getProperty("email_port")); - data.put("from", conf.getProperty("email_from")); + data.put("host", PollenProperty.EMAIL_HOST.getValue()); + data.put("port", PollenProperty.EMAIL_PORT.getValue()); + data.put("from", PollenProperty.EMAIL_FROM.getValue()); // Mails aux votants for (PreventRuleDTO rule : poll.getPreventRuleDTOs()) { Deleted: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/Configuration.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/Configuration.java 2010-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/Configuration.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -1,64 +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.services; - -import java.util.Properties; - -/** - * Service de gestion de la configuration de l'application. Ce service lit la - * configuration dans un fichier properties. - * - * @author rannou - * @version $Id$ - */ -public interface Configuration { - - public static final String FEED_DIR = "feedDir"; - public static final String IMG_DIR = "upImgDir"; - public static final String PROP_APP_VERSION = "version"; - public static final String PROP_CONTACT_EMAIL = "adminEmail"; - - /** - * Retourne les propriétés. - * - * @return les propriétés. - */ - public Properties getConf(); - - /** - * Change les propriétés. - * - * @param conf les propriétés. - */ - public void setConf(Properties conf); - - /** - * Retourne une propriété. - * - * @param key la clé de la propriété. - * @return la propriété. - */ - public String getProperty(String key); - - /** - * Change une propriété. - * - * @param key la clé de la propriété. - * @param value la valeur de la propriété. - */ - public void setProperty(String key, String value); -} Deleted: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ConfigurationImpl.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ConfigurationImpl.java 2010-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ConfigurationImpl.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -1,62 +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.services; - -import java.util.Properties; - -import org.chorem.pollen.business.utils.PropertiesLoader; - -/** - * Implémentation du service de gestion de la configuration de l'application. Ce - * service lit la configuration dans un fichier properties. - * - * @author rannou - * @version $Id$ - */ -public class ConfigurationImpl implements Configuration { - - /** Propriétés de l'application. */ - private Properties conf; - - public ConfigurationImpl(Properties conf) { - this.conf = conf; - } - - public ConfigurationImpl(String filename) { - conf = PropertiesLoader.loadPropertiesFile(filename); - } - - @Override - public Properties getConf() { - return conf; - } - - @Override - public void setConf(Properties conf) { - this.conf = conf; - } - - @Override - public String getProperty(String key) { - return conf.getProperty(key); - } - - @Override - public void setProperty(String key, String value) { - conf.setProperty(key, value); - } -} Added: 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 (rev 0) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -0,0 +1,53 @@ +/* *##% 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.services; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.tapestry5.ioc.services.RegistryShutdownListener; +import org.chorem.pollen.business.PollenContext; +import org.nuiton.util.ApplicationConfig; +import org.nuiton.util.ArgumentsParserException; + +/** + * Service de gestion de l'arrêt du serveur. Ce service exécute une action à la + * fermeture du registre Tapestry. + * + * @author rannou + * @version $Id$ + */ +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(); + } + + @Override + public void registryDidShutdown() { + if (log.isInfoEnabled()) { + log.info("Stop Pollen"); + } + PollenContext.stop(); + } + +} Property changes on: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL" Deleted: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenShutdown.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenShutdown.java 2010-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenShutdown.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -1,36 +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.services; - -import org.apache.tapestry5.ioc.services.RegistryShutdownListener; -import org.chorem.pollen.business.utils.ContextUtil; - -/** - * Service de gestion de l'arrêt du serveur. Ce service exécute une action à la - * fermeture du registre Tapestry. - * - * @author rannou - * @version $Id$ - */ -public class PollenShutdown implements RegistryShutdownListener { - - @Override - public void registryDidShutdown() { - ContextUtil.getInstance().closeContext(); - } - -} 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-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PropertiesFileSymbolProvider.java 2010-02-25 12:07:51 UTC (rev 2884) @@ -10,7 +10,7 @@ import org.apache.tapestry5.ioc.services.SymbolProvider; import org.apache.tapestry5.ioc.util.CaseInsensitiveMap; -import org.chorem.pollen.business.utils.PropertiesLoader; +import org.chorem.pollen.business.PollenContext; import org.slf4j.Logger; public class PropertiesFileSymbolProvider implements SymbolProvider { @@ -59,7 +59,7 @@ * @param resourceName the name of the resource to load */ public PropertiesFileSymbolProvider(Logger logger, String resourceName) { - Properties conf = PropertiesLoader.loadPropertiesFile(resourceName); + Properties conf = PollenContext.getProperties(); initializeProperties(conf); } Deleted: trunk/pollen-ui/src/main/resources/pollen.properties =================================================================== --- trunk/pollen-ui/src/main/resources/pollen.properties 2010-02-24 16:19:22 UTC (rev 2883) +++ trunk/pollen-ui/src/main/resources/pollen.properties 2010-02-25 12:07:51 UTC (rev 2884) @@ -1,52 +0,0 @@ -## Configuration de la base de donn\u00C3\u00A9es -#hibernate.hbm2ddl.auto=update -hibernate.show_sql=false -hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.connection.username=sa -hibernate.connection.password= -hibernate.connection.driver_class=org.h2.Driver -hibernate.connection.url=jdbc:h2:file:~/.pollen/pollendb - -#hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect -#hibernate.connection.username=pollen -#hibernate.connection.password=pollen -#hibernate.connection.driver_class=org.postgresql.Driver -#hibernate.connection.url=jdbc:postgresql://intranet/pollen -#hibernate.default_schema=public - -## Configuration de topia-migration -topia.service.migration=org.nuiton.topia.migration.TopiaMigrationServiceImpl -topia.service.migration.callbackhandlers=org.chorem.pollen.business.migration.PollenMigrationCallbackHandler -topia.service.migration.mappingsdir=oldmappings -topia.service.migration.modelnames=pollen - -## Initialisation de la base de donn\u00C3\u00A9es -choiceType=DATE,IMAGE,TEXT -pollType=RESTRICTED,FREE,GROUP -voteCounting=NORMAL,PERCENTAGE,CONDORCET,NUMBER - -## Utilisateur par d\u00C3\u00A9faut -adminLogin=admin -adminPassword=pollen -adminEmail=admin@domain.com - -## R\u00C3\u00A9pertoire des images transf\u00C3\u00A9r\u00C3\u00A9es -upImgDir=.pollen/uploadedImages - -## Taille maximal des images transf\u00C3\u00A9r\u00C3\u00A9es (en octets) -upload.filesize-max=1048576 -upload.requestsize-max=10485760 - -## Configuration de l'envoi d'emails automatiques -email_host=smtp.free.fr -email_port=25 -email_from=bot@pollen.org - -## R\u00C3\u00A9pertoire des flux de syndication (Atom) -feedDir=.pollen/feeds - -## Adresse du site (utilis\u00C3\u00A9e pour les emails de rappel) -siteUrl= - -## Version de l'application -version=${project.version} \ No newline at end of file