r3823 - in branches/pollen-2.0: . pollen-persistence/src/main/java/org/chorem/pollen/persistence pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity pollen-persistence/src/main/xmi pollen-persistence/src/test/java/org/chorem/pollen/persistence/entity pollen-persistence-legacy pollen-rest-api pollen-rest-api/src pollen-rest-api/src/it pollen-rest-api/src/it/pom pollen-rest-api/src/it/user pollen-rest-api/src
Author: tchemit Date: 2013-06-14 11:12:59 +0200 (Fri, 14 Jun 2013) New Revision: 3823 Url: http://chorem.org/projects/pollen/repository/revisions/3823 Log: - prepare new module layout - implements FavoriteList service - begin of security implementation Added: branches/pollen-2.0/pollen-rest-api/src/it/ branches/pollen-2.0/pollen-rest-api/src/it/pom/ branches/pollen-2.0/pollen-rest-api/src/it/pom/pom.xml branches/pollen-2.0/pollen-rest-api/src/it/user/ branches/pollen-2.0/pollen-rest-api/src/it/user/README.txt branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenSecurityFilter.java branches/pollen-2.0/pollen-services-legacy/ branches/pollen-2.0/pollen-services/ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollResult.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenFixtures.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenTechnicalException.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/config/ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListImportException.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidSessionTokenException.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/package-info.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/AuthService.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/EmailService.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/UserService.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingService.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java branches/pollen-2.0/pollen-services/src/main/resources/fixtures.yaml branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/UserServiceTest.java Removed: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/BookmarkableDao.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoteDao.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoterListDao.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoterListMemberDao.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/AbstractJpaPollenEntity.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/BookmarkableEntity.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Choice.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/ChoiceEntity.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Comment.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/CommentEntity.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/JpaPollenEntity.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollEntity.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenEntities.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Vote.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/VoteEntity.java branches/pollen-2.0/pollen-persistence/src/test/java/org/chorem/pollen/persistence/entity/PollenEntitiesTest.java branches/pollen-2.0/pollen-service/ branches/pollen-2.0/pollen-services/ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/AbstractPollenService.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/AuthService.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/CommentService.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/DefaultPollenServiceContext.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/EmailService.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/FavoriteListService.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/FixturesService.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollResult.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollService.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenFixtures.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenServiceContext.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenServiceSupport.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenTechnicalException.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/UserService.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/VoteCountingService.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/VoteService.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/VoterListService.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/config/ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/exception/ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/package-info.java branches/pollen-2.0/pollen-services/src/main/resources/fixtures.yaml branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/UserServiceTest.java Modified: branches/pollen-2.0/pollen-persistence-legacy/pom.xml branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/ChoiceDao.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/ChoiceJpaDao.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/CommentDao.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/CommentJpaDao.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollDao.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollJpaDao.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollenUserJpaDao.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/SessionTokenJpaDao.java branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoteJpaDao.java branches/pollen-2.0/pollen-persistence/src/main/xmi/pollen.properties branches/pollen-2.0/pollen-rest-api/pom.xml branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenApplicationContext.java branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenRender.java branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceContextFilter.java branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceListener.java branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServices.java branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/AuthService.java branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/CommentService.java branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/FavoriteListService.java branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollService.java branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/UserService.java branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteCountingService.java branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteService.java branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoterListService.java branches/pollen-2.0/pollen-rest-api/src/main/resources/mapping branches/pollen-2.0/pollen-rest-api/src/main/webapp/WEB-INF/web.xml branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/FakePollenServiceContext.java branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/UserServiceTest.java branches/pollen-2.0/pollen-rest-api/src/test/resources/pollen.properties branches/pollen-2.0/pollen-services/pom.xml branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/config/package-info.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/EntityNotFoundException.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserEmailAlreadyUsedException.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserInvalidEmailActiviationTokenException.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserInvalidPasswordException.java branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserLoginAlreadyUsedException.java branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/FakePollenServiceContext.java branches/pollen-2.0/pom.xml Modified: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,10 +1,14 @@ package org.chorem.pollen.persistence; import com.google.common.base.Preconditions; -import org.chorem.pollen.persistence.entity.PollenEntities; +import org.apache.commons.codec.DecoderException; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.codec.binary.Hex; import org.nuiton.jpa.api.JpaEntity; import org.nuiton.jpa.api.JpaEntityIdFactory; +import java.util.UUID; + /** * TODO * @@ -13,10 +17,29 @@ */ public class PollenEntityIdFactory implements JpaEntityIdFactory { + public static String generateId() { + + // generate uuid + String uuid = UUID.randomUUID().toString().replaceAll("-", ""); + + // decode in hexa base + byte[] decode; + try { + decode = Hex.decodeHex(uuid.toCharArray()); + } catch (DecoderException e) { + // can't happen! + throw new RuntimeException(e); + } + + // encode it in base64 (url safe version) + String result = Base64.encodeBase64URLSafeString(decode); + return result; + } + @Override public String newId(JpaEntity entity) { Preconditions.checkNotNull(entity); - return entity.getClass().getName() + '#' + PollenEntities.generateId(); + return generateId(); } } Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/BookmarkableDao.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/BookmarkableDao.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/BookmarkableDao.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,37 +0,0 @@ -package org.chorem.pollen.persistence.dao; - -/* - * #%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 org.nuiton.jpa.api.JpaEntity; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public interface BookmarkableDao<E extends JpaEntity> { - - E findBySimpleId(String simpleId); -} Modified: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/ChoiceDao.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/ChoiceDao.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/ChoiceDao.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -23,13 +23,11 @@ * #L% */ -import org.chorem.pollen.persistence.entity.Choice; - /** * TODO * * @author tchemit <chemit@codelutin.com> * @since 2.0 */ -public interface ChoiceDao extends BookmarkableDao<Choice> { +public interface ChoiceDao { } Modified: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/ChoiceJpaDao.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/ChoiceJpaDao.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/ChoiceJpaDao.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -23,9 +23,6 @@ * #L% */ -import org.chorem.pollen.persistence.entity.Choice; -import org.chorem.pollen.persistence.entity.PollenEntities; - import javax.persistence.EntityManager; public class ChoiceJpaDao extends AbstractChoiceJpaDao { @@ -34,10 +31,4 @@ super(entityManager); } - @Override - public Choice findBySimpleId(String simpleId) { - String id = PollenEntities.getEntityId(getEntityClass(), simpleId); - return findById(id); - } - } //ChoiceJpaDao Modified: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/CommentDao.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/CommentDao.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/CommentDao.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -23,13 +23,11 @@ * #L% */ -import org.chorem.pollen.persistence.entity.Comment; - /** * TODO * * @author tchemit <chemit@codelutin.com> * @since 2.0 */ -public interface CommentDao extends BookmarkableDao<Comment> { +public interface CommentDao { } Modified: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/CommentJpaDao.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/CommentJpaDao.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/CommentJpaDao.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -23,9 +23,6 @@ * #L% */ -import org.chorem.pollen.persistence.entity.Comment; -import org.chorem.pollen.persistence.entity.PollenEntities; - import javax.persistence.EntityManager; public class CommentJpaDao extends AbstractCommentJpaDao { @@ -34,10 +31,4 @@ super(entityManager); } - @Override - public Comment findBySimpleId(String simpleId) { - String id = PollenEntities.getEntityId(getEntityClass(), simpleId); - return findById(id); - } - } //CommentJpaDao Modified: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollDao.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollDao.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollDao.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -33,7 +33,7 @@ * @author tchemit <chemit@codelutin.com> * @since 2.0 */ -public interface PollDao extends BookmarkableDao<Poll> { +public interface PollDao { Set<Poll> findAllCreated(String userId); Modified: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollJpaDao.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollJpaDao.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollJpaDao.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -25,7 +25,6 @@ import com.google.common.collect.Sets; import org.chorem.pollen.persistence.entity.Poll; -import org.chorem.pollen.persistence.entity.PollenEntities; import javax.persistence.EntityManager; import java.util.Set; @@ -60,10 +59,5 @@ return Sets.newHashSet(); } - @Override - public Poll findBySimpleId(String simpleId) { - String id = PollenEntities.getEntityId(getEntityClass(), simpleId); - return findById(id); - } } //PollJpaDao Modified: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollenUserJpaDao.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollenUserJpaDao.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollenUserJpaDao.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -26,7 +26,6 @@ import org.chorem.pollen.persistence.entity.PollenUser; import javax.persistence.EntityManager; -import javax.persistence.TypedQuery; /** * TODO @@ -41,23 +40,6 @@ } @Override - public PollenUser findByLogin(String login) { - TypedQuery<PollenUser> query = - createQuery(PollenUser.PROPERTY_LOGIN, login); - PollenUser result = findUniqueOrNull(query); - - return result; - } - - @Override - public PollenUser findByEmail(String email) { - TypedQuery<PollenUser> query = - createQuery(PollenUser.PROPERTY_EMAIL, email); - PollenUser result = findUniqueOrNull(query); - return result; - } - - @Override public boolean loginExists(String login) { PollenUser user = findByLogin(login); return user != null; Modified: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/SessionTokenJpaDao.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/SessionTokenJpaDao.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/SessionTokenJpaDao.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -23,10 +23,7 @@ * #L% */ -import org.chorem.pollen.persistence.entity.SessionToken; - import javax.persistence.EntityManager; -import javax.persistence.TypedQuery; /** * TODO @@ -40,11 +37,4 @@ super(entityManager); } - @Override - public SessionToken findByToken(String token) { - TypedQuery<SessionToken> query = createQuery(SessionToken.PROPERTY_TOKEN, token); - SessionToken result = findUniqueOrNull(query); - return result; - } - } //SessionTokenJpaDao Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoteDao.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoteDao.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoteDao.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,35 +0,0 @@ -package org.chorem.pollen.persistence.dao; - -/* - * #%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 org.chorem.pollen.persistence.entity.Vote; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public interface VoteDao extends BookmarkableDao<Vote> { -} Modified: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoteJpaDao.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoteJpaDao.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoteJpaDao.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -23,9 +23,6 @@ * #L% */ -import org.chorem.pollen.persistence.entity.PollenEntities; -import org.chorem.pollen.persistence.entity.Vote; - import javax.persistence.EntityManager; public class VoteJpaDao extends AbstractVoteJpaDao { @@ -34,10 +31,4 @@ super(entityManager); } - @Override - public Vote findBySimpleId(String simpleId) { - String id = PollenEntities.getEntityId(getEntityClass(), simpleId); - return findById(id); - } - } //VoteJpaDao Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoterListDao.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoterListDao.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoterListDao.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,33 +0,0 @@ -package org.chorem.pollen.persistence.dao; - -/* - * #%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% - */ - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public interface VoterListDao { -} Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoterListMemberDao.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoterListMemberDao.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoterListMemberDao.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,34 +0,0 @@ -package org.chorem.pollen.persistence.dao; - -/* - * #%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% - */ - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public interface VoterListMemberDao { - -} Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/AbstractJpaPollenEntity.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/AbstractJpaPollenEntity.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/AbstractJpaPollenEntity.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,44 +0,0 @@ -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 org.nuiton.jpa.api.AbstractJpaEntity; - -import java.io.Serializable; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public abstract class AbstractJpaPollenEntity extends AbstractJpaEntity implements JpaPollenEntity { - - private static final long serialVersionUID = 1L; - - @Override - public String getSimpleId() { - return PollenEntities.getSimpleId(this); - } -} Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/BookmarkableEntity.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/BookmarkableEntity.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/BookmarkableEntity.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,41 +0,0 @@ -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% - */ - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public interface BookmarkableEntity { - - String getId(); - - String getSimpleId(); - -// PollenUser getPollenUser(); - -// void setPollenUser(PollenUser pollenUser); -} Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Choice.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Choice.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Choice.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,43 +0,0 @@ -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 Choice extends AbstractJpaChoice { - - private static final long serialVersionUID = 1L; - - @Override - public String getSimpleId() { - return PollenEntities.getSimpleId(this); - } -} //Choice Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/ChoiceEntity.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/ChoiceEntity.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/ChoiceEntity.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,33 +0,0 @@ -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% - */ - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public interface ChoiceEntity extends BookmarkableEntity { -} Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Comment.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Comment.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Comment.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,43 +0,0 @@ -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 Comment extends AbstractJpaComment { - - private static final long serialVersionUID = 1L; - - @Override - public String getSimpleId() { - return PollenEntities.getSimpleId(this); - } -} //Comment Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/CommentEntity.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/CommentEntity.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/CommentEntity.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,33 +0,0 @@ -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% - */ - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public interface CommentEntity extends BookmarkableEntity { -} Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/JpaPollenEntity.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/JpaPollenEntity.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/JpaPollenEntity.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,38 +0,0 @@ -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 org.nuiton.jpa.api.JpaEntity; - -import java.io.Serializable; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public interface JpaPollenEntity extends JpaEntity, Serializable { - String getSimpleId(); -} Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,43 +0,0 @@ -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; - - @Override - public String getSimpleId() { - return PollenEntities.getSimpleId(this); - } -} //Poll Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollEntity.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollEntity.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollEntity.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,33 +0,0 @@ -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% - */ - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public interface PollEntity extends BookmarkableEntity { -} Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenEntities.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenEntities.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenEntities.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,80 +0,0 @@ -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 org.apache.commons.codec.DecoderException; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.codec.binary.Hex; -import org.apache.commons.lang3.StringUtils; -import org.nuiton.jpa.api.JpaEntity; - -import java.util.UUID; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class PollenEntities { - - public static boolean isSimpleId(String id) { - return !id.contains("#"); - } - - public static String getSimpleId(JpaEntity e) { - String result = e.getId(); - if (result != null) { - result = StringUtils.substringAfter(result, "#"); - } - return result; - } - - public static <E extends JpaEntity> String getEntityId(Class<E> type, - String simpleId) { - StringBuilder result = new StringBuilder(type.getName()); - result.append('#'); - result.append(simpleId); - return result.toString(); - } - - public static String generateId() { - // get uuid - String uuid = UUID.randomUUID().toString().replaceAll("-", ""); - - // decode in hexa decimal (reduce by 2 size of it) - byte[] decode; - try { - decode = Hex.decodeHex(uuid.toCharArray()); - } catch (DecoderException e) { - // can't happen! - throw new RuntimeException(e); - } - - // encode it in base64 (url safe version) - String result = Base64.encodeBase64URLSafeString(decode); - return result; - } - -} Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Vote.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Vote.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Vote.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,43 +0,0 @@ -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 Vote extends AbstractJpaVote { - - private static final long serialVersionUID = 1L; - - @Override - public String getSimpleId() { - return PollenEntities.getSimpleId(this); - } -} //Vote Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/VoteEntity.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/VoteEntity.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/VoteEntity.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,33 +0,0 @@ -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% - */ - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public interface VoteEntity extends BookmarkableEntity { -} Modified: branches/pollen-2.0/pollen-persistence/src/main/xmi/pollen.properties =================================================================== --- branches/pollen-2.0/pollen-persistence/src/main/xmi/pollen.properties 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/main/xmi/pollen.properties 2013-06-14 09:12:59 UTC (rev 3823) @@ -22,8 +22,9 @@ ###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 +#model.tagvalue.entitySuperClass=org.chorem.pollen.persistence.entity.AbstractJpaPollenEntity org.chorem.pollen.persistence.entity.Poll.attribute.choice.stereotype=ordered org.chorem.pollen.persistence.entity.Poll.attribute.voterList.stereotype=ordered Deleted: branches/pollen-2.0/pollen-persistence/src/test/java/org/chorem/pollen/persistence/entity/PollenEntitiesTest.java =================================================================== --- branches/pollen-2.0/pollen-persistence/src/test/java/org/chorem/pollen/persistence/entity/PollenEntitiesTest.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence/src/test/java/org/chorem/pollen/persistence/entity/PollenEntitiesTest.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,57 +0,0 @@ -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 org.chorem.pollen.persistence.PollenEntityIdFactory; -import org.junit.Assert; -import org.junit.Test; -import org.nuiton.jpa.api.JpaEntityIdFactoryResolver; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class PollenEntitiesTest { - - @Test - public void getSimpleId() { - - JpaEntityIdFactoryResolver.setFactory(new PollenEntityIdFactory()); - - try { - Poll poll = new Poll(); - poll.prepersist(); - - String id = poll.getId(); - Assert.assertNotNull(id); - - String simpleId = PollenEntities.getSimpleId(poll); - String id2 = PollenEntities.getEntityId(Poll.class, simpleId); - - Assert.assertEquals(id, id2); - } finally { - JpaEntityIdFactoryResolver.setFactory(null); - } - } -} Modified: branches/pollen-2.0/pollen-persistence-legacy/pom.xml =================================================================== --- branches/pollen-2.0/pollen-persistence-legacy/pom.xml 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-persistence-legacy/pom.xml 2013-06-14 09:12:59 UTC (rev 3823) @@ -10,7 +10,7 @@ <parent> <groupId>org.chorem</groupId> <artifactId>pollen</artifactId> - <version>1.5.5-SNAPSHOT</version> + <version>2.0-SNAPSHOT</version> </parent> <groupId>org.chorem.pollen</groupId> Modified: branches/pollen-2.0/pollen-rest-api/pom.xml =================================================================== --- branches/pollen-2.0/pollen-rest-api/pom.xml 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-rest-api/pom.xml 2013-06-14 09:12:59 UTC (rev 3823) @@ -27,7 +27,7 @@ <dependency> <groupId>${project.groupId}</groupId> - <artifactId>pollen-service</artifactId> + <artifactId>pollen-services</artifactId> <version>${project.version}</version> </dependency> @@ -41,11 +41,6 @@ <artifactId>webmotion-unittest</artifactId> </dependency> - <!--dependency> - <groupId>org.debux.webmotion</groupId> - <artifactId>webmotion-extra-jpa</artifactId> - </dependency--> - <dependency> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.0-api</artifactId> @@ -208,18 +203,7 @@ </resource> </resources> </build> - <properties> - - </properties> - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-jcl</artifactId> - <scope>runtime</scope> - </dependency> - </dependencies> </profile> - </profiles> </project> Added: branches/pollen-2.0/pollen-rest-api/src/it/pom/pom.xml =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/it/pom/pom.xml (rev 0) +++ branches/pollen-2.0/pollen-rest-api/src/it/pom/pom.xml 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,272 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + Pollen :: UI (struts2) + $Id$ + $HeadURL: http://svn.chorem.org/svn/pollen/branches/pollen-2.0/pollen-ui-struts2/src/i... $ + %% + Copyright (C) 2009 - 2012 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% + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.chorem</groupId> + <artifactId>pollen</artifactId> + <version>@pom.version@</version> + </parent> + + <groupId>org.chorem.pollen.it</groupId> + <artifactId>pollen-it</artifactId> + <name>Pollen :: IT</name> + <description>Super Pom des ITs</description> + <packaging>pom</packaging> + + <properties> + <defaultWebContextPath>pollen</defaultWebContextPath> + <pollenServerPort>8765</pollenServerPort> + <defaultLogDir>${basedir}/target</defaultLogDir> + + <pollenConfigurationFile>pollen-it.properties</pollenConfigurationFile> + <pollenDataDirectory> + ${project.build.testOutputDirectory}/data + </pollenDataDirectory> + </properties> + + <dependencies> + + <dependency> + <groupId>org.chorem.pollen</groupId> + <artifactId>pollen-rest-api</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty-runner</artifactId> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + + </dependencies> + + <build> + + <resources> + <resource> + <directory>src/main/resources</directory> + <filtering>false</filtering> + </resource> + </resources> + + <plugins> + + </plugins> + + <pluginManagement> + <plugins> + <plugin> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty-maven-plugin</artifactId> + <configuration> + <stopKey>A</stopKey> + <stopPort>1269</stopPort> + <contextXml>${basedir}/src/jetty/jetty-context.xml</contextXml> + <webAppConfig> + <contextPath>/${defaultWebContextPath}</contextPath> + </webAppConfig> + <systemProperties> + <systemProperty> + <name>basedir</name> + <value>${basedir}</value> + </systemProperty> + <systemProperty> + <name>pollen.log.dir</name> + <value>${project.build.directory}</value> + </systemProperty> + <systemProperty> + <name>pollenConfigurationFile</name> + <value>${pollenConfigurationFile}</value> + </systemProperty> + <systemProperty> + <name>jetty.port</name> + <value>${pollenServerPort}</value> + </systemProperty> + <systemProperty> + <name>pollenServerPort</name> + <value>${pollenServerPort}</value> + </systemProperty> + <systemProperty> + <name>pollenDataDirectory</name> + <value>${pollenDataDirectory}</value> + </systemProperty> + </systemProperties> + </configuration> + </plugin> + + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <executions> + + <execution> + <id>default-test</id> + <goals> + <goal>test</goal> + </goals> + <configuration> + <skip>true</skip> + </configuration> + </execution> + </executions> + </plugin> + + </plugins> + </pluginManagement> + </build> + + <profiles> + + <profile> + <id>start-server</id> + <activation> + <property> + <name>runIts</name> + <value>true</value> + </property> + </activation> + + <properties> + <jetty.daemon>${runIts}</jetty.daemon> + </properties> + <build> + <defaultGoal>pre-integration-test</defaultGoal> + <plugins> + + <plugin> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty-maven-plugin</artifactId> + <executions> + <execution> + <id>start-pollen</id> + <phase>pre-integration-test</phase> + <goals> + <goal>run</goal> + </goals> + <configuration> + <!--<daemon>true</daemon>--> + <webAppSourceDirectory> + ${explodedWarPath} + </webAppSourceDirectory> + <webAppConfig> + <descriptor> + ${explodedWarPath}/WEB-INF/web.xml + </descriptor> + </webAppConfig> + <classesDirectory> + ${explodedWarPath}/WEB-INF/classes + </classesDirectory> + <useTestScope>true</useTestScope> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + + <profile> + <id>run-tests</id> + <activation> + <property> + <name>runIts</name> + <value>true</value> + </property> + </activation> + <build> + <defaultGoal>integration-test</defaultGoal> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <executions> + <execution> + <id>run-tests</id> + <phase>integration-test</phase> + <goals> + <goal>test</goal> + </goals> + <configuration> + <includes> + <include>**/PollenTestSuite.java</include> + </includes> + <systemPropertyVariables> + <pollenServerPort>${pollenServerPort}</pollenServerPort> + <pollenConfigurationFile> + ${pollenConfigurationFile} + </pollenConfigurationFile> + <pollenDataDirectory> + ${pollenDataDirectory} + </pollenDataDirectory> + <extraDrivers>${extraDrivers}</extraDrivers> + </systemPropertyVariables> + </configuration> + </execution> + </executions> + </plugin> + + </plugins> + </build> + </profile> + + <profile> + <id>stop-server</id> + <activation> + <property> + <name>runIts</name> + <value>true</value> + </property> + </activation> + <build> + <defaultGoal>post-integration-test</defaultGoal> + <plugins> + + <plugin> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty-maven-plugin</artifactId> + <executions> + <execution> + <id>stop-pollen</id> + <phase>post-integration-test</phase> + <goals> + <goal>stop</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + + </profiles> + +</project> Property changes on: branches/pollen-2.0/pollen-rest-api/src/it/pom/pom.xml ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: branches/pollen-2.0/pollen-rest-api/src/it/user/README.txt =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/it/user/README.txt (rev 0) +++ branches/pollen-2.0/pollen-rest-api/src/it/user/README.txt 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1 @@ +Test the user REST Api \ No newline at end of file Property changes on: branches/pollen-2.0/pollen-rest-api/src/it/user/README.txt ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenApplicationContext.java =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenApplicationContext.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenApplicationContext.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -26,9 +26,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.pollen.persistence.JpaPollenPersistenceContext; -import org.chorem.pollen.service.DefaultPollenServiceContext; -import org.chorem.pollen.service.PollenServiceContext; -import org.chorem.pollen.service.config.PollenServiceConfig; +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; Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenRender.java =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenRender.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenRender.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -28,7 +28,6 @@ import com.google.gson.Gson; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.persistence.entity.JpaPollenEntity; import org.debux.webmotion.server.call.Call; import org.debux.webmotion.server.call.HttpContext; import org.debux.webmotion.server.mapping.Mapping; @@ -53,14 +52,13 @@ import java.util.Map; /** - * To render + * 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. * @@ -115,20 +113,20 @@ // single object - if (model instanceof JpaPollenEntity) { + if (model instanceof JpaEntity) { // entity need to transform it - JpaPollenEntity jpaEntity = (JpaPollenEntity) model; + JpaEntity jpaEntity = (JpaEntity) model; - PollenEntityBinder<JpaPollenEntity> binder = BinderFactory.newBinder(jpaEntity.getClass(), jpaEntity.getClass(), null, PollenEntityBinder.class); + 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 JpaPollenEntity) { + if (propertyValue instanceof JpaEntity) { result.put(propertyName, toMap(propertyValue)); continue; } @@ -136,9 +134,6 @@ result.put(propertyName, propertyValue); } - // replace id to simpleId - result.put(JpaEntity.PROPERTY_ID, jpaEntity.getSimpleId()); - // treat collections if (includeCollection != null) { @@ -149,15 +144,12 @@ } } return result; - } return model; - - } - protected static class PollenEntityBinder<E extends JpaPollenEntity> extends Binder<E, E> { + protected static class PollenEntityBinder<E extends JpaEntity> extends Binder<E, E> { /** Logger. */ private static final Log log = @@ -168,7 +160,6 @@ protected List<String> simpleProperties; public PollenEntityBinder() { - } @Override @@ -176,7 +167,7 @@ super.setModel(model); this.simpleProperties = Lists.newArrayList(); for (String property : model.getSourceDescriptors()) { - if (model.getCollectionType(property)==null) { + if (model.getCollectionType(property) == null) { simpleProperties.add(property); } } Added: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenSecurityFilter.java =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenSecurityFilter.java (rev 0) +++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenSecurityFilter.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,47 @@ +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); + } + } + } +} Property changes on: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenSecurityFilter.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceContextFilter.java =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceContextFilter.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceContextFilter.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -23,7 +23,7 @@ * #L% */ -import org.chorem.pollen.service.PollenServiceContext; +import org.chorem.pollen.services.PollenServiceContext; import org.debux.webmotion.server.WebMotionFilter; import org.debux.webmotion.server.call.HttpContext; Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceListener.java =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceListener.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceListener.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -23,28 +23,21 @@ * #L% */ -import com.google.common.collect.Maps; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.persistence.entity.Comment; -import org.chorem.pollen.persistence.entity.Poll; -import org.chorem.pollen.persistence.entity.PollenEntities; -import org.chorem.pollen.persistence.entity.PollenUser; -import org.chorem.pollen.service.PollenServiceContext; -import org.chorem.pollen.service.exception.UserEmailAlreadyUsedException; -import org.chorem.pollen.service.exception.UserLoginAlreadyUsedException; +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 org.nuiton.jpa.api.JpaEntity; import javax.persistence.EntityManager; import javax.servlet.http.HttpServletRequest; import java.lang.reflect.Type; -import java.util.Map; /** * TODO @@ -62,7 +55,7 @@ public void onStart(Mapping mapping, ServerContext serverContext) { serverContext.addInjector(new PollenServiceContextInjector()); - serverContext.addInjector(new PollenIdInjector()); + serverContext.addInjector(new SessionTokenInjector()); // Create application context PollenApplicationContext applicationContext = @@ -75,7 +68,8 @@ EntityManager entityManager = applicationContext.newEntityManager(); try { - PollenServiceContext serviceContext = applicationContext.newServiceContext(entityManager); + PollenServiceContext serviceContext = + applicationContext.newServiceContext(entityManager); serviceContext.getUserService().createDefaultUsers(); } catch (UserEmailAlreadyUsedException e) { //Can't happen @@ -103,53 +97,28 @@ 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(); - return PollenServices.getServiceContext(request); + + result = PollenServices.getServiceContext(request); } - return null; + return result; } } - protected static class PollenIdInjector implements ExecutorParametersInjectorHandler.Injector { - - final Map<String, Class<? extends JpaEntity>> paramMapping; - - public PollenIdInjector() { - paramMapping = Maps.newTreeMap(); - paramMapping.put("userId", PollenUser.class); - paramMapping.put("pollId", Poll.class); - paramMapping.put("commentId", Comment.class); - } - + protected static class SessionTokenInjector implements ExecutorParametersInjectorHandler.Injector { @Override - public Object getValue(Mapping mapping, - Call call, - String name, - Class<?> type, - Type generic) { + 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(); - if (String.class.isAssignableFrom(type) && paramMapping.containsKey(name)) { - - Class<? extends JpaEntity> entityType = paramMapping.get(name); - - Call.ParameterTree parameterTree = call.getParameterTree(); - Map<String, Call.ParameterTree> tree = parameterTree.getTree(); - - Call.ParameterTree paramValue = tree.get(name); - if (paramValue != null) { - String id = String.valueOf(((String[]) paramValue.getValue())[0]); - if (PollenEntities.isSimpleId(id)) { - - // get the full id - String fullId = PollenEntities.getEntityId( - entityType, id); - return fullId; - } - } + result = PollenServices.getServiceContext(request); } - return null; + return result; } } } Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServices.java =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServices.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServices.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -23,7 +23,8 @@ * #L% */ -import org.chorem.pollen.service.PollenServiceContext; +import org.chorem.pollen.persistence.entity.SessionToken; +import org.chorem.pollen.services.PollenServiceContext; import org.nuiton.web.filter.JpaTransactionFilter; import javax.persistence.EntityManager; @@ -42,6 +43,8 @@ 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) { @@ -72,4 +75,15 @@ request.getAttribute(REQUEST_ENTITY_MANAGER); return result; } + + public static SessionToken getSessionToken(HttpServletRequest request) { + SessionToken result = (SessionToken) + request.getAttribute(REQUEST_POLLEN_CONNECTED_USER); + return result; + } + + public static void setSessionToken(HttpServletRequest request, + SessionToken sessionToken) { + request.setAttribute(REQUEST_POLLEN_CONNECTED_USER, sessionToken); + } } \ No newline at end of file Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/AuthService.java =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/AuthService.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/AuthService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -23,9 +23,9 @@ * #L% */ -import org.chorem.pollen.service.PollenServiceContext; -import org.chorem.pollen.service.exception.EntityNotFoundException; -import org.chorem.pollen.service.exception.UserInvalidPasswordException; +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; /** Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/CommentService.java =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/CommentService.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/CommentService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -24,8 +24,8 @@ */ import org.chorem.pollen.persistence.entity.Comment; -import org.chorem.pollen.service.PollenServiceContext; -import org.chorem.pollen.service.exception.EntityNotFoundException; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.exception.EntityNotFoundException; import org.debux.webmotion.server.WebMotionController; import java.util.List; Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/FavoriteListService.java =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/FavoriteListService.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/FavoriteListService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -25,14 +25,22 @@ import org.chorem.pollen.persistence.entity.FavoriteList; import org.chorem.pollen.persistence.entity.FavoriteListMember; -import org.chorem.pollen.service.PollenServiceContext; -import org.chorem.pollen.service.exception.EntityNotFoundException; +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 @@ -48,18 +56,26 @@ return context.getFavoriteListService().getFavoriteList(favoriteListId); } - public FavoriteList createFavoriteList(PollenServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException { + public FavoriteList createFavoriteList(PollenServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, FavoriteListNameAlreadyUsedException { return context.getFavoriteListService().createFavoriteList(userId, favoriteList); } - public FavoriteList editFavoriteList(PollenServiceContext context, FavoriteList favoriteList) throws EntityNotFoundException { - return context.getFavoriteListService().editFavoriteList(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 { + 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; @@ -69,15 +85,15 @@ return context.getFavoriteListService().getFavoriteListMember(memberId); } - public FavoriteListMember addMember(PollenServiceContext context, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException { + public FavoriteListMember addMember(PollenServiceContext context, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberEmailAlreadyUsedException, FavoriteListMemberNameAlreadyUsedException { return context.getFavoriteListService().addFavoriteListMember(favoriteListId, member); } - public FavoriteListMember editMember(PollenServiceContext context, FavoriteListMember member) throws EntityNotFoundException { - return context.getFavoriteListService().editFavoriteListMember(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 { - context.getFavoriteListService().removeFavoriteListMember( favoriteListId, memberId); + public void removeMember(PollenServiceContext context, String favoriteListId, String memberId) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException { + context.getFavoriteListService().removeFavoriteListMember(favoriteListId, memberId); } } Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollService.java =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollService.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -25,11 +25,10 @@ import org.chorem.pollen.persistence.entity.Choice; import org.chorem.pollen.persistence.entity.Poll; -import org.chorem.pollen.service.PollenServiceContext; -import org.chorem.pollen.service.exception.EntityNotFoundException; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.exception.EntityNotFoundException; import org.debux.webmotion.server.WebMotionController; -import javax.servlet.annotation.WebFilter; import java.io.File; import java.util.List; import java.util.Set; @@ -62,6 +61,10 @@ 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); } Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/UserService.java =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/UserService.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/UserService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -24,12 +24,12 @@ */ import org.chorem.pollen.persistence.entity.PollenUser; -import org.chorem.pollen.service.PollenServiceContext; -import org.chorem.pollen.service.exception.EntityNotFoundException; -import org.chorem.pollen.service.exception.UserEmailAlreadyUsedException; -import org.chorem.pollen.service.exception.UserInvalidEmailActiviationTokenException; -import org.chorem.pollen.service.exception.UserInvalidPasswordException; -import org.chorem.pollen.service.exception.UserLoginAlreadyUsedException; +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; Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteCountingService.java =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteCountingService.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteCountingService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -23,9 +23,9 @@ * #L% */ -import org.chorem.pollen.service.PollResult; -import org.chorem.pollen.service.PollenServiceContext; -import org.chorem.pollen.service.exception.EntityNotFoundException; +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; /** Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteService.java =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteService.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -24,8 +24,8 @@ */ import org.chorem.pollen.persistence.entity.Vote; -import org.chorem.pollen.service.PollenServiceContext; -import org.chorem.pollen.service.exception.EntityNotFoundException; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.exception.EntityNotFoundException; import org.debux.webmotion.server.WebMotionController; import java.util.List; Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoterListService.java =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoterListService.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoterListService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -25,8 +25,8 @@ import org.chorem.pollen.persistence.entity.VoterList; import org.chorem.pollen.persistence.entity.VoterListMember; -import org.chorem.pollen.service.PollenServiceContext; -import org.chorem.pollen.service.exception.EntityNotFoundException; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.exception.EntityNotFoundException; import org.debux.webmotion.server.WebMotionController; import java.util.List; Modified: branches/pollen-2.0/pollen-rest-api/src/main/resources/mapping =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/main/resources/mapping 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-rest-api/src/main/resources/mapping 2013-06-14 09:12:59 UTC (rev 3823) @@ -33,20 +33,22 @@ GET /polls/{pollId}/comments CommentService.getComments POST /polls/{pollId}/comments CommentService.addComment GET /comments/{commentId} CommentService.getComment -PUT /comments CommentService.editComment +PUT /comments/{commentId} CommentService.editComment DELETE /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 FavoriteListService.editFavoriteList +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 /favoriteListMembers FavoriteListService.editMember +PUT /favoriteLists/{flId}/members/{mId} FavoriteListService.editMember DELETE /favoriteLists/{flId}/members/{mId} FavoriteListService.removeMember # PollService @@ -56,7 +58,7 @@ GET /polls/invited PollService.getInvitedPolls GET /polls/participated PollService.getParticipatedPolls POST /polls PollService.createPoll -PUT /polls PollService.editPoll +PUT /polls/{pollId} PollService.editPoll GET /polls/{pollId} PollService.getPoll DELETE /polls/{pollId} PollService.deletePoll POST /polls/{pollId} PollService.clonePoll @@ -66,7 +68,7 @@ GET /polls/{pollId}/choices PollService.getChoices POST /polls/{pollId}/choices PollService.addChoice GET /choices/{choiceId} PollService.getChoice -PUT /choices PollService.editChoice +PUT /choices/{choiceId} PollService.editChoice DELETE /polls/{pollId}/choices/{choiceId} PollService.deleteChoice # UserService @@ -74,7 +76,7 @@ GET /users UserService.getUsers GET /users/{userId} UserService.getUser POST /users UserService.createUser -PUT /users UserService.editUser +PUT /users/{userId} UserService.editUser PUT /users/{userId}?token={} UserService.validateUserEmail # VoteCountingService @@ -86,13 +88,14 @@ 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 GET /voterLists/{vlId}/members VoterListService.getMembers GET /voterListMembers/{mId} VoterListService.getMember POST /voterLists/{vlId}/members VoterListService.addMember -PUT /voterListMembers VoterListService.editMember +PUT /voterListMembers/{mId} VoterListService.editMember DELETE /voterLists/{vlId}/members/{mId} VoterListService.deleteMember # VoteService @@ -100,5 +103,5 @@ GET /polls/{pollId}/votes VoteService.getVotes PUT /polls/{pollId}/votes VoteService.addVote GET /votes/{voteId} VoteService.getVote -PUT /votes VoteService.editVote +PUT /votes/{voteId} VoteService.editVote DELETE /polls/{pollId}/votes/{voteId} VoteService.deleteVote Modified: branches/pollen-2.0/pollen-rest-api/src/main/webapp/WEB-INF/web.xml =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/main/webapp/WEB-INF/web.xml 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-rest-api/src/main/webapp/WEB-INF/web.xml 2013-06-14 09:12:59 UTC (rev 3823) @@ -30,14 +30,6 @@ <display-name>Pollen REST Api</display-name> - <listener> - <listener-class>org.apache.commons.fileupload.servlet.FileCleanerCleanup</listener-class> - </listener> - - <listener> - <listener-class>org.debux.webmotion.server.WebMotionServletContextListener</listener-class> - </listener> - <filter> <filter-name>jpaTransaction</filter-name> <filter-class> @@ -45,24 +37,9 @@ </filter-class> </filter> - <filter> - <filter-name>WebMotionServer</filter-name> - <filter-class>org.debux.webmotion.server.WebMotionServer</filter-class> - <async-supported>true</async-supported> - </filter> - <filter-mapping> <filter-name>jpaTransaction</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> - <filter-mapping> - <filter-name>WebMotionServer</filter-name> - <url-pattern>/*</url-pattern> - <dispatcher>REQUEST</dispatcher> - <dispatcher>INCLUDE</dispatcher> - <dispatcher>FORWARD</dispatcher> - <dispatcher>ERROR</dispatcher> - </filter-mapping> - </web-app> \ No newline at end of file Modified: branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -25,11 +25,10 @@ import org.chorem.pollen.persistence.JpaPollenPersistenceContext; import org.chorem.pollen.rest.PollenApplicationContext; -import org.chorem.pollen.service.FixturesService; -import org.chorem.pollen.service.PollenFixtures; -import org.chorem.pollen.service.PollenServiceContext; -import org.debux.webmotion.unittest.WebMotionTest; -import org.junit.Before; +import org.chorem.pollen.services.service.FixturesService; +import org.chorem.pollen.services.PollenFixtures; +import org.chorem.pollen.services.PollenServiceContext; +import org.debux.webmotion.unittest.WebMotionJUnit; import org.junit.Rule; import org.nuiton.jpa.junit.JpaEntityManagerRule; @@ -42,7 +41,7 @@ * @author tchemit <chemit@codelutin.com> * @since 2.0 */ -public class AbstractPollenRestApiTest extends WebMotionTest { +public class AbstractPollenRestApiTest extends WebMotionJUnit { protected JpaEntityManagerRule jpaEntityManagerRule; @@ -114,8 +113,8 @@ } - @Before - public void launchServer() throws Exception { - runServer(); - } +// @Before +// public void launchServer() throws Exception { +// runServer(); +// } } Modified: branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/FakePollenServiceContext.java =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/FakePollenServiceContext.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/FakePollenServiceContext.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -26,7 +26,7 @@ import com.google.common.base.Preconditions; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.service.DefaultPollenServiceContext; +import org.chorem.pollen.services.DefaultPollenServiceContext; import java.util.Date; Modified: branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/UserServiceTest.java =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/UserServiceTest.java 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/UserServiceTest.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -52,7 +52,7 @@ Request request = createRequest("/users").Get(); String result = request.execute().returnContent().asString(); - assertTrue(result.contains("users")); + assertTrue(result.contains("email")); } Modified: branches/pollen-2.0/pollen-rest-api/src/test/resources/pollen.properties =================================================================== --- branches/pollen-2.0/pollen-rest-api/src/test/resources/pollen.properties 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pollen-rest-api/src/test/resources/pollen.properties 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,5 +1,5 @@ javax.persistence.jdbc.driver=org.h2.Driver -javax.persistence.jdbc.url=jdbc:h2:file:${testDirectory}/pollen/h2data +javax.persistence.jdbc.url=jdbc:h2:file:target/pollen/h2data javax.persistence.jdbc.user=sa javax.persistence.jdbc.password= hibernate.dialect=org.hibernate.dialect.H2Dialect Modified: branches/pollen-2.0/pollen-services/pom.xml =================================================================== --- branches/pollen-2.0/pollen-service/pom.xml 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/pom.xml 2013-06-14 09:12:59 UTC (rev 3823) @@ -9,7 +9,7 @@ </parent> <groupId>org.chorem.pollen</groupId> - <artifactId>pollen-service</artifactId> + <artifactId>pollen-services</artifactId> <name>Pollen :: Service </name> <description>Pollen Service Layer</description> Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/AbstractPollenService.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/AbstractPollenService.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/AbstractPollenService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,117 +0,0 @@ -package org.chorem.pollen.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 org.chorem.pollen.persistence.PollenPersistenceContext; -import org.chorem.pollen.service.config.PollenServiceConfig; -import org.chorem.pollen.service.exception.EntityNotFoundException; -import org.nuiton.jpa.api.JpaEntities; -import org.nuiton.jpa.api.JpaEntity; - -import java.util.Date; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public abstract class AbstractPollenService implements PollenServiceSupport { - - protected PollenServiceContext serviceContext; - - protected void checkHasId(JpaEntity entity) { - Preconditions.checkState(JpaEntities.isEntityHasId(entity)); - } - - protected void checkHasNoId(JpaEntity entity) { - Preconditions.checkState(JpaEntities.isEntityHasNoId(entity)); - } - - @Override - public void setServiceContext(PollenServiceContext serviceContext) { - this.serviceContext = serviceContext; - } - - protected Date getNow() { - return serviceContext.getNow(); - } - - protected String generateId() { - return serviceContext.generateUUID(); - } - - protected PollenPersistenceContext getPersistenceContext() { - return serviceContext.getPersistenceContext(); - } - - protected PollenServiceConfig getPollenServiceConfig() { - return serviceContext.getPollenServiceConfig(); - } - - protected AuthService getAuthService() { - return serviceContext.getAuthService(); - } - - protected CommentService getCommentService() { - return serviceContext.getCommentService(); - } - - protected FavoriteListService getFavoriteListService() { - return serviceContext.getFavoriteListService(); - } - - protected PollService getPollService() { - return serviceContext.getPollService(); - } - - protected UserService getUserService() { - return serviceContext.getUserService(); - } - - protected VoteCountingService getVoteCountingService() { - return serviceContext.getVoteCountingService(); - } - - protected VoterListService getVoterListService() { - return serviceContext.getVoterListService(); - } - - protected VoteService getVoteService() { - return serviceContext.getVoteService(); - } - - protected EmailService getEmailService() { - return serviceContext.getEmailService(); - } - - protected <E extends JpaEntity> void checkEntityExists(Class<E> type, - E entity, - String entityId) throws EntityNotFoundException { - if (entity == null) { - throw new EntityNotFoundException(type, entityId); - } - } -} Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/AuthService.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/AuthService.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/AuthService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,116 +0,0 @@ -package org.chorem.pollen.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 org.chorem.pollen.persistence.dao.PollenUserJpaDao; -import org.chorem.pollen.persistence.dao.SessionTokenJpaDao; -import org.chorem.pollen.persistence.entity.PollenUser; -import org.chorem.pollen.persistence.entity.SessionToken; -import org.chorem.pollen.service.exception.EntityNotFoundException; -import org.chorem.pollen.service.exception.UserInvalidPasswordException; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class AuthService extends AbstractPollenService { - - public String login(String login, String password) throws EntityNotFoundException, UserInvalidPasswordException { - Preconditions.checkNotNull(login); - Preconditions.checkNotNull(password); - - PollenUser user = getPersistenceContext().getPollenUserDao().findByLogin(login); - if (user == null) { - throw new EntityNotFoundException(PollenUser.class, login); - } - - String encodedPassword = serviceContext.encodePassword(password); - if (!encodedPassword.equals(user.getPassword())) { - throw new UserInvalidPasswordException(); - } - - // Create a new session Token - SessionTokenJpaDao dao = getPersistenceContext().getSessionTokenDao(); - - SessionToken sessionToken = dao.newInstance(); - String token = serviceContext.generateUUID(); - String encodedToken = serviceContext.encodePassword(token); - sessionToken.setPollenUser(user); - sessionToken.setToken(encodedToken); - sessionToken.setCreationDate(serviceContext.getNow()); - - dao.persist(sessionToken); - getPersistenceContext().commit(); - - return token; - } - - public void lostPassword(String login) throws EntityNotFoundException { - Preconditions.checkNotNull(login); - - PollenUserJpaDao dao = getPersistenceContext().getPollenUserDao(); - - PollenUser user = dao.findByLogin(login); - if (user == null) { - throw new EntityNotFoundException(PollenUser.class, login); - } - - // Generate a new password - String newPassword = serviceContext.generatePassword(); - String encodedPassword = serviceContext.encodePassword(newPassword); - user.setPassword(encodedPassword); - dao.merge(user); - getPersistenceContext().commit(); - - notifyPasswordChanged(user, newPassword); - } - - public void logout(String login, String token) throws EntityNotFoundException { - Preconditions.checkNotNull(login); - Preconditions.checkNotNull(token); - PollenUser user = getPersistenceContext().getPollenUserDao().findByLogin(login); - if (user == null) { - throw new EntityNotFoundException(PollenUser.class, login); - } - - String encodedToken = serviceContext.encodePassword(token); - - SessionTokenJpaDao dao = getPersistenceContext().getSessionTokenDao(); - - SessionToken sessionToken = dao.findByToken(encodedToken); - if (sessionToken == null) { - throw new EntityNotFoundException(SessionToken.class, token); - } - - dao.remove(sessionToken); - getPersistenceContext().commit(); - } - - protected void notifyPasswordChanged(PollenUser user, String newPassword) { - //TODO - } -} Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/CommentService.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/CommentService.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/CommentService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,94 +0,0 @@ -package org.chorem.pollen.service; - -/* - * #%L - * Pollen :: Service 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.chorem.pollen.persistence.entity.Comment; -import org.chorem.pollen.persistence.entity.Poll; -import org.chorem.pollen.service.exception.EntityNotFoundException; - -import java.util.List; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class CommentService extends AbstractPollenService { - - public List<Comment> getComments(String pollId) throws EntityNotFoundException { - Preconditions.checkNotNull(pollId); - Poll poll = getPollService().getPoll(pollId); - return poll.getComment(); - } - - public Comment getComment(String commentId) throws EntityNotFoundException { - Preconditions.checkNotNull(commentId); - Comment result = getPersistenceContext().getCommentDao().findById(commentId); - checkEntityExists(Comment.class, result, commentId); - return result; - } - - public Comment addComment(String pollId, Comment comment) throws EntityNotFoundException { - Preconditions.checkNotNull(pollId); - checkHasNoId(comment); - Poll poll = getPollService().getPoll(pollId); - - poll.addComment(comment); - getPersistenceContext().getPollDao().merge(poll); - getPersistenceContext().commit(); - - Comment result = getComment(comment.getId()); - return result; - } - - public Comment editComment(Comment comment) throws EntityNotFoundException { - - // check comment exists - getComment(comment.getId()); - - getPersistenceContext().getCommentDao().merge(comment); - getPersistenceContext().commit(); - - Comment result = getComment(comment.getId()); - return result; - } - - public void deleteComment(String pollId, String commentId) throws EntityNotFoundException { - Preconditions.checkNotNull(pollId); - Preconditions.checkNotNull(commentId); - Poll poll = getPollService().getPoll(pollId); - - Comment comment = getComment(commentId); - Preconditions.checkNotNull(comment); - - poll.removeComment(comment); - - getPersistenceContext().getPollDao().merge(poll); - - getPersistenceContext().commit(); - } - -} Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/DefaultPollenServiceContext.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/DefaultPollenServiceContext.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/DefaultPollenServiceContext.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,158 +0,0 @@ -package org.chorem.pollen.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.apache.commons.lang3.RandomStringUtils; -import org.chorem.pollen.persistence.PollenPersistenceContext; -import org.chorem.pollen.service.config.PollenServiceConfig; -import org.nuiton.util.StringUtil; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.Date; -import java.util.UUID; - -public class DefaultPollenServiceContext implements PollenServiceContext { - - protected PollenServiceConfig pollenServiceConfig; - - protected PollenPersistenceContext persistenceContext; - - public void setPollenServiceConfig(PollenServiceConfig pollenServiceConfig) { - this.pollenServiceConfig = pollenServiceConfig; - } - - public void setPersistenceContext(PollenPersistenceContext persistenceContext) { - this.persistenceContext = persistenceContext; - } - - @Override - public PollenServiceConfig getPollenServiceConfig() { - return pollenServiceConfig; - } - - @Override - public String generateUUID() { - return UUID.randomUUID().toString(); - } - - @Override - public Date getNow() { - Date now = new Date(); - return now; - } - - public String generatePassword() { - return RandomStringUtils.randomAlphanumeric(8); - } - - @Override - public PollenPersistenceContext getPersistenceContext() { - return persistenceContext; - } - - @Override - public AuthService getAuthService() { - return newService(AuthService.class); - } - - @Override - public CommentService getCommentService() { - return newService(CommentService.class); - } - - @Override - public FavoriteListService getFavoriteListService() { - return newService(FavoriteListService.class); - } - - @Override - public PollService getPollService() { - return newService(PollService.class); - } - - @Override - public UserService getUserService() { - return newService(UserService.class); - } - - @Override - public VoteCountingService getVoteCountingService() { - return newService(VoteCountingService.class); - } - - @Override - public VoterListService getVoterListService() { - return newService(VoterListService.class); - } - - @Override - public VoteService getVoteService() { - return newService(VoteService.class); - } - - @Override - public EmailService getEmailService() { - return newService(EmailService.class); - } - - @Override - public String encodePassword(String password) { - return StringUtil.encodeMD5(password); - } - - protected <E extends PollenServiceSupport> E newService(Class<E> serviceClass) { - - E service; - - try { - - Constructor<E> constructor = serviceClass.getConstructor(); - - service = constructor.newInstance(); - - } catch (NoSuchMethodException e) { - - throw new PollenTechnicalException("all services must provide a default public constructor", e); - - } catch (InvocationTargetException e) { - - throw new PollenTechnicalException("unable to instantiate pollen service", e); - - } catch (InstantiationException e) { - - throw new PollenTechnicalException("unable to instantiate pollen service", e); - - } catch (IllegalAccessException e) { - - throw new PollenTechnicalException("unable to instantiate pollen service", e); - } - - service.setServiceContext(this); - - return service; - - } - -} Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/EmailService.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/EmailService.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/EmailService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,39 +0,0 @@ -package org.chorem.pollen.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.entity.PollenUser; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class EmailService extends AbstractPollenService { - - public void onUserCreated(PollenUser user) { - //TODO - } -} Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/FavoriteListService.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/FavoriteListService.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/FavoriteListService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,159 +0,0 @@ -package org.chorem.pollen.service; - -/* - * #%L - * Pollen :: Service 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.chorem.pollen.persistence.entity.FavoriteList; -import org.chorem.pollen.persistence.entity.FavoriteListMember; -import org.chorem.pollen.persistence.entity.PollenUser; -import org.chorem.pollen.service.exception.EntityNotFoundException; - -import java.util.List; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class FavoriteListService extends AbstractPollenService { - - public List<FavoriteList> getFavoriteLists(String userId)throws EntityNotFoundException { - Preconditions.checkNotNull(userId); - PollenUser user = getUserService().getUser(userId); - - List<FavoriteList> result = user.getFavoriteList(); - return result; - } - - public FavoriteList getFavoriteList(String favoriteListId) throws EntityNotFoundException{ - Preconditions.checkNotNull(favoriteListId); - FavoriteList result = getPersistenceContext().getFavoriteListDao().findById(favoriteListId); - checkEntityExists(FavoriteList.class, result, favoriteListId); - return result; - } - - public FavoriteList createFavoriteList(String userId, - FavoriteList favoriteList) throws EntityNotFoundException{ - Preconditions.checkNotNull(userId); - Preconditions.checkNotNull(favoriteList); - checkHasNoId(favoriteList); - - PollenUser user = getUserService().getUser(userId); - - user.addFavoriteList(favoriteList); - getPersistenceContext().getPollenUserDao().merge(user); - - getPersistenceContext().commit(); - FavoriteList result = getFavoriteList(favoriteList.getId()); - return result; - } - - public FavoriteList editFavoriteList(FavoriteList favoriteList) throws EntityNotFoundException{ - Preconditions.checkNotNull(favoriteList); - checkHasId(favoriteList); - - getFavoriteList(favoriteList.getId()); - - getPersistenceContext().getFavoriteListDao().merge(favoriteList); - - getPersistenceContext().commit(); - FavoriteList result = getFavoriteList(favoriteList.getId()); - return result; - } - - public void deleteFavoriteList(String userId, String favoriteListId) throws EntityNotFoundException{ - Preconditions.checkNotNull(userId); - Preconditions.checkNotNull(favoriteListId); - - PollenUser user = getUserService().getUser(userId); - - FavoriteList persisted = getFavoriteList(favoriteListId); - - user.removeFavoriteList(persisted); - getPersistenceContext().getPollenUserDao().merge(user); - - getPersistenceContext().commit(); - } - - public List<FavoriteListMember> getFavoriteListMembers(String favoriteListId)throws EntityNotFoundException { - Preconditions.checkNotNull(favoriteListId); - - FavoriteList favoriteList = getFavoriteList(favoriteListId); - - return favoriteList.getFavoriteListMember(); - } - - public FavoriteListMember getFavoriteListMember(String memberId)throws EntityNotFoundException { - Preconditions.checkNotNull(memberId); - FavoriteListMember result = getPersistenceContext().getFavoriteListMemberDao().findById(memberId); - checkEntityExists(FavoriteListMember.class, result, memberId); - return result; - } - - public FavoriteListMember addFavoriteListMember(String favoriteListId, - FavoriteListMember member)throws EntityNotFoundException { - Preconditions.checkNotNull(favoriteListId); - Preconditions.checkNotNull(member); - checkHasNoId(member); - - FavoriteList favoriteList = getFavoriteList(favoriteListId); - - favoriteList.addFavoriteListMember(member); - - getPersistenceContext().getFavoriteListDao().merge(favoriteList); - - getPersistenceContext().commit(); - FavoriteListMember result = getFavoriteListMember(member.getId()); - return result; - } - - public FavoriteListMember editFavoriteListMember(FavoriteListMember member)throws EntityNotFoundException { - Preconditions.checkNotNull(member); - checkHasId(member); - - - getFavoriteListMember(member.getId()); - - member = getPersistenceContext().getFavoriteListMemberDao().merge(member); - getPersistenceContext().commit(); - FavoriteListMember result = getFavoriteListMember(member.getId()); - return result; - } - - public void removeFavoriteListMember(String favoriteListId, String memberId) throws EntityNotFoundException{ - Preconditions.checkNotNull(favoriteListId); - Preconditions.checkNotNull(memberId); - - FavoriteList favoriteList = getFavoriteList(favoriteListId); - - FavoriteListMember member = getFavoriteListMember(memberId); - - favoriteList.removeFavoriteListMember(member); - - getPersistenceContext().getFavoriteListDao().merge(favoriteList); - getPersistenceContext().commit(); - } - -} Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/FixturesService.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/FixturesService.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/FixturesService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,100 +0,0 @@ -package org.chorem.pollen.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.Maps; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.persistence.PollenPersistenceContext; -import org.chorem.pollen.persistence.dao.PollenUserJpaDao; -import org.chorem.pollen.persistence.entity.PollenUser; - -import java.util.Collection; -import java.util.Map; - -public class FixturesService extends AbstractPollenService { - - private static final Log log = LogFactory.getLog(FixturesService.class); - - protected Map<String, PollenFixtures> fixtureSets = Maps.newHashMap(); - - public PollenFixtures cleanDatabaseAndLoadFixtures(String fixturesSetName) { - - return loadFixtures(fixturesSetName, true); - - } - - public PollenFixtures loadFixtures(String fixturesSetName) { - - return loadFixtures(fixturesSetName, false); - - } - - protected PollenFixtures loadFixtures(String fixturesSetName, boolean cleanDatabase) { - - boolean devMode = serviceContext.getPollenServiceConfig().isDevMode(); - - Preconditions.checkState(devMode); - - PollenFixtures fixtures = fixtureSets.get(fixturesSetName); - - if (fixtures == null) { - - fixtures = new PollenFixtures(fixturesSetName); - - fixtureSets.put(fixturesSetName, fixtures); - - if (log.isInfoEnabled()) { - log.info("will restore database with fixture set"); - } - - PollenPersistenceContext persistenceContext = serviceContext.getPersistenceContext(); - - if (cleanDatabase) { - - persistenceContext.clearDatabase(); - - } - - PollenUserJpaDao userDao = persistenceContext.getPollenUserDao(); - - Collection<PollenUser> users = fixtures.fixture("users"); - - for (PollenUser user : users) { - - user.setPassword(serviceContext.encodePassword(user.getPassword())); - userDao.persist(user); - } - - persistenceContext.commit(); - - - } - - return fixtures; - - } - -} Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollResult.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollResult.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollResult.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,36 +0,0 @@ -package org.chorem.pollen.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 java.io.Serializable; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class PollResult implements Serializable { - private static final long serialVersionUID = 1L; -} Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollService.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollService.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,200 +0,0 @@ -package org.chorem.pollen.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 org.chorem.pollen.persistence.entity.Choice; -import org.chorem.pollen.persistence.entity.Poll; -import org.chorem.pollen.persistence.entity.PollenUser; -import org.chorem.pollen.service.exception.EntityNotFoundException; - -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 AbstractPollenService { - - public Set<Poll> getCreatedPolls(String userId) throws EntityNotFoundException { - Preconditions.checkNotNull(userId); - - getUserService().getUser(userId); - - return getPersistenceContext().getPollDao().findAllCreated(userId); - } - - public Set<Poll> getInvitedPolls(String userId) throws EntityNotFoundException { - Preconditions.checkNotNull(userId); - - getUserService().getUser(userId); - - return getPersistenceContext().getPollDao().findAllInvited(userId); - } - - public Set<Poll> getParticipatedPolls(String userId) throws EntityNotFoundException { - Preconditions.checkNotNull(userId); - - getUserService().getUser(userId); - - return getPersistenceContext().getPollDao().findAllParticipated(userId); - } - - public Poll getPoll(String pollId) throws EntityNotFoundException { - Preconditions.checkNotNull(pollId); - Poll result = getPersistenceContext().getPollDao().findById(pollId); - checkEntityExists(Poll.class, result, pollId); - return result; - } - - public Poll createPoll(String userId, Poll poll) throws EntityNotFoundException { - Preconditions.checkNotNull(userId); - Preconditions.checkNotNull(poll); - checkHasNoId(poll); - - if (userId != null) { - - // get user - PollenUser user = getUserService().getUser(userId); - - // link it to creator - - } - - getPersistenceContext().getPollDao().persist(poll); - - getPersistenceContext().commit(); - return poll; - } - - public Poll editPoll(Poll poll) throws EntityNotFoundException { - Preconditions.checkNotNull(poll); - checkHasId(poll); - - getPoll(poll.getId()); - - getPersistenceContext().getPollDao().merge(poll); - getPersistenceContext().commit(); - - Poll result = getPoll(poll.getId()); - return result; - } - - public void deletePoll(String pollId) throws EntityNotFoundException { - Preconditions.checkNotNull(pollId); - - Poll poll = getPoll(pollId); - - getPersistenceContext().getPollDao().remove(poll); - getPersistenceContext().commit(); - } - - public Poll clonePoll(String pollId) throws EntityNotFoundException { - Preconditions.checkNotNull(pollId); - - Poll poll = getPoll(pollId); - //TODO - getPersistenceContext().commit(); - return null; - } - - public File closePoll(String pollId) throws EntityNotFoundException { - Preconditions.checkNotNull(pollId); - - Poll poll = getPoll(pollId); - //TODO - getPersistenceContext().commit(); - return null; - } - - public File exportPoll(String pollId) throws EntityNotFoundException { - Preconditions.checkNotNull(pollId); - Poll poll = getPoll(pollId); - //TODO - return null; - } - - public List<Choice> getChoices(String pollId) throws EntityNotFoundException { - Preconditions.checkNotNull(pollId); - - Poll poll = getPoll(pollId); - - return poll.getChoice(); - } - - public Choice getChoice(String choiceId) throws EntityNotFoundException { - Preconditions.checkNotNull(choiceId); - - Choice result = getPersistenceContext().getChoiceDao().findById(choiceId); - checkEntityExists(Choice.class, result, choiceId); - return result; - } - - public Choice addChoice(String pollId, Choice choice) throws EntityNotFoundException { - Preconditions.checkNotNull(pollId); - Preconditions.checkNotNull(choice); - checkHasNoId(choice); - - Poll poll = getPoll(pollId); - - poll.addChoice(choice); - - getPersistenceContext().getPollDao().merge(poll); - - getPersistenceContext().commit(); - Choice result = getChoice(choice.getId()); - return result; - } - - public Choice editChoice(Choice choice) throws EntityNotFoundException { - Preconditions.checkNotNull(choice); - checkHasId(choice); - - getChoice(choice.getId()); - - getPersistenceContext().getChoiceDao().merge(choice); - getPersistenceContext().commit(); - - Choice result = getChoice(choice.getId()); - return result; - } - - public void deleteChoice(String pollId, String choiceId) throws EntityNotFoundException { - Preconditions.checkNotNull(pollId); - Preconditions.checkNotNull(choiceId); - - Poll poll = getPoll(pollId); - Choice choice = getChoice(choiceId); - - poll.removeChoice(choice); - - getPersistenceContext().getPollDao().merge(poll); - - getPersistenceContext().commit(); - } -} Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenFixtures.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollenFixtures.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenFixtures.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,78 +0,0 @@ -package org.chorem.pollen.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.esotericsoftware.yamlbeans.YamlException; -import com.esotericsoftware.yamlbeans.YamlReader; -import org.apache.commons.io.Charsets; -import org.apache.commons.io.IOUtils; -import org.chorem.pollen.persistence.entity.Choice; -import org.chorem.pollen.persistence.entity.Comment; -import org.chorem.pollen.persistence.entity.FavoriteList; -import org.chorem.pollen.persistence.entity.FavoriteListMember; -import org.chorem.pollen.persistence.entity.Poll; -import org.chorem.pollen.persistence.entity.PollenUser; -import org.chorem.pollen.persistence.entity.Vote; -import org.chorem.pollen.persistence.entity.VoterList; -import org.chorem.pollen.persistence.entity.VoterListMember; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Map; - -public class PollenFixtures { - - protected Map<String, Object> fixtures; - - public PollenFixtures(String fixturesName) { - String yamlPath = "/" + fixturesName + ".yaml"; - InputStream inputStream = PollenFixtures.class.getResourceAsStream(yamlPath); - String yaml; - try { - yaml = IOUtils.toString(inputStream, Charsets.UTF_8); - } catch (IOException e) { - throw new IllegalArgumentException(fixturesName + " is not a valid fixtures set name", e); - } - YamlReader reader = new YamlReader(yaml); - reader.getConfig().setClassTag("poll", Poll.class); - reader.getConfig().setClassTag("user", PollenUser.class); - reader.getConfig().setClassTag("favorite-list", FavoriteList.class); - reader.getConfig().setClassTag("favorite-list-member", FavoriteListMember.class); - reader.getConfig().setClassTag("comment", Comment.class); - reader.getConfig().setClassTag("choice", Choice.class); - reader.getConfig().setClassTag("voter-list", VoterList.class); - reader.getConfig().setClassTag("voter-list-member", VoterListMember.class); - reader.getConfig().setClassTag("vote", Vote.class); - - try { - fixtures = (Map<String, Object>) reader.read(); - } catch (YamlException e) { - throw new PollenTechnicalException("unable to read yaml file", e); - } - } - - public <E> E fixture(String id) { - return (E) fixtures.get(id); - } -} Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenServiceContext.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollenServiceContext.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenServiceContext.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,66 +0,0 @@ -package org.chorem.pollen.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.PollenPersistenceContext; -import org.chorem.pollen.service.config.PollenServiceConfig; - -import java.util.Date; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public interface PollenServiceContext { - - String generateUUID(); - - Date getNow(); - - PollenPersistenceContext getPersistenceContext(); - - PollenServiceConfig getPollenServiceConfig(); - - AuthService getAuthService(); - - CommentService getCommentService(); - - FavoriteListService getFavoriteListService(); - - PollService getPollService(); - - UserService getUserService(); - - VoteCountingService getVoteCountingService(); - - VoterListService getVoterListService(); - - VoteService getVoteService(); - - EmailService getEmailService(); - - String generatePassword(); - - String encodePassword(String password); -} Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenServiceSupport.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollenServiceSupport.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenServiceSupport.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,35 +0,0 @@ -package org.chorem.pollen.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% - */ - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public interface PollenServiceSupport { - - void setServiceContext(PollenServiceContext serviceContext); -} Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenTechnicalException.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollenTechnicalException.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenTechnicalException.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,44 +0,0 @@ -package org.chorem.pollen.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% - */ - -public class PollenTechnicalException extends RuntimeException { - - private static final long serialVersionUID = 1L; - - public PollenTechnicalException() { - } - - public PollenTechnicalException(String message) { - super(message); - } - - public PollenTechnicalException(String message, Throwable cause) { - super(message, cause); - } - - public PollenTechnicalException(Throwable cause) { - super(cause); - } -} Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/UserService.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/UserService.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/UserService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,244 +0,0 @@ -package org.chorem.pollen.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 org.apache.commons.lang3.ObjectUtils; -import org.apache.commons.lang3.StringUtils; -import org.chorem.pollen.persistence.dao.PollenUserJpaDao; -import org.chorem.pollen.persistence.entity.PollenUser; -import org.chorem.pollen.service.exception.EntityNotFoundException; -import org.chorem.pollen.service.exception.UserEmailAlreadyUsedException; -import org.chorem.pollen.service.exception.UserInvalidEmailActiviationTokenException; -import org.chorem.pollen.service.exception.UserInvalidPasswordException; -import org.chorem.pollen.service.exception.UserLoginAlreadyUsedException; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderFactory; - -import java.util.List; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class UserService extends AbstractPollenService implements PollenServiceSupport { - - public List<PollenUser> getUsers() { - return getPollenUserDao().findAll(); - } - - public PollenUser getUser(String userId) throws EntityNotFoundException { - Preconditions.checkNotNull(userId); - - PollenUser result = getPollenUserDao().findById(userId); - checkEntityExists(PollenUser.class, result, userId); - return result; - } - - public PollenUser createUser(PollenUser user, boolean generatePassword) throws UserLoginAlreadyUsedException, UserEmailAlreadyUsedException { - Preconditions.checkNotNull(user); - checkHasNoId(user); - Preconditions.checkNotNull(user.getLogin()); - Preconditions.checkNotNull(user.getEmail()); - - PollenUserJpaDao dao = getPollenUserDao(); - - // check login is available - boolean loginExists = dao.loginExists(user.getLogin()); - if (loginExists) { - throw new UserLoginAlreadyUsedException(user.getLogin()); - } - - // check email is available - boolean emailExists = dao.emailExists(user.getEmail()); - if (emailExists) { - throw new UserEmailAlreadyUsedException(user.getEmail()); - } - - PollenUser toCreate = dao.newInstance(); - - // add a emailValidationToken - String emailValidationToken = generateId(); - - String password; - if (generatePassword) { - // let's generate the new password - password = serviceContext.generatePassword(); - } else { - password = user.getPassword(); - } - - // encode the password - String encodedPassword = serviceContext.encodePassword(password); - - toCreate.setLogin(user.getLogin()); - toCreate.setEmailActivationToken(emailValidationToken); - toCreate.setPassword(encodedPassword); - - copyPollenUser(user, toCreate, true); - - dao.persist(toCreate); - getPersistenceContext().commit(); - - notifyUserCreated(toCreate); - - return toCreate; - } - - public PollenUser editUser(PollenUser user) throws UserInvalidPasswordException, UserEmailAlreadyUsedException, EntityNotFoundException { - Preconditions.checkNotNull(user); - checkHasId(user); - - PollenUser persisted = getUser(user.getId()); - - PollenUserJpaDao dao = getPollenUserDao(); - - // check current password - String encodedPassword = serviceContext.encodePassword(user.getPassword()); - if (!encodedPassword.equals(persisted.getPassword())) { - throw new UserInvalidPasswordException(); - } - - boolean emailChanged = ObjectUtils.notEqual(persisted.getEmail(), - user.getEmail()); - - if (emailChanged) { - - // check this email is not used by another user - boolean emailUsed = dao.emailExists(user.getEmail()); - if (emailUsed) { - throw new UserEmailAlreadyUsedException(user.getEmail()); - } - - // add a new emailValidationtoken - String emailValidationToken = generateId(); - persisted.setEmailActivationToken(emailValidationToken); - } - - copyPollenUser(user, persisted, true); - - persisted = dao.merge(persisted); - getPersistenceContext().commit(); - - if (emailChanged) { - - notifyEmailChanged(persisted); - } - return persisted; - } - - public void changePassword(String userId, - String oldPassword, - String newPassword) throws UserInvalidPasswordException, EntityNotFoundException { - Preconditions.checkNotNull(userId); - Preconditions.checkNotNull(oldPassword); - Preconditions.checkNotNull(newPassword); - - PollenUser user = getUser(userId); - - // check current password - String encodedPassword = serviceContext.encodePassword(user.getPassword()); - if (!encodedPassword.equals(user.getPassword())) { - throw new UserInvalidPasswordException(); - } - - // encode new password and store it in user account - String newEncodedPassword = serviceContext.encodePassword(newPassword); - user.setPassword(newEncodedPassword); - - user = getPollenUserDao().merge(user); - getPersistenceContext().commit(); - - notifyPasswordChanged(user); - } - - public void validateUserEmail(String userId, - String token) throws EntityNotFoundException, UserInvalidEmailActiviationTokenException { - - Preconditions.checkNotNull(userId); - Preconditions.checkNotNull(token); - - PollenUser user = getUser(userId); - - Preconditions.checkNotNull(user); - - boolean valid = ObjectUtils.equals( - user.getEmailActivationToken(), token); - - if (!valid) { - throw new UserInvalidEmailActiviationTokenException(); - } - - // reset token in database - user.setEmailActivationToken(null); - - getPollenUserDao().merge(user); - getPersistenceContext().commit(); - } - - protected void notifyUserCreated(PollenUser user) { - - //TODO - } - - protected void notifyEmailChanged(PollenUser user) { - - //TODO - } - - protected void notifyPasswordChanged(PollenUser user) { - - //TODO - } - - protected PollenUserJpaDao getPollenUserDao() { - return getPersistenceContext().getPollenUserDao(); - } - - /** - * Copy {@code source} user account to {@code destination} one. - * The email is lower cased in the {@code destination} user account. - * - * @param source user account to copy - * @param destination which receive the copy - */ - protected void copyPollenUser(PollenUser source, - PollenUser destination, - boolean copyEmail) { - Binder<PollenUser, PollenUser> binder = - BinderFactory.newBinder(PollenUser.class); - - binder.copy(source, destination, - PollenUser.PROPERTY_ADMINISTRATOR, - PollenUser.PROPERTY_NAME, - PollenUser.PROPERTY_LANGUAGE); - - if (copyEmail) { - // Don't keep case for email - destination.setEmail(StringUtils.lowerCase(source.getEmail())); - } - } -} Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/VoteCountingService.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/VoteCountingService.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/VoteCountingService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,45 +0,0 @@ -package org.chorem.pollen.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 org.chorem.pollen.persistence.entity.Poll; -import org.chorem.pollen.service.exception.EntityNotFoundException; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class VoteCountingService extends AbstractPollenService { - - //GET /poll/{pollId}/results - public PollResult getResult(String pollId) throws EntityNotFoundException { - Preconditions.checkNotNull(pollId); - Poll poll = getPollService().getPoll(pollId); - //TODO - return null; - } -} Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/VoteService.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/VoteService.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/VoteService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,100 +0,0 @@ -package org.chorem.pollen.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 org.chorem.pollen.persistence.entity.Poll; -import org.chorem.pollen.persistence.entity.Vote; -import org.chorem.pollen.service.exception.EntityNotFoundException; - -import java.util.List; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class VoteService extends AbstractPollenService { - - public List<Vote> getVotes(String pollId) throws EntityNotFoundException { - Preconditions.checkNotNull(pollId); - - Poll poll = getPollService().getPoll(pollId); - List<Vote> result = poll.getVote(); - return result; - } - - public Vote getVote(String voteId) throws EntityNotFoundException{ - Preconditions.checkNotNull(voteId); - - Vote result = getPersistenceContext().getVoteDao().findById(voteId); - checkEntityExists(Vote.class, result, voteId); - return result; - } - - public Vote addVote(String pollId, Vote vote)throws EntityNotFoundException { - Preconditions.checkNotNull(pollId); - Preconditions.checkNotNull(vote); - checkHasNoId(vote); - - Poll poll = getPollService().getPoll(pollId); - - poll.addVote(vote); - getPersistenceContext().getPollDao().merge(poll); - - getPersistenceContext().commit(); - Vote result = getVote(vote.getId()); - return result; - } - - public Vote editVote(Vote vote)throws EntityNotFoundException { - Preconditions.checkNotNull(vote); - checkHasId(vote); - - getVote(vote.getId()); - - getPersistenceContext().getVoteDao().merge(vote); - getPersistenceContext().commit(); - - Vote result = getVote(vote.getId()); - return result; - } - - public void deleteVote(String pollId, String voteId)throws EntityNotFoundException { - Preconditions.checkNotNull(pollId); - Preconditions.checkNotNull(voteId); - - Poll poll = getPollService().getPoll(pollId); - - Vote vote = getVote(voteId); - - poll.removeVote(vote); - - getPersistenceContext().getPollDao().merge(poll); - - getPersistenceContext().commit(); - } - -} Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/VoterListService.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/VoterListService.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/VoterListService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,200 +0,0 @@ -package org.chorem.pollen.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 org.chorem.pollen.persistence.dao.VoterListJpaDao; -import org.chorem.pollen.persistence.dao.VoterListMemberJpaDao; -import org.chorem.pollen.persistence.entity.FavoriteList; -import org.chorem.pollen.persistence.entity.FavoriteListMember; -import org.chorem.pollen.persistence.entity.Poll; -import org.chorem.pollen.persistence.entity.VoterList; -import org.chorem.pollen.persistence.entity.VoterListMember; -import org.chorem.pollen.service.exception.EntityNotFoundException; - -import java.util.List; -import java.util.Set; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class VoterListService extends AbstractPollenService { - - public VoterList importFavoriteList(String pollId, - String favoriteListId) throws EntityNotFoundException { - Preconditions.checkNotNull(pollId); - Preconditions.checkNotNull(favoriteListId); - - Poll poll = getPollService().getPoll(pollId); - - FavoriteList favoriteList = getFavoriteListService().getFavoriteList(favoriteListId); - - VoterListJpaDao dao = getPersistenceContext().getVoterListDao(); - VoterList result = dao.newInstance(); - - result.setName(favoriteList.getName()); - result.setWeight(1d); - - VoterListMemberJpaDao voterListMemberDao = - getPersistenceContext().getVoterListMemberDao(); - - for (FavoriteListMember favoriteListMember : favoriteList.getFavoriteListMember()) { - - VoterListMember voterListMember = voterListMemberDao.newInstance(); - voterListMember.setWeight(1d); - voterListMember.setEmail(favoriteListMember.getEmail()); - result.addVoterListMember(voterListMember); - } - - poll.addVoterList(result); - - getPersistenceContext().getPollDao().merge(poll); - - getPersistenceContext().commit(); - return result; - } - - public List<VoterList> getVoterLists(String pollId) throws EntityNotFoundException{ - Preconditions.checkNotNull(pollId); - - Poll poll = getPollService().getPoll(pollId); - - List<VoterList> result = poll.getVoterList(); - return result; - } - - public VoterList getVoterList(String voterListId) throws EntityNotFoundException{ - Preconditions.checkNotNull(voterListId); - - VoterList result = getPersistenceContext().getVoterListDao().findById(voterListId); - checkEntityExists(VoterList.class, result, voterListId); - - return result; - } - - public VoterList addVoterList(String pollId, VoterList voterList) throws EntityNotFoundException{ - Preconditions.checkNotNull(pollId); - Preconditions.checkNotNull(voterList); - checkHasNoId(voterList); - - Poll poll = getPollService().getPoll(pollId); - - poll.addVoterList(voterList); - - getPersistenceContext().getPollDao().merge(poll); - getPersistenceContext().commit(); - VoterList result = getVoterList(voterList.getId()); - return result; - } - - public VoterList editVoterList(VoterList voterList) throws EntityNotFoundException{ - Preconditions.checkNotNull(voterList); - checkHasId(voterList); - - getVoterList(voterList.getId()); - - getPersistenceContext().getVoterListDao().merge(voterList); - getPersistenceContext().commit(); - VoterList result = getVoterList(voterList.getId()); - return result; - } - - public void deleteVoterList(String pollId, String voterListId) throws EntityNotFoundException{ - Preconditions.checkNotNull(pollId); - Preconditions.checkNotNull(voterListId); - - Poll poll = getPollService().getPoll(pollId); - - VoterList voterList = getVoterList(voterListId); - - poll.removeVoterList(voterList); - - getPersistenceContext().getPollDao().merge(poll); - - getPersistenceContext().commit(); - } - - public Set<VoterListMember> getMembers(String voterListId) throws EntityNotFoundException{ - Preconditions.checkNotNull(voterListId); - - VoterList voterList = getVoterList(voterListId); - - Set<VoterListMember> result = voterList.getVoterListMember(); - return result; - } - - public VoterListMember getMember(String memberId) throws EntityNotFoundException{ - Preconditions.checkNotNull(memberId); - - VoterListMember result = getPersistenceContext().getVoterListMemberDao().findById(memberId); - checkEntityExists(VoterListMember.class, result, memberId); - return result; - } - - public VoterListMember addMember(String voterListId, VoterListMember member)throws EntityNotFoundException { - Preconditions.checkNotNull(voterListId); - Preconditions.checkNotNull(member); - checkHasNoId(member); - - VoterList voterList = getVoterList(voterListId); - - voterList.addVoterListMember(member); - getPersistenceContext().getVoterListDao().merge(voterList); - - getPersistenceContext().commit(); - VoterListMember result = getMember(member.getId()); - return result; - } - - public VoterListMember editMember(VoterListMember member) throws EntityNotFoundException{ - Preconditions.checkNotNull(member); - checkHasId(member); - - getMember(member.getId()); - - getPersistenceContext().getVoterListMemberDao().merge(member); - - getPersistenceContext().commit(); - VoterListMember result = getMember(member.getId()); - return result; - } - - public void deleteMember(String voterListId, String memberId) throws EntityNotFoundException{ - Preconditions.checkNotNull(voterListId); - Preconditions.checkNotNull(memberId); - - VoterList voterList = getVoterList(voterListId); - - VoterListMember member = getMember(memberId); - voterList.removeVoterListMember(member); - - getPersistenceContext().getVoterListDao().merge(voterList); - - getPersistenceContext().commit(); - } - -} Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/package-info.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/package-info.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/package-info.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,30 +0,0 @@ -/** - * Base Package for the pollen business service. - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -package org.chorem.pollen.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% - */ Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java (from rev 3821, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/DefaultPollenServiceContext.java) =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,188 @@ +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.commons.lang3.RandomStringUtils; +import org.chorem.pollen.persistence.PollenEntityIdFactory; +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.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.UserService; +import org.chorem.pollen.services.service.VoteCountingService; +import org.chorem.pollen.services.service.VoteService; +import org.chorem.pollen.services.service.VoterListService; +import org.nuiton.util.StringUtil; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Date; +import java.util.Locale; + +public class DefaultPollenServiceContext implements PollenServiceContext { + + protected PollenServiceConfig pollenServiceConfig; + + protected PollenPersistenceContext persistenceContext; + + protected Locale locale; + + public void setPollenServiceConfig(PollenServiceConfig pollenServiceConfig) { + this.pollenServiceConfig = pollenServiceConfig; + } + + public void setPersistenceContext(PollenPersistenceContext persistenceContext) { + this.persistenceContext = persistenceContext; + } + + public void setLocale(Locale locale) { + this.locale = locale; + } + + @Override + public PollenServiceConfig getPollenServiceConfig() { + return pollenServiceConfig; + } + + @Override + public String generateToken() { + return PollenEntityIdFactory.generateId(); + } + + @Override + public Date getNow() { + Date now = new Date(); + return now; + } + + public String generatePassword() { + return RandomStringUtils.randomAlphanumeric(8); + } + + @Override + public PollenPersistenceContext getPersistenceContext() { + return persistenceContext; + } + + @Override + public AuthService getAuthService() { + return newService(AuthService.class); + } + + @Override + public CommentService getCommentService() { + return newService(CommentService.class); + } + + @Override + public FavoriteListService getFavoriteListService() { + return newService(FavoriteListService.class); + } + + @Override + public PollService getPollService() { + return newService(PollService.class); + } + + @Override + public UserService getUserService() { + return newService(UserService.class); + } + + @Override + public VoteCountingService getVoteCountingService() { + return newService(VoteCountingService.class); + } + + @Override + public VoterListService getVoterListService() { + return newService(VoterListService.class); + } + + @Override + public VoteService getVoteService() { + return newService(VoteService.class); + } + + @Override + public EmailService getEmailService() { + return newService(EmailService.class); + } + + @Override + public FixturesService getFixturesService() { + return newService(FixturesService.class); + } + + @Override + public String encodePassword(String password) { + return StringUtil.encodeMD5(password); + } + + @Override + public Locale getLocale() { + if (locale==null) { + locale = Locale.getDefault(); + } + return locale; + } + + public <E extends PollenServiceSupport> E newService(Class<E> serviceClass) { + + E service; + + try { + + Constructor<E> constructor = serviceClass.getConstructor(); + + service = constructor.newInstance(); + + } catch (NoSuchMethodException e) { + + throw new PollenTechnicalException("all services must provide a default public constructor", e); + + } catch (InvocationTargetException e) { + + throw new PollenTechnicalException("unable to instantiate pollen service", e); + + } catch (InstantiationException e) { + + throw new PollenTechnicalException("unable to instantiate pollen service", e); + + } catch (IllegalAccessException e) { + + throw new PollenTechnicalException("unable to instantiate pollen service", e); + } + + service.setServiceContext(this); + + return service; + + } + +} Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollResult.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollResult.java) =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollResult.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollResult.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,36 @@ +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 java.io.Serializable; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollResult implements Serializable { + private static final long serialVersionUID = 1L; +} Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenFixtures.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollenFixtures.java) =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenFixtures.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenFixtures.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,78 @@ +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.esotericsoftware.yamlbeans.YamlException; +import com.esotericsoftware.yamlbeans.YamlReader; +import org.apache.commons.io.Charsets; +import org.apache.commons.io.IOUtils; +import org.chorem.pollen.persistence.entity.Choice; +import org.chorem.pollen.persistence.entity.Comment; +import org.chorem.pollen.persistence.entity.FavoriteList; +import org.chorem.pollen.persistence.entity.FavoriteListMember; +import org.chorem.pollen.persistence.entity.Poll; +import org.chorem.pollen.persistence.entity.PollenUser; +import org.chorem.pollen.persistence.entity.Vote; +import org.chorem.pollen.persistence.entity.VoterList; +import org.chorem.pollen.persistence.entity.VoterListMember; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; + +public class PollenFixtures { + + protected Map<String, Object> fixtures; + + public PollenFixtures(String fixturesName) { + String yamlPath = "/" + fixturesName + ".yaml"; + InputStream inputStream = PollenFixtures.class.getResourceAsStream(yamlPath); + String yaml; + try { + yaml = IOUtils.toString(inputStream, Charsets.UTF_8); + } catch (IOException e) { + throw new IllegalArgumentException(fixturesName + " is not a valid fixtures set name", e); + } + YamlReader reader = new YamlReader(yaml); + reader.getConfig().setClassTag("poll", Poll.class); + reader.getConfig().setClassTag("user", PollenUser.class); + reader.getConfig().setClassTag("favorite-list", FavoriteList.class); + reader.getConfig().setClassTag("favorite-list-member", FavoriteListMember.class); + reader.getConfig().setClassTag("comment", Comment.class); + reader.getConfig().setClassTag("choice", Choice.class); + reader.getConfig().setClassTag("voter-list", VoterList.class); + reader.getConfig().setClassTag("voter-list-member", VoterListMember.class); + reader.getConfig().setClassTag("vote", Vote.class); + + try { + fixtures = (Map<String, Object>) reader.read(); + } catch (YamlException e) { + throw new PollenTechnicalException("unable to read yaml file", e); + } + } + + public <E> E fixture(String id) { + return (E) fixtures.get(id); + } +} Added: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,10 @@ +package org.chorem.pollen.services; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollenSecurityContext { +} Property changes on: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java (from rev 3821, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollenServiceContext.java) =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,81 @@ +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.chorem.pollen.persistence.PollenPersistenceContext; +import org.chorem.pollen.services.config.PollenServiceConfig; +import org.chorem.pollen.services.service.AuthService; +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.UserService; +import org.chorem.pollen.services.service.VoteCountingService; +import org.chorem.pollen.services.service.VoteService; +import org.chorem.pollen.services.service.VoterListService; + +import java.util.Date; +import java.util.Locale; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public interface PollenServiceContext { + + String generateToken(); + + Date getNow(); + + PollenPersistenceContext getPersistenceContext(); + + PollenServiceConfig getPollenServiceConfig(); + + AuthService getAuthService(); + + CommentService getCommentService(); + + FavoriteListService getFavoriteListService(); + + PollService getPollService(); + + UserService getUserService(); + + VoteCountingService getVoteCountingService(); + + VoterListService getVoterListService(); + + VoteService getVoteService(); + + EmailService getEmailService(); + + FixturesService getFixturesService(); + + String generatePassword(); + + String encodePassword(String password); + + Locale getLocale(); +} Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollenServiceSupport.java) =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,35 @@ +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% + */ + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public interface PollenServiceSupport { + + void setServiceContext(PollenServiceContext serviceContext); +} Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenTechnicalException.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollenTechnicalException.java) =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenTechnicalException.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenTechnicalException.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,44 @@ +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% + */ + +public class PollenTechnicalException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + public PollenTechnicalException() { + } + + public PollenTechnicalException(String message) { + super(message); + } + + public PollenTechnicalException(String message, Throwable cause) { + super(message, cause); + } + + public PollenTechnicalException(Throwable cause) { + super(cause); + } +} Modified: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/config/PollenServiceConfig.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,4 +1,4 @@ -package org.chorem.pollen.service.config; +package org.chorem.pollen.services.config; /* * #%L @@ -27,7 +27,7 @@ import com.google.common.collect.Maps; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.service.PollenTechnicalException; +import org.chorem.pollen.services.PollenTechnicalException; import org.nuiton.util.config.ApplicationConfig; import org.nuiton.util.config.ArgumentsParserException; Modified: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/config/PollenServiceConfigOption.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,4 +1,4 @@ -package org.chorem.pollen.service.config; +package org.chorem.pollen.services.config; /* * #%L Modified: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/config/package-info.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/config/package-info.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/config/package-info.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -4,7 +4,7 @@ * @author tchemit <chemit@codelutin.com> * @since 2.0 */ -package org.chorem.pollen.service.config; +package org.chorem.pollen.services.config; /* * #%L Modified: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/EntityNotFoundException.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/exception/EntityNotFoundException.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/EntityNotFoundException.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,4 +1,4 @@ -package org.chorem.pollen.service.exception; +package org.chorem.pollen.services.exception; /* * #%L Added: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListImportException.java =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListImportException.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListImportException.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,30 @@ +package org.chorem.pollen.services.exception; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class FavoriteListImportException extends Exception { + + private static final long serialVersionUID = 1L; + + + private String causeMessage; + + public FavoriteListImportException(String causeMessage, Throwable cause) { + super(cause); + this.causeMessage = causeMessage; + } + + public FavoriteListImportException(Throwable cause) { + this(cause.getMessage(), cause); + } + + /** @return the error message source from import execution. */ + public String getCauseMessage() { + return causeMessage; + } + +} Property changes on: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListImportException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,22 @@ +package org.chorem.pollen.services.exception; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class FavoriteListMemberEmailAlreadyUsedException extends Exception { + + private static final long serialVersionUID = 1L; + + protected final String email; + + public FavoriteListMemberEmailAlreadyUsedException(String email) { + this.email = email; + } + + public String getEmail() { + return email; + } +} \ No newline at end of file Property changes on: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,22 @@ +package org.chorem.pollen.services.exception; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class FavoriteListMemberNameAlreadyUsedException extends Exception { + + private static final long serialVersionUID = 1L; + + protected final String name; + + public FavoriteListMemberNameAlreadyUsedException(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} \ No newline at end of file Property changes on: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,11 @@ +package org.chorem.pollen.services.exception; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class FavoriteListMemberNotOwnedByFavoriteListException extends Throwable { + private static final long serialVersionUID = 1L; +} Property changes on: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,22 @@ +package org.chorem.pollen.services.exception; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class FavoriteListNameAlreadyUsedException extends Exception { + + private static final long serialVersionUID = 1L; + + protected final String name; + + public FavoriteListNameAlreadyUsedException(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} \ No newline at end of file Property changes on: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,12 @@ +package org.chorem.pollen.services.exception; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class FavoriteListNotOwnedByUserException extends Exception { + private static final long serialVersionUID = 1L; + +} Property changes on: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidSessionTokenException.java =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidSessionTokenException.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidSessionTokenException.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,12 @@ +package org.chorem.pollen.services.exception; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class InvalidSessionTokenException extends Exception { + + private static final long serialVersionUID = 1L; +} Property changes on: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidSessionTokenException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserEmailAlreadyUsedException.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/exception/UserEmailAlreadyUsedException.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserEmailAlreadyUsedException.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,4 +1,4 @@ -package org.chorem.pollen.service.exception; +package org.chorem.pollen.services.exception; /* * #%L Modified: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserInvalidEmailActiviationTokenException.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/exception/UserInvalidEmailActiviationTokenException.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserInvalidEmailActiviationTokenException.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,4 +1,4 @@ -package org.chorem.pollen.service.exception; +package org.chorem.pollen.services.exception; /* * #%L Modified: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserInvalidPasswordException.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/exception/UserInvalidPasswordException.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserInvalidPasswordException.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,4 +1,4 @@ -package org.chorem.pollen.service.exception; +package org.chorem.pollen.services.exception; /* * #%L Modified: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserLoginAlreadyUsedException.java =================================================================== --- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/exception/UserLoginAlreadyUsedException.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserLoginAlreadyUsedException.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,4 +1,4 @@ -package org.chorem.pollen.service.exception; +package org.chorem.pollen.services.exception; /* * #%L Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/package-info.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/package-info.java) =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/package-info.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/package-info.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,30 @@ +/** + * Base Package for the pollen business service. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +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% + */ Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java (from rev 3821, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/AbstractPollenService.java) =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,119 @@ +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 org.chorem.pollen.persistence.PollenPersistenceContext; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.PollenServiceSupport; +import org.chorem.pollen.services.config.PollenServiceConfig; +import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.nuiton.jpa.api.JpaEntities; +import org.nuiton.jpa.api.JpaEntity; + +import java.util.Date; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public abstract class AbstractPollenService implements PollenServiceSupport { + + protected PollenServiceContext serviceContext; + + protected void checkHasId(JpaEntity entity) { + Preconditions.checkState(JpaEntities.isEntityHasId(entity)); + } + + protected void checkHasNoId(JpaEntity entity) { + Preconditions.checkState(JpaEntities.isEntityHasNoId(entity)); + } + + @Override + public void setServiceContext(PollenServiceContext serviceContext) { + this.serviceContext = serviceContext; + } + + protected Date getNow() { + return serviceContext.getNow(); + } + + protected String generateToken() { + return serviceContext.generateToken(); + } + + protected PollenPersistenceContext getPersistenceContext() { + return serviceContext.getPersistenceContext(); + } + + protected PollenServiceConfig getPollenServiceConfig() { + return serviceContext.getPollenServiceConfig(); + } + + protected AuthService getAuthService() { + return serviceContext.getAuthService(); + } + + protected CommentService getCommentService() { + return serviceContext.getCommentService(); + } + + protected FavoriteListService getFavoriteListService() { + return serviceContext.getFavoriteListService(); + } + + protected PollService getPollService() { + return serviceContext.getPollService(); + } + + protected UserService getUserService() { + return serviceContext.getUserService(); + } + + protected VoteCountingService getVoteCountingService() { + return serviceContext.getVoteCountingService(); + } + + protected VoterListService getVoterListService() { + return serviceContext.getVoterListService(); + } + + protected VoteService getVoteService() { + return serviceContext.getVoteService(); + } + + protected EmailService getEmailService() { + return serviceContext.getEmailService(); + } + + protected <E extends JpaEntity> void checkEntityExists(Class<E> type, + E entity, + String entityId) throws EntityNotFoundException { + if (entity == null) { + throw new EntityNotFoundException(type, entityId); + } + } +} Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/AuthService.java (from rev 3821, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/AuthService.java) =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/AuthService.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/AuthService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,127 @@ +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 org.chorem.pollen.persistence.dao.PollenUserJpaDao; +import org.chorem.pollen.persistence.dao.SessionTokenJpaDao; +import org.chorem.pollen.persistence.entity.PollenUser; +import org.chorem.pollen.persistence.entity.SessionToken; +import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.chorem.pollen.services.exception.InvalidSessionTokenException; +import org.chorem.pollen.services.exception.UserInvalidPasswordException; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class AuthService extends AbstractPollenService { + + public String login(String login, String password) throws EntityNotFoundException, UserInvalidPasswordException { + Preconditions.checkNotNull(login); + Preconditions.checkNotNull(password); + + PollenUser user = getPersistenceContext().getPollenUserDao().findByLogin(login); + if (user == null) { + throw new EntityNotFoundException(PollenUser.class, login); + } + + String encodedPassword = serviceContext.encodePassword(password); + if (!encodedPassword.equals(user.getPassword())) { + throw new UserInvalidPasswordException(); + } + + // Create a new session Token + SessionTokenJpaDao dao = getPersistenceContext().getSessionTokenDao(); + + SessionToken sessionToken = dao.newInstance(); + String token = serviceContext.generateToken(); + String encodedToken = serviceContext.encodePassword(token); + sessionToken.setPollenUser(user); + sessionToken.setToken(encodedToken); + sessionToken.setCreationDate(serviceContext.getNow()); + + dao.persist(sessionToken); + getPersistenceContext().commit(); + + return token; + } + + public void lostPassword(String login) throws EntityNotFoundException { + Preconditions.checkNotNull(login); + + PollenUserJpaDao dao = getPersistenceContext().getPollenUserDao(); + + PollenUser user = dao.findByLogin(login); + if (user == null) { + throw new EntityNotFoundException(PollenUser.class, login); + } + + // Generate a new password + String newPassword = serviceContext.generatePassword(); + String encodedPassword = serviceContext.encodePassword(newPassword); + user.setPassword(encodedPassword); + dao.merge(user); + getPersistenceContext().commit(); + + notifyPasswordChanged(user, newPassword); + } + + public void logout(String login, String token) throws EntityNotFoundException { + Preconditions.checkNotNull(login); + Preconditions.checkNotNull(token); + PollenUser user = getPersistenceContext().getPollenUserDao().findByLogin(login); + if (user == null) { + throw new EntityNotFoundException(PollenUser.class, login); + } + + String encodedToken = serviceContext.encodePassword(token); + + SessionTokenJpaDao dao = getPersistenceContext().getSessionTokenDao(); + + SessionToken sessionToken = dao.findByToken(encodedToken); + if (sessionToken == null) { + throw new EntityNotFoundException(SessionToken.class, token); + } + + dao.remove(sessionToken); + getPersistenceContext().commit(); + } + + public SessionToken getUserByAuth(String authParam) throws InvalidSessionTokenException { + + SessionToken sessionToken = getPersistenceContext().getSessionTokenDao().findByToken(authParam); + if (sessionToken == null) { + throw new InvalidSessionTokenException(); + } + + return sessionToken; + } + + protected void notifyPasswordChanged(PollenUser user, String newPassword) { + //TODO + } +} Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/CommentService.java) =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,94 @@ +package org.chorem.pollen.services.service; + +/* + * #%L + * Pollen :: Service 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.chorem.pollen.persistence.entity.Comment; +import org.chorem.pollen.persistence.entity.Poll; +import org.chorem.pollen.services.exception.EntityNotFoundException; + +import java.util.List; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class CommentService extends AbstractPollenService { + + public List<Comment> getComments(String pollId) throws EntityNotFoundException { + Preconditions.checkNotNull(pollId); + Poll poll = getPollService().getPoll(pollId); + return poll.getComment(); + } + + public Comment getComment(String commentId) throws EntityNotFoundException { + Preconditions.checkNotNull(commentId); + Comment result = getPersistenceContext().getCommentDao().findById(commentId); + checkEntityExists(Comment.class, result, commentId); + return result; + } + + public Comment addComment(String pollId, Comment comment) throws EntityNotFoundException { + Preconditions.checkNotNull(pollId); + checkHasNoId(comment); + Poll poll = getPollService().getPoll(pollId); + + poll.addComment(comment); + getPersistenceContext().getPollDao().merge(poll); + getPersistenceContext().commit(); + + Comment result = getComment(comment.getId()); + return result; + } + + public Comment editComment(Comment comment) throws EntityNotFoundException { + + // check comment exists + getComment(comment.getId()); + + getPersistenceContext().getCommentDao().merge(comment); + getPersistenceContext().commit(); + + Comment result = getComment(comment.getId()); + return result; + } + + public void deleteComment(String pollId, String commentId) throws EntityNotFoundException { + Preconditions.checkNotNull(pollId); + Preconditions.checkNotNull(commentId); + Poll poll = getPollService().getPoll(pollId); + + Comment comment = getComment(commentId); + Preconditions.checkNotNull(comment); + + poll.removeComment(comment); + + getPersistenceContext().getPollDao().merge(poll); + + getPersistenceContext().commit(); + } + +} Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/EmailService.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/EmailService.java) =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/EmailService.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/EmailService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,39 @@ +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.entity.PollenUser; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class EmailService extends AbstractPollenService { + + public void onUserCreated(PollenUser user) { + //TODO + } +} Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/FavoriteListService.java) =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,547 @@ +package org.chorem.pollen.services.service; + +/* + * #%L + * Pollen :: Service 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 com.google.common.collect.Sets; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; +import org.chorem.pollen.persistence.entity.FavoriteList; +import org.chorem.pollen.persistence.entity.FavoriteListMember; +import org.chorem.pollen.persistence.entity.PollenUser; +import org.chorem.pollen.services.PollenTechnicalException; +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.nuiton.util.StringUtil; + +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.directory.Attribute; +import javax.naming.directory.DirContext; +import javax.naming.directory.InitialDirContext; +import javax.naming.directory.SearchControls; +import javax.naming.directory.SearchResult; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.List; +import java.util.Locale; +import java.util.Properties; +import java.util.Set; + +import static org.nuiton.i18n.I18n.l_; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class FavoriteListService extends AbstractPollenService { + + public List<FavoriteList> getFavoriteLists(String userId) throws EntityNotFoundException { + Preconditions.checkNotNull(userId); + PollenUser user = getUserService().getUser(userId); + + List<FavoriteList> result = user.getFavoriteList(); + return result; + } + + public FavoriteList getFavoriteList(String favoriteListId) throws EntityNotFoundException { + Preconditions.checkNotNull(favoriteListId); + FavoriteList result = getPersistenceContext().getFavoriteListDao().findById(favoriteListId); + checkEntityExists(FavoriteList.class, result, favoriteListId); + return result; + } + + public FavoriteList createFavoriteList(String userId, + FavoriteList favoriteList) throws EntityNotFoundException, FavoriteListNameAlreadyUsedException { + Preconditions.checkNotNull(userId); + Preconditions.checkNotNull(favoriteList); + checkHasNoId(favoriteList); + + String favoriteListName = favoriteList.getName(); + + // can't accept favorite list without name + Preconditions.checkArgument(StringUtils.isNotEmpty(favoriteListName)); + + PollenUser user = getUserService().getUser(userId); + + // check there is not already a favorite list with same name + boolean nameFound = false; + if (!user.isFavoriteListEmpty()) { + for (FavoriteList list : user.getFavoriteList()) { + if (favoriteListName.equals(list.getName())) { + nameFound = true; + break; + } + } + } + + if (nameFound) { + throw new FavoriteListNameAlreadyUsedException(favoriteListName); + } + + FavoriteList toSave = getPersistenceContext().getFavoriteListDao().newInstance(); + copyFavoriteList(favoriteList, toSave); + + user.addFavoriteList(toSave); + getPersistenceContext().getPollenUserDao().merge(user); + + getPersistenceContext().commit(); + return toSave; + } + + public FavoriteList editFavoriteList(String userId, + FavoriteList favoriteList) throws EntityNotFoundException, FavoriteListNameAlreadyUsedException, FavoriteListNotOwnedByUserException { + Preconditions.checkNotNull(favoriteList); + checkHasId(favoriteList); + + String favoriteListName = favoriteList.getName(); + + // can't accept favorite list without name + Preconditions.checkArgument(StringUtils.isNotEmpty(favoriteListName)); + + // get user + PollenUser user = getUserService().getUser(userId); + + // get list + FavoriteList toSave = getFavoriteList(favoriteList.getId()); + + // check user own this list + boolean ownedByUser = user.containsFavoriteListById(favoriteList.getId()); + + if (!ownedByUser) { + throw new FavoriteListNotOwnedByUserException(); + } + + if (ObjectUtils.notEqual(favoriteListName, toSave.getName())) { + + // check that this name is not existing in another list + boolean nameFound = false; + if (!user.isFavoriteListEmpty()) { + for (FavoriteList list : user.getFavoriteList()) { + if (toSave != list && + favoriteListName.equals(list.getName())) { + + // found another list with same name + nameFound = true; + break; + } + } + } + if (nameFound) { + throw new FavoriteListNameAlreadyUsedException(favoriteListName); + } + } + + copyFavoriteList(favoriteList, toSave); + getPersistenceContext().getFavoriteListDao().merge(toSave); + + getPersistenceContext().commit(); + return toSave; + } + + public void deleteFavoriteList(String userId, String favoriteListId) throws EntityNotFoundException, FavoriteListNotOwnedByUserException { + Preconditions.checkNotNull(userId); + Preconditions.checkNotNull(favoriteListId); + + PollenUser user = getUserService().getUser(userId); + + FavoriteList persisted = getFavoriteList(favoriteListId); + + // check user own this list + boolean ownedByUser = user.containsFavoriteListById(favoriteListId); + if (!ownedByUser) { + throw new FavoriteListNotOwnedByUserException(); + } + + user.removeFavoriteList(persisted); + getPersistenceContext().getPollenUserDao().merge(user); + + getPersistenceContext().commit(); + } + + public List<FavoriteListMember> getFavoriteListMembers(String favoriteListId) throws EntityNotFoundException { + Preconditions.checkNotNull(favoriteListId); + + FavoriteList favoriteList = getFavoriteList(favoriteListId); + + return favoriteList.getFavoriteListMember(); + } + + public FavoriteListMember getFavoriteListMember(String memberId) throws EntityNotFoundException { + Preconditions.checkNotNull(memberId); + FavoriteListMember result = getPersistenceContext().getFavoriteListMemberDao().findById(memberId); + checkEntityExists(FavoriteListMember.class, result, memberId); + return result; + } + + public FavoriteListMember addFavoriteListMember(String favoriteListId, + FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberNameAlreadyUsedException, FavoriteListMemberEmailAlreadyUsedException { + Preconditions.checkNotNull(favoriteListId); + Preconditions.checkNotNull(member); + checkHasNoId(member); + + // can't accept member without name + String memberName = member.getName(); + Preconditions.checkArgument(StringUtils.isNotEmpty(memberName)); + + // can't accept member without email + String memberEmail = member.getEmail(); + Preconditions.checkArgument(StringUtils.isNotEmpty(memberEmail)); + + // lowerCase email + memberEmail = StringUtils.lowerCase(memberEmail); + + //TODO Validate email form + + FavoriteList favoriteList = getFavoriteList(favoriteListId); + + if (!favoriteList.isFavoriteListMemberEmpty()) { + + for (FavoriteListMember listMember : favoriteList.getFavoriteListMember()) { + + // check there is no other member with same name + if (memberName.equals(listMember.getName())) { + throw new FavoriteListMemberNameAlreadyUsedException(memberName); + } + // check there is no other member with same email + if (memberEmail.equals(listMember.getEmail())) { + throw new FavoriteListMemberEmailAlreadyUsedException(memberEmail); + } + } + } + + FavoriteListMember newMember = + getPersistenceContext().getFavoriteListMemberDao().newInstance(); + copyFavoriteListMember(member, newMember); + favoriteList.addFavoriteListMember(newMember); + + getPersistenceContext().getFavoriteListDao().merge(favoriteList); + + getPersistenceContext().commit(); + return newMember; + } + + public FavoriteListMember editFavoriteListMember(String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException, FavoriteListMemberNameAlreadyUsedException, FavoriteListMemberEmailAlreadyUsedException { + Preconditions.checkNotNull(member); + checkHasId(member); + + // can't accept member without name + String memberName = member.getName(); + Preconditions.checkArgument(StringUtils.isNotEmpty(memberName)); + + // can't accept member without email + String memberEmail = member.getEmail(); + Preconditions.checkArgument(StringUtils.isNotEmpty(memberEmail)); + + // lowerCase email + memberEmail = StringUtils.lowerCase(memberEmail); + + //TODO Validate email form + + FavoriteList favoriteList = getFavoriteList(favoriteListId); + + String memberId = member.getId(); + + FavoriteListMember toSave = getFavoriteListMember(memberId); + + // check favorite list own this member + boolean ownedByUser = favoriteList.containsFavoriteListMemberById(memberId); + if (!ownedByUser) { + throw new FavoriteListMemberNotOwnedByFavoriteListException(); + } + + + if (!memberName.equals(toSave.getName())) { + + // name has changed must check name is available in the list + for (FavoriteListMember listMember : favoriteList.getFavoriteListMember()) { + + // check there is no other member with same name + if (!memberId.equals(listMember.getId()) && + memberName.equals(listMember.getName())) { + throw new FavoriteListMemberNameAlreadyUsedException(memberName); + } + } + } + + if (!memberEmail.equals(toSave.getEmail())) { + + // email has changed must check name is available in the list + for (FavoriteListMember listMember : favoriteList.getFavoriteListMember()) { + + if (!memberId.equals(listMember.getId()) && + memberEmail.equals(listMember.getEmail())) { + throw new FavoriteListMemberEmailAlreadyUsedException(memberEmail); + } + } + } + copyFavoriteListMember(member, toSave); + + getPersistenceContext().getFavoriteListMemberDao().merge(toSave); + + getPersistenceContext().commit(); + return toSave; + } + + public void removeFavoriteListMember(String favoriteListId, String memberId) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException { + Preconditions.checkNotNull(favoriteListId); + Preconditions.checkNotNull(memberId); + + FavoriteList favoriteList = getFavoriteList(favoriteListId); + + FavoriteListMember member = getFavoriteListMember(memberId); + + // check favorite list own this member + boolean ownedByUser = favoriteList.containsFavoriteListMemberById(memberId); + if (!ownedByUser) { + throw new FavoriteListMemberNotOwnedByFavoriteListException(); + } + + favoriteList.removeFavoriteListMember(member); + + getPersistenceContext().getFavoriteListDao().merge(favoriteList); + getPersistenceContext().commit(); + } + + public int importFavoriteListMembersFromCsv(String userId, String favoriteListId, + File file) throws EntityNotFoundException, FavoriteListImportException, FavoriteListNotOwnedByUserException { + Preconditions.checkNotNull(userId); + Preconditions.checkNotNull(favoriteListId); + Preconditions.checkNotNull(file); + + PollenUser user = getUserService().getUser(userId); + + FavoriteList favoriteList = getFavoriteList(favoriteListId); + + // check user own this list + boolean ownedByUser = user.containsFavoriteListById(favoriteListId); + if (!ownedByUser) { + throw new FavoriteListNotOwnedByUserException(); + } + + Locale locale = serviceContext.getLocale(); + + Set<String> usedName = Sets.newHashSet(); + Set<String> usedEmail = Sets.newHashSet(); + + if (!favoriteList.isFavoriteListMemberEmpty()) { + for (FavoriteListMember member : favoriteList.getFavoriteListMember()) { + usedName.add(member.getName()); + usedEmail.add(member.getEmail()); + } + } + + int result = 0; + BufferedReader reader = null; + try { + reader = new BufferedReader(new FileReader(file)); + String line; + int lineNumber = 0; + while ((line = reader.readLine()) != null) { + line = line.trim(); + if (StringUtils.isBlank(line) || line.startsWith("#")) { + + // comment line + continue; + } + lineNumber++; + result++; + + int spaceIndex = line.indexOf(' '); + String email; + String memberName; + if (spaceIndex == -1) { + // only email + email = line; + memberName = line; + } else { + // email + name + email = line.substring(0, spaceIndex); + memberName = line.substring(spaceIndex); + } + memberName = memberName.trim(); + + if (!usedName.add(memberName)) { + // name already exists + String error = l_(locale, "pollen.error.favoriteList.import.csv.already.used.name", lineNumber, memberName); + throw new FavoriteListImportException(error, null); + } + + email = email.toLowerCase().trim(); + if (!usedEmail.add(email)) { + // email already exists + String error = l_(locale, "pollen.error.favoriteList.import.csv.already.used.email", lineNumber, email); + throw new FavoriteListImportException(error, null); + } + + if (!StringUtil.isEmail(email)) { + + // email is not valid + String error = l_(locale, "pollen.error.favoriteList.import.csv.invalid.email", lineNumber, email); + throw new FavoriteListImportException(error, null); + } + + FavoriteListMember member = getPersistenceContext().getFavoriteListMemberDao().newInstance(); + member.setName(memberName); + member.setEmail(email); + + favoriteList.addFavoriteListMember(member); + } + + reader.close(); + + } catch (FileNotFoundException e) { + // should never happens ? + throw new PollenTechnicalException(e); + } catch (IOException e) { + // should never happens ? + throw new PollenTechnicalException(e); + } finally { + IOUtils.closeQuietly(reader); + } + + getPersistenceContext().getFavoriteListDao().merge(favoriteList); + + getPersistenceContext().commit(); + + return result; + } + + public int importFavoriteListMembersFromLdap(String userId, + String favoriteListId, + String ldap) throws EntityNotFoundException, FavoriteListImportException, FavoriteListNotOwnedByUserException { + Preconditions.checkNotNull(favoriteListId); + Preconditions.checkNotNull(ldap); + + PollenUser user = getUserService().getUser(userId); + + FavoriteList favoriteList = getFavoriteList(favoriteListId); + + // check user own this list + boolean ownedByUser = user.containsFavoriteListById(favoriteListId); + if (!ownedByUser) { + throw new FavoriteListNotOwnedByUserException(); + } + + Locale locale = serviceContext.getLocale(); + + Set<String> usedName = Sets.newHashSet(); + Set<String> usedEmail = Sets.newHashSet(); + + if (!favoriteList.isFavoriteListMemberEmpty()) { + for (FavoriteListMember member : favoriteList.getFavoriteListMember()) { + usedName.add(member.getName()); + usedEmail.add(member.getEmail()); + } + } + + int result = 0; + + try { + + // Initialisation du contexte + Properties env = new Properties(); + + DirContext ictx = new InitialDirContext(env); + + // Recherche en profondeur + SearchControls control = new SearchControls(); + control.setSearchScope(SearchControls.SUBTREE_SCOPE); + + // Création des comptes avec les résultats de la recherche + NamingEnumeration<SearchResult> e = ictx.search(ldap, null, control); + while (e.hasMore()) { + SearchResult r = e.next(); + + Attribute attrName = r.getAttributes().get("cn"); + Attribute attrEmail = r.getAttributes().get("mail"); + + if (attrName != null) { + + result++; + + String memberName = attrName.get().toString().trim(); + + if (!usedName.add(memberName)) { + // name already exists + String error = l_(locale, "pollen.error.favoriteList.import.ldap.already.used.name", memberName); + throw new FavoriteListImportException(error, null); + } + + String email = attrEmail.get().toString().toLowerCase().trim(); + + if (!usedEmail.add(email)) { + // email already exists + String error = l_(locale, "pollen.error.favoriteList.import.ldap.already.used.email", email); + throw new FavoriteListImportException(error, null); + } + + if (!StringUtil.isEmail(email)) { + + // email is not valid + String error = l_(locale, "pollen.error.favoriteList.import.ldap.invalid.email", email); + throw new FavoriteListImportException(error, null); + } + + FavoriteListMember member = getPersistenceContext().getFavoriteListMemberDao().newInstance(); + member.setName(memberName); + member.setEmail(email); + + favoriteList.addFavoriteListMember(member); + } + } + } catch (NamingException ex) { + throw new FavoriteListImportException("LDAP", ex); + } + + getPersistenceContext().getFavoriteListDao().merge(favoriteList); + + getPersistenceContext().commit(); + return result; + } + + protected void copyFavoriteList(FavoriteList source, + FavoriteList destination) { + + destination.setName(source.getName()); + } + + protected void copyFavoriteListMember(FavoriteListMember source, + FavoriteListMember destination) { + + destination.setName(source.getName()); + destination.setEmail(StringUtils.lowerCase(source.getEmail())); + } +} Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/FixturesService.java) =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,101 @@ +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.Maps; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.persistence.PollenPersistenceContext; +import org.chorem.pollen.persistence.dao.PollenUserJpaDao; +import org.chorem.pollen.persistence.entity.PollenUser; +import org.chorem.pollen.services.PollenFixtures; + +import java.util.Collection; +import java.util.Map; + +public class FixturesService extends AbstractPollenService { + + private static final Log log = LogFactory.getLog(FixturesService.class); + + protected Map<String, PollenFixtures> fixtureSets = Maps.newHashMap(); + + public PollenFixtures cleanDatabaseAndLoadFixtures(String fixturesSetName) { + + return loadFixtures(fixturesSetName, true); + + } + + public PollenFixtures loadFixtures(String fixturesSetName) { + + return loadFixtures(fixturesSetName, false); + + } + + protected PollenFixtures loadFixtures(String fixturesSetName, boolean cleanDatabase) { + + boolean devMode = serviceContext.getPollenServiceConfig().isDevMode(); + + Preconditions.checkState(devMode); + + PollenFixtures fixtures = fixtureSets.get(fixturesSetName); + + if (fixtures == null) { + + fixtures = new PollenFixtures(fixturesSetName); + + fixtureSets.put(fixturesSetName, fixtures); + + if (log.isInfoEnabled()) { + log.info("will restore database with fixture set"); + } + + PollenPersistenceContext persistenceContext = serviceContext.getPersistenceContext(); + + if (cleanDatabase) { + + persistenceContext.clearDatabase(); + + } + + PollenUserJpaDao userDao = persistenceContext.getPollenUserDao(); + + Collection<PollenUser> users = fixtures.fixture("users"); + + for (PollenUser user : users) { + + user.setPassword(serviceContext.encodePassword(user.getPassword())); + userDao.persist(user); + } + + persistenceContext.commit(); + + + } + + return fixtures; + + } + +} Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java (from rev 3820, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollService.java) =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,205 @@ +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.Sets; +import org.chorem.pollen.persistence.entity.Choice; +import org.chorem.pollen.persistence.entity.Poll; +import org.chorem.pollen.persistence.entity.PollenUser; +import org.chorem.pollen.services.exception.EntityNotFoundException; + +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 AbstractPollenService { + + public Set<Poll> getCreatedPolls(String userId) throws EntityNotFoundException { + Preconditions.checkNotNull(userId); + + getUserService().getUser(userId); + + return getPersistenceContext().getPollDao().findAllCreated(userId); + } + + public Set<Poll> getInvitedPolls(String userId) throws EntityNotFoundException { + Preconditions.checkNotNull(userId); + + getUserService().getUser(userId); + + return getPersistenceContext().getPollDao().findAllInvited(userId); + } + + public Set<Poll> getParticipatedPolls(String userId) throws EntityNotFoundException { + Preconditions.checkNotNull(userId); + + getUserService().getUser(userId); + + return getPersistenceContext().getPollDao().findAllParticipated(userId); + } + + public Poll getPoll(String pollId) throws EntityNotFoundException { + Preconditions.checkNotNull(pollId); + Poll result = getPersistenceContext().getPollDao().findById(pollId); + checkEntityExists(Poll.class, result, pollId); + return result; + } + + public Poll createPoll(String userId, Poll poll) throws EntityNotFoundException { + Preconditions.checkNotNull(userId); + Preconditions.checkNotNull(poll); + checkHasNoId(poll); + + if (userId != null) { + + // get user + PollenUser user = getUserService().getUser(userId); + + // link it to creator + + } + + getPersistenceContext().getPollDao().persist(poll); + + getPersistenceContext().commit(); + return poll; + } + + public Poll editPoll(Poll poll) throws EntityNotFoundException { + Preconditions.checkNotNull(poll); + checkHasId(poll); + + getPoll(poll.getId()); + + getPersistenceContext().getPollDao().merge(poll); + getPersistenceContext().commit(); + + Poll result = getPoll(poll.getId()); + return result; + } + + public void deletePoll(String pollId) throws EntityNotFoundException { + Preconditions.checkNotNull(pollId); + + Poll poll = getPoll(pollId); + + getPersistenceContext().getPollDao().remove(poll); + getPersistenceContext().commit(); + } + + public Poll clonePoll(String pollId) throws EntityNotFoundException { + Preconditions.checkNotNull(pollId); + + Poll poll = getPoll(pollId); + //TODO + getPersistenceContext().commit(); + return null; + } + + public File closePoll(String pollId) throws EntityNotFoundException { + Preconditions.checkNotNull(pollId); + + Poll poll = getPoll(pollId); + //TODO + getPersistenceContext().commit(); + return null; + } + + public File exportPoll(String pollId) throws EntityNotFoundException { + Preconditions.checkNotNull(pollId); + Poll poll = getPoll(pollId); + //TODO + return null; + } + + public List<Choice> getChoices(String pollId) throws EntityNotFoundException { + Preconditions.checkNotNull(pollId); + + Poll poll = getPoll(pollId); + + return poll.getChoice(); + } + + public Choice getChoice(String choiceId) throws EntityNotFoundException { + Preconditions.checkNotNull(choiceId); + + Choice result = getPersistenceContext().getChoiceDao().findById(choiceId); + checkEntityExists(Choice.class, result, choiceId); + return result; + } + + public Choice addChoice(String pollId, Choice choice) throws EntityNotFoundException { + Preconditions.checkNotNull(pollId); + Preconditions.checkNotNull(choice); + checkHasNoId(choice); + + Poll poll = getPoll(pollId); + + poll.addChoice(choice); + + getPersistenceContext().getPollDao().merge(poll); + + getPersistenceContext().commit(); + Choice result = getChoice(choice.getId()); + return result; + } + + public Choice editChoice(Choice choice) throws EntityNotFoundException { + Preconditions.checkNotNull(choice); + checkHasId(choice); + + getChoice(choice.getId()); + + getPersistenceContext().getChoiceDao().merge(choice); + getPersistenceContext().commit(); + + Choice result = getChoice(choice.getId()); + return result; + } + + public void deleteChoice(String pollId, String choiceId) throws EntityNotFoundException { + Preconditions.checkNotNull(pollId); + Preconditions.checkNotNull(choiceId); + + Poll poll = getPoll(pollId); + Choice choice = getChoice(choiceId); + + poll.removeChoice(choice); + + getPersistenceContext().getPollDao().merge(poll); + + getPersistenceContext().commit(); + } + + public Set<Poll> getPolls(String userId) throws EntityNotFoundException { + return Sets.newHashSet(getPersistenceContext().getPollDao().findAll()); + } +} Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/UserService.java (from rev 3821, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/UserService.java) =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/UserService.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/UserService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,252 @@ +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 org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; +import org.chorem.pollen.persistence.dao.PollenUserJpaDao; +import org.chorem.pollen.persistence.entity.PollenUser; +import org.chorem.pollen.services.PollenServiceSupport; +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 java.util.List; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class UserService extends AbstractPollenService implements PollenServiceSupport { + + public List<PollenUser> getUsers() { + return getPollenUserDao().findAll(); + } + + public PollenUser getUser(String userId) throws EntityNotFoundException { + Preconditions.checkNotNull(userId); + + PollenUser result = getPollenUserDao().findById(userId); + checkEntityExists(PollenUser.class, result, userId); + return result; + } + + public PollenUser createUser(PollenUser user, boolean generatePassword) throws UserLoginAlreadyUsedException, UserEmailAlreadyUsedException { + Preconditions.checkNotNull(user); + checkHasNoId(user); + Preconditions.checkNotNull(user.getLogin()); + Preconditions.checkNotNull(user.getEmail()); + + PollenUserJpaDao dao = getPollenUserDao(); + + // check login is available + boolean loginExists = dao.loginExists(user.getLogin()); + if (loginExists) { + throw new UserLoginAlreadyUsedException(user.getLogin()); + } + + // check email is available + boolean emailExists = dao.emailExists(user.getEmail()); + if (emailExists) { + throw new UserEmailAlreadyUsedException(user.getEmail()); + } + + PollenUser toCreate = dao.newInstance(); + + // add a emailValidationToken + String emailValidationToken = generateToken(); + + String password; + if (generatePassword) { + // let's generate the new password + password = serviceContext.generatePassword(); + } else { + password = user.getPassword(); + } + + // encode the password + String encodedPassword = serviceContext.encodePassword(password); + + toCreate.setLogin(user.getLogin()); + toCreate.setEmailActivationToken(emailValidationToken); + toCreate.setPassword(encodedPassword); + + copyPollenUser(user, toCreate, true); + + dao.persist(toCreate); + getPersistenceContext().commit(); + + notifyUserCreated(toCreate); + + return toCreate; + } + + public PollenUser editUser(PollenUser user) throws UserInvalidPasswordException, UserEmailAlreadyUsedException, EntityNotFoundException { + Preconditions.checkNotNull(user); + checkHasId(user); + + PollenUser persisted = getUser(user.getId()); + + PollenUserJpaDao dao = getPollenUserDao(); + + // check current password + String encodedPassword = serviceContext.encodePassword(user.getPassword()); + if (!encodedPassword.equals(persisted.getPassword())) { + throw new UserInvalidPasswordException(); + } + + boolean emailChanged = ObjectUtils.notEqual(persisted.getEmail(), + user.getEmail()); + + if (emailChanged) { + + // check this email is not used by another user + boolean emailUsed = dao.emailExists(user.getEmail()); + if (emailUsed) { + throw new UserEmailAlreadyUsedException(user.getEmail()); + } + + // add a new emailValidationtoken + String emailValidationToken = generateToken(); + persisted.setEmailActivationToken(emailValidationToken); + } + + copyPollenUser(user, persisted, true); + + persisted = dao.merge(persisted); + getPersistenceContext().commit(); + + if (emailChanged) { + + notifyEmailChanged(persisted); + } + return persisted; + } + + public void changePassword(String userId, + String oldPassword, + String newPassword) throws UserInvalidPasswordException, EntityNotFoundException { + Preconditions.checkNotNull(userId); + Preconditions.checkNotNull(oldPassword); + Preconditions.checkNotNull(newPassword); + + PollenUser user = getUser(userId); + + // check current password + String encodedPassword = serviceContext.encodePassword(user.getPassword()); + if (!encodedPassword.equals(user.getPassword())) { + throw new UserInvalidPasswordException(); + } + + // encode new password and store it in user account + String newEncodedPassword = serviceContext.encodePassword(newPassword); + user.setPassword(newEncodedPassword); + + user = getPollenUserDao().merge(user); + getPersistenceContext().commit(); + + notifyPasswordChanged(user); + } + + public void validateUserEmail(String userId, + String token) throws EntityNotFoundException, UserInvalidEmailActiviationTokenException { + + Preconditions.checkNotNull(userId); + Preconditions.checkNotNull(token); + + PollenUser user = getUser(userId); + + Preconditions.checkNotNull(user); + + boolean valid = ObjectUtils.equals( + user.getEmailActivationToken(), token); + + if (!valid) { + throw new UserInvalidEmailActiviationTokenException(); + } + + // reset token in database + user.setEmailActivationToken(null); + + getPollenUserDao().merge(user); + getPersistenceContext().commit(); + } + + public void createDefaultUsers() throws UserEmailAlreadyUsedException, UserLoginAlreadyUsedException { + + PollenUser user = getPollenUserDao().newInstance(); + + user.setAdministrator(true); + String login = "admin"; + user.setLogin(login); + user.setEmail("admin@pollen.org"); + user.setPassword("admin"); + createUser(user, false); + } + + protected void notifyUserCreated(PollenUser user) { + + //TODO + } + + protected void notifyEmailChanged(PollenUser user) { + + //TODO + } + + protected void notifyPasswordChanged(PollenUser user) { + + //TODO + } + + protected PollenUserJpaDao getPollenUserDao() { + return getPersistenceContext().getPollenUserDao(); + } + + /** + * Copy {@code source} user account to {@code destination} one. + * The email is lower cased in the {@code destination} user account. + * + * @param source user account to copy + * @param destination which receive the copy + */ + protected void copyPollenUser(PollenUser source, + PollenUser destination, + boolean copyEmail) { + + destination.setAdministrator(source.isAdministrator()); + destination.setName(source.getName()); + destination.setLanguage(source.getLanguage()); + + if (copyEmail) { + // Don't keep case for email + destination.setEmail(StringUtils.lowerCase(source.getEmail())); + } + } +} Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingService.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/VoteCountingService.java) =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingService.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,46 @@ +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 org.chorem.pollen.persistence.entity.Poll; +import org.chorem.pollen.services.PollResult; +import org.chorem.pollen.services.exception.EntityNotFoundException; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class VoteCountingService extends AbstractPollenService { + + //GET /poll/{pollId}/results + public PollResult getResult(String pollId) throws EntityNotFoundException { + Preconditions.checkNotNull(pollId); + Poll poll = getPollService().getPoll(pollId); + //TODO + return null; + } +} Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/VoteService.java) =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,100 @@ +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 org.chorem.pollen.persistence.entity.Poll; +import org.chorem.pollen.persistence.entity.Vote; +import org.chorem.pollen.services.exception.EntityNotFoundException; + +import java.util.List; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class VoteService extends AbstractPollenService { + + public List<Vote> getVotes(String pollId) throws EntityNotFoundException { + Preconditions.checkNotNull(pollId); + + Poll poll = getPollService().getPoll(pollId); + List<Vote> result = poll.getVote(); + return result; + } + + public Vote getVote(String voteId) throws EntityNotFoundException{ + Preconditions.checkNotNull(voteId); + + Vote result = getPersistenceContext().getVoteDao().findById(voteId); + checkEntityExists(Vote.class, result, voteId); + return result; + } + + public Vote addVote(String pollId, Vote vote)throws EntityNotFoundException { + Preconditions.checkNotNull(pollId); + Preconditions.checkNotNull(vote); + checkHasNoId(vote); + + Poll poll = getPollService().getPoll(pollId); + + poll.addVote(vote); + getPersistenceContext().getPollDao().merge(poll); + + getPersistenceContext().commit(); + Vote result = getVote(vote.getId()); + return result; + } + + public Vote editVote(Vote vote)throws EntityNotFoundException { + Preconditions.checkNotNull(vote); + checkHasId(vote); + + getVote(vote.getId()); + + getPersistenceContext().getVoteDao().merge(vote); + getPersistenceContext().commit(); + + Vote result = getVote(vote.getId()); + return result; + } + + public void deleteVote(String pollId, String voteId)throws EntityNotFoundException { + Preconditions.checkNotNull(pollId); + Preconditions.checkNotNull(voteId); + + Poll poll = getPollService().getPoll(pollId); + + Vote vote = getVote(voteId); + + poll.removeVote(vote); + + getPersistenceContext().getPollDao().merge(poll); + + getPersistenceContext().commit(); + } + +} Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/VoterListService.java) =================================================================== --- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,200 @@ +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 org.chorem.pollen.persistence.dao.VoterListJpaDao; +import org.chorem.pollen.persistence.dao.VoterListMemberJpaDao; +import org.chorem.pollen.persistence.entity.FavoriteList; +import org.chorem.pollen.persistence.entity.FavoriteListMember; +import org.chorem.pollen.persistence.entity.Poll; +import org.chorem.pollen.persistence.entity.VoterList; +import org.chorem.pollen.persistence.entity.VoterListMember; +import org.chorem.pollen.services.exception.EntityNotFoundException; + +import java.util.List; +import java.util.Set; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class VoterListService extends AbstractPollenService { + + public VoterList importFavoriteList(String pollId, + String favoriteListId) throws EntityNotFoundException { + Preconditions.checkNotNull(pollId); + Preconditions.checkNotNull(favoriteListId); + + Poll poll = getPollService().getPoll(pollId); + + FavoriteList favoriteList = getFavoriteListService().getFavoriteList(favoriteListId); + + VoterListJpaDao dao = getPersistenceContext().getVoterListDao(); + VoterList result = dao.newInstance(); + + result.setName(favoriteList.getName()); + result.setWeight(1d); + + VoterListMemberJpaDao voterListMemberDao = + getPersistenceContext().getVoterListMemberDao(); + + for (FavoriteListMember favoriteListMember : favoriteList.getFavoriteListMember()) { + + VoterListMember voterListMember = voterListMemberDao.newInstance(); + voterListMember.setWeight(1d); + voterListMember.setEmail(favoriteListMember.getEmail()); + result.addVoterListMember(voterListMember); + } + + poll.addVoterList(result); + + getPersistenceContext().getPollDao().merge(poll); + + getPersistenceContext().commit(); + return result; + } + + public List<VoterList> getVoterLists(String pollId) throws EntityNotFoundException{ + Preconditions.checkNotNull(pollId); + + Poll poll = getPollService().getPoll(pollId); + + List<VoterList> result = poll.getVoterList(); + return result; + } + + public VoterList getVoterList(String voterListId) throws EntityNotFoundException{ + Preconditions.checkNotNull(voterListId); + + VoterList result = getPersistenceContext().getVoterListDao().findById(voterListId); + checkEntityExists(VoterList.class, result, voterListId); + + return result; + } + + public VoterList addVoterList(String pollId, VoterList voterList) throws EntityNotFoundException{ + Preconditions.checkNotNull(pollId); + Preconditions.checkNotNull(voterList); + checkHasNoId(voterList); + + Poll poll = getPollService().getPoll(pollId); + + poll.addVoterList(voterList); + + getPersistenceContext().getPollDao().merge(poll); + getPersistenceContext().commit(); + VoterList result = getVoterList(voterList.getId()); + return result; + } + + public VoterList editVoterList(VoterList voterList) throws EntityNotFoundException{ + Preconditions.checkNotNull(voterList); + checkHasId(voterList); + + getVoterList(voterList.getId()); + + getPersistenceContext().getVoterListDao().merge(voterList); + getPersistenceContext().commit(); + VoterList result = getVoterList(voterList.getId()); + return result; + } + + public void deleteVoterList(String pollId, String voterListId) throws EntityNotFoundException{ + Preconditions.checkNotNull(pollId); + Preconditions.checkNotNull(voterListId); + + Poll poll = getPollService().getPoll(pollId); + + VoterList voterList = getVoterList(voterListId); + + poll.removeVoterList(voterList); + + getPersistenceContext().getPollDao().merge(poll); + + getPersistenceContext().commit(); + } + + public Set<VoterListMember> getMembers(String voterListId) throws EntityNotFoundException{ + Preconditions.checkNotNull(voterListId); + + VoterList voterList = getVoterList(voterListId); + + Set<VoterListMember> result = voterList.getVoterListMember(); + return result; + } + + public VoterListMember getMember(String memberId) throws EntityNotFoundException{ + Preconditions.checkNotNull(memberId); + + VoterListMember result = getPersistenceContext().getVoterListMemberDao().findById(memberId); + checkEntityExists(VoterListMember.class, result, memberId); + return result; + } + + public VoterListMember addMember(String voterListId, VoterListMember member)throws EntityNotFoundException { + Preconditions.checkNotNull(voterListId); + Preconditions.checkNotNull(member); + checkHasNoId(member); + + VoterList voterList = getVoterList(voterListId); + + voterList.addVoterListMember(member); + getPersistenceContext().getVoterListDao().merge(voterList); + + getPersistenceContext().commit(); + VoterListMember result = getMember(member.getId()); + return result; + } + + public VoterListMember editMember(VoterListMember member) throws EntityNotFoundException{ + Preconditions.checkNotNull(member); + checkHasId(member); + + getMember(member.getId()); + + getPersistenceContext().getVoterListMemberDao().merge(member); + + getPersistenceContext().commit(); + VoterListMember result = getMember(member.getId()); + return result; + } + + public void deleteMember(String voterListId, String memberId) throws EntityNotFoundException{ + Preconditions.checkNotNull(voterListId); + Preconditions.checkNotNull(memberId); + + VoterList voterList = getVoterList(voterListId); + + VoterListMember member = getMember(memberId); + voterList.removeVoterListMember(member); + + getPersistenceContext().getVoterListDao().merge(voterList); + + getPersistenceContext().commit(); + } + +} Deleted: branches/pollen-2.0/pollen-services/src/main/resources/fixtures.yaml =================================================================== --- branches/pollen-2.0/pollen-service/src/main/resources/fixtures.yaml 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/main/resources/fixtures.yaml 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,31 +0,0 @@ -tony: - &tony !user - id: pollen_user_tony - login: tony - password: fake - name: T - email: tony@pollen.fake - administrator: false - -jean: - &jean !user - id: pollen_user_jean - login: jean - password: fake - name: J - email: jean@pollen.fake - administrator: true - -julien: - &julien !user - id: pollen_user_julien - login: julien - password: fake - name: J - email: julien@pollen.fake - administrator: true - -users: - - *tony - - *jean - - *julien \ No newline at end of file Copied: branches/pollen-2.0/pollen-services/src/main/resources/fixtures.yaml (from rev 3821, branches/pollen-2.0/pollen-service/src/main/resources/fixtures.yaml) =================================================================== --- branches/pollen-2.0/pollen-services/src/main/resources/fixtures.yaml (rev 0) +++ branches/pollen-2.0/pollen-services/src/main/resources/fixtures.yaml 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,28 @@ +tony: + &tony !user + login: tony + password: fake + name: T + email: tony@pollen.fake + administrator: false + +jean: + &jean !user + login: jean + password: fake + name: J + email: jean@pollen.fake + administrator: true + +julien: + &julien !user + login: julien + password: fake + name: J + email: julien@pollen.fake + administrator: true + +users: + - *tony + - *jean + - *julien \ No newline at end of file Deleted: branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java =================================================================== --- branches/pollen-2.0/pollen-service/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,114 +0,0 @@ -package org.chorem.pollen.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.JpaEntityIdFactoryIfNotEmpty; -import org.chorem.pollen.persistence.JpaPollenPersistenceContext; -import org.chorem.pollen.service.config.PollenServiceConfig; -import org.junit.Rule; -import org.nuiton.jpa.junit.JpaEntityManagerRule; - -import javax.persistence.EntityManager; -import java.util.Map; - -public abstract class AbstractPollenServiceTest { - - protected static final double DELTA = 0.0001; - - protected static PollenServiceConfig config; - - protected JpaEntityManagerRule jpaEntityManagerRule; - - protected FakePollenServiceContext serviceContext; - - protected PollenFixtures fixtures; - - protected static PollenServiceConfig getPollenServiceConfig() { - - if (config == null) { - - config = new PollenServiceConfig(); - } - - return config; - - } - - protected FakePollenServiceContext getServiceContext() { - - if (serviceContext == null) { - - synchronized (this) { - serviceContext = new FakePollenServiceContext(); - - serviceContext.setPollenServiceConfig(getPollenServiceConfig()); - - EntityManager entityManager = getJpaEntityManagerRule().getEntityManager(); - - JpaEntityIdFactoryIfNotEmpty idGenerator = new JpaEntityIdFactoryIfNotEmpty(); - JpaPollenPersistenceContext persistenceContext = new JpaPollenPersistenceContext(idGenerator, entityManager); - - serviceContext.setPersistenceContext(persistenceContext); - } - } - - return serviceContext; - - } - - protected void loadFixtures(String fixturesSetName) { - - FixturesService fixturesService = getServiceContext().newService(FixturesService.class); - - fixtures = fixturesService.loadFixtures(fixturesSetName); - - } - - protected <E> E fixture(String id) { - - return fixtures.fixture(id); - - } - - protected <E extends PollenServiceSupport> E newService(Class<E> serviceClass) { - - return getServiceContext().newService(serviceClass); - - } - - @Rule - public JpaEntityManagerRule getJpaEntityManagerRule() { - - if (jpaEntityManagerRule == null) { - - Map<String, String> jpaParameters = getPollenServiceConfig().getJpaParameters(); - - jpaEntityManagerRule = new JpaEntityManagerRule("pollenPersistenceUnit", jpaParameters); - } - - return jpaEntityManagerRule; - - } - -} Copied: branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java (from rev 3821, branches/pollen-2.0/pollen-service/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java) =================================================================== --- branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,117 @@ +package org.chorem.pollen.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.JpaPollenPersistenceContext; +import org.chorem.pollen.services.PollenFixtures; +import org.chorem.pollen.services.config.PollenServiceConfig; +import org.chorem.pollen.services.service.FixturesService; +import org.chorem.pollen.services.PollenServiceSupport; +import org.junit.Rule; +import org.nuiton.jpa.junit.JpaEntityManagerRule; + +import javax.persistence.EntityManager; +import java.util.Map; + +public abstract class AbstractPollenServiceTest { + + protected static final double DELTA = 0.0001; + + protected static PollenServiceConfig config; + + protected JpaEntityManagerRule jpaEntityManagerRule; + + protected FakePollenServiceContext serviceContext; + + protected PollenFixtures fixtures; + + protected static PollenServiceConfig getPollenServiceConfig() { + + if (config == null) { + + config = new PollenServiceConfig(); + } + + return config; + + } + + protected FakePollenServiceContext getServiceContext() { + + if (serviceContext == null) { + + synchronized (this) { + serviceContext = new FakePollenServiceContext(); + + serviceContext.setPollenServiceConfig(getPollenServiceConfig()); + + EntityManager entityManager = getJpaEntityManagerRule().getEntityManager(); + +// JpaEntityIdFactoryIfNotEmpty idGenerator = new JpaEntityIdFactoryIfNotEmpty(); +// JpaPollenPersistenceContext persistenceContext = new JpaPollenPersistenceContext(idGenerator, entityManager); + JpaPollenPersistenceContext persistenceContext = new JpaPollenPersistenceContext(entityManager); + + serviceContext.setPersistenceContext(persistenceContext); + } + } + + return serviceContext; + + } + + protected void loadFixtures(String fixturesSetName) { + + FixturesService fixturesService = getServiceContext().newService(FixturesService.class); + + fixtures = fixturesService.loadFixtures(fixturesSetName); + + } + + protected <E> E fixture(String id) { + + return fixtures.fixture(id); + + } + + protected <E extends PollenServiceSupport> E newService(Class<E> serviceClass) { + + return getServiceContext().newService(serviceClass); + + } + + @Rule + public JpaEntityManagerRule getJpaEntityManagerRule() { + + if (jpaEntityManagerRule == null) { + + Map<String, String> jpaParameters = getPollenServiceConfig().getJpaParameters(); + + jpaEntityManagerRule = new JpaEntityManagerRule("pollenPersistenceUnit", jpaParameters); + } + + return jpaEntityManagerRule; + + } + +} Modified: branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/FakePollenServiceContext.java =================================================================== --- branches/pollen-2.0/pollen-service/src/test/java/org/chorem/pollen/service/FakePollenServiceContext.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/FakePollenServiceContext.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -26,6 +26,7 @@ import com.google.common.base.Preconditions; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.services.DefaultPollenServiceContext; import java.util.Date; Deleted: branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/UserServiceTest.java =================================================================== --- branches/pollen-2.0/pollen-service/src/test/java/org/chorem/pollen/service/UserServiceTest.java 2013-06-08 12:12:35 UTC (rev 3819) +++ branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/UserServiceTest.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -1,201 +0,0 @@ -package org.chorem.pollen.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.apache.commons.collections.CollectionUtils; -import org.chorem.pollen.persistence.entity.PollenUser; -import org.chorem.pollen.service.exception.EntityNotFoundException; -import org.chorem.pollen.service.exception.UserEmailAlreadyUsedException; -import org.chorem.pollen.service.exception.UserInvalidEmailActiviationTokenException; -import org.chorem.pollen.service.exception.UserInvalidPasswordException; -import org.chorem.pollen.service.exception.UserLoginAlreadyUsedException; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import java.text.ParseException; -import java.util.Date; -import java.util.List; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class UserServiceTest extends AbstractPollenServiceTest { - - protected UserService service; - - protected PollenUser user; - - @Before - public void setUp() throws ParseException { - - loadFixtures("fixtures"); - - service = serviceContext.getUserService(); - - serviceContext.setDate(new Date(1363948427576l)); - - user = fixture("tony"); - } - - @Test - public void testGetPollenUsers() { - - List<PollenUser> users = service.getUsers(); - - Assert.assertNotNull(users); - Assert.assertTrue(CollectionUtils.isNotEmpty(users)); - } - - @Test - public void testGetPollenUser() throws EntityNotFoundException { - - try { - service.getUser("pollen_user_tony_" + System.nanoTime()); - - } catch (EntityNotFoundException e) { - Assert.assertTrue(true); - } - - PollenUser user = service.getUser("pollen_user_tony"); - - Assert.assertNotNull(user); - Assert.assertEquals(this.user, user); - } - - @Test - public void testCreatePollenUser() throws Exception { - - try { - service.createUser(user, false); - Assert.fail(); - } catch (IllegalStateException e) { - // Should having id - Assert.assertTrue(true); - } - - PollenUser newUser = new PollenUser(); - newUser.setLogin("pollen"); - newUser.setEmail("pollen@pollen.org"); - - PollenUser savedUser = service.createUser(newUser, true); - Assert.assertNotNull(savedUser); - Assert.assertNotNull(savedUser.getId()); - - PollenUser newUser2 = new PollenUser(); - newUser2.setLogin("pollen"); - newUser2.setEmail("pollen@pollen.org"); - - try { - service.createUser(newUser2, true); - Assert.fail(); - } catch (UserLoginAlreadyUsedException e) { - Assert.assertTrue(true); - } - - newUser2.setLogin("pollen2"); - try { - service.createUser(newUser2, true); - Assert.fail(); - } catch (UserEmailAlreadyUsedException e) { - Assert.assertTrue(true); - } - - newUser2.setEmail("pollen2@pollen.org"); - PollenUser savedUser2 = service.createUser(newUser2, true); - Assert.assertNotNull(savedUser2); - Assert.assertNotNull(savedUser2.getId()); - } - - @Test - public void testEditUser() throws EntityNotFoundException, UserInvalidPasswordException, UserEmailAlreadyUsedException { - - PollenUser user = service.getUser("pollen_user_tony"); - - Assert.assertNotNull(user); - Assert.assertNull(user.getEmailActivationToken()); - - serviceContext.getPersistenceContext().detach(user); - - String originalLogin = user.getLogin(); - - user.setLogin("yetanotherlogin"); - String email = "tony@pollen.org"; - user.setEmail(email); - - try { - service.editUser(user); - Assert.fail(); - } catch (UserInvalidPasswordException e) { - Assert.assertTrue(true); - } - - user.setPassword("fake"); - PollenUser savedUser = service.editUser(user); - Assert.assertNotNull(savedUser); - Assert.assertEquals(originalLogin, savedUser.getLogin()); - Assert.assertEquals(email, savedUser.getEmail()); - Assert.assertNotNull(savedUser.getEmailActivationToken()); - } - - @Test - public void testValidateEmail() throws EntityNotFoundException, UserInvalidPasswordException, UserEmailAlreadyUsedException, UserInvalidEmailActiviationTokenException { - - PollenUser user = service.getUser("pollen_user_tony"); - Assert.assertNotNull(user); - Assert.assertNull(user.getEmailActivationToken()); - - serviceContext.getPersistenceContext().detach(user); - - String email = "tony@pollen.org"; - user.setEmail(email); - user.setPassword("fake"); - - PollenUser savedUser = service.editUser(user); - Assert.assertNotNull(savedUser); - - Assert.assertEquals(email, savedUser.getEmail()); - Assert.assertNotNull(savedUser.getEmailActivationToken()); - - try { - service.validateUserEmail(user.getId(), "fakeToken"); - Assert.fail(); - } catch (UserInvalidEmailActiviationTokenException e) { - Assert.assertTrue(true); - } - - Assert.assertFalse(savedUser.isEmailActivated()); - - service.validateUserEmail(user.getId(), savedUser.getEmailActivationToken()); - - - - PollenUser reloadedUser = service.getUser("pollen_user_tony"); - Assert.assertTrue(reloadedUser.isEmailActivated()); - - } -} Copied: branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/UserServiceTest.java (from rev 3821, branches/pollen-2.0/pollen-service/src/test/java/org/chorem/pollen/service/UserServiceTest.java) =================================================================== --- branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/UserServiceTest.java (rev 0) +++ branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/UserServiceTest.java 2013-06-14 09:12:59 UTC (rev 3823) @@ -0,0 +1,202 @@ +package org.chorem.pollen.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.apache.commons.collections.CollectionUtils; +import org.chorem.pollen.persistence.entity.PollenUser; +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.chorem.pollen.services.service.UserService; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.text.ParseException; +import java.util.Date; +import java.util.List; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class UserServiceTest extends AbstractPollenServiceTest { + + protected UserService service; + + protected PollenUser user; + + @Before + public void setUp() throws ParseException { + + loadFixtures("fixtures"); + + service = serviceContext.getUserService(); + + serviceContext.setDate(new Date(1363948427576l)); + + user = fixture("tony"); + } + + @Test + public void testGetPollenUsers() { + + List<PollenUser> users = service.getUsers(); + + Assert.assertNotNull(users); + Assert.assertTrue(CollectionUtils.isNotEmpty(users)); + } + + @Test + public void testGetPollenUser() throws EntityNotFoundException { + + try { + service.getUser("pollen_user_tony_" + System.nanoTime()); + + } catch (EntityNotFoundException e) { + Assert.assertTrue(true); + } + + PollenUser user = service.getUser(this.user.getId()); + + Assert.assertNotNull(user); + Assert.assertEquals(this.user, user); + } + + @Test + public void testCreatePollenUser() throws Exception { + + try { + service.createUser(user, false); + Assert.fail(); + } catch (IllegalStateException e) { + // Should having id + Assert.assertTrue(true); + } + + PollenUser newUser = new PollenUser(); + newUser.setLogin("pollen"); + newUser.setEmail("pollen@pollen.org"); + + PollenUser savedUser = service.createUser(newUser, true); + Assert.assertNotNull(savedUser); + Assert.assertNotNull(savedUser.getId()); + + PollenUser newUser2 = new PollenUser(); + newUser2.setLogin("pollen"); + newUser2.setEmail("pollen@pollen.org"); + + try { + service.createUser(newUser2, true); + Assert.fail(); + } catch (UserLoginAlreadyUsedException e) { + Assert.assertTrue(true); + } + + newUser2.setLogin("pollen2"); + try { + service.createUser(newUser2, true); + Assert.fail(); + } catch (UserEmailAlreadyUsedException e) { + Assert.assertTrue(true); + } + + newUser2.setEmail("pollen2@pollen.org"); + PollenUser savedUser2 = service.createUser(newUser2, true); + Assert.assertNotNull(savedUser2); + Assert.assertNotNull(savedUser2.getId()); + } + + @Test + public void testEditUser() throws EntityNotFoundException, UserInvalidPasswordException, UserEmailAlreadyUsedException { + + PollenUser user = service.getUser(this.user.getId()); + + Assert.assertNotNull(user); + Assert.assertNull(user.getEmailActivationToken()); + + serviceContext.getPersistenceContext().detach(user); + + String originalLogin = user.getLogin(); + + user.setLogin("yetanotherlogin"); + String email = "tony@pollen.org"; + user.setEmail(email); + + try { + service.editUser(user); + Assert.fail(); + } catch (UserInvalidPasswordException e) { + Assert.assertTrue(true); + } + + user.setPassword("fake"); + PollenUser savedUser = service.editUser(user); + Assert.assertNotNull(savedUser); + Assert.assertEquals(originalLogin, savedUser.getLogin()); + Assert.assertEquals(email, savedUser.getEmail()); + Assert.assertNotNull(savedUser.getEmailActivationToken()); + } + + @Test + public void testValidateEmail() throws EntityNotFoundException, UserInvalidPasswordException, UserEmailAlreadyUsedException, UserInvalidEmailActiviationTokenException { + + PollenUser user = service.getUser(this.user.getId()); + Assert.assertNotNull(user); + Assert.assertNull(user.getEmailActivationToken()); + + serviceContext.getPersistenceContext().detach(user); + + String email = "tony@pollen.org"; + user.setEmail(email); + user.setPassword("fake"); + + PollenUser savedUser = service.editUser(user); + Assert.assertNotNull(savedUser); + + Assert.assertEquals(email, savedUser.getEmail()); + Assert.assertNotNull(savedUser.getEmailActivationToken()); + + try { + service.validateUserEmail(user.getId(), "fakeToken"); + Assert.fail(); + } catch (UserInvalidEmailActiviationTokenException e) { + Assert.assertTrue(true); + } + + Assert.assertFalse(savedUser.isEmailActivated()); + + service.validateUserEmail(user.getId(), savedUser.getEmailActivationToken()); + + + + PollenUser reloadedUser = service.getUser(this.user.getId()); + Assert.assertTrue(reloadedUser.isEmailActivated()); + + } +} Modified: branches/pollen-2.0/pom.xml =================================================================== --- branches/pollen-2.0/pom.xml 2013-06-12 18:00:23 UTC (rev 3822) +++ branches/pollen-2.0/pom.xml 2013-06-14 09:12:59 UTC (rev 3823) @@ -130,13 +130,10 @@ </contributors> <modules> - <!--module>pollen-votecounting-api</module> - <module>pollen-votecounting-aggregator</module--> - <!--module>pollen-persistence</module> - <module>pollen-services</module> - <module>pollen-ui-struts2</module--> + <module>pollen-votecounting-api</module> + <module>pollen-votecounting-aggregator</module> <module>pollen-persistence</module> - <module>pollen-service</module> + <module>pollen-services</module> <module>pollen-rest-api</module> </modules> @@ -291,6 +288,7 @@ <groupId>org.debux.webmotion</groupId> <artifactId>webmotion-unittest</artifactId> <version>${webmotionVersion}</version> + <scope>test</scope> </dependency> <dependency>
participants (1)
-
tchemit@users.chorem.org