Author: tchemit Date: 2014-04-27 18:47:39 +0200 (Sun, 27 Apr 2014) New Revision: 3880 Url: http://forge.chorem.org/projects/pollen/repository/revisions/3880 Log: technical stack is nearly ok Added: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenPersistenceContext.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenTopiaPersistenceContext.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationContext.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestContext.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/FakePollenRestApiApplicationContext.java Removed: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenApplicationContext.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiServiceContext.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceContextFilter.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceListener.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServices.java trunk/pollen-rest-api/src/test/resources/pollen.properties Modified: trunk/pollen-rest-api/pom.xml trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenTopiaTransactionFilter.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java trunk/pollen-rest-api/src/main/resources/mapping trunk/pollen-rest-api/src/main/webapp/WEB-INF/web.xml trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java trunk/pollen-services/pom.xml trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/EntityNotFoundException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AuthService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java trunk/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java trunk/pom.xml Added: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenPersistenceContext.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenPersistenceContext.java (rev 0) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenPersistenceContext.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -0,0 +1,15 @@ +package org.chorem.pollen.persistence; + +import org.nuiton.topia.persistence.TopiaPersistenceContext; +import org.nuiton.topia.persistence.support.TopiaHibernateSupport; + +/** + * Created on 4/27/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.0 + */ +public interface PollenPersistenceContext extends TopiaPersistenceContext, PollenTopiaDaoSupplier { + + TopiaHibernateSupport getHibernateSupport(); +} Property changes on: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenPersistenceContext.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenTopiaPersistenceContext.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenTopiaPersistenceContext.java (rev 0) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenTopiaPersistenceContext.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -0,0 +1,20 @@ +package org.chorem.pollen.persistence; + +import org.nuiton.topia.persistence.TopiaIdFactory; +import org.nuiton.topia.persistence.internal.HibernateProvider; +import org.nuiton.topia.persistence.internal.TopiaHibernateSessionRegistry; +import org.nuiton.topia.persistence.support.TopiaListenableSupport; + +public class PollenTopiaPersistenceContext extends AbstractPollenTopiaPersistenceContext { + + public PollenTopiaPersistenceContext(HibernateProvider hibernateProvider, + TopiaListenableSupport listenableSupport, + TopiaIdFactory topiaIdFactory, + TopiaHibernateSessionRegistry sessionRegistry) { + super(hibernateProvider, + listenableSupport, + topiaIdFactory, + sessionRegistry); + } + +} Property changes on: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenTopiaPersistenceContext.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/pollen-rest-api/pom.xml =================================================================== --- trunk/pollen-rest-api/pom.xml 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-rest-api/pom.xml 2014-04-27 16:47:39 UTC (rev 3880) @@ -92,16 +92,6 @@ </dependency> <dependency> - <groupId>org.nuiton.jpa</groupId> - <artifactId>nuiton-jpa-api</artifactId> - </dependency> - - <dependency> - <groupId>org.nuiton.jpa</groupId> - <artifactId>nuiton-jpa-junit</artifactId> - </dependency> - - <dependency> <groupId>org.nuiton</groupId> <artifactId>nuiton-utils</artifactId> </dependency> Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenApplicationContext.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenApplicationContext.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenApplicationContext.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -1,166 +0,0 @@ -package org.chorem.pollen.rest.api; - -/* - * #%L - * Pollen :: Rest Api - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.log4j.LogManager; -import org.apache.log4j.PropertyConfigurator; -import org.chorem.pollen.persistence.PollenTopiaApplicationContext; -import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; -import org.chorem.pollen.services.DefaultPollenServiceContext; -import org.chorem.pollen.services.PollenServiceContext; -import org.chorem.pollen.services.config.PollenServiceConfig; -import org.nuiton.i18n.I18n; -import org.nuiton.i18n.init.DefaultI18nInitializer; -import org.nuiton.i18n.init.I18nInitializer; - -import java.io.Closeable; -import java.io.File; -import java.util.Locale; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class PollenApplicationContext implements Closeable { - - private static Log log = LogFactory.getLog(PollenApplicationContext.class); - - protected static final String APPLICATION_CONTEXT_PARAMETER = "pollen_PollenApplicationContext"; - - protected static PollenTopiaApplicationContext topiaApplicationContext; - - protected static PollenServiceConfig applicationConfig; - - public static PollenServiceConfig getApplicationConfig() { - if (applicationConfig == null) { - applicationConfig = new PollenServiceConfig(); - } - return applicationConfig; - } - - public static PollenTopiaApplicationContext getTopiaApplicationContext() { - if (topiaApplicationContext == null) { - topiaApplicationContext = new PollenTopiaApplicationContext(getApplicationConfig().getTopiaProperties()); - } - return topiaApplicationContext; - } - - public static void setTopiaApplicationContext(PollenTopiaApplicationContext topiaApplicationContext) { - PollenApplicationContext.topiaApplicationContext = topiaApplicationContext; - } - - public PollenTopiaPersistenceContext newPersistenceContext() { - - PollenTopiaPersistenceContext persistenceContext = getTopiaApplicationContext().newPersistenceContext(); - - return persistenceContext; - - } - - public PollenServiceContext newServiceContext(PollenTopiaPersistenceContext persistenceContext, Locale locale) { - - DefaultPollenServiceContext newServiceContext = - new DefaultPollenServiceContext(); - - PollenServiceConfig applicationConfig = getApplicationConfig(); - - newServiceContext.setPollenServiceConfig(applicationConfig); - - newServiceContext.setPersistenceContext(persistenceContext); - - newServiceContext.setLocale(locale); - - return newServiceContext; - - } - - @Override - public void close() { - - if (topiaApplicationContext != null) { - - if (log.isInfoEnabled()) { - log.info("stopping Pollen, will close entity manager factory"); - } - - topiaApplicationContext.closeContext(); - - } - - } - - public void init() { - - if (getApplicationConfig().isLogConfigurationProvided()) { - - File log4jConfigurationFile = getApplicationConfig().getLogConfigurationFile(); - - String log4jConfigurationFileAbsolutePath = log4jConfigurationFile.getAbsolutePath(); - - if (log4jConfigurationFile.exists()) { - - if (log.isInfoEnabled()) { - log.info("will use logging configuration " + log4jConfigurationFileAbsolutePath); - } - - // reset logger configuration - LogManager.resetConfiguration(); - - // use generate log config file - PropertyConfigurator.configure(log4jConfigurationFileAbsolutePath); - - log = LogFactory.getLog(PollenApplicationContext.class); - - } else { - if (log.isWarnEnabled()) { - log.warn("there is no file " + log4jConfigurationFileAbsolutePath + ". Default logging configuration will be used."); - } - } - - } else { - log.info("will use default logging configuration"); - } - - I18nInitializer initializer = new DefaultI18nInitializer("pollen"); - // to show none translated sentences - initializer.setMissingKeyReturnNull(true); - - I18n.init(initializer, Locale.FRANCE); - -// PollenTopiaPersistenceContext persistenceContext = newPersistenceContext(); -// -// PollenServiceContext serviceContext = newServiceContext(persistenceContext, Locale.FRANCE); -// -// InitWaoService initWaoService = serviceContext.newService(InitWaoService.class); -// -// initWaoService.init(); -// -// persistenceContext.closeContext(); - - } -} Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -25,14 +25,20 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.google.gson.*; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonNull; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.debux.webmotion.server.call.Call; import org.debux.webmotion.server.call.HttpContext; import org.debux.webmotion.server.mapping.Mapping; import org.debux.webmotion.server.render.Render; -import org.nuiton.jpa.api.JpaEntity; +import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.util.ObjectUtil; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; @@ -97,7 +103,7 @@ Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() { @Override public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) { - if(src == null) { + if (src == null) { return JsonNull.INSTANCE; } return new JsonPrimitive(src.getTime()); @@ -124,20 +130,20 @@ // single object - if (model instanceof JpaEntity) { + if (model instanceof TopiaEntity) { // entity need to transform it - JpaEntity jpaEntity = (JpaEntity) model; + TopiaEntity topiaEntity = (TopiaEntity) model; - PollenEntityBinder<JpaEntity> binder = BinderFactory.newBinder(jpaEntity.getClass(), jpaEntity.getClass(), null, PollenEntityBinder.class); - Map<String, Object> map = binder.obtainProperties(jpaEntity); + PollenEntityBinder<TopiaEntity> binder = BinderFactory.newBinder(topiaEntity.getClass(), topiaEntity.getClass(), null, PollenEntityBinder.class); + Map<String, Object> map = binder.obtainProperties(topiaEntity); Map<String, Object> result = Maps.newTreeMap(); for (Map.Entry<String, Object> entry : map.entrySet()) { String propertyName = entry.getKey(); Object propertyValue = entry.getValue(); - if (propertyValue instanceof JpaEntity) { + if (propertyValue instanceof TopiaEntity) { result.put(propertyName, toMap(propertyValue)); continue; } @@ -149,7 +155,7 @@ if (includeCollection != null) { for (String propertyName : includeCollection) { - Iterable<?> collectionValue = binder.getCollectionValue(jpaEntity, propertyName); + Iterable<?> collectionValue = binder.getCollectionValue(topiaEntity, propertyName); result.put(propertyName, toMap(collectionValue)); } @@ -160,7 +166,7 @@ return model; } - protected static class PollenEntityBinder<E extends JpaEntity> extends Binder<E, E> { + protected static class PollenEntityBinder<E extends TopiaEntity> extends Binder<E, E> { /** Logger. */ private static final Log log = @@ -190,7 +196,7 @@ * * @param source the bean to read * @return the map of properties obtained indexed by their property name, - * or an empty map is the given {@code from} is {@code null}. + * or an empty map is the given {@code from} is {@code null}. * @since 2.3 */ public Map<String, Object> obtainProperties(E source) { Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationContext.java (from rev 3879, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenApplicationContext.java) =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationContext.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationContext.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -0,0 +1,216 @@ +package org.chorem.pollen.rest.api; + +/* + * #%L + * Pollen :: Rest Api + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import com.google.common.base.Preconditions; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.log4j.LogManager; +import org.apache.log4j.PropertyConfigurator; +import org.chorem.pollen.persistence.PollenPersistenceContext; +import org.chorem.pollen.persistence.PollenTopiaApplicationContext; +import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; +import org.chorem.pollen.services.DefaultPollenServiceContext; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.config.PollenServiceConfig; +import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.chorem.pollen.services.exception.InvalidPollenUserFormException; +import org.chorem.pollen.services.service.PollenUserService; +import org.nuiton.i18n.I18n; +import org.nuiton.i18n.init.DefaultI18nInitializer; +import org.nuiton.i18n.init.I18nInitializer; + +import java.io.Closeable; +import java.io.File; +import java.util.Locale; +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollenRestApiApplicationContext implements Closeable { + + private static Log log = LogFactory.getLog(PollenRestApiApplicationContext.class); + + protected static PollenRestApiApplicationContext applicationContext; + + public static PollenRestApiApplicationContext getApplicationContext() { + return applicationContext; + } + + public static void setApplicationContext(PollenRestApiApplicationContext applicationContext) { + PollenRestApiApplicationContext.applicationContext = applicationContext; + } + + protected AtomicBoolean started; + + protected AtomicBoolean closed; + + protected PollenTopiaApplicationContext topiaApplicationContext; + + protected PollenServiceConfig applicationConfig; + + public static PollenRestApiApplicationContext newApplicationContext() { + PollenServiceConfig applicationConfig = new PollenServiceConfig(); + PollenTopiaApplicationContext pollenTopiaApplicationContext = new PollenTopiaApplicationContext(applicationConfig.getTopiaProperties()); + PollenRestApiApplicationContext result = new PollenRestApiApplicationContext(applicationConfig, pollenTopiaApplicationContext); + return result; + } + + protected PollenRestApiApplicationContext(PollenServiceConfig applicationConfig, PollenTopiaApplicationContext topiaApplicationContext) { + + Preconditions.checkNotNull(applicationConfig, "Configuration can not be null!"); + Preconditions.checkNotNull(topiaApplicationContext, "topiaApplicationContext can not be null!"); + + this.applicationConfig = applicationConfig; + this.topiaApplicationContext = topiaApplicationContext; + this.started = new AtomicBoolean(false); + this.closed = new AtomicBoolean(false); + } + + public PollenTopiaApplicationContext getTopiaApplicationContext() { + return topiaApplicationContext; + } + + public PollenServiceConfig getApplicationConfig() { + return applicationConfig; + } + + public PollenTopiaPersistenceContext newPersistenceContext() { + + PollenTopiaPersistenceContext persistenceContext = topiaApplicationContext.newPersistenceContext(); + return persistenceContext; + + } + + public PollenServiceContext newServiceContext(PollenPersistenceContext persistenceContext, Locale locale) { + + DefaultPollenServiceContext newServiceContext = new DefaultPollenServiceContext(); + newServiceContext.setPollenServiceConfig(applicationConfig); + newServiceContext.setTopiaApplicationContext(topiaApplicationContext); + newServiceContext.setPersistenceContext(persistenceContext); + newServiceContext.setLocale(locale); + return newServiceContext; + + } + + @Override + public void close() { + + if (closed.get()) { + + if (log.isWarnEnabled()) { + log.warn("Already closed"); + } + return; + } + + if (!started.get()) { + + if (log.isWarnEnabled()) { + log.warn("Not started"); + } + return; + } + + if (topiaApplicationContext != null) { + + if (log.isInfoEnabled()) { + log.info("stopping Pollen, will close persistence context"); + } + topiaApplicationContext.closeContext(); + } + + closed.set(true); + started.set(false); + } + + public void init() { + + if (started.get()) { + + if (log.isWarnEnabled()) { + log.warn("Already started!"); + } + return; + } + + Preconditions.checkState(applicationConfig != null, "No configuration initialized!"); + Preconditions.checkState(topiaApplicationContext != null, "No topiaApplicationContext initialized!"); + + if (applicationConfig.isLogConfigurationProvided()) { + + File log4jConfigurationFile = applicationConfig.getLogConfigurationFile(); + + String log4jConfigurationFileAbsolutePath = log4jConfigurationFile.getAbsolutePath(); + + if (log4jConfigurationFile.exists()) { + + if (log.isInfoEnabled()) { + log.info("will use logging configuration " + log4jConfigurationFileAbsolutePath); + } + + // reset logger configuration + LogManager.resetConfiguration(); + + // use generate log config file + PropertyConfigurator.configure(log4jConfigurationFileAbsolutePath); + + log = LogFactory.getLog(PollenRestApiApplicationContext.class); + + } else { + if (log.isWarnEnabled()) { + log.warn("there is no file " + log4jConfigurationFileAbsolutePath + ". Default logging configuration will be used."); + } + } + + } else { + log.info("will use default logging configuration"); + } + + I18nInitializer initializer = new DefaultI18nInitializer("pollen-i18n"); + // to show none translated sentences + initializer.setMissingKeyReturnNull(true); + + I18n.init(initializer, Locale.FRANCE); + + PollenTopiaPersistenceContext persistenceContext = newPersistenceContext(); + + try { + PollenServiceContext serviceContext = newServiceContext(persistenceContext, Locale.FRANCE); + serviceContext.newService(PollenUserService.class).createDefaultUsers(); + } catch (InvalidPollenUserFormException e) { + //Can't happen + } catch (EntityNotFoundException e) { + //Can't happen + } finally { + persistenceContext.closeContext(); + } + + started.set(true); + } +} Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java (from rev 3879, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceListener.java) =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -0,0 +1,124 @@ +package org.chorem.pollen.rest.api; + +/* + * #%L + * Pollen :: Rest Api + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import org.apache.commons.beanutils.Converter; +import org.debux.webmotion.server.WebMotionServerListener; +import org.debux.webmotion.server.call.Call; +import org.debux.webmotion.server.call.HttpContext; +import org.debux.webmotion.server.call.ServerContext; +import org.debux.webmotion.server.handler.ExecutorParametersInjectorHandler; +import org.debux.webmotion.server.mapping.Mapping; + +import javax.servlet.http.HttpServletRequest; +import java.lang.reflect.Type; +import java.util.Date; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollenRestApiApplicationListener implements WebMotionServerListener { + + @Override + public void onStart(Mapping mapping, ServerContext serverContext) { + + // --- + // init converters + // --- + + serverContext.addConverter(new Converter() { + @Override + public Object convert(Class type, Object value) { + Object result = null; + if (value != null) { + if (value.getClass().isAssignableFrom(Date.class)) { + result = value; + } else { + Object o = ((Object[]) value)[0]; + String sTime = o.toString(); + Long time = Long.parseLong(sTime); + result = new Date(time); + } + } + return result; + } + + }, Date.class); + + // --- + // init injectors + // --- + + serverContext.addInjector(new ExecutorParametersInjectorHandler.Injector() { + @Override + public PollenRestApiRequestContext getValue(Mapping m, Call call, String name, Class<?> type, Type generic) { + PollenRestApiRequestContext result = null; + if (PollenRestApiRequestContext.class.isAssignableFrom(type)) { + HttpContext httpContext = call.getContext(); + HttpServletRequest request = httpContext.getRequest(); + + result = PollenRestApiRequestFilter.getRequestContext(request); + } + return result; + } + }); + + // --- + // init application context + // --- + + PollenRestApiApplicationContext applicationContext = + PollenRestApiApplicationContext.getApplicationContext(); + + if (applicationContext == null) { + + // create application context + applicationContext = PollenRestApiApplicationContext.newApplicationContext(); + PollenRestApiApplicationContext.setApplicationContext(applicationContext); + applicationContext.init(); + } + + // push it in context + PollenRestApiRequestFilter.setApplicationContext( + serverContext.getServletContext(), applicationContext); + } + + @Override + public void onStop(ServerContext serverContext) { + + // Get application context + PollenRestApiApplicationContext applicationContext = + PollenRestApiRequestFilter.getApplicationContext( + serverContext.getServletContext()); + + // close it (and all underlined resources) + if (applicationContext != null) { + applicationContext.close(); + } + } + +} Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestContext.java (from rev 3879, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiServiceContext.java) =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestContext.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestContext.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -0,0 +1,78 @@ +package org.chorem.pollen.rest.api; + +import org.chorem.pollen.services.PollenSecurityContext; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.service.AuthService; +import org.chorem.pollen.services.service.ChoiceService; +import org.chorem.pollen.services.service.CommentService; +import org.chorem.pollen.services.service.FavoriteListService; +import org.chorem.pollen.services.service.FixturesService; +import org.chorem.pollen.services.service.PollService; +import org.chorem.pollen.services.service.PollenUserService; +import org.chorem.pollen.services.service.SecurityService; +import org.chorem.pollen.services.service.VoteCountingService; +import org.chorem.pollen.services.service.VoteService; +import org.chorem.pollen.services.service.VoterListService; + +/** + * Created on 4/25/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollenRestApiRequestContext { + + protected PollenServiceContext serviceContext; + + public void setServiceContext(PollenServiceContext serviceContext) { + this.serviceContext = serviceContext; + } + + public void setSecurityContext(PollenSecurityContext securityContext) { + serviceContext.setSecurityContext(securityContext); + } + + public AuthService getAuthService() { + return serviceContext.newService(AuthService.class); + } + + public ChoiceService getChoiceService() { + return serviceContext.newService(ChoiceService.class); + } + + public CommentService getCommentService() { + return serviceContext.newService(CommentService.class); + } + + public FavoriteListService getFavoriteListService() { + return serviceContext.newService(FavoriteListService.class); + } + + public PollService getPollService() { + return serviceContext.newService(PollService.class); + } + + public PollenUserService getPollenUserService() { + return serviceContext.newService(PollenUserService.class); + } + + public VoteCountingService getVoteCountingService() { + return serviceContext.newService(VoteCountingService.class); + } + + public VoterListService getVoterListService() { + return serviceContext.newService(VoterListService.class); + } + + public VoteService getVoteService() { + return serviceContext.newService(VoteService.class); + } + + public FixturesService getFixturesService() { + return serviceContext.newService(FixturesService.class); + } + + public SecurityService getSecurityService() { + return serviceContext.newService(SecurityService.class); + } +} Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java (from rev 3879, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceContextFilter.java) =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -0,0 +1,134 @@ +package org.chorem.pollen.rest.api; + +/* + * #%L + * Pollen :: Rest Api + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import org.apache.commons.lang3.StringUtils; +import org.chorem.pollen.persistence.PollenPersistenceContext; +import org.chorem.pollen.persistence.entity.SessionToken; +import org.chorem.pollen.services.PollenSecurityContext; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.exception.InvalidSessionTokenException; +import org.debux.webmotion.server.WebMotionFilter; +import org.debux.webmotion.server.call.HttpContext; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Locale; + +/** + * Inject {@link PollenRestApiRequestContext} in services. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollenRestApiRequestFilter extends WebMotionFilter { + + protected static final String APPLICATION_CONTEXT_PARAMETER = "pollen_PollenApplicationContext"; + + protected static final String REQUEST_POLLEN_REQUEST_CONTEXT = "pollen_PollenRequestContext"; + + protected static final String REQUEST_POLLEN_CONNECTED_USER = "pollen_PollenConnectedUser"; + + public static final String REQUEST_AUTH_PARAMETER = "auth"; + + public static PollenRestApiApplicationContext getApplicationContext(ServletContext servletContext) { + PollenRestApiApplicationContext result = (PollenRestApiApplicationContext) + servletContext.getAttribute(APPLICATION_CONTEXT_PARAMETER); + return result; + } + + public static PollenRestApiRequestContext getRequestContext(HttpServletRequest request) { + PollenRestApiRequestContext result = (PollenRestApiRequestContext) + request.getAttribute(REQUEST_POLLEN_REQUEST_CONTEXT); + return result; + } + + public static SessionToken getSessionToken(HttpServletRequest request) { + SessionToken result = (SessionToken) + request.getAttribute(REQUEST_POLLEN_CONNECTED_USER); + return result; + } + + public static void setApplicationContext(ServletContext servletContext, + PollenRestApiApplicationContext applicationContext) { + servletContext.setAttribute(APPLICATION_CONTEXT_PARAMETER, applicationContext); + } + + public static void setRequestContext(HttpServletRequest request, + PollenRestApiRequestContext serviceContext) { + request.setAttribute(REQUEST_POLLEN_REQUEST_CONTEXT, serviceContext); + } + + public static void setSessionToken(HttpServletRequest request, + SessionToken sessionToken) { + request.setAttribute(REQUEST_POLLEN_CONNECTED_USER, sessionToken); + } + + public void inject(HttpContext context) throws InvalidSessionTokenException { + + PollenRestApiApplicationContext applicationContext = + getApplicationContext(context.getServletContext()); + + PollenPersistenceContext persistenceContext = + PollenTopiaTransactionFilter.getPersistenceContext(context.getRequest()); + + //FIXME Reuse user locale + PollenServiceContext serviceContext = + applicationContext.newServiceContext(persistenceContext, Locale.FRANCE); + + PollenRestApiRequestContext requestContext = new PollenRestApiRequestContext(); + requestContext.setServiceContext(serviceContext); + + setRequestContext(context.getRequest(), requestContext); + + addSecurityContext(context, requestContext); + + doProcess(); + + HttpServletResponse response = context.getResponse(); + response.addHeader(HttpContext.HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "*"); + response.addHeader(HttpContext.HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"); + } + + protected void addSecurityContext(HttpContext context, + PollenRestApiRequestContext serviceContext) throws InvalidSessionTokenException { + + String[] strings = context.getParameters().get(REQUEST_AUTH_PARAMETER); + + String authParam = strings == null || strings.length < 1 ? null : strings[0]; + + SessionToken sessionToken = null; + + if (StringUtils.isNotBlank(authParam)) { + + // find out the userId from this auth + + sessionToken = serviceContext.getAuthService().getUserByAuth(authParam); + } + PollenSecurityContext securityContext = + PollenSecurityContext.newContext(sessionToken); + serviceContext.setSecurityContext(securityContext); + } +} Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiServiceContext.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiServiceContext.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiServiceContext.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -1,78 +0,0 @@ -package org.chorem.pollen.rest.api; - -import org.chorem.pollen.services.PollenSecurityContext; -import org.chorem.pollen.services.PollenServiceContext; -import org.chorem.pollen.services.service.AuthService; -import org.chorem.pollen.services.service.ChoiceService; -import org.chorem.pollen.services.service.CommentService; -import org.chorem.pollen.services.service.FavoriteListService; -import org.chorem.pollen.services.service.FixturesService; -import org.chorem.pollen.services.service.PollService; -import org.chorem.pollen.services.service.PollenUserService; -import org.chorem.pollen.services.service.SecurityService; -import org.chorem.pollen.services.service.VoteCountingService; -import org.chorem.pollen.services.service.VoteService; -import org.chorem.pollen.services.service.VoterListService; - -/** - * Created on 4/25/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 2.0 - */ -public class PollenRestApiServiceContext { - - protected PollenServiceContext serviceContext; - - public void setServiceContext(PollenServiceContext serviceContext) { - this.serviceContext = serviceContext; - } - - public void setSecurityContext(PollenSecurityContext securityContext) { - serviceContext.setSecurityContext(securityContext); - } - - public AuthService getAuthService() { - return serviceContext.newService(AuthService.class); - } - - public ChoiceService getChoiceService() { - return serviceContext.newService(ChoiceService.class); - } - - public CommentService getCommentService() { - return serviceContext.newService(CommentService.class); - } - - public FavoriteListService getFavoriteListService() { - return serviceContext.newService(FavoriteListService.class); - } - - public PollService getPollService() { - return serviceContext.newService(PollService.class); - } - - public PollenUserService getPollenUserService() { - return serviceContext.newService(PollenUserService.class); - } - - public VoteCountingService getVoteCountingService() { - return serviceContext.newService(VoteCountingService.class); - } - - public VoterListService getVoterListService() { - return serviceContext.newService(VoterListService.class); - } - - public VoteService getVoteService() { - return serviceContext.newService(VoteService.class); - } - - public FixturesService getFixturesService() { - return serviceContext.newService(FixturesService.class); - } - - public SecurityService getSecurityService() { - return serviceContext.newService(SecurityService.class); - } -} Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceContextFilter.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceContextFilter.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceContextFilter.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -1,92 +0,0 @@ -package org.chorem.pollen.rest.api; - -/* - * #%L - * Pollen :: Rest Api - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -import org.apache.commons.lang3.StringUtils; -import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; -import org.chorem.pollen.persistence.entity.SessionToken; -import org.chorem.pollen.services.PollenSecurityContext; -import org.chorem.pollen.services.PollenServiceContext; -import org.chorem.pollen.services.exception.InvalidSessionTokenException; -import org.debux.webmotion.server.WebMotionFilter; -import org.debux.webmotion.server.call.HttpContext; - -import javax.servlet.http.HttpServletResponse; -import java.util.Locale; - -/** - * Inject le service context dans les controlleurs. - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class PollenServiceContextFilter extends WebMotionFilter { - - public static final String REQUEST_AUTH_PARAMETER = "auth"; - - public void inject(HttpContext context) throws InvalidSessionTokenException { - - PollenApplicationContext applicationContext = - PollenServices.getApplicationContext(context.getServletContext()); - - PollenTopiaPersistenceContext persistenceContext = - PollenServices.getPersistenceContext(context.getRequest()); - - PollenServiceContext serviceContext = - applicationContext.newServiceContext(persistenceContext, Locale.FRANCE); - - PollenRestApiServiceContext apiContext = new PollenRestApiServiceContext(); - apiContext.setServiceContext(serviceContext); - - PollenServices.setServiceContext(context.getRequest(), apiContext); - - addSecurityContext(context, apiContext); - - doProcess(); - - HttpServletResponse response = context.getResponse(); - response.addHeader(HttpContext.HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "*"); - response.addHeader(HttpContext.HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"); - } - - protected void addSecurityContext(HttpContext context, - PollenRestApiServiceContext serviceContext) throws InvalidSessionTokenException { - - String[] strings = context.getParameters().get(REQUEST_AUTH_PARAMETER); - - String authParam = strings == null || strings.length < 1 ? null : strings[0]; - - SessionToken sessionToken = null; - - if (StringUtils.isNotBlank(authParam)) { - - // find out the userId from this auth - - sessionToken = serviceContext.getAuthService().getUserByAuth(authParam); - } - PollenSecurityContext securityContext = - PollenSecurityContext.newContext(sessionToken); - serviceContext.setSecurityContext(securityContext); - } -} Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceListener.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceListener.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceListener.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -1,126 +0,0 @@ -package org.chorem.pollen.rest.api; - -/* - * #%L - * Pollen :: Rest Api - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -import org.apache.commons.beanutils.Converter; -import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; -import org.chorem.pollen.services.PollenServiceContext; -import org.chorem.pollen.services.exception.EntityNotFoundException; -import org.chorem.pollen.services.exception.InvalidPollenUserFormException; -import org.chorem.pollen.services.service.PollenUserService; -import org.debux.webmotion.server.WebMotionServerListener; -import org.debux.webmotion.server.call.Call; -import org.debux.webmotion.server.call.HttpContext; -import org.debux.webmotion.server.call.ServerContext; -import org.debux.webmotion.server.handler.ExecutorParametersInjectorHandler; -import org.debux.webmotion.server.mapping.Mapping; - -import javax.servlet.http.HttpServletRequest; -import java.lang.reflect.Type; -import java.util.Date; -import java.util.Locale; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class PollenServiceListener implements WebMotionServerListener { - - @Override - public void onStart(Mapping mapping, ServerContext serverContext) { - serverContext.addConverter(new Converter() { - @Override - public Object convert(Class type, Object value) { - Object result = null; - if (value != null) { - if (value.getClass().isAssignableFrom(Date.class)) { - result = value; - } else { - Object o = ((Object[]) value)[0]; - String sTime = o.toString(); - Long time = Long.parseLong(sTime); - result = new Date(time); - } - } - return result; - } - - }, Date.class); - serverContext.addInjector(new PollenServiceContextInjector()); - - // Create application context - PollenApplicationContext applicationContext = - new PollenApplicationContext(); - - // push it in context - PollenServices.setApplicationContext( - serverContext.getServletContext(), applicationContext); - - PollenTopiaPersistenceContext persistenceContext = applicationContext.newPersistenceContext(); - - try { - PollenServiceContext serviceContext = - applicationContext.newServiceContext(persistenceContext, Locale.FRANCE); - serviceContext.newService(PollenUserService.class).createDefaultUsers(); - } catch (InvalidPollenUserFormException e) { - //Can't happen - } catch (EntityNotFoundException e) { - //Can't happen - } finally { - persistenceContext.closeContext(); - } - } - - @Override - public void onStop(ServerContext serverContext) { - - // Get application context - PollenApplicationContext applicationContext = - PollenServices.getApplicationContext( - serverContext.getServletContext()); - - // close it (and all underlined resources) - if (applicationContext != null) { - applicationContext.close(); - } - } - - protected static class PollenServiceContextInjector implements ExecutorParametersInjectorHandler.Injector { - @Override - public PollenRestApiServiceContext getValue(Mapping mapping, Call call, String name, Class<?> type, Type generic) { - PollenRestApiServiceContext result = null; - if (PollenServiceContext.class.isAssignableFrom(type)) { - HttpContext httpContext = call.getContext(); - HttpServletRequest request = httpContext.getRequest(); - - result = PollenServices.getServiceContext(request); - } - return result; - } - } - - -} Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServices.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServices.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServices.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -1,89 +0,0 @@ -package org.chorem.pollen.rest.api; - -/* - * #%L - * Pollen :: Rest Api - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; -import org.chorem.pollen.persistence.entity.SessionToken; -import org.nuiton.web.filter.JpaTransactionFilter; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class PollenServices { - - protected static final String APPLICATION_CONTEXT_PARAMETER = "pollen_PollenApplicationContext"; - - protected static final String REQUEST_POLLEN_SERVICE_CONTEXT = "pollen_PollenServiceContext"; - - protected static final String REQUEST_POLLEN_CONNECTED_USER = "pollen_PollenConnectedUser"; - - protected static final String REQUEST_ENTITY_MANAGER = JpaTransactionFilter.JPA_TRANSACTION_REQUEST_ATTRIBUTE; - - public static PollenApplicationContext getApplicationContext(ServletContext servletContext) { - PollenApplicationContext result = (PollenApplicationContext) - servletContext.getAttribute(APPLICATION_CONTEXT_PARAMETER); - return result; - } - - public static void setApplicationContext(ServletContext servletContext, - PollenApplicationContext applicationContext) { - servletContext.setAttribute(APPLICATION_CONTEXT_PARAMETER, applicationContext); - } - - - public static PollenRestApiServiceContext getServiceContext(HttpServletRequest request) { - PollenRestApiServiceContext result = (PollenRestApiServiceContext) - request.getAttribute(REQUEST_POLLEN_SERVICE_CONTEXT); - return result; - } - - public static void setServiceContext(HttpServletRequest request, - PollenRestApiServiceContext serviceContext) { - request.setAttribute(REQUEST_POLLEN_SERVICE_CONTEXT, serviceContext); - } - - - public static PollenTopiaPersistenceContext getPersistenceContext(HttpServletRequest request) { - PollenTopiaPersistenceContext result = (PollenTopiaPersistenceContext) - request.getAttribute(REQUEST_ENTITY_MANAGER); - return result; - } - - public static SessionToken getSessionToken(HttpServletRequest request) { - SessionToken result = (SessionToken) - request.getAttribute(REQUEST_POLLEN_CONNECTED_USER); - return result; - } - - public static void setSessionToken(HttpServletRequest request, - SessionToken sessionToken) { - request.setAttribute(REQUEST_POLLEN_CONNECTED_USER, sessionToken); - } -} \ No newline at end of file Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenTopiaTransactionFilter.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenTopiaTransactionFilter.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenTopiaTransactionFilter.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -23,9 +23,9 @@ * #L% */ -import com.google.common.base.Preconditions; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.persistence.PollenPersistenceContext; import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; import org.nuiton.topia.persistence.TopiaException; import org.nuiton.web.filter.TypedTopiaTransactionFilter; @@ -34,20 +34,18 @@ import javax.servlet.ServletException; import javax.servlet.ServletRequest; -public class PollenTopiaTransactionFilter extends TypedTopiaTransactionFilter<PollenTopiaPersistenceContext> { +public class PollenTopiaTransactionFilter extends TypedTopiaTransactionFilter<PollenPersistenceContext> { private static final Log log = LogFactory.getLog(PollenTopiaTransactionFilter.class); - protected PollenApplicationContext applicationContext; - - protected PollenTopiaTransactionFilter() { - super(PollenTopiaPersistenceContext.class); + public PollenTopiaTransactionFilter() { + super(PollenPersistenceContext.class); } @Override - protected PollenTopiaPersistenceContext beginTransaction(ServletRequest request) throws TopiaException { - PollenApplicationContext applicationContext = getApplicationContext(request); + protected PollenPersistenceContext beginTransaction(ServletRequest request) throws TopiaException { + PollenRestApiApplicationContext applicationContext = PollenRestApiRequestFilter.getApplicationContext(request.getServletContext()); PollenTopiaPersistenceContext persistenceContext = applicationContext.newPersistenceContext(); return persistenceContext; } @@ -62,14 +60,4 @@ } } - protected PollenApplicationContext getApplicationContext(ServletRequest request) { - if (applicationContext == null) { - applicationContext = PollenServices.getApplicationContext( - request.getServletContext()); - - Preconditions.checkNotNull(applicationContext, "Could not find application context at ServletContext#pollen_PollenApplicationContext"); - } - return applicationContext; - } - } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthService.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthService.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -24,7 +24,7 @@ */ import org.chorem.pollen.persistence.entity.SessionToken; -import org.chorem.pollen.rest.api.PollenRestApiServiceContext; +import org.chorem.pollen.rest.api.PollenRestApiRequestContext; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.UserInvalidPasswordException; import org.debux.webmotion.server.WebMotionController; @@ -37,15 +37,15 @@ */ public class AuthService extends WebMotionController { - public SessionToken login(PollenRestApiServiceContext context, String login, String password) throws UserInvalidPasswordException, EntityNotFoundException { + public SessionToken login(PollenRestApiRequestContext context, String login, String password) throws UserInvalidPasswordException, EntityNotFoundException { return context.getAuthService().login(login, password); } - public void lostPassword(PollenRestApiServiceContext context, String login) throws EntityNotFoundException { + public void lostPassword(PollenRestApiRequestContext context, String login) throws EntityNotFoundException { context.getAuthService().lostPassword(login); } - public void logout(PollenRestApiServiceContext context, String login, String token) throws EntityNotFoundException { + public void logout(PollenRestApiRequestContext context, String login, String token) throws EntityNotFoundException { context.getAuthService().logout(login, token); } } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceService.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceService.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -24,7 +24,7 @@ */ import org.chorem.pollen.persistence.entity.Choice; -import org.chorem.pollen.rest.api.PollenRestApiServiceContext; +import org.chorem.pollen.rest.api.PollenRestApiRequestContext; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidChoiceFormException; import org.debux.webmotion.server.WebMotionController; @@ -39,28 +39,28 @@ */ public class ChoiceService extends WebMotionController { - public List<Choice> getChoices(PollenRestApiServiceContext context, String pollId) throws EntityNotFoundException { + public List<Choice> getChoices(PollenRestApiRequestContext context, String pollId) throws EntityNotFoundException { context.getSecurityService().prepareSubject((String) null); List<Choice> choices = context.getChoiceService().getChoices(pollId); return choices; } - public Choice getChoice(PollenRestApiServiceContext context, String pollId, String choiceId) throws EntityNotFoundException { + public Choice getChoice(PollenRestApiRequestContext context, String pollId, String choiceId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(choiceId); return context.getChoiceService().getChoice(pollId, choiceId); } - public Choice addChoice(PollenRestApiServiceContext context, String pollId, Choice choice) throws EntityNotFoundException, InvalidChoiceFormException { + public Choice addChoice(PollenRestApiRequestContext context, String pollId, Choice choice) throws EntityNotFoundException, InvalidChoiceFormException { context.getSecurityService().prepareSubject(pollId); return context.getChoiceService().addChoice(pollId, choice); } - public Choice editChoice(PollenRestApiServiceContext context, String pollId, Choice choice) throws EntityNotFoundException, InvalidChoiceFormException { + public Choice editChoice(PollenRestApiRequestContext context, String pollId, Choice choice) throws EntityNotFoundException, InvalidChoiceFormException { context.getSecurityService().prepareSubject(choice); return context.getChoiceService().editChoice(pollId, choice); } - public void deleteChoice(PollenRestApiServiceContext context, String pollId, String choiceId) throws EntityNotFoundException { + public void deleteChoice(PollenRestApiRequestContext context, String pollId, String choiceId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(choiceId); context.getChoiceService().deleteChoice(pollId, choiceId); } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentService.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentService.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -24,7 +24,7 @@ */ import org.chorem.pollen.persistence.entity.Comment; -import org.chorem.pollen.rest.api.PollenRestApiServiceContext; +import org.chorem.pollen.rest.api.PollenRestApiRequestContext; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidCommentFormException; import org.debux.webmotion.server.WebMotionController; @@ -39,28 +39,28 @@ */ public class CommentService extends WebMotionController { - public List<Comment> getComments(PollenRestApiServiceContext context, String pollId) throws EntityNotFoundException { + public List<Comment> getComments(PollenRestApiRequestContext context, String pollId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(pollId); List<Comment> comments = context.getCommentService().getComments(pollId); return comments; } - public Comment getComment(PollenRestApiServiceContext context, String pollId, String commentId) throws EntityNotFoundException { + public Comment getComment(PollenRestApiRequestContext context, String pollId, String commentId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(commentId); return context.getCommentService().getComment(pollId, commentId); } - public Comment addComment(PollenRestApiServiceContext context, String pollId, Comment comment) throws EntityNotFoundException, InvalidCommentFormException { + public Comment addComment(PollenRestApiRequestContext context, String pollId, Comment comment) throws EntityNotFoundException, InvalidCommentFormException { context.getSecurityService().prepareSubject(pollId); return context.getCommentService().addComment(pollId, comment); } - public Comment editComment(PollenRestApiServiceContext context, String pollId, Comment comment) throws EntityNotFoundException, InvalidCommentFormException { + public Comment editComment(PollenRestApiRequestContext context, String pollId, Comment comment) throws EntityNotFoundException, InvalidCommentFormException { context.getSecurityService().prepareSubject(comment); return context.getCommentService().editComment(pollId, comment); } - public void deleteComment(PollenRestApiServiceContext context, String pollId, String commentId) throws EntityNotFoundException { + public void deleteComment(PollenRestApiRequestContext context, String pollId, String commentId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(commentId); context.getCommentService().deleteComment(pollId, commentId); } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListService.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListService.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -25,7 +25,7 @@ import org.chorem.pollen.persistence.entity.FavoriteList; import org.chorem.pollen.persistence.entity.FavoriteListMember; -import org.chorem.pollen.rest.api.PollenRestApiServiceContext; +import org.chorem.pollen.rest.api.PollenRestApiRequestContext; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.FavoriteListImportException; import org.chorem.pollen.services.exception.InvalidFavoriteListFormException; @@ -43,53 +43,53 @@ */ public class FavoriteListService extends WebMotionController { - public List<FavoriteList> getFavoriteLists(PollenRestApiServiceContext context, String userId) throws EntityNotFoundException { + public List<FavoriteList> getFavoriteLists(PollenRestApiRequestContext context, String userId) throws EntityNotFoundException { List<FavoriteList> favoriteLists = context.getFavoriteListService().getFavoriteLists(userId); return favoriteLists; } - public FavoriteList getFavoriteList(PollenRestApiServiceContext context, String userId, String favoriteListId) throws EntityNotFoundException { + public FavoriteList getFavoriteList(PollenRestApiRequestContext context, String userId, String favoriteListId) throws EntityNotFoundException { return context.getFavoriteListService().getFavoriteList(userId, favoriteListId); } - public FavoriteList createFavoriteList(PollenRestApiServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, InvalidFavoriteListFormException { + public FavoriteList createFavoriteList(PollenRestApiRequestContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, InvalidFavoriteListFormException { return context.getFavoriteListService().createFavoriteList(userId, favoriteList); } - public FavoriteList editFavoriteList(PollenRestApiServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, InvalidFavoriteListFormException { + public FavoriteList editFavoriteList(PollenRestApiRequestContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, InvalidFavoriteListFormException { return context.getFavoriteListService().editFavoriteList(userId, favoriteList); } - public void deleteFavoriteList(PollenRestApiServiceContext context, String userId, String favoriteListId) throws EntityNotFoundException { + public void deleteFavoriteList(PollenRestApiRequestContext context, String userId, String favoriteListId) throws EntityNotFoundException { context.getFavoriteListService().deleteFavoriteList(userId, favoriteListId); } - public int importFavoriteListMembersFromCsv(PollenRestApiServiceContext context, String userId, String favoriteListId, File csvFile) throws EntityNotFoundException, FavoriteListImportException { + public int importFavoriteListMembersFromCsv(PollenRestApiRequestContext context, String userId, String favoriteListId, File csvFile) throws EntityNotFoundException, FavoriteListImportException { return context.getFavoriteListService().importFavoriteListMembersFromCsv(userId, favoriteListId, csvFile); } - public int importFavoriteListMembersFromLdap(PollenRestApiServiceContext context, String userId, String favoriteListId, String ldap) throws EntityNotFoundException, FavoriteListImportException { + public int importFavoriteListMembersFromLdap(PollenRestApiRequestContext context, String userId, String favoriteListId, String ldap) throws EntityNotFoundException, FavoriteListImportException { return context.getFavoriteListService().importFavoriteListMembersFromLdap(userId, favoriteListId, ldap); } - public List<FavoriteListMember> getMembers(PollenRestApiServiceContext context, String userId, String favoriteListId) throws EntityNotFoundException { + public List<FavoriteListMember> getMembers(PollenRestApiRequestContext context, String userId, String favoriteListId) throws EntityNotFoundException { List<FavoriteListMember> members = context.getFavoriteListService().getFavoriteListMembers(userId, favoriteListId); return members; } - public FavoriteListMember getMember(PollenRestApiServiceContext context, String userId, String favoriteListId, String memberId) throws EntityNotFoundException { + public FavoriteListMember getMember(PollenRestApiRequestContext context, String userId, String favoriteListId, String memberId) throws EntityNotFoundException { return context.getFavoriteListService().getFavoriteListMember(userId, favoriteListId, memberId); } - public FavoriteListMember addMember(PollenRestApiServiceContext context, String userId, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, InvalidFavoriteListMemberFormException { + public FavoriteListMember addMember(PollenRestApiRequestContext context, String userId, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, InvalidFavoriteListMemberFormException { return context.getFavoriteListService().addFavoriteListMember(userId, favoriteListId, member); } - public FavoriteListMember editMember(PollenRestApiServiceContext context, String userId, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, InvalidFavoriteListMemberFormException { + public FavoriteListMember editMember(PollenRestApiRequestContext context, String userId, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, InvalidFavoriteListMemberFormException { return context.getFavoriteListService().editFavoriteListMember(userId, favoriteListId, member); } - public void removeMember(PollenRestApiServiceContext context, String userId, String favoriteListId, String memberId) throws EntityNotFoundException { + public void removeMember(PollenRestApiRequestContext context, String userId, String favoriteListId, String memberId) throws EntityNotFoundException { context.getFavoriteListService().removeFavoriteListMember(userId, favoriteListId, memberId); } } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -25,7 +25,7 @@ import org.chorem.pollen.persistence.entity.ChoiceType; import org.chorem.pollen.persistence.entity.Poll; -import org.chorem.pollen.rest.api.PollenRestApiServiceContext; +import org.chorem.pollen.rest.api.PollenRestApiRequestContext; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidPollFormException; import org.debux.webmotion.server.WebMotionController; @@ -41,60 +41,60 @@ */ public class PollService extends WebMotionController { - public Poll getNewPoll(PollenRestApiServiceContext context, String userId, ChoiceType choiceType) throws EntityNotFoundException { + public Poll getNewPoll(PollenRestApiRequestContext context, String userId, ChoiceType choiceType) throws EntityNotFoundException { return context.getPollService().getNewPoll(userId, choiceType); } - public Set<Poll> getPolls(PollenRestApiServiceContext context, String userId) throws EntityNotFoundException { + public Set<Poll> getPolls(PollenRestApiRequestContext context, String userId) throws EntityNotFoundException { Set<Poll> polls = context.getPollService().getPolls(userId); return polls; } - public Set<Poll> getCreatedPolls(PollenRestApiServiceContext context, String userId) throws EntityNotFoundException { + public Set<Poll> getCreatedPolls(PollenRestApiRequestContext context, String userId) throws EntityNotFoundException { Set<Poll> polls = context.getPollService().getCreatedPolls(userId); return polls; } - public Set<Poll> getInvitedPolls(PollenRestApiServiceContext context, String userId) throws EntityNotFoundException { + public Set<Poll> getInvitedPolls(PollenRestApiRequestContext context, String userId) throws EntityNotFoundException { Set<Poll> polls = context.getPollService().getInvitedPolls(userId); return polls; } - public Set<Poll> getParticipatedPolls(PollenRestApiServiceContext context, String userId) throws EntityNotFoundException { + public Set<Poll> getParticipatedPolls(PollenRestApiRequestContext context, String userId) throws EntityNotFoundException { Set<Poll> polls = context.getPollService().getParticipatedPolls(userId); return polls; } - public Poll getPoll(PollenRestApiServiceContext context, String pollId) throws EntityNotFoundException { + public Poll getPoll(PollenRestApiRequestContext context, String pollId) throws EntityNotFoundException { context.getSecurityService().prepareSubject((String) null); return context.getPollService().getPoll(pollId); } - public Poll createPoll(PollenRestApiServiceContext context, String userId, Poll poll) throws EntityNotFoundException, InvalidPollFormException { + public Poll createPoll(PollenRestApiRequestContext context, String userId, Poll poll) throws EntityNotFoundException, InvalidPollFormException { return context.getPollService().createPoll(userId, poll); } - public Poll editPoll(PollenRestApiServiceContext context, Poll poll) throws EntityNotFoundException, InvalidPollFormException { + public Poll editPoll(PollenRestApiRequestContext context, Poll poll) throws EntityNotFoundException, InvalidPollFormException { context.getSecurityService().prepareSubject(poll); return context.getPollService().editPoll(poll); } - public void deletePoll(PollenRestApiServiceContext context, String pollId) throws EntityNotFoundException { + public void deletePoll(PollenRestApiRequestContext context, String pollId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(pollId); context.getPollService().deletePoll(pollId); } - public Poll clonePoll(PollenRestApiServiceContext context, String pollId) throws EntityNotFoundException { + public Poll clonePoll(PollenRestApiRequestContext context, String pollId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(pollId); return context.getPollService().clonePoll(pollId); } - public File closePoll(PollenRestApiServiceContext context, String pollId) throws EntityNotFoundException { + public File closePoll(PollenRestApiRequestContext context, String pollId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(pollId); return context.getPollService().closePoll(pollId); } - public File exportPoll(PollenRestApiServiceContext context, String pollId) throws EntityNotFoundException { + public File exportPoll(PollenRestApiRequestContext context, String pollId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(pollId); return context.getPollService().exportPoll(pollId); } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserService.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserService.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -24,7 +24,7 @@ */ import org.chorem.pollen.persistence.entity.PollenUser; -import org.chorem.pollen.rest.api.PollenRestApiServiceContext; +import org.chorem.pollen.rest.api.PollenRestApiRequestContext; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidPollenUserFormException; import org.chorem.pollen.services.exception.UserInvalidEmailActivationTokenException; @@ -41,34 +41,34 @@ */ public class PollenUserService extends WebMotionController { - public List<PollenUser> getUsers(PollenRestApiServiceContext context) { + public List<PollenUser> getUsers(PollenRestApiRequestContext context) { List<PollenUser> users = context.getPollenUserService().getUsers(); return users; } - public PollenUser getUser(PollenRestApiServiceContext context, String userId) throws EntityNotFoundException { + public PollenUser getUser(PollenRestApiRequestContext context, String userId) throws EntityNotFoundException { return context.getPollenUserService().getUser(userId); } - public PollenUser createUser(PollenRestApiServiceContext context, + public PollenUser createUser(PollenRestApiRequestContext context, PollenUser user, boolean generatePassword) throws EntityNotFoundException, InvalidPollenUserFormException { return context.getPollenUserService().createUser(user, generatePassword); } - public PollenUser editUser(PollenRestApiServiceContext context, + public PollenUser editUser(PollenRestApiRequestContext context, PollenUser user) throws EntityNotFoundException, InvalidPollenUserFormException { return context.getPollenUserService().editUser(user); } - public void validateUserEmail(PollenRestApiServiceContext context, + public void validateUserEmail(PollenRestApiRequestContext context, String userId, String token) throws EntityNotFoundException, UserInvalidEmailActivationTokenException { context.getPollenUserService().validateUserEmail(userId, token); } - public void changePassword(PollenRestApiServiceContext context, + public void changePassword(PollenRestApiRequestContext context, String userId, String oldPassword, String newPassword) throws EntityNotFoundException, UserInvalidPasswordException { Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingService.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingService.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -23,7 +23,7 @@ * #L% */ -import org.chorem.pollen.rest.api.PollenRestApiServiceContext; +import org.chorem.pollen.rest.api.PollenRestApiRequestContext; import org.chorem.pollen.services.PollResult; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.debux.webmotion.server.WebMotionController; @@ -36,7 +36,7 @@ */ public class VoteCountingService extends WebMotionController { - public PollResult getResult(PollenRestApiServiceContext context, String pollId) throws EntityNotFoundException { + public PollResult getResult(PollenRestApiRequestContext context, String pollId) throws EntityNotFoundException { return context.getVoteCountingService().getResult(pollId); } } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteService.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteService.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -24,7 +24,7 @@ */ import org.chorem.pollen.persistence.entity.Vote; -import org.chorem.pollen.rest.api.PollenRestApiServiceContext; +import org.chorem.pollen.rest.api.PollenRestApiRequestContext; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidVoteFormException; import org.debux.webmotion.server.WebMotionController; @@ -39,28 +39,28 @@ */ public class VoteService extends WebMotionController { - public List<Vote> getVotes(PollenRestApiServiceContext context, String pollId) throws EntityNotFoundException { + public List<Vote> getVotes(PollenRestApiRequestContext context, String pollId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(pollId); List<Vote> votes = context.getVoteService().getVotes(pollId); return votes; } - public Vote getVote(PollenRestApiServiceContext context, String pollId, String voteId) throws EntityNotFoundException { + public Vote getVote(PollenRestApiRequestContext context, String pollId, String voteId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(voteId); return context.getVoteService().getVote(pollId, voteId); } - public Vote addVote(PollenRestApiServiceContext context, String pollId, Vote vote) throws EntityNotFoundException, InvalidVoteFormException { + public Vote addVote(PollenRestApiRequestContext context, String pollId, Vote vote) throws EntityNotFoundException, InvalidVoteFormException { context.getSecurityService().prepareSubject(pollId); return context.getVoteService().addVote(pollId, vote); } - public Vote editVote(PollenRestApiServiceContext context, String pollId, Vote vote) throws EntityNotFoundException, InvalidVoteFormException { + public Vote editVote(PollenRestApiRequestContext context, String pollId, Vote vote) throws EntityNotFoundException, InvalidVoteFormException { context.getSecurityService().prepareSubject(vote); return context.getVoteService().editVote(pollId, vote); } - public void deleteVote(PollenRestApiServiceContext context, String pollId, String voteId) throws EntityNotFoundException { + public void deleteVote(PollenRestApiRequestContext context, String pollId, String voteId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(voteId); context.getVoteService().deleteVote(pollId, voteId); } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -25,7 +25,7 @@ import org.chorem.pollen.persistence.entity.VoterList; import org.chorem.pollen.persistence.entity.VoterListMember; -import org.chorem.pollen.rest.api.PollenRestApiServiceContext; +import org.chorem.pollen.rest.api.PollenRestApiRequestContext; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidVoterListFormException; import org.chorem.pollen.services.exception.InvalidVoterListMemberFormException; @@ -42,58 +42,58 @@ */ public class VoterListService extends WebMotionController { - public VoterList importFavoriteList(PollenRestApiServiceContext context, String userId, String pollId, String favoriteListId) throws EntityNotFoundException { + public VoterList importFavoriteList(PollenRestApiRequestContext context, String userId, String pollId, String favoriteListId) throws EntityNotFoundException { return context.getVoterListService().importFavoriteList(userId, pollId, favoriteListId); } - public List<VoterList> getVoterLists(PollenRestApiServiceContext context, String pollId) throws EntityNotFoundException { + public List<VoterList> getVoterLists(PollenRestApiRequestContext context, String pollId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(pollId); List<VoterList> voterLists = context.getVoterListService().getVoterLists(pollId); return voterLists; } - public VoterList getVoterList(PollenRestApiServiceContext context, String pollId, String voterListId) throws EntityNotFoundException { + public VoterList getVoterList(PollenRestApiRequestContext context, String pollId, String voterListId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(voterListId); return context.getVoterListService().getVoterList(pollId, voterListId); } - public VoterList createVoterList(PollenRestApiServiceContext context, String pollId, VoterList voterList) throws EntityNotFoundException, InvalidVoterListFormException { + public VoterList createVoterList(PollenRestApiRequestContext context, String pollId, VoterList voterList) throws EntityNotFoundException, InvalidVoterListFormException { context.getSecurityService().prepareSubject(pollId); return context.getVoterListService().addVoterList(pollId, voterList); } - public VoterList editVoterList(PollenRestApiServiceContext context, String pollId, VoterList voterList) throws EntityNotFoundException, InvalidVoterListFormException { + public VoterList editVoterList(PollenRestApiRequestContext context, String pollId, VoterList voterList) throws EntityNotFoundException, InvalidVoterListFormException { context.getSecurityService().prepareSubject(voterList); return context.getVoterListService().editVoterList(pollId, voterList); } - public void deleteVoterList(PollenRestApiServiceContext context, String pollId, String voterListId) throws EntityNotFoundException { + public void deleteVoterList(PollenRestApiRequestContext context, String pollId, String voterListId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(voterListId); context.getVoterListService().deleteVoterList(pollId, voterListId); } - public Set<VoterListMember> getMembers(PollenRestApiServiceContext context, String pollId, String voterListId) throws EntityNotFoundException { + public Set<VoterListMember> getMembers(PollenRestApiRequestContext context, String pollId, String voterListId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(voterListId); Set<VoterListMember> members = context.getVoterListService().getVoterListMembers(pollId, voterListId); return members; } - public VoterListMember getMember(PollenRestApiServiceContext context, String pollId, String voterListId, String memberId) throws EntityNotFoundException { + public VoterListMember getMember(PollenRestApiRequestContext context, String pollId, String voterListId, String memberId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(memberId); return context.getVoterListService().getVoterListMember(pollId, voterListId, memberId); } - public VoterListMember addMember(PollenRestApiServiceContext context, String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException, InvalidVoterListMemberFormException { + public VoterListMember addMember(PollenRestApiRequestContext context, String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException, InvalidVoterListMemberFormException { context.getSecurityService().prepareSubject(member); return context.getVoterListService().addVoterListMember(pollId, voterListId, member); } - public VoterListMember editMember(PollenRestApiServiceContext context, String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException, InvalidVoterListMemberFormException { + public VoterListMember editMember(PollenRestApiRequestContext context, String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException, InvalidVoterListMemberFormException { context.getSecurityService().prepareSubject(member); return context.getVoterListService().editVoterListMember(pollId, voterListId, member); } - public void deleteMember(PollenRestApiServiceContext context, String pollId, String voterListId, String memberId) throws EntityNotFoundException { + public void deleteMember(PollenRestApiRequestContext context, String pollId, String voterListId, String memberId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(memberId); context.getVoterListService().deleteVoterListMember(pollId, voterListId, memberId); } Modified: trunk/pollen-rest-api/src/main/resources/mapping =================================================================== --- trunk/pollen-rest-api/src/main/resources/mapping 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-rest-api/src/main/resources/mapping 2014-04-27 16:47:39 UTC (rev 3880) @@ -2,11 +2,11 @@ package.filters=org.chorem.pollen.rest.api package.actions=org.chorem.pollen.rest.api.v1 package.errors=org.chorem.pollen.rest.api.v1 -server.listener.class=org.chorem.pollen.rest.api.PollenServiceListener +server.listener.class=org.chorem.pollen.rest.api.PollenRestApiApplicationListener default.render=org.chorem.pollen.rest.api.PollenRender [filters] -* /* PollenServiceContextFilter.inject +* /* PollenRestApiRequestFilter.inject #- une fois un object lié à PollenUser, c'est immuable. Modified: trunk/pollen-rest-api/src/main/webapp/WEB-INF/web.xml =================================================================== --- trunk/pollen-rest-api/src/main/webapp/WEB-INF/web.xml 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-rest-api/src/main/webapp/WEB-INF/web.xml 2014-04-27 16:47:39 UTC (rev 3880) @@ -31,14 +31,14 @@ <display-name>Pollen REST Api</display-name> <filter> - <filter-name>jpaTransaction</filter-name> + <filter-name>topiaTransaction</filter-name> <filter-class> - org.chorem.pollen.rest.api.PollenJpaTransactionFilter + org.chorem.pollen.rest.api.PollenTopiaTransactionFilter </filter-class> </filter> <filter-mapping> - <filter-name>jpaTransaction</filter-name> + <filter-name>topiaTransaction</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> Modified: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java =================================================================== --- trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -23,25 +23,17 @@ * #L% */ -import org.apache.commons.lang3.SystemUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.persistence.PollenTopiaApplicationContext; import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; import org.chorem.pollen.services.PollenFixtures; import org.chorem.pollen.services.PollenServiceContext; import org.chorem.pollen.services.service.FixturesService; import org.debux.webmotion.unittest.WebMotionJUnit; -import org.hibernate.cfg.Environment; import org.junit.After; +import org.junit.Before; -import java.io.File; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; import java.util.Locale; -import java.util.Map; -import java.util.UUID; /** * TODO @@ -54,25 +46,23 @@ /** Logger. */ private static final Log log = LogFactory.getLog(AbstractPollenRestApiTest.class); - protected PollenApplicationContext applicationContext; + protected PollenFixtures fixtures; - protected List<PollenTopiaPersistenceContext> openedTransactions = new LinkedList<>(); + @Before + public void launchServer() throws Exception { - protected PollenFixtures fixtures; + PollenRestApiApplicationContext applicationContext = FakePollenRestApiApplicationContext.newApplicationContext(); + applicationContext.init(); + PollenRestApiApplicationContext.setApplicationContext(applicationContext); + super.launchServer(); + } + @After public void tearDown() { - for (PollenTopiaPersistenceContext openedTransaction : openedTransactions) { + PollenRestApiApplicationContext applicationContext = PollenRestApiApplicationContext.getApplicationContext(); - if (log.isTraceEnabled()) { - log.trace("closing transaction " + openedTransaction); - } - - openedTransaction.closeContext(); - - } - if (applicationContext != null) { if (log.isTraceEnabled()) { @@ -82,117 +72,13 @@ } } - protected PollenTopiaApplicationContext newTopiaApplicationContext(String dataBase) { - - Map<String, String> hibernateH2Config = new HashMap<>(); - - hibernateH2Config.putAll(PollenApplicationContext.getApplicationConfig().getTopiaProperties()); - - hibernateH2Config.put(Environment.DRIVER, org.h2.Driver.class.getName()); - hibernateH2Config.put(Environment.DIALECT, org.hibernate.dialect.H2Dialect.class.getName()); - hibernateH2Config.put(Environment.USER, "sa"); - hibernateH2Config.put(Environment.PASS, "sa"); - hibernateH2Config.put(Environment.HBM2DDL_AUTO, "update"); - - File tempDirFile = SystemUtils.getJavaIoTmpDir(); - - File databaseFile = new File(tempDirFile, dataBase); - - String h2dataPath = databaseFile.getAbsolutePath() + File.separator + "h2data"; - - String jdbcUrl = "jdbc:h2:file:" + h2dataPath; - - hibernateH2Config.put(Environment.URL, jdbcUrl); - - if (log.isTraceEnabled()) { - log.trace("will store H2 data in " + h2dataPath); - log.trace("allTopiaParameters = " + hibernateH2Config); - } - - if (log.isDebugEnabled()) { - log.debug("jdbc url is\n" + jdbcUrl); - } - - PollenTopiaApplicationContext applicationContext = new PollenTopiaApplicationContext(hibernateH2Config); - - if (log.isTraceEnabled()) { - log.trace("created root context " + applicationContext); - } - - return applicationContext; - } - - public PollenApplicationContext getApplicationContext() { - if (applicationContext == null) { - - // prepare db - - String databaseName = UUID.randomUUID().toString(); - - PollenTopiaApplicationContext pollenTopiaApplicationContext = newTopiaApplicationContext(databaseName); - - PollenApplicationContext.setTopiaApplicationContext(pollenTopiaApplicationContext); - - applicationContext = - new PollenApplicationContext() { - - - @Override - public PollenServiceContext newServiceContext(PollenTopiaPersistenceContext persistenceContext, Locale locale) { - - FakePollenServiceContext serviceContext = new FakePollenServiceContext(); - serviceContext.setPersistenceContext(persistenceContext); - serviceContext.setPollenServiceConfig(applicationConfig); - - return serviceContext; - - } - - @Override - public PollenTopiaPersistenceContext newPersistenceContext() { - PollenTopiaPersistenceContext pollenTopiaPersistenceContext = super.newPersistenceContext(); - openedTransactions.add(pollenTopiaPersistenceContext); - return pollenTopiaPersistenceContext; - } - }; - } - return applicationContext; - } - - protected PollenTopiaPersistenceContext newPersistenceContext() { - - if (applicationContext == null) { - - applicationContext = getApplicationContext(); - } - - PollenTopiaPersistenceContext persistenceContext; - - persistenceContext = applicationContext.newPersistenceContext(); - - if (log.isTraceEnabled()) { - log.trace("opened transaction " + persistenceContext); - } - - openedTransactions.add(persistenceContext); - - return persistenceContext; - - } - - protected PollenServiceContext getServiceContext() { - - PollenTopiaPersistenceContext entityManager = getApplicationContext().newPersistenceContext(); - - PollenServiceContext result = applicationContext.newServiceContext(entityManager, Locale.FRANCE); - return result; - } - protected void loadFixtures(String fixturesSetName) { + PollenRestApiApplicationContext applicationContext = PollenRestApiApplicationContext.getApplicationContext(); + PollenTopiaPersistenceContext entityManager = applicationContext.newPersistenceContext(); + PollenServiceContext pollenServiceContext = applicationContext.newServiceContext(entityManager, Locale.FRANCE); - FixturesService fixturesService = getServiceContext().newService(FixturesService.class); - + FixturesService fixturesService = pollenServiceContext.newService(FixturesService.class); fixtures = fixturesService.loadFixtures(fixturesSetName); } @@ -203,8 +89,4 @@ } -// @Before -// public void launchServer() throws Exception { -// runServer(); -// } } Added: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/FakePollenRestApiApplicationContext.java =================================================================== --- trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/FakePollenRestApiApplicationContext.java (rev 0) +++ trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/FakePollenRestApiApplicationContext.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -0,0 +1,123 @@ +package org.chorem.pollen.rest.api; + +import org.apache.commons.lang3.SystemUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.persistence.PollenPersistenceContext; +import org.chorem.pollen.persistence.PollenTopiaApplicationContext; +import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.config.PollenServiceConfig; +import org.hibernate.cfg.Environment; + +import java.io.File; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.UUID; + +/** + * Created on 4/27/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.0 + */ +public class FakePollenRestApiApplicationContext extends PollenRestApiApplicationContext { + + /** Logger. */ + private static final Log log = LogFactory.getLog(FakePollenRestApiApplicationContext.class); + + protected List<PollenTopiaPersistenceContext> openedTransactions = new LinkedList<>(); + + public static PollenRestApiApplicationContext newApplicationContext() { + PollenServiceConfig applicationConfig = new PollenServiceConfig(); + PollenTopiaApplicationContext pollenTopiaApplicationContext = newTopiaApplicationContext(applicationConfig, UUID.randomUUID().toString()); + PollenRestApiApplicationContext result = new FakePollenRestApiApplicationContext(applicationConfig, pollenTopiaApplicationContext); + return result; + } + + public FakePollenRestApiApplicationContext(PollenServiceConfig applicationConfig, PollenTopiaApplicationContext pollenTopiaApplicationContext) { + + super(applicationConfig, pollenTopiaApplicationContext); + } + + @Override + public PollenServiceContext newServiceContext(PollenPersistenceContext persistenceContext, Locale locale) { + + FakePollenServiceContext serviceContext = new FakePollenServiceContext(); + serviceContext.setPersistenceContext(persistenceContext); + serviceContext.setPollenServiceConfig(getApplicationConfig()); + serviceContext.setTopiaApplicationContext(getTopiaApplicationContext()); + serviceContext.setLocale(locale); + + return serviceContext; + } + + @Override + public PollenTopiaPersistenceContext newPersistenceContext() { + PollenTopiaPersistenceContext pollenTopiaPersistenceContext = super.newPersistenceContext(); + openedTransactions.add(pollenTopiaPersistenceContext); + return pollenTopiaPersistenceContext; + } + + @Override + public void close() { + if (!closed.get()) { + + for (PollenTopiaPersistenceContext openedTransaction : openedTransactions) { + + if (log.isTraceEnabled()) { + log.trace("closing transaction " + openedTransaction); + } + + if (!openedTransaction.isClosed()) { + openedTransaction.closeContext(); + } + } + openedTransactions.clear(); + } + super.close(); + } + + protected static PollenTopiaApplicationContext newTopiaApplicationContext(PollenServiceConfig applicationConfig, String dataBase) { + + Map<String, String> hibernateH2Config = new HashMap<>(); + + hibernateH2Config.putAll(applicationConfig.getTopiaProperties()); + + hibernateH2Config.put(Environment.DRIVER, org.h2.Driver.class.getName()); + hibernateH2Config.put(Environment.DIALECT, org.hibernate.dialect.H2Dialect.class.getName()); + hibernateH2Config.put(Environment.USER, "sa"); + hibernateH2Config.put(Environment.PASS, "sa"); + hibernateH2Config.put(Environment.HBM2DDL_AUTO, "update"); + + File tempDirFile = SystemUtils.getJavaIoTmpDir(); + + File databaseFile = new File(tempDirFile, dataBase); + + String h2dataPath = databaseFile.getAbsolutePath() + File.separator + "h2data"; + + String jdbcUrl = "jdbc:h2:file:" + h2dataPath; + + hibernateH2Config.put(Environment.URL, jdbcUrl); + + if (log.isTraceEnabled()) { + log.trace("will store H2 data in " + h2dataPath); + log.trace("allTopiaParameters = " + hibernateH2Config); + } + + if (log.isDebugEnabled()) { + log.debug("jdbc url is\n" + jdbcUrl); + } + + PollenTopiaApplicationContext applicationContext = new PollenTopiaApplicationContext(hibernateH2Config); + + if (log.isTraceEnabled()) { + log.trace("created root context " + applicationContext); + } + + return applicationContext; + } +} Property changes on: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/FakePollenRestApiApplicationContext.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Deleted: trunk/pollen-rest-api/src/test/resources/pollen.properties =================================================================== --- trunk/pollen-rest-api/src/test/resources/pollen.properties 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-rest-api/src/test/resources/pollen.properties 2014-04-27 16:47:39 UTC (rev 3880) @@ -1,31 +0,0 @@ -### -# #%L -# Pollen :: Rest Api -# $Id$ -# $HeadURL$ -# %% -# Copyright (C) 2009 - 2013 CodeLutin -# %% -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# #L% -### -javax.persistence.jdbc.driver=org.h2.Driver -javax.persistence.jdbc.url=jdbc:h2:file:target/pollen/h2data -javax.persistence.jdbc.user=sa -javax.persistence.jdbc.password= -hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.hbm2ddl.auto=update -hibernate.show_sql=false -hibernate.format_sql=true -hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy Modified: trunk/pollen-services/pom.xml =================================================================== --- trunk/pollen-services/pom.xml 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-services/pom.xml 2014-04-27 16:47:39 UTC (rev 3880) @@ -83,16 +83,6 @@ </dependency> <dependency> - <groupId>org.nuiton.jpa</groupId> - <artifactId>nuiton-jpa-api</artifactId> - </dependency> - - <dependency> - <groupId>org.nuiton.jpa</groupId> - <artifactId>nuiton-jpa-junit</artifactId> - </dependency> - - <dependency> <groupId>org.nuiton</groupId> <artifactId>nuiton-utils</artifactId> </dependency> Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -28,7 +28,8 @@ import org.apache.commons.codec.binary.Hex; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.StringUtils; -import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; +import org.chorem.pollen.persistence.PollenPersistenceContext; +import org.chorem.pollen.persistence.PollenTopiaApplicationContext; import org.chorem.pollen.services.config.PollenServiceConfig; import org.nuiton.util.StringUtil; @@ -42,17 +43,19 @@ protected PollenServiceConfig pollenServiceConfig; - protected PollenTopiaPersistenceContext persistenceContext; + protected PollenPersistenceContext persistenceContext; protected PollenSecurityContext securityContext; protected Locale locale; + private PollenTopiaApplicationContext topiaApplicationContext; + public void setPollenServiceConfig(PollenServiceConfig pollenServiceConfig) { this.pollenServiceConfig = pollenServiceConfig; } - public void setPersistenceContext(PollenTopiaPersistenceContext persistenceContext) { + public void setPersistenceContext(PollenPersistenceContext persistenceContext) { this.persistenceContext = persistenceContext; } @@ -60,6 +63,15 @@ this.securityContext = securityContext; } + public void setTopiaApplicationContext(PollenTopiaApplicationContext topiaApplicationContext) { + this.topiaApplicationContext = topiaApplicationContext; + } + + @Override + public PollenTopiaApplicationContext getTopiaApplicationContext() { + return topiaApplicationContext; + } + public void setLocale(Locale locale) { this.locale = locale; } @@ -90,7 +102,7 @@ } @Override - public PollenTopiaPersistenceContext getPersistenceContext() { + public PollenPersistenceContext getPersistenceContext() { return persistenceContext; } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -23,7 +23,8 @@ * #L% */ -import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; +import org.chorem.pollen.persistence.PollenPersistenceContext; +import org.chorem.pollen.persistence.PollenTopiaApplicationContext; import org.chorem.pollen.services.config.PollenServiceConfig; import java.util.Date; @@ -43,8 +44,10 @@ void setSecurityContext(PollenSecurityContext securityContext); - PollenTopiaPersistenceContext getPersistenceContext(); + PollenTopiaApplicationContext getTopiaApplicationContext(); + PollenPersistenceContext getPersistenceContext(); + PollenServiceConfig getPollenServiceConfig(); <E extends PollenService> E newService(Class<E> serviceClass); Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/EntityNotFoundException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/EntityNotFoundException.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/EntityNotFoundException.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -37,19 +37,37 @@ protected final Class<? extends TopiaEntity> entityType; - protected final String entityId; + protected final String property; + protected final String propertyValue; + public EntityNotFoundException(Class<? extends TopiaEntity> entityType, - String entityId) { + String propertyValue) { + this(entityType, TopiaEntity.PROPERTY_TOPIA_ID, propertyValue); + } + + public EntityNotFoundException(Class<? extends TopiaEntity> entityType, + String property, + String propertyValue) { this.entityType = entityType; - this.entityId = entityId; + this.property = property; + this.propertyValue = propertyValue; } public Class<? extends TopiaEntity> getEntityType() { return entityType; } - public String getEntityId() { - return entityId; + public String getProperty() { + return property; } + + public String getPropertyValue() { + return propertyValue; + } + + @Override + public String getMessage() { + return "Could not find entity (property: " + property + " = " + propertyValue + ") of type: " + entityType; + } } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AuthService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AuthService.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AuthService.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -57,7 +57,7 @@ } // Create a new session Token - SessionTokenTopiaDao dao = getPersistenceContext().getSessionTokenDao(); + SessionTokenTopiaDao dao = getSessionTokenDao(); SessionToken sessionToken = dao.newInstance(); String token = serviceContext.generateToken(); @@ -67,7 +67,7 @@ sessionToken.setCreationDate(serviceContext.getNow()); dao.create(sessionToken); - getPersistenceContext().commit(); + commit(); return sessionToken; } @@ -75,8 +75,6 @@ public void lostPassword(String login) throws EntityNotFoundException { Preconditions.checkNotNull(login); - PollenUserTopiaDao dao = getPersistenceContext().getPollenUserDao(); - PollenUser user = getUserService().getUserByLogin(login); // Generate a new password @@ -84,7 +82,7 @@ String encodedPassword = serviceContext.encodePassword(newPassword); user.setPassword(encodedPassword); // dao.update(user); - getPersistenceContext().commit(); + commit(); //TODO Notifiy Password changed if (log.isDebugEnabled()) { @@ -98,19 +96,18 @@ getUserService().getUserByLogin(login); + SessionTokenTopiaDao dao = getSessionTokenDao(); - SessionTokenTopiaDao dao = getPersistenceContext().getSessionTokenDao(); - SessionToken sessionToken = dao.findByTopiaId(token); checkEntityExists(SessionToken.class, sessionToken, token); dao.delete(sessionToken); - getPersistenceContext().commit(); + commit(); } public SessionToken getUserByAuth(String authParam) throws InvalidSessionTokenException { - SessionToken sessionToken = getPersistenceContext().getSessionTokenDao().findByTopiaId(authParam); + SessionToken sessionToken = getSessionTokenDao().findByTopiaId(authParam); if (sessionToken == null) { throw new InvalidSessionTokenException(); } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -75,8 +75,8 @@ Choice result = saveChoice(poll, choice); - getPersistenceContext().getPollDao().update(poll); - getPersistenceContext().commit(); + getPollDao().update(poll); + commit(); //TODO Notify Choice added return result; } @@ -92,8 +92,8 @@ Choice result = saveChoice(poll, choice); - getPersistenceContext().getChoiceDao().update(choice); - getPersistenceContext().commit(); + getChoiceDao().update(choice); + commit(); //TODO Notify Choice edited return result; } @@ -108,8 +108,8 @@ poll.removeChoice(choice); - getPersistenceContext().getPollDao().update(poll); - getPersistenceContext().commit(); + getPollDao().update(poll); + commit(); //TODO Notify Choice deleted } @@ -123,7 +123,7 @@ protected Choice saveChoice(Poll poll, Choice choice) throws EntityNotFoundException { - ChoiceTopiaDao choiceDao = getPersistenceContext().getChoiceDao(); + ChoiceTopiaDao choiceDao = getChoiceDao(); boolean choiceExists = choice.isPersisted(); Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -32,7 +32,6 @@ import org.chorem.pollen.persistence.entity.PollenPrincipal; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidCommentFormException; -import org.nuiton.jpa.api.JpaEntities; import java.util.List; @@ -71,8 +70,8 @@ Comment result = saveComment(poll, comment); - getPersistenceContext().getPollDao().update(poll); - getPersistenceContext().commit(); + getPollDao().update(poll); + commit(); return result; } @@ -88,8 +87,8 @@ Comment result = saveComment(poll, comment); - getPersistenceContext().getCommentDao().update(comment); - getPersistenceContext().commit(); + getCommentDao().update(comment); + commit(); return result; } @@ -105,8 +104,8 @@ poll.removeComment(comment); - getPersistenceContext().getPollDao().update(poll); - getPersistenceContext().commit(); + getPollDao().update(poll); + commit(); } protected Comment getComment(Poll poll, String commentId) throws EntityNotFoundException { @@ -144,7 +143,7 @@ toSave = getComment(poll, comment.getTopiaId()); } else { - toSave = getPersistenceContext().getCommentDao().newInstance(); + toSave = getCommentDao().newInstance(); toSave.setPostDate(serviceContext.getNow()); // -- author -- // Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -94,13 +94,13 @@ checkFavoriteListForm(user, favoriteList); - FavoriteList toSave = getPersistenceContext().getFavoriteListDao().newInstance(); + FavoriteList toSave = getFavoriteListDao().newInstance(); copyFavoriteList(favoriteList, toSave); user.addFavoriteList(toSave); - getPersistenceContext().getPollenUserDao().update(user); + getPollenUserDao().update(user); - getPersistenceContext().commit(); + commit(); return toSave; } @@ -120,8 +120,8 @@ copyFavoriteList(favoriteList, toSave); - getPersistenceContext().getFavoriteListDao().update(toSave); - getPersistenceContext().commit(); + getFavoriteListDao().update(toSave); + commit(); return toSave; } @@ -135,8 +135,8 @@ user.removeFavoriteList(persisted); - getPersistenceContext().getPollenUserDao().update(user); - getPersistenceContext().commit(); + getPollenUserDao().update(user); + commit(); } public List<FavoriteListMember> getFavoriteListMembers(String userId, String favoriteListId) throws EntityNotFoundException { @@ -178,13 +178,13 @@ checkFavoriteListMemberForm(favoriteList, member); FavoriteListMember newMember = - getPersistenceContext().getFavoriteListMemberDao().newInstance(); + getFavoriteListMemberDao().newInstance(); copyFavoriteListMember(member, newMember); favoriteList.addFavoriteListMember(newMember); - getPersistenceContext().getFavoriteListDao().update(favoriteList); + getFavoriteListDao().update(favoriteList); - getPersistenceContext().commit(); + commit(); return newMember; } @@ -209,9 +209,9 @@ copyFavoriteListMember(member, toSave); - getPersistenceContext().getFavoriteListMemberDao().update(toSave); + getFavoriteListMemberDao().update(toSave); - getPersistenceContext().commit(); + commit(); return toSave; } @@ -230,8 +230,8 @@ favoriteList.removeFavoriteListMember(member); - getPersistenceContext().getFavoriteListDao().update(favoriteList); - getPersistenceContext().commit(); + getFavoriteListDao().update(favoriteList); + commit(); } public int importFavoriteListMembersFromCsv(String userId, @@ -307,7 +307,7 @@ throw new FavoriteListImportException(error, null); } - FavoriteListMember member = getPersistenceContext().getFavoriteListMemberDao().newInstance(); + FavoriteListMember member = getFavoriteListMemberDao().newInstance(); member.setName(memberName); member.setEmail(email); @@ -326,9 +326,9 @@ IOUtils.closeQuietly(reader); } - getPersistenceContext().getFavoriteListDao().update(favoriteList); + getFavoriteListDao().update(favoriteList); - getPersistenceContext().commit(); + commit(); return result; } @@ -403,7 +403,7 @@ throw new FavoriteListImportException(error, null); } - FavoriteListMember member = getPersistenceContext().getFavoriteListMemberDao().newInstance(); + FavoriteListMember member = getFavoriteListMemberDao().newInstance(); member.setName(memberName); member.setEmail(email); @@ -414,9 +414,9 @@ throw new FavoriteListImportException("LDAP", ex); } - getPersistenceContext().getFavoriteListDao().update(favoriteList); + getFavoriteListDao().update(favoriteList); - getPersistenceContext().commit(); + commit(); return result; } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -27,13 +27,12 @@ import com.google.common.collect.Maps; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; +import org.chorem.pollen.persistence.PollenPersistenceContext; +import org.chorem.pollen.persistence.PollenTopiaApplicationContext; import org.chorem.pollen.persistence.entity.PollenUser; import org.chorem.pollen.persistence.entity.PollenUserTopiaDao; import org.chorem.pollen.services.PollenFixtures; -import javax.persistence.EntityManager; -import java.lang.reflect.Field; import java.util.Collection; import java.util.Map; @@ -73,13 +72,15 @@ log.info("will restore database with fixture set"); } - PollenTopiaPersistenceContext persistenceContext = serviceContext.getPersistenceContext(); + PollenPersistenceContext persistenceContext = serviceContext.getPersistenceContext(); if (cleanDatabase) { - //FIXME - //persistenceContext.clearDatabase(); + PollenTopiaApplicationContext topiaApplicationContext = serviceContext.getTopiaApplicationContext(); + topiaApplicationContext.dropSchema(); + topiaApplicationContext.createSchema(); + } PollenUserTopiaDao userDao = persistenceContext.getPollenUserDao(); Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -53,7 +53,7 @@ public class PollService extends PollenServiceSupport { public Set<Poll> getPolls(String userId) throws EntityNotFoundException { - return Sets.newHashSet(getPersistenceContext().getPollDao().findAll()); + return Sets.newHashSet(getPollDao().findAll()); } public Set<Poll> getCreatedPolls(String userId) throws EntityNotFoundException { @@ -61,7 +61,7 @@ getUserService().getUser(userId); - return getPersistenceContext().getPollDao().findAllCreated(userId); + return getPollDao().findAllCreated(userId); } public Set<Poll> getInvitedPolls(String userId) throws EntityNotFoundException { @@ -69,7 +69,7 @@ getUserService().getUser(userId); - return getPersistenceContext().getPollDao().findAllInvited(userId); + return getPollDao().findAllInvited(userId); } public Set<Poll> getParticipatedPolls(String userId) throws EntityNotFoundException { @@ -77,20 +77,20 @@ getUserService().getUser(userId); - return getPersistenceContext().getPollDao().findAllParticipated(userId); + return getPollDao().findAllParticipated(userId); } public Poll getPoll(String pollId) throws EntityNotFoundException { Preconditions.checkNotNull(pollId); checkPermission(PermissionVerb.readPoll, pollId); - Poll result = getPersistenceContext().getPollDao().findByTopiaId(pollId); + Poll result = getPollDao().findByTopiaId(pollId); checkEntityExists(Poll.class, result, pollId); return result; } public Poll getNewPoll(String userId, ChoiceType choiceType) throws EntityNotFoundException { - Poll result = getPersistenceContext().getPollDao().newInstance(); + Poll result = getPollDao().newInstance(); result.setChoiceType(choiceType); @@ -104,7 +104,7 @@ // -- creator -- // - PollenPrincipal creator = getPersistenceContext().getPollenPrincipalDao().newInstance(); + PollenPrincipal creator = getPollenPrincipalDao().newInstance(); result.setCreator(creator); if (userId != null) { @@ -128,8 +128,8 @@ Poll pollToPersist = savePoll(userId, poll); - getPersistenceContext().getPollDao().create(pollToPersist); - getPersistenceContext().commit(); + getPollDao().create(pollToPersist); + commit(); return pollToPersist; } @@ -143,8 +143,8 @@ Poll toSave = savePoll(null, poll); - getPersistenceContext().getPollDao().update(toSave); - getPersistenceContext().commit(); + getPollDao().update(toSave); + commit(); return toSave; } @@ -157,8 +157,8 @@ Poll poll = getPoll(pollId); - getPersistenceContext().getPollDao().delete(poll); - getPersistenceContext().commit(); + getPollDao().delete(poll); + commit(); if (poll.getCreator().getEmail() != null) { @@ -173,7 +173,7 @@ Poll poll = getPoll(pollId); //TODO - getPersistenceContext().commit(); + commit(); return null; } @@ -183,7 +183,7 @@ Poll poll = getPoll(pollId); //TODO - getPersistenceContext().commit(); + commit(); return null; } @@ -205,7 +205,7 @@ toSave = getPoll(poll.getTopiaId()); } else { - PollTopiaDao dao = getPersistenceContext().getPollDao(); + PollTopiaDao dao = getPollDao(); toSave = dao.newInstance(); Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -27,7 +27,19 @@ import com.google.common.collect.Multimap; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; +import org.chorem.pollen.persistence.PollenPersistenceContext; +import org.chorem.pollen.persistence.entity.ChoiceTopiaDao; +import org.chorem.pollen.persistence.entity.CommentTopiaDao; +import org.chorem.pollen.persistence.entity.FavoriteListMemberTopiaDao; +import org.chorem.pollen.persistence.entity.FavoriteListTopiaDao; +import org.chorem.pollen.persistence.entity.PollTopiaDao; +import org.chorem.pollen.persistence.entity.PollenPrincipalTopiaDao; +import org.chorem.pollen.persistence.entity.PollenUserTopiaDao; +import org.chorem.pollen.persistence.entity.SessionTokenTopiaDao; +import org.chorem.pollen.persistence.entity.VoteToChoiceTopiaDao; +import org.chorem.pollen.persistence.entity.VoteTopiaDao; +import org.chorem.pollen.persistence.entity.VoterListMemberTopiaDao; +import org.chorem.pollen.persistence.entity.VoterListTopiaDao; import org.chorem.pollen.services.PollenService; import org.chorem.pollen.services.PollenServiceContext; import org.chorem.pollen.services.config.PollenServiceConfig; @@ -73,7 +85,7 @@ return serviceContext.getCleanMail(email); } - protected PollenTopiaPersistenceContext getPersistenceContext() { + protected PollenPersistenceContext getPersistenceContext() { return serviceContext.getPersistenceContext(); } @@ -81,6 +93,8 @@ return serviceContext.getPollenServiceConfig(); } + // -- Services -- // + protected AuthService getAuthService() { return newService(AuthService.class); } @@ -125,6 +139,64 @@ return serviceContext.newService(serviceClass); } + // -- delegate persistenceContext method -- // + + protected ChoiceTopiaDao getChoiceDao() { + return getPersistenceContext().getChoiceDao(); + } + + protected CommentTopiaDao getCommentDao() { + return getPersistenceContext().getCommentDao(); + } + + protected FavoriteListTopiaDao getFavoriteListDao() { + return getPersistenceContext().getFavoriteListDao(); + } + + protected FavoriteListMemberTopiaDao getFavoriteListMemberDao() { + return getPersistenceContext().getFavoriteListMemberDao(); + } + + protected PollTopiaDao getPollDao() { + return getPersistenceContext().getPollDao(); + } + + protected PollenPrincipalTopiaDao getPollenPrincipalDao() { + return getPersistenceContext().getPollenPrincipalDao(); + } + + protected PollenUserTopiaDao getPollenUserDao() { + return getPersistenceContext().getPollenUserDao(); + } + + protected SessionTokenTopiaDao getSessionTokenDao() { + return getPersistenceContext().getSessionTokenDao(); + } + + protected VoteTopiaDao getVoteDao() { + return getPersistenceContext().getVoteDao(); + } + + protected VoteToChoiceTopiaDao getVoteToChoiceDao() { + return getPersistenceContext().getVoteToChoiceDao(); + } + + protected VoterListTopiaDao getVoterListDao() { + return getPersistenceContext().getVoterListDao(); + } + + protected VoterListMemberTopiaDao getVoterListMemberDao() { + return getPersistenceContext().getVoterListMemberDao(); + } + + public void commit() { + getPersistenceContext().commit(); + } + + public void rollback() { + getPersistenceContext().rollback(); + } + // -- check method -- // protected void checkPermission(PermissionVerb verb, String id) { Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -47,14 +47,14 @@ public class PollenUserService extends PollenServiceSupport implements PollenService { public List<PollenUser> getUsers() { - return getPersistenceContext().getPollenUserDao().findAll(); + return getPollenUserDao().findAll(); } public PollenUser getUser(String userId) throws EntityNotFoundException { Preconditions.checkNotNull(userId); try { - PollenUser result = getPersistenceContext().getPollenUserDao().findByTopiaId(userId); + PollenUser result = getPollenUserDao().findByTopiaId(userId); return result; } catch (TopiaNoResultException e) { throw new EntityNotFoundException(PollenUser.class, userId); @@ -64,10 +64,10 @@ public PollenUser getUserByLogin(String login) throws EntityNotFoundException { Preconditions.checkNotNull(login); try { - PollenUser result = getPersistenceContext().getPollenUserDao().forLoginEquals(login).findAny(); + PollenUser result = getPollenUserDao().forLoginEquals(login).findAny(); return result; } catch (TopiaNoResultException e) { - throw new EntityNotFoundException(PollenUser.class, login); + throw new EntityNotFoundException(PollenUser.class, PollenUser.PROPERTY_LOGIN, login); } } @@ -78,8 +78,8 @@ PollenUser result = savePollenUser(user, generatePassword); - getPersistenceContext().getPollenUserDao().create(result); - getPersistenceContext().commit(); + getPollenUserDao().create(result); + commit(); //TODO Notify user created return result; } @@ -91,8 +91,8 @@ PollenUser result = savePollenUser(user, false); - getPersistenceContext().getPollenUserDao().update(result); - getPersistenceContext().commit(); + getPollenUserDao().update(result); + commit(); //TODO Notify user edited return result; } @@ -116,8 +116,8 @@ String newEncodedPassword = serviceContext.encodePassword(newPassword); user.setPassword(newEncodedPassword); - getPersistenceContext().getPollenUserDao().update(user); - getPersistenceContext().commit(); + getPollenUserDao().update(user); + commit(); //TODO Notify PasswordChanged } @@ -139,20 +139,23 @@ // reset token in database user.setEmailActivationToken(null); - getPersistenceContext().getPollenUserDao().update(user); - getPersistenceContext().commit(); + getPollenUserDao().update(user); + commit(); } public void createDefaultUsers() throws EntityNotFoundException, InvalidPollenUserFormException { - PollenUser user = getPersistenceContext().getPollenUserDao().newInstance(); + if (getPollenUserDao().count() == 0) { - user.setAdministrator(true); - String login = "admin"; - user.setLogin(login); - user.setEmail("admin@pollen.org"); - user.setPassword("admin"); - createUser(user, false); + PollenUser user = getPollenUserDao().newInstance(); + + user.setAdministrator(true); + String login = "admin"; + user.setLogin(login); + user.setEmail("admin@pollen.org"); + user.setPassword("admin"); + createUser(user, false); + } } protected void checkPollenUserForm(PollenUser user) throws EntityNotFoundException, InvalidPollenUserFormException { @@ -162,7 +165,7 @@ boolean userExists = user.isPersisted(); PollenUser persisted = userExists ? getUser(user.getTopiaId()) : null; - PollenUserTopiaDao dao = getPersistenceContext().getPollenUserDao(); + PollenUserTopiaDao dao = getPollenUserDao(); String userLogin = user.getLogin(); String userEmail = getCleanMail(user.getEmail()); @@ -234,7 +237,7 @@ } } else { - toSave = getPersistenceContext().getPollenUserDao().newInstance(); + toSave = getPollenUserDao().newInstance(); // add a emailValidationToken emailValidationToken = generateToken(); Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -28,17 +28,13 @@ import com.google.common.collect.Sets; import org.apache.shiro.subject.Subject; import org.chorem.pollen.persistence.entity.Choice; -import org.chorem.pollen.persistence.entity.ChoiceTopiaDao; import org.chorem.pollen.persistence.entity.Comment; -import org.chorem.pollen.persistence.entity.CommentTopiaDao; import org.chorem.pollen.persistence.entity.Poll; -import org.chorem.pollen.persistence.entity.PollTopiaDao; import org.chorem.pollen.persistence.entity.PollenPrincipal; import org.chorem.pollen.persistence.entity.PollenPrincipalTopiaDao; import org.chorem.pollen.persistence.entity.PollenUser; import org.chorem.pollen.persistence.entity.Polls; import org.chorem.pollen.persistence.entity.Vote; -import org.chorem.pollen.persistence.entity.VoteTopiaDao; import org.chorem.pollen.persistence.entity.VoterListMember; import org.chorem.pollen.services.PollenSecurityContext; import org.nuiton.topia.persistence.TopiaEntity; @@ -248,42 +244,6 @@ return result; } - protected CommentTopiaDao commentDao; - - protected VoteTopiaDao voteDao; - - protected ChoiceTopiaDao choiceDao; - - protected PollTopiaDao pollDao; - - protected CommentTopiaDao getCommentDao() { - if (commentDao == null) { - commentDao = getPersistenceContext().getCommentDao(); - } - return commentDao; - } - - protected VoteTopiaDao getVoteDao() { - if (voteDao == null) { - voteDao = getPersistenceContext().getVoteDao(); - } - return voteDao; - } - - protected ChoiceTopiaDao getChoiceDao() { - if (choiceDao == null) { - choiceDao = getPersistenceContext().getChoiceDao(); - } - return choiceDao; - } - - protected PollTopiaDao getPollDao() { - if (pollDao == null) { - pollDao = getPersistenceContext().getPollDao(); - } - return pollDao; - } - protected String createSubjectPermission(String people, PermissionVerb verb, TopiaEntity entity) { return people + ":" + verb.name() + ":" + entity.getTopiaId(); } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -73,8 +73,8 @@ Vote result = saveVote(poll, vote); - getPersistenceContext().getPollDao().update(poll); - getPersistenceContext().commit(); + getPollDao().update(poll); + commit(); //TODO Notify vote added return result; } @@ -89,8 +89,8 @@ Vote result = saveVote(poll, vote); - getPersistenceContext().getVoteDao().update(vote); - getPersistenceContext().commit(); + getVoteDao().update(vote); + commit(); //TODO Notify vote edited return result; } @@ -107,8 +107,8 @@ poll.removeVote(vote); - getPersistenceContext().getPollDao().update(poll); - getPersistenceContext().commit(); + getPollDao().update(poll); + commit(); //TODO Notify vote deleted } @@ -147,7 +147,7 @@ toSave = getVote(poll, vote.getTopiaId()); } else { - toSave = getPersistenceContext().getVoteDao().newInstance(); + toSave = getVoteDao().newInstance(); // toSave.setPostDate(serviceContext.getNow()); // -- author -- // Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -59,14 +59,14 @@ FavoriteList favoriteList = getFavoriteListService().getFavoriteList(userId, favoriteListId); - VoterListTopiaDao dao = getPersistenceContext().getVoterListDao(); + VoterListTopiaDao dao = getVoterListDao(); VoterList result = dao.newInstance(); result.setName(favoriteList.getName()); result.setWeight(1d); VoterListMemberTopiaDao voterListMemberDao = - getPersistenceContext().getVoterListMemberDao(); + getVoterListMemberDao(); for (FavoriteListMember favoriteListMember : favoriteList.getFavoriteListMember()) { @@ -78,8 +78,8 @@ poll.addVoterList(result); - getPersistenceContext().getPollDao().update(poll); - getPersistenceContext().commit(); + getPollDao().update(poll); + commit(); return result; } @@ -112,8 +112,8 @@ VoterList result = saveVoterList(poll, voterList); - getPersistenceContext().getPollDao().update(poll); - getPersistenceContext().commit(); + getPollDao().update(poll); + commit(); return result; } @@ -127,8 +127,8 @@ VoterList result = saveVoterList(poll, voterList); - getPersistenceContext().getVoterListDao().update(voterList); - getPersistenceContext().commit(); + getVoterListDao().update(voterList); + commit(); return result; } @@ -142,8 +142,8 @@ poll.removeVoterList(voterList); - getPersistenceContext().getPollDao().update(poll); - getPersistenceContext().commit(); + getPollDao().update(poll); + commit(); } public Set<VoterListMember> getVoterListMembers(String pollId, String voterListId) throws EntityNotFoundException { @@ -180,8 +180,8 @@ VoterListMember result = saveVoterListMember(voterList, member); - getPersistenceContext().getVoterListDao().update(voterList); - getPersistenceContext().commit(); + getVoterListDao().update(voterList); + commit(); return result; } @@ -198,8 +198,8 @@ VoterListMember result = saveVoterListMember(voterList, member); - getPersistenceContext().getVoterListMemberDao().update(member); - getPersistenceContext().commit(); + getVoterListMemberDao().update(member); + commit(); return result; } @@ -213,9 +213,9 @@ VoterListMember member = getVoterListMember(voterList, memberId); voterList.removeVoterListMember(member); -// getPersistenceContext().getVoterListDao().merge(voterList); +// getVoterListDao().merge(voterList); - getPersistenceContext().commit(); + commit(); } protected VoterList getVoterList(Poll poll, String voterListId) throws EntityNotFoundException { @@ -245,7 +245,7 @@ toSave = getVoterList(poll, voterList.getTopiaId()); } else { VoterListTopiaDao voterListDao = - getPersistenceContext().getVoterListDao(); + getVoterListDao(); toSave = voterListDao.newInstance(); poll.addVoterList(toSave); @@ -275,7 +275,7 @@ } else { VoterListMemberTopiaDao voterListMemberDao = - getPersistenceContext().getVoterListMemberDao(); + getVoterListMemberDao(); toSave = voterListMemberDao.newInstance(); Modified: trunk/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java =================================================================== --- trunk/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java 2014-04-27 16:47:39 UTC (rev 3880) @@ -34,18 +34,12 @@ import org.chorem.pollen.services.config.PollenServiceConfig; import org.chorem.pollen.services.exception.AbstractInvalidFormException; import org.chorem.pollen.services.service.FixturesService; -import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; -import org.hibernate.service.ServiceRegistry; -import org.hibernate.service.internal.SessionFactoryServiceRegistryImpl; -import org.hibernate.tool.hbm2ddl.SchemaExport; import org.junit.After; import org.junit.Assert; import org.nuiton.util.DateUtil; -import javax.persistence.EntityManager; import java.io.File; -import java.lang.reflect.Field; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -179,6 +173,7 @@ PollenTopiaPersistenceContext persistenceContext = newPersistenceContext(); serviceContext.setPersistenceContext(persistenceContext); serviceContext.setDate(DateUtil.createDate(2, 11, 2009)); + serviceContext.setTopiaApplicationContext(getApplicationContext()); } return serviceContext; @@ -189,8 +184,6 @@ FixturesService fixturesService = getServiceContext().newService(FixturesService.class); fixtures = fixturesService.loadFixtures(fixturesSetName); - -// getServiceContext().getPersistenceContext().getHibernateSupport().getHibernateSession().clear(); } protected <E> E fixture(String id) { Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2014-04-26 19:20:22 UTC (rev 3879) +++ trunk/pom.xml 2014-04-27 16:47:39 UTC (rev 3880) @@ -283,36 +283,6 @@ </dependency> <dependency> - <groupId>org.nuiton.jpa</groupId> - <artifactId>nuiton-jpa-api</artifactId> - <version>${nuitonJpaVersion}</version> - <exclusions> - <exclusion> - <groupId>org.hibernate.javax.persistence</groupId> - <artifactId>hibernate-jpa-2.0-api</artifactId> - </exclusion> - </exclusions> - </dependency> - - <dependency> - <groupId>org.nuiton.jpa</groupId> - <artifactId>nuiton-jpa-hibernate</artifactId> - <version>${nuitonJpaVersion}</version> - <exclusions> - <exclusion> - <groupId>org.hibernate.javax.persistence</groupId> - <artifactId>hibernate-jpa-2.0-api</artifactId> - </exclusion> - </exclusions> - </dependency> - - <dependency> - <groupId>org.nuiton.jpa</groupId> - <artifactId>nuiton-jpa-junit</artifactId> - <version>${nuitonJpaVersion}</version> - </dependency> - - <dependency> <groupId>com.esotericsoftware.yamlbeans</groupId> <artifactId>yamlbeans</artifactId> <version>1.06</version>