r3834 - in trunk: pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity pollen-rest-api/src/main/java/org/chorem/pollen/rest/api pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1 pollen-rest-api/src/test/java/org/chorem/pollen/rest/api pollen-services/src/main/java/org/chorem/pollen/services pollen-services/src/main/java/org/chorem/pollen/services/exception pollen-services/src/main/java/org/chorem/pollen/services/service pollen-services/src/test/java/org/chorem/pol
Author: tchemit Date: 2013-06-18 08:22:46 +0200 (Tue, 18 Jun 2013) New Revision: 3834 Url: http://chorem.org/projects/pollen/repository/revisions/3834 Log: continue services Added: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserService.java trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserServiceTest.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidCommentFormException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidPollenUserFormException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoteFormException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserInvalidEmailActivationTokenException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollenUserServiceTest.java Removed: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/UserService.java trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/UserServiceTest.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserEmailAlreadyUsedException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserInvalidEmailActiviationTokenException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserLoginAlreadyUsedException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/EmailService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/UserService.java trunk/pollen-services/src/test/java/org/chorem/pollen/service/UserServiceTest.java Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceListener.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/VoteService.java trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.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/exception/AbstractInvalidFormException.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/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/VoteService.java trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java trunk/pollen-ui-js/pom.xml trunk/pollen-ui-js/src/main/resources/nuiton-js/wro.properties trunk/pollen-ui-js/src/main/resources/nuiton-js/wro.xml Modified: 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 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -24,6 +24,7 @@ */ import javax.persistence.Entity; +import java.util.Date; /** * TODO @@ -48,4 +49,36 @@ 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)); + } + } //Poll 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 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceListener.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -26,8 +26,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.pollen.services.PollenServiceContext; -import org.chorem.pollen.services.exception.UserEmailAlreadyUsedException; -import org.chorem.pollen.services.exception.UserLoginAlreadyUsedException; +import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.chorem.pollen.services.exception.InvalidPollenUserFormException; import org.debux.webmotion.server.WebMotionServerListener; import org.debux.webmotion.server.call.Call; import org.debux.webmotion.server.call.HttpContext; @@ -71,9 +71,9 @@ PollenServiceContext serviceContext = applicationContext.newServiceContext(entityManager); serviceContext.getUserService().createDefaultUsers(); - } catch (UserEmailAlreadyUsedException e) { + } catch (InvalidPollenUserFormException e) { //Can't happen - } catch (UserLoginAlreadyUsedException e) { + } catch (EntityNotFoundException e) { //Can't happen } finally { entityManager.close(); 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 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentService.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -26,6 +26,7 @@ import org.chorem.pollen.persistence.entity.Comment; import org.chorem.pollen.services.PollenServiceContext; import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.chorem.pollen.services.exception.InvalidCommentFormException; import org.debux.webmotion.server.WebMotionController; import java.util.List; @@ -43,16 +44,16 @@ return comments; } - public Comment getComment(PollenServiceContext context, String commentId) throws EntityNotFoundException { - return context.getCommentService().getComment(commentId); + public Comment getComment(PollenServiceContext context, String pollId, String commentId) throws EntityNotFoundException { + return context.getCommentService().getComment(pollId, commentId); } - public Comment addComment(PollenServiceContext context, String pollId, Comment comment) throws EntityNotFoundException { + public Comment addComment(PollenServiceContext context, String pollId, Comment comment) throws EntityNotFoundException, InvalidCommentFormException { return context.getCommentService().addComment(pollId, comment); } - public Comment editComment(PollenServiceContext context,Comment comment) throws EntityNotFoundException { - return context.getCommentService().editComment(comment); + public Comment editComment(PollenServiceContext context, String pollId, Comment comment) throws EntityNotFoundException, InvalidCommentFormException { + return context.getCommentService().editComment(pollId, comment); } public void deleteComment(PollenServiceContext context, String pollId, String commentId) throws EntityNotFoundException { 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 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListService.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -28,8 +28,6 @@ import org.chorem.pollen.services.PollenServiceContext; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.FavoriteListImportException; -import org.chorem.pollen.services.exception.FavoriteListMemberNotOwnedByFavoriteListException; -import org.chorem.pollen.services.exception.FavoriteListNotOwnedByUserException; import org.chorem.pollen.services.exception.InvalidFavoriteListFormException; import org.chorem.pollen.services.exception.InvalidFavoriteListMemberFormException; import org.debux.webmotion.server.WebMotionController; @@ -39,7 +37,6 @@ /** * TODO - * TODO All method needs a userId connected * * @author tchemit <chemit@codelutin.com> * @since 2.0 @@ -51,7 +48,7 @@ return favoriteLists; } - public FavoriteList getFavoriteList(PollenServiceContext context, String userId, String favoriteListId) throws EntityNotFoundException, FavoriteListNotOwnedByUserException { + public FavoriteList getFavoriteList(PollenServiceContext context, String userId, String favoriteListId) throws EntityNotFoundException { return context.getFavoriteListService().getFavoriteList(userId, favoriteListId); } @@ -59,40 +56,40 @@ return context.getFavoriteListService().createFavoriteList(userId, favoriteList); } - public FavoriteList editFavoriteList(PollenServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, FavoriteListNotOwnedByUserException, InvalidFavoriteListFormException { + public FavoriteList editFavoriteList(PollenServiceContext 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, FavoriteListNotOwnedByUserException { + public void deleteFavoriteList(PollenServiceContext 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, FavoriteListNotOwnedByUserException { + public int importFavoriteListMembersFromCsv(PollenServiceContext 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, FavoriteListNotOwnedByUserException { + public int importFavoriteListMembersFromLdap(PollenServiceContext 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, FavoriteListNotOwnedByUserException { + public List<FavoriteListMember> getMembers(PollenServiceContext 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, FavoriteListMemberNotOwnedByFavoriteListException, FavoriteListNotOwnedByUserException { + public FavoriteListMember getMember(PollenServiceContext 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, FavoriteListNotOwnedByUserException { + public FavoriteListMember addMember(PollenServiceContext 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, FavoriteListMemberNotOwnedByFavoriteListException, InvalidFavoriteListMemberFormException, FavoriteListNotOwnedByUserException { + public FavoriteListMember editMember(PollenServiceContext 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, FavoriteListMemberNotOwnedByFavoriteListException, FavoriteListNotOwnedByUserException { + public void removeMember(PollenServiceContext context, String userId, String favoriteListId, String memberId) throws EntityNotFoundException { context.getFavoriteListService().removeFavoriteListMember(userId, favoriteListId, memberId); } } Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserService.java (from rev 3831, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/UserService.java) =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserService.java (rev 0) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserService.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -0,0 +1,77 @@ +package org.chorem.pollen.rest.api.v1; + +/* + * #%L + * Pollen :: Rest Api + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import org.chorem.pollen.persistence.entity.PollenUser; +import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.chorem.pollen.services.exception.InvalidPollenUserFormException; +import org.chorem.pollen.services.exception.UserInvalidEmailActivationTokenException; +import org.chorem.pollen.services.exception.UserInvalidPasswordException; +import org.debux.webmotion.server.WebMotionController; + +import java.util.List; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollenUserService extends WebMotionController { + + public List<PollenUser> getUsers(PollenServiceContext context) { + List<PollenUser> users = context.getUserService().getUsers(); + return users; + } + + public PollenUser getUser(PollenServiceContext context, String userId) throws EntityNotFoundException { + return context.getUserService().getUser(userId); + } + + public PollenUser createUser(PollenServiceContext context, + PollenUser user, + boolean generatePassword) throws EntityNotFoundException, InvalidPollenUserFormException { + return context.getUserService().createUser(user, generatePassword); + + } + + public PollenUser editUser(PollenServiceContext context, + PollenUser user) throws EntityNotFoundException, InvalidPollenUserFormException { + return context.getUserService().editUser(user); + } + + public void validateUserEmail(PollenServiceContext context, + String userId, + String token) throws EntityNotFoundException, UserInvalidEmailActivationTokenException { + context.getUserService().validateUserEmail(userId, token); + } + + public void changePassword(PollenServiceContext context, + String userId, + String oldPassword, + String newPassword) throws EntityNotFoundException, UserInvalidPasswordException { + context.getUserService().changePassword(userId, oldPassword, newPassword); + } +} Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/UserService.java =================================================================== --- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/UserService.java 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/UserService.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -1,79 +0,0 @@ -package org.chorem.pollen.rest.api.v1; - -/* - * #%L - * Pollen :: Rest Api - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -import org.chorem.pollen.persistence.entity.PollenUser; -import org.chorem.pollen.services.PollenServiceContext; -import org.chorem.pollen.services.exception.EntityNotFoundException; -import org.chorem.pollen.services.exception.UserEmailAlreadyUsedException; -import org.chorem.pollen.services.exception.UserInvalidEmailActiviationTokenException; -import org.chorem.pollen.services.exception.UserInvalidPasswordException; -import org.chorem.pollen.services.exception.UserLoginAlreadyUsedException; -import org.debux.webmotion.server.WebMotionController; - -import java.util.List; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class UserService extends WebMotionController { - - public List<PollenUser> getUsers(PollenServiceContext context) { - List<PollenUser> users = context.getUserService().getUsers(); - return users; - } - - public PollenUser getUser(PollenServiceContext context, - String userId) throws EntityNotFoundException { - return context.getUserService().getUser(userId); - } - - public PollenUser createUser(PollenServiceContext context, - PollenUser user, - boolean generatePassword) throws UserEmailAlreadyUsedException, UserLoginAlreadyUsedException { - return context.getUserService().createUser(user, generatePassword); - - } - - public PollenUser editUser(PollenServiceContext context, - PollenUser user) throws UserInvalidPasswordException, UserEmailAlreadyUsedException, EntityNotFoundException { - return context.getUserService().editUser(user); - } - - public void validateUserEmail(PollenServiceContext context, - String userId, - String token) throws EntityNotFoundException, UserInvalidEmailActiviationTokenException { - context.getUserService().validateUserEmail(userId, token); - } - - public void changePassword(PollenServiceContext context, - String userId, - String oldPassword, - String newPassword) throws UserInvalidPasswordException, EntityNotFoundException { - context.getUserService().changePassword(userId, oldPassword, newPassword); - } -} 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 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteService.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -26,6 +26,7 @@ import org.chorem.pollen.persistence.entity.Vote; import org.chorem.pollen.services.PollenServiceContext; import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.chorem.pollen.services.exception.InvalidVoteFormException; import org.debux.webmotion.server.WebMotionController; import java.util.List; @@ -43,16 +44,16 @@ return votes; } - public Vote getVote(PollenServiceContext context, String voteId) throws EntityNotFoundException { - return context.getVoteService().getVote(voteId); + public Vote getVote(PollenServiceContext context, String pollId, String voteId) throws EntityNotFoundException { + return context.getVoteService().getVote(pollId, voteId); } - public Vote addVote(PollenServiceContext context, String pollId, Vote vote) throws EntityNotFoundException { + public Vote addVote(PollenServiceContext context, String pollId, Vote vote) throws EntityNotFoundException, InvalidVoteFormException { return context.getVoteService().addVote(pollId, vote); } - public Vote editVote(PollenServiceContext context, Vote vote) throws EntityNotFoundException { - return context.getVoteService().editVote(vote); + public Vote editVote(PollenServiceContext context, String pollId, Vote vote) throws EntityNotFoundException, InvalidVoteFormException { + return context.getVoteService().editVote(pollId, vote); } public void deleteVote(PollenServiceContext context, String pollId, String voteId) throws EntityNotFoundException { 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 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -27,8 +27,8 @@ import org.chorem.pollen.persistence.entity.VoterListMember; import org.chorem.pollen.services.PollenServiceContext; import org.chorem.pollen.services.exception.EntityNotFoundException; -import org.chorem.pollen.services.exception.FavoriteListNotOwnedByUserException; import org.chorem.pollen.services.exception.InvalidVoterListFormException; +import org.chorem.pollen.services.exception.InvalidVoterListMemberFormException; import org.debux.webmotion.server.WebMotionController; import java.util.List; @@ -42,7 +42,7 @@ */ public class VoterListService extends WebMotionController { - public VoterList importFavoriteList(PollenServiceContext context, String userId, String pollId, String favoriteListId) throws EntityNotFoundException, FavoriteListNotOwnedByUserException { + public VoterList importFavoriteList(PollenServiceContext context, String userId, String pollId, String favoriteListId) throws EntityNotFoundException { return context.getVoterListService().importFavoriteList(userId, pollId, favoriteListId); } @@ -76,11 +76,11 @@ return context.getVoterListService().getVoterListMember(pollId, voterListId, memberId); } - public VoterListMember addMember(PollenServiceContext context, String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException { + public VoterListMember addMember(PollenServiceContext context, String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException, InvalidVoterListMemberFormException { return context.getVoterListService().addVoterListMember(pollId, voterListId, member); } - public VoterListMember editMember(PollenServiceContext context, String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException { + public VoterListMember editMember(PollenServiceContext context, String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException, InvalidVoterListMemberFormException { return context.getVoterListService().editVoterListMember(pollId, voterListId, member); } Copied: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserServiceTest.java (from rev 3833, trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/UserServiceTest.java) =================================================================== --- trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserServiceTest.java (rev 0) +++ trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserServiceTest.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -0,0 +1,84 @@ +package org.chorem.pollen.rest.api; + +/* + * #%L + * Pollen :: Rest Api + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import org.apache.http.client.fluent.Request; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +@Ignore +public class PollenUserServiceTest extends AbstractPollenRestApiTest { + + + @Before + public void setUp() throws Exception { + + loadFixtures("fixtures"); + } + + @Test + public void testGetUsers() throws Exception { + + Request request = createRequest("/users").Get(); + String result = request.execute().returnContent().asString(); + + assertTrue(result.contains("email")); + + + } + +// @Test +// public void testGetUser() throws Exception { +// +// } +// +// @Test +// public void testCreateUser() throws Exception { +// +// } +// +// @Test +// public void testEditUser() throws Exception { +// +// } +// +// @Test +// public void testValidateUserEmail() throws Exception { +// +// } +// +// @Test +// public void testChangePassword() throws Exception { +// +// } +} Deleted: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/UserServiceTest.java =================================================================== --- trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/UserServiceTest.java 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/UserServiceTest.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -1,84 +0,0 @@ -package org.chorem.pollen.rest.api; - -/* - * #%L - * Pollen :: Rest Api - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -import org.apache.http.client.fluent.Request; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import static org.junit.Assert.assertTrue; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -@Ignore -public class UserServiceTest extends AbstractPollenRestApiTest { - - - @Before - public void setUp() throws Exception { - - loadFixtures("fixtures"); - } - - @Test - public void testGetUsers() throws Exception { - - Request request = createRequest("/users").Get(); - String result = request.execute().returnContent().asString(); - - assertTrue(result.contains("email")); - - - } - -// @Test -// public void testGetUser() throws Exception { -// -// } -// -// @Test -// public void testCreateUser() throws Exception { -// -// } -// -// @Test -// public void testEditUser() throws Exception { -// -// } -// -// @Test -// public void testValidateUserEmail() throws Exception { -// -// } -// -// @Test -// public void testChangePassword() throws Exception { -// -// } -} Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -24,18 +24,18 @@ */ 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.services.config.PollenServiceConfig; import org.chorem.pollen.services.service.AuthService; import org.chorem.pollen.services.service.ChoiceService; import org.chorem.pollen.services.service.CommentService; -import org.chorem.pollen.services.service.EmailService; import org.chorem.pollen.services.service.FavoriteListService; import org.chorem.pollen.services.service.FixturesService; import org.chorem.pollen.services.service.PollService; +import org.chorem.pollen.services.service.PollenUserService; import org.chorem.pollen.services.service.SecurityService; -import org.chorem.pollen.services.service.UserService; import org.chorem.pollen.services.service.VoteCountingService; import org.chorem.pollen.services.service.VoteService; import org.chorem.pollen.services.service.VoterListService; @@ -128,8 +128,8 @@ } @Override - public UserService getUserService() { - return newService(UserService.class); + public PollenUserService getUserService() { + return newService(PollenUserService.class); } @Override @@ -148,11 +148,6 @@ } @Override - public EmailService getEmailService() { - return newService(EmailService.class); - } - - @Override public FixturesService getFixturesService() { return newService(FixturesService.class); } @@ -169,12 +164,17 @@ @Override public Locale getLocale() { - if (locale==null) { + if (locale == null) { locale = Locale.getDefault(); } return locale; } + @Override + public String getCleanMail(String email) { + return email == null ? null : StringUtils.lowerCase(email.trim()); + } + public <E extends PollenServiceSupport> E newService(Class<E> serviceClass) { E service; 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 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityRealm.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -37,7 +37,7 @@ /** * TODO - * + * <p/> * http://www.slideshare.net/chunsaker/securing-rest-apis ? * * @author tchemit <chemit@codelutin.com> Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -28,12 +28,11 @@ import org.chorem.pollen.services.service.AuthService; import org.chorem.pollen.services.service.ChoiceService; import org.chorem.pollen.services.service.CommentService; -import org.chorem.pollen.services.service.EmailService; import org.chorem.pollen.services.service.FavoriteListService; import org.chorem.pollen.services.service.FixturesService; import org.chorem.pollen.services.service.PollService; +import org.chorem.pollen.services.service.PollenUserService; import org.chorem.pollen.services.service.SecurityService; -import org.chorem.pollen.services.service.UserService; import org.chorem.pollen.services.service.VoteCountingService; import org.chorem.pollen.services.service.VoteService; import org.chorem.pollen.services.service.VoterListService; @@ -69,14 +68,13 @@ PollService getPollService(); - UserService getUserService(); + PollenUserService getUserService(); VoteCountingService getVoteCountingService(); VoterListService getVoterListService(); VoteService getVoteService(); - EmailService getEmailService(); FixturesService getFixturesService(); @@ -87,4 +85,6 @@ String encodePassword(String password); Locale getLocale(); + + String getCleanMail(String email); } Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/AbstractInvalidFormException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/AbstractInvalidFormException.java 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/AbstractInvalidFormException.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -31,7 +31,7 @@ * @author tchemit <chemit@codelutin.com> * @since 2.0 */ -public abstract class AbstractInvalidFormException extends Exception{ +public abstract class AbstractInvalidFormException extends Exception { private static final long serialVersionUID = 1L; protected final Multimap<String, String> errors; @@ -47,6 +47,6 @@ @Override public String toString() { - return super.toString()+ " errors: "+errors; + return super.toString() + " errors: " + errors; } } Deleted: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -1,34 +0,0 @@ -package org.chorem.pollen.services.exception; - -/* - * #%L - * Pollen :: Service - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class FavoriteListMemberNotOwnedByFavoriteListException extends Throwable { - private static final long serialVersionUID = 1L; -} Deleted: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -1,35 +0,0 @@ -package org.chorem.pollen.services.exception; - -/* - * #%L - * Pollen :: Service - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class FavoriteListNotOwnedByUserException extends Exception { - private static final long serialVersionUID = 1L; - -} Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidCommentFormException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidCommentFormException.java (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidCommentFormException.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -0,0 +1,40 @@ +package org.chorem.pollen.services.exception; + +/* + * #%L + * Pollen :: Service + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import com.google.common.collect.Multimap; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class InvalidCommentFormException extends AbstractInvalidFormException { + private static final long serialVersionUID = 1L; + + public InvalidCommentFormException(Multimap<String, String> errors) { + super(errors); + } +} Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidCommentFormException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidPollenUserFormException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidPollenUserFormException.java (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidPollenUserFormException.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -0,0 +1,40 @@ +package org.chorem.pollen.services.exception; + +/* + * #%L + * Pollen :: Service + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import com.google.common.collect.Multimap; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class InvalidPollenUserFormException extends AbstractInvalidFormException { + private static final long serialVersionUID = 1L; + + public InvalidPollenUserFormException(Multimap<String, String> errors) { + super(errors); + } +} Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidPollenUserFormException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoteFormException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoteFormException.java (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoteFormException.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -0,0 +1,40 @@ +package org.chorem.pollen.services.exception; + +/* + * #%L + * Pollen :: Service + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import com.google.common.collect.Multimap; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class InvalidVoteFormException extends AbstractInvalidFormException { + private static final long serialVersionUID = 1L; + + public InvalidVoteFormException(Multimap<String, String> errors) { + super(errors); + } +} Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoteFormException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserEmailAlreadyUsedException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserEmailAlreadyUsedException.java 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserEmailAlreadyUsedException.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -1,45 +0,0 @@ -package org.chorem.pollen.services.exception; - -/* - * #%L - * Pollen :: Service - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class UserEmailAlreadyUsedException extends Exception { - - private static final long serialVersionUID = 1L; - - protected final String email; - - public UserEmailAlreadyUsedException(String email) { - this.email = email; - } - - public String getEmail() { - return email; - } -} Copied: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserInvalidEmailActivationTokenException.java (from rev 3833, trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserInvalidEmailActiviationTokenException.java) =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserInvalidEmailActivationTokenException.java (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserInvalidEmailActivationTokenException.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -0,0 +1,34 @@ +package org.chorem.pollen.services.exception; + +/* + * #%L + * Pollen :: Service + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class UserInvalidEmailActivationTokenException extends Exception { + private static final long serialVersionUID = 1L; +} Deleted: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserInvalidEmailActiviationTokenException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserInvalidEmailActiviationTokenException.java 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserInvalidEmailActiviationTokenException.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -1,34 +0,0 @@ -package org.chorem.pollen.services.exception; - -/* - * #%L - * Pollen :: Service - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class UserInvalidEmailActiviationTokenException extends Exception { - private static final long serialVersionUID = 1L; -} Deleted: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserLoginAlreadyUsedException.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserLoginAlreadyUsedException.java 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserLoginAlreadyUsedException.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -1,45 +0,0 @@ -package org.chorem.pollen.services.exception; - -/* - * #%L - * Pollen :: Service - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class UserLoginAlreadyUsedException extends Exception { - - private static final long serialVersionUID = 1L; - - protected final String login; - - public UserLoginAlreadyUsedException(String login) { - this.login=login; - } - - public String getLogin() { - return login; - } -} Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -47,21 +47,17 @@ */ public abstract class AbstractPollenService implements PollenServiceSupport { + // -- PollenServiceSupport -- // + protected PollenServiceContext serviceContext; - protected void checkHasId(JpaEntity entity) { - Preconditions.checkState(JpaEntities.isEntityHasId(entity)); - } - - protected void checkHasNoId(JpaEntity entity) { - Preconditions.checkState(JpaEntities.isEntityHasNoId(entity)); - } - @Override public void setServiceContext(PollenServiceContext serviceContext) { this.serviceContext = serviceContext; } + // -- Delegate serviceContext -- // + protected Date getNow() { return serviceContext.getNow(); } @@ -70,6 +66,10 @@ return serviceContext.generateToken(); } + protected String getCleanMail(String email) { + return serviceContext.getCleanMail(email); + } + protected PollenPersistenceContext getPersistenceContext() { return serviceContext.getPersistenceContext(); } @@ -102,7 +102,7 @@ return serviceContext.getSecurityService(); } - protected UserService getUserService() { + protected PollenUserService getUserService() { return serviceContext.getUserService(); } @@ -118,10 +118,16 @@ return serviceContext.getVoteService(); } - protected EmailService getEmailService() { - return serviceContext.getEmailService(); + // -- check method -- // + + 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 { @@ -138,18 +144,23 @@ 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); + 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); + boolean valid = check(errors, field, CollectionUtils.isNotEmpty(value), error); return valid; } 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 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -26,9 +26,9 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; +import com.google.common.collect.Sets; import org.chorem.pollen.persistence.dao.ChoiceJpaDao; import org.chorem.pollen.persistence.entity.Choice; -import org.chorem.pollen.persistence.entity.ChoiceType; import org.chorem.pollen.persistence.entity.Poll; import org.chorem.pollen.persistence.entity.PollenPrincipal; import org.chorem.pollen.services.exception.EntityNotFoundException; @@ -36,6 +36,7 @@ import org.nuiton.jpa.api.JpaEntities; import java.util.List; +import java.util.Set; /** * TODO @@ -69,12 +70,13 @@ Poll poll = getPollService().getPoll(pollId); - checkChoiceForm(poll.getChoiceType(), choice); + checkChoiceForm(poll, choice); Choice result = saveChoice(poll, choice, null); getPersistenceContext().getPollDao().merge(poll); getPersistenceContext().commit(); + //TODO Notify Choice added return result; } @@ -84,12 +86,13 @@ Poll poll = getPollService().getPoll(pollId); - checkChoiceForm(poll.getChoiceType(), choice); + checkChoiceForm(poll, choice); Choice result = saveChoice(poll, choice, null); getPersistenceContext().getChoiceDao().merge(choice); getPersistenceContext().commit(); + //TODO Notify Choice edited return result; } @@ -104,9 +107,10 @@ getPersistenceContext().getPollDao().merge(poll); getPersistenceContext().commit(); + //TODO Notify Choice deleted } - protected Choice getChoice(Poll poll, String choiceId) throws EntityNotFoundException { + protected Choice getChoice(Poll poll, String choiceId) throws EntityNotFoundException { Choice result = poll.getChoiceById(choiceId); checkEntityExists(Choice.class, result, choiceId); @@ -170,21 +174,43 @@ return choiceToPersist; } - protected void checkChoiceForm(ChoiceType choiceType, Choice choice) throws InvalidChoiceFormException { + protected void checkChoiceForm(Poll poll, Choice choice) throws InvalidChoiceFormException { //TODO use nuiton validator ? Multimap<String, String> errors = ArrayListMultimap.create(); - switch (choiceType) { + boolean choiceExists = JpaEntities.isEntityHasId(choice); + Set<String> choiceNames = Sets.newHashSet(); + + if (!poll.isChoiceEmpty()) { + + // get all used names + + for (Choice member : poll.getChoice()) { + + if (choiceExists && + member.getId().equals(choice.getId())) { + continue; + } + choiceNames.add(member.getName()); + } + } + + switch (poll.getChoiceType()) { + case TEXT: - //TODO Should check unique choice name ? + String choiceName = choice.getName(); + boolean nameNotBlank = checkNotBlank(errors, + "name", + choiceName, + "choice name can not be empty"); - checkNotBlank(errors, - "name", - choice.getName(), - "choice name can not be empty"); + if (nameNotBlank) { + boolean nameAdded = choiceNames.add(choiceName); + check(errors, "name", nameAdded, "choice name already used in this list"); + } break; case DATE: 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 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -24,9 +24,15 @@ */ import com.google.common.base.Preconditions; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; +import org.apache.commons.lang3.StringUtils; import org.chorem.pollen.persistence.entity.Comment; 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.InvalidCommentFormException; +import org.nuiton.jpa.api.JpaEntities; import java.util.List; @@ -44,51 +50,116 @@ return poll.getComment(); } - public Comment getComment(String commentId) throws EntityNotFoundException { + public Comment getComment(String pollId, String commentId) throws EntityNotFoundException { + Preconditions.checkNotNull(pollId); Preconditions.checkNotNull(commentId); - Comment result = getPersistenceContext().getCommentDao().findById(commentId); - checkEntityExists(Comment.class, result, commentId); + + Poll poll = getPollService().getPoll(pollId); + + Comment result = getComment(poll, commentId); return result; } - public Comment addComment(String pollId, Comment comment) throws EntityNotFoundException { + public Comment addComment(String pollId, Comment comment) throws EntityNotFoundException, InvalidCommentFormException { Preconditions.checkNotNull(pollId); + Preconditions.checkNotNull(comment); checkHasNoId(comment); + Poll poll = getPollService().getPoll(pollId); + checkCommentForm(poll, comment); - poll.addComment(comment); + Comment result = saveComment(poll, comment); + getPersistenceContext().getPollDao().merge(poll); getPersistenceContext().commit(); - - Comment result = getComment(comment.getId()); return result; } - public Comment editComment(Comment comment) throws EntityNotFoundException { + public Comment editComment(String pollId, Comment comment) throws EntityNotFoundException, InvalidCommentFormException { + Preconditions.checkNotNull(pollId); + Preconditions.checkNotNull(comment); + checkHasId(comment); - // check comment exists - getComment(comment.getId()); + Poll poll = getPollService().getPoll(pollId); + checkCommentForm(poll, comment); + Comment result = saveComment(poll, comment); + getPersistenceContext().getCommentDao().merge(comment); getPersistenceContext().commit(); - - Comment result = getComment(comment.getId()); return result; } public void deleteComment(String pollId, String commentId) throws EntityNotFoundException { Preconditions.checkNotNull(pollId); Preconditions.checkNotNull(commentId); + Poll poll = getPollService().getPoll(pollId); - Comment comment = getComment(commentId); - Preconditions.checkNotNull(comment); + Comment comment = getComment(poll, commentId); poll.removeComment(comment); getPersistenceContext().getPollDao().merge(poll); - getPersistenceContext().commit(); } + protected Comment getComment(Poll poll, String commentId) throws EntityNotFoundException { + + Comment result = poll.getCommentById(commentId); + checkEntityExists(Comment.class, result, commentId); + return result; + } + + protected void checkCommentForm(Poll poll, Comment comment) throws InvalidCommentFormException { + + //TODO use nuiton validator ? + Multimap<String, String> errors = ArrayListMultimap.create(); + + checkNotBlank(errors, "text", comment.getText(), "textcan not be empty"); + boolean authorNotNull = checkNotNull(errors, "author", comment.getAuthor(), "author can not be null"); + if (authorNotNull) { + checkNotBlank(errors, "author.name", comment.getAuthor().getName(), "author name can not be empty"); + } + + if (!errors.isEmpty()) { + + throw new InvalidCommentFormException(errors); + } + } + + protected Comment saveComment(Poll poll, Comment comment) throws EntityNotFoundException { + + boolean commentExists = JpaEntities.isEntityHasId(comment); + + Comment toSave; + + if (commentExists) { + + toSave = getComment(poll, comment.getId()); + } else { + + toSave = getPersistenceContext().getCommentDao().newInstance(); + toSave.setPostDate(serviceContext.getNow()); + + // -- author -- // + + PollenPrincipal author = getSecurityService().generatePrincipal(); + toSave.setAuthor(author); + + poll.addComment(toSave); + } + + toSave.setText(comment.getText()); + + // -- author -- // + + toSave.getAuthor().setName(comment.getAuthor().getName()); + if (StringUtils.isNotBlank(comment.getAuthor().getEmail())) { + toSave.getAuthor().setEmail(StringUtils.lowerCase(comment.getAuthor().getEmail())); + } + + return toSave; + } + } Deleted: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/EmailService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/EmailService.java 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/EmailService.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -1,39 +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 org.chorem.pollen.persistence.entity.PollenUser; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class EmailService extends AbstractPollenService { - - public void onUserCreated(PollenUser user) { - //TODO - } -} 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 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -35,8 +35,6 @@ import org.chorem.pollen.services.PollenTechnicalException; import org.chorem.pollen.services.exception.EntityNotFoundException; import org.chorem.pollen.services.exception.FavoriteListImportException; -import org.chorem.pollen.services.exception.FavoriteListMemberNotOwnedByFavoriteListException; -import org.chorem.pollen.services.exception.FavoriteListNotOwnedByUserException; import org.chorem.pollen.services.exception.InvalidFavoriteListFormException; import org.chorem.pollen.services.exception.InvalidFavoriteListMemberFormException; import org.nuiton.jpa.api.JpaEntities; @@ -77,7 +75,7 @@ return result; } - public FavoriteList getFavoriteList(String userId, String favoriteListId) throws EntityNotFoundException, FavoriteListNotOwnedByUserException { + public FavoriteList getFavoriteList(String userId, String favoriteListId) throws EntityNotFoundException { Preconditions.checkNotNull(userId); Preconditions.checkNotNull(favoriteListId); @@ -108,7 +106,7 @@ } public FavoriteList editFavoriteList(String userId, - FavoriteList favoriteList) throws EntityNotFoundException, InvalidFavoriteListFormException, FavoriteListNotOwnedByUserException { + FavoriteList favoriteList) throws EntityNotFoundException, InvalidFavoriteListFormException { Preconditions.checkNotNull(favoriteList); checkHasId(favoriteList); @@ -128,7 +126,7 @@ return toSave; } - public void deleteFavoriteList(String userId, String favoriteListId) throws EntityNotFoundException, FavoriteListNotOwnedByUserException { + public void deleteFavoriteList(String userId, String favoriteListId) throws EntityNotFoundException { Preconditions.checkNotNull(userId); Preconditions.checkNotNull(favoriteListId); @@ -136,19 +134,13 @@ FavoriteList persisted = getFavoriteList(user, favoriteListId); - // check user own this list - boolean ownedByUser = user.containsFavoriteListById(favoriteListId); - if (!ownedByUser) { - throw new FavoriteListNotOwnedByUserException(); - } - user.removeFavoriteList(persisted); getPersistenceContext().getPollenUserDao().merge(user); getPersistenceContext().commit(); } - public List<FavoriteListMember> getFavoriteListMembers(String userId, String favoriteListId) throws EntityNotFoundException, FavoriteListNotOwnedByUserException { + public List<FavoriteListMember> getFavoriteListMembers(String userId, String favoriteListId) throws EntityNotFoundException { Preconditions.checkNotNull(userId); Preconditions.checkNotNull(favoriteListId); @@ -159,7 +151,7 @@ return favoriteList.getFavoriteListMember(); } - public FavoriteListMember getFavoriteListMember(String userId, String favoriteListId, String memberId) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException, FavoriteListNotOwnedByUserException { + public FavoriteListMember getFavoriteListMember(String userId, String favoriteListId, String memberId) throws EntityNotFoundException { Preconditions.checkNotNull(userId); Preconditions.checkNotNull(favoriteListId); Preconditions.checkNotNull(memberId); @@ -174,7 +166,7 @@ public FavoriteListMember addFavoriteListMember(String userId, String favoriteListId, - FavoriteListMember member) throws EntityNotFoundException, InvalidFavoriteListMemberFormException, FavoriteListNotOwnedByUserException { + FavoriteListMember member) throws EntityNotFoundException, InvalidFavoriteListMemberFormException { Preconditions.checkNotNull(userId); Preconditions.checkNotNull(favoriteListId); Preconditions.checkNotNull(member); @@ -199,7 +191,7 @@ public FavoriteListMember editFavoriteListMember(String userId, String favoriteListId, - FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException, InvalidFavoriteListMemberFormException, FavoriteListNotOwnedByUserException { + FavoriteListMember member) throws EntityNotFoundException, InvalidFavoriteListMemberFormException { Preconditions.checkNotNull(userId); Preconditions.checkNotNull(favoriteListId); Preconditions.checkNotNull(member); @@ -226,7 +218,7 @@ public void removeFavoriteListMember(String userId, String favoriteListId, - String memberId) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException, FavoriteListNotOwnedByUserException { + String memberId) throws EntityNotFoundException { Preconditions.checkNotNull(userId); Preconditions.checkNotNull(favoriteListId); Preconditions.checkNotNull(memberId); @@ -245,7 +237,7 @@ public int importFavoriteListMembersFromCsv(String userId, String favoriteListId, - File file) throws EntityNotFoundException, FavoriteListImportException, FavoriteListNotOwnedByUserException { + File file) throws EntityNotFoundException, FavoriteListImportException { Preconditions.checkNotNull(userId); Preconditions.checkNotNull(favoriteListId); Preconditions.checkNotNull(file); @@ -344,7 +336,7 @@ public int importFavoriteListMembersFromLdap(String userId, String favoriteListId, - String ldap) throws EntityNotFoundException, FavoriteListImportException, FavoriteListNotOwnedByUserException { + String ldap) throws EntityNotFoundException, FavoriteListImportException { Preconditions.checkNotNull(favoriteListId); Preconditions.checkNotNull(ldap); @@ -429,31 +421,19 @@ return result; } - protected FavoriteList getFavoriteList(PollenUser user, String favoriteListId) throws EntityNotFoundException, FavoriteListNotOwnedByUserException { + protected FavoriteList getFavoriteList(PollenUser user, String favoriteListId) throws EntityNotFoundException { Preconditions.checkNotNull(favoriteListId); FavoriteList result = user.getFavoriteListById(favoriteListId); checkEntityExists(FavoriteList.class, result, favoriteListId); - // check user own this list - boolean ownedByUser = user.containsFavoriteListById(favoriteListId); - - if (!ownedByUser) { - throw new FavoriteListNotOwnedByUserException(); - } return result; } - protected FavoriteListMember getFavoriteListMember(FavoriteList favoriteList, String memberId) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException { + protected FavoriteListMember getFavoriteListMember(FavoriteList favoriteList, String memberId) throws EntityNotFoundException { FavoriteListMember result = favoriteList.getFavoriteListMemberById(memberId); checkEntityExists(FavoriteListMember.class, result, memberId); - - // check favorite list own this member - boolean ownedByUser = favoriteList.containsFavoriteListMemberById(memberId); - if (!ownedByUser) { - throw new FavoriteListMemberNotOwnedByFavoriteListException(); - } return result; } @@ -505,21 +485,19 @@ String choiceField = "favoriteListMember[" + (memberIndex++) + "]."; - boolean notBlankName = checkNotBlank(errors, choiceField + "name", member.getName(), "member name can not be empty"); - if (notBlankName) { + boolean nameNotBlank = checkNotBlank(errors, choiceField + "name", member.getName(), "member name can not be empty"); + if (nameNotBlank) { boolean added = memberNames.add(member.getName()); check(errors, choiceField + "name", added, "member name already used"); } - String memberEmail = member.getEmail(); + String memberEmail = getCleanMail(member.getEmail()); - boolean emailNotNull = checkNotBlank(errors, choiceField + "email", memberEmail, "member email can not be empty"); + boolean emailNotBlank = checkNotBlank(errors, choiceField + "email", memberEmail, "member email can not be empty"); - if (emailNotNull) { + if (emailNotBlank) { - memberEmail = StringUtils.lowerCase(memberEmail); - checkValidEmail(errors, choiceField + "email", memberEmail, "member email is not valid"); boolean emailAdded = memberEmails.add(memberEmail); check(errors, choiceField + "email", emailAdded, "member email already used in this list"); @@ -559,24 +537,23 @@ } } - boolean notBlankName = checkNotBlank(errors, "name", favoriteListMember.getName(), "member name can not be empty"); - if (notBlankName) { + boolean nameNotBlank = checkNotBlank(errors, "name", favoriteListMember.getName(), "member name can not be empty"); + if (nameNotBlank) { boolean added = memberNames.add(favoriteListMember.getName()); - check(errors, "name", added, "member name already used"); } - String memberEmail = favoriteListMember.getEmail(); + String memberEmail = getCleanMail(favoriteListMember.getEmail()); - boolean emailNotNull = checkNotBlank(errors, "email", memberEmail, "member email can not be empty"); + boolean emailNotBlank = checkNotBlank(errors, "email", memberEmail, "member email can not be empty"); - if (emailNotNull) { + if (emailNotBlank) { - memberEmail = StringUtils.lowerCase(memberEmail); - - checkValidEmail(errors, "email", memberEmail, "member email is not valid"); - boolean emailAdded = memberEmails.add(memberEmail); - check(errors, "email", emailAdded, "member email already used in this list"); + boolean emailValid = checkValidEmail(errors, "email", memberEmail, "member email is not valid"); + if (emailValid) { + boolean emailAdded = memberEmails.add(memberEmail); + check(errors, "email", emailAdded, "member email already used in this list"); + } } if (!errors.isEmpty()) { Copied: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java (from rev 3831, trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/UserService.java) =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java (rev 0) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -0,0 +1,256 @@ +package org.chorem.pollen.services.service; + +/* + * #%L + * Pollen :: Service + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import com.google.common.base.Preconditions; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; +import org.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.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 java.util.List; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollenUserService extends AbstractPollenService implements PollenServiceSupport { + + public List<PollenUser> getUsers() { + return getPersistenceContext().getPollenUserDao().findAll(); + } + + public PollenUser getUser(String userId) throws EntityNotFoundException { + Preconditions.checkNotNull(userId); + + PollenUser result = getPersistenceContext().getPollenUserDao().findById(userId); + checkEntityExists(PollenUser.class, result, userId); + return result; + } + + public PollenUser createUser(PollenUser user, boolean generatePassword) throws InvalidPollenUserFormException, EntityNotFoundException { + Preconditions.checkNotNull(user); + checkHasNoId(user); + checkPollenUserForm(user); + + PollenUser result = savePollenUser(user, generatePassword); + + getPersistenceContext().getPollenUserDao().persist(result); + getPersistenceContext().commit(); + //TODO Notify user created + return result; + } + + public PollenUser editUser(PollenUser user) throws EntityNotFoundException, InvalidPollenUserFormException { + Preconditions.checkNotNull(user); + checkHasId(user); + checkPollenUserForm(user); + + PollenUser result = savePollenUser(user, false); + + getPersistenceContext().getPollenUserDao().merge(result); + getPersistenceContext().commit(); + //TODO Notify user edited + return result; + } + + public void changePassword(String userId, + String oldPassword, + String newPassword) throws EntityNotFoundException, UserInvalidPasswordException { + Preconditions.checkNotNull(userId); + Preconditions.checkNotNull(oldPassword); + Preconditions.checkNotNull(newPassword); + + PollenUser user = getUser(userId); + + // check current password + String encodedPassword = serviceContext.encodePassword(user.getPassword()); + if (!encodedPassword.equals(user.getPassword())) { + throw new UserInvalidPasswordException(); + } + + // encode new password and store it in user account + String newEncodedPassword = serviceContext.encodePassword(newPassword); + user.setPassword(newEncodedPassword); + + getPersistenceContext().getPollenUserDao().merge(user); + getPersistenceContext().commit(); + //TODO Notify PasswordChanged + } + + public void validateUserEmail(String userId, + String token) throws EntityNotFoundException, UserInvalidEmailActivationTokenException { + + Preconditions.checkNotNull(userId); + Preconditions.checkNotNull(token); + + PollenUser user = getUser(userId); + + boolean valid = ObjectUtils.equals( + user.getEmailActivationToken(), token); + + if (!valid) { + throw new UserInvalidEmailActivationTokenException(); + } + + // reset token in database + user.setEmailActivationToken(null); + + getPersistenceContext().getPollenUserDao().merge(user); + getPersistenceContext().commit(); + } + + public void createDefaultUsers() throws EntityNotFoundException, InvalidPollenUserFormException { + + PollenUser user = getPersistenceContext().getPollenUserDao().newInstance(); + + user.setAdministrator(true); + String login = "admin"; + user.setLogin(login); + user.setEmail("admin@pollen.org"); + user.setPassword("admin"); + createUser(user, false); + } + + protected void checkPollenUserForm(PollenUser user) throws EntityNotFoundException, InvalidPollenUserFormException { + + //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(); + + String userLogin = user.getLogin(); + String userEmail = getCleanMail(user.getEmail()); + + boolean loginNotBlank = checkNotBlank(errors, "login", userLogin, "login can not be empty"); + + if (loginNotBlank && !userExists) { + check(errors, "login", !dao.loginExists(userLogin), "login already exists"); + } + + boolean emailNotblank = checkNotBlank(errors, "email", userEmail, "email can not be empty"); + + if (emailNotblank) { + checkValidEmail(errors, "email", userEmail, "email is not valid"); + + + if (userExists) { + + // check if email is available only if has changed + + boolean emailChanged = ObjectUtils.notEqual(persisted.getEmail(), + userEmail); + + if (emailChanged) { + check(errors, "email", !dao.emailExists(userEmail), "email already exists"); + } + } else { + check(errors, "email", !dao.emailExists(userEmail), "email already exists"); + } + } + + if (userExists) { + + // check current password + String encodedPassword = serviceContext.encodePassword(user.getPassword()); + check(errors, "password", encodedPassword.equals(persisted.getPassword()), "invalid password"); + } + + if (!errors.isEmpty()) { + + throw new InvalidPollenUserFormException(errors); + } + } + + protected PollenUser savePollenUser(PollenUser user, + boolean generatePassword) throws EntityNotFoundException { + + boolean userExists = JpaEntities.isEntityHasId(user); + + PollenUser toSave; + + String userEmail = getCleanMail(user.getEmail()); + + String emailValidationToken = null; + + if (userExists) { + + toSave = getUser(user.getId()); + + boolean emailChanged = ObjectUtils.notEqual(toSave.getEmail(), + userEmail); + + if (emailChanged) { + + // add a new emailValidationtoken + emailValidationToken = generateToken(); + + //TODO Notify email changed + } + } else { + + toSave = getPersistenceContext().getPollenUserDao().newInstance(); + + // add a emailValidationToken + emailValidationToken = generateToken(); + + String password; + + if (generatePassword) { + // let's generate the new password + password = serviceContext.generatePassword(); + } else { + password = user.getPassword(); + } + + // encode the password + String encodedPassword = serviceContext.encodePassword(password); + + toSave.setLogin(user.getLogin()); + toSave.setPassword(encodedPassword); + } + + toSave.setAdministrator(user.isAdministrator()); + toSave.setName(user.getName()); + toSave.setLanguage(user.getLanguage()); + toSave.setEmail(userEmail); + + if (emailValidationToken != null) { + toSave.setEmailActivationToken(emailValidationToken); + } + + return toSave; + } +} Deleted: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/UserService.java =================================================================== --- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/UserService.java 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/UserService.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -1,252 +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 org.apache.commons.lang3.ObjectUtils; -import org.apache.commons.lang3.StringUtils; -import org.chorem.pollen.persistence.dao.PollenUserJpaDao; -import org.chorem.pollen.persistence.entity.PollenUser; -import org.chorem.pollen.services.PollenServiceSupport; -import org.chorem.pollen.services.exception.EntityNotFoundException; -import org.chorem.pollen.services.exception.UserEmailAlreadyUsedException; -import org.chorem.pollen.services.exception.UserInvalidEmailActiviationTokenException; -import org.chorem.pollen.services.exception.UserInvalidPasswordException; -import org.chorem.pollen.services.exception.UserLoginAlreadyUsedException; - -import java.util.List; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class UserService extends AbstractPollenService implements PollenServiceSupport { - - public List<PollenUser> getUsers() { - return getPollenUserDao().findAll(); - } - - public PollenUser getUser(String userId) throws EntityNotFoundException { - Preconditions.checkNotNull(userId); - - PollenUser result = getPollenUserDao().findById(userId); - checkEntityExists(PollenUser.class, result, userId); - return result; - } - - public PollenUser createUser(PollenUser user, boolean generatePassword) throws UserLoginAlreadyUsedException, UserEmailAlreadyUsedException { - Preconditions.checkNotNull(user); - checkHasNoId(user); - Preconditions.checkNotNull(user.getLogin()); - Preconditions.checkNotNull(user.getEmail()); - - PollenUserJpaDao dao = getPollenUserDao(); - - // check login is available - boolean loginExists = dao.loginExists(user.getLogin()); - if (loginExists) { - throw new UserLoginAlreadyUsedException(user.getLogin()); - } - - // check email is available - boolean emailExists = dao.emailExists(user.getEmail()); - if (emailExists) { - throw new UserEmailAlreadyUsedException(user.getEmail()); - } - - PollenUser toCreate = dao.newInstance(); - - // add a emailValidationToken - String emailValidationToken = generateToken(); - - String password; - if (generatePassword) { - // let's generate the new password - password = serviceContext.generatePassword(); - } else { - password = user.getPassword(); - } - - // encode the password - String encodedPassword = serviceContext.encodePassword(password); - - toCreate.setLogin(user.getLogin()); - toCreate.setEmailActivationToken(emailValidationToken); - toCreate.setPassword(encodedPassword); - - copyPollenUser(user, toCreate, true); - - dao.persist(toCreate); - getPersistenceContext().commit(); - - notifyUserCreated(toCreate); - - return toCreate; - } - - public PollenUser editUser(PollenUser user) throws UserInvalidPasswordException, UserEmailAlreadyUsedException, EntityNotFoundException { - Preconditions.checkNotNull(user); - checkHasId(user); - - PollenUser persisted = getUser(user.getId()); - - PollenUserJpaDao dao = getPollenUserDao(); - - // check current password - String encodedPassword = serviceContext.encodePassword(user.getPassword()); - if (!encodedPassword.equals(persisted.getPassword())) { - throw new UserInvalidPasswordException(); - } - - boolean emailChanged = ObjectUtils.notEqual(persisted.getEmail(), - user.getEmail()); - - if (emailChanged) { - - // check this email is not used by another user - boolean emailUsed = dao.emailExists(user.getEmail()); - if (emailUsed) { - throw new UserEmailAlreadyUsedException(user.getEmail()); - } - - // add a new emailValidationtoken - String emailValidationToken = generateToken(); - persisted.setEmailActivationToken(emailValidationToken); - } - - copyPollenUser(user, persisted, true); - - persisted = dao.merge(persisted); - getPersistenceContext().commit(); - - if (emailChanged) { - - notifyEmailChanged(persisted); - } - return persisted; - } - - public void changePassword(String userId, - String oldPassword, - String newPassword) throws UserInvalidPasswordException, EntityNotFoundException { - Preconditions.checkNotNull(userId); - Preconditions.checkNotNull(oldPassword); - Preconditions.checkNotNull(newPassword); - - PollenUser user = getUser(userId); - - // check current password - String encodedPassword = serviceContext.encodePassword(user.getPassword()); - if (!encodedPassword.equals(user.getPassword())) { - throw new UserInvalidPasswordException(); - } - - // encode new password and store it in user account - String newEncodedPassword = serviceContext.encodePassword(newPassword); - user.setPassword(newEncodedPassword); - - user = getPollenUserDao().merge(user); - getPersistenceContext().commit(); - - notifyPasswordChanged(user); - } - - public void validateUserEmail(String userId, - String token) throws EntityNotFoundException, UserInvalidEmailActiviationTokenException { - - Preconditions.checkNotNull(userId); - Preconditions.checkNotNull(token); - - PollenUser user = getUser(userId); - - Preconditions.checkNotNull(user); - - boolean valid = ObjectUtils.equals( - user.getEmailActivationToken(), token); - - if (!valid) { - throw new UserInvalidEmailActiviationTokenException(); - } - - // reset token in database - user.setEmailActivationToken(null); - - getPollenUserDao().merge(user); - getPersistenceContext().commit(); - } - - public void createDefaultUsers() throws UserEmailAlreadyUsedException, UserLoginAlreadyUsedException { - - PollenUser user = getPollenUserDao().newInstance(); - - user.setAdministrator(true); - String login = "admin"; - user.setLogin(login); - user.setEmail("admin@pollen.org"); - user.setPassword("admin"); - createUser(user, false); - } - - protected void notifyUserCreated(PollenUser user) { - - //TODO - } - - protected void notifyEmailChanged(PollenUser user) { - - //TODO - } - - protected void notifyPasswordChanged(PollenUser user) { - - //TODO - } - - protected PollenUserJpaDao getPollenUserDao() { - return getPersistenceContext().getPollenUserDao(); - } - - /** - * Copy {@code source} user account to {@code destination} one. - * The email is lower cased in the {@code destination} user account. - * - * @param source user account to copy - * @param destination which receive the copy - */ - protected void copyPollenUser(PollenUser source, - PollenUser destination, - boolean copyEmail) { - - destination.setAdministrator(source.isAdministrator()); - destination.setName(source.getName()); - destination.setLanguage(source.getLanguage()); - - if (copyEmail) { - // Don't keep case for email - destination.setEmail(StringUtils.lowerCase(source.getEmail())); - } - } -} 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 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -24,10 +24,15 @@ */ import com.google.common.base.Preconditions; +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.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; /** @@ -46,55 +51,124 @@ return result; } - public Vote getVote(String voteId) throws EntityNotFoundException{ + public Vote getVote(String pollId, String voteId) throws EntityNotFoundException { Preconditions.checkNotNull(voteId); - Vote result = getPersistenceContext().getVoteDao().findById(voteId); - checkEntityExists(Vote.class, result, voteId); + Poll poll = getPollService().getPoll(pollId); + + Vote result = getVote(poll, voteId); return result; } - public Vote addVote(String pollId, Vote vote)throws EntityNotFoundException { + + public Vote addVote(String pollId, Vote vote) throws EntityNotFoundException, InvalidVoteFormException { Preconditions.checkNotNull(pollId); Preconditions.checkNotNull(vote); checkHasNoId(vote); Poll poll = getPollService().getPoll(pollId); + checkVoteForm(poll, vote); - poll.addVote(vote); + Vote result = saveVote(poll, vote); + getPersistenceContext().getPollDao().merge(poll); - getPersistenceContext().commit(); - Vote result = getVote(vote.getId()); + //TODO Notify vote added return result; } - public Vote editVote(Vote vote)throws EntityNotFoundException { + public Vote editVote(String pollId, Vote vote) throws EntityNotFoundException, InvalidVoteFormException { Preconditions.checkNotNull(vote); checkHasId(vote); - getVote(vote.getId()); + Poll poll = getPollService().getPoll(pollId); + checkVoteForm(poll, vote); + Vote result = saveVote(poll, vote); + getPersistenceContext().getVoteDao().merge(vote); getPersistenceContext().commit(); - - Vote result = getVote(vote.getId()); + //TODO Notify vote edited return result; } - public void deleteVote(String pollId, String voteId)throws EntityNotFoundException { + public void deleteVote(String pollId, String voteId) throws EntityNotFoundException { Preconditions.checkNotNull(pollId); Preconditions.checkNotNull(voteId); Poll poll = getPollService().getPoll(pollId); - Vote vote = getVote(voteId); + Vote vote = getVote(poll, voteId); poll.removeVote(vote); getPersistenceContext().getPollDao().merge(poll); - getPersistenceContext().commit(); + //TODO Notify vote deleted } + protected void checkVoteForm(Poll poll, Vote vote) throws InvalidVoteFormException { + + //TODO use nuiton validator ? + Multimap<String, String> errors = ArrayListMultimap.create(); + + // poll can't be closed + checkNot(errors, "poll", poll.isClosed(), "poll can not be closed"); + + Date now = serviceContext.getNow(); + + // poll must be started + check(errors, "poll", poll.isStarted(now), "poll is not stardted"); + + checkNotBlank(errors, "voter.name", vote.getVoter().getName(), "voter name can not be empty"); + + //TODO Finish validation + + if (!errors.isEmpty()) { + + throw new InvalidVoteFormException(errors); + } + } + + protected Vote saveVote(Poll poll, Vote vote) throws EntityNotFoundException { + + boolean commentExists = JpaEntities.isEntityHasId(vote); + + Vote toSave; + + if (commentExists) { + + toSave = getVote(poll, vote.getId()); + } else { + + toSave = getPersistenceContext().getVoteDao().newInstance(); +// toSave.setPostDate(serviceContext.getNow()); + + // -- author -- // + +// PollenPrincipal author = getSecurityService().generatePrincipal(); +// toSave.setAuthor(author); + + poll.addVote(toSave); + } + +// toSave.setText(vote.getText()); +// +// // -- author -- // +// +// toSave.getAuthor().setName(vote.getAuthor().getName()); +// if (StringUtils.isNotBlank(vote.getAuthor().getEmail())) { +// toSave.getAuthor().setEmail(StringUtils.lowerCase(vote.getAuthor().getEmail())); +// } + + return toSave; + } + + protected Vote getVote(Poll poll, String voteId) throws EntityNotFoundException { + Preconditions.checkNotNull(voteId); + + Vote result = poll.getVoteById(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 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -28,7 +28,6 @@ import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import com.google.common.collect.Sets; -import org.apache.commons.lang3.StringUtils; import org.chorem.pollen.persistence.dao.VoterListJpaDao; import org.chorem.pollen.persistence.dao.VoterListMemberJpaDao; import org.chorem.pollen.persistence.entity.FavoriteList; @@ -37,7 +36,6 @@ 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.FavoriteListNotOwnedByUserException; import org.chorem.pollen.services.exception.InvalidVoterListFormException; import org.chorem.pollen.services.exception.InvalidVoterListMemberFormException; import org.nuiton.jpa.api.JpaEntities; @@ -54,7 +52,7 @@ public class VoterListService extends AbstractPollenService { public VoterList importFavoriteList(String userId, String pollId, - String favoriteListId) throws EntityNotFoundException, FavoriteListNotOwnedByUserException { + String favoriteListId) throws EntityNotFoundException { Preconditions.checkNotNull(pollId); Preconditions.checkNotNull(favoriteListId); @@ -171,7 +169,7 @@ return result; } - public VoterListMember addVoterListMember(String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException { + public VoterListMember addVoterListMember(String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException, InvalidVoterListMemberFormException { Preconditions.checkNotNull(pollId); Preconditions.checkNotNull(voterListId); Preconditions.checkNotNull(member); @@ -179,6 +177,8 @@ VoterList voterList = getVoterList(pollId, voterListId); + checkVoterListMember(voterList, member); + VoterListMember result = saveVoterListMember(voterList, member); getPersistenceContext().getVoterListDao().merge(voterList); @@ -187,7 +187,7 @@ } - public VoterListMember editVoterListMember(String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException { + public VoterListMember editVoterListMember(String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException, InvalidVoterListMemberFormException { Preconditions.checkNotNull(pollId); Preconditions.checkNotNull(voterListId); Preconditions.checkNotNull(member); @@ -195,6 +195,8 @@ VoterList voterList = getVoterList(pollId, voterListId); + checkVoterListMember(voterList, member); + VoterListMember result = saveVoterListMember(voterList, member); getPersistenceContext().getVoterListMemberDao().merge(member); @@ -283,7 +285,7 @@ } toSave.setName(voterListMember.getName()); - toSave.setEmail(StringUtils.lowerCase(voterListMember.getEmail())); + toSave.setEmail(getCleanMail(voterListMember.getEmail())); toSave.setWeight(voterListMember.getWeight()); return toSave; @@ -330,21 +332,19 @@ String voterListMemberField = "member[" + (voterListMemberIndex++) + "]."; String voterListMemberName = voterListMember.getName(); - boolean nameNotNull = checkNotBlank(errors, voterListMemberField + "name", voterListMemberName, "member name can not be empty"); + boolean nameNotBlank = checkNotBlank(errors, voterListMemberField + "name", voterListMemberName, "member name can not be empty"); - if (nameNotNull) { + if (nameNotBlank) { boolean nameAdded = voterListMemberNames.add(voterListMemberName); check(errors, voterListMemberField + "name", nameAdded, "member name already used in this list"); } - String voterListMemberEmail = voterListMember.getEmail(); + String voterListMemberEmail = getCleanMail(voterListMember.getEmail()); - boolean emailNotNull = checkNotBlank(errors, voterListMemberField + "email", voterListMemberEmail, "member email can not be empty"); + boolean emailNotBlank = checkNotBlank(errors, voterListMemberField + "email", voterListMemberEmail, "member email can not be empty"); - if (emailNotNull) { + if (emailNotBlank) { - voterListMemberEmail = StringUtils.lowerCase(voterListMemberEmail); - checkValidEmail(errors, voterListMemberField + "email", voterListMemberEmail, "member email is not valid"); boolean emailAdded = voterListMemberEmails.add(voterListMemberEmail); check(errors, voterListMemberField + "email", emailAdded, "member email already used in this list"); @@ -372,7 +372,8 @@ for (VoterListMember member : voterList.getVoterListMember()) { - if (voterListMemberExists && member.getId().equals(voterListMember.getId())) { + if (voterListMemberExists && + member.getId().equals(voterListMember.getId())) { continue; } @@ -381,21 +382,19 @@ } } String voterListMemberName = voterListMember.getName(); - boolean nameNotNull = checkNotBlank(errors, "name", voterListMemberName, "member name can not be empty"); + boolean nameNotblank = checkNotBlank(errors, "name", voterListMemberName, "member name can not be empty"); - if (nameNotNull) { + if (nameNotblank) { boolean nameAdded = voterListMemberNames.add(voterListMemberName); check(errors, "name", nameAdded, "member name already used in this list"); } - String voterListMemberEmail = voterListMember.getEmail(); + String voterListMemberEmail = getCleanMail(voterListMember.getEmail()); - boolean emailNotNull = checkNotBlank(errors, "email", voterListMemberEmail, "member email can not be empty"); + boolean emailNotBlank = checkNotBlank(errors, "email", voterListMemberEmail, "member email can not be empty"); - if (emailNotNull) { + if (emailNotBlank) { - voterListMemberEmail = StringUtils.lowerCase(voterListMemberEmail); - checkValidEmail(errors, "email", voterListMemberEmail, "member email is not valid"); boolean emailAdded = voterListMemberEmails.add(voterListMemberEmail); check(errors, "email", emailAdded, "member email already used in this list"); Copied: trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollenUserServiceTest.java (from rev 3833, trunk/pollen-services/src/test/java/org/chorem/pollen/service/UserServiceTest.java) =================================================================== --- trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollenUserServiceTest.java (rev 0) +++ trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollenUserServiceTest.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -0,0 +1,203 @@ +package org.chorem.pollen.service; + +/* + * #%L + * Pollen :: Service + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import org.apache.commons.collections.CollectionUtils; +import org.chorem.pollen.persistence.entity.PollenUser; +import org.chorem.pollen.services.exception.EntityNotFoundException; +import org.chorem.pollen.services.exception.InvalidPollenUserFormException; +import org.chorem.pollen.services.exception.UserInvalidEmailActivationTokenException; +import org.chorem.pollen.services.service.PollenUserService; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.text.ParseException; +import java.util.Date; +import java.util.List; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollenUserServiceTest extends AbstractPollenServiceTest { + + protected PollenUserService service; + + protected PollenUser user; + + @Before + public void setUp() throws ParseException { + + loadFixtures("fixtures"); + + service = serviceContext.getUserService(); + + serviceContext.setDate(new Date(1363948427576l)); + + user = fixture("tony"); + } + + @Test + public void testGetPollenUsers() { + + List<PollenUser> users = service.getUsers(); + + Assert.assertNotNull(users); + Assert.assertTrue(CollectionUtils.isNotEmpty(users)); + } + + @Test + public void testGetPollenUser() throws EntityNotFoundException { + + try { + service.getUser("pollen_user_tony_" + System.nanoTime()); + + } catch (EntityNotFoundException e) { + Assert.assertTrue(true); + } + + PollenUser user = service.getUser(this.user.getId()); + + Assert.assertNotNull(user); + Assert.assertEquals(this.user, user); + } + + @Test + public void testCreatePollenUser() throws Exception { + + try { + service.createUser(user, false); + Assert.fail(); + } catch (IllegalStateException e) { + // Should having id + Assert.assertTrue(true); + } + + PollenUser newUser = new PollenUser(); + newUser.setLogin("pollen"); + newUser.setEmail("pollen@pollen.org"); + + PollenUser savedUser = service.createUser(newUser, true); + Assert.assertNotNull(savedUser); + Assert.assertNotNull(savedUser.getId()); + + PollenUser newUser2 = new PollenUser(); + newUser2.setLogin("pollen"); + newUser2.setEmail("pollen@pollen.org"); + + try { + service.createUser(newUser2, true); + Assert.fail(); + } catch (InvalidPollenUserFormException e) { + // not available login + // not available email + assertErrorKeyFound(e, "login", "email"); + } + + newUser2.setLogin("pollen2"); + try { + service.createUser(newUser2, true); + Assert.fail(); + } catch (InvalidPollenUserFormException e) { + // not available email + assertErrorKeyFound(e, "email"); + } + + newUser2.setEmail("pollen2@pollen.org"); + PollenUser savedUser2 = service.createUser(newUser2, true); + Assert.assertNotNull(savedUser2); + Assert.assertNotNull(savedUser2.getId()); + } + + @Test + public void testEditUser() throws EntityNotFoundException, InvalidPollenUserFormException { + + PollenUser user = service.getUser(this.user.getId()); + + Assert.assertNotNull(user); + Assert.assertNull(user.getEmailActivationToken()); + + serviceContext.getPersistenceContext().detach(user); + + String originalLogin = user.getLogin(); + + user.setLogin("yetanotherlogin"); + String email = "tony@pollen.org"; + user.setEmail(email); + + try { + service.editUser(user); + Assert.fail(); + } catch (InvalidPollenUserFormException e) { + // invalid password + assertErrorKeyFound(e, "password"); + } + + user.setPassword("fake"); + PollenUser savedUser = service.editUser(user); + Assert.assertNotNull(savedUser); + Assert.assertEquals(originalLogin, savedUser.getLogin()); + Assert.assertEquals(email, savedUser.getEmail()); + Assert.assertNotNull(savedUser.getEmailActivationToken()); + } + + @Test + public void testValidateEmail() throws EntityNotFoundException, UserInvalidEmailActivationTokenException, InvalidPollenUserFormException { + + PollenUser user = service.getUser(this.user.getId()); + Assert.assertNotNull(user); + Assert.assertNull(user.getEmailActivationToken()); + + serviceContext.getPersistenceContext().detach(user); + + String email = "tony@pollen.org"; + user.setEmail(email); + user.setPassword("fake"); + + PollenUser savedUser = service.editUser(user); + Assert.assertNotNull(savedUser); + + Assert.assertEquals(email, savedUser.getEmail()); + Assert.assertNotNull(savedUser.getEmailActivationToken()); + + try { + service.validateUserEmail(user.getId(), "fakeToken"); + Assert.fail(); + } catch (UserInvalidEmailActivationTokenException e) { + Assert.assertTrue(true); + } + + Assert.assertFalse(savedUser.isEmailActivated()); + + service.validateUserEmail(user.getId(), savedUser.getEmailActivationToken()); + + + PollenUser reloadedUser = service.getUser(this.user.getId()); + Assert.assertTrue(reloadedUser.isEmailActivated()); + + } +} Deleted: trunk/pollen-services/src/test/java/org/chorem/pollen/service/UserServiceTest.java =================================================================== --- trunk/pollen-services/src/test/java/org/chorem/pollen/service/UserServiceTest.java 2013-06-17 16:40:14 UTC (rev 3833) +++ trunk/pollen-services/src/test/java/org/chorem/pollen/service/UserServiceTest.java 2013-06-18 06:22:46 UTC (rev 3834) @@ -1,202 +0,0 @@ -package org.chorem.pollen.service; - -/* - * #%L - * Pollen :: Service - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2013 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -import org.apache.commons.collections.CollectionUtils; -import org.chorem.pollen.persistence.entity.PollenUser; -import org.chorem.pollen.services.exception.EntityNotFoundException; -import org.chorem.pollen.services.exception.UserEmailAlreadyUsedException; -import org.chorem.pollen.services.exception.UserInvalidEmailActiviationTokenException; -import org.chorem.pollen.services.exception.UserInvalidPasswordException; -import org.chorem.pollen.services.exception.UserLoginAlreadyUsedException; -import org.chorem.pollen.services.service.UserService; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import java.text.ParseException; -import java.util.Date; -import java.util.List; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 2.0 - */ -public class UserServiceTest extends AbstractPollenServiceTest { - - protected UserService service; - - protected PollenUser user; - - @Before - public void setUp() throws ParseException { - - loadFixtures("fixtures"); - - service = serviceContext.getUserService(); - - serviceContext.setDate(new Date(1363948427576l)); - - user = fixture("tony"); - } - - @Test - public void testGetPollenUsers() { - - List<PollenUser> users = service.getUsers(); - - Assert.assertNotNull(users); - Assert.assertTrue(CollectionUtils.isNotEmpty(users)); - } - - @Test - public void testGetPollenUser() throws EntityNotFoundException { - - try { - service.getUser("pollen_user_tony_" + System.nanoTime()); - - } catch (EntityNotFoundException e) { - Assert.assertTrue(true); - } - - PollenUser user = service.getUser(this.user.getId()); - - Assert.assertNotNull(user); - Assert.assertEquals(this.user, user); - } - - @Test - public void testCreatePollenUser() throws Exception { - - try { - service.createUser(user, false); - Assert.fail(); - } catch (IllegalStateException e) { - // Should having id - Assert.assertTrue(true); - } - - PollenUser newUser = new PollenUser(); - newUser.setLogin("pollen"); - newUser.setEmail("pollen@pollen.org"); - - PollenUser savedUser = service.createUser(newUser, true); - Assert.assertNotNull(savedUser); - Assert.assertNotNull(savedUser.getId()); - - PollenUser newUser2 = new PollenUser(); - newUser2.setLogin("pollen"); - newUser2.setEmail("pollen@pollen.org"); - - try { - service.createUser(newUser2, true); - Assert.fail(); - } catch (UserLoginAlreadyUsedException e) { - Assert.assertTrue(true); - } - - newUser2.setLogin("pollen2"); - try { - service.createUser(newUser2, true); - Assert.fail(); - } catch (UserEmailAlreadyUsedException e) { - Assert.assertTrue(true); - } - - newUser2.setEmail("pollen2@pollen.org"); - PollenUser savedUser2 = service.createUser(newUser2, true); - Assert.assertNotNull(savedUser2); - Assert.assertNotNull(savedUser2.getId()); - } - - @Test - public void testEditUser() throws EntityNotFoundException, UserInvalidPasswordException, UserEmailAlreadyUsedException { - - PollenUser user = service.getUser(this.user.getId()); - - Assert.assertNotNull(user); - Assert.assertNull(user.getEmailActivationToken()); - - serviceContext.getPersistenceContext().detach(user); - - String originalLogin = user.getLogin(); - - user.setLogin("yetanotherlogin"); - String email = "tony@pollen.org"; - user.setEmail(email); - - try { - service.editUser(user); - Assert.fail(); - } catch (UserInvalidPasswordException e) { - Assert.assertTrue(true); - } - - user.setPassword("fake"); - PollenUser savedUser = service.editUser(user); - Assert.assertNotNull(savedUser); - Assert.assertEquals(originalLogin, savedUser.getLogin()); - Assert.assertEquals(email, savedUser.getEmail()); - Assert.assertNotNull(savedUser.getEmailActivationToken()); - } - - @Test - public void testValidateEmail() throws EntityNotFoundException, UserInvalidPasswordException, UserEmailAlreadyUsedException, UserInvalidEmailActiviationTokenException { - - PollenUser user = service.getUser(this.user.getId()); - Assert.assertNotNull(user); - Assert.assertNull(user.getEmailActivationToken()); - - serviceContext.getPersistenceContext().detach(user); - - String email = "tony@pollen.org"; - user.setEmail(email); - user.setPassword("fake"); - - PollenUser savedUser = service.editUser(user); - Assert.assertNotNull(savedUser); - - Assert.assertEquals(email, savedUser.getEmail()); - Assert.assertNotNull(savedUser.getEmailActivationToken()); - - try { - service.validateUserEmail(user.getId(), "fakeToken"); - Assert.fail(); - } catch (UserInvalidEmailActiviationTokenException e) { - Assert.assertTrue(true); - } - - Assert.assertFalse(savedUser.isEmailActivated()); - - service.validateUserEmail(user.getId(), savedUser.getEmailActivationToken()); - - - - PollenUser reloadedUser = service.getUser(this.user.getId()); - Assert.assertTrue(reloadedUser.isEmailActivated()); - - } -} Property changes on: trunk/pollen-ui-js/pom.xml ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Property changes on: trunk/pollen-ui-js/src/main/resources/nuiton-js/wro.properties ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Property changes on: trunk/pollen-ui-js/src/main/resources/nuiton-js/wro.xml ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native
participants (1)
-
tchemit@users.chorem.org