Author: fdesbois Date: 2010-03-20 19:42:04 +0100 (Sat, 20 Mar 2010) New Revision: 2953 Log: - Improve context managment : no more static. Use inject in Tapestry - Idem in PollenConverter use as a unique service managed by PollenContext Added: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContextImpl.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContextImplementor.java trunk/pollen-business/src/test/resources/log4j.properties Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContext.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenConverter.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenProperty.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollConverter.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/SendMail.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceAuthImpl.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoiceImpl.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceListImpl.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccountImpl.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePreventRuleImpl.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceResultsImpl.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceUserImpl.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils/ContextUtil.java trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestData.java trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestManager.java trunk/pollen-business/src/test/java/org/chorem/pollen/business/scaling/ScalingVote.java trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/SendMailTest.java trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceAuthImplTest.java trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceChoiceImplTest.java trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceListImplTest.java trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePreventRuleImplTest.java trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceUserImplTest.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/FeedContextLink.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ImageContextLink.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/UsersAdmin.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollModification.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/Register.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/BackgroundWorkerImpl.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PropertiesFileSymbolProvider.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContext.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContext.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContext.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -3,27 +3,13 @@ import java.util.Date; import java.util.Properties; -import java.util.UUID; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.business.persistence.PollenModelDAOHelper; import org.chorem.pollen.business.services.SendMail; -import org.chorem.pollen.business.services.ServiceUserImpl; -import org.nuiton.i18n.I18n; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaContextFactory; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaNotFoundException; import org.nuiton.util.ApplicationConfig; -import org.nuiton.util.ArgumentsParserException; -import static org.nuiton.i18n.I18n._; -import static org.nuiton.i18n.I18n.n_; -import org.nuiton.i18n.init.DefaultI18nInitializer; /** * PollenContext * - * Created: 24 févr. 2010 + * Created: 20 mars 2010 * * @author fdesbois * @version $Revision$ @@ -31,45 +17,9 @@ * Mise a jour: $Date$ * par : $Author$ */ -public class PollenContext { +public interface PollenContext { - /** log. */ - private static final Log log = LogFactory.getLog(PollenContext.class); - - public static final String DEFAULT_FILENAME = "pollen.properties"; - - private static ApplicationConfig configuration; - - private static Date currentDate; - - private static SendMail sendMail; - /** - * Default configuration file will be loaded using - * {@link org.nuiton.util.ApplicationConfig }. - * Then the other configuration initialization will be done in - * {@link #loadConfiguration(ApplicationConfig)} method. - */ - private static void loadDefaultConfiguration() { - try { - if (log.isInfoEnabled()) { - log.info("load default configuration from " + - PollenContext.DEFAULT_FILENAME); - } - ApplicationConfig conf = new ApplicationConfig(); - conf.setConfigFileName(PollenContext.DEFAULT_FILENAME); - conf.parse(new String[]{}); - - conf.printConfig(); - - loadConfiguration(conf); - } catch (ArgumentsParserException eee) { - doCatch(eee, n_("pollen.error.context.parse"), - PollenContext.DEFAULT_FILENAME); - } - } - - /** * Load the application configuration : * <pre> * - Add entities implementation classes for Topia-persistence @@ -78,13 +28,7 @@ * * @param conf ApplicationConfig */ - public static void loadConfiguration(ApplicationConfig conf) { - configuration = conf; - configuration.setOption("topia.persistence.classes", - PollenModelDAOHelper.getImplementationClassesAsString()); - configuration.setOption("topia.service.migration.version", - PollenModelDAOHelper.getModelVersion()); - } + void loadConfiguration(ApplicationConfig conf); /** * Start of the application. The application configuration will be loaded @@ -96,194 +40,51 @@ * - Initialize i18n for error messages * - Create default admin if needed (this will load the topiaRootContext). * </pre> - * + * */ - public static void start() { - try { - if (log.isInfoEnabled()) { - log.info("Initialize i18n bundle"); - } - I18n.setInitializer(new DefaultI18nInitializer("pollen-business")); - I18n.init(); + void start(); - ServiceUserImpl serviceUser = new ServiceUserImpl(); - serviceUser.createDefaultAdmin( - PollenProperty.ADMIN_LOGIN.getValue(), - PollenProperty.ADMIN_PASSWORD.getValue(), - PollenProperty.ADMIN_EMAIL.getValue() - ); - - sendMail = new SendMail(); - sendMail.start(); - - if (log.isInfoEnabled()) { - log.info("pollen is started !"); - } - - } catch (Exception eee) { - doCatch(eee, n_("pollen.error.context.start")); - } - } - /** * Stop the application. Close the Topia rootContext. */ - public static void stop() { - try { - getRootContext().closeContext(); - sendMail.stopExec(); - } catch (Exception eee) { - doCatch(eee, n_("pollen.error.context.stop")); - } - } + void stop(); - public static SendMail getSendMail() { - return sendMail; - } - /** - * Get a property from the configuration. + * Get the SendMail thread to manage emails. * - * @param property PollenProperty - * @return value of this property - * @ + * @return the SendMail running thread */ - public static String getProperty(PollenProperty property) { - return getConfiguration().getOption(property.getKey()); - } + SendMail getSendMail(); /** * Get a property from the configuration. * - * @param key of the property + * @param property PollenProperty * @return value of this property - * @ */ - public static String getProperty(String key) { - return getConfiguration().getOption(key); - } + String getProperty(PollenProperty property); /** - * Get all properties from the configuration + * Test if the property is defined in this context * - * @return the Properties of the application - * @ + * @param property PollenProperty + * @return value of this property */ - public static Properties getProperties() { - return getConfiguration().getOptions(); - } + boolean hasProperty(PollenProperty property); /** - * Get the configuration of the application. + * Get the configuration of the application. Instantiate the default one + * if needed. * * @return the ApplicationConfig - * @ */ - public static ApplicationConfig getConfiguration() { - if (configuration == null) { - loadDefaultConfiguration(); - } - return configuration; - } + ApplicationConfig getConfiguration(); /** - * Get the Topia rootContext. + * Return the current date from context * - * @return the main TopiaContext needed to begin new transaction - * @ + * @return a date */ - public static TopiaContext getRootContext() { - try { - return TopiaContextFactory.getContext(getProperties()); - } catch (TopiaNotFoundException eee) { - doCatch(eee, n_("pollen.error.context.getRootContext")); - } - return null; - } + Date getCurrentDate(); - /** - * Manage exceptions. The {@code exception} will be embedded in a - * PollenException with the {@code message} provided. - * Used in catch statement in services. - * - * @param eee the exception to manage - * @param message the message to add to the new PollenException - * @param args for message - * @throws PollenException which contains the exception as the cause - */ - public static void doCatch(Exception eee, String message, Object... args) throws PollenException { - doCatch(null, eee, message); - } - - /** - * Manage exceptions. The {@code exception} will be embedded in a - * PollenException with the {@code message} provided. Also, the current - * {@code transaction} will be rollback. - * Used in catch statement in services. - * - * @param transaction the current TopiaContext - * @param eee the exception to manage - * @param message the message to add to the new PollenException - * @param args for message - * @throws PollenException - */ - public static void doCatch(TopiaContext transaction, Exception eee, String message, Object... args) throws PollenException { - if (log.isErrorEnabled()) { - log.error(_(message, args), eee); - } - - // rollback de la transaction courante - if (transaction != null) { - try { - transaction.rollbackTransaction(); - } catch (TopiaException ex) { - if (log.isErrorEnabled()) { - log.error(_("pollen.error.context.rollback"), ex); - } - } - } - // PollenBusinessException must be managed (catch and throw) when needed -// if (! (eee instanceof PollenBusinessException)) { - throw new PollenException(eee, message, args); -// } - } - - /** - * Close current TopiaContext. - * Used in finally statement in services. - * - * @param transaction current TopiaContext - */ - public static void doFinally(TopiaContext transaction) { - if (transaction != null) { - try { - transaction.closeContext(); - } catch (TopiaException eee) { - if (log.isErrorEnabled()) { - log.error(_("pollen.error.context.close"), eee); - } - } - } - } - - /** - * Create an id to easily managed polls using urls. - * - * @return a fresh generated String - */ - public static String createPollenUrlId() { - return UUID.randomUUID().toString().replaceAll("-", ""); - } - - public static void setCurrentDate(Date currentDate) { - PollenContext.currentDate = currentDate; - } - - public static Date getCurrentDate() { - if (currentDate == null) { - currentDate = new Date(); - } - return currentDate; - } - } Copied: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContextImpl.java (from rev 2951, trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContext.java) =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContextImpl.java (rev 0) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContextImpl.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -0,0 +1,342 @@ + +package org.chorem.pollen.business; + +import java.util.Date; +import java.util.Properties; +import java.util.UUID; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.business.persistence.PollenModelDAOHelper; +import org.chorem.pollen.business.services.SendMail; +import org.chorem.pollen.business.services.ServiceUserImpl; +import org.nuiton.i18n.I18n; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.TopiaNotFoundException; +import org.nuiton.util.ApplicationConfig; +import org.nuiton.util.ArgumentsParserException; +import static org.nuiton.i18n.I18n._; +import static org.nuiton.i18n.I18n.n_; +import org.nuiton.i18n.init.DefaultI18nInitializer; + +/** + * PollenContext + * + * Created: 24 févr. 2010 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class PollenContextImpl implements PollenContextImplementor { + + /** log. */ + private static final Log log = LogFactory.getLog(PollenContextImpl.class); + + public static final String DEFAULT_FILENAME = "pollen.properties"; + + private ApplicationConfig configuration; + + private Date currentDate; + + private SendMail sendMail; + + /** Conversion service for services **/ + private PollenConverter converter; + + public PollenContextImpl() { + + } + + @Override + public void finalize() { + stop(); + } + + /** + * Default configuration file will be loaded using + * {@link org.nuiton.util.ApplicationConfig }. + * Then the other configuration initialization will be done in + * {@link #loadConfiguration(ApplicationConfig)} method. + */ + private void loadDefaultConfiguration() { + try { + if (log.isInfoEnabled()) { + log.info("load default configuration from " + + PollenContextImpl.DEFAULT_FILENAME); + } + ApplicationConfig conf = new ApplicationConfig(); + conf.setConfigFileName(PollenContextImpl.DEFAULT_FILENAME); + conf.parse(new String[]{}); + + conf.printConfig(); + + loadConfiguration(conf); + } catch (ArgumentsParserException eee) { + doCatch(eee, n_("pollen.error.context.parse"), + PollenContextImpl.DEFAULT_FILENAME); + } + } + + /** + * Load the application configuration : + * <pre> + * - Add entities implementation classes for Topia-persistence + * - Add model version for Topia-migration-service + * </pre> + * + * @param conf ApplicationConfig + */ + @Override + public void loadConfiguration(ApplicationConfig conf) { + configuration = conf; + configuration.setOption("topia.persistence.classes", + PollenModelDAOHelper.getImplementationClassesAsString()); + configuration.setOption("topia.service.migration.version", + PollenModelDAOHelper.getModelVersion()); + } + + /** + * Start of the application. The application configuration will be loaded + * automatically if needed using {@link #loadDefaultConfiguration }. Also + * you can manually load the configuration using + * {@link #loadConfiguration(ApplicationConfig)} + * This start does : + * <pre> + * - Initialize i18n for error messages + * - Create default admin if needed (this will load the topiaRootContext). + * </pre> + * + */ + @Override + public void start() { + try { + if (log.isInfoEnabled()) { + log.info("Start Pollen"); + log.info("Initialize i18n bundle"); + } + I18n.setInitializer(new DefaultI18nInitializer("pollen-business")); + I18n.init(); + + ServiceUserImpl serviceUser = new ServiceUserImpl(this); + serviceUser.createDefaultAdmin( + getProperty(PollenProperty.ADMIN_LOGIN), + getProperty(PollenProperty.ADMIN_PASSWORD), + getProperty(PollenProperty.ADMIN_EMAIL) + ); + + sendMail = new SendMail(this); + sendMail.start(); + + if (log.isInfoEnabled()) { + log.info("pollen is started !"); + } + + } catch (Exception eee) { + doCatch(eee, n_("pollen.error.context.start")); + } + } + + /** + * Stop the application. Close the Topia rootContext. + */ + @Override + public void stop() { + try { + if (log.isDebugEnabled()) { + log.debug("Stop Pollen"); + } + getRootContext().closeContext(); + sendMail.stopExec(); + } catch (Exception eee) { + doCatch(eee, n_("pollen.error.context.stop")); + } + } + + @Override + public SendMail getSendMail() { + return sendMail; + } + + /** + * Get a property from the configuration. + * + * @param property PollenProperty + * @return value of this property + */ + @Override + public String getProperty(PollenProperty property) { + return getConfiguration().getOption(property.getKey()); + } + + /** + * Test if the property is defined in this context + * + * @param property PollenProperty + * @return value of this property + */ + @Override + public boolean hasProperty(PollenProperty property) { + return !getProperty(property).equals(""); + } + + /** + * Get a property from the configuration. + * + * @param key of the property + * @return value of this property + */ + public String getProperty(String key) { + return getConfiguration().getOption(key); + } + + /** + * Get all properties from the configuration + * + * @return the Properties of the application + */ + public Properties getProperties() { + return getConfiguration().getOptions(); + } + + /** + * Get the configuration of the application. + * + * @return the ApplicationConfig + */ + @Override + public ApplicationConfig getConfiguration() { + if (configuration == null) { + loadDefaultConfiguration(); + } + return configuration; + } + + /** + * Get the Topia rootContext. + * + * @return the main TopiaContext needed to begin new transaction + */ + @Override + public TopiaContext getRootContext() { + try { + return TopiaContextFactory.getContext(getProperties()); + } catch (TopiaNotFoundException eee) { + doCatch(eee, n_("pollen.error.context.getRootContext")); + } + return null; + } + + @Override + public PollenConverter getConverter() { + if (converter == null) { + converter = new PollenConverter(); + } + return converter; + } + + /** + * Manage exceptions. The {@code exception} will be embedded in a + * PollenException with the {@code message} provided. + * Used in catch statement in services. + * + * @param eee the exception to manage + * @param message the message to add to the new PollenException + * @param args for message + * @throws PollenException which contains the exception as the cause + */ + @Override + public void doCatch(Exception eee, String message, Object... args) + throws PollenException { + doCatch(null, eee, message); + } + + /** + * Manage exceptions. The {@code exception} will be embedded in a + * PollenException with the {@code message} provided. Also, the current + * {@code transaction} will be rollback. + * Used in catch statement in services. + * + * @param transaction the current TopiaContext + * @param eee the exception to manage + * @param message the message to add to the new PollenException + * @param args for message + * @throws PollenException + */ + @Override + public void doCatch(TopiaContext transaction, Exception eee, String message, + Object... args) throws PollenException { + if (log.isErrorEnabled()) { + log.error(_(message, args), eee); + } + + // rollback de la transaction courante + if (transaction != null) { + try { + transaction.rollbackTransaction(); + } catch (TopiaException ex) { + if (log.isErrorEnabled()) { + log.error(_("pollen.error.context.rollback"), ex); + } + } + } + // PollenBusinessException must be managed (catch and throw) when needed +// if (! (eee instanceof PollenBusinessException)) { + throw new PollenException(eee, message, args); +// } + } + + /** + * Close current TopiaContext. + * Used in finally statement in services. + * + * @param transaction current TopiaContext + */ + @Override + public void doFinally(TopiaContext transaction) { + if (transaction != null) { + try { + transaction.closeContext(); + } catch (TopiaException eee) { + if (log.isErrorEnabled()) { + log.error(_("pollen.error.context.close"), eee); + } + } + } + } + + /** + * Create an id to easily managed polls using urls. + * + * @return a fresh generated String + */ + @Override + public String createPollenUrlId() { + return UUID.randomUUID().toString().replaceAll("-", ""); + } + +// public void setCurrentDate(Date currentDate) { +// PollenContextBusiness.currentDate = currentDate; +// } + + @Override + public Date getCurrentDate() { + if (currentDate == null) { + currentDate = new Date(); + } + return currentDate; + } + + /** + * Set the current date in context. Used for test + * + * @param currentDate to set in the context + */ + public void setCurrentDate(Date currentDate) { + this.currentDate = currentDate; + } + +} Property changes on: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContextImpl.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL" Added: svn:mergeinfo + Added: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContextImplementor.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContextImplementor.java (rev 0) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContextImplementor.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -0,0 +1,78 @@ + +package org.chorem.pollen.business; + +import org.nuiton.topia.TopiaContext; + +/** + * PollenContextImplementor + * + * Created: 20 mars 2010 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public interface PollenContextImplementor extends PollenContext { + + /** + * Topia main context used to open new transaction. + * + * @return the topia root context + */ + TopiaContext getRootContext(); + + /** + * Pollen converter used to convert entities to DTO. + * + * @return the current pollen converter + */ + PollenConverter getConverter(); + + /** + * Manage exceptions. The {@code exception} will be embedded in a + * PollenException with the {@code message} provided. + * Used in catch statement in services. + * + * @param eee the exception to manage + * @param message the message to add to the new PollenException + * @param args for message + * @throws PollenException which contains the exception as the cause + */ + void doCatch(Exception eee, String message, Object... args) + throws PollenException; + + /** + * Manage exceptions. The {@code exception} will be embedded in a + * PollenException with the {@code message} provided. Also, the current + * {@code transaction} will be rollback. + * Used in catch statement in services. + * + * @param transaction the current TopiaContext + * @param eee the exception to manage + * @param message the message to add to the new PollenException + * @param args for message + * @throws PollenException + */ + void doCatch(TopiaContext transaction, Exception eee, String message, + Object... args) throws PollenException; + + /** + * Close current TopiaContext. + * Used in finally statement in services. + * + * @param transaction current TopiaContext + */ + void doFinally(TopiaContext transaction); + + /** + * Create a unique UId for entities which need it (PollAccount, Poll). + * This UId represent the entity in UI module. + * + * @return a new pollenUrlId (UId) + */ + String createPollenUrlId(); + + +} Property changes on: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenContextImplementor.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL" Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenConverter.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenConverter.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenConverter.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -1,6 +1,8 @@ package org.chorem.pollen.business; +import java.util.ArrayList; +import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.pollen.business.dto.ChoiceDTO; @@ -28,7 +30,7 @@ import org.nuiton.util.beans.BinderProvider; /** - * ConverterFactory + * PollenConverter * * Created: 22 févr. 2010 * @@ -42,9 +44,22 @@ private static final Log log = LogFactory.getLog(PollenConverter.class); - private static BinderBuilder builder = new BinderBuilder(); + private BinderBuilder builder; - private static final void prepare(Class<? extends TopiaEntity> entityClass, Class<?> dtoClass, String... properties) { + private List<Class<? extends TopiaEntity>> prepareLoaded; + + public PollenConverter() { + builder = new BinderBuilder(); + prepareLoaded = new ArrayList<Class<? extends TopiaEntity>>(); + } + + private final void prepare(Class<? extends TopiaEntity> entityClass, + Class<?> dtoClass, String... properties) { + + if (prepareLoaded.contains(entityClass)) { + return; + } + // Binder DTO -> Entity builder.createBinderModel(dtoClass, entityClass). addSimpleProperties(properties); @@ -57,9 +72,11 @@ //builder.addProperty(TopiaEntity.TOPIA_ID, "id"); BinderProvider.registerBinder(builder); + + prepareLoaded.add(entityClass); } - public static void preparePollConverters() { + public void preparePollConverters() { String[] properties = new String[] { Poll.TITLE, Poll.DESCRIPTION, @@ -79,7 +96,7 @@ prepare(Poll.class, PollDTO.class, properties); } - public static void prepareChoiceConverters() { + public void prepareChoiceConverters() { String[] properties = new String[] { Choice.NAME, Choice.DESCRIPTION, @@ -89,7 +106,7 @@ prepare(Choice.class, ChoiceDTO.class, properties); } - public static void prepareVotingListConverters() { + public void prepareVotingListConverters() { String[] properties = new String[] { VotingList.NAME, VotingList.WEIGHT @@ -98,7 +115,7 @@ prepare(VotingList.class, VotingListDTO.class, properties); } - public static void preparePollAccountConverters() { + public void preparePollAccountConverters() { String[] properties = new String[] { PollAccount.VOTING_ID, PollAccount.EMAIL @@ -107,7 +124,7 @@ prepare(PollAccount.class, PollAccountDTO.class, properties); } - public static void preparePreventRuleConverters() { + public void preparePreventRuleConverters() { String[] properties = new String[] { PreventRule.ACTIVE, PreventRule.METHOD, @@ -120,7 +137,7 @@ prepare(PreventRule.class, PreventRuleDTO.class, properties); } - public static void prepareVoteConverters() { + public void prepareVoteConverters() { String[] properties = new String[] { Vote.WEIGHT, Vote.COMMENT, @@ -130,7 +147,7 @@ prepare(Vote.class, VoteDTO.class, properties); } - public static void prepareCommentConverters() { + public void prepareCommentConverters() { String[] properties = new String[] { Comment.TEXT, Comment.POST_DATE, @@ -140,13 +157,15 @@ prepare(Comment.class, CommentDTO.class, properties); } - public static Choice convert(ChoiceDTO dto, Choice entity) { - BinderProvider.getBinder(ChoiceDTO.class, Choice.class).copy(dto, entity); + public Choice convert(ChoiceDTO dto, Choice entity) { + BinderProvider.getBinder( + ChoiceDTO.class, Choice.class).copy(dto, entity); return entity; } - public static ChoiceDTO convert(Choice entity, ChoiceDTO dto) { - BinderProvider.getBinder(Choice.class, ChoiceDTO.class).copy(entity, dto); + public ChoiceDTO convert(Choice entity, ChoiceDTO dto) { + BinderProvider.getBinder( + Choice.class, ChoiceDTO.class).copy(entity, dto); dto.setId(entity.getTopiaId()); String name = entity.getName(); dto.setHidden(name != null @@ -155,7 +174,7 @@ return dto; } - public static Poll convert(PollDTO dto, Poll entity) { + public Poll convert(PollDTO dto, Poll entity) { BinderProvider.getBinder(PollDTO.class, Poll.class).copy(dto, entity); entity.setChoiceType(dto.getChoiceType().name()); entity.setPollType(dto.getPollType().name()); @@ -163,7 +182,7 @@ return entity; } - public static PollDTO convert(Poll entity, PollDTO dto) { + public PollDTO convert(Poll entity, PollDTO dto) { BinderProvider.getBinder(Poll.class, PollDTO.class).copy(entity, dto); dto.setId(entity.getTopiaId()); dto.setPollUId(entity.getPollId()); @@ -182,43 +201,49 @@ return dto; } - public static VotingList convert(VotingListDTO dto, VotingList entity) { - BinderProvider.getBinder(VotingListDTO.class, VotingList.class).copy(dto, entity); + public VotingList convert(VotingListDTO dto, VotingList entity) { + BinderProvider.getBinder( + VotingListDTO.class, VotingList.class).copy(dto, entity); return entity; } - public static VotingListDTO convert(VotingList entity, VotingListDTO dto) { - BinderProvider.getBinder(VotingList.class, VotingListDTO.class).copy(entity, dto); + public VotingListDTO convert(VotingList entity, VotingListDTO dto) { + BinderProvider.getBinder( + VotingList.class, VotingListDTO.class).copy(entity, dto); dto.setId(entity.getTopiaId()); return dto; } - public static PollAccount convert(PollAccountDTO dto, PollAccount entity) { - BinderProvider.getBinder(PollAccountDTO.class, PollAccount.class).copy(dto, entity); + public PollAccount convert(PollAccountDTO dto, PollAccount entity) { + BinderProvider.getBinder( + PollAccountDTO.class, PollAccount.class).copy(dto, entity); return entity; } - public static PollAccountDTO convert(PollAccount entity, PollAccountDTO dto) { - BinderProvider.getBinder(PollAccount.class, PollAccountDTO.class).copy(entity, dto); + public PollAccountDTO convert(PollAccount entity, PollAccountDTO dto) { + BinderProvider.getBinder( + PollAccount.class, PollAccountDTO.class).copy(entity, dto); dto.setId(entity.getTopiaId()); dto.setAccountId(entity.getAccountId()); return dto; } - public static PreventRule convert(PreventRuleDTO dto, PreventRule entity) { - BinderProvider.getBinder(PreventRuleDTO.class, PreventRule.class).copy(dto, entity); + public PreventRule convert(PreventRuleDTO dto, PreventRule entity) { + BinderProvider.getBinder( + PreventRuleDTO.class, PreventRule.class).copy(dto, entity); return entity; } - public static PreventRuleDTO convert(PreventRule entity, PreventRuleDTO dto) { - BinderProvider.getBinder(PreventRule.class, PreventRuleDTO.class).copy(entity, dto); + public PreventRuleDTO convert(PreventRule entity, PreventRuleDTO dto) { + BinderProvider.getBinder( + PreventRule.class, PreventRuleDTO.class).copy(entity, dto); dto.setId(entity.getTopiaId()); Poll poll = entity.getPoll(); dto.setPollId(poll.getTopiaId()); return dto; } - public static Vote convert(VoteDTO dto, Vote entity) { + public Vote convert(VoteDTO dto, Vote entity) { BinderProvider.getBinder(VoteDTO.class, Vote.class).copy(dto, entity); return entity; } @@ -234,7 +259,7 @@ * @param dto VoteDTO * @return VoteDTO */ - public static VoteDTO convert(Vote entity, VoteDTO dto) { + public VoteDTO convert(Vote entity, VoteDTO dto) { BinderProvider.getBinder(Vote.class, VoteDTO.class).copy(entity, dto); dto.setId(entity.getTopiaId()); Poll poll = entity.getPoll(); @@ -268,13 +293,15 @@ return dto; } - public static Comment convert(CommentDTO dto, Comment entity) { - BinderProvider.getBinder(CommentDTO.class, Comment.class).copy(dto, entity); + public Comment convert(CommentDTO dto, Comment entity) { + BinderProvider.getBinder( + CommentDTO.class, Comment.class).copy(dto, entity); return entity; } - public static CommentDTO convert(Comment entity, CommentDTO dto) { - BinderProvider.getBinder(Comment.class, CommentDTO.class).copy(entity, dto); + public CommentDTO convert(Comment entity, CommentDTO dto) { + BinderProvider.getBinder( + Comment.class, CommentDTO.class).copy(entity, dto); dto.setId(entity.getTopiaId()); return dto; } Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenProperty.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenProperty.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/PollenProperty.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -50,11 +50,11 @@ return key; } - public String getValue() { - return PollenContext.getProperty(this); - } +// public String getValue() { +// return PollenContexImpl.getProperty(this); +// } - public boolean hasValue() { - return !getValue().equals(""); - } +// public boolean hasValue() { +// return !getValue().equals(""); +// } } Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollConverter.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollConverter.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPollConverter.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -24,6 +24,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.pollen.business.PollenBusinessException; +import org.chorem.pollen.business.PollenContextImplementor; import org.chorem.pollen.business.dto.ChoiceDTO; import org.chorem.pollen.business.dto.CommentDTO; import org.chorem.pollen.business.dto.PollDTO; @@ -61,8 +62,8 @@ * @deprecated use {@link ConverterHelper} */ @Deprecated - public PollDTO createPollDTO(Poll ePoll) { - PollDTO pollDTO = PollenConverter.convert(ePoll, new PollDTO()); + public PollDTO createPollDTO(Poll ePoll, PollenConverter converter) { + PollDTO pollDTO = converter.convert(ePoll, new PollDTO()); // pollDTO.setId(ePoll.getTopiaId()); // pollDTO.setPollId(ePoll.getPollId()); @@ -96,7 +97,7 @@ // } for (Comment comment : ePoll.getComment()) { CommentDTO dto = - PollenConverter.convert(comment, new CommentDTO()); + converter.convert(comment, new CommentDTO()); pollDTO.addComment(dto); } // if (ePoll.getComment().size() > 0) { @@ -119,15 +120,16 @@ * Retourne une liste de dtos sondage à partir d'une liste d'entités. * * @param lPolls liste de entités sondages + * @param converter * @return la liste des dtos sondages * @deprecated use {@link ConverterHelper} */ @Deprecated - public List<PollDTO> createPollDTOs(List<Poll> lPolls) { + public List<PollDTO> createPollDTOs(List<Poll> lPolls, PollenConverter converter) { ArrayList<PollDTO> results = new ArrayList<PollDTO>(); PollDTO dto; for (Poll p : lPolls) { - dto = this.createPollDTO(p); + dto = this.createPollDTO(p, converter); results.add(dto); } return results; @@ -141,11 +143,11 @@ * @deprecated use dao managment instead */ @Deprecated - public void persistChoices(PollDTO pollDTO, Poll ePoll) + public void persistChoices(PollDTO pollDTO, Poll ePoll, PollenContextImplementor context) throws TopiaException, PollenBusinessException { // mise à jour ou création des choix - ServiceChoice sChoice = new ServiceChoiceImpl(); + ServiceChoice sChoice = new ServiceChoiceImpl(context); for (ChoiceDTO choiceDTO : pollDTO.getChoices()) { boolean updated = sChoice.updateChoice(choiceDTO); if (!updated) { @@ -182,11 +184,11 @@ * @param pollDTO le dto sondage * @param ePoll l'entité sondage */ - public void persistPreventRules(PollDTO pollDTO, Poll ePoll) + public void persistPreventRules(PollDTO pollDTO, Poll ePoll, PollenContextImplementor context) throws TopiaException, PollenBusinessException { // mise à jour ou création des règles de notification - ServicePreventRule sPreventRule = new ServicePreventRuleImpl(); + ServicePreventRule sPreventRule = new ServicePreventRuleImpl(context); for (PreventRuleDTO preventRuleDTO : pollDTO.getPreventRuleDTOs()) { boolean updated = sPreventRule.updatePreventRule(preventRuleDTO); if (!updated) { Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/SendMail.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/SendMail.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/SendMail.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -37,6 +37,7 @@ import au.com.bytecode.opencsv.CSVReader; import au.com.bytecode.opencsv.CSVWriter; import org.apache.commons.io.IOUtils; +import org.chorem.pollen.business.PollenContextImplementor; import org.chorem.pollen.business.PollenProperty; /** @@ -63,6 +64,8 @@ /** logger. */ private static final Logger log = LoggerFactory.getLogger(SendMail.class); + protected PollenContextImplementor context; + public static final String EXTENSION_MAIL = ".mail"; public static final String EXTENSION_INDEX = ".index"; @@ -71,11 +74,14 @@ protected volatile boolean stop; - public SendMail() { - + public SendMail(PollenContextImplementor context) { + this.context = context; + if (log.isInfoEnabled()) { + log.info("P:[ SendMail ] init"); + } // get email directory in configuration // create it if not exists - String filename = PollenProperty.EMAIL_DIR.getValue(); + String filename = context.getProperty(PollenProperty.EMAIL_DIR); mailStorageDirectory = new File(filename); if (!mailStorageDirectory.exists()) { if (mailStorageDirectory.mkdirs()) { @@ -95,6 +101,9 @@ */ @Override public void run() { + if (log.isInfoEnabled()) { + log.info("P:[ SendMail ] start"); + } // try to find existing files while (!stop) { @@ -162,10 +171,12 @@ // index contains next index to treat so == is ok if (currentIndex >= index) { - String host = PollenProperty.EMAIL_HOST.getValue(); + String host = + context.getProperty(PollenProperty.EMAIL_HOST); int port = Integer.parseInt( - PollenProperty.EMAIL_PORT.getValue()); - String from = PollenProperty.EMAIL_FROM.getValue(); + context.getProperty(PollenProperty.EMAIL_PORT)); + String from = + context.getProperty(PollenProperty.EMAIL_FROM); MailUtil.sendMail(host, port, from, receiver, subject, body); Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceAuthImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceAuthImpl.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceAuthImpl.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -18,8 +18,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.business.PollenBusinessException; -import org.chorem.pollen.business.PollenContext; +import org.chorem.pollen.business.PollenContextImpl; +import org.chorem.pollen.business.PollenContextImplementor; import org.chorem.pollen.business.converters.DataUserConverter; import org.chorem.pollen.business.dto.UserDTO; import org.chorem.pollen.business.persistence.PollenModelDAOHelper; @@ -37,15 +37,15 @@ */ public class ServiceAuthImpl implements ServiceAuth { - private TopiaContext rootContext; + private PollenContextImplementor context; private UserAccountDAO userDAO = null; private DataUserConverter converter = new DataUserConverter(); /** log. */ private static final Log log = LogFactory.getLog(ServiceAuthImpl.class); - public ServiceAuthImpl() { - rootContext = PollenContext.getRootContext(); + public ServiceAuthImpl(PollenContextImplementor context) { + this.context = context; } @Override @@ -53,7 +53,7 @@ TopiaContext transaction = null; boolean result = false; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction); @@ -84,7 +84,7 @@ TopiaContext transaction = null; UserDTO result = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction); Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoiceImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoiceImpl.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceChoiceImpl.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -16,15 +16,14 @@ package org.chorem.pollen.business.services; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.business.PollenBusinessException; -import org.chorem.pollen.business.PollenContext; +import org.chorem.pollen.business.PollenContextImpl; +import org.chorem.pollen.business.PollenContextImplementor; import org.chorem.pollen.business.converters.DataChoiceConverter; import org.chorem.pollen.business.dto.ChoiceDTO; import org.chorem.pollen.business.persistence.Choice; @@ -41,15 +40,15 @@ */ public class ServiceChoiceImpl implements ServiceChoice { - private TopiaContext rootContext; + private PollenContextImplementor context; private ChoiceDAO choiceDAO = null; private DataChoiceConverter converter = new DataChoiceConverter(); /** log. */ private static final Log log = LogFactory.getLog(ServiceChoiceImpl.class); - public ServiceChoiceImpl() { - rootContext = PollenContext.getRootContext(); + public ServiceChoiceImpl(PollenContextImplementor context) { + this.context = context; } @Override @@ -57,7 +56,7 @@ TopiaContext transaction = null; String topiaId = ""; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction); @@ -114,7 +113,7 @@ TopiaContext transaction = null; boolean resu = false; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction); @@ -145,7 +144,7 @@ public boolean deleteChoice(String choiceId) { TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction); @@ -172,7 +171,7 @@ TopiaContext transaction = null; ChoiceDTO result = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction); @@ -205,7 +204,7 @@ List<ChoiceDTO> results = null; List<Choice> choiceEntities = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction); @@ -240,7 +239,7 @@ List<ChoiceDTO> results = null; List<Choice> choiceEntities = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction); Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceListImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceListImpl.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceListImpl.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -18,12 +18,10 @@ import java.util.ArrayList; import java.util.List; -import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.business.PollenContext; -import org.chorem.pollen.business.PollenConverter; +import org.chorem.pollen.business.PollenContextImplementor; import org.chorem.pollen.business.converters.DataPersonListConverter; import org.chorem.pollen.business.converters.DataVotingListConverter; import org.chorem.pollen.business.dto.PersonListDTO; @@ -51,7 +49,7 @@ */ public class ServiceListImpl implements ServiceList { - private TopiaContext rootContext; + private PollenContextImplementor context; private VotingListDAO votingListDAO = null; private PersonListDAO personListDAO = null; private DataVotingListConverter votingListConverter = new DataVotingListConverter(); @@ -60,11 +58,11 @@ /** log. */ private static final Log log = LogFactory.getLog(ServiceListImpl.class); - public ServiceListImpl() { - rootContext = PollenContext.getRootContext(); + public ServiceListImpl(PollenContextImplementor context) { + this.context = context; - PollenConverter.preparePollAccountConverters(); - PollenConverter.prepareVotingListConverters(); + context.getConverter().preparePollAccountConverters(); + context.getConverter().prepareVotingListConverters(); } @Override @@ -72,7 +70,7 @@ TopiaContext transaction = null; String topiaId = ""; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); votingListDAO = PollenModelDAOHelper.getVotingListDAO(transaction); @@ -84,7 +82,7 @@ // Création des pollAccount de la liste si nécessaire // FIXME do not call a Service from an other one - ServicePollAccount spa = new ServicePollAccountImpl(); + ServicePollAccount spa = new ServicePollAccountImpl(context); //spa.createPollAccounts(votingList.getPollAccountDTOs(), transaction); for (PollAccountDTO account : votingList.getPollAccountDTOs()) { if (spa.findPollAccountById(account.getId()) == null) { @@ -117,7 +115,7 @@ public boolean updateVotingList(VotingListDTO votingList) { TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); votingListDAO = PollenModelDAOHelper.getVotingListDAO(transaction); @@ -147,7 +145,7 @@ TopiaContext transaction = null; String topiaId = ""; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); personListDAO = PollenModelDAOHelper.getPersonListDAO(transaction); PersonList entity = personListDAO.create(); @@ -157,7 +155,7 @@ // Création des comptes de la liste // FIXME do not call a Service from an other one - ServicePollAccount spa = new ServicePollAccountImpl(); + ServicePollAccount spa = new ServicePollAccountImpl(context); for (PollAccountDTO account : personList.getPollAccounts()) { account.setPersonListId(entity.getTopiaId()); } @@ -185,7 +183,7 @@ public void createAccountInPersonList(PersonListDTO personList, PollAccountDTO account) { TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); personListDAO = PollenModelDAOHelper.getPersonListDAO(transaction); @@ -195,9 +193,9 @@ PollenModelDAOHelper.getPollAccountDAO(transaction); // Create new pollAccount - String accountUID = PollenContext.createPollenUrlId(); + String accountUID = context.createPollenUrlId(); PollAccount eAccount = accountDAO.create(accountUID); - PollenConverter.convert(account, eAccount); + context.getConverter().convert(account, eAccount); // Add the account into the list eList.addPollAccount(eAccount); @@ -210,11 +208,11 @@ personList.addPollAccount(account); } catch (Exception eee) { - PollenContext.doCatch(transaction, eee, + context.doCatch(transaction, eee, n_("pollen.error.serviceList.createAccountForPersonList"), personList.getName(), account.getVotingId()); } finally { - PollenContext.doFinally(transaction); + context.doFinally(transaction); } } @@ -222,7 +220,7 @@ public void deleteAccountFromPersonList(PersonListDTO personList, String accountId) { TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); // Find the account PollAccountDAO accountDAO = @@ -245,11 +243,11 @@ personList.removePollAccount(accountId); } catch (Exception eee) { - PollenContext.doCatch(transaction, eee, + context.doCatch(transaction, eee, n_("pollen.error.serviceList.deleteAccountFromPersonList"), accountId, personList.getName(), personList.getId()); } finally { - PollenContext.doFinally(transaction); + context.doFinally(transaction); } } @@ -257,7 +255,7 @@ public boolean deletePersonList(String personListId) { TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); personListDAO = PollenModelDAOHelper.getPersonListDAO(transaction); @@ -285,7 +283,7 @@ List<PersonList> personListEntities = null; UserAccountDAO userDAO = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction); UserAccount user = userDAO.findByTopiaId(userId); @@ -320,7 +318,7 @@ TopiaContext transaction = null; PersonListDTO result = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); personListDAO = PollenModelDAOHelper.getPersonListDAO(transaction); @@ -356,7 +354,7 @@ List<PersonList> personListEntities = null; UserAccountDAO userDAO = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction); UserAccount user = userDAO.findByTopiaId(userId); Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccountImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccountImpl.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollAccountImpl.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -22,10 +22,10 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.business.PollenContext; +import org.chorem.pollen.business.PollenContextImpl; +import org.chorem.pollen.business.PollenContextImplementor; import org.chorem.pollen.business.converters.DataPollAccountConverter; import org.chorem.pollen.business.dto.PollAccountDTO; -import org.chorem.pollen.business.dto.UserDTO; import org.chorem.pollen.business.persistence.PollAccount; import org.chorem.pollen.business.persistence.PollAccountDAO; import org.chorem.pollen.business.persistence.PollenModelDAOHelper; @@ -41,7 +41,7 @@ */ public class ServicePollAccountImpl implements ServicePollAccount { - private TopiaContext rootContext; + private PollenContextImplementor context; private PollAccountDAO pollAccountDAO = null; private DataPollAccountConverter converter = new DataPollAccountConverter(); @@ -49,8 +49,8 @@ private static final Log log = LogFactory .getLog(ServicePollAccountImpl.class); - public ServicePollAccountImpl() { - rootContext = PollenContext.getRootContext(); + public ServicePollAccountImpl(PollenContextImplementor context) { + this.context = context; } @Override @@ -58,7 +58,7 @@ TopiaContext transaction = null; String topiaId; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); pollAccountDAO = PollenModelDAOHelper .getPollAccountDAO(transaction); @@ -123,7 +123,7 @@ public boolean deletePollAccount(String pollAccountId) { TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); pollAccountDAO = PollenModelDAOHelper .getPollAccountDAO(transaction); @@ -150,7 +150,7 @@ TopiaContext transaction = null; boolean resu = false; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); pollAccountDAO = PollenModelDAOHelper .getPollAccountDAO(transaction); @@ -185,7 +185,7 @@ TopiaContext transaction = null; PollAccountDTO result = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); pollAccountDAO = PollenModelDAOHelper .getPollAccountDAO(transaction); @@ -219,7 +219,7 @@ TopiaContext transaction = null; PollAccountDTO result = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); pollAccountDAO = PollenModelDAOHelper .getPollAccountDAO(transaction); Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -25,7 +25,6 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.business.PollenConverter; import org.chorem.pollen.business.converters.DataPollConverter; import org.chorem.pollen.business.converters.DataVotingListConverter; import org.chorem.pollen.business.dto.ChoiceDTO; @@ -52,7 +51,8 @@ import org.chorem.pollen.business.persistence.VotingList; import org.chorem.pollen.business.persistence.VotingListDAO; import org.chorem.pollen.business.utils.ContextUtil; -import org.chorem.pollen.business.PollenContext; +import org.chorem.pollen.business.PollenContextImpl; +import org.chorem.pollen.business.PollenContextImplementor; import org.chorem.pollen.business.persistence.PersonToListDAO; import org.chorem.pollen.common.PollType; import org.chorem.pollen.common.VoteCountingType; @@ -73,22 +73,22 @@ */ public class ServicePollImpl implements ServicePoll { - private TopiaContext rootContext; + private PollenContextImplementor context; private PollDAO pollDAO = null; private DataPollConverter converter = new DataPollConverter(); /** log. */ private static final Log log = LogFactory.getLog(ServicePollImpl.class); - public ServicePollImpl() { - rootContext = PollenContext.getRootContext(); + public ServicePollImpl(PollenContextImplementor context) { + this.context = context; - PollenConverter.preparePollConverters(); - PollenConverter.prepareChoiceConverters(); - PollenConverter.prepareVotingListConverters(); - PollenConverter.preparePollAccountConverters(); - PollenConverter.preparePreventRuleConverters(); - PollenConverter.prepareVoteConverters(); - PollenConverter.prepareCommentConverters(); + context.getConverter().preparePollConverters(); + context.getConverter().prepareChoiceConverters(); + context.getConverter().prepareVotingListConverters(); + context.getConverter().preparePollAccountConverters(); + context.getConverter().preparePreventRuleConverters(); + context.getConverter().prepareVoteConverters(); + context.getConverter().prepareCommentConverters(); } @Override @@ -101,14 +101,14 @@ log.info("P:[ createPoll ] : " + pollDTO); } - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); pollDAO = PollenModelDAOHelper.getPollDAO(transaction); // Create with the pollId from dto String pollId = pollDTO.getPollUId(); Poll entity = pollDAO.create(pollId); - PollenConverter.convert(pollDTO, entity); + context.getConverter().convert(pollDTO, entity); // ** Manage the poll creator PollAccount creator = prepareCreator(transaction, pollDTO); @@ -118,7 +118,7 @@ ChoiceDAO choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction); for (ChoiceDTO choiceDTO : pollDTO.getChoices()) { Choice choice = - PollenConverter.convert(choiceDTO, choiceDAO.create()); + context.getConverter().convert(choiceDTO, choiceDAO.create()); choice.setPoll(entity); } @@ -133,7 +133,7 @@ PollenModelDAOHelper.getPreventRuleDAO(transaction); for (PreventRuleDTO ruleDTO : pollDTO.getPreventRuleDTOs()) { PreventRule rule = - PollenConverter.convert(ruleDTO, ruleDAO.create()); + context.getConverter().convert(ruleDTO, ruleDAO.create()); rule.setPoll(entity); } @@ -148,14 +148,14 @@ // Update dto : need creator and id update // WARN : Update for choices, preventRules and // votingLists is not needed in this case - PollenConverter.convert(entity, pollDTO); + context.getConverter().convert(entity, pollDTO); } catch (Exception eee) { - PollenContext.doCatch(transaction, eee, + context.doCatch(transaction, eee, n_("pollen.error.servicePoll.createPoll"), pollDTO.getTitle(), pollDTO.getCreatorId()); } finally { - PollenContext.doFinally(transaction); + context.doFinally(transaction); } return result; } @@ -172,7 +172,7 @@ * @return the PollAccount used as creator for this poll * @throws TopiaException */ - private static final PollAccount prepareCreator(TopiaContext transaction, + private final PollAccount prepareCreator(TopiaContext transaction, PollDTO poll) throws TopiaException { // Search user from database @@ -196,7 +196,7 @@ // Create new account if account properties changed or no user found if (creator == null) { accountProperties.put( - PollAccount.ACCOUNT_ID, PollenContext.createPollenUrlId()); + PollAccount.ACCOUNT_ID, context.createPollenUrlId()); creator = accountDAO.create(accountProperties); } return creator; @@ -213,12 +213,12 @@ * @return VotingList entity created * @throws TopiaException */ - private static final VotingList createVotingList(TopiaContext transaction, + private final VotingList createVotingList(TopiaContext transaction, VotingListDTO listDTO) throws TopiaException { VotingListDAO dao = PollenModelDAOHelper.getVotingListDAO(transaction); VotingList votingList = - PollenConverter.convert(listDTO, dao.create()); + context.getConverter().convert(listDTO, dao.create()); PollAccountDAO pollAccountDAO = PollenModelDAOHelper.getPollAccountDAO(transaction); @@ -230,9 +230,9 @@ // Create a new PollAccount if not already exists if (account == null) { - String accountId = PollenContext.createPollenUrlId(); + String accountId = context.createPollenUrlId(); account = pollAccountDAO.create(accountId); - PollenConverter.convert(accountDTO, account); + context.getConverter().convert(accountDTO, account); } // Create association between VotingList and PollAccount @@ -254,26 +254,26 @@ log.info("P:[ updatePoll ] : " + pollDTO); } - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); pollDAO = PollenModelDAOHelper.getPollDAO(transaction); Poll pollEntity = pollDAO.findByTopiaId(pollDTO.getId()); - PollenConverter.convert(pollDTO, pollEntity); + context.getConverter().convert(pollDTO, pollEntity); ChoiceDAO choiceDAO = PollenModelDAOHelper.getChoiceDAO(transaction); // ** Update choices (no add, no remove) for (ChoiceDTO choiceDTO : pollDTO.getChoices()) { Choice choice = choiceDAO.findByTopiaId(choiceDTO.getId()); - PollenConverter.convert(choiceDTO, choice); + context.getConverter().convert(choiceDTO, choice); choice.update(); } // Les règles de notifications restent mystérieuses // Y a t-il un besoin de suppression ? - converter.persistPreventRules(pollDTO, pollEntity); + converter.persistPreventRules(pollDTO, pollEntity, context); pollDAO.update(pollEntity); @@ -285,12 +285,12 @@ return true; } catch (Exception eee) { - PollenContext.doCatch(transaction, eee, + context.doCatch(transaction, eee, n_("pollen.error.servicePoll.updatePoll"), pollDTO.getTitle(), pollDTO.getPollUId()); return false; } finally { - PollenContext.doFinally(transaction); + context.doFinally(transaction); } } @@ -299,7 +299,7 @@ PollDTO newPoll = new PollDTO(); newPoll.setVoteCounting(VoteCountingType.NORMAL); newPoll.setPollType(PollType.FREE); - newPoll.setPollUId(PollenContext.createPollenUrlId()); + newPoll.setPollUId(context.createPollenUrlId()); return newPoll; } @@ -318,7 +318,7 @@ log.info("P:[ deletePoll ] : pollId = " + pollId); } - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); pollDAO = PollenModelDAOHelper.getPollDAO(transaction); @@ -333,11 +333,11 @@ return true; } catch (Exception eee) { - PollenContext.doCatch(transaction, eee, + context.doCatch(transaction, eee, n_("pollen.error.servicePoll.deletePoll"), pollId); return false; } finally { - PollenContext.doFinally(transaction); + context.doFinally(transaction); } } @@ -350,19 +350,19 @@ log.info("P:[ getPoll ] : pollUId = " + pollId); } - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); pollDAO = PollenModelDAOHelper.getPollDAO(transaction); Poll pollEntity = pollDAO.findByPollId(pollId); if (pollEntity != null) { - result = PollenConverter.convert(pollEntity, new PollDTO()); + result = context.getConverter().convert(pollEntity, new PollDTO()); // Load choices for (Choice choice : pollEntity.getChoice()) { ChoiceDTO dto = - PollenConverter.convert(choice, new ChoiceDTO()); + context.getConverter().convert(choice, new ChoiceDTO()); result.addChoice(dto); } @@ -387,21 +387,21 @@ // Load votes // for (Vote vote : pollEntity.getVote()) { // VoteDTO dto = -// PollenConverter.convert(vote, new VoteDTO()); +// context.getConverter().convert(vote, new VoteDTO()); // result.addVote(dto); // } // Load comments // for (Comment comment : pollEntity.getComment()) { // CommentDTO dto = -// PollenConverter.convert(comment, new CommentDTO()); +// context.getConverter().convert(comment, new CommentDTO()); // result.addComment(dto); // } // Load preventRules for (PreventRule rule : pollEntity.getPreventRule()) { PreventRuleDTO dto = - PollenConverter.convert(rule, new PreventRuleDTO()); + context.getConverter().convert(rule, new PreventRuleDTO()); result.addPreventRule(dto); } @@ -420,11 +420,11 @@ return result; } catch (Exception eee) { - PollenContext.doCatch(transaction, eee, + context.doCatch(transaction, eee, n_("pollen.error.servicePoll.getPoll"), pollId); return null; } finally { - PollenContext.doFinally(transaction); + context.doFinally(transaction); } } @@ -434,7 +434,7 @@ List<PollDTO> results = null; UserAccountDAO userDAO = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction); UserAccount user = userDAO.findByTopiaId(userId); @@ -445,7 +445,8 @@ } converter.setTransaction(transaction); - results = converter.createPollDTOs(pollEntities); + results = converter.createPollDTOs(pollEntities, + context.getConverter()); transaction.commitTransaction(); @@ -458,7 +459,7 @@ ContextUtil.doCatch(e, transaction); return null; } finally { - PollenContext.doFinally(transaction); + context.doFinally(transaction); } } @@ -468,7 +469,7 @@ List<PollDTO> results = null; UserAccountDAO userDAO = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction); UserAccount user = userDAO.findByTopiaId(userId); @@ -481,7 +482,8 @@ } converter.setTransaction(transaction); - results = converter.createPollDTOs(new ArrayList<Poll>(pollEntities)); + results = converter.createPollDTOs( + new ArrayList<Poll>(pollEntities), context.getConverter()); transaction.commitTransaction(); @@ -494,7 +496,7 @@ ContextUtil.doCatch(e, transaction); return null; } finally { - PollenContext.doFinally(transaction); + context.doFinally(transaction); } } @@ -504,7 +506,7 @@ List<PollDTO> results = null; UserAccountDAO userDAO = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction); UserAccount user = userDAO.findByTopiaId(userId); @@ -528,7 +530,9 @@ } converter.setTransaction(transaction); - results = converter.createPollDTOs(new ArrayList<Poll>(pollEntities)); + results = converter.createPollDTOs( + new ArrayList<Poll>(pollEntities), + context.getConverter()); transaction.commitTransaction(); @@ -541,7 +545,7 @@ ContextUtil.doCatch(e, transaction); return null; } finally { - PollenContext.doFinally(transaction); + context.doFinally(transaction); } } @@ -550,13 +554,13 @@ TopiaContext transaction = null; List<PollDTO> results = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); PollDAO dao = PollenModelDAOHelper.getPollDAO(transaction); String beginDate = Poll.BEGIN_DATE; String endDate = Poll.END_DATE; - Date currentDate = PollenContext.getCurrentDate(); + Date currentDate = context.getCurrentDate(); TopiaQuery query = dao.createQuery(). addNullOr(beginDate, Op.LT, currentDate); @@ -585,7 +589,8 @@ // } converter.setTransaction(transaction); - results = converter.createPollDTOs(entities); + results = converter.createPollDTOs(entities, + context.getConverter()); transaction.commitTransaction(); @@ -598,7 +603,7 @@ ContextUtil.doCatch(e, transaction); return null; } finally { - PollenContext.doFinally(transaction); + context.doFinally(transaction); } } @@ -608,7 +613,7 @@ List<PollDTO> results = null; List<Poll> pollEntities = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); pollDAO = PollenModelDAOHelper.getPollDAO(transaction); @@ -621,7 +626,8 @@ pollEntities = pollDAO.findAllByProperties(properties); } converter.setTransaction(transaction); - results = converter.createPollDTOs(pollEntities); + results = converter.createPollDTOs(pollEntities, + context.getConverter()); transaction.commitTransaction(); @@ -635,7 +641,7 @@ _("pollen.error.servicePoll.getAllPolls")); return null; } finally { - PollenContext.doFinally(transaction); + context.doFinally(transaction); } } @@ -647,12 +653,12 @@ log.info("P:[ createComment ] : pollUId = " + poll.getPollUId() + " _ comment = " + comment); } - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); // Create the new comment CommentDAO dao = PollenModelDAOHelper.getCommentDAO(transaction); Comment eComment = - PollenConverter.convert(comment, dao.create()); + context.getConverter().convert(comment, dao.create()); // Get the poll entity corresponding Poll ePoll = PollenModelDAOHelper.getPollDAO(transaction). @@ -668,11 +674,11 @@ poll.addComment(comment); } catch (Exception eee) { - PollenContext.doCatch(transaction, eee, + context.doCatch(transaction, eee, n_("pollen.error.servicePoll.addComment"), comment.getAuthor(), poll.getTitle(), poll.getId()); } finally { - PollenContext.doFinally(transaction); + context.doFinally(transaction); } } @@ -684,7 +690,7 @@ log.info("P:[ deleteComment ] : pollUId = " + poll.getPollUId() + " _ commentId = " + commentId); } - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); // Find the comment CommentDAO dao = PollenModelDAOHelper.getCommentDAO(transaction); @@ -704,11 +710,11 @@ poll.removeComment(commentId); } catch (Exception eee) { - PollenContext.doCatch(transaction, eee, + context.doCatch(transaction, eee, n_("pollen.error.servicePoll.deleteComment"), commentId, poll.getTitle(), poll.getId()); } finally { - PollenContext.doFinally(transaction); + context.doFinally(transaction); } } @@ -720,7 +726,7 @@ if (log.isInfoEnabled()) { log.info("P:[ getComments ] : pollUId = " + poll.getPollUId()); } - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); CommentDAO dao = PollenModelDAOHelper.getCommentDAO(transaction); TopiaQuery query = dao.createQuery(). @@ -730,16 +736,16 @@ for (Comment entity : entities) { CommentDTO dto = - PollenConverter.convert(entity, new CommentDTO()); + context.getConverter().convert(entity, new CommentDTO()); results.add(dto); } } catch (Exception eee) { - PollenContext.doCatch(transaction, eee, + context.doCatch(transaction, eee, n_("pollen.error.servicePoll.getComments"), poll.getTitle(), poll.getId()); } finally { - PollenContext.doFinally(transaction); + context.doFinally(transaction); } return results; } @@ -749,7 +755,7 @@ TopiaContext transaction = null; PollAccountDTO result = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); if (log.isInfoEnabled()) { log.info("P:[ getRestrictedAccount ] : accountUId = " + accountUId + @@ -777,15 +783,15 @@ if (assoc != null) { PollAccount account = assoc.getPollAccount(); - PollenConverter.convert(account, result); + context.getConverter().convert(account, result); } } catch (Exception eee) { - PollenContext.doCatch(transaction, eee, + context.doCatch(transaction, eee, n_("pollen.error.servicePoll.getRestrictedAccount"), accountUId, poll.getPollUId()); } finally { - PollenContext.doFinally(transaction); + context.doFinally(transaction); } return result; } @@ -811,7 +817,7 @@ log.info("P:[ deleteChoice ] : pollUId = " + poll.getPollUId() + " _ choiceId = " + choiceId); } - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); // Find the comment ChoiceDAO dao = PollenModelDAOHelper.getChoiceDAO(transaction); @@ -831,11 +837,11 @@ poll.removeChoice(choiceId); } catch (Exception eee) { - PollenContext.doCatch(transaction, eee, + context.doCatch(transaction, eee, n_("pollen.error.servicePoll.deleteChoice"), choiceId, poll.getTitle(), poll.getId()); } finally { - PollenContext.doFinally(transaction); + context.doFinally(transaction); } } } Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePreventRuleImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePreventRuleImpl.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePreventRuleImpl.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -22,8 +22,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.business.PollenBusinessException; -import org.chorem.pollen.business.PollenContext; +import org.chorem.pollen.business.PollenContextImpl; +import org.chorem.pollen.business.PollenContextImplementor; import org.chorem.pollen.business.converters.DataPreventRuleConverter; import org.chorem.pollen.business.dto.PreventRuleDTO; import org.chorem.pollen.business.persistence.PollenModelDAOHelper; @@ -40,7 +40,7 @@ */ public class ServicePreventRuleImpl implements ServicePreventRule { - private TopiaContext rootContext; + private PollenContextImplementor context; private PreventRuleDAO preventRuleDAO = null; private DataPreventRuleConverter converter = new DataPreventRuleConverter(); @@ -48,8 +48,8 @@ private static final Log log = LogFactory .getLog(ServicePreventRuleImpl.class); - public ServicePreventRuleImpl() { - rootContext = PollenContext.getRootContext(); + public ServicePreventRuleImpl(PollenContextImplementor context) { + this.context = context; } @Override @@ -57,7 +57,7 @@ TopiaContext transaction = null; String topiaId = ""; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); preventRuleDAO = PollenModelDAOHelper .getPreventRuleDAO(transaction); @@ -117,7 +117,7 @@ TopiaContext transaction = null; boolean resu = false; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); preventRuleDAO = PollenModelDAOHelper .getPreventRuleDAO(transaction); @@ -151,7 +151,7 @@ public boolean deletePreventRule(String preventRuleId) { TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); preventRuleDAO = PollenModelDAOHelper .getPreventRuleDAO(transaction); @@ -180,7 +180,7 @@ TopiaContext transaction = null; PreventRuleDTO result = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); preventRuleDAO = PollenModelDAOHelper .getPreventRuleDAO(transaction); @@ -216,7 +216,7 @@ List<PreventRuleDTO> results = null; List<PreventRule> preventRuleEntities = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); preventRuleDAO = PollenModelDAOHelper .getPreventRuleDAO(transaction); Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceResultsImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceResultsImpl.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceResultsImpl.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -23,8 +23,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.business.PollenBusinessException; -import org.chorem.pollen.business.PollenContext; +import org.chorem.pollen.business.PollenContextImpl; +import org.chorem.pollen.business.PollenContextImplementor; import org.chorem.pollen.business.converters.DataResultConverter; import org.chorem.pollen.business.converters.DataVoteCountingConverter; import org.chorem.pollen.business.dto.ResultDTO; @@ -56,13 +56,13 @@ */ public class ServiceResultsImpl implements ServiceResults { - private TopiaContext rootContext; + private PollenContextImplementor context; /** log. */ private static final Log log = LogFactory.getLog(ServiceResultsImpl.class); - public ServiceResultsImpl() { - rootContext = PollenContext.getRootContext(); + public ServiceResultsImpl(PollenContextImplementor context) { + this.context = context; } @Override @@ -99,7 +99,7 @@ VoteCountingType voteCounting, boolean byGroup, boolean groupOnly) { TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); PollDAO daoPoll = PollenModelDAOHelper.getPollDAO(transaction); Poll ePoll = daoPoll.findByPollId(pollId); @@ -212,7 +212,7 @@ public String exportPoll(String pollId) { TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); // Recherche du sondage PollDAO daoPoll = PollenModelDAOHelper.getPollDAO(transaction); @@ -281,7 +281,7 @@ // Transformation du sondage // FIXME do not call a Service from an other one ServicePoll servicePoll; - servicePoll = new ServicePollImpl(); + servicePoll = new ServicePollImpl(context); org.chorem.pollen.business.dto.PollDTO poll = DataVoteCountingConverter .createPollDTO(pollExportDTO.getPoll()); @@ -296,7 +296,7 @@ } } catch (Exception eee) { - PollenContext.doCatch(eee, + context.doCatch(eee, n_("pollen.error.serviceResults.importPoll")); } Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceUserImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceUserImpl.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceUserImpl.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -21,8 +21,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.business.PollenBusinessException; -import org.chorem.pollen.business.PollenContext; +import org.chorem.pollen.business.PollenContextImplementor; import org.chorem.pollen.business.converters.DataUserConverter; import org.chorem.pollen.business.dto.UserDTO; import org.chorem.pollen.business.persistence.PollenModelDAOHelper; @@ -31,6 +30,7 @@ import org.chorem.pollen.business.utils.ContextUtil; import org.chorem.pollen.business.utils.MD5; import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.framework.TopiaQuery; import static org.nuiton.i18n.I18n.n_; /** @@ -41,15 +41,15 @@ * @version $Id$ */ public class ServiceUserImpl implements ServiceUser { - private TopiaContext rootContext; + private PollenContextImplementor context; private UserAccountDAO userDAO = null; private DataUserConverter converter = new DataUserConverter(); /** log. */ private static final Log log = LogFactory.getLog(ServiceUserImpl.class); - public ServiceUserImpl() { - rootContext = PollenContext.getRootContext(); + public ServiceUserImpl(PollenContextImplementor context) { + this.context = context; } @Override @@ -57,7 +57,7 @@ TopiaContext transaction = null; String topiaId = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction); if (userDAO.findByLogin(user.getLogin()) != null @@ -89,7 +89,7 @@ public boolean deleteUser(String login) { TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction); @@ -115,7 +115,7 @@ public boolean deleteUser(UserDTO user) { TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction); @@ -141,7 +141,7 @@ TopiaContext transaction = null; UserDTO result = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction); @@ -174,7 +174,7 @@ List<UserDTO> results = null; List<UserAccount> userEntities = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction); @@ -210,7 +210,7 @@ public boolean updateUser(UserDTO user) { TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction); @@ -239,7 +239,7 @@ public boolean updatePasswordUser(UserDTO user, String newPassword) { TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction); @@ -267,7 +267,7 @@ TopiaContext transaction = null; boolean userExists = true; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction); if (userDAO.findByLogin(login) == null) { @@ -292,7 +292,7 @@ TopiaContext transaction = null; boolean userExists = true; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); userDAO = PollenModelDAOHelper.getUserAccountDAO(transaction); if (userDAO.findByEmail(email) == null) { @@ -315,12 +315,16 @@ public void createDefaultAdmin(String login, String password, String email) { TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); + UserAccountDAO dao = PollenModelDAOHelper.getUserAccountDAO(transaction); - if (dao.findAllByAdministrator(true).size() == 0) { + int nbAdmin = dao.createQuery(). + add(UserAccount.ADMINISTRATOR, Boolean.TRUE).executeCount(); + + if (nbAdmin == 0) { UserAccount userEntity = dao.create(); userEntity.setLogin(login); String encodedPassword = MD5.encode(password); @@ -335,11 +339,11 @@ transaction.commitTransaction(); } } catch (Exception eee) { - PollenContext.doCatch(transaction, eee, + context.doCatch(transaction, eee, n_("pollen.error.serviceUser.createDefaultAdmin"), login, email); } finally { - PollenContext.doFinally(transaction); + context.doFinally(transaction); } } } \ No newline at end of file Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServiceVoteImpl.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -22,8 +22,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.business.PollenContext; -import org.chorem.pollen.business.PollenConverter; +import org.chorem.pollen.business.PollenContextImplementor; import org.chorem.pollen.business.converters.DataPollAccountConverter; import org.chorem.pollen.business.converters.DataVoteConverter; import org.chorem.pollen.business.dto.PollAccountDTO; @@ -50,16 +49,16 @@ */ public class ServiceVoteImpl implements ServiceVote { - private TopiaContext rootContext; + private PollenContextImplementor context; private DataVoteConverter converter = new DataVoteConverter(); /** log. */ private static final Log log = LogFactory.getLog(ServiceVoteImpl.class); - public ServiceVoteImpl() { - rootContext = PollenContext.getRootContext(); + public ServiceVoteImpl(PollenContextImplementor context) { + this.context = context; - PollenConverter.prepareVoteConverters(); + context.getConverter().prepareVoteConverters(); } @Override @@ -67,7 +66,7 @@ TopiaContext transaction = null; String topiaId = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); // création du compte associé au vote s'il n'existe pas // sinon mise à jour du compte @@ -84,7 +83,7 @@ if (pollAccountEntity == null) { log.debug("Nouveau compte associé au vote"); pollAccountEntity = pollAccountDAO.create( - PollenContext.createPollenUrlId()); + context.createPollenUrlId()); // EVO #108 : Migration to ToPIA 2.3, the entity must be // commited because an other findBy is called in the // converter (wtf ?! :/). This behavior doesn't work @@ -144,7 +143,7 @@ public boolean updateVote(VoteDTO voteDTO) { TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); VoteDAO voteDAO = PollenModelDAOHelper.getVoteDAO(transaction); Vote voteEntity = voteDAO.findByTopiaId(voteDTO.getId()); @@ -171,7 +170,7 @@ public boolean deleteVote(String voteId) { TopiaContext transaction = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); VoteDAO voteDAO = PollenModelDAOHelper.getVoteDAO(transaction); Vote voteEntity = voteDAO.findByTopiaId(voteId); @@ -213,7 +212,7 @@ // FIXME-FD20100309 : change dto to suppress link from poll to vote // It's not necessary to have votes when retrieving the poll, this // method do this job only when it's needed - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); // List<Vote> votes = transaction.find( // "FROM " + Vote.class.getName() + @@ -236,18 +235,18 @@ log.debug("Nb votes found : " + eVotes.size()); } for (Vote eVote : eVotes) { - VoteDTO vote = PollenConverter.convert(eVote, new VoteDTO()); + VoteDTO vote = context.getConverter().convert(eVote, new VoteDTO()); results.add(vote); } // converter.setTransaction(transaction); // results = converter.createVoteDTOs(votes); } catch (Exception eee) { - PollenContext.doCatch(transaction, eee, + context.doCatch(transaction, eee, n_("pollen.error.serviceVote.getVotesByPoll"), poll.getPollUId()); } finally { - PollenContext.doFinally(transaction); + context.doFinally(transaction); } return results; } @@ -281,7 +280,7 @@ " _ pollUId = " + poll.getPollUId()); } - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); // List<Long> tmp = transaction.find( // "SELECT COUNT(*)" + @@ -304,11 +303,11 @@ result = count > 0; } catch (Exception eee) { - PollenContext.doCatch(transaction, eee, + context.doCatch(transaction, eee, n_("pollen.error.serviceVote.hasAlreadyVoted"), votingId, poll.getPollUId()); } finally { - PollenContext.doFinally(transaction); + context.doFinally(transaction); } return result; } @@ -319,7 +318,7 @@ List<VoteDTO> results = null; List<Vote> voteEntities = null; try { - transaction = rootContext.beginTransaction(); + transaction = context.getRootContext().beginTransaction(); VoteDAO voteDAO = PollenModelDAOHelper.getVoteDAO(transaction); Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils/ContextUtil.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils/ContextUtil.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/utils/ContextUtil.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -26,7 +26,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.pollen.business.PollenBusinessException; -import org.chorem.pollen.business.PollenContext; +import org.chorem.pollen.business.PollenContextImpl; import org.chorem.pollen.business.PollenException; import org.chorem.pollen.business.persistence.PollenModelDAOHelper; import org.chorem.pollen.business.persistence.UserAccount; @@ -76,21 +76,21 @@ * @ * @deprecated use {@link #getRootContext } instead */ - @Deprecated - public TopiaContext getContext() { - return PollenContext.getRootContext(); - } - +// @Deprecated +// public TopiaContext getContext() { +// return PollenContexImpl.getRootContext(); +// } +// +// /** +// * Retourne la configuration de la base de données. +// * +// * @return la configuration +// * @ +// */ +// public Properties getConf() { +// return PollenContexImpl.getProperties(); +// } /** - * Retourne la configuration de la base de données. - * - * @return la configuration - * @ - */ - public Properties getConf() { - return PollenContext.getProperties(); - } - /** * Construction du contexte global * @deprecated use directly {@link #getRootContext} method */ Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestData.java =================================================================== --- trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestData.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestData.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -21,7 +21,8 @@ public void execute() throws Exception { transaction = null; try { - transaction = PollenContext.getRootContext().beginTransaction(); + transaction = TestManager.getContext(). + getRootContext().beginTransaction(); test(); Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestManager.java =================================================================== --- trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestManager.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/TestManager.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -9,6 +9,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Ignore; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; import org.nuiton.util.ApplicationConfig; /** @@ -27,6 +29,8 @@ private static final Log log = LogFactory.getLog(TestManager.class); + private static PollenContextImplementor context; + public static void start(String dbname) throws IOException { log.info("## START ## : " + dbname); @@ -43,16 +47,27 @@ "jdbc:h2:file:target/surefire-data/" + dbname ); - PollenContext.loadConfiguration(config); - PollenContext.start(); + getContext().loadConfiguration(config); + getContext().start(); // Set currentDate to 23/02/2010 for tests Calendar calendar = new GregorianCalendar(2010, 1, 23, 0, 0, 0); - PollenContext.setCurrentDate(calendar.getTime()); + ((PollenContextImpl)getContext()).setCurrentDate(calendar.getTime()); } public static void stop() throws IOException { - PollenContext.stop(); + getContext().stop(); } + public static PollenContextImplementor getContext() { + if (context == null) { + context = new PollenContextImpl(); + } + return context; + } + + public static TopiaContext beginTransaction() throws TopiaException { + return getContext().getRootContext().beginTransaction(); + } + } Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/scaling/ScalingVote.java =================================================================== --- trunk/pollen-business/src/test/java/org/chorem/pollen/business/scaling/ScalingVote.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/scaling/ScalingVote.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -16,13 +16,14 @@ package org.chorem.pollen.business.scaling; -import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Properties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.business.TestManager; import org.chorem.pollen.business.persistence.Choice; import org.chorem.pollen.business.persistence.PersonToList; import org.chorem.pollen.business.persistence.Poll; @@ -35,7 +36,6 @@ import org.chorem.pollen.business.persistence.VoteToChoice; import org.chorem.pollen.business.persistence.VoteToChoiceDAO; import org.chorem.pollen.business.persistence.VotingList; -import org.chorem.pollen.business.utils.ContextUtil; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaContextFactory; import org.nuiton.topia.TopiaException; @@ -55,8 +55,8 @@ private static final Log log = LogFactory.getLog(ScalingVote.class); /** Adresse de la base de données (surchage l'adresse dans src/test/resources) */ - public static final String DB_URL = "jdbc:h2:" + System.getProperty("user.home") + - File.separator + ".pollen" + File.separator + "pollendb"; +// public static final String DB_URL = "jdbc:h2:" + System.getProperty("user.home") + +// File.separator + ".pollen" + File.separator + "pollendb"; /** La config en cours. */ protected static Properties config; @@ -66,14 +66,16 @@ * * @param args */ - public static void main(String args[]) { - System.out.println("Using database at : " + DB_URL); + public static void main(String args[]) throws IOException { +// System.out.println("Using database at : " + DB_URL); - ContextUtil contextUtil = ContextUtil.getInstance(); - config = contextUtil.getConf(); - config.setProperty("hibernate.connection.url", DB_URL); - config.remove("hibernate.hbm2ddl.auto"); +// ContextUtil contextUtil = ContextUtil.getInstance(); +// config = contextUtil.getConf(); + TestManager.start("ScalingVote"); +// config.setProperty("hibernate.connection.url", DB_URL); +// config.remove("hibernate.hbm2ddl.auto"); + try { new ScalingVote().doInsertFixedNumber(); } @@ -92,9 +94,8 @@ * * @throws TopiaException */ - public void doInsertWithVotingList() throws TopiaException { - TopiaContext rootContext = TopiaContextFactory.getContext(config); - TopiaContext context = rootContext.beginTransaction(); + public void doInsertWithVotingList() throws TopiaException, IOException { + TopiaContext context = TestManager.beginTransaction(); PollDAO pollDAO = PollenModelDAOHelper.getPollDAO(context); VoteDAO voteDAO = PollenModelDAOHelper.getVoteDAO(context); @@ -151,7 +152,7 @@ context.commitTransaction(); context.closeContext(); - rootContext.closeContext(); + TestManager.stop(); } /** @@ -162,9 +163,8 @@ * * @throws TopiaException */ - public void doInsertFixedNumber() throws TopiaException { - TopiaContext rootContext = TopiaContextFactory.getContext(config); - TopiaContext context = rootContext.beginTransaction(); + public void doInsertFixedNumber() throws TopiaException, IOException { + TopiaContext context = TestManager.beginTransaction(); PollDAO pollDAO = PollenModelDAOHelper.getPollDAO(context); VoteDAO voteDAO = PollenModelDAOHelper.getVoteDAO(context); @@ -218,6 +218,6 @@ context.commitTransaction(); context.closeContext(); - rootContext.closeContext(); + TestManager.stop(); } } Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/SendMailTest.java =================================================================== --- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/SendMailTest.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/SendMailTest.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -24,7 +24,7 @@ import java.util.List; import java.util.Map; -import org.chorem.pollen.business.PollenContext; +import org.chorem.pollen.business.PollenContextImpl; import org.chorem.pollen.business.PollenProperty; import org.junit.Assert; import org.junit.BeforeClass; @@ -46,6 +46,8 @@ protected static SendMail sendMail; + protected static PollenContextImpl context; + @BeforeClass public static void init() throws InterruptedException { @@ -55,9 +57,9 @@ config.setOption(PollenProperty.EMAIL_PORT.getKey(), "25"); config.setOption(PollenProperty.EMAIL_FROM.getKey(), "pollenreminder@codelutin.com"); - PollenContext.loadConfiguration(config); + context.loadConfiguration(config); - sendMail = new SendMail(); + sendMail = new SendMail(context); sendMail.start(); Thread.sleep(3000); } @@ -89,7 +91,7 @@ sendMail.prepareMails("test", mailList); - String emailDir = PollenProperty.EMAIL_DIR.getValue(); + String emailDir = context.getProperty(PollenProperty.EMAIL_DIR); Assert.assertTrue(new File(emailDir, "test.mail").exists()); Assert.assertTrue(new File(emailDir, "test.index").exists()); Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceAuthImplTest.java =================================================================== --- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceAuthImplTest.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceAuthImplTest.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -52,7 +52,7 @@ @Before public void setUp() { - instance = new ServiceAuthImpl(); + instance = new ServiceAuthImpl(TestManager.getContext()); } @After @@ -71,7 +71,7 @@ UserDTO dto = new UserDTO(); dto.setLogin(login); - ServiceUser smu = new ServiceUserImpl(); + ServiceUser smu = new ServiceUserImpl(TestManager.getContext()); smu.createUser(dto, password); boolean result2 = instance.isLoginRight(login, password); assertTrue(result2); @@ -89,7 +89,7 @@ UserDTO dto = new UserDTO(); dto.setLogin(login); - ServiceUser smu = new ServiceUserImpl(); + ServiceUser smu = new ServiceUserImpl(TestManager.getContext()); smu.createUser(dto, password); UserDTO result2 = instance.getUser(login, password); assertEquals(login, result2.getLogin()); Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceChoiceImplTest.java =================================================================== --- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceChoiceImplTest.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceChoiceImplTest.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -61,7 +61,7 @@ @Before public void setUp() { - instance = new ServiceChoiceImpl(); + instance = new ServiceChoiceImpl(TestManager.getContext()); } @After Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceListImplTest.java =================================================================== --- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceListImplTest.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceListImplTest.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -68,7 +68,7 @@ @Before public void setUp() { - instance = new ServiceListImpl(); + instance = new ServiceListImpl(TestManager.getContext()); } @After @@ -124,7 +124,7 @@ // temp stop, must refactor all tests from this class TestManager.stop(); TestManager.start("createAccountInPersonList"); - instance = new ServiceListImpl(); + instance = new ServiceListImpl(TestManager.getContext()); /** PREPARE DATA **/ PersonListDTO dto = new PersonListDTO(); @@ -173,7 +173,7 @@ // temp stop, must refactor all tests from this class TestManager.stop(); TestManager.start("deleteAccountFromPersonList"); - instance = new ServiceListImpl(); + instance = new ServiceListImpl(TestManager.getContext()); /** PREPARE DATA **/ PersonListDTO dto = new PersonListDTO(); Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java =================================================================== --- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -26,7 +26,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.business.PollenContext; +import org.chorem.pollen.business.PollenContextImpl; import org.chorem.pollen.business.TestData; import org.chorem.pollen.business.TestManager; import org.chorem.pollen.business.dto.ChoiceDTO; @@ -79,7 +79,7 @@ @After public void tearDown() throws IOException { TestManager.stop(); - BinderProvider.clear(); + //BinderProvider.clear(); } /** @@ -89,7 +89,7 @@ @Test public void testCreatePoll() throws Exception { TestManager.start("testCreatePoll"); - instance = new ServicePollImpl(); + instance = new ServicePollImpl(TestManager.getContext()); PollDTO dto = instance.getNewPoll(); dto.setBeginChoiceDate(new Date()); @@ -150,7 +150,7 @@ @Test public void testUpdatePoll() throws Exception { TestManager.start("testUpdatePoll"); - instance = new ServicePollImpl(); + instance = new ServicePollImpl(TestManager.getContext()); String pollId = ""; PollDTO dto = instance.getNewPoll(); @@ -174,7 +174,7 @@ @Test public void testDeletePoll() throws Exception { TestManager.start("testDeletePoll"); - instance = new ServicePollImpl(); + instance = new ServicePollImpl(TestManager.getContext()); PollDTO dto = instance.getNewPoll(); dto.setDescription("Test_deletePoll"); @@ -194,7 +194,7 @@ @Test public void testFindPollByPollId() throws Exception { TestManager.start("testFindPollByPollId"); - instance = new ServicePollImpl(); + instance = new ServicePollImpl(TestManager.getContext()); String pollId = ""; PollDTO dto = instance.getNewPoll(); @@ -240,13 +240,13 @@ @Test public void testFindPollsByUser() throws Exception { TestManager.start("testFindPollsByUser"); - instance = new ServicePollImpl(); + instance = new ServicePollImpl(TestManager.getContext()); // création de l'utilisateur UserDTO user = new UserDTO(); user.setLogin("login_findPollsByUser"); user.setEmail("email_findPollsByUser"); - ServiceUser su = new ServiceUserImpl(); + ServiceUser su = new ServiceUserImpl(TestManager.getContext()); String userId = su.createUser(user, "password"); // création du sondage @@ -269,19 +269,19 @@ @Test public void testFindParticipatedPolls() throws Exception { TestManager.start("testFindParticipatedPolls"); - instance = new ServicePollImpl(); + instance = new ServicePollImpl(TestManager.getContext()); // création de l'utilisateur UserDTO user = new UserDTO(); user.setLogin("login_findParticipatedPolls"); user.setEmail("email_findParticipatedPolls"); - ServiceUser su = new ServiceUserImpl(); + ServiceUser su = new ServiceUserImpl(TestManager.getContext()); String userId = su.createUser(user, "password"); // création du compte associé à l'utilisateur PollAccountDTO account = new PollAccountDTO(); account.setUserId(userId); - ServicePollAccount spa = new ServicePollAccountImpl(); + ServicePollAccount spa = new ServicePollAccountImpl(TestManager.getContext()); String accountId = spa.createPollAccount(account); // création du sondage @@ -294,7 +294,7 @@ // création du vote VoteDTO vote = new VoteDTO(accountId, pollId, null); - ServiceVote sv = new ServiceVoteImpl(); + ServiceVote sv = new ServiceVoteImpl(TestManager.getContext()); sv.createVote(vote, account); // recherche des sondages de l'utilisateur @@ -308,9 +308,9 @@ @Test public void testFindRunningPolls() throws Exception { TestManager.start("testFindRunningPolls"); - instance = new ServicePollImpl(); + instance = new ServicePollImpl(TestManager.getContext()); - Date now = PollenContext.getCurrentDate(); + Date now = TestManager.getContext().getCurrentDate(); // sondage en cours sans date de fin PollDTO poll1 = instance.getNewPoll(); @@ -359,7 +359,7 @@ @Test public void testSelectPolls() throws Exception { TestManager.start("testSelectPolls"); - instance = new ServicePollImpl(); + instance = new ServicePollImpl(TestManager.getContext()); PollDTO dto = instance.getNewPoll(); dto.setDescription("test selectPolls"); @@ -395,7 +395,7 @@ @Test public void testCreateComment() throws Exception { TestManager.start("testCreateComment"); - instance = new ServicePollImpl(); + instance = new ServicePollImpl(TestManager.getContext()); /** PREPARE DATA **/ PollDTO poll = instance.getNewPoll(); @@ -440,7 +440,7 @@ @Test public void testDeleteComment() throws Exception { TestManager.start("testDeleteComment"); - instance = new ServicePollImpl(); + instance = new ServicePollImpl(TestManager.getContext()); /** PREPARE DATA **/ PollDTO poll = instance.getNewPoll(); @@ -483,7 +483,7 @@ //@Test public void testGetRestrictedAccount() throws IOException { TestManager.start("testGetRestrictedAccount"); - instance = new ServicePollImpl(); + instance = new ServicePollImpl(TestManager.getContext()); /** PREPARE DATA **/ PollDTO poll = instance.getNewPoll(); Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePreventRuleImplTest.java =================================================================== --- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePreventRuleImplTest.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePreventRuleImplTest.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -63,7 +63,7 @@ @Before public void setUp() throws Exception { - instance = new ServicePreventRuleImpl(); + instance = new ServicePreventRuleImpl(TestManager.getContext()); } @After Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceUserImplTest.java =================================================================== --- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceUserImplTest.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceUserImplTest.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -54,7 +54,7 @@ @Before public void setUp() { - instance = new ServiceUserImpl(); + instance = new ServiceUserImpl(TestManager.getContext()); } @After @@ -142,7 +142,7 @@ user.setId(instance.createUser(user, "password")); instance.updatePasswordUser(user, "newPassword"); - ServiceAuth sa = new ServiceAuthImpl(); + ServiceAuth sa = new ServiceAuthImpl(TestManager.getContext()); UserDTO result = sa.getUser(user.getLogin(), "newPassword"); assertNotNull(result); } Added: trunk/pollen-business/src/test/resources/log4j.properties =================================================================== --- trunk/pollen-business/src/test/resources/log4j.properties (rev 0) +++ trunk/pollen-business/src/test/resources/log4j.properties 2010-03-20 18:42:04 UTC (rev 2953) @@ -0,0 +1,14 @@ +# Default to info level output; this is very handy if you eventually use Hibernate as well. +log4j.rootCategory=warn, A1 + +# A1 is set to be a ConsoleAppender. +log4j.appender.A1=org.apache.log4j.ConsoleAppender + +# A1 uses PatternLayout. +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%d [%p] %c{2} %m%n + +log4j.logger.org.chorem.pollen=debug + +log4j.logger.org.chorem.pollen.business.PollenContextImpl=warn +log4j.logger.org.chorem.pollen.business.services.SendMail=warn Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Border.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -24,7 +24,6 @@ import java.util.Locale; import org.apache.tapestry5.BindingConstants; -import org.apache.tapestry5.Link; import org.apache.tapestry5.annotations.Component; import org.apache.tapestry5.annotations.IncludeStylesheet; import org.apache.tapestry5.annotations.InjectComponent; @@ -35,7 +34,7 @@ import org.apache.tapestry5.ioc.annotations.Inject; import org.apache.tapestry5.services.PersistentLocale; import org.apache.tapestry5.services.Request; -import org.chorem.pollen.business.PollenBusinessException; +import org.chorem.pollen.business.PollenContext; import org.chorem.pollen.business.PollenProperty; import org.chorem.pollen.business.dto.UserDTO; import org.chorem.pollen.business.services.ServiceAuth; @@ -159,6 +158,9 @@ @Inject private Request request; + @Inject + private PollenContext pollen; + /** * Accès aux messages */ @@ -231,7 +233,7 @@ * @return current application version */ public String getVersion() { - return PollenProperty.APP_VERSION.getValue(); + return pollen.getProperty(PollenProperty.APP_VERSION); } public int getCurrentYear() { @@ -240,7 +242,7 @@ } public String getContactEmail() { - return PollenProperty.CONTACT_EMAIL.getValue(); + return pollen.getProperty(PollenProperty.CONTACT_EMAIL); } /** Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/FeedContextLink.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/FeedContextLink.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/FeedContextLink.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -2,7 +2,8 @@ package org.chorem.pollen.ui.components; import java.io.File; -import org.chorem.pollen.business.PollenBusinessException; +import org.apache.tapestry5.ioc.annotations.Inject; +import org.chorem.pollen.business.PollenContext; import org.chorem.pollen.ui.base.ContextLink; import org.chorem.pollen.business.PollenProperty; @@ -19,9 +20,12 @@ */ public class FeedContextLink implements ContextLink { + @Inject + private PollenContext pollen; + @Override public String getContextPath() { - return PollenProperty.FEED_DIR.getValue(); + return pollen.getProperty(PollenProperty.FEED_DIR); } @Override Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ImageContextLink.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ImageContextLink.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/ImageContextLink.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -17,10 +17,9 @@ package org.chorem.pollen.ui.components; import java.io.File; -import java.util.logging.Level; -import java.util.logging.Logger; import org.apache.tapestry5.annotations.Parameter; -import org.chorem.pollen.business.PollenBusinessException; +import org.apache.tapestry5.ioc.annotations.Inject; +import org.chorem.pollen.business.PollenContext; import org.chorem.pollen.business.PollenProperty; import org.chorem.pollen.ui.base.ContextLink; @@ -41,6 +40,9 @@ public static final String THUMB_PREFIX = "thumb_"; + @Inject + private PollenContext pollen; + /** * Directory for files getting or saving from this context * (ie. subdirectory where images are uploaded, main directory is defined by contextPath) @@ -56,7 +58,7 @@ @Override public String getContextPath() { - return PollenProperty.IMG_DIR.getValue(); + return pollen.getProperty(PollenProperty.IMG_DIR); } @Override Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/UsersAdmin.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/UsersAdmin.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/admin/UsersAdmin.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -31,7 +31,7 @@ import org.apache.tapestry5.annotations.SessionState; import org.apache.tapestry5.ioc.Messages; import org.apache.tapestry5.ioc.annotations.Inject; -import org.chorem.pollen.business.PollenBusinessException; +import org.chorem.pollen.business.PollenContext; import org.chorem.pollen.business.PollenProperty; import org.chorem.pollen.business.business.PreventRuleManager; import org.chorem.pollen.business.dto.UserDTO; @@ -199,12 +199,15 @@ }; } + @Inject + private PollenContext pollen; + /** Envoi du mail de notification */ private void sendMailNotification(UserDTO newUser, String password) { Map<String, String> data = new HashMap<String, String>(); - data.put("host", PollenProperty.EMAIL_HOST.getValue()); - data.put("port", PollenProperty.EMAIL_PORT.getValue()); - data.put("from", PollenProperty.EMAIL_FROM.getValue()); + data.put("host", pollen.getProperty(PollenProperty.EMAIL_HOST)); + data.put("port", pollen.getProperty(PollenProperty.EMAIL_PORT)); + data.put("from", pollen.getProperty(PollenProperty.EMAIL_FROM)); data.put("to", newUser.getEmail()); data.put("title", messages.format("registerEmail_subject", newUser .getLogin())); Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -49,6 +49,7 @@ import org.apache.tapestry5.json.JSONObject; import org.apache.tapestry5.upload.services.UploadSymbols; import org.chorem.pollen.business.PollenContext; +import org.chorem.pollen.business.PollenContextImpl; import org.chorem.pollen.business.PollenProperty; import org.chorem.pollen.business.business.PreventRuleManager; import org.chorem.pollen.business.dto.ChoiceDTO; @@ -815,6 +816,9 @@ creator.getVotingId()), voteURL, messages.get("pollFeed_createContent")); } + @Inject + private PollenContext pollen; + /** Envoi du mail de notification */ private void sendMailNotification(String siteURL, ServicePollAccount servicePollAccount, PollDTO poll, Messages messages) { @@ -822,9 +826,9 @@ String voteURL = siteURL + "poll/VoteFor/" + poll.getPollUId(); String modifURL = siteURL + "poll/Modification/" + poll.getPollUId() + ":" + creator.getAccountId(); Map<String, String> data = new HashMap<String, String>(); - data.put("host", PollenProperty.EMAIL_HOST.getValue()); - data.put("port", PollenProperty.EMAIL_PORT.getValue()); - data.put("from", PollenProperty.EMAIL_FROM.getValue()); + data.put("host", pollen.getProperty(PollenProperty.EMAIL_HOST)); + data.put("port", pollen.getProperty(PollenProperty.EMAIL_PORT)); + data.put("from", pollen.getProperty(PollenProperty.EMAIL_FROM)); // Mail au créateur if (poll.getCreatorEmail() != null) { @@ -867,8 +871,8 @@ // send mail preparation try { - PollenContext.getSendMail().prepareMails(poll.getId(), mailList); - PollenContext.getSendMail().wakeUp(); + pollen.getSendMail().prepareMails(poll.getId(), mailList); + pollen.getSendMail().wakeUp(); } catch (IOException ex) { if (log.isErrorEnabled()) { log.error("Can't prepare send mail on disk, mail won't be send !!!", ex); Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollModification.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollModification.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollModification.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -38,7 +38,6 @@ import org.apache.tapestry5.ioc.Messages; import org.apache.tapestry5.ioc.annotations.Inject; import org.chenillekit.tapestry.core.components.DateTimeField; -import org.chorem.pollen.business.PollenBusinessException; import org.chorem.pollen.business.PollenContext; import org.chorem.pollen.business.PollenProperty; import org.chorem.pollen.business.business.PreventRuleManager; @@ -530,13 +529,16 @@ return poll.getChoiceType() == ChoiceType.IMAGE; } + @Inject + private PollenContext pollen; + /** Envoi du mail de notification */ private void sendMailNotification(List<PollAccountDTO> modifiedAccounts) { String voteURL = siteURL + "poll/VoteFor/" + poll.getPollUId(); Map<String, String> data = new HashMap<String, String>(); - data.put("host", PollenProperty.EMAIL_HOST.getValue()); - data.put("port", PollenProperty.EMAIL_PORT.getValue()); - data.put("from", PollenProperty.EMAIL_FROM.getValue()); + data.put("host", pollen.getProperty(PollenProperty.EMAIL_HOST)); + data.put("port", pollen.getProperty(PollenProperty.EMAIL_PORT)); + data.put("from", pollen.getProperty(PollenProperty.EMAIL_FROM)); // Mails aux votants for (PollAccountDTO account : modifiedAccounts) { Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/VoteForPoll.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -53,6 +53,7 @@ import org.chorem.pollen.business.PollenBusinessException; import org.chorem.pollen.business.PollenBusinessException.PollenExceptionType; import org.chorem.pollen.business.PollenProperty; +import org.chorem.pollen.business.PollenContext; import org.chorem.pollen.business.business.PreventRuleManager; import org.chorem.pollen.business.dto.ChoiceDTO; import org.chorem.pollen.business.dto.CommentDTO; @@ -587,9 +588,9 @@ String modifURL = siteURL + "poll/Modification/" + getPoll().getPollUId() + ":" + MD5.encode(getPoll().getCreatorId()); Map<String, String> data = new HashMap<String, String>(); - data.put("host", PollenProperty.EMAIL_HOST.getValue()); - data.put("port", PollenProperty.EMAIL_PORT.getValue()); - data.put("from", PollenProperty.EMAIL_FROM.getValue()); + data.put("host", pollen.getProperty(PollenProperty.EMAIL_HOST)); + data.put("port", pollen.getProperty(PollenProperty.EMAIL_PORT)); + data.put("from", pollen.getProperty(PollenProperty.EMAIL_FROM)); // Mail au créateur data.put("to", getPoll().getCreatorEmail()); @@ -975,8 +976,9 @@ + @Inject + private PollenContext pollen; - @Property private PollUri uri; @@ -1319,7 +1321,8 @@ } public int getPagerRange() { - return Integer.parseInt(PollenProperty.NB_VOTES_PER_PAGE.getValue()); + return Integer.parseInt( + pollen.getProperty(PollenProperty.NB_VOTES_PER_PAGE)); } public String getNoPagerText() throws PollenBusinessException { Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/Register.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/Register.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/user/Register.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -30,7 +30,7 @@ import org.apache.tapestry5.corelib.components.TextField; import org.apache.tapestry5.ioc.Messages; import org.apache.tapestry5.ioc.annotations.Inject; -import org.chorem.pollen.business.PollenBusinessException; +import org.chorem.pollen.business.PollenContext; import org.chorem.pollen.business.PollenProperty; import org.chorem.pollen.business.business.PreventRuleManager; import org.chorem.pollen.business.dto.UserDTO; @@ -149,13 +149,16 @@ return this; } + + @Inject + private PollenContext pollen; /** Envoi du mail de notification */ private void sendMailNotification() { Map<String, String> data = new HashMap<String, String>(); - data.put("host", PollenProperty.EMAIL_HOST.getValue()); - data.put("port", PollenProperty.EMAIL_PORT.getValue()); - data.put("from", PollenProperty.EMAIL_FROM.getValue()); + data.put("host", pollen.getProperty(PollenProperty.EMAIL_HOST)); + data.put("port", pollen.getProperty(PollenProperty.EMAIL_PORT)); + data.put("from", pollen.getProperty(PollenProperty.EMAIL_FROM)); data.put("to", newUser.getEmail()); data.put("title", messages.format("registerEmail_subject", newUser .getLogin())); Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -16,8 +16,6 @@ package org.chorem.pollen.ui.services; -import java.math.BigDecimal; -import org.chorem.pollen.business.services.SendMail; import org.apache.tapestry5.SymbolConstants; import org.apache.tapestry5.ioc.Configuration; import org.apache.tapestry5.ioc.MappedConfiguration; @@ -28,21 +26,29 @@ import org.apache.tapestry5.ioc.annotations.InjectService; import org.apache.tapestry5.ioc.services.Coercion; import org.apache.tapestry5.ioc.services.CoercionTuple; -import org.apache.tapestry5.ioc.services.RegistryShutdownHub; -import org.apache.tapestry5.ioc.services.RegistryShutdownListener; import org.apache.tapestry5.ioc.services.SymbolProvider; import org.apache.tapestry5.services.ComponentSource; import org.apache.tapestry5.upload.services.UploadSymbols; +import org.chorem.pollen.business.PollenContext; +import org.chorem.pollen.business.PollenContextImpl; +import org.chorem.pollen.business.PollenContextImplementor; import org.chorem.pollen.business.services.ServiceAuth; +import org.chorem.pollen.business.services.ServiceAuthImpl; import org.chorem.pollen.business.services.ServiceChoice; +import org.chorem.pollen.business.services.ServiceChoiceImpl; import org.chorem.pollen.business.services.ServiceList; +import org.chorem.pollen.business.services.ServiceListImpl; import org.chorem.pollen.business.services.ServicePoll; import org.chorem.pollen.business.services.ServicePollAccount; +import org.chorem.pollen.business.services.ServicePollAccountImpl; +import org.chorem.pollen.business.services.ServicePollImpl; import org.chorem.pollen.business.services.ServiceResults; +import org.chorem.pollen.business.services.ServiceResultsImpl; import org.chorem.pollen.business.services.ServiceUser; +import org.chorem.pollen.business.services.ServiceUserImpl; import org.chorem.pollen.business.services.ServiceVote; +import org.chorem.pollen.business.services.ServiceVoteImpl; import org.chorem.pollen.ui.data.PollUri; -import org.slf4j.Logger; /** * This module is automatically included as part of the Tapestry IoC Registry, @@ -53,28 +59,81 @@ */ public class AppModule { - private static final String CONFIGURATION_FILE = "pollen.properties"; - public static void bind(ServiceBinder binder) { - // binder.bind(MyServiceInterface.class, MyServiceImpl.class); + // Pollen-Business services +// binder.bind(ServiceAuth.class); +// binder.bind(ServiceList.class); +// binder.bind(ServiceUser.class); +// binder.bind(ServicePoll.class); +// binder.bind(ServicePollAccount.class); +// binder.bind(ServiceResults.class); +// binder.bind(ServiceVote.class); +// binder.bind(ServiceChoice.class); +// binder.bind(ServiceImage.class); +// binder.bind(PollenContext.class, PollenContextImpl.class); + } - // Make bind() calls on the binder object to define most IoC services. - // Use service builder methods (example below) when the implementation - // is provided inline, or requires more initialization than simply - // invoking the constructor. + /** + * Build the main application context PollenContext. + * + * @return PollenContextImplementor type to use injection in services build + */ + public static PollenContextImplementor buildPollenContext() { + PollenContextImplementor context = new PollenContextImpl(); + context.start(); + return context; + } - // Pollen-Business services - binder.bind(ServiceAuth.class); - binder.bind(ServiceList.class); - binder.bind(ServiceUser.class); - binder.bind(ServicePoll.class); - binder.bind(ServicePollAccount.class); - binder.bind(ServiceResults.class); - binder.bind(ServiceVote.class); - binder.bind(ServiceChoice.class); - binder.bind(ServiceImage.class); + /** Will be merged with serviceUser **/ + public static ServiceAuth buildServiceAuth( + @InjectService("PollenContext") PollenContextImplementor context) { + return new ServiceAuthImpl(context); } + /** Will be divided between servicePoll and serviceUser, maybe other + * services for LDAP or CSV + **/ + public static ServiceList buildServiceList( + @InjectService("PollenContext") PollenContextImplementor context) { + return new ServiceListImpl(context); + } + public static ServiceUser buildServiceUser( + @InjectService("PollenContext") PollenContextImplementor context) { + return new ServiceUserImpl(context); + } + + public static ServicePoll buildServicePoll( + @InjectService("PollenContext") PollenContextImplementor context) { + return new ServicePollImpl(context); + } + + /** Will be divided between serviceVote, serviceUser and servicePoll **/ + public static ServicePollAccount buildServicePollAccount( + @InjectService("PollenContext") PollenContextImplementor context) { + return new ServicePollAccountImpl(context); + } + + public static ServiceResults buildServiceResults( + @InjectService("PollenContext") PollenContextImplementor context) { + return new ServiceResultsImpl(context); + } + + public static ServiceVote buildServiceVote( + @InjectService("PollenContext") PollenContextImplementor context) { + return new ServiceVoteImpl(context); + } + + /** Will be divided between serviceVote and servicePoll **/ + public static ServiceChoice buildServiceChoice( + @InjectService("PollenContext") PollenContextImplementor context) { + return new ServiceChoiceImpl(context); + } + + public static ServiceImage buildServiceImage( + @InjectService("PollenContext") PollenContextImplementor context) { + return new ServiceImageImpl(context); + } + public static void contributeApplicationDefaults( MappedConfiguration<String, String> configuration) { // Contributions to ApplicationDefaults will override any contributions to @@ -96,63 +155,15 @@ configuration.add(UploadSymbols.REQUESTSIZE_MAX, "10485760"); } - /* - * This is a service definition, the service will be named "TimingFilter". - * The interface, RequestFilter, is used within the RequestHandler service - * pipeline, which is built from the RequestHandler service configuration. - * Tapestry IoC is responsible for passing in an appropriate Logger - * instance. Requests for static resources are handled at a higher level, so - * this filter will only be invoked for Tapestry related requests. - * - * <p> - * Service builder methods are useful when the implementation is inline as - * an inner class (as here) or require some other kind of special - * initialization. In most cases, use the static bind() method instead. - * - * <p> - * If this method was named "build", then the service id would be taken from - * the service interface and would be "RequestFilter". Since Tapestry - * already defines a service named "RequestFilter" we use an explicit - * service id that we can reference inside the contribution method. - * - public RequestFilter buildTimingFilter(final Logger log) { - return new RequestFilter() { - public boolean service(Request request, Response response, - RequestHandler handler) throws IOException { - long startTime = System.currentTimeMillis(); - - try { - // The responsibility of a filter is to invoke the corresponding method - // in the handler. When you chain multiple filters together, each filter - // received a handler that is a bridge to the next filter. - - return handler.service(request, response); - } finally { - long elapsed = System.currentTimeMillis() - startTime; - - log.info(String.format("Request time: %d ms", elapsed)); - } - } - }; - }*/ - /** - * This is the Shutdown service definition. This service is used when the - * server shutdown. It detects the Tapestry registry shutdown. + * TypeCoercion for PollUri. This will convert automatically between String + * and PollUri. So pollUri can be used in activation/passivation page + * context. + * + * @param configuration */ - @EagerLoad - public RegistryShutdownListener buildPollenShutdown( - @InjectService("RegistryShutdownHub") RegistryShutdownHub hub) { - RegistryShutdownListener listener = new PollenManager(); - hub.addRegistryShutdownListener(listener); - return listener; - } - - public static void contributeRegistryStartup(OrderedConfiguration<Runnable> configuration) { - configuration.add("PollenStartup", new PollenManager()); - } - - public static void contributeTypeCoercer(Configuration<CoercionTuple> configuration) { + public static void contributeTypeCoercer( + Configuration<CoercionTuple> configuration) { Coercion<String, PollUri> coercion1 = new Coercion<String, PollUri>() { @Override @@ -169,8 +180,12 @@ } }; - configuration.add(new CoercionTuple<String, PollUri>(String.class, PollUri.class, coercion1)); - configuration.add(new CoercionTuple<PollUri, String>(PollUri.class, String.class, coercion2)); + configuration.add( + new CoercionTuple<String, PollUri>( + String.class, PollUri.class, coercion1)); + configuration.add( + new CoercionTuple<PollUri, String>( + PollUri.class, String.class, coercion2)); } /** @@ -180,42 +195,20 @@ @EagerLoad public static BackgroundWorker buildBackgroundWorker( ComponentSource componentSource, - ServicePoll servicePoll) { + ServicePoll servicePoll, PollenContext context) { Messages messages = componentSource.getPage("LocalMessages") .getComponentResources().getMessages(); - return new BackgroundWorkerImpl(messages, servicePoll); + return new BackgroundWorkerImpl(messages, servicePoll, context); } - /* - * Contribution au démarrage de services tapestry. - * - * Ajout de SendMail - * - * @param configuration configuration tapestry - * @param conf configuration pollen - * - public static void contributeRegistryStartup(OrderedConfiguration<Runnable> configuration, Configuration conf) { - configuration.add("SendMail", new SendMail(conf)); - }*/ - /** - * Init send mail service. - * - * @param conf + * Make configuration from a Properties file available as symbols. + * @param context * @return */ - @EagerLoad - public SendMail buildSendMail() { - SendMail res = new SendMail(); - return res; - } - - /** - * Make configuration from a Properties file available as symbols. - */ public PropertiesFileSymbolProvider buildConfigPropertiesFileSymbolProvider( - Logger logger) { - return new PropertiesFileSymbolProvider(logger, CONFIGURATION_FILE); + @InjectService("PollenContext") PollenContext context) { + return new PropertiesFileSymbolProvider(context); } /** @@ -229,22 +222,4 @@ configPropertiesFileSymbolProvider, "after:SystemProperties", "before:ApplicationDefaults"); } - - /* - * This is a contribution to the RequestHandler service configuration. This - * is how we extend Tapestry using the timing filter. A common use for this - * kind of filter is transaction management or security. The @Local - * annotation selects the desired service by type, but only from the same - * module. Without @Local, there would be an error due to the other - * service(s) that implement RequestFilter (defined in other modules). - * - public void contributeRequestHandler( - OrderedConfiguration<RequestFilter> configuration, - @Local RequestFilter filter) { - // Each contribution to an ordered configuration has a name, When necessary, you may - // set constraints to precisely control the invocation order of the contributed filter - // within the pipeline. - - //configuration.add("Timing", filter); - }*/ } Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/BackgroundWorkerImpl.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/BackgroundWorkerImpl.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/BackgroundWorkerImpl.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -23,10 +23,11 @@ import java.util.Timer; import java.util.TimerTask; -import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.tapestry5.ioc.Messages; +import org.chorem.pollen.business.PollenContext; +import org.chorem.pollen.business.PollenContextImplementor; import org.chorem.pollen.business.PollenProperty; import org.chorem.pollen.business.business.PreventRuleManager; import org.chorem.pollen.business.dto.PollAccountDTO; @@ -58,11 +59,14 @@ /** Injection du service de gestion de sondages. */ private ServicePoll servicePoll; + private PollenContext context; + /** * Constructeur exécuté au lancement de l'application. */ public BackgroundWorkerImpl(Messages messages, - ServicePoll servicePoll) { + ServicePoll servicePoll, PollenContext context) { + this.context = context; this.messages = messages; this.servicePoll = servicePoll; @@ -74,7 +78,7 @@ * Lancement des tâches en arrière-plan. */ public void executeTasks() { - if (!PollenProperty.SERVER_URL.hasValue()) { + if (!context.hasProperty(PollenProperty.SERVER_URL)) { log.warn("No property siteUrl. Reminder emails would not contain it"); } @@ -126,12 +130,12 @@ * @param poll sondage concerné */ private void sendMailNotification(PollDTO poll, Long timeValue) { - String voteURL = PollenProperty.SERVER_URL.getValue() + "/poll/VoteFor/" - + poll.getPollUId(); + String voteURL = context.getProperty(PollenProperty.SERVER_URL) + + "/poll/VoteFor/" + poll.getPollUId(); Map<String, String> data = new HashMap<String, String>(); - data.put("host", PollenProperty.EMAIL_HOST.getValue()); - data.put("port", PollenProperty.EMAIL_PORT.getValue()); - data.put("from", PollenProperty.EMAIL_FROM.getValue()); + data.put("host", context.getProperty(PollenProperty.EMAIL_HOST)); + data.put("port", context.getProperty(PollenProperty.EMAIL_PORT)); + data.put("from", context.getProperty(PollenProperty.EMAIL_FROM)); // Mails aux votants for (PreventRuleDTO rule : poll.getPreventRuleDTOs()) { @@ -162,7 +166,7 @@ // désactivation de la règle de rappel pour éviter qu'elle soit réexécutée if (hasRun) { rule.setActive(false); - ServicePreventRule spr = new ServicePreventRuleImpl(); + ServicePreventRule spr = new ServicePreventRuleImpl((PollenContextImplementor)context); spr.updatePreventRule(rule); } } Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PollenManager.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -20,6 +20,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.tapestry5.ioc.services.RegistryShutdownListener; import org.chorem.pollen.business.PollenContext; +import org.chorem.pollen.business.PollenContextImpl; /** * Service de gestion de l'arrêt du serveur. Ce service exécute une action à la @@ -28,24 +29,30 @@ * @author rannou * @version $Id$ */ -public class PollenManager implements RegistryShutdownListener, Runnable { +public class PollenManager implements RegistryShutdownListener /*, Runnable */{ private static final Log log = LogFactory.getLog(PollenManager.class); - @Override - public void run() { - if (log.isInfoEnabled()) { - log.info("Start Pollen"); - } - PollenContext.start(); + private PollenContext context; + + public PollenManager(PollenContext context) { + this.context = context; } +// @Override +// public void run() { +// if (log.isInfoEnabled()) { +// log.info("Start Pollen"); +// } +// context.start(); +// } + @Override public void registryDidShutdown() { if (log.isInfoEnabled()) { log.info("Stop Pollen"); } - PollenContext.stop(); + context.stop(); } } Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PropertiesFileSymbolProvider.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PropertiesFileSymbolProvider.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/PropertiesFileSymbolProvider.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -17,6 +17,8 @@ private final Map<String, String> propertiesMap = new CaseInsensitiveMap<String>(); + private PollenContext context; + /** * Instantiate a new PropertiesFileSymbolProvider using a given resource * name @@ -55,11 +57,10 @@ * Instantiate a new PropertiesFileSymbolProvider using a given resource * name (looking in filesystem and classpath) * - * @param logger the logger to log error messages to - * @param resourceName the name of the resource to load + * @param context PollenContext */ - public PropertiesFileSymbolProvider(Logger logger, String resourceName) { - Properties conf = PollenContext.getProperties(); + public PropertiesFileSymbolProvider(PollenContext context) { + Properties conf = context.getConfiguration().getOptions(); initializeProperties(conf); } @@ -129,6 +130,7 @@ } } + @Override public String valueForSymbol(String arg0) { return propertiesMap.get(arg0); } Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java 2010-03-20 15:30:29 UTC (rev 2952) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/ServiceImageImpl.java 2010-03-20 18:42:04 UTC (rev 2953) @@ -41,13 +41,15 @@ private static final Logger logger = LoggerFactory.getLogger(ServiceImageImpl.class); - public ServiceImageImpl() { - + private PollenContext context; + + public ServiceImageImpl(PollenContext context) { + this.context = context; } @Override public String getContextPath() { - return PollenContext.getProperty(PollenProperty.IMG_DIR); + return context.getProperty(PollenProperty.IMG_DIR); } /** @@ -75,6 +77,7 @@ @Override public StreamResponse createImageStream(String filename, String filedir, boolean thumb) { + // security : src containing .. are filtered, to not access to full system if (StringUtils.isEmpty(filename) || filename.contains("..")) { return null; }