Author: tchemit Date: 2014-04-25 17:34:32 +0200 (Fri, 25 Apr 2014) New Revision: 3877 Url: http://forge.chorem.org/projects/pollen/repository/revisions/3877 Log: refs #885 : move to Topia3 stack Added: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollImpl.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollTopiaDao.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUserImpl.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUserTopiaDao.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUsers.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiServiceContext.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenTopiaTransactionFilter.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java Removed: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/JpaPollenPersistenceContext.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenPersistenceContext.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUser.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenJpaTransactionFilter.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java Modified: trunk/pollen-persistence/pom.xml trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Polls.java trunk/pollen-persistence/src/main/xmi/pollen.properties trunk/pollen-persistence/src/main/xmi/pollen.zargo trunk/pollen-rest-api/pom.xml trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenApplicationContext.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceContextFilter.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceListener.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServices.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java trunk/pollen-services/pom.xml trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenFixtures.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityRealm.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/EntityNotFoundException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AuthService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java trunk/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollServiceTest.java trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollenUserServiceTest.java trunk/pollen-services/src/test/resources/log4j.properties trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCounting.java trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCounting.java trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCounting.java trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCounting.java trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCounting.java trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCounting.java trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCounting.java trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCounting.java trunk/pom.xml Modified: trunk/pollen-persistence/pom.xml =================================================================== --- trunk/pollen-persistence/pom.xml 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-persistence/pom.xml 2014-04-25 15:34:32 UTC (rev 3877) @@ -18,12 +18,6 @@ <dependencies> - <!--dependency> - <groupId>${project.groupId}</groupId> - <artifactId>pollen-votecounting-api</artifactId> - <version>${project.version}</version> - </dependency--> - <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> @@ -39,23 +33,18 @@ </dependency> <dependency> - <groupId>org.nuiton.jpa</groupId> - <artifactId>nuiton-jpa-api</artifactId> + <groupId>org.nuiton.topia</groupId> + <artifactId>topia-persistence</artifactId> </dependency> <dependency> - <groupId>org.nuiton.jpa</groupId> - <artifactId>nuiton-jpa-hibernate</artifactId> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-core</artifactId> </dependency> <dependency> - <groupId>org.hibernate.javax.persistence</groupId> - <artifactId>hibernate-jpa-2.1-api</artifactId> - </dependency> - - <dependency> <groupId>org.hibernate</groupId> - <artifactId>hibernate-core</artifactId> + <artifactId>hibernate-c3p0</artifactId> </dependency> <dependency> @@ -100,7 +89,7 @@ <configuration> <!-- Corresponding to extracted package from zargo file --> <fullPackagePath> - org.chorem.pollen.persistence.entity + org.chorem.pollen.persistence </fullPackagePath> <!-- defaultPackage used for generation --> <defaultPackage> @@ -108,7 +97,7 @@ </defaultPackage> <templates> org.nuiton.eugene.java.JavaEnumerationTransformer, - org.nuiton.jpa.templates.JpaMetaTransformer + org.nuiton.topia.templates.TopiaMetaTransformer </templates> </configuration> <goals> @@ -116,6 +105,13 @@ </goals> </execution> </executions> + <dependencies> + <dependency> + <groupId>org.nuiton.topia</groupId> + <artifactId>topia-templates</artifactId> + <version>${topiaVersion}</version> + </dependency> + </dependencies> </plugin> </plugins> </build> Deleted: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/JpaPollenPersistenceContext.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/JpaPollenPersistenceContext.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/JpaPollenPersistenceContext.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -1,61 +0,0 @@ -package org.chorem.pollen.persistence; - -/* - * #%L - * Pollen :: Persistence - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -import org.nuiton.jpa.api.JpaEntity; -import org.nuiton.jpa.api.JpaEntityIdFactory; -import org.nuiton.jpa.hibernate.HibernateUtil; - -import javax.persistence.EntityManager; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class JpaPollenPersistenceContext extends AbstractJpaPollenPersistenceContext { - - public JpaPollenPersistenceContext(EntityManager entityManager) { - this(new PollenEntityIdFactory(), entityManager); - } - - public JpaPollenPersistenceContext(JpaEntityIdFactory idGenerator, - EntityManager entityManager) { - super(idGenerator, entityManager); - } - - @Override - public void detach(JpaEntity entity) { - entityManager.detach(entity); - } - - @Override - public void clearDatabase() { - rollback(); - HibernateUtil.cleanDatabase(entityManager); - commit(); - } - -} //JpaPollenPersistenceContext Deleted: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -1,68 +0,0 @@ -package org.chorem.pollen.persistence; - -/* - * #%L - * Pollen :: Persistence - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -import com.google.common.base.Preconditions; -import org.apache.commons.codec.DecoderException; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.codec.binary.Hex; -import org.nuiton.jpa.api.JpaEntity; -import org.nuiton.jpa.api.JpaEntityIdFactory; - -import java.util.UUID; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -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 generateId(); - } -} Deleted: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenPersistenceContext.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenPersistenceContext.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenPersistenceContext.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -1,82 +0,0 @@ -package org.chorem.pollen.persistence; - -/* - * #%L - * Pollen :: Persistence - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -import org.chorem.pollen.persistence.dao.ChoiceJpaDao; -import org.chorem.pollen.persistence.dao.CommentJpaDao; -import org.chorem.pollen.persistence.dao.FavoriteListJpaDao; -import org.chorem.pollen.persistence.dao.FavoriteListMemberJpaDao; -import org.chorem.pollen.persistence.dao.PollJpaDao; -import org.chorem.pollen.persistence.dao.PollenPrincipalJpaDao; -import org.chorem.pollen.persistence.dao.PollenUserJpaDao; -import org.chorem.pollen.persistence.dao.SessionTokenJpaDao; -import org.chorem.pollen.persistence.dao.VoteJpaDao; -import org.chorem.pollen.persistence.dao.VoteToChoiceJpaDao; -import org.chorem.pollen.persistence.dao.VoterJpaDao; -import org.chorem.pollen.persistence.dao.VoterListJpaDao; -import org.chorem.pollen.persistence.dao.VoterListMemberJpaDao; -import org.nuiton.jpa.api.JpaEntity; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public interface PollenPersistenceContext { - - void detach(JpaEntity entity); - - void commit(); - - void rollback(); - - void clearDatabase(); - - ChoiceJpaDao getChoiceDao(); - - CommentJpaDao getCommentDao(); - - FavoriteListJpaDao getFavoriteListDao(); - - FavoriteListMemberJpaDao getFavoriteListMemberDao(); - - PollJpaDao getPollDao(); - - PollenPrincipalJpaDao getPollenPrincipalDao(); - - PollenUserJpaDao getPollenUserDao(); - - SessionTokenJpaDao getSessionTokenDao(); - - VoteJpaDao getVoteDao(); - - VoteToChoiceJpaDao getVoteToChoiceDao(); - - VoterJpaDao getVoterDao(); - - VoterListJpaDao getVoterListDao(); - - VoterListMemberJpaDao getVoterListMemberDao(); -} Deleted: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -1,99 +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 com.google.common.collect.Sets; - -import javax.persistence.Entity; -import java.util.Date; -import java.util.Set; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -@Entity -public class Poll extends AbstractJpaPoll { - - private static final long serialVersionUID = 1L; - - public boolean isFreePoll() { - return PollType.FREE == pollType; - } - - public boolean isRestrictedPoll() { - return PollType.RESTRICTED == pollType; - } - - public boolean isGroupPoll() { - return PollType.GROUP == pollType; - } - - public boolean isStarted(Date currentDate) { - return beginDate == null || beginDate.before(currentDate); - } - - public boolean isRunning(Date currentDate) { - return !isClosed() && - isStarted(currentDate) && - !isFinished(currentDate); - } - - public boolean isFinished(Date currentDate) { - return endDate != null && currentDate.after(endDate); - } - - public boolean isAddChoiceStarted(Date currentDate) { - return isChoiceAddAllowed() && - (beginChoiceDate == null || beginChoiceDate.before(currentDate)); - } - - public boolean isAddChoiceRunning(Date currentDate) { - return isChoiceAddAllowed() && - !isClosed() && - !isFinished(currentDate) && - isAddChoiceStarted(currentDate) && - !isAddChoiceFinished(currentDate); - } - - public boolean isAddChoiceFinished(Date currentDate) { - return !isChoiceAddAllowed() || - (endChoiceDate != null && endChoiceDate.before(currentDate)); - } - - public Set<VoterListMember> getAllVoters() { - Set<VoterListMember> result = Sets.newHashSet(); - if (!isVoterListEmpty()) { - for (VoterList list : getVoterList()) { - - if (!list.isVoterListMemberEmpty()) { - result.addAll(list.getVoterListMember()); - } - } - } - return result; - } -} //Poll Added: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollImpl.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollImpl.java (rev 0) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollImpl.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -0,0 +1,107 @@ +package org.chorem.pollen.persistence.entity; + +/* + * #%L + * Pollen :: Persistence + * $Id$ + * $HeadURL: http://svn.chorem.org/svn/pollen/trunk/pollen-persistence/src/main/java/org/... $ + * %% + * Copyright (C) 2009 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import com.google.common.collect.Sets; + +import java.util.Date; +import java.util.Set; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollImpl extends PollAbstract { + + private static final long serialVersionUID = 1L; + + //FIXME Remove this + public boolean isFreePoll() { + return Polls.isPollFree(this); + } + + //FIXME Remove this + public boolean isRestrictedPoll() { + return Polls.isPollRestricted(this); + } + + //FIXME Remove this + public boolean isGroupPoll() { + return Polls.isPollGroup(this); + } + + //FIXME Remove this + public boolean isStarted(Date currentDate) { + return beginDate == null || beginDate.before(currentDate); + } + + //FIXME Remove this + public boolean isRunning(Date currentDate) { + return !isClosed() && + isStarted(currentDate) && + !isFinished(currentDate); + } + + //FIXME Remove this + public boolean isFinished(Date currentDate) { + return endDate != null && currentDate.after(endDate); + } + + //FIXME Remove this + public boolean isAddChoiceStarted(Date currentDate) { + return isChoiceAddAllowed() && + (beginChoiceDate == null || beginChoiceDate.before(currentDate)); + } + + //FIXME Remove this + public boolean isAddChoiceRunning(Date currentDate) { + return isChoiceAddAllowed() && + !isClosed() && + !isFinished(currentDate) && + isAddChoiceStarted(currentDate) && + !isAddChoiceFinished(currentDate); + } + + //FIXME Remove this + public boolean isAddChoiceFinished(Date currentDate) { + return !isChoiceAddAllowed() || + (endChoiceDate != null && endChoiceDate.before(currentDate)); + } + + //FIXME Remove this + public Set<VoterListMember> getAllVoters() { + Set<VoterListMember> result = Sets.newHashSet(); + if (!isVoterListEmpty()) { + for (VoterList list : getVoterList()) { + + if (!list.isVoterListMemberEmpty()) { + result.addAll(list.getVoterListMember()); + } + } + } + return result; + } +} Property changes on: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollImpl.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollTopiaDao.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollTopiaDao.java (rev 0) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollTopiaDao.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -0,0 +1,52 @@ +package org.chorem.pollen.persistence.entity; + +/* + * #%L + * Pollen :: Persistence + * $Id$ + * $HeadURL: http://svn.chorem.org/svn/pollen/trunk/pollen-persistence/src/main/java/org/... $ + * %% + * Copyright (C) 2009 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import com.google.common.collect.Sets; + +import java.util.Set; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollTopiaDao extends AbstractPollTopiaDao<Poll> { + + public Set<Poll> findAllCreated(String userId) { + //TODO + return Sets.newHashSet(); + } + + public Set<Poll> findAllInvited(String userId) { + //TODO + return Sets.newHashSet(); + } + + public Set<Poll> findAllParticipated(String userId) { + //TODO + return Sets.newHashSet(); + } + + +} Property changes on: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollTopiaDao.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Deleted: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUser.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUser.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUser.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -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 PollenUser extends AbstractJpaPollenUser { - - private static final long serialVersionUID = 1L; - - public boolean isEmailActivated() { - return emailActivationToken == null; - } - -} //PollenUser Added: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUserImpl.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUserImpl.java (rev 0) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUserImpl.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -0,0 +1,40 @@ +package org.chorem.pollen.persistence.entity; + +/* + * #%L + * Pollen :: Persistence + * $Id$ + * $HeadURL: http://svn.chorem.org/svn/pollen/trunk/pollen-persistence/src/main/java/org/... $ + * %% + * 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 class PollenUserImpl extends PollenUserAbstract { + + private static final long serialVersionUID = 1L; + + public boolean isEmailActivated() { + return emailActivationToken == null; + } + +} Property changes on: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUserImpl.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUserTopiaDao.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUserTopiaDao.java (rev 0) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUserTopiaDao.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -0,0 +1,41 @@ +package org.chorem.pollen.persistence.entity; + +/* + * #%L + * Pollen :: Persistence + * $Id$ + * $HeadURL: http://svn.chorem.org/svn/pollen/trunk/pollen-persistence/src/main/java/org/... $ + * %% + * 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% + */ + +/** + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollenUserTopiaDao extends AbstractPollenUserTopiaDao<PollenUser> { + + public boolean loginExists(String login) { + boolean exists = forLoginEquals(login).exists(); + return exists; + } + + public boolean emailExists(String email) { + boolean exists = forEmailEquals(email).exists(); + return exists; + } +} Property changes on: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUserTopiaDao.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUsers.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUsers.java (rev 0) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUsers.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -0,0 +1,14 @@ +package org.chorem.pollen.persistence.entity; + +/** + * Created on 4/25/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollenUsers { + + public static boolean isEmailActivated(PollenUser pollenUser) { + return pollenUser.getEmailActivationToken() == null; + } +} Property changes on: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUsers.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Polls.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Polls.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Polls.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -23,8 +23,12 @@ * #L% */ -import org.apache.commons.lang3.ObjectUtils; +import com.google.common.collect.Sets; +import java.util.Date; +import java.util.Objects; +import java.util.Set; + /** * TODO * @@ -33,15 +37,33 @@ */ public class Polls { - public boolean isPollFree(Poll poll) { - return ObjectUtils.equals(PollType.FREE, poll.getPollType()); + public static boolean isPollFree(Poll poll) { + return Objects.equals(PollType.FREE, poll.getPollType()); } - public boolean isPollRestricted(Poll poll) { - return ObjectUtils.equals(PollType.RESTRICTED, poll.getPollType()); + public static boolean isPollRestricted(Poll poll) { + return Objects.equals(PollType.RESTRICTED, poll.getPollType()); } - public boolean isPollGroup(Poll poll) { - return ObjectUtils.equals(PollType.GROUP, poll.getPollType()); + public static boolean isPollGroup(Poll poll) { + return Objects.equals(PollType.GROUP, poll.getPollType()); } + + public static boolean isStarted(Poll poll, Date currentDate) { + Date beginDate = poll.getBeginDate(); + return beginDate == null || beginDate.before(currentDate); + } + + public static Set<VoterListMember> getAllVoters(Poll poll) { + Set<VoterListMember> result = Sets.newHashSet(); + if (poll.isVoterListNotEmpty()) { + for (VoterList list : poll.getVoterList()) { + + if (!list.isVoterListMemberEmpty()) { + result.addAll(list.getVoterListMember()); + } + } + } + return result; + } } Modified: trunk/pollen-persistence/src/main/xmi/pollen.properties =================================================================== --- trunk/pollen-persistence/src/main/xmi/pollen.properties 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-persistence/src/main/xmi/pollen.properties 2014-04-25 15:34:32 UTC (rev 3877) @@ -21,9 +21,11 @@ # #L% ###m model.tagvalue.version=2.0 -model.tagValue.idFactory=true -model.tagValue.generateVisitors=true -model.tagValue.generateExtraTechnicalFields=true +model.tagValue.notGenerateToString=true +model.tagValue.constantPrefix=PROPERTY_ +model.tagValue.useEnumerationName=true +model.tagValue.indexForeignKeys=true +model.tagValue.String=string org.chorem.pollen.persistence.entity.Poll.attribute.choice.stereotype=ordered org.chorem.pollen.persistence.entity.Poll.attribute.voterList.stereotype=ordered Modified: trunk/pollen-persistence/src/main/xmi/pollen.zargo =================================================================== (Binary files differ) Modified: trunk/pollen-rest-api/pom.xml =================================================================== --- trunk/pollen-rest-api/pom.xml 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-rest-api/pom.xml 2014-04-25 15:34:32 UTC (rev 3877) @@ -42,11 +42,6 @@ </dependency> <dependency> - <groupId>org.hibernate.javax.persistence</groupId> - <artifactId>hibernate-jpa-2.1-api</artifactId> - </dependency> - - <dependency> <groupId>org.nuiton.web</groupId> <artifactId>nuiton-web</artifactId> </dependency> @@ -126,7 +121,7 @@ <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> - <scope>test</scope> + <scope>compile</scope> </dependency> </dependencies> Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenApplicationContext.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenApplicationContext.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenApplicationContext.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -25,17 +25,20 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.persistence.JpaPollenPersistenceContext; +import org.apache.log4j.LogManager; +import org.apache.log4j.PropertyConfigurator; +import org.chorem.pollen.persistence.PollenTopiaApplicationContext; +import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; import org.chorem.pollen.services.DefaultPollenServiceContext; import org.chorem.pollen.services.PollenServiceContext; import org.chorem.pollen.services.config.PollenServiceConfig; +import org.nuiton.i18n.I18n; +import org.nuiton.i18n.init.DefaultI18nInitializer; +import org.nuiton.i18n.init.I18nInitializer; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.Persistence; -import javax.persistence.PersistenceException; import java.io.Closeable; -import java.util.Map; +import java.io.File; +import java.util.Locale; /** * TODO @@ -45,81 +48,119 @@ */ public class PollenApplicationContext implements Closeable { - private static final Log log = LogFactory.getLog(PollenApplicationContext.class); + private static Log log = LogFactory.getLog(PollenApplicationContext.class); protected static final String APPLICATION_CONTEXT_PARAMETER = "pollen_PollenApplicationContext"; - protected PollenServiceConfig applicationConfig; + protected static PollenTopiaApplicationContext topiaApplicationContext; - protected EntityManagerFactory entityManagerFactory; + protected static PollenServiceConfig applicationConfig; - public PollenServiceConfig getPollenServiceConfig() { + public static PollenServiceConfig getApplicationConfig() { if (applicationConfig == null) { applicationConfig = new PollenServiceConfig(); } return applicationConfig; } - public EntityManager newEntityManager() { + public static PollenTopiaApplicationContext getTopiaApplicationContext() { + if (topiaApplicationContext == null) { + topiaApplicationContext = new PollenTopiaApplicationContext(getApplicationConfig().getTopiaProperties()); + } + return topiaApplicationContext; + } - if (entityManagerFactory == null) { + public static void setTopiaApplicationContext(PollenTopiaApplicationContext topiaApplicationContext) { + PollenApplicationContext.topiaApplicationContext = topiaApplicationContext; + } - PollenServiceConfig applicationConfig = getPollenServiceConfig(); + public PollenTopiaPersistenceContext newPersistenceContext() { - Map<String, String> jpaParameters = applicationConfig.getJpaParameters(); + PollenTopiaPersistenceContext persistenceContext = getTopiaApplicationContext().newPersistenceContext(); - if (log.isInfoEnabled()) { - log.info("creating entity manager factory"); - } + return persistenceContext; - try { + } - entityManagerFactory = Persistence.createEntityManagerFactory("pollenPersistenceUnit", jpaParameters); + public PollenServiceContext newServiceContext(PollenTopiaPersistenceContext persistenceContext, Locale locale) { - } catch (PersistenceException e) { + DefaultPollenServiceContext newServiceContext = + new DefaultPollenServiceContext(); - if (log.isErrorEnabled()) { - log.error("unable to create entity manager factory", e); - } + PollenServiceConfig applicationConfig = getApplicationConfig(); - throw e; + newServiceContext.setPollenServiceConfig(applicationConfig); - } + newServiceContext.setPersistenceContext(persistenceContext); - } + newServiceContext.setLocale(locale); - EntityManager entityManager = entityManagerFactory.createEntityManager(); + return newServiceContext; - return entityManager; - } + @Override public void close() { - if (entityManagerFactory != null && entityManagerFactory.isOpen()) { + if (topiaApplicationContext != null) { if (log.isInfoEnabled()) { log.info("stopping Pollen, will close entity manager factory"); } - entityManagerFactory.close(); + topiaApplicationContext.closeContext(); } } - public PollenServiceContext newServiceContext(EntityManager entityManager) { + public void init() { - DefaultPollenServiceContext serviceContext = new DefaultPollenServiceContext(); + if (getApplicationConfig().isLogConfigurationProvided()) { - JpaPollenPersistenceContext jpaMagaliePersistenceContext = - new JpaPollenPersistenceContext(entityManager); + File log4jConfigurationFile = getApplicationConfig().getLogConfigurationFile(); - serviceContext.setPersistenceContext(jpaMagaliePersistenceContext); + String log4jConfigurationFileAbsolutePath = log4jConfigurationFile.getAbsolutePath(); - serviceContext.setPollenServiceConfig(applicationConfig); + if (log4jConfigurationFile.exists()) { - return serviceContext; + if (log.isInfoEnabled()) { + log.info("will use logging configuration " + log4jConfigurationFileAbsolutePath); + } + // reset logger configuration + LogManager.resetConfiguration(); + + // use generate log config file + PropertyConfigurator.configure(log4jConfigurationFileAbsolutePath); + + log = LogFactory.getLog(PollenApplicationContext.class); + + } else { + if (log.isWarnEnabled()) { + log.warn("there is no file " + log4jConfigurationFileAbsolutePath + ". Default logging configuration will be used."); + } + } + + } else { + log.info("will use default logging configuration"); + } + + I18nInitializer initializer = new DefaultI18nInitializer("pollen"); + // to show none translated sentences + initializer.setMissingKeyReturnNull(true); + + I18n.init(initializer, Locale.FRANCE); + +// PollenTopiaPersistenceContext persistenceContext = newPersistenceContext(); +// +// PollenServiceContext serviceContext = newServiceContext(persistenceContext, Locale.FRANCE); +// +// InitWaoService initWaoService = serviceContext.newService(InitWaoService.class); +// +// initWaoService.init(); +// +// persistenceContext.closeContext(); + } } Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenJpaTransactionFilter.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenJpaTransactionFilter.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenJpaTransactionFilter.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -1,87 +0,0 @@ -package org.chorem.pollen.rest.api; - -/* - * #%L - * Pollen :: Rest Api - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -import com.google.common.base.Preconditions; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.web.filter.JpaTransactionFilter; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceException; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; - -public class PollenJpaTransactionFilter extends JpaTransactionFilter { - - private static final Log log = - LogFactory.getLog(PollenJpaTransactionFilter.class); - - protected PollenApplicationContext applicationContext; - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - - super.init(filterConfig); - - if (log.isInfoEnabled()) { - log.info("Init JPA Filter"); - } - -// applicationContext = PollenServices.getApplicationContext( -// filterConfig.getServletContext()); -// -// Preconditions.checkNotNull(applicationContext, "Could not find application context at ServletContext#pollen_PollenApplicationContext"); - } - - protected PollenApplicationContext getApplicationContext(ServletRequest request) { - if (applicationContext == null) { - applicationContext = PollenServices.getApplicationContext( - request.getServletContext()); - - Preconditions.checkNotNull(applicationContext, "Could not find application context at ServletContext#pollen_PollenApplicationContext"); - } - return applicationContext; - } - - @Override - protected EntityManager createEntityManager(ServletRequest request) { - - EntityManager entityManager; - - try { - - entityManager = getApplicationContext(request).newEntityManager(); - - } catch (PersistenceException e) { - - if (log.isErrorEnabled()) { - log.error("unable to create entity manager", e); - } - throw e; - } - return entityManager; - } -} Added: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiServiceContext.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiServiceContext.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiServiceContext.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -0,0 +1,78 @@ +package org.chorem.pollen.rest.api; + +import org.chorem.pollen.services.PollenSecurityContext; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.service.AuthService; +import org.chorem.pollen.services.service.ChoiceService; +import org.chorem.pollen.services.service.CommentService; +import org.chorem.pollen.services.service.FavoriteListService; +import org.chorem.pollen.services.service.FixturesService; +import org.chorem.pollen.services.service.PollService; +import org.chorem.pollen.services.service.PollenUserService; +import org.chorem.pollen.services.service.SecurityService; +import org.chorem.pollen.services.service.VoteCountingService; +import org.chorem.pollen.services.service.VoteService; +import org.chorem.pollen.services.service.VoterListService; + +/** + * Created on 4/25/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollenRestApiServiceContext { + + protected PollenServiceContext serviceContext; + + public void setServiceContext(PollenServiceContext serviceContext) { + this.serviceContext = serviceContext; + } + + public void setSecurityContext(PollenSecurityContext securityContext) { + serviceContext.setSecurityContext(securityContext); + } + + public AuthService getAuthService() { + return serviceContext.newService(AuthService.class); + } + + public ChoiceService getChoiceService() { + return serviceContext.newService(ChoiceService.class); + } + + public CommentService getCommentService() { + return serviceContext.newService(CommentService.class); + } + + public FavoriteListService getFavoriteListService() { + return serviceContext.newService(FavoriteListService.class); + } + + public PollService getPollService() { + return serviceContext.newService(PollService.class); + } + + public PollenUserService getPollenUserService() { + return serviceContext.newService(PollenUserService.class); + } + + public VoteCountingService getVoteCountingService() { + return serviceContext.newService(VoteCountingService.class); + } + + public VoterListService getVoterListService() { + return serviceContext.newService(VoterListService.class); + } + + public VoteService getVoteService() { + return serviceContext.newService(VoteService.class); + } + + public FixturesService getFixturesService() { + return serviceContext.newService(FixturesService.class); + } + + public SecurityService getSecurityService() { + return serviceContext.newService(SecurityService.class); + } +} Property changes on: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiServiceContext.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceContextFilter.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceContextFilter.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceContextFilter.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -24,6 +24,7 @@ */ import org.apache.commons.lang3.StringUtils; +import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; import org.chorem.pollen.persistence.entity.SessionToken; import org.chorem.pollen.services.PollenSecurityContext; import org.chorem.pollen.services.PollenServiceContext; @@ -31,8 +32,8 @@ import org.debux.webmotion.server.WebMotionFilter; import org.debux.webmotion.server.call.HttpContext; -import javax.persistence.EntityManager; import javax.servlet.http.HttpServletResponse; +import java.util.Locale; /** * Inject le service context dans les controlleurs. @@ -49,15 +50,19 @@ PollenApplicationContext applicationContext = PollenServices.getApplicationContext(context.getServletContext()); - EntityManager entityManager = - PollenServices.getEntityManager(context.getRequest()); + PollenTopiaPersistenceContext persistenceContext = + PollenServices.getPersistenceContext(context.getRequest()); PollenServiceContext serviceContext = - applicationContext.newServiceContext(entityManager); - PollenServices.setServiceContext(context.getRequest(), serviceContext); + applicationContext.newServiceContext(persistenceContext, Locale.FRANCE); - addSecurityContext(context, serviceContext); + PollenRestApiServiceContext apiContext = new PollenRestApiServiceContext(); + apiContext.setServiceContext(serviceContext); + PollenServices.setServiceContext(context.getRequest(), apiContext); + + addSecurityContext(context, apiContext); + doProcess(); HttpServletResponse response = context.getResponse(); @@ -66,7 +71,7 @@ } protected void addSecurityContext(HttpContext context, - PollenServiceContext serviceContext) throws InvalidSessionTokenException { + PollenRestApiServiceContext serviceContext) throws InvalidSessionTokenException { String[] strings = context.getParameters().get(REQUEST_AUTH_PARAMETER); Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceListener.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceListener.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceListener.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -24,11 +24,11 @@ */ import org.apache.commons.beanutils.Converter; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; import org.chorem.pollen.services.PollenServiceContext; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidPollenUserFormException; +import org.chorem.pollen.services.service.PollenUserService; import org.debux.webmotion.server.WebMotionServerListener; import org.debux.webmotion.server.call.Call; import org.debux.webmotion.server.call.HttpContext; @@ -36,10 +36,10 @@ import org.debux.webmotion.server.handler.ExecutorParametersInjectorHandler; import org.debux.webmotion.server.mapping.Mapping; -import javax.persistence.EntityManager; import javax.servlet.http.HttpServletRequest; import java.lang.reflect.Type; import java.util.Date; +import java.util.Locale; /** * TODO @@ -49,10 +49,6 @@ */ public class PollenServiceListener implements WebMotionServerListener { - /** Logger. */ - private static final Log log = - LogFactory.getLog(PollenServiceListener.class); - @Override public void onStart(Mapping mapping, ServerContext serverContext) { serverContext.addConverter(new Converter() { @@ -83,18 +79,18 @@ PollenServices.setApplicationContext( serverContext.getServletContext(), applicationContext); - EntityManager entityManager = applicationContext.newEntityManager(); + PollenTopiaPersistenceContext persistenceContext = applicationContext.newPersistenceContext(); try { PollenServiceContext serviceContext = - applicationContext.newServiceContext(entityManager); - serviceContext.getPollenUserService().createDefaultUsers(); + applicationContext.newServiceContext(persistenceContext, Locale.FRANCE); + serviceContext.newService(PollenUserService.class).createDefaultUsers(); } catch (InvalidPollenUserFormException e) { //Can't happen } catch (EntityNotFoundException e) { //Can't happen } finally { - entityManager.close(); + persistenceContext.closeContext(); } } @@ -114,8 +110,8 @@ protected static class PollenServiceContextInjector implements ExecutorParametersInjectorHandler.Injector { @Override - public Object getValue(Mapping mapping, Call call, String name, Class<?> type, Type generic) { - PollenServiceContext result = null; + public PollenRestApiServiceContext getValue(Mapping mapping, Call call, String name, Class<?> type, Type generic) { + PollenRestApiServiceContext result = null; if (PollenServiceContext.class.isAssignableFrom(type)) { HttpContext httpContext = call.getContext(); HttpServletRequest request = httpContext.getRequest(); Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServices.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServices.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServices.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -23,11 +23,10 @@ * #L% */ +import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; import org.chorem.pollen.persistence.entity.SessionToken; -import org.chorem.pollen.services.PollenServiceContext; import org.nuiton.web.filter.JpaTransactionFilter; -import javax.persistence.EntityManager; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; @@ -59,19 +58,20 @@ } - public static PollenServiceContext getServiceContext(HttpServletRequest request) { - PollenServiceContext result = (PollenServiceContext) + public static PollenRestApiServiceContext getServiceContext(HttpServletRequest request) { + PollenRestApiServiceContext result = (PollenRestApiServiceContext) request.getAttribute(REQUEST_POLLEN_SERVICE_CONTEXT); return result; } public static void setServiceContext(HttpServletRequest request, - PollenServiceContext serviceContext) { + PollenRestApiServiceContext serviceContext) { request.setAttribute(REQUEST_POLLEN_SERVICE_CONTEXT, serviceContext); } - public static EntityManager getEntityManager(HttpServletRequest request) { - EntityManager result = (EntityManager) + + public static PollenTopiaPersistenceContext getPersistenceContext(HttpServletRequest request) { + PollenTopiaPersistenceContext result = (PollenTopiaPersistenceContext) request.getAttribute(REQUEST_ENTITY_MANAGER); return result; } Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenTopiaTransactionFilter.java (from rev 3875, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenJpaTransactionFilter.java) =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenTopiaTransactionFilter.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenTopiaTransactionFilter.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -0,0 +1,75 @@ +package org.chorem.pollen.rest.api; + +/* + * #%L + * Pollen :: Rest Api + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import com.google.common.base.Preconditions; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.web.filter.TypedTopiaTransactionFilter; + +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; + +public class PollenTopiaTransactionFilter extends TypedTopiaTransactionFilter<PollenTopiaPersistenceContext> { + + private static final Log log = + LogFactory.getLog(PollenTopiaTransactionFilter.class); + + protected PollenApplicationContext applicationContext; + + protected PollenTopiaTransactionFilter() { + super(PollenTopiaPersistenceContext.class); + } + + @Override + protected PollenTopiaPersistenceContext beginTransaction(ServletRequest request) throws TopiaException { + PollenApplicationContext applicationContext = getApplicationContext(request); + PollenTopiaPersistenceContext persistenceContext = applicationContext.newPersistenceContext(); + return persistenceContext; + } + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + + super.init(filterConfig); + + if (log.isInfoEnabled()) { + log.info("Init Topia Filter"); + } + } + + protected PollenApplicationContext getApplicationContext(ServletRequest request) { + if (applicationContext == null) { + applicationContext = PollenServices.getApplicationContext( + request.getServletContext()); + + Preconditions.checkNotNull(applicationContext, "Could not find application context at ServletContext#pollen_PollenApplicationContext"); + } + return applicationContext; + } + +} Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthService.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -24,7 +24,7 @@ */ import org.chorem.pollen.persistence.entity.SessionToken; -import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.rest.api.PollenRestApiServiceContext; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.UserInvalidPasswordException; import org.debux.webmotion.server.WebMotionController; @@ -37,15 +37,15 @@ */ public class AuthService extends WebMotionController { - public SessionToken login(PollenServiceContext context, String login, String password) throws UserInvalidPasswordException, EntityNotFoundException { + public SessionToken login(PollenRestApiServiceContext context, String login, String password) throws UserInvalidPasswordException, EntityNotFoundException { return context.getAuthService().login(login, password); } - public void lostPassword(PollenServiceContext context, String login) throws EntityNotFoundException { + public void lostPassword(PollenRestApiServiceContext context, String login) throws EntityNotFoundException { context.getAuthService().lostPassword(login); } - public void logout(PollenServiceContext context, String login, String token) throws EntityNotFoundException { + public void logout(PollenRestApiServiceContext context, String login, String token) throws EntityNotFoundException { context.getAuthService().logout(login, token); } } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceService.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -24,7 +24,7 @@ */ import org.chorem.pollen.persistence.entity.Choice; -import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.rest.api.PollenRestApiServiceContext; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidChoiceFormException; import org.debux.webmotion.server.WebMotionController; @@ -39,28 +39,28 @@ */ public class ChoiceService extends WebMotionController { - public List<Choice> getChoices(PollenServiceContext context, String pollId) throws EntityNotFoundException { + public List<Choice> getChoices(PollenRestApiServiceContext context, String pollId) throws EntityNotFoundException { context.getSecurityService().prepareSubject((String) null); List<Choice> choices = context.getChoiceService().getChoices(pollId); return choices; } - public Choice getChoice(PollenServiceContext context, String pollId, String choiceId) throws EntityNotFoundException { + public Choice getChoice(PollenRestApiServiceContext context, String pollId, String choiceId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(choiceId); return context.getChoiceService().getChoice(pollId, choiceId); } - public Choice addChoice(PollenServiceContext context, String pollId, Choice choice) throws EntityNotFoundException, InvalidChoiceFormException { + public Choice addChoice(PollenRestApiServiceContext context, String pollId, Choice choice) throws EntityNotFoundException, InvalidChoiceFormException { context.getSecurityService().prepareSubject(pollId); return context.getChoiceService().addChoice(pollId, choice); } - public Choice editChoice(PollenServiceContext context, String pollId, Choice choice) throws EntityNotFoundException, InvalidChoiceFormException { + public Choice editChoice(PollenRestApiServiceContext context, String pollId, Choice choice) throws EntityNotFoundException, InvalidChoiceFormException { context.getSecurityService().prepareSubject(choice); return context.getChoiceService().editChoice(pollId, choice); } - public void deleteChoice(PollenServiceContext context, String pollId, String choiceId) throws EntityNotFoundException { + public void deleteChoice(PollenRestApiServiceContext context, String pollId, String choiceId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(choiceId); context.getChoiceService().deleteChoice(pollId, choiceId); } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentService.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -24,7 +24,7 @@ */ import org.chorem.pollen.persistence.entity.Comment; -import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.rest.api.PollenRestApiServiceContext; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidCommentFormException; import org.debux.webmotion.server.WebMotionController; @@ -39,28 +39,28 @@ */ public class CommentService extends WebMotionController { - public List<Comment> getComments(PollenServiceContext context, String pollId) throws EntityNotFoundException { + public List<Comment> getComments(PollenRestApiServiceContext context, String pollId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(pollId); List<Comment> comments = context.getCommentService().getComments(pollId); return comments; } - public Comment getComment(PollenServiceContext context, String pollId, String commentId) throws EntityNotFoundException { + public Comment getComment(PollenRestApiServiceContext context, String pollId, String commentId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(commentId); return context.getCommentService().getComment(pollId, commentId); } - public Comment addComment(PollenServiceContext context, String pollId, Comment comment) throws EntityNotFoundException, InvalidCommentFormException { + public Comment addComment(PollenRestApiServiceContext context, String pollId, Comment comment) throws EntityNotFoundException, InvalidCommentFormException { context.getSecurityService().prepareSubject(pollId); return context.getCommentService().addComment(pollId, comment); } - public Comment editComment(PollenServiceContext context, String pollId, Comment comment) throws EntityNotFoundException, InvalidCommentFormException { + public Comment editComment(PollenRestApiServiceContext context, String pollId, Comment comment) throws EntityNotFoundException, InvalidCommentFormException { context.getSecurityService().prepareSubject(comment); return context.getCommentService().editComment(pollId, comment); } - public void deleteComment(PollenServiceContext context, String pollId, String commentId) throws EntityNotFoundException { + public void deleteComment(PollenRestApiServiceContext context, String pollId, String commentId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(commentId); context.getCommentService().deleteComment(pollId, commentId); } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListService.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -25,7 +25,7 @@ import org.chorem.pollen.persistence.entity.FavoriteList; import org.chorem.pollen.persistence.entity.FavoriteListMember; -import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.rest.api.PollenRestApiServiceContext; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.FavoriteListImportException; import org.chorem.pollen.services.exception.InvalidFavoriteListFormException; @@ -43,53 +43,53 @@ */ public class FavoriteListService extends WebMotionController { - public List<FavoriteList> getFavoriteLists(PollenServiceContext context, String userId) throws EntityNotFoundException { + public List<FavoriteList> getFavoriteLists(PollenRestApiServiceContext context, String userId) throws EntityNotFoundException { List<FavoriteList> favoriteLists = context.getFavoriteListService().getFavoriteLists(userId); return favoriteLists; } - public FavoriteList getFavoriteList(PollenServiceContext context, String userId, String favoriteListId) throws EntityNotFoundException { + public FavoriteList getFavoriteList(PollenRestApiServiceContext context, String userId, String favoriteListId) throws EntityNotFoundException { return context.getFavoriteListService().getFavoriteList(userId, favoriteListId); } - public FavoriteList createFavoriteList(PollenServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, InvalidFavoriteListFormException { + public FavoriteList createFavoriteList(PollenRestApiServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, InvalidFavoriteListFormException { return context.getFavoriteListService().createFavoriteList(userId, favoriteList); } - public FavoriteList editFavoriteList(PollenServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, InvalidFavoriteListFormException { + public FavoriteList editFavoriteList(PollenRestApiServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, InvalidFavoriteListFormException { return context.getFavoriteListService().editFavoriteList(userId, favoriteList); } - public void deleteFavoriteList(PollenServiceContext context, String userId, String favoriteListId) throws EntityNotFoundException { + public void deleteFavoriteList(PollenRestApiServiceContext context, String userId, String favoriteListId) throws EntityNotFoundException { context.getFavoriteListService().deleteFavoriteList(userId, favoriteListId); } - public int importFavoriteListMembersFromCsv(PollenServiceContext context, String userId, String favoriteListId, File csvFile) throws EntityNotFoundException, FavoriteListImportException { + public int importFavoriteListMembersFromCsv(PollenRestApiServiceContext context, String userId, String favoriteListId, File csvFile) throws EntityNotFoundException, FavoriteListImportException { return context.getFavoriteListService().importFavoriteListMembersFromCsv(userId, favoriteListId, csvFile); } - public int importFavoriteListMembersFromLdap(PollenServiceContext context, String userId, String favoriteListId, String ldap) throws EntityNotFoundException, FavoriteListImportException { + public int importFavoriteListMembersFromLdap(PollenRestApiServiceContext context, String userId, String favoriteListId, String ldap) throws EntityNotFoundException, FavoriteListImportException { return context.getFavoriteListService().importFavoriteListMembersFromLdap(userId, favoriteListId, ldap); } - public List<FavoriteListMember> getMembers(PollenServiceContext context, String userId, String favoriteListId) throws EntityNotFoundException { + public List<FavoriteListMember> getMembers(PollenRestApiServiceContext context, String userId, String favoriteListId) throws EntityNotFoundException { List<FavoriteListMember> members = context.getFavoriteListService().getFavoriteListMembers(userId, favoriteListId); return members; } - public FavoriteListMember getMember(PollenServiceContext context, String userId, String favoriteListId, String memberId) throws EntityNotFoundException { + public FavoriteListMember getMember(PollenRestApiServiceContext context, String userId, String favoriteListId, String memberId) throws EntityNotFoundException { return context.getFavoriteListService().getFavoriteListMember(userId, favoriteListId, memberId); } - public FavoriteListMember addMember(PollenServiceContext context, String userId, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, InvalidFavoriteListMemberFormException { + public FavoriteListMember addMember(PollenRestApiServiceContext context, String userId, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, InvalidFavoriteListMemberFormException { return context.getFavoriteListService().addFavoriteListMember(userId, favoriteListId, member); } - public FavoriteListMember editMember(PollenServiceContext context, String userId, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, InvalidFavoriteListMemberFormException { + public FavoriteListMember editMember(PollenRestApiServiceContext context, String userId, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, InvalidFavoriteListMemberFormException { return context.getFavoriteListService().editFavoriteListMember(userId, favoriteListId, member); } - public void removeMember(PollenServiceContext context, String userId, String favoriteListId, String memberId) throws EntityNotFoundException { + public void removeMember(PollenRestApiServiceContext context, String userId, String favoriteListId, String memberId) throws EntityNotFoundException { context.getFavoriteListService().removeFavoriteListMember(userId, favoriteListId, memberId); } } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -25,7 +25,7 @@ import org.chorem.pollen.persistence.entity.ChoiceType; import org.chorem.pollen.persistence.entity.Poll; -import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.rest.api.PollenRestApiServiceContext; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidPollFormException; import org.debux.webmotion.server.WebMotionController; @@ -41,60 +41,60 @@ */ public class PollService extends WebMotionController { - public Poll getNewPoll(PollenServiceContext context, String userId, ChoiceType choiceType) throws EntityNotFoundException { + public Poll getNewPoll(PollenRestApiServiceContext context, String userId, ChoiceType choiceType) throws EntityNotFoundException { return context.getPollService().getNewPoll(userId, choiceType); } - public Set<Poll> getPolls(PollenServiceContext context, String userId) throws EntityNotFoundException { + public Set<Poll> getPolls(PollenRestApiServiceContext context, String userId) throws EntityNotFoundException { Set<Poll> polls = context.getPollService().getPolls(userId); return polls; } - public Set<Poll> getCreatedPolls(PollenServiceContext context, String userId) throws EntityNotFoundException { + public Set<Poll> getCreatedPolls(PollenRestApiServiceContext context, String userId) throws EntityNotFoundException { Set<Poll> polls = context.getPollService().getCreatedPolls(userId); return polls; } - public Set<Poll> getInvitedPolls(PollenServiceContext context, String userId) throws EntityNotFoundException { + public Set<Poll> getInvitedPolls(PollenRestApiServiceContext context, String userId) throws EntityNotFoundException { Set<Poll> polls = context.getPollService().getInvitedPolls(userId); return polls; } - public Set<Poll> getParticipatedPolls(PollenServiceContext context, String userId) throws EntityNotFoundException { + public Set<Poll> getParticipatedPolls(PollenRestApiServiceContext context, String userId) throws EntityNotFoundException { Set<Poll> polls = context.getPollService().getParticipatedPolls(userId); return polls; } - public Poll getPoll(PollenServiceContext context, String pollId) throws EntityNotFoundException { - context.getSecurityService().prepareSubject((String)null); + public Poll getPoll(PollenRestApiServiceContext context, String pollId) throws EntityNotFoundException { + context.getSecurityService().prepareSubject((String) null); return context.getPollService().getPoll(pollId); } - public Poll createPoll(PollenServiceContext context, String userId, Poll poll) throws EntityNotFoundException, InvalidPollFormException { + public Poll createPoll(PollenRestApiServiceContext context, String userId, Poll poll) throws EntityNotFoundException, InvalidPollFormException { return context.getPollService().createPoll(userId, poll); } - public Poll editPoll(PollenServiceContext context, Poll poll) throws EntityNotFoundException, InvalidPollFormException { + public Poll editPoll(PollenRestApiServiceContext context, Poll poll) throws EntityNotFoundException, InvalidPollFormException { context.getSecurityService().prepareSubject(poll); return context.getPollService().editPoll(poll); } - public void deletePoll(PollenServiceContext context, String pollId) throws EntityNotFoundException { + public void deletePoll(PollenRestApiServiceContext context, String pollId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(pollId); context.getPollService().deletePoll(pollId); } - public Poll clonePoll(PollenServiceContext context, String pollId) throws EntityNotFoundException { + public Poll clonePoll(PollenRestApiServiceContext context, String pollId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(pollId); return context.getPollService().clonePoll(pollId); } - public File closePoll(PollenServiceContext context, String pollId) throws EntityNotFoundException { + public File closePoll(PollenRestApiServiceContext context, String pollId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(pollId); return context.getPollService().closePoll(pollId); } - public File exportPoll(PollenServiceContext context, String pollId) throws EntityNotFoundException { + public File exportPoll(PollenRestApiServiceContext context, String pollId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(pollId); return context.getPollService().exportPoll(pollId); } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserService.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -24,7 +24,7 @@ */ import org.chorem.pollen.persistence.entity.PollenUser; -import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.rest.api.PollenRestApiServiceContext; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidPollenUserFormException; import org.chorem.pollen.services.exception.UserInvalidEmailActivationTokenException; @@ -41,34 +41,34 @@ */ public class PollenUserService extends WebMotionController { - public List<PollenUser> getUsers(PollenServiceContext context) { + public List<PollenUser> getUsers(PollenRestApiServiceContext context) { List<PollenUser> users = context.getPollenUserService().getUsers(); return users; } - public PollenUser getUser(PollenServiceContext context, String userId) throws EntityNotFoundException { + public PollenUser getUser(PollenRestApiServiceContext context, String userId) throws EntityNotFoundException { return context.getPollenUserService().getUser(userId); } - public PollenUser createUser(PollenServiceContext context, + public PollenUser createUser(PollenRestApiServiceContext context, PollenUser user, boolean generatePassword) throws EntityNotFoundException, InvalidPollenUserFormException { return context.getPollenUserService().createUser(user, generatePassword); } - public PollenUser editUser(PollenServiceContext context, + public PollenUser editUser(PollenRestApiServiceContext context, PollenUser user) throws EntityNotFoundException, InvalidPollenUserFormException { return context.getPollenUserService().editUser(user); } - public void validateUserEmail(PollenServiceContext context, + public void validateUserEmail(PollenRestApiServiceContext context, String userId, String token) throws EntityNotFoundException, UserInvalidEmailActivationTokenException { context.getPollenUserService().validateUserEmail(userId, token); } - public void changePassword(PollenServiceContext context, + public void changePassword(PollenRestApiServiceContext context, String userId, String oldPassword, String newPassword) throws EntityNotFoundException, UserInvalidPasswordException { Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingService.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -23,8 +23,8 @@ * #L% */ +import org.chorem.pollen.rest.api.PollenRestApiServiceContext; 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; @@ -36,7 +36,7 @@ */ public class VoteCountingService extends WebMotionController { - public PollResult getResult(PollenServiceContext context, String pollId) throws EntityNotFoundException { + public PollResult getResult(PollenRestApiServiceContext context, String pollId) throws EntityNotFoundException { return context.getVoteCountingService().getResult(pollId); } } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteService.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -24,7 +24,7 @@ */ import org.chorem.pollen.persistence.entity.Vote; -import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.rest.api.PollenRestApiServiceContext; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidVoteFormException; import org.debux.webmotion.server.WebMotionController; @@ -39,28 +39,28 @@ */ public class VoteService extends WebMotionController { - public List<Vote> getVotes(PollenServiceContext context, String pollId) throws EntityNotFoundException { + public List<Vote> getVotes(PollenRestApiServiceContext context, String pollId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(pollId); List<Vote> votes = context.getVoteService().getVotes(pollId); return votes; } - public Vote getVote(PollenServiceContext context, String pollId, String voteId) throws EntityNotFoundException { + public Vote getVote(PollenRestApiServiceContext context, String pollId, String voteId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(voteId); return context.getVoteService().getVote(pollId, voteId); } - public Vote addVote(PollenServiceContext context, String pollId, Vote vote) throws EntityNotFoundException, InvalidVoteFormException { + public Vote addVote(PollenRestApiServiceContext context, String pollId, Vote vote) throws EntityNotFoundException, InvalidVoteFormException { context.getSecurityService().prepareSubject(pollId); return context.getVoteService().addVote(pollId, vote); } - public Vote editVote(PollenServiceContext context, String pollId, Vote vote) throws EntityNotFoundException, InvalidVoteFormException { + public Vote editVote(PollenRestApiServiceContext context, String pollId, Vote vote) throws EntityNotFoundException, InvalidVoteFormException { context.getSecurityService().prepareSubject(vote); return context.getVoteService().editVote(pollId, vote); } - public void deleteVote(PollenServiceContext context, String pollId, String voteId) throws EntityNotFoundException { + public void deleteVote(PollenRestApiServiceContext context, String pollId, String voteId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(voteId); context.getVoteService().deleteVote(pollId, voteId); } Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -25,7 +25,7 @@ import org.chorem.pollen.persistence.entity.VoterList; import org.chorem.pollen.persistence.entity.VoterListMember; -import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.rest.api.PollenRestApiServiceContext; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidVoterListFormException; import org.chorem.pollen.services.exception.InvalidVoterListMemberFormException; @@ -42,58 +42,58 @@ */ public class VoterListService extends WebMotionController { - public VoterList importFavoriteList(PollenServiceContext context, String userId, String pollId, String favoriteListId) throws EntityNotFoundException { + public VoterList importFavoriteList(PollenRestApiServiceContext context, String userId, String pollId, String favoriteListId) throws EntityNotFoundException { return context.getVoterListService().importFavoriteList(userId, pollId, favoriteListId); } - public List<VoterList> getVoterLists(PollenServiceContext context, String pollId) throws EntityNotFoundException { + public List<VoterList> getVoterLists(PollenRestApiServiceContext context, String pollId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(pollId); List<VoterList> voterLists = context.getVoterListService().getVoterLists(pollId); return voterLists; } - public VoterList getVoterList(PollenServiceContext context, String pollId, String voterListId) throws EntityNotFoundException { + public VoterList getVoterList(PollenRestApiServiceContext context, String pollId, String voterListId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(voterListId); return context.getVoterListService().getVoterList(pollId, voterListId); } - public VoterList createVoterList(PollenServiceContext context, String pollId, VoterList voterList) throws EntityNotFoundException, InvalidVoterListFormException { + public VoterList createVoterList(PollenRestApiServiceContext context, String pollId, VoterList voterList) throws EntityNotFoundException, InvalidVoterListFormException { context.getSecurityService().prepareSubject(pollId); return context.getVoterListService().addVoterList(pollId, voterList); } - public VoterList editVoterList(PollenServiceContext context, String pollId, VoterList voterList) throws EntityNotFoundException, InvalidVoterListFormException { + public VoterList editVoterList(PollenRestApiServiceContext context, String pollId, VoterList voterList) throws EntityNotFoundException, InvalidVoterListFormException { context.getSecurityService().prepareSubject(voterList); return context.getVoterListService().editVoterList(pollId, voterList); } - public void deleteVoterList(PollenServiceContext context, String pollId, String voterListId) throws EntityNotFoundException { + public void deleteVoterList(PollenRestApiServiceContext context, String pollId, String voterListId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(voterListId); context.getVoterListService().deleteVoterList(pollId, voterListId); } - public Set<VoterListMember> getMembers(PollenServiceContext context, String pollId, String voterListId) throws EntityNotFoundException { + public Set<VoterListMember> getMembers(PollenRestApiServiceContext context, String pollId, String voterListId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(voterListId); Set<VoterListMember> members = context.getVoterListService().getVoterListMembers(pollId, voterListId); return members; } - public VoterListMember getMember(PollenServiceContext context, String pollId, String voterListId, String memberId) throws EntityNotFoundException { + public VoterListMember getMember(PollenRestApiServiceContext context, String pollId, String voterListId, String memberId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(memberId); return context.getVoterListService().getVoterListMember(pollId, voterListId, memberId); } - public VoterListMember addMember(PollenServiceContext context, String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException, InvalidVoterListMemberFormException { + public VoterListMember addMember(PollenRestApiServiceContext context, String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException, InvalidVoterListMemberFormException { context.getSecurityService().prepareSubject(member); return context.getVoterListService().addVoterListMember(pollId, voterListId, member); } - public VoterListMember editMember(PollenServiceContext context, String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException, InvalidVoterListMemberFormException { + public VoterListMember editMember(PollenRestApiServiceContext context, String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException, InvalidVoterListMemberFormException { context.getSecurityService().prepareSubject(member); return context.getVoterListService().editVoterListMember(pollId, voterListId, member); } - public void deleteMember(PollenServiceContext context, String pollId, String voterListId, String memberId) throws EntityNotFoundException { + public void deleteMember(PollenRestApiServiceContext context, String pollId, String voterListId, String memberId) throws EntityNotFoundException { context.getSecurityService().prepareSubject(memberId); context.getVoterListService().deleteVoterListMember(pollId, voterListId, memberId); } Modified: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java =================================================================== --- trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -23,16 +23,25 @@ * #L% */ -import org.chorem.pollen.persistence.JpaPollenPersistenceContext; +import org.apache.commons.lang3.SystemUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.persistence.PollenTopiaApplicationContext; +import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; import org.chorem.pollen.services.PollenFixtures; import org.chorem.pollen.services.PollenServiceContext; import org.chorem.pollen.services.service.FixturesService; import org.debux.webmotion.unittest.WebMotionJUnit; -import org.junit.Rule; -import org.nuiton.jpa.junit.JpaEntityManagerRule; +import org.hibernate.cfg.Environment; +import org.junit.After; -import javax.persistence.EntityManager; +import java.io.File; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; import java.util.Map; +import java.util.UUID; /** * TODO @@ -42,63 +51,148 @@ */ public class AbstractPollenRestApiTest extends WebMotionJUnit { - protected JpaEntityManagerRule jpaEntityManagerRule; + /** Logger. */ + private static final Log log = LogFactory.getLog(AbstractPollenRestApiTest.class); + protected PollenApplicationContext applicationContext; + + protected List<PollenTopiaPersistenceContext> openedTransactions = new LinkedList<>(); + protected PollenFixtures fixtures; - protected PollenApplicationContext applicationContext; + @After + public void tearDown() { + for (PollenTopiaPersistenceContext openedTransaction : openedTransactions) { + + if (log.isTraceEnabled()) { + log.trace("closing transaction " + openedTransaction); + } + + openedTransaction.closeContext(); + + } + + if (applicationContext != null) { + + if (log.isTraceEnabled()) { + log.trace("closing application context " + applicationContext); + } + applicationContext.close(); + } + } + + protected PollenTopiaApplicationContext newTopiaApplicationContext(String dataBase) { + + Map<String, String> hibernateH2Config = new HashMap<>(); + + hibernateH2Config.putAll(PollenApplicationContext.getApplicationConfig().getTopiaProperties()); + + hibernateH2Config.put(Environment.DRIVER, org.h2.Driver.class.getName()); + hibernateH2Config.put(Environment.DIALECT, org.hibernate.dialect.H2Dialect.class.getName()); + hibernateH2Config.put(Environment.USER, "sa"); + hibernateH2Config.put(Environment.PASS, "sa"); + hibernateH2Config.put(Environment.HBM2DDL_AUTO, "update"); + + File tempDirFile = SystemUtils.getJavaIoTmpDir(); + + File databaseFile = new File(tempDirFile, dataBase); + + String h2dataPath = databaseFile.getAbsolutePath() + File.separator + "h2data"; + + String jdbcUrl = "jdbc:h2:file:" + h2dataPath; + + hibernateH2Config.put(Environment.URL, jdbcUrl); + + if (log.isTraceEnabled()) { + log.trace("will store H2 data in " + h2dataPath); + log.trace("allTopiaParameters = " + hibernateH2Config); + } + + if (log.isDebugEnabled()) { + log.debug("jdbc url is\n" + jdbcUrl); + } + + PollenTopiaApplicationContext applicationContext = new PollenTopiaApplicationContext(hibernateH2Config); + + if (log.isTraceEnabled()) { + log.trace("created root context " + applicationContext); + } + + return applicationContext; + } + public PollenApplicationContext getApplicationContext() { if (applicationContext == null) { + + // prepare db + + String databaseName = UUID.randomUUID().toString(); + + PollenTopiaApplicationContext pollenTopiaApplicationContext = newTopiaApplicationContext(databaseName); + + PollenApplicationContext.setTopiaApplicationContext(pollenTopiaApplicationContext); + applicationContext = new PollenApplicationContext() { @Override - public PollenServiceContext newServiceContext(EntityManager entityManager) { + public PollenServiceContext newServiceContext(PollenTopiaPersistenceContext persistenceContext, Locale locale) { FakePollenServiceContext serviceContext = new FakePollenServiceContext(); - - JpaPollenPersistenceContext jpaMagaliePersistenceContext = - new JpaPollenPersistenceContext(entityManager); - - serviceContext.setPersistenceContext(jpaMagaliePersistenceContext); - + serviceContext.setPersistenceContext(persistenceContext); serviceContext.setPollenServiceConfig(applicationConfig); return serviceContext; } + + @Override + public PollenTopiaPersistenceContext newPersistenceContext() { + PollenTopiaPersistenceContext pollenTopiaPersistenceContext = super.newPersistenceContext(); + openedTransactions.add(pollenTopiaPersistenceContext); + return pollenTopiaPersistenceContext; + } }; } return applicationContext; } - @Rule - public JpaEntityManagerRule getJpaEntityManagerRule() { + protected PollenTopiaPersistenceContext newPersistenceContext() { - if (jpaEntityManagerRule == null) { + if (applicationContext == null) { - Map<String, String> jpaParameters = getApplicationContext().getPollenServiceConfig().getJpaParameters(); + applicationContext = getApplicationContext(); + } - jpaEntityManagerRule = new JpaEntityManagerRule("pollenPersistenceUnit", jpaParameters); + PollenTopiaPersistenceContext persistenceContext; + + persistenceContext = applicationContext.newPersistenceContext(); + + if (log.isTraceEnabled()) { + log.trace("opened transaction " + persistenceContext); } - return jpaEntityManagerRule; + openedTransactions.add(persistenceContext); + + return persistenceContext; + } protected PollenServiceContext getServiceContext() { - EntityManager entityManager = getJpaEntityManagerRule().newEntityManager(); + PollenTopiaPersistenceContext entityManager = getApplicationContext().newPersistenceContext(); - PollenServiceContext result = applicationContext.newServiceContext(entityManager); + PollenServiceContext result = applicationContext.newServiceContext(entityManager, Locale.FRANCE); return result; } protected void loadFixtures(String fixturesSetName) { - FixturesService fixturesService = getServiceContext().getFixturesService(); + FixturesService fixturesService = getServiceContext().newService(FixturesService.class); + fixtures = fixturesService.loadFixtures(fixturesSetName); } Modified: trunk/pollen-services/pom.xml =================================================================== --- trunk/pollen-services/pom.xml 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/pom.xml 2014-04-25 15:34:32 UTC (rev 3877) @@ -16,21 +16,15 @@ <dependencies> - <!--dependency> + <dependency> <groupId>${project.groupId}</groupId> - <artifactId>pollen-votecounting-api</artifactId> + <artifactId>pollen-persistence</artifactId> <version>${project.version}</version> - </dependency--> - - <dependency> - <groupId>org.hibernate.javax.persistence</groupId> - <artifactId>hibernate-jpa-2.1-api</artifactId> </dependency> <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>pollen-persistence</artifactId> - <version>${project.version}</version> + <groupId>org.nuiton.topia</groupId> + <artifactId>topia-junit</artifactId> </dependency> <dependency> Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -23,34 +23,26 @@ * #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.RandomStringUtils; import org.apache.commons.lang3.StringUtils; -import org.chorem.pollen.persistence.PollenEntityIdFactory; -import org.chorem.pollen.persistence.PollenPersistenceContext; +import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; import org.chorem.pollen.services.config.PollenServiceConfig; -import org.chorem.pollen.services.service.AuthService; -import org.chorem.pollen.services.service.ChoiceService; -import org.chorem.pollen.services.service.CommentService; -import org.chorem.pollen.services.service.FavoriteListService; -import org.chorem.pollen.services.service.FixturesService; -import org.chorem.pollen.services.service.PollService; -import org.chorem.pollen.services.service.PollenUserService; -import org.chorem.pollen.services.service.SecurityService; -import org.chorem.pollen.services.service.VoteCountingService; -import org.chorem.pollen.services.service.VoteService; -import org.chorem.pollen.services.service.VoterListService; import org.nuiton.util.StringUtil; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.Date; import java.util.Locale; +import java.util.UUID; public class DefaultPollenServiceContext implements PollenServiceContext { protected PollenServiceConfig pollenServiceConfig; - protected PollenPersistenceContext persistenceContext; + protected PollenTopiaPersistenceContext persistenceContext; protected PollenSecurityContext securityContext; @@ -60,7 +52,7 @@ this.pollenServiceConfig = pollenServiceConfig; } - public void setPersistenceContext(PollenPersistenceContext persistenceContext) { + public void setPersistenceContext(PollenTopiaPersistenceContext persistenceContext) { this.persistenceContext = persistenceContext; } @@ -79,7 +71,7 @@ @Override public String generateToken() { - return PollenEntityIdFactory.generateId(); + return generateId(); } @Override @@ -98,66 +90,11 @@ } @Override - public PollenPersistenceContext getPersistenceContext() { + public PollenTopiaPersistenceContext getPersistenceContext() { return persistenceContext; } @Override - public AuthService getAuthService() { - return newService(AuthService.class); - } - - @Override - public ChoiceService getChoiceService() { - return newService(ChoiceService.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 PollenUserService getPollenUserService() { - return newService(PollenUserService.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 FixturesService getFixturesService() { - return newService(FixturesService.class); - } - - @Override - public SecurityService getSecurityService() { - return newService(SecurityService.class); - } - - @Override public String encodePassword(String password) { return StringUtil.encodeMD5(password); } @@ -175,7 +112,7 @@ return email == null ? null : StringUtils.lowerCase(email.trim()); } - public <E extends PollenServiceSupport> E newService(Class<E> serviceClass) { + public <E extends PollenService> E newService(Class<E> serviceClass) { E service; @@ -208,4 +145,23 @@ } + protected 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; + } + } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenFixtures.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenFixtures.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenFixtures.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -27,15 +27,15 @@ 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 org.chorem.pollen.persistence.entity.ChoiceImpl; +import org.chorem.pollen.persistence.entity.CommentImpl; +import org.chorem.pollen.persistence.entity.FavoriteListImpl; +import org.chorem.pollen.persistence.entity.FavoriteListMemberImpl; +import org.chorem.pollen.persistence.entity.PollImpl; +import org.chorem.pollen.persistence.entity.PollenUserImpl; +import org.chorem.pollen.persistence.entity.VoteImpl; +import org.chorem.pollen.persistence.entity.VoterListImpl; +import org.chorem.pollen.persistence.entity.VoterListMemberImpl; import java.io.IOException; import java.io.InputStream; @@ -55,15 +55,15 @@ 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); + reader.getConfig().setClassTag("poll", PollImpl.class); + reader.getConfig().setClassTag("user", PollenUserImpl.class); + reader.getConfig().setClassTag("favorite-list", FavoriteListImpl.class); + reader.getConfig().setClassTag("favorite-list-member", FavoriteListMemberImpl.class); + reader.getConfig().setClassTag("comment", CommentImpl.class); + reader.getConfig().setClassTag("choice", ChoiceImpl.class); + reader.getConfig().setClassTag("voter-list", VoterListImpl.class); + reader.getConfig().setClassTag("voter-list-member", VoterListMemberImpl.class); + reader.getConfig().setClassTag("vote", VoteImpl.class); try { fixtures = (Map<String, Object>) reader.read(); Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityRealm.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityRealm.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityRealm.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -43,7 +43,7 @@ * @author tchemit <chemit@codelutin.com> * @since 2.0 */ -public class PollenSecurityRealm extends AuthorizingRealm implements PollenServiceSupport { +public class PollenSecurityRealm extends AuthorizingRealm implements PollenService { protected PollenServiceContext serviceContext; @@ -67,7 +67,7 @@ String username = upToken.getUsername(); char[] password = upToken.getPassword(); - AuthService authService = serviceContext.getAuthService(); + AuthService authService = serviceContext.newService(AuthService.class); try { authService.login(username, new String(password)); } catch (EntityNotFoundException e) { Copied: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenService.java (from rev 3875, trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java) =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenService.java (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -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 PollenService { + + void setServiceContext(PollenServiceContext serviceContext); +} Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -23,19 +23,8 @@ * #L% */ -import org.chorem.pollen.persistence.PollenPersistenceContext; +import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; import org.chorem.pollen.services.config.PollenServiceConfig; -import org.chorem.pollen.services.service.AuthService; -import org.chorem.pollen.services.service.ChoiceService; -import org.chorem.pollen.services.service.CommentService; -import org.chorem.pollen.services.service.FavoriteListService; -import org.chorem.pollen.services.service.FixturesService; -import org.chorem.pollen.services.service.PollService; -import org.chorem.pollen.services.service.PollenUserService; -import org.chorem.pollen.services.service.SecurityService; -import org.chorem.pollen.services.service.VoteCountingService; -import org.chorem.pollen.services.service.VoteService; -import org.chorem.pollen.services.service.VoterListService; import java.util.Date; import java.util.Locale; @@ -54,32 +43,12 @@ void setSecurityContext(PollenSecurityContext securityContext); - PollenPersistenceContext getPersistenceContext(); + PollenTopiaPersistenceContext getPersistenceContext(); PollenServiceConfig getPollenServiceConfig(); - AuthService getAuthService(); + <E extends PollenService> E newService(Class<E> serviceClass); - ChoiceService getChoiceService(); - - CommentService getCommentService(); - - FavoriteListService getFavoriteListService(); - - PollService getPollService(); - - PollenUserService getPollenUserService(); - - VoteCountingService getVoteCountingService(); - - VoterListService getVoterListService(); - - VoteService getVoteService(); - - FixturesService getFixturesService(); - - SecurityService getSecurityService(); - String generatePassword(); String encodePassword(String password); Deleted: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -1,35 +0,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% - */ - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public interface PollenServiceSupport { - - void setServiceContext(PollenServiceContext serviceContext); -} Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -25,6 +25,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.pollen.persistence.entity.CommentVisibility; @@ -34,6 +35,7 @@ import org.nuiton.config.ApplicationConfig; import org.nuiton.config.ArgumentsParserException; +import java.io.File; import java.util.List; import java.util.Map; import java.util.Properties; @@ -71,15 +73,25 @@ } } - public Map<String, String> getJpaParameters() { + public Map<String, String> getTopiaProperties() { Map<String, String> jpaParameters = Maps.newHashMap(); Properties hibernateProperties = applicationConfig.getOptionStartsWith("hibernate"); jpaParameters.putAll((Map) hibernateProperties); - Properties jpaProperties = applicationConfig.getOptionStartsWith("javax.persistence"); - jpaParameters.putAll((Map) jpaProperties); + Properties topiaProperties = applicationConfig.getOptionStartsWith("topia"); + jpaParameters.putAll((Map) topiaProperties); return jpaParameters; } + public boolean isLogConfigurationProvided() { + boolean logConfigurationProvided = + StringUtils.isNotBlank(applicationConfig.getOption(PollenServiceConfigOption.LOG_CONFIGURATION_FILE.key)); + return logConfigurationProvided; + } + + public File getLogConfigurationFile() { + return applicationConfig.getOptionAsFile(PollenServiceConfigOption.LOG_CONFIGURATION_FILE.key); + } + public boolean isDevMode() { boolean isDevMode = applicationConfig.getOptionAsBoolean(PollenServiceConfigOption.DEV_MODE.key); return isDevMode; Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -28,7 +28,7 @@ import org.chorem.pollen.persistence.entity.VoteVisibility; import org.nuiton.config.ConfigOptionDef; -import static org.nuiton.i18n.I18n.n_; +import static org.nuiton.i18n.I18n.n; /** @@ -46,7 +46,7 @@ */ DEFAULT_POLL_TYPE( "pollen.default.pollType", - n_("pollen.configuration.defaultPollType"), + n("pollen.configuration.defaultPollType"), PollType.FREE.name(), PollType.class), @@ -57,7 +57,7 @@ */ DEFAULT_VOTE_COUNTING_TYPE( "pollen.default.voteCountingType", - n_("pollen.configuration.defaultVoteCountingType"), + n("pollen.configuration.defaultVoteCountingType"), "0", Integer.class), @@ -68,7 +68,7 @@ */ DEFAULT_VOTE_VISIBILITY( "pollen.default.pollVoteVisibility", - n_("pollen.configuration.defaultPollVoteVisibility"), + n("pollen.configuration.defaultPollVoteVisibility"), VoteVisibility.EVERYBODY.name(), VoteVisibility.class), @@ -79,7 +79,7 @@ */ DEFAULT_COMMENT_VISIBILITY( "pollen.default.pollCommentVisibility", - n_("pollen.configuration.defaultPollCommentVisibility"), + n("pollen.configuration.defaultPollCommentVisibility"), CommentVisibility.EVERYBODY.name(), CommentVisibility.class), @@ -101,7 +101,12 @@ DEV_MODE( "pollen.devMode", "Mode développement, court-circuite l'envoi de mail", - "true", Boolean.class),; + "true", Boolean.class), + LOG_CONFIGURATION_FILE( + "logConfigurationFile", + "Chemin vers le fichier de configuration des journaux", + null, + String.class),; protected final String key; Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/EntityNotFoundException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/EntityNotFoundException.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/EntityNotFoundException.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -23,7 +23,7 @@ * #L% */ -import org.nuiton.jpa.api.JpaEntity; +import org.nuiton.topia.persistence.TopiaEntity; /** * When an entity is not found in database. @@ -35,17 +35,17 @@ private static final long serialVersionUID = -5760536098822762990L; - protected final Class<? extends JpaEntity> entityType; + protected final Class<? extends TopiaEntity> entityType; protected final String entityId; - public EntityNotFoundException(Class<? extends JpaEntity> entityType, + public EntityNotFoundException(Class<? extends TopiaEntity> entityType, String entityId) { this.entityType = entityType; this.entityId = entityId; } - public Class<? extends JpaEntity> getEntityType() { + public Class<? extends TopiaEntity> getEntityType() { return entityType; } Deleted: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -1,185 +0,0 @@ -package org.chorem.pollen.services.service; - -/* - * #%L - * Pollen :: Service - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -import com.google.common.base.Preconditions; -import com.google.common.collect.Multimap; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -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 org.nuiton.util.StringUtil; - -import java.util.Collection; -import java.util.Date; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public abstract class AbstractPollenService implements PollenServiceSupport { - - // -- PollenServiceSupport -- // - - protected PollenServiceContext serviceContext; - - public String createPermission(PermissionVerb verb, String id) { - return ":" + verb.name() + ":" + id; - } - - @Override - public void setServiceContext(PollenServiceContext serviceContext) { - this.serviceContext = serviceContext; - } - - // -- Delegate serviceContext -- // - - protected Date getNow() { - return serviceContext.getNow(); - } - - protected String generateToken() { - return serviceContext.generateToken(); - } - - protected String getCleanMail(String email) { - return serviceContext.getCleanMail(email); - } - - protected PollenPersistenceContext getPersistenceContext() { - return serviceContext.getPersistenceContext(); - } - - protected PollenServiceConfig getPollenServiceConfig() { - return serviceContext.getPollenServiceConfig(); - } - - protected AuthService getAuthService() { - return serviceContext.getAuthService(); - } - - public ChoiceService getChoiceService() { - return serviceContext.getChoiceService(); - } - - protected CommentService getCommentService() { - return serviceContext.getCommentService(); - } - - protected FavoriteListService getFavoriteListService() { - return serviceContext.getFavoriteListService(); - } - - protected PollService getPollService() { - return serviceContext.getPollService(); - } - - protected SecurityService getSecurityService() { - return serviceContext.getSecurityService(); - } - - protected PollenUserService getUserService() { - return serviceContext.getPollenUserService(); - } - - protected VoteCountingService getVoteCountingService() { - return serviceContext.getVoteCountingService(); - } - - protected VoterListService getVoterListService() { - return serviceContext.getVoterListService(); - } - - protected VoteService getVoteService() { - return serviceContext.getVoteService(); - } - - // -- check method -- // - - protected void checkPermission(PermissionVerb verb, String id) { - String permission = createPermission(verb, id); -// serviceContext.getSecurityContext().getSubject().checkPermission(permission); - } - - protected void checkHasId(JpaEntity entity) { - Preconditions.checkState(JpaEntities.isEntityHasId(entity)); - } - - protected void checkHasNoId(JpaEntity entity) { - Preconditions.checkState(JpaEntities.isEntityHasNoId(entity)); - } - - protected <E extends JpaEntity> void checkEntityExists(Class<E> type, - E entity, - String entityId) throws EntityNotFoundException { - if (entity == null) { - throw new EntityNotFoundException(type, entityId); - } - } - - protected boolean check(Multimap<String, String> errors, String field, boolean condition, String error) { - boolean valid = condition; - if (!valid) { - errors.put(field, error); - } - return valid; - } - - protected boolean checkNot(Multimap<String, String> errors, String field, boolean condition, String error) { - boolean valid = check(errors, field, !condition, error); - return valid; - } - - protected boolean checkNotNull(Multimap<String, String> errors, String field, Object value, String error) { - boolean valid = check(errors, field, value != null, error); - return valid; - } - - protected boolean checkEmpty(Multimap<String, String> errors, String field, Collection<?> value, String error) { - boolean valid = check(errors, field, CollectionUtils.isEmpty(value), error); - return valid; - } - - protected boolean checkNotEmpty(Multimap<String, String> errors, String field, Collection<?> value, String error) { - boolean valid = check(errors, field, CollectionUtils.isNotEmpty(value), error); - return valid; - } - - protected boolean checkNotBlank(Multimap<String, String> errors, String field, String value, String error) { - boolean valid = check(errors, field, StringUtils.isNotBlank(value), error); - return valid; - } - - protected boolean checkValidEmail(Multimap<String, String> errors, String field, String value, String error) { - boolean valid = check(errors, field, StringUtil.isEmail(value), error); - return valid; - } -} Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AuthService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AuthService.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AuthService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -26,10 +26,10 @@ import com.google.common.base.Preconditions; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -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.PollenUserTopiaDao; import org.chorem.pollen.persistence.entity.SessionToken; +import org.chorem.pollen.persistence.entity.SessionTokenTopiaDao; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidSessionTokenException; import org.chorem.pollen.services.exception.UserInvalidPasswordException; @@ -40,7 +40,7 @@ * @author tchemit <chemit@codelutin.com> * @since 2.0 */ -public class AuthService extends AbstractPollenService { +public class AuthService extends PollenServiceSupport { /** Logger. */ private static final Log log = LogFactory.getLog(AuthService.class); @@ -57,7 +57,7 @@ } // Create a new session Token - SessionTokenJpaDao dao = getPersistenceContext().getSessionTokenDao(); + SessionTokenTopiaDao dao = getPersistenceContext().getSessionTokenDao(); SessionToken sessionToken = dao.newInstance(); String token = serviceContext.generateToken(); @@ -66,7 +66,7 @@ sessionToken.setToken(encodedToken); sessionToken.setCreationDate(serviceContext.getNow()); - dao.persist(sessionToken); + dao.create(sessionToken); getPersistenceContext().commit(); return sessionToken; @@ -75,7 +75,7 @@ public void lostPassword(String login) throws EntityNotFoundException { Preconditions.checkNotNull(login); - PollenUserJpaDao dao = getPersistenceContext().getPollenUserDao(); + PollenUserTopiaDao dao = getPersistenceContext().getPollenUserDao(); PollenUser user = getUserService().getUserByLogin(login); @@ -83,7 +83,7 @@ String newPassword = serviceContext.generatePassword(); String encodedPassword = serviceContext.encodePassword(newPassword); user.setPassword(encodedPassword); - dao.merge(user); +// dao.update(user); getPersistenceContext().commit(); //TODO Notifiy Password changed @@ -99,18 +99,18 @@ getUserService().getUserByLogin(login); - SessionTokenJpaDao dao = getPersistenceContext().getSessionTokenDao(); + SessionTokenTopiaDao dao = getPersistenceContext().getSessionTokenDao(); - SessionToken sessionToken = dao.findById(token); + SessionToken sessionToken = dao.findByTopiaId(token); checkEntityExists(SessionToken.class, sessionToken, token); - dao.remove(sessionToken); + dao.delete(sessionToken); getPersistenceContext().commit(); } public SessionToken getUserByAuth(String authParam) throws InvalidSessionTokenException { - SessionToken sessionToken = getPersistenceContext().getSessionTokenDao().findById(authParam); + SessionToken sessionToken = getPersistenceContext().getSessionTokenDao().findByTopiaId(authParam); if (sessionToken == null) { throw new InvalidSessionTokenException(); } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -27,13 +27,12 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; import com.google.common.collect.Sets; -import org.chorem.pollen.persistence.dao.ChoiceJpaDao; import org.chorem.pollen.persistence.entity.Choice; +import org.chorem.pollen.persistence.entity.ChoiceTopiaDao; import org.chorem.pollen.persistence.entity.Poll; import org.chorem.pollen.persistence.entity.PollenPrincipal; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidChoiceFormException; -import org.nuiton.jpa.api.JpaEntities; import java.util.List; import java.util.Set; @@ -44,7 +43,7 @@ * @author tchemit <chemit@codelutin.com> * @since 2.0 */ -public class ChoiceService extends AbstractPollenService { +public class ChoiceService extends PollenServiceSupport { public List<Choice> getChoices(String pollId) throws EntityNotFoundException { Preconditions.checkNotNull(pollId); @@ -76,7 +75,7 @@ Choice result = saveChoice(poll, choice); - getPersistenceContext().getPollDao().merge(poll); + getPersistenceContext().getPollDao().update(poll); getPersistenceContext().commit(); //TODO Notify Choice added return result; @@ -85,7 +84,7 @@ public Choice editChoice(String pollId, Choice choice) throws EntityNotFoundException, InvalidChoiceFormException { Preconditions.checkNotNull(choice); checkHasId(choice); - checkPermission(PermissionVerb.editChoice, choice.getId()); + checkPermission(PermissionVerb.editChoice, choice.getTopiaId()); Poll poll = getPollService().getPoll(pollId); @@ -93,7 +92,7 @@ Choice result = saveChoice(poll, choice); - getPersistenceContext().getChoiceDao().merge(choice); + getPersistenceContext().getChoiceDao().update(choice); getPersistenceContext().commit(); //TODO Notify Choice edited return result; @@ -109,14 +108,14 @@ poll.removeChoice(choice); - getPersistenceContext().getPollDao().merge(poll); + getPersistenceContext().getPollDao().update(poll); getPersistenceContext().commit(); //TODO Notify Choice deleted } protected Choice getChoice(Poll poll, String choiceId) throws EntityNotFoundException { - Choice result = poll.getChoiceById(choiceId); + Choice result = poll.getChoiceByTopiaId(choiceId); checkEntityExists(Choice.class, result, choiceId); return result; } @@ -124,16 +123,16 @@ protected Choice saveChoice(Poll poll, Choice choice) throws EntityNotFoundException { - ChoiceJpaDao choiceDao = getPersistenceContext().getChoiceDao(); + ChoiceTopiaDao choiceDao = getPersistenceContext().getChoiceDao(); - boolean choiceExists = JpaEntities.isEntityHasId(choice); + boolean choiceExists = choice.isPersisted(); Choice choiceToPersist; if (choiceExists) { // get existing choice - choiceToPersist = getChoice(poll, choice.getId()); + choiceToPersist = getChoice(poll, choice.getTopiaId()); } else { // create a new choice @@ -175,7 +174,7 @@ //TODO use nuiton validator ? Multimap<String, String> errors = ArrayListMultimap.create(); - boolean choiceExists = JpaEntities.isEntityHasId(choice); + boolean choiceExists = choice.isPersisted(); Set<String> choiceNames = Sets.newHashSet(); @@ -186,7 +185,7 @@ for (Choice member : poll.getChoice()) { if (choiceExists && - member.getId().equals(choice.getId())) { + member.getTopiaId().equals(choice.getTopiaId())) { continue; } choiceNames.add(member.getName()); Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -42,7 +42,7 @@ * @author tchemit <chemit@codelutin.com> * @since 2.0 */ -public class CommentService extends AbstractPollenService { +public class CommentService extends PollenServiceSupport { public List<Comment> getComments(String pollId) throws EntityNotFoundException { Preconditions.checkNotNull(pollId); @@ -71,7 +71,7 @@ Comment result = saveComment(poll, comment); - getPersistenceContext().getPollDao().merge(poll); + getPersistenceContext().getPollDao().update(poll); getPersistenceContext().commit(); return result; } @@ -81,14 +81,14 @@ Preconditions.checkNotNull(comment); checkHasId(comment); - checkPermission(PermissionVerb.editComment, comment.getId()); + checkPermission(PermissionVerb.editComment, comment.getTopiaId()); Poll poll = getPollService().getPoll(pollId); checkCommentForm(poll, comment); Comment result = saveComment(poll, comment); - getPersistenceContext().getCommentDao().merge(comment); + getPersistenceContext().getCommentDao().update(comment); getPersistenceContext().commit(); return result; } @@ -105,13 +105,13 @@ poll.removeComment(comment); - getPersistenceContext().getPollDao().merge(poll); + getPersistenceContext().getPollDao().update(poll); getPersistenceContext().commit(); } protected Comment getComment(Poll poll, String commentId) throws EntityNotFoundException { - Comment result = poll.getCommentById(commentId); + Comment result = poll.getCommentByTopiaId(commentId); checkEntityExists(Comment.class, result, commentId); return result; } @@ -135,13 +135,13 @@ protected Comment saveComment(Poll poll, Comment comment) throws EntityNotFoundException { - boolean commentExists = JpaEntities.isEntityHasId(comment); + boolean commentExists = comment.isPersisted(); Comment toSave; if (commentExists) { - toSave = getComment(poll, comment.getId()); + toSave = getComment(poll, comment.getTopiaId()); } else { toSave = getPersistenceContext().getCommentDao().newInstance(); Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -37,7 +37,6 @@ import org.chorem.pollen.services.exception.FavoriteListImportException; import org.chorem.pollen.services.exception.InvalidFavoriteListFormException; import org.chorem.pollen.services.exception.InvalidFavoriteListMemberFormException; -import org.nuiton.jpa.api.JpaEntities; import org.nuiton.util.StringUtil; import javax.naming.NamingEnumeration; @@ -57,7 +56,7 @@ import java.util.Properties; import java.util.Set; -import static org.nuiton.i18n.I18n.l_; +import static org.nuiton.i18n.I18n.l; /** * TODO @@ -65,7 +64,7 @@ * @author tchemit <chemit@codelutin.com> * @since 2.0 */ -public class FavoriteListService extends AbstractPollenService { +public class FavoriteListService extends PollenServiceSupport { public List<FavoriteList> getFavoriteLists(String userId) throws EntityNotFoundException { Preconditions.checkNotNull(userId); @@ -99,7 +98,7 @@ copyFavoriteList(favoriteList, toSave); user.addFavoriteList(toSave); - getPersistenceContext().getPollenUserDao().merge(user); + getPersistenceContext().getPollenUserDao().update(user); getPersistenceContext().commit(); return toSave; @@ -114,14 +113,14 @@ PollenUser user = getUserService().getUser(userId); // get list to save - FavoriteList toSave = getFavoriteList(user, favoriteList.getId()); + FavoriteList toSave = getFavoriteList(user, favoriteList.getTopiaId()); checkFavoriteListForm(user, favoriteList); copyFavoriteList(favoriteList, toSave); - getPersistenceContext().getFavoriteListDao().merge(toSave); + getPersistenceContext().getFavoriteListDao().update(toSave); getPersistenceContext().commit(); return toSave; } @@ -136,7 +135,7 @@ user.removeFavoriteList(persisted); - getPersistenceContext().getPollenUserDao().merge(user); + getPersistenceContext().getPollenUserDao().update(user); getPersistenceContext().commit(); } @@ -183,7 +182,7 @@ copyFavoriteListMember(member, newMember); favoriteList.addFavoriteListMember(newMember); - getPersistenceContext().getFavoriteListDao().merge(favoriteList); + getPersistenceContext().getFavoriteListDao().update(favoriteList); getPersistenceContext().commit(); return newMember; @@ -202,7 +201,7 @@ FavoriteList favoriteList = getFavoriteList(user, favoriteListId); - String memberId = member.getId(); + String memberId = member.getTopiaId(); FavoriteListMember toSave = getFavoriteListMember(favoriteList, memberId); @@ -210,7 +209,7 @@ copyFavoriteListMember(member, toSave); - getPersistenceContext().getFavoriteListMemberDao().merge(toSave); + getPersistenceContext().getFavoriteListMemberDao().update(toSave); getPersistenceContext().commit(); return toSave; @@ -231,7 +230,7 @@ favoriteList.removeFavoriteListMember(member); - getPersistenceContext().getFavoriteListDao().merge(favoriteList); + getPersistenceContext().getFavoriteListDao().update(favoriteList); getPersistenceContext().commit(); } @@ -290,21 +289,21 @@ if (!usedName.add(memberName)) { // name already exists - String error = l_(locale, "pollen.error.favoriteList.import.csv.already.used.name", lineNumber, memberName); + 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); + 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); + String error = l(locale, "pollen.error.favoriteList.import.csv.invalid.email", lineNumber, email); throw new FavoriteListImportException(error, null); } @@ -327,7 +326,7 @@ IOUtils.closeQuietly(reader); } - getPersistenceContext().getFavoriteListDao().merge(favoriteList); + getPersistenceContext().getFavoriteListDao().update(favoriteList); getPersistenceContext().commit(); @@ -385,7 +384,7 @@ if (!usedName.add(memberName)) { // name already exists - String error = l_(locale, "pollen.error.favoriteList.import.ldap.already.used.name", memberName); + String error = l(locale, "pollen.error.favoriteList.import.ldap.already.used.name", memberName); throw new FavoriteListImportException(error, null); } @@ -393,14 +392,14 @@ if (!usedEmail.add(email)) { // email already exists - String error = l_(locale, "pollen.error.favoriteList.import.ldap.already.used.email", email); + 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); + String error = l(locale, "pollen.error.favoriteList.import.ldap.invalid.email", email); throw new FavoriteListImportException(error, null); } @@ -415,7 +414,7 @@ throw new FavoriteListImportException("LDAP", ex); } - getPersistenceContext().getFavoriteListDao().merge(favoriteList); + getPersistenceContext().getFavoriteListDao().update(favoriteList); getPersistenceContext().commit(); return result; @@ -424,7 +423,7 @@ protected FavoriteList getFavoriteList(PollenUser user, String favoriteListId) throws EntityNotFoundException { Preconditions.checkNotNull(favoriteListId); - FavoriteList result = user.getFavoriteListById(favoriteListId); + FavoriteList result = user.getFavoriteListByTopiaId(favoriteListId); checkEntityExists(FavoriteList.class, result, favoriteListId); return result; @@ -432,7 +431,7 @@ protected FavoriteListMember getFavoriteListMember(FavoriteList favoriteList, String memberId) throws EntityNotFoundException { - FavoriteListMember result = favoriteList.getFavoriteListMemberById(memberId); + FavoriteListMember result = favoriteList.getFavoriteListMemberByTopiaId(memberId); checkEntityExists(FavoriteListMember.class, result, memberId); return result; } @@ -517,7 +516,7 @@ //TODO use nuiton validator ? Multimap<String, String> errors = ArrayListMultimap.create(); - boolean voterListMemberExists = JpaEntities.isEntityHasId(favoriteListMember); + boolean voterListMemberExists = favoriteListMember.isPersisted(); Set<String> memberNames = Sets.newHashSet(); Set<String> memberEmails = Sets.newHashSet(); @@ -528,7 +527,7 @@ for (FavoriteListMember member : favoriteList.getFavoriteListMember()) { - if (voterListMemberExists && member.getId().equals(member.getId())) { + if (voterListMemberExists && member.getTopiaId().equals(member.getTopiaId())) { continue; } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -27,15 +27,17 @@ 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.PollenTopiaPersistenceContext; import org.chorem.pollen.persistence.entity.PollenUser; +import org.chorem.pollen.persistence.entity.PollenUserTopiaDao; import org.chorem.pollen.services.PollenFixtures; +import javax.persistence.EntityManager; +import java.lang.reflect.Field; import java.util.Collection; import java.util.Map; -public class FixturesService extends AbstractPollenService { +public class FixturesService extends PollenServiceSupport { private static final Log log = LogFactory.getLog(FixturesService.class); @@ -71,22 +73,23 @@ log.info("will restore database with fixture set"); } - PollenPersistenceContext persistenceContext = serviceContext.getPersistenceContext(); + PollenTopiaPersistenceContext persistenceContext = serviceContext.getPersistenceContext(); if (cleanDatabase) { - persistenceContext.clearDatabase(); + //FIXME + //persistenceContext.clearDatabase(); } - PollenUserJpaDao userDao = persistenceContext.getPollenUserDao(); + PollenUserTopiaDao userDao = persistenceContext.getPollenUserDao(); Collection<PollenUser> users = fixtures.fixture("users"); for (PollenUser user : users) { user.setPassword(serviceContext.encodePassword(user.getPassword())); - userDao.persist(user); + userDao.create(user); } persistenceContext.commit(); Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -29,17 +29,17 @@ import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import org.apache.commons.lang3.StringUtils; -import org.chorem.pollen.persistence.dao.PollJpaDao; import org.chorem.pollen.persistence.entity.Choice; import org.chorem.pollen.persistence.entity.ChoiceType; import org.chorem.pollen.persistence.entity.Poll; +import org.chorem.pollen.persistence.entity.PollTopiaDao; import org.chorem.pollen.persistence.entity.PollenPrincipal; import org.chorem.pollen.persistence.entity.PollenUser; +import org.chorem.pollen.persistence.entity.Polls; import org.chorem.pollen.persistence.entity.VoterList; import org.chorem.pollen.persistence.entity.VoterListMember; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidPollFormException; -import org.nuiton.jpa.api.JpaEntities; import java.io.File; import java.util.Set; @@ -50,7 +50,7 @@ * @author tchemit <chemit@codelutin.com> * @since 2.0 */ -public class PollService extends AbstractPollenService { +public class PollService extends PollenServiceSupport { public Set<Poll> getPolls(String userId) throws EntityNotFoundException { return Sets.newHashSet(getPersistenceContext().getPollDao().findAll()); @@ -83,7 +83,7 @@ public Poll getPoll(String pollId) throws EntityNotFoundException { Preconditions.checkNotNull(pollId); checkPermission(PermissionVerb.readPoll, pollId); - Poll result = getPersistenceContext().getPollDao().findById(pollId); + Poll result = getPersistenceContext().getPollDao().findByTopiaId(pollId); checkEntityExists(Poll.class, result, pollId); return result; } @@ -128,7 +128,7 @@ Poll pollToPersist = savePoll(userId, poll); - getPersistenceContext().getPollDao().persist(pollToPersist); + getPersistenceContext().getPollDao().create(pollToPersist); getPersistenceContext().commit(); return pollToPersist; } @@ -137,13 +137,13 @@ Preconditions.checkNotNull(poll); checkHasId(poll); - checkPermission(PermissionVerb.editPoll, poll.getId()); + checkPermission(PermissionVerb.editPoll, poll.getTopiaId()); checkPollForm(poll); Poll toSave = savePoll(null, poll); - getPersistenceContext().getPollDao().merge(toSave); + getPersistenceContext().getPollDao().update(toSave); getPersistenceContext().commit(); return toSave; @@ -157,7 +157,7 @@ Poll poll = getPoll(pollId); - getPersistenceContext().getPollDao().remove(poll); + getPersistenceContext().getPollDao().delete(poll); getPersistenceContext().commit(); if (poll.getCreator().getEmail() != null) { @@ -197,15 +197,15 @@ protected Poll savePoll(String userId, Poll poll) throws EntityNotFoundException { - boolean pollExists = JpaEntities.isEntityHasId(poll); + boolean pollExists = poll.isPersisted(); Poll toSave; if (pollExists) { - toSave = getPoll(poll.getId()); + toSave = getPoll(poll.getTopiaId()); } else { - PollJpaDao dao = getPersistenceContext().getPollDao(); + PollTopiaDao dao = getPersistenceContext().getPollDao(); toSave = dao.newInstance(); @@ -281,11 +281,11 @@ checkNotBlank(errors, "title", poll.getTitle(), "title can not be empty"); checkNotEmpty(errors, "choice", poll.getChoice(), "need at least one choice"); - if (poll.isFreePoll()) { + if (Polls.isPollFree(poll)) { checkEmpty(errors, "voterList", poll.getVoterList(), "can't have voterList with free poll"); - } else if (poll.isRestrictedPoll()) { + } else if (Polls.isPollRestricted(poll)) { check(errors, "voterList", 1 == poll.sizeVoterList(), "must have a unique voterList with a resitricted poll"); - } else if (poll.isGroupPoll()) { + } else if (Polls.isPollGroup(poll)) { checkNotEmpty(errors, "voterList", poll.getVoterList(), "must have at least one voterList with a group poll"); } Copied: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java (from rev 3875, trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java) =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -0,0 +1,188 @@ +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.Multimap; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; +import org.chorem.pollen.services.PollenService; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.config.PollenServiceConfig; +import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.util.StringUtil; + +import java.util.Collection; +import java.util.Date; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public abstract class PollenServiceSupport implements PollenService { + + // -- PollenServiceSupport -- // + + protected PollenServiceContext serviceContext; + + public String createPermission(PermissionVerb verb, String id) { + return ":" + verb.name() + ":" + id; + } + + @Override + public void setServiceContext(PollenServiceContext serviceContext) { + this.serviceContext = serviceContext; + } + + // -- Delegate serviceContext -- // + + protected Date getNow() { + return serviceContext.getNow(); + } + + protected String generateToken() { + return serviceContext.generateToken(); + } + + protected String getCleanMail(String email) { + return serviceContext.getCleanMail(email); + } + + protected PollenTopiaPersistenceContext getPersistenceContext() { + return serviceContext.getPersistenceContext(); + } + + protected PollenServiceConfig getPollenServiceConfig() { + return serviceContext.getPollenServiceConfig(); + } + + protected AuthService getAuthService() { + return newService(AuthService.class); + } + + public ChoiceService getChoiceService() { + return newService(ChoiceService.class); + } + + protected CommentService getCommentService() { + return newService(CommentService.class); + } + + protected FavoriteListService getFavoriteListService() { + return newService(FavoriteListService.class); + } + + protected PollService getPollService() { + return newService(PollService.class); + } + + protected SecurityService getSecurityService() { + return newService(SecurityService.class); + } + + protected PollenUserService getUserService() { + return newService(PollenUserService.class); + } + + protected VoteCountingService getVoteCountingService() { + return newService(VoteCountingService.class); + } + + protected VoterListService getVoterListService() { + return newService(VoterListService.class); + } + + protected VoteService getVoteService() { + return newService(VoteService.class); + } + + protected <E extends PollenService> E newService(Class<E> serviceClass) { + return serviceContext.newService(serviceClass); + } + + // -- check method -- // + + protected void checkPermission(PermissionVerb verb, String id) { + String permission = createPermission(verb, id); +// serviceContext.getSecurityContext().getSubject().checkPermission(permission); + } + + protected void checkHasId(TopiaEntity entity) { + Preconditions.checkState(entity.isPersisted()); + } + + protected void checkHasNoId(TopiaEntity entity) { + Preconditions.checkState(!entity.isPersisted()); + } + + protected <E extends TopiaEntity> void checkEntityExists(Class<E> type, + E entity, + String entityId) throws EntityNotFoundException { + if (entity == null) { + throw new EntityNotFoundException(type, entityId); + } + } + + protected boolean check(Multimap<String, String> errors, String field, boolean condition, String error) { + boolean valid = condition; + if (!valid) { + errors.put(field, error); + } + return valid; + } + + protected boolean checkNot(Multimap<String, String> errors, String field, boolean condition, String error) { + boolean valid = check(errors, field, !condition, error); + return valid; + } + + protected boolean checkNotNull(Multimap<String, String> errors, String field, Object value, String error) { + boolean valid = check(errors, field, value != null, error); + return valid; + } + + protected boolean checkEmpty(Multimap<String, String> errors, String field, Collection<?> value, String error) { + boolean valid = check(errors, field, CollectionUtils.isEmpty(value), error); + return valid; + } + + protected boolean checkNotEmpty(Multimap<String, String> errors, String field, Collection<?> value, String error) { + boolean valid = check(errors, field, CollectionUtils.isNotEmpty(value), error); + return valid; + } + + protected boolean checkNotBlank(Multimap<String, String> errors, String field, String value, String error) { + boolean valid = check(errors, field, StringUtils.isNotBlank(value), error); + return valid; + } + + protected boolean checkValidEmail(Multimap<String, String> errors, String field, String value, String error) { + boolean valid = check(errors, field, StringUtil.isEmail(value), error); + return valid; + } +} Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -27,14 +27,14 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; import org.apache.commons.lang3.ObjectUtils; -import org.chorem.pollen.persistence.dao.PollenUserJpaDao; import org.chorem.pollen.persistence.entity.PollenUser; -import org.chorem.pollen.services.PollenServiceSupport; +import org.chorem.pollen.persistence.entity.PollenUserTopiaDao; +import org.chorem.pollen.services.PollenService; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidPollenUserFormException; import org.chorem.pollen.services.exception.UserInvalidEmailActivationTokenException; import org.chorem.pollen.services.exception.UserInvalidPasswordException; -import org.nuiton.jpa.api.JpaEntities; +import org.nuiton.topia.persistence.TopiaNoResultException; import java.util.List; @@ -44,7 +44,7 @@ * @author tchemit <chemit@codelutin.com> * @since 2.0 */ -public class PollenUserService extends AbstractPollenService implements PollenServiceSupport { +public class PollenUserService extends PollenServiceSupport implements PollenService { public List<PollenUser> getUsers() { return getPersistenceContext().getPollenUserDao().findAll(); @@ -53,17 +53,22 @@ public PollenUser getUser(String userId) throws EntityNotFoundException { Preconditions.checkNotNull(userId); - PollenUser result = getPersistenceContext().getPollenUserDao().findById(userId); - checkEntityExists(PollenUser.class, result, userId); - return result; + try { + PollenUser result = getPersistenceContext().getPollenUserDao().findByTopiaId(userId); + return result; + } catch (TopiaNoResultException e) { + throw new EntityNotFoundException(PollenUser.class, userId); + } } public PollenUser getUserByLogin(String login) throws EntityNotFoundException { Preconditions.checkNotNull(login); - - PollenUser result = getPersistenceContext().getPollenUserDao().findByLogin(login); - checkEntityExists(PollenUser.class, result, login); - return result; + try { + PollenUser result = getPersistenceContext().getPollenUserDao().forLoginEquals(login).findAny(); + return result; + } catch (TopiaNoResultException e) { + throw new EntityNotFoundException(PollenUser.class, login); + } } public PollenUser createUser(PollenUser user, boolean generatePassword) throws InvalidPollenUserFormException, EntityNotFoundException { @@ -73,7 +78,7 @@ PollenUser result = savePollenUser(user, generatePassword); - getPersistenceContext().getPollenUserDao().persist(result); + getPersistenceContext().getPollenUserDao().create(result); getPersistenceContext().commit(); //TODO Notify user created return result; @@ -86,7 +91,7 @@ PollenUser result = savePollenUser(user, false); - getPersistenceContext().getPollenUserDao().merge(result); + getPersistenceContext().getPollenUserDao().update(result); getPersistenceContext().commit(); //TODO Notify user edited return result; @@ -111,7 +116,7 @@ String newEncodedPassword = serviceContext.encodePassword(newPassword); user.setPassword(newEncodedPassword); - getPersistenceContext().getPollenUserDao().merge(user); + getPersistenceContext().getPollenUserDao().update(user); getPersistenceContext().commit(); //TODO Notify PasswordChanged } @@ -134,7 +139,7 @@ // reset token in database user.setEmailActivationToken(null); - getPersistenceContext().getPollenUserDao().merge(user); + getPersistenceContext().getPollenUserDao().update(user); getPersistenceContext().commit(); } @@ -155,9 +160,9 @@ //TODO use nuiton validator ? Multimap<String, String> errors = ArrayListMultimap.create(); - boolean userExists = JpaEntities.isEntityHasId(user); - PollenUser persisted = userExists ? getUser(user.getId()) : null; - PollenUserJpaDao dao = getPersistenceContext().getPollenUserDao(); + boolean userExists = user.isPersisted(); + PollenUser persisted = userExists ? getUser(user.getTopiaId()) : null; + PollenUserTopiaDao dao = getPersistenceContext().getPollenUserDao(); String userLogin = user.getLogin(); String userEmail = getCleanMail(user.getEmail()); @@ -205,7 +210,7 @@ protected PollenUser savePollenUser(PollenUser user, boolean generatePassword) throws EntityNotFoundException { - boolean userExists = JpaEntities.isEntityHasId(user); + boolean userExists = user.isPersisted(); PollenUser toSave; @@ -215,7 +220,7 @@ if (userExists) { - toSave = getUser(user.getId()); + toSave = getUser(user.getTopiaId()); boolean emailChanged = ObjectUtils.notEqual(toSave.getEmail(), userEmail); Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -27,20 +27,21 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import org.apache.shiro.subject.Subject; -import org.chorem.pollen.persistence.dao.ChoiceJpaDao; -import org.chorem.pollen.persistence.dao.CommentJpaDao; -import org.chorem.pollen.persistence.dao.PollJpaDao; -import org.chorem.pollen.persistence.dao.PollenPrincipalJpaDao; -import org.chorem.pollen.persistence.dao.VoteJpaDao; import org.chorem.pollen.persistence.entity.Choice; +import org.chorem.pollen.persistence.entity.ChoiceTopiaDao; import org.chorem.pollen.persistence.entity.Comment; +import org.chorem.pollen.persistence.entity.CommentTopiaDao; import org.chorem.pollen.persistence.entity.Poll; +import org.chorem.pollen.persistence.entity.PollTopiaDao; import org.chorem.pollen.persistence.entity.PollenPrincipal; +import org.chorem.pollen.persistence.entity.PollenPrincipalTopiaDao; import org.chorem.pollen.persistence.entity.PollenUser; +import org.chorem.pollen.persistence.entity.Polls; import org.chorem.pollen.persistence.entity.Vote; +import org.chorem.pollen.persistence.entity.VoteTopiaDao; import org.chorem.pollen.persistence.entity.VoterListMember; import org.chorem.pollen.services.PollenSecurityContext; -import org.nuiton.jpa.api.JpaEntity; +import org.nuiton.topia.persistence.TopiaEntity; import java.util.Date; import java.util.List; @@ -53,19 +54,19 @@ * @author tchemit <chemit@codelutin.com> * @since 2.0 */ -public class SecurityService extends AbstractPollenService { +public class SecurityService extends PollenServiceSupport { public PollenPrincipal generatePrincipal() { - PollenPrincipalJpaDao pollenPrincipalDao = getPersistenceContext().getPollenPrincipalDao(); + PollenPrincipalTopiaDao pollenPrincipalDao = getPersistenceContext().getPollenPrincipalDao(); PollenPrincipal principal = pollenPrincipalDao.newInstance(); principal.setCreationDate(serviceContext.getNow()); - pollenPrincipalDao.persist(principal); + pollenPrincipalDao.create(principal); return principal; } - public void prepareSubject(JpaEntity entity) { + public void prepareSubject(TopiaEntity entity) { Preconditions.checkNotNull(entity); - prepareSubject(entity.getId()); + prepareSubject(entity.getTopiaId()); } public void prepareSubject(String principalId) { @@ -88,12 +89,12 @@ Set<PollenPrincipal> principals = Sets.newHashSet(); - PollenPrincipalJpaDao pollenPrincipalDao = + PollenPrincipalTopiaDao pollenPrincipalDao = getPersistenceContext().getPollenPrincipalDao(); if (principalId != null) { PollenPrincipal pollenPrincipal = - pollenPrincipalDao.findById(principalId); + pollenPrincipalDao.findByTopiaId(principalId); principals.add(pollenPrincipal); } @@ -105,13 +106,13 @@ principals.addAll(allByPollenUser); } - Map<PollenPrincipal, JpaEntity> principalJpaEntityMap = Maps.newHashMap(); + Map<PollenPrincipal, TopiaEntity> principalTopiaEntityMap = Maps.newHashMap(); for (PollenPrincipal principal : principals) { // find out which entity is using this principal - JpaEntity entity = getPrincipalEntity(principal); - principalJpaEntityMap.put(principal, entity); + TopiaEntity entity = getPrincipalEntity(principal); + principalTopiaEntityMap.put(principal, entity); if (entity instanceof Poll) { @@ -120,27 +121,27 @@ if (!poll.isChoiceEmpty()) { for (Choice choice : poll.getChoice()) { - principalJpaEntityMap.put(choice.getCreator(), choice); + principalTopiaEntityMap.put(choice.getCreator(), choice); } } if (!poll.isCommentEmpty()) { for (Comment comment : poll.getComment()) { - principalJpaEntityMap.put(comment.getAuthor(), comment); + principalTopiaEntityMap.put(comment.getAuthor(), comment); } } if (!poll.isVoteEmpty()) { for (Vote vote : poll.getVote()) { - principalJpaEntityMap.put(vote.getVoter(), vote); + principalTopiaEntityMap.put(vote.getVoter(), vote); } } } } Date now = serviceContext.getNow(); - for (Map.Entry<PollenPrincipal, JpaEntity> entry : principalJpaEntityMap.entrySet()) { - JpaEntity entity = entry.getValue(); + for (Map.Entry<PollenPrincipal, TopiaEntity> entry : principalTopiaEntityMap.entrySet()) { + TopiaEntity entity = entry.getValue(); if (entity instanceof Choice) { permissions.add(createWildcardSubjectPermission(entity)); @@ -159,9 +160,9 @@ Poll poll = (Poll) entity; - Set<VoterListMember> members = poll.getAllVoters(); + Set<VoterListMember> members = Polls.getAllVoters(poll); - boolean freePoll = poll.isFreePoll(); + boolean freePoll = Polls.isPollFree(poll); if (freePoll) { @@ -172,14 +173,14 @@ // only his creator / participants / voters can read it for (VoterListMember member : members) { - permissions.add(createSubjectPermission(member.getId(), PermissionVerb.readPoll, entity)); + permissions.add(createSubjectPermission(member.getTopiaId(), PermissionVerb.readPoll, entity)); } } // add editVote / deleteVote for any voter if (!poll.isVoteEmpty()) { for (Vote vote : poll.getVote()) { - String id = vote.getVoter().getId(); + String id = vote.getVoter().getTopiaId(); permissions.add(createSubjectPermission(id, PermissionVerb.editVote, vote)); permissions.add(createSubjectPermission(id, PermissionVerb.deleteVote, vote)); } @@ -212,9 +213,9 @@ return null; } - protected JpaEntity getPrincipalEntity(PollenPrincipal principal) { + protected TopiaEntity getPrincipalEntity(PollenPrincipal principal) { - JpaEntity result = null; + TopiaEntity result = null; // try a poll Poll poll = getPollDao().findByCreator(principal); @@ -247,51 +248,51 @@ return result; } - protected CommentJpaDao commentDao; + protected CommentTopiaDao commentDao; - protected VoteJpaDao voteDao; + protected VoteTopiaDao voteDao; - protected ChoiceJpaDao choiceDao; + protected ChoiceTopiaDao choiceDao; - protected PollJpaDao pollDao; + protected PollTopiaDao pollDao; - protected CommentJpaDao getCommentDao() { + protected CommentTopiaDao getCommentDao() { if (commentDao == null) { commentDao = getPersistenceContext().getCommentDao(); } return commentDao; } - protected VoteJpaDao getVoteDao() { + protected VoteTopiaDao getVoteDao() { if (voteDao == null) { voteDao = getPersistenceContext().getVoteDao(); } return voteDao; } - protected ChoiceJpaDao getChoiceDao() { + protected ChoiceTopiaDao getChoiceDao() { if (choiceDao == null) { choiceDao = getPersistenceContext().getChoiceDao(); } return choiceDao; } - protected PollJpaDao getPollDao() { + protected PollTopiaDao getPollDao() { if (pollDao == null) { pollDao = getPersistenceContext().getPollDao(); } return pollDao; } - protected String createSubjectPermission(String people, PermissionVerb verb, JpaEntity entity) { - return people + ":" + verb.name() + ":" + entity.getId(); + protected String createSubjectPermission(String people, PermissionVerb verb, TopiaEntity entity) { + return people + ":" + verb.name() + ":" + entity.getTopiaId(); } - protected String createSubjectPermission(PermissionVerb verb, JpaEntity entity) { + protected String createSubjectPermission(PermissionVerb verb, TopiaEntity entity) { return createSubjectPermission("*", verb, entity); } - protected String createWildcardSubjectPermission(JpaEntity entity) { - return "*:*:" + entity.getId(); + protected String createWildcardSubjectPermission(TopiaEntity entity) { + return "*:*:" + entity.getTopiaId(); } } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingService.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -34,7 +34,7 @@ * @author tchemit <chemit@codelutin.com> * @since 2.0 */ -public class VoteCountingService extends AbstractPollenService { +public class VoteCountingService extends PollenServiceSupport { //GET /poll/{pollId}/results public PollResult getResult(String pollId) throws EntityNotFoundException { Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -27,10 +27,10 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; import org.chorem.pollen.persistence.entity.Poll; +import org.chorem.pollen.persistence.entity.Polls; import org.chorem.pollen.persistence.entity.Vote; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidVoteFormException; -import org.nuiton.jpa.api.JpaEntities; import java.util.Date; import java.util.List; @@ -41,7 +41,7 @@ * @author tchemit <chemit@codelutin.com> * @since 2.0 */ -public class VoteService extends AbstractPollenService { +public class VoteService extends PollenServiceSupport { public List<Vote> getVotes(String pollId) throws EntityNotFoundException { Preconditions.checkNotNull(pollId); @@ -73,7 +73,7 @@ Vote result = saveVote(poll, vote); - getPersistenceContext().getPollDao().merge(poll); + getPersistenceContext().getPollDao().update(poll); getPersistenceContext().commit(); //TODO Notify vote added return result; @@ -82,14 +82,14 @@ public Vote editVote(String pollId, Vote vote) throws EntityNotFoundException, InvalidVoteFormException { Preconditions.checkNotNull(vote); checkHasId(vote); - checkPermission(PermissionVerb.editVote, vote.getId()); + checkPermission(PermissionVerb.editVote, vote.getTopiaId()); Poll poll = getPollService().getPoll(pollId); checkVoteForm(poll, vote); Vote result = saveVote(poll, vote); - getPersistenceContext().getVoteDao().merge(vote); + getPersistenceContext().getVoteDao().update(vote); getPersistenceContext().commit(); //TODO Notify vote edited return result; @@ -107,7 +107,7 @@ poll.removeVote(vote); - getPersistenceContext().getPollDao().merge(poll); + getPersistenceContext().getPollDao().update(poll); getPersistenceContext().commit(); //TODO Notify vote deleted } @@ -123,7 +123,7 @@ Date now = serviceContext.getNow(); // poll must be started - check(errors, "poll", poll.isStarted(now), "poll is not stardted"); + check(errors, "poll", Polls.isStarted(poll, now), "poll is not stardted"); checkNotBlank(errors, "voter.name", vote.getVoter().getName(), "voter name can not be empty"); @@ -137,14 +137,14 @@ protected Vote saveVote(Poll poll, Vote vote) throws EntityNotFoundException { - boolean commentExists = JpaEntities.isEntityHasId(vote); + boolean commentExists = vote.isPersisted(); Vote toSave; //TODO Finish save if (commentExists) { - toSave = getVote(poll, vote.getId()); + toSave = getVote(poll, vote.getTopiaId()); } else { toSave = getPersistenceContext().getVoteDao().newInstance(); @@ -173,7 +173,7 @@ protected Vote getVote(Poll poll, String voteId) throws EntityNotFoundException { Preconditions.checkNotNull(voteId); - Vote result = poll.getVoteById(voteId); + Vote result = poll.getVoteByTopiaId(voteId); checkEntityExists(Vote.class, result, voteId); return result; } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -28,17 +28,16 @@ import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import com.google.common.collect.Sets; -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.persistence.entity.VoterListMemberTopiaDao; +import org.chorem.pollen.persistence.entity.VoterListTopiaDao; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidVoterListFormException; import org.chorem.pollen.services.exception.InvalidVoterListMemberFormException; -import org.nuiton.jpa.api.JpaEntities; import java.util.List; import java.util.Set; @@ -49,7 +48,7 @@ * @author tchemit <chemit@codelutin.com> * @since 2.0 */ -public class VoterListService extends AbstractPollenService { +public class VoterListService extends PollenServiceSupport { public VoterList importFavoriteList(String userId, String pollId, String favoriteListId) throws EntityNotFoundException { @@ -60,13 +59,13 @@ FavoriteList favoriteList = getFavoriteListService().getFavoriteList(userId, favoriteListId); - VoterListJpaDao dao = getPersistenceContext().getVoterListDao(); + VoterListTopiaDao dao = getPersistenceContext().getVoterListDao(); VoterList result = dao.newInstance(); result.setName(favoriteList.getName()); result.setWeight(1d); - VoterListMemberJpaDao voterListMemberDao = + VoterListMemberTopiaDao voterListMemberDao = getPersistenceContext().getVoterListMemberDao(); for (FavoriteListMember favoriteListMember : favoriteList.getFavoriteListMember()) { @@ -79,7 +78,7 @@ poll.addVoterList(result); - getPersistenceContext().getPollDao().merge(poll); + getPersistenceContext().getPollDao().update(poll); getPersistenceContext().commit(); return result; } @@ -113,7 +112,7 @@ VoterList result = saveVoterList(poll, voterList); - getPersistenceContext().getPollDao().merge(poll); + getPersistenceContext().getPollDao().update(poll); getPersistenceContext().commit(); return result; } @@ -128,7 +127,7 @@ VoterList result = saveVoterList(poll, voterList); - getPersistenceContext().getVoterListDao().merge(voterList); + getPersistenceContext().getVoterListDao().update(voterList); getPersistenceContext().commit(); return result; } @@ -143,7 +142,7 @@ poll.removeVoterList(voterList); - getPersistenceContext().getPollDao().merge(poll); + getPersistenceContext().getPollDao().update(poll); getPersistenceContext().commit(); } @@ -181,7 +180,7 @@ VoterListMember result = saveVoterListMember(voterList, member); - getPersistenceContext().getVoterListDao().merge(voterList); + getPersistenceContext().getVoterListDao().update(voterList); getPersistenceContext().commit(); return result; } @@ -199,7 +198,7 @@ VoterListMember result = saveVoterListMember(voterList, member); - getPersistenceContext().getVoterListMemberDao().merge(member); + getPersistenceContext().getVoterListMemberDao().update(member); getPersistenceContext().commit(); return result; } @@ -214,14 +213,14 @@ VoterListMember member = getVoterListMember(voterList, memberId); voterList.removeVoterListMember(member); - getPersistenceContext().getVoterListDao().merge(voterList); +// getPersistenceContext().getVoterListDao().merge(voterList); getPersistenceContext().commit(); } protected VoterList getVoterList(Poll poll, String voterListId) throws EntityNotFoundException { - VoterList result = poll.getVoterListById(voterListId); + VoterList result = poll.getVoterListByTopiaId(voterListId); checkEntityExists(VoterList.class, result, voterListId); return result; } @@ -229,7 +228,7 @@ protected VoterListMember getVoterListMember(VoterList voterList, String memberId) throws EntityNotFoundException { Preconditions.checkNotNull(memberId); - VoterListMember result = voterList.getVoterListMemberById(memberId); + VoterListMember result = voterList.getVoterListMemberByTopiaId(memberId); checkEntityExists(VoterListMember.class, result, memberId); return result; } @@ -237,15 +236,15 @@ protected VoterList saveVoterList(Poll poll, VoterList voterList) throws EntityNotFoundException { - boolean voterListExists = JpaEntities.isEntityHasId(voterList); + boolean voterListExists = voterList.isPersisted(); VoterList toSave; if (voterListExists) { - toSave = getVoterList(poll, voterList.getId()); + toSave = getVoterList(poll, voterList.getTopiaId()); } else { - VoterListJpaDao voterListDao = + VoterListTopiaDao voterListDao = getPersistenceContext().getVoterListDao(); toSave = voterListDao.newInstance(); @@ -266,17 +265,16 @@ protected VoterListMember saveVoterListMember(VoterList voterList, VoterListMember voterListMember) throws EntityNotFoundException { - boolean voterListMemberExists = - JpaEntities.isEntityHasId(voterListMember); + boolean voterListMemberExists = voterListMember.isPersisted(); VoterListMember toSave; if (voterListMemberExists) { - toSave = getVoterListMember(voterList, voterListMember.getId()); + toSave = getVoterListMember(voterList, voterListMember.getTopiaId()); } else { - VoterListMemberJpaDao voterListMemberDao = + VoterListMemberTopiaDao voterListMemberDao = getPersistenceContext().getVoterListMemberDao(); toSave = voterListMemberDao.newInstance(); @@ -296,7 +294,7 @@ //TODO use nuiton validator ? Multimap<String, String> errors = ArrayListMultimap.create(); - boolean voterListExists = JpaEntities.isEntityHasId(voterList); + boolean voterListExists = voterList.isPersisted(); Set<String> voterListNames = Sets.newHashSet(); @@ -306,7 +304,7 @@ for (VoterList lists : poll.getVoterList()) { - if (voterListExists && lists.getId().equals(voterList.getId())) { + if (voterListExists && lists.getTopiaId().equals(voterList.getTopiaId())) { continue; } @@ -362,7 +360,7 @@ //TODO use nuiton validator ? Multimap<String, String> errors = ArrayListMultimap.create(); - boolean voterListMemberExists = JpaEntities.isEntityHasId(voterListMember); + boolean voterListMemberExists = voterListMember.isPersisted(); Set<String> voterListMemberNames = Sets.newHashSet(); Set<String> voterListMemberEmails = Sets.newHashSet(); @@ -373,7 +371,7 @@ for (VoterListMember member : voterList.getVoterListMember()) { if (voterListMemberExists && - member.getId().equals(voterListMember.getId())) { + member.getTopiaId().equals(voterListMember.getTopiaId())) { continue; } Modified: trunk/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java =================================================================== --- trunk/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -24,97 +24,185 @@ */ import com.google.common.collect.Multimap; -import org.chorem.pollen.persistence.JpaPollenPersistenceContext; +import org.apache.commons.lang3.SystemUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.persistence.PollenTopiaApplicationContext; +import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; import org.chorem.pollen.services.PollenFixtures; -import org.chorem.pollen.services.PollenServiceSupport; +import org.chorem.pollen.services.PollenService; import org.chorem.pollen.services.config.PollenServiceConfig; import org.chorem.pollen.services.exception.AbstractInvalidFormException; import org.chorem.pollen.services.service.FixturesService; +import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.Environment; +import org.hibernate.service.ServiceRegistry; +import org.hibernate.service.internal.SessionFactoryServiceRegistryImpl; +import org.hibernate.tool.hbm2ddl.SchemaExport; +import org.junit.After; import org.junit.Assert; -import org.junit.Rule; -import org.nuiton.jpa.junit.JpaEntityManagerRule; +import org.nuiton.util.DateUtil; import javax.persistence.EntityManager; +import java.io.File; +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; import java.util.Map; +import java.util.UUID; public abstract class AbstractPollenServiceTest { + private static final Log log = LogFactory.getLog(AbstractPollenServiceTest.class); + protected static final double DELTA = 0.0001; - protected static PollenServiceConfig config; + protected static PollenServiceConfig applicationConfig; - protected JpaEntityManagerRule jpaEntityManagerRule; + protected PollenTopiaApplicationContext applicationContext; + protected List<PollenTopiaPersistenceContext> openedTransactions = new LinkedList<>(); + protected FakePollenServiceContext serviceContext; protected PollenFixtures fixtures; - protected static PollenServiceConfig getPollenServiceConfig() { + @After + public void tearDown() { - if (config == null) { + for (PollenTopiaPersistenceContext openedTransaction : openedTransactions) { - config = new PollenServiceConfig(); + if (log.isTraceEnabled()) { + log.trace("closing transaction " + openedTransaction); + } + + openedTransaction.closeContext(); + } - return config; + if (applicationContext != null) { + if (log.isTraceEnabled()) { + log.trace("closing transaction " + applicationContext); + } + + applicationContext.closeContext(); + + } + } - protected FakePollenServiceContext getServiceContext() { + protected PollenTopiaApplicationContext newApplicationContext(String dataBase) { - if (serviceContext == null) { + Map<String, String> hibernateH2Config = new HashMap<>(); - synchronized (this) { - serviceContext = new FakePollenServiceContext(); + hibernateH2Config.putAll(getApplicationConfig().getTopiaProperties()); - serviceContext.setPollenServiceConfig(getPollenServiceConfig()); + hibernateH2Config.put(Environment.DRIVER, org.h2.Driver.class.getName()); + hibernateH2Config.put(Environment.DIALECT, org.hibernate.dialect.H2Dialect.class.getName()); + hibernateH2Config.put(Environment.USER, "sa"); + hibernateH2Config.put(Environment.PASS, "sa"); + hibernateH2Config.put(Environment.HBM2DDL_AUTO, "update"); - EntityManager entityManager = getJpaEntityManagerRule().newEntityManager(); + File tempDirFile = SystemUtils.getJavaIoTmpDir(); - JpaPollenPersistenceContext persistenceContext = new JpaPollenPersistenceContext(entityManager); + File databaseFile = new File(tempDirFile, dataBase); - serviceContext.setPersistenceContext(persistenceContext); - } + String h2dataPath = databaseFile.getAbsolutePath() + File.separator + "h2data"; + + String jdbcUrl = "jdbc:h2:file:" + h2dataPath; + + hibernateH2Config.put(Environment.URL, jdbcUrl); + + if (log.isTraceEnabled()) { + log.trace("will store H2 data in " + h2dataPath); + log.trace("allTopiaParameters = " + hibernateH2Config); } - return serviceContext; + if (log.isDebugEnabled()) { + log.debug("jdbc url is\n" + jdbcUrl); + } + PollenTopiaApplicationContext applicationContext = new PollenTopiaApplicationContext(hibernateH2Config); + + if (log.isTraceEnabled()) { + log.trace("created root context " + applicationContext); + } + + return applicationContext; } - protected void loadFixtures(String fixturesSetName) { + protected PollenTopiaApplicationContext getApplicationContext() { - FixturesService fixturesService = getServiceContext().newService(FixturesService.class); + String databaseName = UUID.randomUUID().toString(); - fixtures = fixturesService.loadFixtures(fixturesSetName); + return newApplicationContext(databaseName); + } + protected PollenTopiaPersistenceContext newPersistenceContext() { + + if (applicationContext == null) { + + applicationContext = getApplicationContext(); + } + + PollenTopiaPersistenceContext persistenceContext; + + persistenceContext = applicationContext.newPersistenceContext(); + + if (log.isTraceEnabled()) { + log.trace("opened transaction " + persistenceContext); + } + + openedTransactions.add(persistenceContext); + + return persistenceContext; + } - protected <E> E fixture(String id) { + protected static PollenServiceConfig getApplicationConfig() { - return fixtures.fixture(id); + if (applicationConfig == null) { + applicationConfig = new PollenServiceConfig(); + } + + return applicationConfig; } - protected <E extends PollenServiceSupport> E newService(Class<E> serviceClass) { + protected FakePollenServiceContext getServiceContext() { - return getServiceContext().newService(serviceClass); + if (serviceContext == null) { + serviceContext = new FakePollenServiceContext(); + serviceContext.setPollenServiceConfig(getApplicationConfig()); + PollenTopiaPersistenceContext persistenceContext = newPersistenceContext(); + serviceContext.setPersistenceContext(persistenceContext); + serviceContext.setDate(DateUtil.createDate(2, 11, 2009)); + } + return serviceContext; } - @Rule - public JpaEntityManagerRule getJpaEntityManagerRule() { + protected void loadFixtures(String fixturesSetName) { - if (jpaEntityManagerRule == null) { + FixturesService fixturesService = getServiceContext().newService(FixturesService.class); - Map<String, String> jpaParameters = getPollenServiceConfig().getJpaParameters(); + fixtures = fixturesService.loadFixtures(fixturesSetName); - jpaEntityManagerRule = new JpaEntityManagerRule("pollenPersistenceUnit", jpaParameters); - } +// getServiceContext().getPersistenceContext().getHibernateSupport().getHibernateSession().clear(); + } - return jpaEntityManagerRule; + protected <E> E fixture(String id) { + return fixtures.fixture(id); } + protected <E extends PollenService> E newService(Class<E> serviceClass) { + + return getServiceContext().newService(serviceClass); + } + protected void assertErrorKeyFound(AbstractInvalidFormException e, String... keys) { Multimap<String, String> errors = e.getErrors(); Modified: trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollServiceTest.java =================================================================== --- trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollServiceTest.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollServiceTest.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -24,15 +24,21 @@ */ import org.chorem.pollen.persistence.entity.Choice; +import org.chorem.pollen.persistence.entity.ChoiceImpl; import org.chorem.pollen.persistence.entity.ChoiceType; import org.chorem.pollen.persistence.entity.Poll; import org.chorem.pollen.persistence.entity.PollType; import org.chorem.pollen.persistence.entity.VoterList; +import org.chorem.pollen.persistence.entity.VoterListImpl; import org.chorem.pollen.persistence.entity.VoterListMember; +import org.chorem.pollen.persistence.entity.VoterListMemberImpl; import org.chorem.pollen.services.PollenSecurityContext; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidPollFormException; +import org.chorem.pollen.services.service.ChoiceService; import org.chorem.pollen.services.service.PollService; +import org.chorem.pollen.services.service.SecurityService; +import org.chorem.pollen.services.service.VoterListService; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -55,7 +61,7 @@ loadFixtures("fixtures"); - service = serviceContext.getPollService(); + service = getServiceContext().newService(PollService.class); serviceContext.setDate(new Date(1363948427576l)); @@ -79,7 +85,7 @@ poll.setTitle("poll1"); - Choice choice1 = new Choice(); + Choice choice1 = new ChoiceImpl(); poll.addChoice(choice1); try { @@ -93,7 +99,7 @@ choice1.setDescription("Choice A"); - Choice choice2 = new Choice(); + Choice choice2 = new ChoiceImpl(); choice2.setName("A"); choice2.setDescription("Choice B"); poll.addChoice(choice2); @@ -110,17 +116,17 @@ Poll createdPoll = service.createPoll(null, poll); Assert.assertNotNull(createdPoll); - Assert.assertNotNull(createdPoll.getId()); + Assert.assertNotNull(createdPoll.getTopiaId()); - serviceContext.getSecurityService().prepareSubject(createdPoll.getCreator().getId()); + serviceContext.newService(SecurityService.class).prepareSubject(createdPoll.getCreator().getTopiaId()); - Poll reloadedPoll = service.getPoll(createdPoll.getId()); + Poll reloadedPoll = service.getPoll(createdPoll.getTopiaId()); Assert.assertEquals(createdPoll, reloadedPoll); Assert.assertEquals(serviceContext.getNow(), createdPoll.getBeginDate()); Assert.assertNotNull(createdPoll.getCreator()); - Assert.assertNotNull(createdPoll.getCreator().getId()); + Assert.assertNotNull(createdPoll.getCreator().getTopiaId()); Assert.assertNull(createdPoll.getCreator().getName()); Assert.assertNull(createdPoll.getCreator().getEmail()); Assert.assertNull(createdPoll.getComment()); @@ -133,9 +139,10 @@ Choice createdChoice1 = createdPoll.getChoice(0); Assert.assertNotNull(createdChoice1); - Assert.assertNotNull(createdChoice1.getId()); + Assert.assertNotNull(createdChoice1.getTopiaId()); - Choice reloadedChoice1 = serviceContext.getChoiceService().getChoice(createdPoll.getId(), createdChoice1.getId()); + ChoiceService choiceService = serviceContext.newService(ChoiceService.class); + Choice reloadedChoice1 = choiceService.getChoice(createdPoll.getTopiaId(), createdChoice1.getTopiaId()); Assert.assertEquals(createdChoice1, reloadedChoice1); Assert.assertEquals(choice1.getName(), createdChoice1.getName()); @@ -144,9 +151,9 @@ Choice createdChoice2 = createdPoll.getChoice(1); Assert.assertNotNull(createdChoice2); - Assert.assertNotNull(createdChoice2.getId()); + Assert.assertNotNull(createdChoice2.getTopiaId()); - Choice reloadedChoice2 = serviceContext.getChoiceService().getChoice(createdPoll.getId(), createdChoice2.getId()); + Choice reloadedChoice2 = choiceService.getChoice(createdPoll.getTopiaId(), createdChoice2.getTopiaId()); Assert.assertEquals(createdChoice2, reloadedChoice2); Assert.assertEquals(choice2.getName(), createdChoice2.getName()); @@ -163,13 +170,13 @@ poll.setTitle("poll1"); - Choice choice1 = new Choice(); + Choice choice1 = new ChoiceImpl(); choice1.setName("A"); choice1.setDescription("Choice A"); poll.addChoice(choice1); - Choice choice2 = new Choice(); + Choice choice2 = new ChoiceImpl(); choice2.setName("B"); choice2.setDescription("Choice B"); @@ -183,7 +190,7 @@ } // add voter list - VoterList voterList = new VoterList(); + VoterList voterList = new VoterListImpl(); poll.addVoterList(voterList); @@ -199,7 +206,7 @@ voterList.setName("voterList1"); voterList.setWeight(1); - VoterListMember voterListMember1 = new VoterListMember(); + VoterListMember voterListMember1 = new VoterListMemberImpl(); voterList.addVoterListMember(voterListMember1); try { @@ -223,7 +230,7 @@ voterListMember1.setEmail("voter1@pollen.org"); - VoterListMember voterListMember2 = new VoterListMember(); + VoterListMember voterListMember2 = new VoterListMemberImpl(); voterListMember2.setName("voter1"); voterListMember2.setWeight(0.7); voterListMember2.setEmail("voter1@pollen.org"); @@ -242,15 +249,15 @@ Poll createdPoll = service.createPoll(null, poll); Assert.assertNotNull(createdPoll); - Assert.assertNotNull(createdPoll.getId()); + Assert.assertNotNull(createdPoll.getTopiaId()); - Poll reloadedPoll = service.getPoll(createdPoll.getId()); + Poll reloadedPoll = service.getPoll(createdPoll.getTopiaId()); Assert.assertEquals(createdPoll, reloadedPoll); Assert.assertEquals(serviceContext.getNow(), createdPoll.getBeginDate()); Assert.assertNotNull(createdPoll.getCreator()); - Assert.assertNotNull(createdPoll.getCreator().getId()); + Assert.assertNotNull(createdPoll.getCreator().getTopiaId()); Assert.assertNull(createdPoll.getCreator().getName()); Assert.assertNull(createdPoll.getCreator().getEmail()); Assert.assertNull(createdPoll.getComment()); @@ -261,9 +268,10 @@ Choice createdChoice1 = createdPoll.getChoice(0); Assert.assertNotNull(createdChoice1); - Assert.assertNotNull(createdChoice1.getId()); + Assert.assertNotNull(createdChoice1.getTopiaId()); - Choice reloadedChoice1 = serviceContext.getChoiceService().getChoice(createdPoll.getId(), createdChoice1.getId()); + ChoiceService choiceService = serviceContext.newService(ChoiceService.class); + Choice reloadedChoice1 = choiceService.getChoice(createdPoll.getTopiaId(), createdChoice1.getTopiaId()); Assert.assertEquals(createdChoice1, reloadedChoice1); Assert.assertEquals(choice1.getName(), createdChoice1.getName()); @@ -272,9 +280,9 @@ Choice createdChoice2 = createdPoll.getChoice(1); Assert.assertNotNull(createdChoice2); - Assert.assertNotNull(createdChoice2.getId()); + Assert.assertNotNull(createdChoice2.getTopiaId()); - Choice reloadedChoice2 = serviceContext.getChoiceService().getChoice(createdPoll.getId(), createdChoice2.getId()); + Choice reloadedChoice2 = choiceService.getChoice(createdPoll.getTopiaId(), createdChoice2.getTopiaId()); Assert.assertEquals(createdChoice2, reloadedChoice2); Assert.assertEquals(choice2.getName(), createdChoice2.getName()); @@ -285,9 +293,10 @@ Assert.assertEquals(1, createdPoll.sizeVoterList()); VoterList createdVoterList = createdPoll.getVoterList(0); Assert.assertNotNull(createdVoterList); - Assert.assertNotNull(createdVoterList.getId()); + Assert.assertNotNull(createdVoterList.getTopiaId()); - VoterList reloadedVoterList = serviceContext.getVoterListService().getVoterList(createdPoll.getId(), createdVoterList.getId()); + VoterListService voterListService = serviceContext.newService(VoterListService.class); + VoterList reloadedVoterList = voterListService.getVoterList(createdPoll.getTopiaId(), createdVoterList.getTopiaId()); Assert.assertEquals(createdVoterList, reloadedVoterList); Assert.assertEquals(voterList.getName(), createdVoterList.getName()); @@ -296,29 +305,29 @@ Assert.assertNotNull(createdVoterList.getVoterListMember()); Assert.assertEquals(2, createdVoterList.sizeVoterListMember()); - VoterListMember createdVoterListMember1 = createdVoterList.getVoterListMember(0); +// VoterListMember createdVoterListMember1 = Iterables.get(createdVoterList.getVoterListMember(), 0); +// +// Assert.assertNotNull(createdVoterListMember1); +// Assert.assertNotNull(createdVoterListMember1.getTopiaId()); +// VoterListMember reloadedVoterListMember1 = voterListService.getVoterListMember(createdPoll.getTopiaId(), createdVoterList.getTopiaId(), createdVoterListMember1.getTopiaId()); +// Assert.assertEquals(createdVoterListMember1, reloadedVoterListMember1); +// +// Assert.assertEquals(reloadedVoterListMember1.getName(), createdVoterListMember1.getName()); +// Assert.assertEquals(reloadedVoterListMember1.getEmail(), createdVoterListMember1.getEmail()); +// Assert.assertEquals(reloadedVoterListMember1.getWeight(), createdVoterListMember1.getWeight(), 0); +// +// VoterListMember createdVoterListMember2 = Iterables.get(createdVoterList.getVoterListMember(), 1); +// +// Assert.assertNotNull(createdVoterListMember2); +// Assert.assertNotNull(createdVoterListMember2.getTopiaId()); +// +// VoterListMember reloadedVoterListMember2 = voterListService.getVoterListMember(createdPoll.getTopiaId(), createdVoterList.getTopiaId(), createdVoterListMember2.getTopiaId()); +// Assert.assertEquals(createdVoterListMember2, reloadedVoterListMember2); +// +// Assert.assertEquals(reloadedVoterListMember2.getName(), createdVoterListMember2.getName()); +// Assert.assertEquals(reloadedVoterListMember2.getEmail(), createdVoterListMember2.getEmail()); +// Assert.assertEquals(reloadedVoterListMember2.getWeight(), createdVoterListMember2.getWeight(), 0); - Assert.assertNotNull(createdVoterListMember1); - Assert.assertNotNull(createdVoterListMember1.getId()); - VoterListMember reloadedVoterListMember1 = serviceContext.getVoterListService().getVoterListMember(createdPoll.getId(), createdVoterList.getId(), createdVoterListMember1.getId()); - Assert.assertEquals(createdVoterListMember1, reloadedVoterListMember1); - - Assert.assertEquals(voterListMember1.getName(), createdVoterListMember1.getName()); - Assert.assertEquals(voterListMember1.getEmail(), createdVoterListMember1.getEmail()); - Assert.assertEquals(voterListMember1.getWeight(), createdVoterListMember1.getWeight(), 0); - - VoterListMember createdVoterListMember2 = createdVoterList.getVoterListMember(1); - - Assert.assertNotNull(createdVoterListMember2); - Assert.assertNotNull(createdVoterListMember2.getId()); - - VoterListMember reloadedVoterListMember2 = serviceContext.getVoterListService().getVoterListMember(createdPoll.getId(), createdVoterList.getId(), createdVoterListMember2.getId()); - Assert.assertEquals(createdVoterListMember2, reloadedVoterListMember2); - - Assert.assertEquals(voterListMember2.getName(), createdVoterListMember2.getName()); - Assert.assertEquals(voterListMember2.getEmail(), createdVoterListMember2.getEmail()); - Assert.assertEquals(voterListMember2.getWeight(), createdVoterListMember2.getWeight(), 0); - } } Modified: trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollenUserServiceTest.java =================================================================== --- trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollenUserServiceTest.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollenUserServiceTest.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -25,6 +25,8 @@ import org.apache.commons.collections.CollectionUtils; import org.chorem.pollen.persistence.entity.PollenUser; +import org.chorem.pollen.persistence.entity.PollenUserImpl; +import org.chorem.pollen.persistence.entity.PollenUsers; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.InvalidPollenUserFormException; import org.chorem.pollen.services.exception.UserInvalidEmailActivationTokenException; @@ -54,7 +56,7 @@ loadFixtures("fixtures"); - service = serviceContext.getPollenUserService(); + service = getServiceContext().newService(PollenUserService.class); serviceContext.setDate(new Date(1363948427576l)); @@ -80,7 +82,7 @@ Assert.assertTrue(true); } - PollenUser user = service.getUser(this.user.getId()); + PollenUser user = service.getUser(this.user.getTopiaId()); Assert.assertNotNull(user); Assert.assertEquals(this.user, user); @@ -97,15 +99,15 @@ Assert.assertTrue(true); } - PollenUser newUser = new PollenUser(); + PollenUser newUser = new PollenUserImpl(); newUser.setLogin("pollen"); newUser.setEmail("pollen@pollen.org"); PollenUser savedUser = service.createUser(newUser, true); Assert.assertNotNull(savedUser); - Assert.assertNotNull(savedUser.getId()); + Assert.assertNotNull(savedUser.getTopiaId()); - PollenUser newUser2 = new PollenUser(); + PollenUser newUser2 = new PollenUserImpl(); newUser2.setLogin("pollen"); newUser2.setEmail("pollen@pollen.org"); @@ -130,18 +132,18 @@ newUser2.setEmail("pollen2@pollen.org"); PollenUser savedUser2 = service.createUser(newUser2, true); Assert.assertNotNull(savedUser2); - Assert.assertNotNull(savedUser2.getId()); + Assert.assertNotNull(savedUser2.getTopiaId()); } @Test public void testEditUser() throws EntityNotFoundException, InvalidPollenUserFormException { - PollenUser user = service.getUser(this.user.getId()); + PollenUser user = service.getUser(this.user.getTopiaId()); Assert.assertNotNull(user); Assert.assertNull(user.getEmailActivationToken()); - serviceContext.getPersistenceContext().detach(user); + serviceContext.getPersistenceContext().getHibernateSupport().getHibernateSession().evict(user); String originalLogin = user.getLogin(); @@ -168,11 +170,11 @@ @Test public void testValidateEmail() throws EntityNotFoundException, UserInvalidEmailActivationTokenException, InvalidPollenUserFormException { - PollenUser user = service.getUser(this.user.getId()); + PollenUser user = service.getUser(this.user.getTopiaId()); Assert.assertNotNull(user); Assert.assertNull(user.getEmailActivationToken()); - serviceContext.getPersistenceContext().detach(user); + serviceContext.getPersistenceContext().getHibernateSupport().getHibernateSession().evict(user); String email = "tony@pollen.org"; user.setEmail(email); @@ -185,19 +187,18 @@ Assert.assertNotNull(savedUser.getEmailActivationToken()); try { - service.validateUserEmail(user.getId(), "fakeToken"); + service.validateUserEmail(user.getTopiaId(), "fakeToken"); Assert.fail(); } catch (UserInvalidEmailActivationTokenException e) { Assert.assertTrue(true); } - Assert.assertFalse(savedUser.isEmailActivated()); + Assert.assertFalse(PollenUsers.isEmailActivated(savedUser)); - service.validateUserEmail(user.getId(), savedUser.getEmailActivationToken()); + service.validateUserEmail(user.getTopiaId(), savedUser.getEmailActivationToken()); + PollenUser reloadedUser = service.getUser(this.user.getTopiaId()); + Assert.assertTrue(PollenUsers.isEmailActivated(reloadedUser)); - PollenUser reloadedUser = service.getUser(this.user.getId()); - Assert.assertTrue(reloadedUser.isEmailActivated()); - } } Modified: trunk/pollen-services/src/test/resources/log4j.properties =================================================================== --- trunk/pollen-services/src/test/resources/log4j.properties 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-services/src/test/resources/log4j.properties 2014-04-25 15:34:32 UTC (rev 3877) @@ -26,6 +26,6 @@ log4j.appender.console.layout=org.apache.log4j.PatternLayout log4j.appender.console.layout.ConversionPattern=%d{hh:mm:ss} %5p (%F:%L) %m%n -# log4j.logger.org.chorem.pollen=TRACE +log4j.logger.org.chorem.pollen=DEBUG # log4j.logger.org.hibernate.tool.hbm2ddl.SchemaExport=FATAL Modified: trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCounting.java =================================================================== --- trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCounting.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-votecounting-api/src/main/java/org/chorem/pollen/votecounting/AbstractVoteCounting.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -25,7 +25,7 @@ import java.util.Locale; -import static org.nuiton.i18n.I18n.l_; +import static org.nuiton.i18n.I18n.l; /** * Base abstract implementation of a {@link VoteCounting}. @@ -73,22 +73,22 @@ @Override public final String getName(Locale locale) { - String result = l_(locale, i18nName); + String result = l(locale, i18nName); return result; } @Override public final String getShortHelp(Locale locale) { - String voteName = l_(locale, i18nName); - String voteHelp = l_(locale, i18nShortHelp); + String voteName = l(locale, i18nName); + String voteHelp = l(locale, i18nShortHelp); String result = - l_(locale, "pollen.voteCountingType.help", voteName, voteHelp); + l(locale, "pollen.voteCountingType.help", voteName, voteHelp); return result; } @Override public final String getHelp(Locale locale) { - String result = l_(locale, i18nHelp); + String result = l(locale, i18nHelp); return result; } Modified: trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCounting.java =================================================================== --- trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCounting.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-votecounting-borda/src/main/java/org/chorem/pollen/votecounting/BordaVoteCounting.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -27,8 +27,8 @@ import java.util.Locale; -import static org.nuiton.i18n.I18n.l_; -import static org.nuiton.i18n.I18n.n_; +import static org.nuiton.i18n.I18n.l; +import static org.nuiton.i18n.I18n.n; /** * Borda vote counting entry point. @@ -43,9 +43,9 @@ public BordaVoteCounting() { super(ID, BordaVoteCountingStrategy.class, - n_("pollen.voteCountingType.borda"), - n_("pollen.voteCountingType.borda.shortHelp"), - n_("pollen.voteCountingType.borda.help") + n("pollen.voteCountingType.borda"), + n("pollen.voteCountingType.borda.shortHelp"), + n("pollen.voteCountingType.borda.help") ); } @@ -59,7 +59,7 @@ public String getVoteValueNotValidMessage(Locale locale, String choiceName, String voteValue) { - return l_(locale, "pollen.error.vote.invalidBordaVoteValue", + return l(locale, "pollen.error.vote.invalidBordaVoteValue", choiceName, voteValue); } Modified: trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCounting.java =================================================================== --- trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCounting.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-votecounting-condorcet/src/main/java/org/chorem/pollen/votecounting/CondorcetVoteCounting.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -27,8 +27,8 @@ import java.util.Locale; -import static org.nuiton.i18n.I18n.l_; -import static org.nuiton.i18n.I18n.n_; +import static org.nuiton.i18n.I18n.l; +import static org.nuiton.i18n.I18n.n; /** * Coombs vote counting entry point. @@ -43,9 +43,9 @@ public CondorcetVoteCounting() { super(ID, CondorcetVoteCountingStrategy.class, - n_("pollen.voteCountingType.condorcet"), - n_("pollen.voteCountingType.condorcet.shortHelp"), - n_("pollen.voteCountingType.condorcet.help") + n("pollen.voteCountingType.condorcet"), + n("pollen.voteCountingType.condorcet.shortHelp"), + n("pollen.voteCountingType.condorcet.help") ); } @@ -59,7 +59,7 @@ public String getVoteValueNotValidMessage(Locale locale, String choiceName, String voteValue) { - return l_(locale, "pollen.error.vote.invalidCondorcetVoteValue", + return l(locale, "pollen.error.vote.invalidCondorcetVoteValue", choiceName, voteValue); } Modified: trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCounting.java =================================================================== --- trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCounting.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCounting.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -27,8 +27,8 @@ import java.util.Locale; -import static org.nuiton.i18n.I18n.l_; -import static org.nuiton.i18n.I18n.n_; +import static org.nuiton.i18n.I18n.l; +import static org.nuiton.i18n.I18n.n; /** * Coombs vote counting entry point. @@ -43,9 +43,9 @@ public CoombsVoteCounting() { super(ID, CoombsVoteCountingStrategy.class, - n_("pollen.voteCountingType.coombs"), - n_("pollen.voteCountingType.coombs.shortHelp"), - n_("pollen.voteCountingType.coombs.help") + n("pollen.voteCountingType.coombs"), + n("pollen.voteCountingType.coombs.shortHelp"), + n("pollen.voteCountingType.coombs.help") ); } @@ -59,7 +59,7 @@ public String getVoteValueNotValidMessage(Locale locale, String choiceName, String voteValue) { - return l_(locale, "pollen.error.vote.invalidCoombsVoteValue", + return l(locale, "pollen.error.vote.invalidCoombsVoteValue", choiceName, voteValue); } Modified: trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCounting.java =================================================================== --- trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCounting.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCounting.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -27,8 +27,8 @@ import java.util.Locale; -import static org.nuiton.i18n.I18n.l_; -import static org.nuiton.i18n.I18n.n_; +import static org.nuiton.i18n.I18n.l; +import static org.nuiton.i18n.I18n.n; /** * Coombs vote counting entry point. @@ -43,9 +43,9 @@ public InstantRunoffVoteCounting() { super(ID, InstantRunoffVoteCountingStrategy.class, - n_("pollen.voteCountingType.instantRunoff"), - n_("pollen.voteCountingType.instantRunoff.shortHelp"), - n_("pollen.voteCountingType.instantRunoff.help") + n("pollen.voteCountingType.instantRunoff"), + n("pollen.voteCountingType.instantRunoff.shortHelp"), + n("pollen.voteCountingType.instantRunoff.help") ); } @@ -59,7 +59,7 @@ public String getVoteValueNotValidMessage(Locale locale, String choiceName, String voteValue) { - return l_(locale, "pollen.error.vote.invalidInstantRunoffVoteValue", + return l(locale, "pollen.error.vote.invalidInstantRunoffVoteValue", choiceName, voteValue); } Modified: trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCounting.java =================================================================== --- trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCounting.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-votecounting-normal/src/main/java/org/chorem/pollen/votecounting/NormalVoteCounting.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -27,7 +27,7 @@ import java.util.Locale; -import static org.nuiton.i18n.I18n.n_; +import static org.nuiton.i18n.I18n.n; /** * Coombs vote counting entry point. @@ -42,9 +42,9 @@ public NormalVoteCounting() { super(ID, NormalVoteCountingStrategy.class, - n_("pollen.voteCountingType.normal"), - n_("pollen.voteCountingType.normal.shortHelp"), - n_("pollen.voteCountingType.normal.help") + n("pollen.voteCountingType.normal"), + n("pollen.voteCountingType.normal.shortHelp"), + n("pollen.voteCountingType.normal.help") ); } Modified: trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCounting.java =================================================================== --- trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCounting.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-votecounting-number/src/main/java/org/chorem/pollen/votecounting/NumberVoteCounting.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -27,7 +27,7 @@ import java.util.Locale; -import static org.nuiton.i18n.I18n.n_; +import static org.nuiton.i18n.I18n.n; /** * Coombs vote counting entry point. @@ -42,9 +42,9 @@ public NumberVoteCounting() { super(ID, NumberVoteCountingStrategy.class, - n_("pollen.voteCountingType.number"), - n_("pollen.voteCountingType.number.shortHelp"), - n_("pollen.voteCountingType.number.help") + n("pollen.voteCountingType.number"), + n("pollen.voteCountingType.number.shortHelp"), + n("pollen.voteCountingType.number.help") ); } Modified: trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCounting.java =================================================================== --- trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCounting.java 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pollen-votecounting-percentage/src/main/java/org/chorem/pollen/votecounting/PercentageVoteCounting.java 2014-04-25 15:34:32 UTC (rev 3877) @@ -27,8 +27,8 @@ import java.util.Locale; -import static org.nuiton.i18n.I18n.l_; -import static org.nuiton.i18n.I18n.n_; +import static org.nuiton.i18n.I18n.l; +import static org.nuiton.i18n.I18n.n; /** * Coombs vote counting entry point. @@ -43,9 +43,9 @@ public PercentageVoteCounting() { super(ID, PercentageVoteCountingStrategy.class, - n_("pollen.voteCountingType.percentage"), - n_("pollen.voteCountingType.percentage.shortHelp"), - n_("pollen.voteCountingType.percentage.help") + n("pollen.voteCountingType.percentage"), + n("pollen.voteCountingType.percentage.shortHelp"), + n("pollen.voteCountingType.percentage.help") ); } @@ -91,7 +91,7 @@ @Override public String getTotalVoteValueNotValidMessage(Locale locale) { - return l_(locale, "pollen.error.vote.percentage"); + return l(locale, "pollen.error.vote.percentage"); } } Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2014-04-25 09:34:07 UTC (rev 3876) +++ trunk/pom.xml 2014-04-25 15:34:32 UTC (rev 3877) @@ -5,7 +5,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>mavenpom4redmine</artifactId> - <version>5.0.4</version> + <version>5.0.6</version> </parent> <groupId>org.chorem</groupId> @@ -163,20 +163,21 @@ <nuitonJpaVersion>1.0-rc-1</nuitonJpaVersion> <webmotionVersion>2.4</webmotionVersion> - <eugenePluginVersion>2.7</eugenePluginVersion> - <nuitonI18nVersion>2.5.1</nuitonI18nVersion> + <nuitonI18nVersion>3.0</nuitonI18nVersion> + <eugenePluginVersion>2.9-SNAPSHOT</eugenePluginVersion> + <topiaVersion>3.0-SNAPSHOT</topiaVersion> - <nuitonWebVersion>1.13</nuitonWebVersion> + <nuitonWebVersion>1.16</nuitonWebVersion> <nuitonUtilsVersion>2.7.1</nuitonUtilsVersion> - <nuitonConfigVersion>3.0-alpha-1</nuitonConfigVersion> - <nuitonCsvVersion>3.0-alpha-1</nuitonCsvVersion> + <nuitonConfigVersion>3.0-alpha-2</nuitonConfigVersion> + <nuitonCsvVersion>3.0-alpha-3</nuitonCsvVersion> <nuitonValidatorVersion>3.0-alpha-1</nuitonValidatorVersion> <h2Version>1.3.173</h2Version> <postgresqlVersion>9.1-901-1.jdbc4</postgresqlVersion> <shiroVersion>1.2.2</shiroVersion> - <slf4jVersion>1.7.5</slf4jVersion> + <slf4jVersion>1.7.6</slf4jVersion> <jettyVersion>9.0.3.v20130506</jettyVersion> - <hibernateVersion>4.3.0.Beta3</hibernateVersion> + <hibernateVersion>4.3.5.Final</hibernateVersion> <seleniumVersion>2.33.0</seleniumVersion> <mockitoVersion>1.9.5</mockitoVersion> <httpCommonsHttpclientVersion>4.2.3</httpCommonsHttpclientVersion> @@ -190,7 +191,12 @@ <scmwebeditorEnabled>true</scmwebeditorEnabled> <!-- java configuration --> + <!-- Using Java 7 --> <javaVersion>1.7</javaVersion> + <!--TODO remove this when IDEA won't ask to change jdk level at each pom modification--> + <maven.compiler.source>${javaVersion}</maven.compiler.source> + <!--TODO remove this when IDEA won't ask to change jdk level at each pom modification--> + <maven.compiler.target>${javaVersion}</maven.compiler.target> <signatureArtifactId>java17</signatureArtifactId> <signatureVersion>1.0</signatureVersion> </properties> @@ -230,6 +236,8 @@ <dependencyManagement> <dependencies> + <!-- persistence module dependencies --> + <dependency> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.1-api</artifactId> @@ -237,6 +245,17 @@ </dependency> <dependency> + <groupId>org.nuiton.topia</groupId> + <artifactId>topia-persistence</artifactId> + <version>${topiaVersion}</version> + </dependency> + <dependency> + <groupId>org.nuiton.topia</groupId> + <artifactId>topia-junit</artifactId> + <version>${topiaVersion}</version> + </dependency> + + <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>${hibernateVersion}</version> @@ -251,6 +270,13 @@ <dependency> <groupId>org.hibernate</groupId> + <artifactId>hibernate-c3p0</artifactId> + <version>${hibernateVersion}</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>${hibernateVersion}</version> <scope>runtime</scope> @@ -633,7 +659,7 @@ <plugin> <groupId>org.nuiton</groupId> <artifactId>nuiton-utils-maven-report-plugin</artifactId> - <version>${nuitonUtilsVersion}</version> + <version>3.0-rc-1</version> <reportSets> <reportSet> <reports>