r3830 - in trunk: pollen-persistence/src/main/java/org/chorem/pollen/persistence pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity pollen-persistence/src/main/xmi pollen-rest-api/src/it/pom pollen-rest-api/src/it/user pollen-rest-api/src/main/java/org/chorem/pollen/rest pollen-rest-api/src/main/java/org/chorem/pollen/rest/api pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1 pollen-rest-api/src/main/resources pollen-rest-api/src/main/webapp/WEB-INF pollen-rest-
Author: tchemit Date: 2013-06-15 12:58:03 +0200 (Sat, 15 Jun 2013) New Revision: 3830 Url: http://chorem.org/projects/pollen/repository/revisions/3830 Log: - use version in REST api (v1) - normalize rest api (need all the data path) - implements poll create - edit service - implements choice create - edit service - implements voterList create - edit service Added: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java 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/PollenJpaTransactionFilter.java 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/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/main/java/org/chorem/pollen/rest/api/v1/ 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/ErrorAction.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/UserService.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-services/src/main/java/org/chorem/pollen/services/PollenSecurityRealm.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/AbstractInvalidFormException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidChoiceFormException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidPollFormException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/package-info.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/SecurityService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/package-info.java Removed: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenApplicationContext.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenJpaTransactionFilter.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenRender.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenSecurityFilter.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceContextFilter.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceListener.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServices.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/AuthService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/CommentService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/ErrorAction.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/FavoriteListService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/UserService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteCountingService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoterListService.java trunk/pollen-services/src/main/java/org/chorem/pollen/service/ Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenPersistenceContext.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUser.java trunk/pollen-persistence/src/main/xmi/pollen.properties trunk/pollen-persistence/src/main/xmi/pollen.zargo trunk/pollen-rest-api/src/it/pom/pom.xml trunk/pollen-rest-api/src/it/user/README.txt 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-rest-api/src/test/resources/pollen.properties 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/PollenSecurityContext.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListImportException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidSessionTokenException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/package-info.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.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/VoterListService.java trunk/pollen-ui-js/src/main/webapp/img/glyphicons_050_link.png trunk/pollen-ui-js/src/main/webapp/js/libs/date.js trunk/pollen-ui-js/src/main/webapp/js/libs/jquery.scrollto.js Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,5 +1,28 @@ package org.chorem.pollen.persistence; +/* + * #%L + * Pollen :: Persistence + * $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.codec.DecoderException; import org.apache.commons.codec.binary.Base64; Property changes on: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java ___________________________________________________________________ Modified: svn:keywords - Author Date Id Revision + Author Date Id Revision HeadURL Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenPersistenceContext.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenPersistenceContext.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenPersistenceContext.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -28,6 +28,7 @@ import org.chorem.pollen.persistence.dao.FavoriteListJpaDao; import org.chorem.pollen.persistence.dao.FavoriteListMemberJpaDao; import org.chorem.pollen.persistence.dao.PollJpaDao; +import org.chorem.pollen.persistence.dao.PollenPrincipalJpaDao; import org.chorem.pollen.persistence.dao.PollenUserJpaDao; import org.chorem.pollen.persistence.dao.SessionTokenJpaDao; import org.chorem.pollen.persistence.dao.VoteJpaDao; @@ -63,6 +64,8 @@ PollJpaDao getPollDao(); + PollenPrincipalJpaDao getPollenPrincipalDao(); + PollenUserJpaDao getPollenUserDao(); SessionTokenJpaDao getSessionTokenDao(); Added: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java (rev 0) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,51 @@ +package org.chorem.pollen.persistence.entity; + +/* + * #%L + * Pollen :: Persistence + * $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 javax.persistence.Entity; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +@Entity +public class Poll extends AbstractJpaPoll { + + private static final long serialVersionUID = 1L; + + public boolean isFreePoll() { + return PollType.FREE == pollType; + } + + public boolean isRestrictedPoll() { + return PollType.RESTRICTED == pollType; + } + + public boolean isGroupPoll() { + return PollType.GROUP == pollType; + } + +} //Poll Property changes on: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUser.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUser.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUser.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -25,6 +25,12 @@ import javax.persistence.Entity; +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ @Entity public class PollenUser extends AbstractJpaPollenUser { Modified: trunk/pollen-persistence/src/main/xmi/pollen.properties =================================================================== --- trunk/pollen-persistence/src/main/xmi/pollen.properties 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-persistence/src/main/xmi/pollen.properties 2013-06-15 10:58:03 UTC (rev 3830) @@ -21,7 +21,6 @@ # #L% ###m model.tagValue.idFactory=true -model.tagValue.generatePropertyChangeListeners=true model.tagValue.generateVisitors=true model.tagvalue.version=2.0 #model.tagvalue.entitySuperClass=org.chorem.pollen.persistence.entity.AbstractJpaPollenEntity Modified: trunk/pollen-persistence/src/main/xmi/pollen.zargo =================================================================== (Binary files differ) Modified: trunk/pollen-rest-api/src/it/pom/pom.xml =================================================================== --- trunk/pollen-rest-api/src/it/pom/pom.xml 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-rest-api/src/it/pom/pom.xml 2013-06-15 10:58:03 UTC (rev 3830) @@ -3,7 +3,7 @@ #%L Pollen :: UI (struts2) $Id$ - $HeadURL: http://svn.chorem.org/svn/pollen/branches/pollen-2.0/pollen-ui-struts2/src/i... $ + $HeadURL$ %% Copyright (C) 2009 - 2012 CodeLutin %% Property changes on: trunk/pollen-rest-api/src/it/pom/pom.xml ___________________________________________________________________ Modified: svn:keywords - Author Date Id Revision + Author Date Id Revision HeadURL Property changes on: trunk/pollen-rest-api/src/it/user/README.txt ___________________________________________________________________ Modified: svn:keywords - Author Date Id Revision + Author Date Id Revision HeadURL Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenApplicationContext.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenApplicationContext.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenApplicationContext.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,125 +0,0 @@ -package org.chorem.pollen.rest; - -/* - * #%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.chorem.pollen.persistence.JpaPollenPersistenceContext; -import org.chorem.pollen.services.DefaultPollenServiceContext; -import org.chorem.pollen.services.PollenServiceContext; -import org.chorem.pollen.services.config.PollenServiceConfig; - -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.Persistence; -import javax.persistence.PersistenceException; -import java.io.Closeable; -import java.util.Map; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class PollenApplicationContext implements Closeable { - - private static final Log log = LogFactory.getLog(PollenApplicationContext.class); - - protected static final String APPLICATION_CONTEXT_PARAMETER = "pollen_PollenApplicationContext"; - - protected PollenServiceConfig applicationConfig; - - protected EntityManagerFactory entityManagerFactory; - - public PollenServiceConfig getPollenServiceConfig() { - if (applicationConfig == null) { - applicationConfig = new PollenServiceConfig(); - } - return applicationConfig; - } - - public EntityManager newEntityManager() { - - if (entityManagerFactory == null) { - - PollenServiceConfig applicationConfig = getPollenServiceConfig(); - - Map<String, String> jpaParameters = applicationConfig.getJpaParameters(); - - if (log.isInfoEnabled()) { - log.info("creating entity manager factory"); - } - - try { - - entityManagerFactory = Persistence.createEntityManagerFactory("pollenPersistenceUnit", jpaParameters); - - } catch (PersistenceException e) { - - if (log.isErrorEnabled()) { - log.error("unable to create entity manager factory", e); - } - - throw e; - - } - - } - - EntityManager entityManager = entityManagerFactory.createEntityManager(); - - return entityManager; - - } - - public void close() { - - if (entityManagerFactory != null && entityManagerFactory.isOpen()) { - - if (log.isInfoEnabled()) { - log.info("stopping magalie, will close entity manager factory"); - } - - entityManagerFactory.close(); - - } - - } - - public PollenServiceContext newServiceContext(EntityManager entityManager) { - - DefaultPollenServiceContext serviceContext = new DefaultPollenServiceContext(); - - JpaPollenPersistenceContext jpaMagaliePersistenceContext = - new JpaPollenPersistenceContext(entityManager); - - serviceContext.setPersistenceContext(jpaMagaliePersistenceContext); - - serviceContext.setPollenServiceConfig(applicationConfig); - - return serviceContext; - - } -} Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenJpaTransactionFilter.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenJpaTransactionFilter.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenJpaTransactionFilter.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,87 +0,0 @@ -package org.chorem.pollen.rest; - -/* - * #%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.nuiton.web.filter.JpaTransactionFilter; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceException; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; - -public class PollenJpaTransactionFilter extends JpaTransactionFilter { - - private static final Log log = - LogFactory.getLog(PollenJpaTransactionFilter.class); - - protected PollenApplicationContext applicationContext; - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - - super.init(filterConfig); - - if (log.isInfoEnabled()) { - log.info("Init JPA Filter"); - } - -// applicationContext = PollenServices.getApplicationContext( -// filterConfig.getServletContext()); -// -// Preconditions.checkNotNull(applicationContext, "Could not find application context at ServletContext#pollen_PollenApplicationContext"); - } - - 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; - } - - @Override - protected EntityManager createEntityManager(ServletRequest request) { - - EntityManager entityManager; - - try { - - entityManager = getApplicationContext(request).newEntityManager(); - - } catch (PersistenceException e) { - - if (log.isErrorEnabled()) { - log.error("unable to create entity manager", e); - } - throw e; - } - return entityManager; - } -} Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenRender.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenRender.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenRender.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,234 +0,0 @@ -package org.chorem.pollen.rest; - -/* - * #%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.collect.Lists; -import com.google.common.collect.Maps; -import com.google.gson.Gson; -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.util.ObjectUtil; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderFactory; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.PrintWriter; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * To render any entities. - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class PollenRender<T> extends Render { - - /** - * To specify entity collections to include in binded entities. - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.METHOD) - public @interface ExposeCollection { - - public String[] values() default {}; - } - - protected T model; - - public PollenRender(T model) { - this.model = model; - } - - @Override - public void create(Mapping mapping, Call call) throws IOException, ServletException { - - HttpContext context = call.getContext(); - HttpServletResponse response = context.getResponse(); - response.setContentType("application/json"); - - String[] includeCollection = null; - ExposeCollection annotation = call.getCurrent().getMethod().getAnnotation(ExposeCollection.class); - if (annotation != null) { - includeCollection = annotation.values(); - } - Object map = toMap(model, includeCollection); - - Gson gson = new Gson(); - String json = gson.toJson(map); - PrintWriter out = context.getOut(); - out.print(json); - } - - protected <M> Object toMap(M model, String... includeCollection) { - if (model instanceof Iterable<?>) { - - // collection of objects - Iterable<?> objects = (Iterable<?>) model; - List<Object> result = Lists.newArrayList(); - for (Object object : objects) { - Object objectMap = toMap(object, includeCollection); - result.add(objectMap); - } - return result; - } - - // single object - - if (model instanceof JpaEntity) { - - // entity need to transform it - - JpaEntity jpaEntity = (JpaEntity) model; - - PollenEntityBinder<JpaEntity> binder = BinderFactory.newBinder(jpaEntity.getClass(), jpaEntity.getClass(), null, PollenEntityBinder.class); - Map<String, Object> map = binder.obtainProperties(jpaEntity); - 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) { - result.put(propertyName, toMap(propertyValue)); - continue; - } - - result.put(propertyName, propertyValue); - } - - // treat collections - - if (includeCollection != null) { - for (String propertyName : includeCollection) { - Iterable<?> collectionValue = binder.getCollectionValue(jpaEntity, propertyName); - result.put(propertyName, toMap(collectionValue)); - - } - } - return result; - } - - return model; - } - - protected static class PollenEntityBinder<E extends JpaEntity> extends Binder<E, E> { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(PollenEntityBinder.class); - - private static final long serialVersionUID = 1L; - - protected List<String> simpleProperties; - - public PollenEntityBinder() { - } - - @Override - protected void setModel(BinderModel<E, E> model) { - super.setModel(model); - this.simpleProperties = Lists.newArrayList(); - for (String property : model.getSourceDescriptors()) { - if (model.getCollectionType(property) == null) { - simpleProperties.add(property); - } - } - } - - /** - * Obtain from the given object all properties registered in the binder - * model. - * - * @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}. - * @since 2.3 - */ - public Map<String, Object> obtainProperties(E source) { - if (source == null) { - // special limit case - return Collections.emptyMap(); - } - - Map<String, Object> result = Maps.newTreeMap(); - for (String sourceProperty : simpleProperties) { - - - try { - Object read; - Method readMethod = model.getSourceReadMethod(sourceProperty); - read = readMethod.invoke(source); - if (log.isDebugEnabled()) { - log.debug("property " + sourceProperty + ", type : " + - readMethod.getReturnType() + ", value = " + read); - } - if (readMethod.getReturnType().isPrimitive() && - ObjectUtil.getNullValue( - readMethod.getReturnType()).equals(read)) { - // for primitive type case, force nullity - read = null; - } - - if (read != null) { - result.put(sourceProperty, read); - } - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } - } - return result; - } - - public Iterable<?> getCollectionValue(E source, String sourceProperty) { - try { - Method readMethod = model.getSourceReadMethod(sourceProperty); - Object result = readMethod.invoke(source); - return (Iterable<?>) result; - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } - } - } -} Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenSecurityFilter.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenSecurityFilter.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenSecurityFilter.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,47 +0,0 @@ -package org.chorem.pollen.rest; - -import org.apache.commons.lang3.StringUtils; -import org.chorem.pollen.persistence.entity.SessionToken; -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.HttpServletRequest; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class PollenSecurityFilter extends WebMotionFilter { - - public static final String REQUEST_AUTH_PARAMETER = "auth"; - - void injectConnectedUser(HttpContext context) throws InvalidSessionTokenException { - - String[] strings = context.getParameters().get(REQUEST_AUTH_PARAMETER); - - String authParam = strings == null || strings.length < 1 ? null : strings[1]; - - if (StringUtils.isNotBlank(authParam)) { - - // find out the userId from this auth - - HttpServletRequest request = context.getRequest(); - - PollenServiceContext serviceContext = - PollenServices.getServiceContext(request); - - SessionToken sessionToken = - serviceContext.getAuthService().getUserByAuth(authParam); - - if (sessionToken != null) { - - // reinject it in request - PollenServices.setSessionToken(request, sessionToken); - } - } - } -} Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceContextFilter.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceContextFilter.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceContextFilter.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,55 +0,0 @@ -package org.chorem.pollen.rest; - -/* - * #%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.services.PollenServiceContext; -import org.debux.webmotion.server.WebMotionFilter; -import org.debux.webmotion.server.call.HttpContext; - -import javax.persistence.EntityManager; - -/** - * Inject le service context dans les controlleurs. - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class PollenServiceContextFilter extends WebMotionFilter { - - public void inject(HttpContext context) { - - PollenApplicationContext applicationContext = - PollenServices.getApplicationContext(context.getServletContext()); - - EntityManager entityManager = - PollenServices.getEntityManager(context.getRequest()); - - PollenServiceContext serviceContext = - applicationContext.newServiceContext(entityManager); - - PollenServices.setServiceContext(context.getRequest(), serviceContext); - - doProcess(); - } -} Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceListener.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceListener.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceListener.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,124 +0,0 @@ -package org.chorem.pollen.rest; - -/* - * #%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.chorem.pollen.services.PollenServiceContext; -import org.chorem.pollen.services.exception.UserEmailAlreadyUsedException; -import org.chorem.pollen.services.exception.UserLoginAlreadyUsedException; -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.persistence.EntityManager; -import javax.servlet.http.HttpServletRequest; -import java.lang.reflect.Type; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class PollenServiceListener implements WebMotionServerListener { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(PollenServiceListener.class); - - @Override - public void onStart(Mapping mapping, ServerContext serverContext) { - - serverContext.addInjector(new PollenServiceContextInjector()); - serverContext.addInjector(new SessionTokenInjector()); - - // Create application context - PollenApplicationContext applicationContext = - new PollenApplicationContext(); - - // push it in context - PollenServices.setApplicationContext( - serverContext.getServletContext(), applicationContext); - - EntityManager entityManager = applicationContext.newEntityManager(); - - try { - PollenServiceContext serviceContext = - applicationContext.newServiceContext(entityManager); - serviceContext.getUserService().createDefaultUsers(); - } catch (UserEmailAlreadyUsedException e) { - //Can't happen - } catch (UserLoginAlreadyUsedException e) { - //Can't happen - } finally { - entityManager.close(); - } - } - - @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 Object getValue(Mapping mapping, Call call, String name, Class<?> type, Type generic) { - PollenServiceContext result = null; - if (PollenServiceContext.class.isAssignableFrom(type)) { - HttpContext httpContext = call.getContext(); - HttpServletRequest request = httpContext.getRequest(); - - result = PollenServices.getServiceContext(request); - } - return result; - } - } - - protected static class SessionTokenInjector implements ExecutorParametersInjectorHandler.Injector { - @Override - public Object getValue(Mapping mapping, Call call, String name, Class<?> type, Type generic) { - PollenServiceContext 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/PollenServices.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServices.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServices.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,89 +0,0 @@ -package org.chorem.pollen.rest; - -/* - * #%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.entity.SessionToken; -import org.chorem.pollen.services.PollenServiceContext; -import org.nuiton.web.filter.JpaTransactionFilter; - -import javax.persistence.EntityManager; -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 PollenServiceContext getServiceContext(HttpServletRequest request) { - PollenServiceContext result = (PollenServiceContext) - request.getAttribute(REQUEST_POLLEN_SERVICE_CONTEXT); - return result; - } - - public static void setServiceContext(HttpServletRequest request, - PollenServiceContext serviceContext) { - request.setAttribute(REQUEST_POLLEN_SERVICE_CONTEXT, serviceContext); - } - - public static EntityManager getEntityManager(HttpServletRequest request) { - EntityManager result = (EntityManager) - 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 Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/AuthService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/AuthService.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/AuthService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,50 +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.services.PollenServiceContext; -import org.chorem.pollen.services.exception.EntityNotFoundException; -import org.chorem.pollen.services.exception.UserInvalidPasswordException; -import org.debux.webmotion.server.WebMotionController; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class AuthService extends WebMotionController { - - public String login(PollenServiceContext context, String login, String password) throws UserInvalidPasswordException, EntityNotFoundException { - return context.getAuthService().login(login, password); - } - - public void lostPassword(PollenServiceContext context, String login) throws EntityNotFoundException { - context.getAuthService().lostPassword(login); - } - - public void logout(PollenServiceContext context, String login, String token) throws EntityNotFoundException { - context.getAuthService().logout(login, token); - } -} Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/CommentService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/CommentService.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/CommentService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,61 +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.entity.Comment; -import org.chorem.pollen.services.PollenServiceContext; -import org.chorem.pollen.services.exception.EntityNotFoundException; -import org.debux.webmotion.server.WebMotionController; - -import java.util.List; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class CommentService extends WebMotionController { - - public List<Comment> getComments(PollenServiceContext context, String pollId) throws EntityNotFoundException { - List<Comment> comments = context.getCommentService().getComments(pollId); - return comments; - } - - public Comment getComment(PollenServiceContext context, String commentId) throws EntityNotFoundException { - return context.getCommentService().getComment(commentId); - } - - public Comment addComment(PollenServiceContext context, String pollId, Comment comment) throws EntityNotFoundException { - return context.getCommentService().addComment(pollId, comment); - } - - public Comment editComment(PollenServiceContext context,Comment comment) throws EntityNotFoundException { - return context.getCommentService().editComment(comment); - } - - public void deleteComment(PollenServiceContext context, String pollId, String commentId) throws EntityNotFoundException { - context.getCommentService().deleteComment(pollId, commentId); - } -} Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/ErrorAction.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/ErrorAction.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/ErrorAction.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,44 +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.debux.webmotion.server.WebMotionController; -import org.debux.webmotion.server.render.Render; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class ErrorAction extends WebMotionController { - - public Render on404(Exception e) { - return renderError(404, e.getMessage()); - } - - public Render on500(Exception e) { - return renderError(500, e.getMessage()); - } -} Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/FavoriteListService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/FavoriteListService.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/FavoriteListService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,99 +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.entity.FavoriteList; -import org.chorem.pollen.persistence.entity.FavoriteListMember; -import org.chorem.pollen.services.PollenServiceContext; -import org.chorem.pollen.services.exception.EntityNotFoundException; -import org.chorem.pollen.services.exception.FavoriteListImportException; -import org.chorem.pollen.services.exception.FavoriteListMemberEmailAlreadyUsedException; -import org.chorem.pollen.services.exception.FavoriteListMemberNameAlreadyUsedException; -import org.chorem.pollen.services.exception.FavoriteListMemberNotOwnedByFavoriteListException; -import org.chorem.pollen.services.exception.FavoriteListNameAlreadyUsedException; -import org.chorem.pollen.services.exception.FavoriteListNotOwnedByUserException; -import org.debux.webmotion.server.WebMotionController; - -import java.io.File; -import java.util.List; - -/** - * TODO - * TODO All method needs a userId connected - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class FavoriteListService extends WebMotionController { - - public List<FavoriteList> getFavoriteLists(PollenServiceContext context, String userId) throws EntityNotFoundException { - List<FavoriteList> favoriteLists = context.getFavoriteListService().getFavoriteLists(userId); - return favoriteLists; - } - - public FavoriteList getFavoriteList(PollenServiceContext context, String favoriteListId) throws EntityNotFoundException { - return context.getFavoriteListService().getFavoriteList(favoriteListId); - } - - public FavoriteList createFavoriteList(PollenServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, FavoriteListNameAlreadyUsedException { - return context.getFavoriteListService().createFavoriteList(userId, favoriteList); - } - - public FavoriteList editFavoriteList(PollenServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, FavoriteListNameAlreadyUsedException, FavoriteListNotOwnedByUserException { - return context.getFavoriteListService().editFavoriteList(userId, favoriteList); - } - - public void deleteFavoriteList(PollenServiceContext context, String userId, String favoriteListId) throws EntityNotFoundException, FavoriteListNotOwnedByUserException { - context.getFavoriteListService().deleteFavoriteList(userId, favoriteListId); - } - - public int importFavoriteListMembersFromCsv(PollenServiceContext context, String userId, String favoriteListId, File csvFile) throws EntityNotFoundException, FavoriteListImportException, FavoriteListNotOwnedByUserException { - return context.getFavoriteListService().importFavoriteListMembersFromCsv(userId, favoriteListId, csvFile); - } - - public int importFavoriteListMembersFromLdap(PollenServiceContext context, String userId, String favoriteListId, String ldap) throws EntityNotFoundException, FavoriteListImportException, FavoriteListNotOwnedByUserException { - return context.getFavoriteListService().importFavoriteListMembersFromLdap(userId, favoriteListId, ldap); - } - - public List<FavoriteListMember> getMembers(PollenServiceContext context, String favoriteListId) throws EntityNotFoundException { - List<FavoriteListMember> members = context.getFavoriteListService().getFavoriteListMembers(favoriteListId); - return members; - } - - public FavoriteListMember getMember(PollenServiceContext context, String memberId) throws EntityNotFoundException { - return context.getFavoriteListService().getFavoriteListMember(memberId); - } - - public FavoriteListMember addMember(PollenServiceContext context, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberEmailAlreadyUsedException, FavoriteListMemberNameAlreadyUsedException { - return context.getFavoriteListService().addFavoriteListMember(favoriteListId, member); - } - - public FavoriteListMember editMember(PollenServiceContext context, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberEmailAlreadyUsedException, FavoriteListMemberNameAlreadyUsedException, FavoriteListMemberNotOwnedByFavoriteListException { - return context.getFavoriteListService().editFavoriteListMember(favoriteListId, member); - } - - public void removeMember(PollenServiceContext context, String favoriteListId, String memberId) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException { - context.getFavoriteListService().removeFavoriteListMember(favoriteListId, memberId); - } -} Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollService.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,112 +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.entity.Choice; -import org.chorem.pollen.persistence.entity.Poll; -import org.chorem.pollen.services.PollenServiceContext; -import org.chorem.pollen.services.exception.EntityNotFoundException; -import org.debux.webmotion.server.WebMotionController; - -import java.io.File; -import java.util.List; -import java.util.Set; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class PollService extends WebMotionController { - - public Set<Poll> getPolls(PollenServiceContext context, String userId) throws EntityNotFoundException { - Set<Poll> polls = context.getPollService().getPolls(userId); - return polls; - } - - public Set<Poll> getCreatedPolls(PollenServiceContext context, String userId) throws EntityNotFoundException { - Set<Poll> polls = context.getPollService().getCreatedPolls(userId); - return polls; - } - - public Set<Poll> getInvitedPolls(PollenServiceContext context, String userId) throws EntityNotFoundException { - Set<Poll> polls = context.getPollService().getInvitedPolls(userId); - return polls; - } - - public Set<Poll> getParticipatedPolls(PollenServiceContext context, String userId) throws EntityNotFoundException { - Set<Poll> polls = context.getPollService().getParticipatedPolls(userId); - return polls; - } - - public Poll getPoll(PollenServiceContext context, String pollId) throws EntityNotFoundException { - return context.getPollService().getPoll(pollId); - } - - public Poll createPoll(PollenServiceContext context, String userId, Poll poll) throws EntityNotFoundException { - return context.getPollService().createPoll(userId, poll); - } - - public Poll editPoll(PollenServiceContext context, Poll poll) throws EntityNotFoundException { - return context.getPollService().editPoll(poll); - } - - public void deletePoll(PollenServiceContext context, String pollId) throws EntityNotFoundException { - context.getPollService().deletePoll(pollId); - } - - public Poll clonePoll(PollenServiceContext context, String pollId) throws EntityNotFoundException { - return context.getPollService().clonePoll(pollId); - } - - public File closePoll(PollenServiceContext context, String pollId) throws EntityNotFoundException { - return context.getPollService().closePoll(pollId); - } - - public File exportPoll(PollenServiceContext context, String pollId) throws EntityNotFoundException { - return context.getPollService().exportPoll(pollId); - } - - public List<Choice> getChoices(PollenServiceContext context, String pollId) throws EntityNotFoundException { - List<Choice> choices = context.getPollService().getChoices(pollId); - return choices; - } - - public Choice getChoice(PollenServiceContext context, String choiceId) throws EntityNotFoundException { - return context.getPollService().getChoice(choiceId); - } - - public Choice addChoice(PollenServiceContext context, String pollId, Choice choice) throws EntityNotFoundException { - return context.getPollService().addChoice(pollId, choice); - } - - public Choice editChoice(PollenServiceContext context, Choice choice) throws EntityNotFoundException { - return context.getPollService().editChoice(choice); - } - - public void deleteChoice(PollenServiceContext context, String pollId, String choiceId) throws EntityNotFoundException { - context.getPollService().deleteChoice(pollId, choiceId); - } -} Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenApplicationContext.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenApplicationContext.java) =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenApplicationContext.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenApplicationContext.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,125 @@ +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.chorem.pollen.persistence.JpaPollenPersistenceContext; +import org.chorem.pollen.services.DefaultPollenServiceContext; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.config.PollenServiceConfig; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; +import javax.persistence.PersistenceException; +import java.io.Closeable; +import java.util.Map; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollenApplicationContext implements Closeable { + + private static final Log log = LogFactory.getLog(PollenApplicationContext.class); + + protected static final String APPLICATION_CONTEXT_PARAMETER = "pollen_PollenApplicationContext"; + + protected PollenServiceConfig applicationConfig; + + protected EntityManagerFactory entityManagerFactory; + + public PollenServiceConfig getPollenServiceConfig() { + if (applicationConfig == null) { + applicationConfig = new PollenServiceConfig(); + } + return applicationConfig; + } + + public EntityManager newEntityManager() { + + if (entityManagerFactory == null) { + + PollenServiceConfig applicationConfig = getPollenServiceConfig(); + + Map<String, String> jpaParameters = applicationConfig.getJpaParameters(); + + if (log.isInfoEnabled()) { + log.info("creating entity manager factory"); + } + + try { + + entityManagerFactory = Persistence.createEntityManagerFactory("pollenPersistenceUnit", jpaParameters); + + } catch (PersistenceException e) { + + if (log.isErrorEnabled()) { + log.error("unable to create entity manager factory", e); + } + + throw e; + + } + + } + + EntityManager entityManager = entityManagerFactory.createEntityManager(); + + return entityManager; + + } + + public void close() { + + if (entityManagerFactory != null && entityManagerFactory.isOpen()) { + + if (log.isInfoEnabled()) { + log.info("stopping magalie, will close entity manager factory"); + } + + entityManagerFactory.close(); + + } + + } + + public PollenServiceContext newServiceContext(EntityManager entityManager) { + + DefaultPollenServiceContext serviceContext = new DefaultPollenServiceContext(); + + JpaPollenPersistenceContext jpaMagaliePersistenceContext = + new JpaPollenPersistenceContext(entityManager); + + serviceContext.setPersistenceContext(jpaMagaliePersistenceContext); + + serviceContext.setPollenServiceConfig(applicationConfig); + + return serviceContext; + + } +} Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenJpaTransactionFilter.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenJpaTransactionFilter.java) =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenJpaTransactionFilter.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenJpaTransactionFilter.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,87 @@ +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.nuiton.web.filter.JpaTransactionFilter; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceException; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; + +public class PollenJpaTransactionFilter extends JpaTransactionFilter { + + private static final Log log = + LogFactory.getLog(PollenJpaTransactionFilter.class); + + protected PollenApplicationContext applicationContext; + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + + super.init(filterConfig); + + if (log.isInfoEnabled()) { + log.info("Init JPA Filter"); + } + +// applicationContext = PollenServices.getApplicationContext( +// filterConfig.getServletContext()); +// +// Preconditions.checkNotNull(applicationContext, "Could not find application context at ServletContext#pollen_PollenApplicationContext"); + } + + 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; + } + + @Override + protected EntityManager createEntityManager(ServletRequest request) { + + EntityManager entityManager; + + try { + + entityManager = getApplicationContext(request).newEntityManager(); + + } catch (PersistenceException e) { + + if (log.isErrorEnabled()) { + log.error("unable to create entity manager", e); + } + throw e; + } + return entityManager; + } +} Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenRender.java) =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,234 @@ +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.collect.Lists; +import com.google.common.collect.Maps; +import com.google.gson.Gson; +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.util.ObjectUtil; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderFactory; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +/** + * To render any entities. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollenRender<T> extends Render { + + /** + * To specify entity collections to include in binded entities. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + public @interface ExposeCollection { + + public String[] values() default {}; + } + + protected T model; + + public PollenRender(T model) { + this.model = model; + } + + @Override + public void create(Mapping mapping, Call call) throws IOException, ServletException { + + HttpContext context = call.getContext(); + HttpServletResponse response = context.getResponse(); + response.setContentType("application/json"); + + String[] includeCollection = null; + ExposeCollection annotation = call.getCurrent().getMethod().getAnnotation(ExposeCollection.class); + if (annotation != null) { + includeCollection = annotation.values(); + } + Object map = toMap(model, includeCollection); + + Gson gson = new Gson(); + String json = gson.toJson(map); + PrintWriter out = context.getOut(); + out.print(json); + } + + protected <M> Object toMap(M model, String... includeCollection) { + if (model instanceof Iterable<?>) { + + // collection of objects + Iterable<?> objects = (Iterable<?>) model; + List<Object> result = Lists.newArrayList(); + for (Object object : objects) { + Object objectMap = toMap(object, includeCollection); + result.add(objectMap); + } + return result; + } + + // single object + + if (model instanceof JpaEntity) { + + // entity need to transform it + + JpaEntity jpaEntity = (JpaEntity) model; + + PollenEntityBinder<JpaEntity> binder = BinderFactory.newBinder(jpaEntity.getClass(), jpaEntity.getClass(), null, PollenEntityBinder.class); + Map<String, Object> map = binder.obtainProperties(jpaEntity); + 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) { + result.put(propertyName, toMap(propertyValue)); + continue; + } + + result.put(propertyName, propertyValue); + } + + // treat collections + + if (includeCollection != null) { + for (String propertyName : includeCollection) { + Iterable<?> collectionValue = binder.getCollectionValue(jpaEntity, propertyName); + result.put(propertyName, toMap(collectionValue)); + + } + } + return result; + } + + return model; + } + + protected static class PollenEntityBinder<E extends JpaEntity> extends Binder<E, E> { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(PollenEntityBinder.class); + + private static final long serialVersionUID = 1L; + + protected List<String> simpleProperties; + + public PollenEntityBinder() { + } + + @Override + protected void setModel(BinderModel<E, E> model) { + super.setModel(model); + this.simpleProperties = Lists.newArrayList(); + for (String property : model.getSourceDescriptors()) { + if (model.getCollectionType(property) == null) { + simpleProperties.add(property); + } + } + } + + /** + * Obtain from the given object all properties registered in the binder + * model. + * + * @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}. + * @since 2.3 + */ + public Map<String, Object> obtainProperties(E source) { + if (source == null) { + // special limit case + return Collections.emptyMap(); + } + + Map<String, Object> result = Maps.newTreeMap(); + for (String sourceProperty : simpleProperties) { + + + try { + Object read; + Method readMethod = model.getSourceReadMethod(sourceProperty); + read = readMethod.invoke(source); + if (log.isDebugEnabled()) { + log.debug("property " + sourceProperty + ", type : " + + readMethod.getReturnType() + ", value = " + read); + } + if (readMethod.getReturnType().isPrimitive() && + ObjectUtil.getNullValue( + readMethod.getReturnType()).equals(read)) { + // for primitive type case, force nullity + read = null; + } + + if (read != null) { + result.put(sourceProperty, read); + } + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } + } + return result; + } + + public Iterable<?> getCollectionValue(E source, String sourceProperty) { + try { + Method readMethod = model.getSourceReadMethod(sourceProperty); + Object result = readMethod.invoke(source); + return (Iterable<?>) result; + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } + } + } +} Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceContextFilter.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceContextFilter.java) =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceContextFilter.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceContextFilter.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,84 @@ +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.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.persistence.EntityManager; + +/** + * 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()); + + EntityManager entityManager = + PollenServices.getEntityManager(context.getRequest()); + + PollenServiceContext serviceContext = + applicationContext.newServiceContext(entityManager); + PollenServices.setServiceContext(context.getRequest(), serviceContext); + + addSecurityContext(context, serviceContext); + + doProcess(); + } + + protected void addSecurityContext(HttpContext context, + PollenServiceContext serviceContext) throws InvalidSessionTokenException { + + String[] strings = context.getParameters().get(REQUEST_AUTH_PARAMETER); + + String authParam = strings == null || strings.length < 1 ? null : strings[1]; + + SessionToken sessionToken = null; + + if (StringUtils.isNotBlank(authParam)) { + + // find out the userId from this auth + + sessionToken = serviceContext.getAuthService().getUserByAuth(authParam); + } + PollenSecurityContext securityContext; + securityContext = PollenSecurityContext.newContext( + sessionToken == null ? null : sessionToken.getPollenUser() + ); + serviceContext.setSecurityContext(securityContext); + } +} Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceListener.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceListener.java) =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceListener.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceListener.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -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.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.exception.UserEmailAlreadyUsedException; +import org.chorem.pollen.services.exception.UserLoginAlreadyUsedException; +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.persistence.EntityManager; +import javax.servlet.http.HttpServletRequest; +import java.lang.reflect.Type; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollenServiceListener implements WebMotionServerListener { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(PollenServiceListener.class); + + @Override + public void onStart(Mapping mapping, ServerContext serverContext) { + + serverContext.addInjector(new PollenServiceContextInjector()); + serverContext.addInjector(new SessionTokenInjector()); + + // Create application context + PollenApplicationContext applicationContext = + new PollenApplicationContext(); + + // push it in context + PollenServices.setApplicationContext( + serverContext.getServletContext(), applicationContext); + + EntityManager entityManager = applicationContext.newEntityManager(); + + try { + PollenServiceContext serviceContext = + applicationContext.newServiceContext(entityManager); + serviceContext.getUserService().createDefaultUsers(); + } catch (UserEmailAlreadyUsedException e) { + //Can't happen + } catch (UserLoginAlreadyUsedException e) { + //Can't happen + } finally { + entityManager.close(); + } + } + + @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 Object getValue(Mapping mapping, Call call, String name, Class<?> type, Type generic) { + PollenServiceContext result = null; + if (PollenServiceContext.class.isAssignableFrom(type)) { + HttpContext httpContext = call.getContext(); + HttpServletRequest request = httpContext.getRequest(); + + result = PollenServices.getServiceContext(request); + } + return result; + } + } + + protected static class SessionTokenInjector implements ExecutorParametersInjectorHandler.Injector { + @Override + public Object getValue(Mapping mapping, Call call, String name, Class<?> type, Type generic) { + PollenServiceContext result = null; + if (PollenServiceContext.class.isAssignableFrom(type)) { + HttpContext httpContext = call.getContext(); + HttpServletRequest request = httpContext.getRequest(); + + result = PollenServices.getServiceContext(request); + } + return result; + } + } +} Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServices.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServices.java) =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServices.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServices.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,89 @@ +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.entity.SessionToken; +import org.chorem.pollen.services.PollenServiceContext; +import org.nuiton.web.filter.JpaTransactionFilter; + +import javax.persistence.EntityManager; +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 PollenServiceContext getServiceContext(HttpServletRequest request) { + PollenServiceContext result = (PollenServiceContext) + request.getAttribute(REQUEST_POLLEN_SERVICE_CONTEXT); + return result; + } + + public static void setServiceContext(HttpServletRequest request, + PollenServiceContext serviceContext) { + request.setAttribute(REQUEST_POLLEN_SERVICE_CONTEXT, serviceContext); + } + + public static EntityManager getEntityManager(HttpServletRequest request) { + EntityManager result = (EntityManager) + 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 Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/UserService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/UserService.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/UserService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,79 +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.entity.PollenUser; -import org.chorem.pollen.services.PollenServiceContext; -import org.chorem.pollen.services.exception.EntityNotFoundException; -import org.chorem.pollen.services.exception.UserEmailAlreadyUsedException; -import org.chorem.pollen.services.exception.UserInvalidEmailActiviationTokenException; -import org.chorem.pollen.services.exception.UserInvalidPasswordException; -import org.chorem.pollen.services.exception.UserLoginAlreadyUsedException; -import org.debux.webmotion.server.WebMotionController; - -import java.util.List; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class UserService extends WebMotionController { - - public List<PollenUser> getUsers(PollenServiceContext context) { - List<PollenUser> users = context.getUserService().getUsers(); - return users; - } - - public PollenUser getUser(PollenServiceContext context, - String userId) throws EntityNotFoundException { - return context.getUserService().getUser(userId); - } - - public PollenUser createUser(PollenServiceContext context, - PollenUser user, - boolean generatePassword) throws UserEmailAlreadyUsedException, UserLoginAlreadyUsedException { - return context.getUserService().createUser(user, generatePassword); - - } - - public PollenUser editUser(PollenServiceContext context, - PollenUser user) throws UserInvalidPasswordException, UserEmailAlreadyUsedException, EntityNotFoundException { - return context.getUserService().editUser(user); - } - - public void validateUserEmail(PollenServiceContext context, - String userId, - String token) throws EntityNotFoundException, UserInvalidEmailActiviationTokenException { - context.getUserService().validateUserEmail(userId, token); - } - - public void changePassword(PollenServiceContext context, - String userId, - String oldPassword, - String newPassword) throws UserInvalidPasswordException, EntityNotFoundException { - context.getUserService().changePassword(userId, oldPassword, newPassword); - } -} Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteCountingService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteCountingService.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteCountingService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,42 +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.services.PollResult; -import org.chorem.pollen.services.PollenServiceContext; -import org.chorem.pollen.services.exception.EntityNotFoundException; -import org.debux.webmotion.server.WebMotionController; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class VoteCountingService extends WebMotionController { - - public PollResult getResult(PollenServiceContext context, String pollId) throws EntityNotFoundException { - return context.getVoteCountingService().getResult(pollId); - } -} Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteService.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,61 +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.entity.Vote; -import org.chorem.pollen.services.PollenServiceContext; -import org.chorem.pollen.services.exception.EntityNotFoundException; -import org.debux.webmotion.server.WebMotionController; - -import java.util.List; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class VoteService extends WebMotionController { - - public List<Vote> getVotes(PollenServiceContext context, String pollId) throws EntityNotFoundException { - List<Vote> votes = context.getVoteService().getVotes(pollId); - return votes; - } - - public Vote getVote(PollenServiceContext context, String voteId) throws EntityNotFoundException { - return context.getVoteService().getVote(voteId); - } - - public Vote addVote(PollenServiceContext context, String pollId, Vote vote) throws EntityNotFoundException { - return context.getVoteService().addVote(pollId, vote); - } - - public Vote editVote(PollenServiceContext context, Vote vote) throws EntityNotFoundException { - return context.getVoteService().editVote(vote); - } - - public void deleteVote(PollenServiceContext context, String pollId, String voteId) throws EntityNotFoundException { - context.getVoteService().deleteVote(pollId, voteId); - } -} Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoterListService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoterListService.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoterListService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,88 +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.entity.VoterList; -import org.chorem.pollen.persistence.entity.VoterListMember; -import org.chorem.pollen.services.PollenServiceContext; -import org.chorem.pollen.services.exception.EntityNotFoundException; -import org.debux.webmotion.server.WebMotionController; - -import java.util.List; -import java.util.Set; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class VoterListService extends WebMotionController { - - public VoterList importFavoriteList(PollenServiceContext context, String pollId, String favoriteListId) throws EntityNotFoundException { - return context.getVoterListService().importFavoriteList(pollId, favoriteListId); - } - - public List<VoterList> getVoterLists(PollenServiceContext context, String pollId) throws EntityNotFoundException { - List<VoterList> voterLists = context.getVoterListService().getVoterLists(pollId); - return voterLists; - } - - public VoterList getVoterList(PollenServiceContext context, String voterListId) throws EntityNotFoundException { - return context.getVoterListService().getVoterList(voterListId); - } - - public VoterList addVoterList(PollenServiceContext context, String pollId, VoterList voterList) throws EntityNotFoundException { - return context.getVoterListService().addVoterList(pollId, voterList); - } - - public VoterList editVoterList(PollenServiceContext context, VoterList voterList) throws EntityNotFoundException { - return context.getVoterListService().editVoterList(voterList); - } - - public void deleteVoterList(PollenServiceContext context, String pollId, String voterListId) throws EntityNotFoundException { - context.getVoterListService().deleteVoterList(pollId, voterListId); - } - - public Set<VoterListMember> getMembers(PollenServiceContext context, String voterListId) throws EntityNotFoundException { - Set<VoterListMember> members = context.getVoterListService().getMembers(voterListId); - return members; - } - - public VoterListMember getMember(PollenServiceContext context, String memberId) throws EntityNotFoundException { - return context.getVoterListService().getMember(memberId); - } - - public VoterListMember addMember(PollenServiceContext context, String voterListId, VoterListMember member) throws EntityNotFoundException { - return context.getVoterListService().addMember(voterListId, member); - } - - public VoterListMember editMember(PollenServiceContext context, VoterListMember member) throws EntityNotFoundException { - return context.getVoterListService().editMember(member); - } - - public void deleteMember(PollenServiceContext context, String voterListId, String memberId) throws EntityNotFoundException { - context.getVoterListService().deleteMember(voterListId, memberId); - } -} Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthService.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/AuthService.java) =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthService.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,50 @@ +package org.chorem.pollen.rest.api.v1; + +/* + * #%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.services.PollenServiceContext; +import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.chorem.pollen.services.exception.UserInvalidPasswordException; +import org.debux.webmotion.server.WebMotionController; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class AuthService extends WebMotionController { + + public String login(PollenServiceContext context, String login, String password) throws UserInvalidPasswordException, EntityNotFoundException { + return context.getAuthService().login(login, password); + } + + public void lostPassword(PollenServiceContext context, String login) throws EntityNotFoundException { + context.getAuthService().lostPassword(login); + } + + public void logout(PollenServiceContext context, String login, String token) throws EntityNotFoundException { + context.getAuthService().logout(login, token); + } +} Added: 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 (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,62 @@ +package org.chorem.pollen.rest.api.v1; + +/* + * #%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.entity.Choice; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.chorem.pollen.services.exception.InvalidChoiceFormException; +import org.debux.webmotion.server.WebMotionController; + +import java.util.List; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class ChoiceService extends WebMotionController { + + public List<Choice> getChoices(PollenServiceContext context, String pollId) throws EntityNotFoundException { + List<Choice> choices = context.getChoiceService().getChoices(pollId); + return choices; + } + + public Choice getChoice(PollenServiceContext context, String pollId, String choiceId) throws EntityNotFoundException { + return context.getChoiceService().getChoice(pollId, choiceId); + } + + public Choice addChoice(PollenServiceContext context, String pollId, Choice choice) throws EntityNotFoundException, InvalidChoiceFormException { + return context.getChoiceService().addChoice(pollId, choice); + } + + public Choice editChoice(PollenServiceContext context, String pollId, Choice choice) throws EntityNotFoundException, InvalidChoiceFormException { + return context.getChoiceService().editChoice(pollId, choice); + } + + public void deleteChoice(PollenServiceContext context, String pollId, String choiceId) throws EntityNotFoundException { + context.getChoiceService().deleteChoice(pollId, choiceId); + } +} \ No newline at end of file Property changes on: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentService.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/CommentService.java) =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentService.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,61 @@ +package org.chorem.pollen.rest.api.v1; + +/* + * #%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.entity.Comment; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.debux.webmotion.server.WebMotionController; + +import java.util.List; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class CommentService extends WebMotionController { + + public List<Comment> getComments(PollenServiceContext context, String pollId) throws EntityNotFoundException { + List<Comment> comments = context.getCommentService().getComments(pollId); + return comments; + } + + public Comment getComment(PollenServiceContext context, String commentId) throws EntityNotFoundException { + return context.getCommentService().getComment(commentId); + } + + public Comment addComment(PollenServiceContext context, String pollId, Comment comment) throws EntityNotFoundException { + return context.getCommentService().addComment(pollId, comment); + } + + public Comment editComment(PollenServiceContext context,Comment comment) throws EntityNotFoundException { + return context.getCommentService().editComment(comment); + } + + public void deleteComment(PollenServiceContext context, String pollId, String commentId) throws EntityNotFoundException { + context.getCommentService().deleteComment(pollId, commentId); + } +} Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ErrorAction.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/ErrorAction.java) =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ErrorAction.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ErrorAction.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,55 @@ +package org.chorem.pollen.rest.api.v1; + +/* + * #%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.collect.Multimap; +import org.chorem.pollen.services.exception.AbstractInvalidFormException; +import org.debux.webmotion.server.WebMotionController; +import org.debux.webmotion.server.render.Render; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class ErrorAction extends WebMotionController { + + public Render on404(Exception e) { + return renderError(404, e.getMessage()); + } + + public Render on500(Exception e) { + return renderError(500, e.getMessage()); + } + + public Render on500Form(Exception e) { + AbstractInvalidFormException ex = (AbstractInvalidFormException) e; + + //TODO Send back this + Multimap<String, String> errors = ex.getErrors(); + + return renderError(500, e.getMessage()); + } +} Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListService.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/FavoriteListService.java) =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListService.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,99 @@ +package org.chorem.pollen.rest.api.v1; + +/* + * #%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.entity.FavoriteList; +import org.chorem.pollen.persistence.entity.FavoriteListMember; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.chorem.pollen.services.exception.FavoriteListImportException; +import org.chorem.pollen.services.exception.FavoriteListMemberEmailAlreadyUsedException; +import org.chorem.pollen.services.exception.FavoriteListMemberNameAlreadyUsedException; +import org.chorem.pollen.services.exception.FavoriteListMemberNotOwnedByFavoriteListException; +import org.chorem.pollen.services.exception.FavoriteListNameAlreadyUsedException; +import org.chorem.pollen.services.exception.FavoriteListNotOwnedByUserException; +import org.debux.webmotion.server.WebMotionController; + +import java.io.File; +import java.util.List; + +/** + * TODO + * TODO All method needs a userId connected + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class FavoriteListService extends WebMotionController { + + public List<FavoriteList> getFavoriteLists(PollenServiceContext context, String userId) throws EntityNotFoundException { + List<FavoriteList> favoriteLists = context.getFavoriteListService().getFavoriteLists(userId); + return favoriteLists; + } + + public FavoriteList getFavoriteList(PollenServiceContext context, String favoriteListId) throws EntityNotFoundException { + return context.getFavoriteListService().getFavoriteList(favoriteListId); + } + + public FavoriteList createFavoriteList(PollenServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, FavoriteListNameAlreadyUsedException { + return context.getFavoriteListService().createFavoriteList(userId, favoriteList); + } + + public FavoriteList editFavoriteList(PollenServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, FavoriteListNameAlreadyUsedException, FavoriteListNotOwnedByUserException { + return context.getFavoriteListService().editFavoriteList(userId, favoriteList); + } + + public void deleteFavoriteList(PollenServiceContext context, String userId, String favoriteListId) throws EntityNotFoundException, FavoriteListNotOwnedByUserException { + context.getFavoriteListService().deleteFavoriteList(userId, favoriteListId); + } + + public int importFavoriteListMembersFromCsv(PollenServiceContext context, String userId, String favoriteListId, File csvFile) throws EntityNotFoundException, FavoriteListImportException, FavoriteListNotOwnedByUserException { + return context.getFavoriteListService().importFavoriteListMembersFromCsv(userId, favoriteListId, csvFile); + } + + public int importFavoriteListMembersFromLdap(PollenServiceContext context, String userId, String favoriteListId, String ldap) throws EntityNotFoundException, FavoriteListImportException, FavoriteListNotOwnedByUserException { + return context.getFavoriteListService().importFavoriteListMembersFromLdap(userId, favoriteListId, ldap); + } + + public List<FavoriteListMember> getMembers(PollenServiceContext context, String favoriteListId) throws EntityNotFoundException { + List<FavoriteListMember> members = context.getFavoriteListService().getFavoriteListMembers(favoriteListId); + return members; + } + + public FavoriteListMember getMember(PollenServiceContext context, String memberId) throws EntityNotFoundException { + return context.getFavoriteListService().getFavoriteListMember(memberId); + } + + public FavoriteListMember addMember(PollenServiceContext context, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberEmailAlreadyUsedException, FavoriteListMemberNameAlreadyUsedException { + return context.getFavoriteListService().addFavoriteListMember(favoriteListId, member); + } + + public FavoriteListMember editMember(PollenServiceContext context, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberEmailAlreadyUsedException, FavoriteListMemberNameAlreadyUsedException, FavoriteListMemberNotOwnedByFavoriteListException { + return context.getFavoriteListService().editFavoriteListMember(favoriteListId, member); + } + + public void removeMember(PollenServiceContext context, String favoriteListId, String memberId) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException { + context.getFavoriteListService().removeFavoriteListMember(favoriteListId, memberId); + } +} Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollService.java) =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,95 @@ +package org.chorem.pollen.rest.api.v1; + +/* + * #%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.entity.ChoiceType; +import org.chorem.pollen.persistence.entity.Poll; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.chorem.pollen.services.exception.InvalidPollFormException; +import org.debux.webmotion.server.WebMotionController; + +import java.io.File; +import java.util.Set; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollService extends WebMotionController { + + public Poll getNewPoll(PollenServiceContext context, String userId, ChoiceType choiceType) throws EntityNotFoundException { + return context.getPollService().getNewPoll(userId, choiceType); + } + + public Set<Poll> getPolls(PollenServiceContext context, String userId) throws EntityNotFoundException { + Set<Poll> polls = context.getPollService().getPolls(userId); + return polls; + } + + public Set<Poll> getCreatedPolls(PollenServiceContext context, String userId) throws EntityNotFoundException { + Set<Poll> polls = context.getPollService().getCreatedPolls(userId); + return polls; + } + + public Set<Poll> getInvitedPolls(PollenServiceContext context, String userId) throws EntityNotFoundException { + Set<Poll> polls = context.getPollService().getInvitedPolls(userId); + return polls; + } + + public Set<Poll> getParticipatedPolls(PollenServiceContext context, String userId) throws EntityNotFoundException { + Set<Poll> polls = context.getPollService().getParticipatedPolls(userId); + return polls; + } + + public Poll getPoll(PollenServiceContext context, String pollId) throws EntityNotFoundException { + return context.getPollService().getPoll(pollId); + } + + public Poll createPoll(PollenServiceContext context, String userId, Poll poll) throws EntityNotFoundException, InvalidPollFormException { + return context.getPollService().createPoll(userId, poll); + } + + public Poll editPoll(PollenServiceContext context, Poll poll) throws EntityNotFoundException, InvalidPollFormException { + return context.getPollService().editPoll(poll); + } + + public void deletePoll(PollenServiceContext context, String pollId) throws EntityNotFoundException { + context.getPollService().deletePoll(pollId); + } + + public Poll clonePoll(PollenServiceContext context, String pollId) throws EntityNotFoundException { + return context.getPollService().clonePoll(pollId); + } + + public File closePoll(PollenServiceContext context, String pollId) throws EntityNotFoundException { + return context.getPollService().closePoll(pollId); + } + + public File exportPoll(PollenServiceContext context, String pollId) throws EntityNotFoundException { + return context.getPollService().exportPoll(pollId); + } +} Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/UserService.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/UserService.java) =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/UserService.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/UserService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,79 @@ +package org.chorem.pollen.rest.api.v1; + +/* + * #%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.entity.PollenUser; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.chorem.pollen.services.exception.UserEmailAlreadyUsedException; +import org.chorem.pollen.services.exception.UserInvalidEmailActiviationTokenException; +import org.chorem.pollen.services.exception.UserInvalidPasswordException; +import org.chorem.pollen.services.exception.UserLoginAlreadyUsedException; +import org.debux.webmotion.server.WebMotionController; + +import java.util.List; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class UserService extends WebMotionController { + + public List<PollenUser> getUsers(PollenServiceContext context) { + List<PollenUser> users = context.getUserService().getUsers(); + return users; + } + + public PollenUser getUser(PollenServiceContext context, + String userId) throws EntityNotFoundException { + return context.getUserService().getUser(userId); + } + + public PollenUser createUser(PollenServiceContext context, + PollenUser user, + boolean generatePassword) throws UserEmailAlreadyUsedException, UserLoginAlreadyUsedException { + return context.getUserService().createUser(user, generatePassword); + + } + + public PollenUser editUser(PollenServiceContext context, + PollenUser user) throws UserInvalidPasswordException, UserEmailAlreadyUsedException, EntityNotFoundException { + return context.getUserService().editUser(user); + } + + public void validateUserEmail(PollenServiceContext context, + String userId, + String token) throws EntityNotFoundException, UserInvalidEmailActiviationTokenException { + context.getUserService().validateUserEmail(userId, token); + } + + public void changePassword(PollenServiceContext context, + String userId, + String oldPassword, + String newPassword) throws UserInvalidPasswordException, EntityNotFoundException { + context.getUserService().changePassword(userId, oldPassword, newPassword); + } +} Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingService.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteCountingService.java) =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingService.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,42 @@ +package org.chorem.pollen.rest.api.v1; + +/* + * #%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.services.PollResult; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.debux.webmotion.server.WebMotionController; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class VoteCountingService extends WebMotionController { + + public PollResult getResult(PollenServiceContext context, String pollId) throws EntityNotFoundException { + return context.getVoteCountingService().getResult(pollId); + } +} Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteService.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteService.java) =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteService.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,61 @@ +package org.chorem.pollen.rest.api.v1; + +/* + * #%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.entity.Vote; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.debux.webmotion.server.WebMotionController; + +import java.util.List; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class VoteService extends WebMotionController { + + public List<Vote> getVotes(PollenServiceContext context, String pollId) throws EntityNotFoundException { + List<Vote> votes = context.getVoteService().getVotes(pollId); + return votes; + } + + public Vote getVote(PollenServiceContext context, String voteId) throws EntityNotFoundException { + return context.getVoteService().getVote(voteId); + } + + public Vote addVote(PollenServiceContext context, String pollId, Vote vote) throws EntityNotFoundException { + return context.getVoteService().addVote(pollId, vote); + } + + public Vote editVote(PollenServiceContext context, Vote vote) throws EntityNotFoundException { + return context.getVoteService().editVote(vote); + } + + public void deleteVote(PollenServiceContext context, String pollId, String voteId) throws EntityNotFoundException { + context.getVoteService().deleteVote(pollId, voteId); + } +} Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoterListService.java) =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,88 @@ +package org.chorem.pollen.rest.api.v1; + +/* + * #%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.entity.VoterList; +import org.chorem.pollen.persistence.entity.VoterListMember; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.debux.webmotion.server.WebMotionController; + +import java.util.List; +import java.util.Set; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class VoterListService extends WebMotionController { + + public VoterList importFavoriteList(PollenServiceContext context, String pollId, String favoriteListId) throws EntityNotFoundException { + return context.getVoterListService().importFavoriteList(pollId, favoriteListId); + } + + public List<VoterList> getVoterLists(PollenServiceContext context, String pollId) throws EntityNotFoundException { + List<VoterList> voterLists = context.getVoterListService().getVoterLists(pollId); + return voterLists; + } + + public VoterList getVoterList(PollenServiceContext context, String pollId, String voterListId) throws EntityNotFoundException { + return context.getVoterListService().getVoterList(pollId, voterListId); + } + + public VoterList addVoterList(PollenServiceContext context, String pollId, VoterList voterList) throws EntityNotFoundException { + return context.getVoterListService().addVoterList(pollId, voterList); + } + + public VoterList editVoterList(PollenServiceContext context, String pollId, VoterList voterList) throws EntityNotFoundException { + return context.getVoterListService().editVoterList(pollId, voterList); + } + + public void deleteVoterList(PollenServiceContext context, String pollId, String voterListId) throws EntityNotFoundException { + context.getVoterListService().deleteVoterList(pollId, voterListId); + } + + public Set<VoterListMember> getMembers(PollenServiceContext context, String pollId, String voterListId) throws EntityNotFoundException { + Set<VoterListMember> members = context.getVoterListService().getMembers(pollId, voterListId); + return members; + } + + public VoterListMember getMember(PollenServiceContext context, String pollId, String voterListId, String memberId) throws EntityNotFoundException { + return context.getVoterListService().getMember(pollId, voterListId, memberId); + } + + public VoterListMember addMember(PollenServiceContext context, String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException { + return context.getVoterListService().addMember(pollId, voterListId, member); + } + + public VoterListMember editMember(PollenServiceContext context, String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException { + return context.getVoterListService().editMember(pollId, voterListId, member); + } + + public void deleteMember(PollenServiceContext context, String pollId, String voterListId, String memberId) throws EntityNotFoundException { + context.getVoterListService().deleteMember(pollId, voterListId, memberId); + } +} Modified: trunk/pollen-rest-api/src/main/resources/mapping =================================================================== --- trunk/pollen-rest-api/src/main/resources/mapping 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-rest-api/src/main/resources/mapping 2013-06-15 10:58:03 UTC (rev 3830) @@ -7,8 +7,6 @@ [filters] * /* PollenServiceContextFilter.inject -#* /* PollenIdOrTokenInjector.inject -#* /* PollenSecurityFilter.inject (prend le param auth pour retrouver le PollenUser) #- une fois un object lié à PollenUser, c'est immuable. @@ -19,89 +17,93 @@ org.chorem.pollen.service.exception.UserLoginAlreadyUsedException ErrorAction.on500 org.chorem.pollen.service.exception.UserInvalidPasswordException ErrorAction.on500 org.chorem.pollen.service.exception.UserInvalidEmailActiviationTokenException ErrorAction.on500 +org.chorem.pollen.service.exception.AbstractInvalidFormException ErrorAction.on500Form [actions] # AuthService -PUT /login AuthService.login -GET /lostpassword/{token} AuthService.lostPassword -GET /logout AuthService.logout +PUT /v1/login AuthService.login +GET /v1/lostpassword/{token} AuthService.lostPassword +GET /v1/logout AuthService.logout +# ChoiceService + +GET /v1/polls/{pollId}/choices ChoiceService.getChoices +POST /v1/polls/{pollId}/choices ChoiceService.addChoice +GET /v1/polls/{pollId}/choices/{choiceId} ChoiceService.getChoice +PUT /v1/polls/{pollId}/choices/{choiceId} ChoiceService.editChoice +DELETE /v1/polls/{pollId}/choices/{choiceId} ChoiceService.deleteChoice + # CommentService -GET /polls/{pollId}/comments CommentService.getComments -POST /polls/{pollId}/comments CommentService.addComment -GET /comments/{commentId} CommentService.getComment -PUT /comments/{commentId} CommentService.editComment -DELETE /polls/{pollId}/comments/{commentId} CommentService.deleteComment +GET /v1/polls/{pollId}/comments CommentService.getComments +POST /v1/polls/{pollId}/comments CommentService.addComment +GET /v1/polls/{pollId}/comments/{commentId} CommentService.getComment +PUT /v1/polls/{pollId}/comments/{commentId} CommentService.editComment +DELETE /v1/polls/{pollId}/comments/{commentId} CommentService.deleteComment # FavoriteListService -GET /favoriteLists FavoriteListService.getFavoriteLists -GET /favoriteLists/{flId} FavoriteListService.getFavoriteList -POST /favoriteLists/{flId}/importCsv FavoriteListService.importFavoriteListMemberFromCsv -POST /favoriteLists/{flId}/importLdap FavoriteListService.importFavoriteListMemberFromLdap -POST /favoriteLists FavoriteListService.createFavoriteList -PUT /favoriteLists/{flId} FavoriteListService.editFavoriteList -DELETE /favoriteLists/{flId} FavoriteListService.deleteFavoriteList -GET /favoriteLists/{flId}/members FavoriteListService.getMembers -GET /favoriteListMembers/{mId} FavoriteListService.getMember -POST /favoriteLists/{flId}/members FavoriteListService.addMember -PUT /favoriteLists/{flId}/members/{mId} FavoriteListService.editMember -DELETE /favoriteLists/{flId}/members/{mId} FavoriteListService.removeMember +GET /v1/favoriteLists FavoriteListService.getFavoriteLists +GET /v1/favoriteLists/{flId} FavoriteListService.getFavoriteList +POST /v1/favoriteLists/{flId}/importCsv FavoriteListService.importFavoriteListMemberFromCsv +POST /v1/favoriteLists/{flId}/importLdap FavoriteListService.importFavoriteListMemberFromLdap +POST /v1/favoriteLists FavoriteListService.createFavoriteList +PUT /v1/favoriteLists/{flId} FavoriteListService.editFavoriteList +DELETE /v1/favoriteLists/{flId} FavoriteListService.deleteFavoriteList +GET /v1/favoriteLists/{flId}/members FavoriteListService.getMembers +GET /v1/favoriteLists/{flId}/members/{mId} FavoriteListService.getMember +POST /v1/favoriteLists/{flId}/members FavoriteListService.addMember +PUT /v1/favoriteLists/{flId}/members/{mId} FavoriteListService.editMember +DELETE /v1/favoriteLists/{flId}/members/{mId} FavoriteListService.removeMember # PollService -GET /polls PollService.getPolls -GET /polls/created PollService.getCreatedPolls -GET /polls/invited PollService.getInvitedPolls -GET /polls/participated PollService.getParticipatedPolls -POST /polls PollService.createPoll -PUT /polls/{pollId} PollService.editPoll -GET /polls/{pollId} PollService.getPoll -DELETE /polls/{pollId} PollService.deletePoll -POST /polls/{pollId} PollService.clonePoll -GET /polls/{pollId}/export PollService.exportPoll -PUT /polls/{pollId}/close PollService.closePoll +GET /v1/polls/new PollService.getNewPoll +GET /v1/polls PollService.getPolls +GET /v1/polls/created PollService.getCreatedPolls +GET /v1/polls/invited PollService.getInvitedPolls +GET /v1/polls/participated PollService.getParticipatedPolls +POST /v1/polls PollService.createPoll +PUT /v1/polls/{pollId} PollService.editPoll +GET /v1/polls/{pollId} PollService.getPoll +DELETE /v1/polls/{pollId} PollService.deletePoll +POST /v1/polls/{pollId} PollService.clonePoll +GET /v1/polls/{pollId}/export PollService.exportPoll +PUT /v1/polls/{pollId}/close PollService.closePoll -GET /polls/{pollId}/choices PollService.getChoices -POST /polls/{pollId}/choices PollService.addChoice -GET /choices/{choiceId} PollService.getChoice -PUT /choices/{choiceId} PollService.editChoice -DELETE /polls/{pollId}/choices/{choiceId} PollService.deleteChoice - # UserService -GET /users UserService.getUsers -GET /users/{userId} UserService.getUser -POST /users UserService.createUser -PUT /users/{userId} UserService.editUser -PUT /users/{userId}?token={} UserService.validateUserEmail +GET /v1/users UserService.getUsers +GET /v1/users/{userId} UserService.getUser +POST /v1/users UserService.createUser +PUT /v1/users/{userId} UserService.editUser +PUT /v1/users/{userId}?token={} UserService.validateUserEmail # VoteCountingService -GET /polls/{pollId}/results VoteCountingService.getResult +GET /v1/polls/{pollId}/results VoteCountingService.getResult # VoterListService -PUT /polls/{pollId}/favoriteLists/{flId} VoterListService.importFavoriteList -GET /polls/{pollId}/voterLists VoterListService.getVoterLists -GET /voterLists/{vlId} VoterListService.getVoterList -POST /voterLists VoterListService.createVoterList -PUT /voterLists/{vlId} VoterListService.editVoterList -DELETE /polls/{pollId}/voterLists/{vlId} VoterListService.deleteVoterList +PUT /v1/polls/{pollId}/favoriteLists/{flId} VoterListService.importFavoriteList +GET /v1/polls/{pollId}/voterLists VoterListService.getVoterLists +GET /v1/polls/{pollId}/voterLists/{vlId} VoterListService.getVoterList +POST /v1/polls/{pollId}/voterLists VoterListService.createVoterList +PUT /v1/polls/{pollId}/voterLists/{vlId} VoterListService.editVoterList +DELETE /v1/polls/{pollId}/voterLists/{vlId} VoterListService.deleteVoterList -GET /voterLists/{vlId}/members VoterListService.getMembers -GET /voterListMembers/{mId} VoterListService.getMember -POST /voterLists/{vlId}/members VoterListService.addMember -PUT /voterListMembers/{mId} VoterListService.editMember -DELETE /voterLists/{vlId}/members/{mId} VoterListService.deleteMember +GET /v1/polls/{pollId}/voterLists/{vlId}/members VoterListService.getMembers +GET /v1/polls/{pollId}/voterLists/{vlId}/members/{mId} VoterListService.getMember +POST /v1/polls/{pollId}/voterLists/{vlId}/members VoterListService.addMember +PUT /v1/polls/{pollId}/voterLists/{vlId}/members/{mId} VoterListService.editMember +DELETE /v1/polls/{pollId}/voterLists/{vlId}/members/{mId} VoterListService.deleteMember # VoteService -GET /polls/{pollId}/votes VoteService.getVotes -PUT /polls/{pollId}/votes VoteService.addVote -GET /votes/{voteId} VoteService.getVote -PUT /votes/{voteId} VoteService.editVote -DELETE /polls/{pollId}/votes/{voteId} VoteService.deleteVote +GET /v1/polls/{pollId}/votes VoteService.getVotes +PUT /v1/polls/{pollId}/votes VoteService.addVote +GET /v1/polls/{pollId}/votes/{voteId} VoteService.getVote +PUT /v1/polls/{pollId}/votes/{voteId} VoteService.editVote +DELETE /v1/polls/{pollId}/votes/{voteId} VoteService.deleteVote Modified: trunk/pollen-rest-api/src/main/webapp/WEB-INF/web.xml =================================================================== --- trunk/pollen-rest-api/src/main/webapp/WEB-INF/web.xml 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-rest-api/src/main/webapp/WEB-INF/web.xml 2013-06-15 10:58:03 UTC (rev 3830) @@ -33,7 +33,7 @@ <filter> <filter-name>jpaTransaction</filter-name> <filter-class> - org.chorem.pollen.rest.PollenJpaTransactionFilter + org.chorem.pollen.rest.api.PollenJpaTransactionFilter </filter-class> </filter> 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 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -24,7 +24,6 @@ */ import org.chorem.pollen.persistence.JpaPollenPersistenceContext; -import org.chorem.pollen.rest.PollenApplicationContext; import org.chorem.pollen.services.service.FixturesService; import org.chorem.pollen.services.PollenFixtures; import org.chorem.pollen.services.PollenServiceContext; Modified: trunk/pollen-rest-api/src/test/resources/pollen.properties =================================================================== --- trunk/pollen-rest-api/src/test/resources/pollen.properties 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-rest-api/src/test/resources/pollen.properties 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,3 +1,25 @@ +### +# #%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 Modified: trunk/pollen-services/pom.xml =================================================================== --- trunk/pollen-services/pom.xml 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-services/pom.xml 2013-06-15 10:58:03 UTC (rev 3830) @@ -99,6 +99,11 @@ </dependency> <dependency> + <groupId>org.apache.shiro</groupId> + <artifactId>shiro-core</artifactId> + </dependency> + + <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>test</scope> 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 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -28,11 +28,13 @@ import org.chorem.pollen.persistence.PollenPersistenceContext; import org.chorem.pollen.services.config.PollenServiceConfig; 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.EmailService; 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.SecurityService; import org.chorem.pollen.services.service.UserService; import org.chorem.pollen.services.service.VoteCountingService; import org.chorem.pollen.services.service.VoteService; @@ -50,6 +52,8 @@ protected PollenPersistenceContext persistenceContext; + protected PollenSecurityContext securityContext; + protected Locale locale; public void setPollenServiceConfig(PollenServiceConfig pollenServiceConfig) { @@ -60,6 +64,10 @@ this.persistenceContext = persistenceContext; } + public void setSecurityContext(PollenSecurityContext securityContext) { + this.securityContext = securityContext; + } + public void setLocale(Locale locale) { this.locale = locale; } @@ -80,6 +88,11 @@ return now; } + @Override + public PollenSecurityContext getSecurityContext() { + return securityContext; + } + public String generatePassword() { return RandomStringUtils.randomAlphanumeric(8); } @@ -95,6 +108,11 @@ } @Override + public ChoiceService getChoiceService() { + return newService(ChoiceService.class); + } + + @Override public CommentService getCommentService() { return newService(CommentService.class); } @@ -140,6 +158,11 @@ } @Override + public SecurityService getSecurityService() { + return newService(SecurityService.class); + } + + @Override public String encodePassword(String password) { return StringUtil.encodeMD5(password); } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,10 +1,178 @@ package org.chorem.pollen.services; +/* + * #%L + * Pollen :: Service + * $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.collect.ImmutableSet; +import org.apache.commons.collections.CollectionUtils; +import org.chorem.pollen.persistence.entity.PollenUser; +import org.nuiton.jpa.api.JpaEntity; + +import java.io.Serializable; +import java.util.Collections; +import java.util.Set; + /** * TODO * * @author tchemit <chemit@codelutin.com> * @since 2.0 */ -public class PollenSecurityContext { +public class PollenSecurityContext implements Serializable { + + private static final long serialVersionUID = 5348851531764083245L; + + /** + * Connected user account. + * <p/> + * Can be {@code null} if user is not connected. + * + * @since 2.0 + */ + protected final PollenUser connectedUser; + + /** + * Resource to edit/delete (can be null for some creation contexts). + * + * @since 2.0 + */ + protected ObjectSecurityContext<?> resource; + + /** + * User roles on the poll. + * + * @since 2.0 + */ + protected Set<PollenUserSecurityRole> userRoles; + + public static PollenSecurityContext newContext(PollenUser userAccount) { + PollenSecurityContext result = new PollenSecurityContext( + userAccount); + return result; + } + + public static <E extends JpaEntity> ObjectSecurityContext<E> ObjectSecurityContext(Class<E> type, + String id, + String token) { + return new ObjectSecurityContext<E>(type, id, token); + } + + public void setResource(ObjectSecurityContext<?> resource) { + this.resource = resource; + } + + public void setUserRoles(Set<PollenUserSecurityRole> userRoles) { + this.userRoles = userRoles == null ? null : ImmutableSet.copyOf(userRoles); + } + + public boolean isAdministrator() { + return userRoles != null && userRoles.contains(PollenUserSecurityRole.ADMINISTRATOR); + } + + public boolean isCreator() { + return userRoles != null && userRoles.contains(PollenUserSecurityRole.CREATOR); + } + + public boolean isVoter() { + return userRoles != null && userRoles.contains(PollenUserSecurityRole.VOTER); + } + + public boolean isRestrictedVoter() { + return userRoles != null && userRoles.contains(PollenUserSecurityRole.RESTRICTED_VOTER); + } + + public boolean hasNoRole() { + return CollectionUtils.isEmpty(userRoles); + } + + public Set<PollenUserSecurityRole> getUserRoles() { + return userRoles == null ? + Collections.<PollenUserSecurityRole>emptySet() : + userRoles; + } + + public PollenUser getPollenUser() { + return connectedUser; + } + + protected PollenSecurityContext(PollenUser connectedUser) { + this.connectedUser = connectedUser; + } + + public boolean isConnected() { + return connectedUser != null; + } + + /** + * To define a security role for a given pollen user which can be + * identified by his user account or a accountId. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ + public enum PollenUserSecurityRole { + + /** + * Connected user with administration rights. + * <p/> + * This role can access to everything, but can not vote. + */ + ADMINISTRATOR, + + /** + * Creator of the poll. + * <p/> + * This role can access to everything, but can not vote. + */ + CREATOR, + + /** A user that has voted on a poll. */ + VOTER, + /** + * A user that was invited to a restricted poll. + * <p/> + * It might have alreay voted or not. + */ + RESTRICTED_VOTER + + } + + public static class ObjectSecurityContext<E extends JpaEntity> implements Serializable { + + private static final long serialVersionUID = 8554648867841712974L; + + protected final Class<E> type; + + protected final String id; + + protected final String token; + + public ObjectSecurityContext(Class<E> type, + String id, + String token) { + this.type = type; + this.id = id; + this.token = token; + } + } } Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java ___________________________________________________________________ Modified: svn:keywords - Author Date Id Revision + Author Date Id Revision HeadURL Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityRealm.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityRealm.java (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityRealm.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,82 @@ +package org.chorem.pollen.services; + +/* + * #%L + * Pollen :: Service + * $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.shiro.authc.AuthenticationException; +import org.apache.shiro.authc.AuthenticationInfo; +import org.apache.shiro.authc.AuthenticationToken; +import org.apache.shiro.authc.SimpleAuthenticationInfo; +import org.apache.shiro.authc.UsernamePasswordToken; +import org.apache.shiro.authz.AuthorizationInfo; +import org.apache.shiro.realm.AuthorizingRealm; +import org.apache.shiro.subject.PrincipalCollection; +import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.chorem.pollen.services.exception.UserInvalidPasswordException; +import org.chorem.pollen.services.service.AuthService; + +/** + * TODO + * + * http://www.slideshare.net/chunsaker/securing-rest-apis ? + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollenSecurityRealm extends AuthorizingRealm implements PollenServiceSupport { + + protected PollenServiceContext serviceContext; + + @Override + public void setServiceContext(PollenServiceContext serviceContext) { + this.serviceContext = serviceContext; + } + + @Override + protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { + + principals.getPrimaryPrincipal(); + + return null; + } + + @Override + protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { + + UsernamePasswordToken upToken = (UsernamePasswordToken) token; + String username = upToken.getUsername(); + char[] password = upToken.getPassword(); + + AuthService authService = serviceContext.getAuthService(); + try { + authService.login(username, new String(password)); + } catch (EntityNotFoundException e) { + throw new AuthenticationException(e); + } catch (UserInvalidPasswordException e) { + throw new AuthenticationException(e); + } + SimpleAuthenticationInfo result = + new SimpleAuthenticationInfo(username, password, getName()); + return result; + } +} Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityRealm.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native 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 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -26,11 +26,13 @@ import org.chorem.pollen.persistence.PollenPersistenceContext; import org.chorem.pollen.services.config.PollenServiceConfig; 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.EmailService; 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.SecurityService; import org.chorem.pollen.services.service.UserService; import org.chorem.pollen.services.service.VoteCountingService; import org.chorem.pollen.services.service.VoteService; @@ -49,12 +51,18 @@ Date getNow(); + PollenSecurityContext getSecurityContext(); + + void setSecurityContext(PollenSecurityContext securityContext); + PollenPersistenceContext getPersistenceContext(); PollenServiceConfig getPollenServiceConfig(); AuthService getAuthService(); + ChoiceService getChoiceService(); + CommentService getCommentService(); FavoriteListService getFavoriteListService(); @@ -68,11 +76,12 @@ VoterListService getVoterListService(); VoteService getVoteService(); - EmailService getEmailService(); FixturesService getFixturesService(); + SecurityService getSecurityService(); + String generatePassword(); String encodePassword(String password); Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -27,6 +27,9 @@ import com.google.common.collect.Maps; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.persistence.entity.CommentVisibility; +import org.chorem.pollen.persistence.entity.PollType; +import org.chorem.pollen.persistence.entity.VoteVisibility; import org.chorem.pollen.services.PollenTechnicalException; import org.nuiton.util.config.ApplicationConfig; import org.nuiton.util.config.ArgumentsParserException; @@ -81,4 +84,31 @@ boolean isDevMode = applicationConfig.getOptionAsBoolean(PollenServiceConfigOption.DEV_MODE.key); return isDevMode; } + + public int getDefaultVoteCountingType() { + int result = applicationConfig.getOptionAsInt( + PollenServiceConfigOption.DEFAULT_VOTE_COUNTING_TYPE.key); + return result; + } + + public PollType getDefaultPollType() { + PollType result = applicationConfig.getOption( + PollType.class, + PollenServiceConfigOption.DEFAULT_POLL_TYPE.key); + return result; + } + + public VoteVisibility getDefaultVoteVisibility() { + VoteVisibility result = applicationConfig.getOption( + VoteVisibility.class, + PollenServiceConfigOption.DEFAULT_VOTE_VISIBILITY.key); + return result; + } + + public CommentVisibility getDefaultCommentVisibility() { + CommentVisibility result = applicationConfig.getOption( + CommentVisibility.class, + PollenServiceConfigOption.DEFAULT_COMMENT_VISIBILITY.key); + return result; + } } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -23,9 +23,14 @@ * #L% */ +import org.chorem.pollen.persistence.entity.CommentVisibility; +import org.chorem.pollen.persistence.entity.PollType; +import org.chorem.pollen.persistence.entity.VoteVisibility; import org.nuiton.util.config.ConfigOptionDef; +import static org.nuiton.i18n.I18n.n_; + /** * TODO * @@ -34,23 +39,67 @@ */ public enum PollenServiceConfigOption implements ConfigOptionDef { + /** + * Default poll type to use at a new poll creation. + * + * @since 2.0 + */ + DEFAULT_POLL_TYPE( + "pollen.default.pollType", + n_("pollen.configuration.defaultPollType"), + PollType.FREE.name(), + PollType.class), + + /** + * Default vote counting type to use at a new poll creation. + * + * @since 2.0 + */ + DEFAULT_VOTE_COUNTING_TYPE( + "pollen.default.voteCountingType", + n_("pollen.configuration.defaultVoteCountingType"), + "0", + Integer.class), + + /** + * Default poll vote visibility to use at a new poll creation. + * + * @since 2.0 + */ + DEFAULT_VOTE_VISIBILITY( + "pollen.default.pollVoteVisibility", + n_("pollen.configuration.defaultPollVoteVisibility"), + VoteVisibility.EVERYBODY.name(), + VoteVisibility.class), + + /** + * Default poll comment visibility to use at a new poll creation. + * + * @since 2.0 + */ + DEFAULT_COMMENT_VISIBILITY( + "pollen.default.pollCommentVisibility", + n_("pollen.configuration.defaultPollCommentVisibility"), + CommentVisibility.EVERYBODY.name(), + CommentVisibility.class), + SMTP_HOST( - "smtp.host", + "pollen.smtp.host", "Nom d'hôte du serveur SMTP", "", String.class), SMTP_PORT( - "smtp.port", + "pollen.smtp.port", "Le port du serveur SMTP", "25", Integer.class), SMTP_FROM( - "smtp.from", + "pollen.smtp.from", "L'adresse d'expéditeur pour les mails de notifications", "", String.class), DEV_MODE( - "devMode", + "pollen.devMode", "Mode développement, court-circuite l'envoi de mail", "true", Boolean.class),; Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/AbstractInvalidFormException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/AbstractInvalidFormException.java (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/AbstractInvalidFormException.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,47 @@ +package org.chorem.pollen.services.exception; + +/* + * #%L + * Pollen :: Service + * $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.collect.Multimap; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public abstract class AbstractInvalidFormException extends Exception{ + private static final long serialVersionUID = 1L; + + protected final Multimap<String, String> errors; + + + public AbstractInvalidFormException(Multimap<String, String> errors) { + this.errors = errors; + } + + public Multimap<String, String> getErrors() { + return errors; + } +} Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/AbstractInvalidFormException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListImportException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListImportException.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListImportException.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,5 +1,28 @@ package org.chorem.pollen.services.exception; +/* + * #%L + * Pollen :: Service + * $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% + */ + /** * TODO * Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListImportException.java ___________________________________________________________________ Modified: svn:keywords - Author Date Id Revision + Author Date Id Revision HeadURL Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,5 +1,28 @@ package org.chorem.pollen.services.exception; +/* + * #%L + * Pollen :: Service + * $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% + */ + /** * TODO * Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java ___________________________________________________________________ Modified: svn:keywords - Author Date Id Revision + Author Date Id Revision HeadURL Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,5 +1,28 @@ package org.chorem.pollen.services.exception; +/* + * #%L + * Pollen :: Service + * $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% + */ + /** * TODO * Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java ___________________________________________________________________ Modified: svn:keywords - Author Date Id Revision + Author Date Id Revision HeadURL Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,5 +1,28 @@ package org.chorem.pollen.services.exception; +/* + * #%L + * Pollen :: Service + * $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% + */ + /** * TODO * Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java ___________________________________________________________________ Modified: svn:keywords - Author Date Id Revision + Author Date Id Revision HeadURL Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,5 +1,28 @@ package org.chorem.pollen.services.exception; +/* + * #%L + * Pollen :: Service + * $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% + */ + /** * TODO * Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java ___________________________________________________________________ Modified: svn:keywords - Author Date Id Revision + Author Date Id Revision HeadURL Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,5 +1,28 @@ package org.chorem.pollen.services.exception; +/* + * #%L + * Pollen :: Service + * $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% + */ + /** * TODO * Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java ___________________________________________________________________ Modified: svn:keywords - Author Date Id Revision + Author Date Id Revision HeadURL Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidChoiceFormException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidChoiceFormException.java (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidChoiceFormException.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,43 @@ +package org.chorem.pollen.services.exception; + +/* + * #%L + * Pollen :: Service + * $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.collect.Multimap; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class InvalidChoiceFormException extends AbstractInvalidFormException { + + private static final long serialVersionUID = 1L; + + + public InvalidChoiceFormException(Multimap<String, String> errors) { + super(errors); + } + +} Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidChoiceFormException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidPollFormException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidPollFormException.java (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidPollFormException.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,42 @@ +package org.chorem.pollen.services.exception; + +/* + * #%L + * Pollen :: Service + * $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.collect.Multimap; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class InvalidPollFormException extends AbstractInvalidFormException { + + private static final long serialVersionUID = 1L; + + public InvalidPollFormException(Multimap<String, String> errors) { + super(errors); + } + +} Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidPollFormException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidSessionTokenException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidSessionTokenException.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidSessionTokenException.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,5 +1,28 @@ package org.chorem.pollen.services.exception; +/* + * #%L + * Pollen :: Service + * $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% + */ + /** * TODO * Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidSessionTokenException.java ___________________________________________________________________ Modified: svn:keywords - Author Date Id Revision + Author Date Id Revision HeadURL Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/package-info.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/package-info.java (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/package-info.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,30 @@ +/** + * Package where to find all services exception. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +package org.chorem.pollen.services.exception; + +/* + * #%L + * Pollen :: Service + * $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% + */ Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/package-info.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/package-info.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/package-info.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -1,5 +1,5 @@ /** - * Base Package for the pollen business service. + * Base package of the service layer. * * @author tchemit <chemit@codelutin.com> * @since 2.0 Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -24,6 +24,8 @@ */ import com.google.common.base.Preconditions; +import com.google.common.collect.Multimap; +import org.apache.commons.lang3.StringUtils; import org.chorem.pollen.persistence.PollenPersistenceContext; import org.chorem.pollen.services.PollenServiceContext; import org.chorem.pollen.services.PollenServiceSupport; @@ -31,6 +33,7 @@ import org.chorem.pollen.services.exception.EntityNotFoundException; import org.nuiton.jpa.api.JpaEntities; import org.nuiton.jpa.api.JpaEntity; +import org.nuiton.util.StringUtil; import java.util.Date; @@ -77,6 +80,10 @@ return serviceContext.getAuthService(); } + public ChoiceService getChoiceService() { + return serviceContext.getChoiceService(); + } + protected CommentService getCommentService() { return serviceContext.getCommentService(); } @@ -89,6 +96,10 @@ return serviceContext.getPollService(); } + protected SecurityService getSecurityService() { + return serviceContext.getSecurityService(); + } + protected UserService getUserService() { return serviceContext.getUserService(); } @@ -116,4 +127,27 @@ throw new EntityNotFoundException(type, entityId); } } + + protected boolean check(Multimap<String, String> errors, String field, boolean condition, String error) { + boolean valid = condition; + if (!valid) { + errors.put(field, error); + } + return valid; + } + + protected boolean checkNotNull(Multimap<String, String> errors, String field, Object value, String error) { + boolean valid = check(errors, field, value != null, error); + return valid; + } + + protected boolean checkNotBlank(Multimap<String, String> errors, String field, String value, String error) { + boolean valid = check(errors, field, StringUtils.isNotBlank(value), error); + return valid; + } + + protected boolean checkValidEmail(Multimap<String, String> errors, String field, String value, String error) { + boolean valid = check(errors, field, StringUtil.isEmail(value), error); + return valid; + } } Added: 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 (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,202 @@ +package org.chorem.pollen.services.service; + +/* + * #%L + * Pollen :: Service + * $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 com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; +import org.chorem.pollen.persistence.dao.ChoiceJpaDao; +import org.chorem.pollen.persistence.entity.Choice; +import org.chorem.pollen.persistence.entity.ChoiceType; +import org.chorem.pollen.persistence.entity.Poll; +import org.chorem.pollen.persistence.entity.PollenPrincipal; +import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.chorem.pollen.services.exception.InvalidChoiceFormException; +import org.nuiton.jpa.api.JpaEntities; + +import java.util.List; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class ChoiceService extends AbstractPollenService { + + public List<Choice> getChoices(String pollId) throws EntityNotFoundException { + Preconditions.checkNotNull(pollId); + + Poll poll = getPollService().getPoll(pollId); + + return poll.getChoice(); + } + + public Choice getChoice(String pollId, String choiceId) throws EntityNotFoundException { + Preconditions.checkNotNull(pollId); + Preconditions.checkNotNull(choiceId); + Poll poll = getPollService().getPoll(pollId); + + Choice result = getChoice(poll, choiceId); + return result; + } + + public Choice addChoice(String pollId, Choice choice) throws EntityNotFoundException, InvalidChoiceFormException { + Preconditions.checkNotNull(pollId); + Preconditions.checkNotNull(choice); + checkHasNoId(choice); + + Poll poll = getPollService().getPoll(pollId); + + checkChoiceForm(poll.getChoiceType(), choice); + + Choice result = saveChoice(poll, choice, null); + + getPersistenceContext().getPollDao().merge(poll); + getPersistenceContext().commit(); + return result; + } + + public Choice editChoice(String pollId, Choice choice) throws EntityNotFoundException, InvalidChoiceFormException { + Preconditions.checkNotNull(choice); + checkHasId(choice); + + Poll poll = getPollService().getPoll(pollId); + + checkChoiceForm(poll.getChoiceType(), choice); + + Choice result = saveChoice(poll, choice, null); + + getPersistenceContext().getChoiceDao().merge(choice); + getPersistenceContext().commit(); + return result; + } + + public void deleteChoice(String pollId, String choiceId) throws EntityNotFoundException { + Preconditions.checkNotNull(pollId); + Preconditions.checkNotNull(choiceId); + + Poll poll = getPollService().getPoll(pollId); + Choice choice = getChoice(poll, choiceId); + + poll.removeChoice(choice); + + getPersistenceContext().getPollDao().merge(poll); + getPersistenceContext().commit(); + } + + protected Choice getChoice(Poll poll, String choiceId) throws EntityNotFoundException { + + Choice result = poll.getChoiceById(choiceId); + checkEntityExists(Choice.class, result, choiceId); + return result; + } + + protected Choice saveChoice(Poll poll, + Choice choice, + PollenPrincipal principal) throws EntityNotFoundException { + + ChoiceJpaDao choiceDao = getPersistenceContext().getChoiceDao(); + + boolean choiceExists = JpaEntities.isEntityHasId(choice); + + Choice choiceToPersist; + if (choiceExists) { + + // get existing choice + + choiceToPersist = getChoice(poll, choice.getId()); + } else { + + // create a new choice + choiceToPersist = choiceDao.newInstance(); + + if (principal == null) { + + // create a new principal + + principal = getSecurityService().generatePrincipal(); + + if (choice.getCreator() == null) { + + //TODO Should we use the poll creator ? + + } else { + + principal.setName(choice.getCreator().getName()); + principal.setEmail(choice.getCreator().getEmail()); + } + } + choiceToPersist.setCreator(principal); + poll.addChoice(choiceToPersist); + } + + switch (poll.getChoiceType()) { + + case TEXT: + choiceToPersist.setName(choice.getName()); + choiceToPersist.setDescription(choice.getDescription()); + choiceToPersist.setCreator(poll.getCreator()); + + break; + + case DATE: + throw new IllegalStateException("Not implemented"); + + case IMAGE: + throw new IllegalStateException("Not implemented"); + } + return choiceToPersist; + } + + protected void checkChoiceForm(ChoiceType choiceType, Choice choice) throws InvalidChoiceFormException { + + //TODO use nuiton validator ? + Multimap<String, String> errors = ArrayListMultimap.create(); + + switch (choiceType) { + + case TEXT: + + //TODO Should check unique choice name ? + + checkNotBlank(errors, + "name", + choice.getName(), + "choice name can not be empty"); + + break; + case DATE: + throw new IllegalStateException("Not implemented"); + + case IMAGE: + throw new IllegalStateException("Not implemented"); + } + + if (!errors.isEmpty()) { + + throw new InvalidChoiceFormException(errors); + } + } +} Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native 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 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -24,14 +24,23 @@ */ import com.google.common.base.Preconditions; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; import com.google.common.collect.Sets; +import org.apache.commons.lang3.StringUtils; +import org.chorem.pollen.persistence.dao.PollJpaDao; import org.chorem.pollen.persistence.entity.Choice; +import org.chorem.pollen.persistence.entity.ChoiceType; import org.chorem.pollen.persistence.entity.Poll; +import org.chorem.pollen.persistence.entity.PollenPrincipal; import org.chorem.pollen.persistence.entity.PollenUser; +import org.chorem.pollen.persistence.entity.VoterList; +import org.chorem.pollen.persistence.entity.VoterListMember; import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.chorem.pollen.services.exception.InvalidPollFormException; +import org.nuiton.jpa.api.JpaEntities; import java.io.File; -import java.util.List; import java.util.Set; /** @@ -42,6 +51,10 @@ */ public class PollService extends AbstractPollenService { + public Set<Poll> getPolls(String userId) throws EntityNotFoundException { + return Sets.newHashSet(getPersistenceContext().getPollDao().findAll()); + } + public Set<Poll> getCreatedPolls(String userId) throws EntityNotFoundException { Preconditions.checkNotNull(userId); @@ -73,39 +86,63 @@ return result; } - public Poll createPoll(String userId, Poll poll) throws EntityNotFoundException { - Preconditions.checkNotNull(userId); - Preconditions.checkNotNull(poll); - checkHasNoId(poll); + public Poll getNewPoll(String userId, ChoiceType choiceType) throws EntityNotFoundException { + Poll result = getPersistenceContext().getPollDao().newInstance(); + + result.setChoiceType(choiceType); + + // -- default values -- // + + result.setVoteCountingType(getPollenServiceConfig().getDefaultVoteCountingType()); + result.setPollType(getPollenServiceConfig().getDefaultPollType()); + result.setVoteVisibility(getPollenServiceConfig().getDefaultVoteVisibility()); + result.setCommentVisibility(getPollenServiceConfig().getDefaultCommentVisibility()); + result.setBeginDate(serviceContext.getNow()); + + // -- creator -- // + + PollenPrincipal creator = getPersistenceContext().getPollenPrincipalDao().newInstance(); + result.setCreator(creator); + if (userId != null) { - - // get user PollenUser user = getUserService().getUser(userId); - // link it to creator - + creator.setName(user.getName()); + creator.setEmail(user.getEmail()); } + return result; + } - getPersistenceContext().getPollDao().persist(poll); + public Poll createPoll(String userId, Poll poll) throws EntityNotFoundException, InvalidPollFormException { + Preconditions.checkNotNull(poll); + checkHasNoId(poll); + + checkPollForm(poll); + + Poll pollToPersist = savePoll(userId, poll); + + getPersistenceContext().getPollDao().persist(pollToPersist); getPersistenceContext().commit(); - return poll; + return pollToPersist; } - public Poll editPoll(Poll poll) throws EntityNotFoundException { + public Poll editPoll(Poll poll) throws EntityNotFoundException, InvalidPollFormException { Preconditions.checkNotNull(poll); checkHasId(poll); - getPoll(poll.getId()); + checkPollForm(poll); - getPersistenceContext().getPollDao().merge(poll); + Poll toSave = savePoll(null, poll); + + getPersistenceContext().getPollDao().merge(toSave); getPersistenceContext().commit(); - Poll result = getPoll(poll.getId()); - return result; + return toSave; } + public void deletePoll(String pollId) throws EntityNotFoundException { Preconditions.checkNotNull(pollId); @@ -113,6 +150,11 @@ getPersistenceContext().getPollDao().remove(poll); getPersistenceContext().commit(); + + if (poll.getCreator().getEmail() != null) { + + //TODO Notify ? + } } public Poll clonePoll(String pollId) throws EntityNotFoundException { @@ -140,66 +182,183 @@ return null; } - public List<Choice> getChoices(String pollId) throws EntityNotFoundException { - Preconditions.checkNotNull(pollId); + protected Poll savePoll(String userId, Poll poll) throws EntityNotFoundException { - Poll poll = getPoll(pollId); + boolean pollExists = JpaEntities.isEntityHasId(poll); - return poll.getChoice(); - } + Poll toSave; - public Choice getChoice(String choiceId) throws EntityNotFoundException { - Preconditions.checkNotNull(choiceId); + if (pollExists) { + toSave = getPoll(poll.getId()); - Choice result = getPersistenceContext().getChoiceDao().findById(choiceId); - checkEntityExists(Choice.class, result, choiceId); - return result; - } + } else { + PollJpaDao dao = getPersistenceContext().getPollDao(); - public Choice addChoice(String pollId, Choice choice) throws EntityNotFoundException { - Preconditions.checkNotNull(pollId); - Preconditions.checkNotNull(choice); - checkHasNoId(choice); + toSave = dao.newInstance(); - Poll poll = getPoll(pollId); + PollenPrincipal creatorToPersist = + getSecurityService().generatePrincipal(); - poll.addChoice(choice); + toSave.setCreator(creatorToPersist); + } - getPersistenceContext().getPollDao().merge(poll); + // -- creator -- // - getPersistenceContext().commit(); - Choice result = getChoice(choice.getId()); - return result; - } + if (userId != null) { - public Choice editChoice(Choice choice) throws EntityNotFoundException { - Preconditions.checkNotNull(choice); - checkHasId(choice); + // link to connected user + PollenUser user = getUserService().getUser(userId); + toSave.getCreator().setPollenUser(user); + } - getChoice(choice.getId()); + toSave.getCreator().setName(poll.getCreator().getName()); + toSave.getCreator().setEmail(poll.getCreator().getEmail()); - getPersistenceContext().getChoiceDao().merge(choice); - getPersistenceContext().commit(); + // -- simple properties -- // - Choice result = getChoice(choice.getId()); - return result; - } + toSave.setVoteCountingType(poll.getVoteCountingType()); + toSave.setVoteVisibility(poll.getVoteVisibility()); + toSave.setCommentVisibility(poll.getCommentVisibility()); + toSave.setChoiceType(poll.getChoiceType()); - public void deleteChoice(String pollId, String choiceId) throws EntityNotFoundException { - Preconditions.checkNotNull(pollId); - Preconditions.checkNotNull(choiceId); + toSave.setAnonymousVoteAllowed(poll.isAnonymousVoteAllowed()); + toSave.setChoiceAddAllowed(poll.isChoiceAddAllowed()); + toSave.setBeginChoiceDate(poll.getBeginChoiceDate()); + toSave.setBeginDate(poll.getBeginDate()); - Poll poll = getPoll(pollId); - Choice choice = getChoice(choiceId); + toSave.setContinuousResults(poll.isContinuousResults()); + toSave.setDescription(poll.getDescription()); + toSave.setEndDate(poll.getEndDate()); + toSave.setEndChoiceDate(poll.getEndChoiceDate()); + toSave.setPollType(poll.getPollType()); + toSave.setMaxChoiceNumber(poll.getMaxChoiceNumber()); + toSave.setTitle(poll.getTitle()); - poll.removeChoice(choice); + // -- choice -- // - getPersistenceContext().getPollDao().merge(poll); + for (Choice choice : poll.getChoice()) { - getPersistenceContext().commit(); + getChoiceService().saveChoice(toSave, choice, toSave.getCreator()); + } + + // -- voting list -- // + + if (!poll.isVoterListEmpty()) { + + for (VoterList voterList : poll.getVoterList()) { + + getVoterListService().saveVoterList(toSave, voterList); + } + } + + return toSave; } - public Set<Poll> getPolls(String userId) throws EntityNotFoundException { - return Sets.newHashSet(getPersistenceContext().getPollDao().findAll()); + protected void checkPollForm(Poll poll) throws InvalidPollFormException { + + //TODO use nuiton validator ? + Multimap<String, String> errors = ArrayListMultimap.create(); + + checkNotNull(errors, "pollType", poll.getPollType(), "pollType can not be null"); + checkNotNull(errors, "choiceType", poll.getChoiceType(), "choiceType can not be null"); + checkNotNull(errors, "commentVisibility", poll.getCommentVisibility(), "commentVisibility can not be null"); + checkNotNull(errors, "voteVisibility", poll.getVoteVisibility(), "voteVisibility can not be null"); + checkNotNull(errors, "voteCountingType", poll.getVoteCountingType(), "voteCountingType can not be null"); + + checkNotBlank(errors, "title", poll.getTitle(), "title can not be empty"); + check(errors, "choice", poll.isChoiceEmpty(), "need at least one choice"); + + if (poll.isFreePoll()) { + check(errors, "pollType", poll.isVoterListEmpty(), "can't have voterList with free poll"); + } else { + check(errors, "pollType", !poll.isVoterListEmpty(), "must have voterList with not free poll"); + } + + if (!poll.isChoiceEmpty()) { + + // validate choices + + int choiceIndex = 0; + + for (Choice choice : poll.getChoice()) { + + String choiceField = "choice[" + (choiceIndex++) + "]"; + + switch (poll.getChoiceType()) { + + case TEXT: + + checkNotBlank(errors, + choiceField + ".name", + choice.getName(), + "choice name can not be empty"); + + break; + case DATE: + throw new IllegalStateException("Not implemented"); + + case IMAGE: + throw new IllegalStateException("Not implemented"); + } + } + } + + if (!poll.isVoterListEmpty()) { + + Set<String> voterListNames = Sets.newHashSet(); + + // validate voter lists + + int voterListIndex = 0; + + for (VoterList voterList : poll.getVoterList()) { + + String voterListField = "voterList[" + (voterListIndex++) + "]"; + + checkNotBlank(errors, voterListField + ".name", voterList.getName(), "voterList name can not be empty"); + check(errors, voterListField + ".weight", voterList.getWeight() > 0, "voterList weight must be greater than 0"); + check(errors, voterListField + ".member", !voterList.isVoterListMemberEmpty(), "voterList must contains at least one member"); + + boolean added = voterListNames.add(voterList.getName()); + + check(errors, voterListField, added, "voterList name already used"); + + Set<String> voterListMemberNames = Sets.newHashSet(); + Set<String> voterListMemberEmails = Sets.newHashSet(); + + int voterListMemberIndex = 0; + + for (VoterListMember voterListMember : voterList.getVoterListMember()) { + + String voterListMemberField = voterListField + ".member[" + (voterListMemberIndex++) + "]"; + + String voterListMemberName = voterListMember.getName(); + boolean nameNotNull = checkNotBlank(errors, voterListMemberField + ".name", voterListMemberName, "member name can not be empty"); + + if (nameNotNull) { + boolean nameAdded = voterListMemberNames.add(voterListMemberName); + check(errors, voterListMemberField + ".name", nameAdded, "member name already used in this list"); + } + + String voterListMemberEmail = voterListMember.getEmail(); + + boolean emailNotNull = checkNotBlank(errors, voterListMemberField + ".email", voterListMemberEmail, "member email can not be empty"); + + if (emailNotNull) { + + voterListMemberEmail = StringUtils.lowerCase(voterListMemberEmail); + + checkValidEmail(errors, voterListMemberField + ".email", voterListMemberEmail, "member email is not valid"); + boolean emailAdded = voterListMemberEmails.add(voterListMemberEmail); + check(errors, voterListMemberField + ".email", emailAdded, "member email already used in this list"); + } + } + } + } + + if (!errors.isEmpty()) { + + throw new InvalidPollFormException(errors); + } } } Added: 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 (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,45 @@ +package org.chorem.pollen.services.service; + +/* + * #%L + * Pollen :: Service + * $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.dao.PollenPrincipalJpaDao; +import org.chorem.pollen.persistence.entity.PollenPrincipal; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class SecurityService extends AbstractPollenService { + + public PollenPrincipal generatePrincipal() { + PollenPrincipalJpaDao pollenPrincipalDao = getPersistenceContext().getPollenPrincipalDao(); + PollenPrincipal principal = pollenPrincipalDao.newInstance(); + principal.setToken(serviceContext.generateToken()); + principal.setCreationDate(serviceContext.getNow()); + return principal; + + } +} Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native 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 2013-06-14 15:12:49 UTC (rev 3829) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -24,6 +24,7 @@ */ import com.google.common.base.Preconditions; +import org.apache.commons.lang3.StringUtils; import org.chorem.pollen.persistence.dao.VoterListJpaDao; import org.chorem.pollen.persistence.dao.VoterListMemberJpaDao; import org.chorem.pollen.persistence.entity.FavoriteList; @@ -32,6 +33,7 @@ import org.chorem.pollen.persistence.entity.VoterList; import org.chorem.pollen.persistence.entity.VoterListMember; import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.nuiton.jpa.api.JpaEntities; import java.util.List; import java.util.Set; @@ -78,7 +80,7 @@ return result; } - public List<VoterList> getVoterLists(String pollId) throws EntityNotFoundException{ + public List<VoterList> getVoterLists(String pollId) throws EntityNotFoundException { Preconditions.checkNotNull(pollId); Poll poll = getPollService().getPoll(pollId); @@ -87,7 +89,7 @@ return result; } - public VoterList getVoterList(String voterListId) throws EntityNotFoundException{ + public VoterList getVoterList(String pollId, String voterListId) throws EntityNotFoundException { Preconditions.checkNotNull(voterListId); VoterList result = getPersistenceContext().getVoterListDao().findById(voterListId); @@ -96,40 +98,39 @@ return result; } - public VoterList addVoterList(String pollId, VoterList voterList) throws EntityNotFoundException{ + public VoterList addVoterList(String pollId, VoterList voterList) throws EntityNotFoundException { Preconditions.checkNotNull(pollId); Preconditions.checkNotNull(voterList); checkHasNoId(voterList); Poll poll = getPollService().getPoll(pollId); + VoterList result = saveVoterList(poll, voterList); - poll.addVoterList(voterList); - getPersistenceContext().getPollDao().merge(poll); getPersistenceContext().commit(); - VoterList result = getVoterList(voterList.getId()); return result; } - public VoterList editVoterList(VoterList voterList) throws EntityNotFoundException{ + public VoterList editVoterList(String pollId, VoterList voterList) throws EntityNotFoundException { + Preconditions.checkNotNull(pollId); Preconditions.checkNotNull(voterList); checkHasId(voterList); - getVoterList(voterList.getId()); + Poll poll = getPollService().getPoll(pollId); + VoterList result = saveVoterList(poll, voterList); getPersistenceContext().getVoterListDao().merge(voterList); getPersistenceContext().commit(); - VoterList result = getVoterList(voterList.getId()); return result; } - public void deleteVoterList(String pollId, String voterListId) throws EntityNotFoundException{ + public void deleteVoterList(String pollId, String voterListId) throws EntityNotFoundException { Preconditions.checkNotNull(pollId); Preconditions.checkNotNull(voterListId); Poll poll = getPollService().getPoll(pollId); - VoterList voterList = getVoterList(voterListId); + VoterList voterList = getVoterList(pollId, voterListId); poll.removeVoterList(voterList); @@ -138,58 +139,69 @@ getPersistenceContext().commit(); } - public Set<VoterListMember> getMembers(String voterListId) throws EntityNotFoundException{ + public Set<VoterListMember> getMembers(String pollId, String voterListId) throws EntityNotFoundException { Preconditions.checkNotNull(voterListId); - VoterList voterList = getVoterList(voterListId); + VoterList voterList = getVoterList(pollId, voterListId); Set<VoterListMember> result = voterList.getVoterListMember(); return result; } - public VoterListMember getMember(String memberId) throws EntityNotFoundException{ + public VoterListMember getMember(String pollId, String voterListId, String memberId) throws EntityNotFoundException { Preconditions.checkNotNull(memberId); - VoterListMember result = getPersistenceContext().getVoterListMemberDao().findById(memberId); + VoterList voterList = getVoterList(pollId, voterListId); + + VoterListMember result = getMember(voterList, memberId); checkEntityExists(VoterListMember.class, result, memberId); return result; } - public VoterListMember addMember(String voterListId, VoterListMember member)throws EntityNotFoundException { + + public VoterListMember getMember(VoterList voterList, String memberId) throws EntityNotFoundException { + Preconditions.checkNotNull(memberId); + + VoterListMember result = voterList.getVoterListMemberById(memberId); + checkEntityExists(VoterListMember.class, result, memberId); + return result; + } + + public VoterListMember addMember(String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException { Preconditions.checkNotNull(voterListId); Preconditions.checkNotNull(member); checkHasNoId(member); - VoterList voterList = getVoterList(voterListId); + VoterList voterList = getVoterList(pollId, voterListId); - voterList.addVoterListMember(member); + VoterListMember result = saveVoterListMember(voterList, member); + getPersistenceContext().getVoterListDao().merge(voterList); - getPersistenceContext().commit(); - VoterListMember result = getMember(member.getId()); return result; } - public VoterListMember editMember(VoterListMember member) throws EntityNotFoundException{ + public VoterListMember editMember(String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException { + Preconditions.checkNotNull(voterListId); Preconditions.checkNotNull(member); checkHasId(member); - getMember(member.getId()); + VoterList voterList = getVoterList(pollId, voterListId); + VoterListMember result = saveVoterListMember(voterList, member); + getPersistenceContext().getVoterListMemberDao().merge(member); - getPersistenceContext().commit(); - VoterListMember result = getMember(member.getId()); return result; } - public void deleteMember(String voterListId, String memberId) throws EntityNotFoundException{ + public void deleteMember(String pollId, String voterListId, String memberId) throws EntityNotFoundException { Preconditions.checkNotNull(voterListId); Preconditions.checkNotNull(memberId); - VoterList voterList = getVoterList(voterListId); + VoterList voterList = getVoterList(pollId, voterListId); - VoterListMember member = getMember(memberId); + VoterListMember member = getMember(voterList, memberId); voterList.removeVoterListMember(member); getPersistenceContext().getVoterListDao().merge(voterList); @@ -197,4 +209,62 @@ getPersistenceContext().commit(); } + protected VoterList saveVoterList(Poll poll, VoterList voterList) throws EntityNotFoundException { + + + boolean voterListExists = JpaEntities.isEntityHasId(voterList); + + VoterList voterListToPersist; + + if (voterListExists) { + + voterListToPersist = + getVoterListService().getVoterList(poll.getId(), voterList.getId()); + } else { + VoterListJpaDao voterListDao = + getPersistenceContext().getVoterListDao(); + voterListToPersist = voterListDao.newInstance(); + + poll.addVoterList(voterListToPersist); + } + + voterListToPersist.setName(voterList.getName()); + voterListToPersist.setWeight(voterList.getWeight()); + + for (VoterListMember voterListMember : voterList.getVoterListMember()) { + + saveVoterListMember(voterListToPersist, voterListMember); + } + + return voterListToPersist; + } + + protected VoterListMember saveVoterListMember(VoterList voterList, + VoterListMember voterListMember) throws EntityNotFoundException { + + boolean voterListMemberExists = + JpaEntities.isEntityHasId(voterListMember); + + VoterListMember voterListMemberToPersist; + + if (voterListMemberExists) { + + voterListMemberToPersist = + getMember(voterList, voterListMember.getId()); + } else { + + VoterListMemberJpaDao voterListMemberDao = + getPersistenceContext().getVoterListMemberDao(); + + voterListMemberToPersist = voterListMemberDao.newInstance(); + + voterList.addVoterListMember(voterListMemberToPersist); + } + + voterListMemberToPersist.setName(voterListMember.getName()); + voterListMemberToPersist.setEmail(StringUtils.lowerCase(voterListMember.getEmail())); + voterListMemberToPersist.setWeight(voterListMember.getWeight()); + + return voterListMemberToPersist; + } } Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/package-info.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/package-info.java (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/package-info.java 2013-06-15 10:58:03 UTC (rev 3830) @@ -0,0 +1,30 @@ +/** + * Package where to find all services. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +package org.chorem.pollen.services.service; + +/* + * #%L + * Pollen :: Service + * $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% + */ Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Property changes on: trunk/pollen-ui-js/src/main/webapp/img/glyphicons_050_link.png ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Property changes on: trunk/pollen-ui-js/src/main/webapp/js/libs/date.js ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Property changes on: trunk/pollen-ui-js/src/main/webapp/js/libs/jquery.scrollto.js ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native
participants (1)
-
tchemit@users.chorem.org