Pollen-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
June 2013
- 3 participants
- 32 discussions
r3832 - in trunk: pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1 pollen-services/src/main/java/org/chorem/pollen/services/exception pollen-services/src/main/java/org/chorem/pollen/services/service
by tchemitï¼ users.chorem.org 17 Jun '13
by tchemitï¼ users.chorem.org 17 Jun '13
17 Jun '13
Author: tchemit
Date: 2013-06-17 17:36:31 +0200 (Mon, 17 Jun 2013)
New Revision: 3832
Url: http://chorem.org/projects/pollen/repository/revisions/3832
Log:
review favorite list service
Added:
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidFavoriteListFormException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidFavoriteListMemberFormException.java
Removed:
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java
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/VoterListService.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/PollService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java
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-15 14:29:32 UTC (rev 3831)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListService.java 2013-06-17 15:36:31 UTC (rev 3832)
@@ -28,11 +28,10 @@
import org.chorem.pollen.services.PollenServiceContext;
import org.chorem.pollen.services.exception.EntityNotFoundException;
import org.chorem.pollen.services.exception.FavoriteListImportException;
-import org.chorem.pollen.services.exception.FavoriteListMemberEmailAlreadyUsedException;
-import org.chorem.pollen.services.exception.FavoriteListMemberNameAlreadyUsedException;
import org.chorem.pollen.services.exception.FavoriteListMemberNotOwnedByFavoriteListException;
-import org.chorem.pollen.services.exception.FavoriteListNameAlreadyUsedException;
import org.chorem.pollen.services.exception.FavoriteListNotOwnedByUserException;
+import org.chorem.pollen.services.exception.InvalidFavoriteListFormException;
+import org.chorem.pollen.services.exception.InvalidFavoriteListMemberFormException;
import org.debux.webmotion.server.WebMotionController;
import java.io.File;
@@ -52,15 +51,15 @@
return favoriteLists;
}
- public FavoriteList getFavoriteList(PollenServiceContext context, String favoriteListId) throws EntityNotFoundException {
- return context.getFavoriteListService().getFavoriteList(favoriteListId);
+ public FavoriteList getFavoriteList(PollenServiceContext context, String userId, String favoriteListId) throws EntityNotFoundException, FavoriteListNotOwnedByUserException {
+ return context.getFavoriteListService().getFavoriteList(userId, favoriteListId);
}
- public FavoriteList createFavoriteList(PollenServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, FavoriteListNameAlreadyUsedException {
+ public FavoriteList createFavoriteList(PollenServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, InvalidFavoriteListFormException {
return context.getFavoriteListService().createFavoriteList(userId, favoriteList);
}
- public FavoriteList editFavoriteList(PollenServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, FavoriteListNameAlreadyUsedException, FavoriteListNotOwnedByUserException {
+ public FavoriteList editFavoriteList(PollenServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, FavoriteListNotOwnedByUserException, InvalidFavoriteListFormException {
return context.getFavoriteListService().editFavoriteList(userId, favoriteList);
}
@@ -76,24 +75,24 @@
return context.getFavoriteListService().importFavoriteListMembersFromLdap(userId, favoriteListId, ldap);
}
- public List<FavoriteListMember> getMembers(PollenServiceContext context, String favoriteListId) throws EntityNotFoundException {
- List<FavoriteListMember> members = context.getFavoriteListService().getFavoriteListMembers(favoriteListId);
+ public List<FavoriteListMember> getMembers(PollenServiceContext context, String userId, String favoriteListId) throws EntityNotFoundException, FavoriteListNotOwnedByUserException {
+ List<FavoriteListMember> members = context.getFavoriteListService().getFavoriteListMembers(userId, favoriteListId);
return members;
}
- public FavoriteListMember getMember(PollenServiceContext context, String memberId) throws EntityNotFoundException {
- return context.getFavoriteListService().getFavoriteListMember(memberId);
+ public FavoriteListMember getMember(PollenServiceContext context, String userId, String favoriteListId, String memberId) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException, FavoriteListNotOwnedByUserException {
+ return context.getFavoriteListService().getFavoriteListMember(userId, favoriteListId, memberId);
}
- public FavoriteListMember addMember(PollenServiceContext context, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberEmailAlreadyUsedException, FavoriteListMemberNameAlreadyUsedException {
- return context.getFavoriteListService().addFavoriteListMember(favoriteListId, member);
+ public FavoriteListMember addMember(PollenServiceContext context, String userId, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, InvalidFavoriteListMemberFormException, FavoriteListNotOwnedByUserException {
+ return context.getFavoriteListService().addFavoriteListMember(userId, favoriteListId, member);
}
- public FavoriteListMember editMember(PollenServiceContext context, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberEmailAlreadyUsedException, FavoriteListMemberNameAlreadyUsedException, FavoriteListMemberNotOwnedByFavoriteListException {
- return context.getFavoriteListService().editFavoriteListMember(favoriteListId, member);
+ public FavoriteListMember editMember(PollenServiceContext context, String userId, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException, InvalidFavoriteListMemberFormException, FavoriteListNotOwnedByUserException {
+ return context.getFavoriteListService().editFavoriteListMember(userId, favoriteListId, member);
}
- public void removeMember(PollenServiceContext context, String favoriteListId, String memberId) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException {
- context.getFavoriteListService().removeFavoriteListMember(favoriteListId, memberId);
+ public void removeMember(PollenServiceContext context, String userId, String favoriteListId, String memberId) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException, FavoriteListNotOwnedByUserException {
+ context.getFavoriteListService().removeFavoriteListMember(userId, favoriteListId, memberId);
}
}
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-15 14:29:32 UTC (rev 3831)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java 2013-06-17 15:36:31 UTC (rev 3832)
@@ -27,6 +27,7 @@
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.debux.webmotion.server.WebMotionController;
@@ -41,8 +42,8 @@
*/
public class VoterListService extends WebMotionController {
- public VoterList importFavoriteList(PollenServiceContext context, String pollId, String favoriteListId) throws EntityNotFoundException {
- return context.getVoterListService().importFavoriteList(pollId, favoriteListId);
+ public VoterList importFavoriteList(PollenServiceContext context, String userId, String pollId, String favoriteListId) throws EntityNotFoundException, FavoriteListNotOwnedByUserException {
+ return context.getVoterListService().importFavoriteList(userId, pollId, favoriteListId);
}
public List<VoterList> getVoterLists(PollenServiceContext context, String pollId) throws EntityNotFoundException {
Deleted: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java 2013-06-15 14:29:32 UTC (rev 3831)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java 2013-06-17 15:36:31 UTC (rev 3832)
@@ -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(a)codelutin.com>
- * @since 2.0
- */
-public class FavoriteListMemberEmailAlreadyUsedException extends Exception {
-
- private static final long serialVersionUID = 1L;
-
- protected final String email;
-
- public FavoriteListMemberEmailAlreadyUsedException(String email) {
- this.email = email;
- }
-
- public String getEmail() {
- return email;
- }
-}
\ No newline at end of file
Deleted: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java 2013-06-15 14:29:32 UTC (rev 3831)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java 2013-06-17 15:36:31 UTC (rev 3832)
@@ -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(a)codelutin.com>
- * @since 2.0
- */
-public class FavoriteListMemberNameAlreadyUsedException extends Exception {
-
- private static final long serialVersionUID = 1L;
-
- protected final String name;
-
- public FavoriteListMemberNameAlreadyUsedException(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-}
\ No newline at end of file
Deleted: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java 2013-06-15 14:29:32 UTC (rev 3831)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java 2013-06-17 15:36:31 UTC (rev 3832)
@@ -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(a)codelutin.com>
- * @since 2.0
- */
-public class FavoriteListNameAlreadyUsedException extends Exception {
-
- private static final long serialVersionUID = 1L;
-
- protected final String name;
-
- public FavoriteListNameAlreadyUsedException(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-}
\ No newline at end of file
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidFavoriteListFormException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidFavoriteListFormException.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidFavoriteListFormException.java 2013-06-17 15:36:31 UTC (rev 3832)
@@ -0,0 +1,41 @@
+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(a)codelutin.com>
+ * @since 2.0
+ */
+public class InvalidFavoriteListFormException extends AbstractInvalidFormException {
+
+ private static final long serialVersionUID = 1L;
+
+ public InvalidFavoriteListFormException(Multimap<String, String> errors) {
+ super(errors);
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidFavoriteListFormException.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/InvalidFavoriteListMemberFormException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidFavoriteListMemberFormException.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidFavoriteListMemberFormException.java 2013-06-17 15:36:31 UTC (rev 3832)
@@ -0,0 +1,41 @@
+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(a)codelutin.com>
+ * @since 2.0
+ */
+public class InvalidFavoriteListMemberFormException extends AbstractInvalidFormException {
+
+ private static final long serialVersionUID = 1L;
+
+ public InvalidFavoriteListMemberFormException(Multimap<String, String> errors) {
+ super(errors);
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidFavoriteListMemberFormException.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java 2013-06-15 14:29:32 UTC (rev 3831)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java 2013-06-17 15:36:31 UTC (rev 3832)
@@ -24,9 +24,10 @@
*/
import com.google.common.base.Preconditions;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.chorem.pollen.persistence.entity.FavoriteList;
import org.chorem.pollen.persistence.entity.FavoriteListMember;
@@ -34,11 +35,11 @@
import org.chorem.pollen.services.PollenTechnicalException;
import org.chorem.pollen.services.exception.EntityNotFoundException;
import org.chorem.pollen.services.exception.FavoriteListImportException;
-import org.chorem.pollen.services.exception.FavoriteListMemberEmailAlreadyUsedException;
-import org.chorem.pollen.services.exception.FavoriteListMemberNameAlreadyUsedException;
import org.chorem.pollen.services.exception.FavoriteListMemberNotOwnedByFavoriteListException;
-import org.chorem.pollen.services.exception.FavoriteListNameAlreadyUsedException;
import org.chorem.pollen.services.exception.FavoriteListNotOwnedByUserException;
+import org.chorem.pollen.services.exception.InvalidFavoriteListFormException;
+import org.chorem.pollen.services.exception.InvalidFavoriteListMemberFormException;
+import org.nuiton.jpa.api.JpaEntities;
import org.nuiton.util.StringUtil;
import javax.naming.NamingEnumeration;
@@ -76,41 +77,26 @@
return result;
}
- public FavoriteList getFavoriteList(String favoriteListId) throws EntityNotFoundException {
+ public FavoriteList getFavoriteList(String userId, String favoriteListId) throws EntityNotFoundException, FavoriteListNotOwnedByUserException {
+ Preconditions.checkNotNull(userId);
Preconditions.checkNotNull(favoriteListId);
- FavoriteList result = getPersistenceContext().getFavoriteListDao().findById(favoriteListId);
- checkEntityExists(FavoriteList.class, result, favoriteListId);
+
+ PollenUser user = getUserService().getUser(userId);
+
+ FavoriteList result = getFavoriteList(user, favoriteListId);
return result;
}
public FavoriteList createFavoriteList(String userId,
- FavoriteList favoriteList) throws EntityNotFoundException, FavoriteListNameAlreadyUsedException {
+ FavoriteList favoriteList) throws EntityNotFoundException, InvalidFavoriteListFormException {
Preconditions.checkNotNull(userId);
Preconditions.checkNotNull(favoriteList);
checkHasNoId(favoriteList);
- String favoriteListName = favoriteList.getName();
-
- // can't accept favorite list without name
- Preconditions.checkArgument(StringUtils.isNotEmpty(favoriteListName));
-
PollenUser user = getUserService().getUser(userId);
- // check there is not already a favorite list with same name
- boolean nameFound = false;
- if (!user.isFavoriteListEmpty()) {
- for (FavoriteList list : user.getFavoriteList()) {
- if (favoriteListName.equals(list.getName())) {
- nameFound = true;
- break;
- }
- }
- }
+ checkFavoriteListForm(user, favoriteList);
- if (nameFound) {
- throw new FavoriteListNameAlreadyUsedException(favoriteListName);
- }
-
FavoriteList toSave = getPersistenceContext().getFavoriteListDao().newInstance();
copyFavoriteList(favoriteList, toSave);
@@ -122,51 +108,22 @@
}
public FavoriteList editFavoriteList(String userId,
- FavoriteList favoriteList) throws EntityNotFoundException, FavoriteListNameAlreadyUsedException, FavoriteListNotOwnedByUserException {
+ FavoriteList favoriteList) throws EntityNotFoundException, InvalidFavoriteListFormException, FavoriteListNotOwnedByUserException {
Preconditions.checkNotNull(favoriteList);
checkHasId(favoriteList);
- String favoriteListName = favoriteList.getName();
-
- // can't accept favorite list without name
- Preconditions.checkArgument(StringUtils.isNotEmpty(favoriteListName));
-
// get user
PollenUser user = getUserService().getUser(userId);
- // get list
- FavoriteList toSave = getFavoriteList(favoriteList.getId());
+ // get list to save
+ FavoriteList toSave = getFavoriteList(user, favoriteList.getId());
- // check user own this list
- boolean ownedByUser = user.containsFavoriteListById(favoriteList.getId());
+ checkFavoriteListForm(user, favoriteList);
- if (!ownedByUser) {
- throw new FavoriteListNotOwnedByUserException();
- }
- if (ObjectUtils.notEqual(favoriteListName, toSave.getName())) {
+ copyFavoriteList(favoriteList, toSave);
- // check that this name is not existing in another list
- boolean nameFound = false;
- if (!user.isFavoriteListEmpty()) {
- for (FavoriteList list : user.getFavoriteList()) {
- if (toSave != list &&
- favoriteListName.equals(list.getName())) {
-
- // found another list with same name
- nameFound = true;
- break;
- }
- }
- }
- if (nameFound) {
- throw new FavoriteListNameAlreadyUsedException(favoriteListName);
- }
- }
-
- copyFavoriteList(favoriteList, toSave);
getPersistenceContext().getFavoriteListDao().merge(toSave);
-
getPersistenceContext().commit();
return toSave;
}
@@ -177,7 +134,7 @@
PollenUser user = getUserService().getUser(userId);
- FavoriteList persisted = getFavoriteList(favoriteListId);
+ FavoriteList persisted = getFavoriteList(user, favoriteListId);
// check user own this list
boolean ownedByUser = user.containsFavoriteListById(favoriteListId);
@@ -186,62 +143,49 @@
}
user.removeFavoriteList(persisted);
+
getPersistenceContext().getPollenUserDao().merge(user);
-
getPersistenceContext().commit();
}
- public List<FavoriteListMember> getFavoriteListMembers(String favoriteListId) throws EntityNotFoundException {
+ public List<FavoriteListMember> getFavoriteListMembers(String userId, String favoriteListId) throws EntityNotFoundException, FavoriteListNotOwnedByUserException {
+ Preconditions.checkNotNull(userId);
Preconditions.checkNotNull(favoriteListId);
- FavoriteList favoriteList = getFavoriteList(favoriteListId);
+ PollenUser user = getUserService().getUser(userId);
+ FavoriteList favoriteList = getFavoriteList(user, favoriteListId);
+
return favoriteList.getFavoriteListMember();
}
- public FavoriteListMember getFavoriteListMember(String memberId) throws EntityNotFoundException {
+ public FavoriteListMember getFavoriteListMember(String userId, String favoriteListId, String memberId) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException, FavoriteListNotOwnedByUserException {
+ Preconditions.checkNotNull(userId);
+ Preconditions.checkNotNull(favoriteListId);
Preconditions.checkNotNull(memberId);
- FavoriteListMember result = getPersistenceContext().getFavoriteListMemberDao().findById(memberId);
- checkEntityExists(FavoriteListMember.class, result, memberId);
+
+ PollenUser user = getUserService().getUser(userId);
+
+ FavoriteList favoriteList = getFavoriteList(user, favoriteListId);
+
+ FavoriteListMember result = getFavoriteListMember(favoriteList, memberId);
return result;
}
- public FavoriteListMember addFavoriteListMember(String favoriteListId,
- FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberNameAlreadyUsedException, FavoriteListMemberEmailAlreadyUsedException {
+ public FavoriteListMember addFavoriteListMember(String userId,
+ String favoriteListId,
+ FavoriteListMember member) throws EntityNotFoundException, InvalidFavoriteListMemberFormException, FavoriteListNotOwnedByUserException {
+ Preconditions.checkNotNull(userId);
Preconditions.checkNotNull(favoriteListId);
Preconditions.checkNotNull(member);
checkHasNoId(member);
- // can't accept member without name
- String memberName = member.getName();
- Preconditions.checkArgument(StringUtils.isNotEmpty(memberName));
+ PollenUser user = getUserService().getUser(userId);
- // can't accept member without email
- String memberEmail = member.getEmail();
- Preconditions.checkArgument(StringUtils.isNotEmpty(memberEmail));
+ FavoriteList favoriteList = getFavoriteList(user, favoriteListId);
- // lowerCase email
- memberEmail = StringUtils.lowerCase(memberEmail);
+ checkFavoriteListMemberForm(favoriteList, member);
- //TODO Validate email form
-
- FavoriteList favoriteList = getFavoriteList(favoriteListId);
-
- if (!favoriteList.isFavoriteListMemberEmpty()) {
-
- for (FavoriteListMember listMember : favoriteList.getFavoriteListMember()) {
-
- // check there is no other member with same name
- if (memberName.equals(listMember.getName())) {
- throw new FavoriteListMemberNameAlreadyUsedException(memberName);
- }
- // check there is no other member with same email
- if (memberEmail.equals(listMember.getEmail())) {
- throw new FavoriteListMemberEmailAlreadyUsedException(memberEmail);
- }
- }
- }
-
FavoriteListMember newMember =
getPersistenceContext().getFavoriteListMemberDao().newInstance();
copyFavoriteListMember(member, newMember);
@@ -253,60 +197,25 @@
return newMember;
}
- public FavoriteListMember editFavoriteListMember(String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException, FavoriteListMemberNameAlreadyUsedException, FavoriteListMemberEmailAlreadyUsedException {
+ public FavoriteListMember editFavoriteListMember(String userId,
+ String favoriteListId,
+ FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException, InvalidFavoriteListMemberFormException, FavoriteListNotOwnedByUserException {
+ Preconditions.checkNotNull(userId);
+ Preconditions.checkNotNull(favoriteListId);
Preconditions.checkNotNull(member);
checkHasId(member);
- // can't accept member without name
- String memberName = member.getName();
- Preconditions.checkArgument(StringUtils.isNotEmpty(memberName));
- // can't accept member without email
- String memberEmail = member.getEmail();
- Preconditions.checkArgument(StringUtils.isNotEmpty(memberEmail));
+ PollenUser user = getUserService().getUser(userId);
- // lowerCase email
- memberEmail = StringUtils.lowerCase(memberEmail);
+ FavoriteList favoriteList = getFavoriteList(user, favoriteListId);
- //TODO Validate email form
-
- FavoriteList favoriteList = getFavoriteList(favoriteListId);
-
String memberId = member.getId();
- FavoriteListMember toSave = getFavoriteListMember(memberId);
+ FavoriteListMember toSave = getFavoriteListMember(favoriteList, memberId);
- // check favorite list own this member
- boolean ownedByUser = favoriteList.containsFavoriteListMemberById(memberId);
- if (!ownedByUser) {
- throw new FavoriteListMemberNotOwnedByFavoriteListException();
- }
+ checkFavoriteListMemberForm(favoriteList, member);
-
- if (!memberName.equals(toSave.getName())) {
-
- // name has changed must check name is available in the list
- for (FavoriteListMember listMember : favoriteList.getFavoriteListMember()) {
-
- // check there is no other member with same name
- if (!memberId.equals(listMember.getId()) &&
- memberName.equals(listMember.getName())) {
- throw new FavoriteListMemberNameAlreadyUsedException(memberName);
- }
- }
- }
-
- if (!memberEmail.equals(toSave.getEmail())) {
-
- // email has changed must check name is available in the list
- for (FavoriteListMember listMember : favoriteList.getFavoriteListMember()) {
-
- if (!memberId.equals(listMember.getId()) &&
- memberEmail.equals(listMember.getEmail())) {
- throw new FavoriteListMemberEmailAlreadyUsedException(memberEmail);
- }
- }
- }
copyFavoriteListMember(member, toSave);
getPersistenceContext().getFavoriteListMemberDao().merge(toSave);
@@ -315,19 +224,18 @@
return toSave;
}
- public void removeFavoriteListMember(String favoriteListId, String memberId) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException {
+ public void removeFavoriteListMember(String userId,
+ String favoriteListId,
+ String memberId) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException, FavoriteListNotOwnedByUserException {
+ Preconditions.checkNotNull(userId);
Preconditions.checkNotNull(favoriteListId);
Preconditions.checkNotNull(memberId);
- FavoriteList favoriteList = getFavoriteList(favoriteListId);
+ PollenUser user = getUserService().getUser(userId);
- FavoriteListMember member = getFavoriteListMember(memberId);
+ FavoriteList favoriteList = getFavoriteList(user, favoriteListId);
- // check favorite list own this member
- boolean ownedByUser = favoriteList.containsFavoriteListMemberById(memberId);
- if (!ownedByUser) {
- throw new FavoriteListMemberNotOwnedByFavoriteListException();
- }
+ FavoriteListMember member = getFavoriteListMember(favoriteList, memberId);
favoriteList.removeFavoriteListMember(member);
@@ -335,7 +243,8 @@
getPersistenceContext().commit();
}
- public int importFavoriteListMembersFromCsv(String userId, String favoriteListId,
+ public int importFavoriteListMembersFromCsv(String userId,
+ String favoriteListId,
File file) throws EntityNotFoundException, FavoriteListImportException, FavoriteListNotOwnedByUserException {
Preconditions.checkNotNull(userId);
Preconditions.checkNotNull(favoriteListId);
@@ -343,14 +252,8 @@
PollenUser user = getUserService().getUser(userId);
- FavoriteList favoriteList = getFavoriteList(favoriteListId);
+ FavoriteList favoriteList = getFavoriteList(user, favoriteListId);
- // check user own this list
- boolean ownedByUser = user.containsFavoriteListById(favoriteListId);
- if (!ownedByUser) {
- throw new FavoriteListNotOwnedByUserException();
- }
-
Locale locale = serviceContext.getLocale();
Set<String> usedName = Sets.newHashSet();
@@ -447,14 +350,8 @@
PollenUser user = getUserService().getUser(userId);
- FavoriteList favoriteList = getFavoriteList(favoriteListId);
+ FavoriteList favoriteList = getFavoriteList(user, favoriteListId);
- // check user own this list
- boolean ownedByUser = user.containsFavoriteListById(favoriteListId);
- if (!ownedByUser) {
- throw new FavoriteListNotOwnedByUserException();
- }
-
Locale locale = serviceContext.getLocale();
Set<String> usedName = Sets.newHashSet();
@@ -532,6 +429,34 @@
return result;
}
+ protected FavoriteList getFavoriteList(PollenUser user, String favoriteListId) throws EntityNotFoundException, FavoriteListNotOwnedByUserException {
+ 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 {
+
+ 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;
+ }
+
protected void copyFavoriteList(FavoriteList source,
FavoriteList destination) {
@@ -544,4 +469,119 @@
destination.setName(source.getName());
destination.setEmail(StringUtils.lowerCase(source.getEmail()));
}
+
+ protected void checkFavoriteListForm(PollenUser user, FavoriteList favoriteList) throws InvalidFavoriteListFormException {
+
+ //TODO use nuiton validator ?
+ Multimap<String, String> errors = ArrayListMultimap.create();
+
+ String favoriteListName = favoriteList.getName();
+
+ // can't accept favorite list without name
+ checkNotBlank(errors, "name", favoriteListName, "name can not be empty");
+
+
+ // check there is not already a favorite list with same name
+ boolean nameFound = false;
+ if (!user.isFavoriteListEmpty()) {
+ for (FavoriteList list : user.getFavoriteList()) {
+ if (favoriteListName.equals(list.getName())) {
+ nameFound = true;
+ break;
+ }
+ }
+ }
+
+ check(errors, "name", !nameFound, "name already used by another favorite list");
+
+ if (!favoriteList.isFavoriteListMemberEmpty()) {
+
+ int memberIndex = 0;
+
+ Set<String> memberNames = Sets.newHashSet();
+ Set<String> memberEmails = Sets.newHashSet();
+
+ for (FavoriteListMember member : favoriteList.getFavoriteListMember()) {
+
+ String choiceField = "favoriteListMember[" + (memberIndex++) + "].";
+
+ boolean notBlankName = checkNotBlank(errors, choiceField + "name", member.getName(), "member name can not be empty");
+ if (notBlankName) {
+ boolean added = memberNames.add(member.getName());
+
+ check(errors, choiceField + "name", added, "member name already used");
+ }
+
+ String memberEmail = member.getEmail();
+
+ boolean emailNotNull = checkNotBlank(errors, choiceField + "email", memberEmail, "member email can not be empty");
+
+ if (emailNotNull) {
+
+ 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");
+ }
+ }
+ }
+
+ if (!errors.isEmpty()) {
+
+ throw new InvalidFavoriteListFormException(errors);
+ }
+ }
+
+
+ protected void checkFavoriteListMemberForm(FavoriteList favoriteList, FavoriteListMember favoriteListMember) throws InvalidFavoriteListMemberFormException {
+
+ //TODO use nuiton validator ?
+ Multimap<String, String> errors = ArrayListMultimap.create();
+
+ boolean voterListMemberExists = JpaEntities.isEntityHasId(favoriteListMember);
+
+ Set<String> memberNames = Sets.newHashSet();
+ Set<String> memberEmails = Sets.newHashSet();
+
+ if (!favoriteList.isFavoriteListMemberEmpty()) {
+
+ // get all used names
+
+ for (FavoriteListMember member : favoriteList.getFavoriteListMember()) {
+
+ if (voterListMemberExists && member.getId().equals(member.getId())) {
+ continue;
+ }
+
+ memberNames.add(member.getName());
+ memberEmails.add(member.getEmail());
+ }
+ }
+
+ boolean notBlankName = checkNotBlank(errors, "name", favoriteListMember.getName(), "member name can not be empty");
+ if (notBlankName) {
+ boolean added = memberNames.add(favoriteListMember.getName());
+
+ check(errors, "name", added, "member name already used");
+ }
+
+ String memberEmail = favoriteListMember.getEmail();
+
+ boolean emailNotNull = checkNotBlank(errors, "email", memberEmail, "member email can not be empty");
+
+ if (emailNotNull) {
+
+ 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");
+ }
+
+ if (!errors.isEmpty()) {
+
+ throw new InvalidFavoriteListMemberFormException(errors);
+ }
+ }
}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java 2013-06-15 14:29:32 UTC (rev 3831)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java 2013-06-17 15:36:31 UTC (rev 3832)
@@ -274,8 +274,10 @@
if (poll.isFreePoll()) {
checkEmpty(errors, "voterList", poll.getVoterList(), "can't have voterList with free poll");
- } else {
- checkNotEmpty(errors, "voterList", poll.getVoterList(), "must have voterList with not free poll");
+ } else if (poll.isRestrictedPoll()) {
+ check(errors, "voterList", 1 == poll.sizeVoterList(), "must have a unique voterList with a resitricted poll");
+ } else if (poll.isGroupPoll()) {
+ checkNotEmpty(errors, "voterList", poll.getVoterList(), "must have at least one voterList with a group poll");
}
if (!poll.isChoiceEmpty()) {
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-15 14:29:32 UTC (rev 3831)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java 2013-06-17 15:36:31 UTC (rev 3832)
@@ -37,6 +37,7 @@
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;
@@ -52,14 +53,14 @@
*/
public class VoterListService extends AbstractPollenService {
- public VoterList importFavoriteList(String pollId,
- String favoriteListId) throws EntityNotFoundException {
+ public VoterList importFavoriteList(String userId, String pollId,
+ String favoriteListId) throws EntityNotFoundException, FavoriteListNotOwnedByUserException {
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(favoriteListId);
Poll poll = getPollService().getPoll(pollId);
- FavoriteList favoriteList = getFavoriteListService().getFavoriteList(favoriteListId);
+ FavoriteList favoriteList = getFavoriteListService().getFavoriteList(userId, favoriteListId);
VoterListJpaDao dao = getPersistenceContext().getVoterListDao();
VoterList result = dao.newInstance();
1
0
r3831 - in trunk: pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1 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/pollen/service pollen-ui-js/src/main/webapp/bundle pollen-ui-js/src/main/webapp/js/libs
by tchemitï¼ users.chorem.org 15 Jun '13
by tchemitï¼ users.chorem.org 15 Jun '13
15 Jun '13
Author: tchemit
Date: 2013-06-15 16:29:32 +0200 (Sat, 15 Jun 2013)
New Revision: 3831
Url: http://chorem.org/projects/pollen/repository/revisions/3831
Log:
continue edit form + add service poll test
Added:
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoterListFormException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoterListMemberFormException.java
trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollServiceTest.java
Modified:
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/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/PollService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java
trunk/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java
trunk/pollen-ui-js/src/main/webapp/bundle/Messages.properties
trunk/pollen-ui-js/src/main/webapp/js/libs/jquery.i18n.properties-min-1.0.9.js
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-15 10:58:03 UTC (rev 3830)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java 2013-06-15 14:29:32 UTC (rev 3831)
@@ -27,6 +27,7 @@
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.InvalidVoterListFormException;
import org.debux.webmotion.server.WebMotionController;
import java.util.List;
@@ -53,11 +54,11 @@
return context.getVoterListService().getVoterList(pollId, voterListId);
}
- public VoterList addVoterList(PollenServiceContext context, String pollId, VoterList voterList) throws EntityNotFoundException {
+ public VoterList addVoterList(PollenServiceContext context, String pollId, VoterList voterList) throws EntityNotFoundException, InvalidVoterListFormException {
return context.getVoterListService().addVoterList(pollId, voterList);
}
- public VoterList editVoterList(PollenServiceContext context, String pollId, VoterList voterList) throws EntityNotFoundException {
+ public VoterList editVoterList(PollenServiceContext context, String pollId, VoterList voterList) throws EntityNotFoundException, InvalidVoterListFormException {
return context.getVoterListService().editVoterList(pollId, voterList);
}
@@ -66,23 +67,23 @@
}
public Set<VoterListMember> getMembers(PollenServiceContext context, String pollId, String voterListId) throws EntityNotFoundException {
- Set<VoterListMember> members = context.getVoterListService().getMembers(pollId, voterListId);
+ Set<VoterListMember> members = context.getVoterListService().getVoterListMembers(pollId, voterListId);
return members;
}
public VoterListMember getMember(PollenServiceContext context, String pollId, String voterListId, String memberId) throws EntityNotFoundException {
- return context.getVoterListService().getMember(pollId, voterListId, memberId);
+ return context.getVoterListService().getVoterListMember(pollId, voterListId, memberId);
}
public VoterListMember addMember(PollenServiceContext context, String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException {
- return context.getVoterListService().addMember(pollId, voterListId, member);
+ return context.getVoterListService().addVoterListMember(pollId, voterListId, member);
}
public VoterListMember editMember(PollenServiceContext context, String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException {
- return context.getVoterListService().editMember(pollId, voterListId, member);
+ return context.getVoterListService().editVoterListMember(pollId, voterListId, member);
}
public void deleteMember(PollenServiceContext context, String pollId, String voterListId, String memberId) throws EntityNotFoundException {
- context.getVoterListService().deleteMember(pollId, voterListId, memberId);
+ context.getVoterListService().deleteVoterListMember(pollId, voterListId, memberId);
}
}
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-15 10:58:03 UTC (rev 3830)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/AbstractInvalidFormException.java 2013-06-15 14:29:32 UTC (rev 3831)
@@ -44,4 +44,9 @@
public Multimap<String, String> getErrors() {
return errors;
}
+
+ @Override
+ public String toString() {
+ return super.toString()+ " errors: "+errors;
+ }
}
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoterListFormException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoterListFormException.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoterListFormException.java 2013-06-15 14:29:32 UTC (rev 3831)
@@ -0,0 +1,41 @@
+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(a)codelutin.com>
+ * @since 2.0
+ */
+public class InvalidVoterListFormException extends AbstractInvalidFormException {
+
+ private static final long serialVersionUID = 1L;
+
+ public InvalidVoterListFormException(Multimap<String, String> errors) {
+ super(errors);
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoterListFormException.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/InvalidVoterListMemberFormException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoterListMemberFormException.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoterListMemberFormException.java 2013-06-15 14:29:32 UTC (rev 3831)
@@ -0,0 +1,41 @@
+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(a)codelutin.com>
+ * @since 2.0
+ */
+public class InvalidVoterListMemberFormException extends AbstractInvalidFormException {
+
+ private static final long serialVersionUID = 1L;
+
+ public InvalidVoterListMemberFormException(Multimap<String, String> errors) {
+ super(errors);
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoterListMemberFormException.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java 2013-06-15 10:58:03 UTC (rev 3830)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java 2013-06-15 14:29:32 UTC (rev 3831)
@@ -25,6 +25,7 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.Multimap;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.chorem.pollen.persistence.PollenPersistenceContext;
import org.chorem.pollen.services.PollenServiceContext;
@@ -35,6 +36,7 @@
import org.nuiton.jpa.api.JpaEntity;
import org.nuiton.util.StringUtil;
+import java.util.Collection;
import java.util.Date;
/**
@@ -141,6 +143,16 @@
return valid;
}
+ protected boolean checkEmpty(Multimap<String, String> errors, String field, Collection<?> value, String error) {
+ boolean valid = check(errors, field, CollectionUtils.isEmpty(value ), error);
+ return valid;
+ }
+
+ protected boolean checkNotEmpty(Multimap<String, String> errors, String field, Collection<?> value, String error) {
+ boolean valid = check(errors, field, CollectionUtils.isNotEmpty(value ), error);
+ return valid;
+ }
+
protected boolean checkNotBlank(Multimap<String, String> errors, String field, String value, String error) {
boolean valid = check(errors, field, StringUtils.isNotBlank(value), error);
return valid;
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java 2013-06-15 10:58:03 UTC (rev 3830)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java 2013-06-15 14:29:32 UTC (rev 3831)
@@ -25,6 +25,7 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import org.apache.commons.lang3.StringUtils;
@@ -111,6 +112,9 @@
creator.setName(user.getName());
creator.setEmail(user.getEmail());
}
+
+ result.setChoice(Lists.<Choice>newArrayList());
+ result.setVoterList(Lists.<VoterList>newArrayList());
return result;
}
@@ -266,12 +270,12 @@
checkNotNull(errors, "voteCountingType", poll.getVoteCountingType(), "voteCountingType can not be null");
checkNotBlank(errors, "title", poll.getTitle(), "title can not be empty");
- check(errors, "choice", poll.isChoiceEmpty(), "need at least one choice");
+ checkNotEmpty(errors, "choice", poll.getChoice(), "need at least one choice");
if (poll.isFreePoll()) {
- check(errors, "pollType", poll.isVoterListEmpty(), "can't have voterList with free poll");
+ checkEmpty(errors, "voterList", poll.getVoterList(), "can't have voterList with free poll");
} else {
- check(errors, "pollType", !poll.isVoterListEmpty(), "must have voterList with not free poll");
+ checkNotEmpty(errors, "voterList", poll.getVoterList(), "must have voterList with not free poll");
}
if (!poll.isChoiceEmpty()) {
@@ -313,44 +317,50 @@
for (VoterList voterList : poll.getVoterList()) {
- String voterListField = "voterList[" + (voterListIndex++) + "]";
+ String voterListField = "voterList[" + (voterListIndex++) + "].";
- checkNotBlank(errors, voterListField + ".name", voterList.getName(), "voterList name can not be empty");
- check(errors, voterListField + ".weight", voterList.getWeight() > 0, "voterList weight must be greater than 0");
- check(errors, voterListField + ".member", !voterList.isVoterListMemberEmpty(), "voterList must contains at least one member");
+ boolean notBlankName = checkNotBlank(errors, voterListField + "name", voterList.getName(), "voterList name can not be empty");
- boolean added = voterListNames.add(voterList.getName());
+ if (notBlankName) {
+ boolean added = voterListNames.add(voterList.getName());
- check(errors, voterListField, added, "voterList name already used");
+ check(errors, voterListField + "name", added, "voterList name already used");
+ }
+ check(errors, voterListField + "weight", voterList.getWeight() > 0, "voterList weight must be greater than 0");
+ boolean withMember = checkNotEmpty(errors, voterListField + "member", voterList.getVoterListMember(), "voterList must contains at least one member");
- Set<String> voterListMemberNames = Sets.newHashSet();
- Set<String> voterListMemberEmails = Sets.newHashSet();
+ if (withMember) {
+ Set<String> voterListMemberNames = Sets.newHashSet();
+ Set<String> voterListMemberEmails = Sets.newHashSet();
- int voterListMemberIndex = 0;
+ int voterListMemberIndex = 0;
- for (VoterListMember voterListMember : voterList.getVoterListMember()) {
+ for (VoterListMember voterListMember : voterList.getVoterListMember()) {
- String voterListMemberField = voterListField + ".member[" + (voterListMemberIndex++) + "]";
+ String voterListMemberField = voterListField + "member[" + (voterListMemberIndex++) + "].";
- String voterListMemberName = voterListMember.getName();
- boolean nameNotNull = checkNotBlank(errors, voterListMemberField + ".name", voterListMemberName, "member name can not be empty");
+ String voterListMemberName = voterListMember.getName();
+ boolean nameNotNull = checkNotBlank(errors, voterListMemberField + "name", voterListMemberName, "member name can not be empty");
- if (nameNotNull) {
- boolean nameAdded = voterListMemberNames.add(voterListMemberName);
- check(errors, voterListMemberField + ".name", nameAdded, "member name already used in this list");
- }
+ if (nameNotNull) {
+ boolean nameAdded = voterListMemberNames.add(voterListMemberName);
+ check(errors, voterListMemberField + "name", nameAdded, "member name already used in this list");
+ }
- String voterListMemberEmail = voterListMember.getEmail();
+ String voterListMemberEmail = voterListMember.getEmail();
- boolean emailNotNull = checkNotBlank(errors, voterListMemberField + ".email", voterListMemberEmail, "member email can not be empty");
+ boolean emailNotNull = checkNotBlank(errors, voterListMemberField + "email", voterListMemberEmail, "member email can not be empty");
- if (emailNotNull) {
+ if (emailNotNull) {
- voterListMemberEmail = StringUtils.lowerCase(voterListMemberEmail);
+ 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");
+ 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");
+ }
+
+ check(errors, voterListMemberField + "weight", voterListMember.getWeight() > 0, "member weight must be greater than 0");
}
}
}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java 2013-06-15 10:58:03 UTC (rev 3830)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java 2013-06-15 14:29:32 UTC (rev 3831)
@@ -39,6 +39,7 @@
PollenPrincipal principal = pollenPrincipalDao.newInstance();
principal.setToken(serviceContext.generateToken());
principal.setCreationDate(serviceContext.getNow());
+ pollenPrincipalDao.persist(principal);
return principal;
}
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-15 10:58:03 UTC (rev 3830)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java 2013-06-15 14:29:32 UTC (rev 3831)
@@ -24,6 +24,10 @@
*/
import com.google.common.base.Preconditions;
+import com.google.common.collect.ArrayListMultimap;
+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;
@@ -33,6 +37,8 @@
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.InvalidVoterListFormException;
+import org.chorem.pollen.services.exception.InvalidVoterListMemberFormException;
import org.nuiton.jpa.api.JpaEntities;
import java.util.List;
@@ -75,7 +81,6 @@
poll.addVoterList(result);
getPersistenceContext().getPollDao().merge(poll);
-
getPersistenceContext().commit();
return result;
}
@@ -85,25 +90,28 @@
Poll poll = getPollService().getPoll(pollId);
- List<VoterList> result = poll.getVoterList();
+ List<VoterList> result = Lists.newArrayList(poll.getVoterList());
return result;
}
public VoterList getVoterList(String pollId, String voterListId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(voterListId);
- VoterList result = getPersistenceContext().getVoterListDao().findById(voterListId);
- checkEntityExists(VoterList.class, result, voterListId);
+ Poll poll = getPollService().getPoll(pollId);
+ VoterList result = getVoterList(poll, voterListId);
return result;
}
- public VoterList addVoterList(String pollId, VoterList voterList) throws EntityNotFoundException {
+ public VoterList addVoterList(String pollId, VoterList voterList) throws EntityNotFoundException, InvalidVoterListFormException {
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(voterList);
checkHasNoId(voterList);
Poll poll = getPollService().getPoll(pollId);
+ checkVoterList(poll, voterList);
+
VoterList result = saveVoterList(poll, voterList);
getPersistenceContext().getPollDao().merge(poll);
@@ -111,12 +119,14 @@
return result;
}
- public VoterList editVoterList(String pollId, VoterList voterList) throws EntityNotFoundException {
+ public VoterList editVoterList(String pollId, VoterList voterList) throws EntityNotFoundException, InvalidVoterListFormException {
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(voterList);
checkHasId(voterList);
Poll poll = getPollService().getPoll(pollId);
+ checkVoterList(poll, voterList);
+
VoterList result = saveVoterList(poll, voterList);
getPersistenceContext().getVoterListDao().merge(voterList);
@@ -130,16 +140,16 @@
Poll poll = getPollService().getPoll(pollId);
- VoterList voterList = getVoterList(pollId, voterListId);
+ VoterList voterList = getVoterList(poll, voterListId);
poll.removeVoterList(voterList);
getPersistenceContext().getPollDao().merge(poll);
-
getPersistenceContext().commit();
}
- public Set<VoterListMember> getMembers(String pollId, String voterListId) throws EntityNotFoundException {
+ public Set<VoterListMember> getVoterListMembers(String pollId, String voterListId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(voterListId);
VoterList voterList = getVoterList(pollId, voterListId);
@@ -148,26 +158,20 @@
return result;
}
- public VoterListMember getMember(String pollId, String voterListId, String memberId) throws EntityNotFoundException {
+ public VoterListMember getVoterListMember(String pollId, String voterListId, String memberId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
+ Preconditions.checkNotNull(voterListId);
Preconditions.checkNotNull(memberId);
VoterList voterList = getVoterList(pollId, voterListId);
- VoterListMember result = getMember(voterList, memberId);
+ VoterListMember result = getVoterListMember(voterList, memberId);
checkEntityExists(VoterListMember.class, result, memberId);
return result;
}
-
- public VoterListMember getMember(VoterList voterList, String memberId) throws EntityNotFoundException {
- Preconditions.checkNotNull(memberId);
-
- VoterListMember result = voterList.getVoterListMemberById(memberId);
- checkEntityExists(VoterListMember.class, result, memberId);
- return result;
- }
-
- public VoterListMember addMember(String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException {
+ public VoterListMember addVoterListMember(String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(voterListId);
Preconditions.checkNotNull(member);
checkHasNoId(member);
@@ -181,7 +185,9 @@
return result;
}
- public VoterListMember editMember(String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException {
+
+ public VoterListMember editVoterListMember(String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(voterListId);
Preconditions.checkNotNull(member);
checkHasId(member);
@@ -195,13 +201,14 @@
return result;
}
- public void deleteMember(String pollId, String voterListId, String memberId) throws EntityNotFoundException {
+ public void deleteVoterListMember(String pollId, String voterListId, String memberId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(voterListId);
Preconditions.checkNotNull(memberId);
VoterList voterList = getVoterList(pollId, voterListId);
- VoterListMember member = getMember(voterList, memberId);
+ VoterListMember member = getVoterListMember(voterList, memberId);
voterList.removeVoterListMember(member);
getPersistenceContext().getVoterListDao().merge(voterList);
@@ -209,34 +216,48 @@
getPersistenceContext().commit();
}
+ protected VoterList getVoterList(Poll poll, String voterListId) throws EntityNotFoundException {
+
+ VoterList result = poll.getVoterListById(voterListId);
+ checkEntityExists(VoterList.class, result, voterListId);
+ return result;
+ }
+
+ protected VoterListMember getVoterListMember(VoterList voterList, String memberId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(memberId);
+
+ VoterListMember result = voterList.getVoterListMemberById(memberId);
+ checkEntityExists(VoterListMember.class, result, memberId);
+ return result;
+ }
+
protected VoterList saveVoterList(Poll poll, VoterList voterList) throws EntityNotFoundException {
boolean voterListExists = JpaEntities.isEntityHasId(voterList);
- VoterList voterListToPersist;
+ VoterList toSave;
if (voterListExists) {
- voterListToPersist =
- getVoterListService().getVoterList(poll.getId(), voterList.getId());
+ toSave = getVoterList(poll, voterList.getId());
} else {
VoterListJpaDao voterListDao =
getPersistenceContext().getVoterListDao();
- voterListToPersist = voterListDao.newInstance();
+ toSave = voterListDao.newInstance();
- poll.addVoterList(voterListToPersist);
+ poll.addVoterList(toSave);
}
- voterListToPersist.setName(voterList.getName());
- voterListToPersist.setWeight(voterList.getWeight());
+ toSave.setName(voterList.getName());
+ toSave.setWeight(voterList.getWeight());
for (VoterListMember voterListMember : voterList.getVoterListMember()) {
- saveVoterListMember(voterListToPersist, voterListMember);
+ saveVoterListMember(toSave, voterListMember);
}
- return voterListToPersist;
+ return toSave;
}
protected VoterListMember saveVoterListMember(VoterList voterList,
@@ -245,26 +266,143 @@
boolean voterListMemberExists =
JpaEntities.isEntityHasId(voterListMember);
- VoterListMember voterListMemberToPersist;
+ VoterListMember toSave;
if (voterListMemberExists) {
- voterListMemberToPersist =
- getMember(voterList, voterListMember.getId());
+ toSave = getVoterListMember(voterList, voterListMember.getId());
} else {
VoterListMemberJpaDao voterListMemberDao =
getPersistenceContext().getVoterListMemberDao();
- voterListMemberToPersist = voterListMemberDao.newInstance();
+ toSave = voterListMemberDao.newInstance();
- voterList.addVoterListMember(voterListMemberToPersist);
+ voterList.addVoterListMember(toSave);
}
- voterListMemberToPersist.setName(voterListMember.getName());
- voterListMemberToPersist.setEmail(StringUtils.lowerCase(voterListMember.getEmail()));
- voterListMemberToPersist.setWeight(voterListMember.getWeight());
+ toSave.setName(voterListMember.getName());
+ toSave.setEmail(StringUtils.lowerCase(voterListMember.getEmail()));
+ toSave.setWeight(voterListMember.getWeight());
- return voterListMemberToPersist;
+ return toSave;
}
+
+ protected void checkVoterList(Poll poll, VoterList voterList) throws InvalidVoterListFormException {
+
+ //TODO use nuiton validator ?
+ Multimap<String, String> errors = ArrayListMultimap.create();
+
+ boolean voterListExists = JpaEntities.isEntityHasId(voterList);
+
+ Set<String> voterListNames = Sets.newHashSet();
+
+ if (!poll.isVoterListEmpty()) {
+
+ // get all used names
+
+ for (VoterList lists : poll.getVoterList()) {
+
+ if (voterListExists && lists.getId().equals(voterList.getId())) {
+ continue;
+ }
+
+ voterListNames.add(voterList.getName());
+ }
+ }
+
+ checkNotBlank(errors, "name", voterList.getName(), "voterList name can not be empty");
+ check(errors, "weight", voterList.getWeight() > 0, "voterList weight must be greater than 0");
+ checkNotEmpty(errors, "member", voterList.getVoterListMember(), "voterList must contains at least one member");
+
+ boolean added = voterListNames.add(voterList.getName());
+
+ check(errors, "name", added, "voterList name already used");
+
+ Set<String> voterListMemberNames = Sets.newHashSet();
+ Set<String> voterListMemberEmails = Sets.newHashSet();
+
+ int voterListMemberIndex = 0;
+
+ for (VoterListMember voterListMember : voterList.getVoterListMember()) {
+
+ String voterListMemberField = "member[" + (voterListMemberIndex++) + "].";
+
+ String voterListMemberName = voterListMember.getName();
+ boolean nameNotNull = checkNotBlank(errors, voterListMemberField + "name", voterListMemberName, "member name can not be empty");
+
+ if (nameNotNull) {
+ boolean nameAdded = voterListMemberNames.add(voterListMemberName);
+ check(errors, voterListMemberField + "name", nameAdded, "member name already used in this list");
+ }
+
+ String voterListMemberEmail = voterListMember.getEmail();
+
+ boolean emailNotNull = checkNotBlank(errors, voterListMemberField + "email", voterListMemberEmail, "member email can not be empty");
+
+ if (emailNotNull) {
+
+ voterListMemberEmail = StringUtils.lowerCase(voterListMemberEmail);
+
+ checkValidEmail(errors, voterListMemberField + "email", voterListMemberEmail, "member email is not valid");
+ boolean emailAdded = voterListMemberEmails.add(voterListMemberEmail);
+ check(errors, voterListMemberField + "email", emailAdded, "member email already used in this list");
+ }
+ }
+
+ if (!errors.isEmpty()) {
+
+ throw new InvalidVoterListFormException(errors);
+ }
+ }
+
+ protected void checkVoterListMember(VoterList voterList, VoterListMember voterListMember) throws InvalidVoterListMemberFormException {
+
+ //TODO use nuiton validator ?
+ Multimap<String, String> errors = ArrayListMultimap.create();
+
+ boolean voterListMemberExists = JpaEntities.isEntityHasId(voterListMember);
+
+ Set<String> voterListMemberNames = Sets.newHashSet();
+ Set<String> voterListMemberEmails = Sets.newHashSet();
+ if (!voterList.isVoterListMemberEmpty()) {
+
+ // get all used names
+
+ for (VoterListMember member : voterList.getVoterListMember()) {
+
+ if (voterListMemberExists && member.getId().equals(voterListMember.getId())) {
+ continue;
+ }
+
+ voterListMemberNames.add(voterListMember.getName());
+ voterListMemberEmails.add(voterListMember.getEmail());
+ }
+ }
+ String voterListMemberName = voterListMember.getName();
+ boolean nameNotNull = checkNotBlank(errors, "name", voterListMemberName, "member name can not be empty");
+
+ if (nameNotNull) {
+ boolean nameAdded = voterListMemberNames.add(voterListMemberName);
+ check(errors, "name", nameAdded, "member name already used in this list");
+ }
+
+ String voterListMemberEmail = voterListMember.getEmail();
+
+ boolean emailNotNull = checkNotBlank(errors, "email", voterListMemberEmail, "member email can not be empty");
+
+ if (emailNotNull) {
+
+ 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");
+ }
+
+ if (!errors.isEmpty()) {
+
+ throw new InvalidVoterListMemberFormException(errors);
+ }
+ }
}
Modified: trunk/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java
===================================================================
--- trunk/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java 2013-06-15 10:58:03 UTC (rev 3830)
+++ trunk/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java 2013-06-15 14:29:32 UTC (rev 3831)
@@ -23,11 +23,14 @@
* #L%
*/
+import com.google.common.collect.Multimap;
import org.chorem.pollen.persistence.JpaPollenPersistenceContext;
import org.chorem.pollen.services.PollenFixtures;
+import org.chorem.pollen.services.PollenServiceSupport;
import org.chorem.pollen.services.config.PollenServiceConfig;
+import org.chorem.pollen.services.exception.AbstractInvalidFormException;
import org.chorem.pollen.services.service.FixturesService;
-import org.chorem.pollen.services.PollenServiceSupport;
+import org.junit.Assert;
import org.junit.Rule;
import org.nuiton.jpa.junit.JpaEntityManagerRule;
@@ -114,4 +117,14 @@
}
+ protected void assertErrorKeyFound(AbstractInvalidFormException e, String... keys) {
+ Multimap<String, String> errors = e.getErrors();
+
+ Assert.assertEquals("Expected " + keys.length + " errors, but had " + errors.keySet(), keys.length, errors.keySet().size());
+ for (String key : keys) {
+
+ Assert.assertTrue("Expected error:" + key + ", but not found among:" + errors.keySet(), errors.containsKey(key));
+ }
+ }
+
}
Added: trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollServiceTest.java
===================================================================
--- trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollServiceTest.java (rev 0)
+++ trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollServiceTest.java 2013-06-15 14:29:32 UTC (rev 3831)
@@ -0,0 +1,322 @@
+package org.chorem.pollen.service;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.chorem.pollen.persistence.entity.Choice;
+import org.chorem.pollen.persistence.entity.ChoiceType;
+import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.persistence.entity.PollType;
+import org.chorem.pollen.persistence.entity.VoterList;
+import org.chorem.pollen.persistence.entity.VoterListMember;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.chorem.pollen.services.exception.InvalidPollFormException;
+import org.chorem.pollen.services.service.PollService;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.text.ParseException;
+import java.util.Date;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollServiceTest extends AbstractPollenServiceTest {
+
+ protected PollService service;
+
+ @Before
+ public void setUp() throws ParseException {
+
+ loadFixtures("fixtures");
+
+ service = serviceContext.getPollService();
+
+ serviceContext.setDate(new Date(1363948427576l));
+ }
+
+ @Test
+ public void testCreateFreePoll() throws EntityNotFoundException, InvalidPollFormException {
+
+ Poll poll = service.getNewPoll(null, ChoiceType.TEXT);
+
+ poll.setPollType(PollType.FREE);
+
+ try {
+ service.createPoll(null, poll);
+ } catch (InvalidPollFormException e) {
+ // missing title
+ // missing choice
+ assertErrorKeyFound(e, "title", "choice");
+ }
+
+ poll.setTitle("poll1");
+
+ Choice choice1 = new Choice();
+ poll.addChoice(choice1);
+
+ try {
+ service.createPoll(null, poll);
+ } catch (InvalidPollFormException e) {
+ // missing choice name
+ assertErrorKeyFound(e, "choice[0].name");
+ }
+
+ choice1.setName("A");
+ choice1.setDescription("Choice A");
+
+
+ Choice choice2 = new Choice();
+ choice2.setName("A");
+ choice2.setDescription("Choice B");
+ poll.addChoice(choice2);
+
+ try {
+ service.createPoll(null, poll);
+ } catch (InvalidPollFormException e) {
+ // duplicated choice name
+ assertErrorKeyFound(e, "choice[1].name");
+ }
+
+ choice2.setName("B");
+
+
+ Poll createdPoll = service.createPoll(null, poll);
+ Assert.assertNotNull(createdPoll);
+ Assert.assertNotNull(createdPoll.getId());
+
+ Poll reloadedPoll = service.getPoll(createdPoll.getId());
+ Assert.assertEquals(createdPoll, reloadedPoll);
+
+ Assert.assertEquals(serviceContext.getNow(), createdPoll.getBeginDate());
+
+ Assert.assertNotNull(createdPoll.getCreator());
+ Assert.assertNotNull(createdPoll.getCreator().getId());
+ Assert.assertNotNull(createdPoll.getCreator().getToken());
+ Assert.assertNull(createdPoll.getCreator().getName());
+ Assert.assertNull(createdPoll.getCreator().getEmail());
+ Assert.assertNull(createdPoll.getComment());
+ Assert.assertNull(createdPoll.getVote());
+ Assert.assertNull(createdPoll.getVoterList());
+
+ Assert.assertNotNull(createdPoll.getChoice());
+ Assert.assertEquals(2, createdPoll.sizeChoice());
+
+
+ Choice createdChoice1 = createdPoll.getChoice(0);
+ Assert.assertNotNull(createdChoice1);
+ Assert.assertNotNull(createdChoice1.getId());
+
+ Choice reloadedChoice1 = serviceContext.getChoiceService().getChoice(createdPoll.getId(), createdChoice1.getId());
+ Assert.assertEquals(createdChoice1, reloadedChoice1);
+
+ Assert.assertEquals(choice1.getName(), createdChoice1.getName());
+ Assert.assertEquals(choice1.getDescription(), createdChoice1.getDescription());
+ Assert.assertEquals(createdPoll.getCreator(), createdChoice1.getCreator());
+
+ Choice createdChoice2 = createdPoll.getChoice(1);
+ Assert.assertNotNull(createdChoice2);
+ Assert.assertNotNull(createdChoice2.getId());
+
+ Choice reloadedChoice2 = serviceContext.getChoiceService().getChoice(createdPoll.getId(), createdChoice2.getId());
+ Assert.assertEquals(createdChoice2, reloadedChoice2);
+
+ Assert.assertEquals(choice2.getName(), createdChoice2.getName());
+ Assert.assertEquals(choice2.getDescription(), createdChoice2.getDescription());
+ Assert.assertEquals(createdPoll.getCreator(), createdChoice2.getCreator());
+
+ }
+
+ @Test
+ public void testCreateRestrictedPoll() throws EntityNotFoundException, InvalidPollFormException {
+
+ Poll poll = service.getNewPoll(null, ChoiceType.TEXT);
+ poll.setPollType(PollType.RESTRICTED);
+
+ poll.setTitle("poll1");
+
+ Choice choice1 = new Choice();
+ choice1.setName("A");
+ choice1.setDescription("Choice A");
+
+ poll.addChoice(choice1);
+
+ Choice choice2 = new Choice();
+ choice2.setName("B");
+ choice2.setDescription("Choice B");
+
+ poll.addChoice(choice2);
+
+ try {
+ service.createPoll(null, poll);
+ } catch (InvalidPollFormException e) {
+ // missing voterList
+ assertErrorKeyFound(e, "voterList");
+ }
+
+ // add voter list
+ VoterList voterList = new VoterList();
+
+ poll.addVoterList(voterList);
+
+ try {
+ service.createPoll(null, poll);
+ } catch (InvalidPollFormException e) {
+ // missing name
+ // missing weight
+ // missing voterListMember
+ assertErrorKeyFound(e, "voterList[0].name", "voterList[0].weight", "voterList[0].member");
+ }
+
+ voterList.setName("voterList1");
+ voterList.setWeight(1);
+
+ VoterListMember voterListMember1 = new VoterListMember();
+ voterList.addVoterListMember(voterListMember1);
+
+ try {
+ service.createPoll(null, poll);
+ } catch (InvalidPollFormException e) {
+ // missing member name
+ // missing member email
+ assertErrorKeyFound(e, "voterList[0].member[0].name", "voterList[0].member[0].email", "voterList[0].member[0].weight");
+ }
+
+ voterListMember1.setName("voter1");
+ voterListMember1.setWeight(0.3);
+ voterListMember1.setEmail("voter1_pollen.org");
+
+ try {
+ service.createPoll(null, poll);
+ } catch (InvalidPollFormException e) {
+ // invalid member email
+ assertErrorKeyFound(e, "voterList[0].member[0].email");
+ }
+
+ voterListMember1.setEmail("voter1(a)pollen.org");
+
+ VoterListMember voterListMember2 = new VoterListMember();
+ voterListMember2.setName("voter1");
+ voterListMember2.setWeight(0.7);
+ voterListMember2.setEmail("voter1(a)pollen.org");
+ voterList.addVoterListMember(voterListMember2);
+
+ try {
+ service.createPoll(null, poll);
+ } catch (InvalidPollFormException e) {
+ // same name
+ // same email
+ assertErrorKeyFound(e, "voterList[0].member[1].name", "voterList[0].member[1].email");
+ }
+
+ voterListMember2.setName("voter2");
+ voterListMember2.setEmail("voter2(a)pollen.org");
+
+
+ Poll createdPoll = service.createPoll(null, poll);
+ Assert.assertNotNull(createdPoll);
+ Assert.assertNotNull(createdPoll.getId());
+
+ Poll reloadedPoll = service.getPoll(createdPoll.getId());
+ Assert.assertEquals(createdPoll, reloadedPoll);
+
+ Assert.assertEquals(serviceContext.getNow(), createdPoll.getBeginDate());
+
+ Assert.assertNotNull(createdPoll.getCreator());
+ Assert.assertNotNull(createdPoll.getCreator().getId());
+ Assert.assertNotNull(createdPoll.getCreator().getToken());
+ Assert.assertNull(createdPoll.getCreator().getName());
+ Assert.assertNull(createdPoll.getCreator().getEmail());
+ Assert.assertNull(createdPoll.getComment());
+ Assert.assertNull(createdPoll.getVote());
+
+ Assert.assertNotNull(createdPoll.getChoice());
+ Assert.assertEquals(2, createdPoll.sizeChoice());
+
+ Choice createdChoice1 = createdPoll.getChoice(0);
+ Assert.assertNotNull(createdChoice1);
+ Assert.assertNotNull(createdChoice1.getId());
+
+ Choice reloadedChoice1 = serviceContext.getChoiceService().getChoice(createdPoll.getId(), createdChoice1.getId());
+ Assert.assertEquals(createdChoice1, reloadedChoice1);
+
+ Assert.assertEquals(choice1.getName(), createdChoice1.getName());
+ Assert.assertEquals(choice1.getDescription(), createdChoice1.getDescription());
+ Assert.assertEquals(createdPoll.getCreator(), createdChoice1.getCreator());
+
+ Choice createdChoice2 = createdPoll.getChoice(1);
+ Assert.assertNotNull(createdChoice2);
+ Assert.assertNotNull(createdChoice2.getId());
+
+ Choice reloadedChoice2 = serviceContext.getChoiceService().getChoice(createdPoll.getId(), createdChoice2.getId());
+ Assert.assertEquals(createdChoice2, reloadedChoice2);
+
+ Assert.assertEquals(choice2.getName(), createdChoice2.getName());
+ Assert.assertEquals(choice2.getDescription(), createdChoice2.getDescription());
+ Assert.assertEquals(createdPoll.getCreator(), createdChoice2.getCreator());
+
+ Assert.assertNotNull(createdPoll.getVoterList());
+ Assert.assertEquals(1, createdPoll.sizeVoterList());
+ VoterList createdVoterList = createdPoll.getVoterList(0);
+ Assert.assertNotNull(createdVoterList);
+ Assert.assertNotNull(createdVoterList.getId());
+
+ VoterList reloadedVoterList = serviceContext.getVoterListService().getVoterList(createdPoll.getId(), createdVoterList.getId());
+ Assert.assertEquals(createdVoterList, reloadedVoterList);
+
+ Assert.assertEquals(voterList.getName(), createdVoterList.getName());
+ Assert.assertEquals(voterList.getWeight(), createdVoterList.getWeight(), 0);
+
+ Assert.assertNotNull(createdVoterList.getVoterListMember());
+ Assert.assertEquals(2, createdVoterList.sizeVoterListMember());
+
+ VoterListMember createdVoterListMember1 = createdVoterList.getVoterListMember(0);
+
+ Assert.assertNotNull(createdVoterListMember1);
+ Assert.assertNotNull(createdVoterListMember1.getId());
+ VoterListMember reloadedVoterListMember1 = serviceContext.getVoterListService().getVoterListMember(createdPoll.getId(), createdVoterList.getId(), createdVoterListMember1.getId());
+ Assert.assertEquals(createdVoterListMember1, reloadedVoterListMember1);
+
+ Assert.assertEquals(voterListMember1.getName(), createdVoterListMember1.getName());
+ Assert.assertEquals(voterListMember1.getEmail(), createdVoterListMember1.getEmail());
+ Assert.assertEquals(voterListMember1.getWeight(), createdVoterListMember1.getWeight(), 0);
+
+ VoterListMember createdVoterListMember2 = createdVoterList.getVoterListMember(1);
+
+ Assert.assertNotNull(createdVoterListMember2);
+ Assert.assertNotNull(createdVoterListMember2.getId());
+
+ VoterListMember reloadedVoterListMember2 = serviceContext.getVoterListService().getVoterListMember(createdPoll.getId(), createdVoterList.getId(), createdVoterListMember2.getId());
+ Assert.assertEquals(createdVoterListMember2, reloadedVoterListMember2);
+
+ Assert.assertEquals(voterListMember2.getName(), createdVoterListMember2.getName());
+ Assert.assertEquals(voterListMember2.getEmail(), createdVoterListMember2.getEmail());
+ Assert.assertEquals(voterListMember2.getWeight(), createdVoterListMember2.getWeight(), 0);
+
+ }
+
+}
Property changes on: trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollServiceTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: trunk/pollen-ui-js/src/main/webapp/bundle/Messages.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: trunk/pollen-ui-js/src/main/webapp/js/libs/jquery.i18n.properties-min-1.0.9.js
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
Author: tchemit
Date: 2013-06-15 12:58:03 +0200 (Sat, 15 Jun 2013)
New Revision: 3830
Url: http://chorem.org/projects/pollen/repository/revisions/3830
Log:
- use version in REST api (v1)
- normalize rest api (need all the data path)
- implements poll create - edit service
- implements choice create - edit service
- implements voterList create - edit service
Added:
trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenApplicationContext.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenJpaTransactionFilter.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceContextFilter.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceListener.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServices.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthService.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceService.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentService.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ErrorAction.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListService.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/UserService.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingService.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteService.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityRealm.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/AbstractInvalidFormException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidChoiceFormException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidPollFormException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/package-info.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/package-info.java
Removed:
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenApplicationContext.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenJpaTransactionFilter.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenRender.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenSecurityFilter.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceContextFilter.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceListener.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServices.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/AuthService.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/CommentService.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/ErrorAction.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/FavoriteListService.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollService.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/UserService.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteCountingService.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteService.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoterListService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/service/
Modified:
trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java
trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenPersistenceContext.java
trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUser.java
trunk/pollen-persistence/src/main/xmi/pollen.properties
trunk/pollen-persistence/src/main/xmi/pollen.zargo
trunk/pollen-rest-api/src/it/pom/pom.xml
trunk/pollen-rest-api/src/it/user/README.txt
trunk/pollen-rest-api/src/main/resources/mapping
trunk/pollen-rest-api/src/main/webapp/WEB-INF/web.xml
trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java
trunk/pollen-rest-api/src/test/resources/pollen.properties
trunk/pollen-services/pom.xml
trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListImportException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidSessionTokenException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/package-info.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java
trunk/pollen-ui-js/src/main/webapp/img/glyphicons_050_link.png
trunk/pollen-ui-js/src/main/webapp/js/libs/date.js
trunk/pollen-ui-js/src/main/webapp/js/libs/jquery.scrollto.js
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,5 +1,28 @@
package org.chorem.pollen.persistence;
+/*
+ * #%L
+ * Pollen :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
import com.google.common.base.Preconditions;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
Property changes on: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenPersistenceContext.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenPersistenceContext.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenPersistenceContext.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -28,6 +28,7 @@
import org.chorem.pollen.persistence.dao.FavoriteListJpaDao;
import org.chorem.pollen.persistence.dao.FavoriteListMemberJpaDao;
import org.chorem.pollen.persistence.dao.PollJpaDao;
+import org.chorem.pollen.persistence.dao.PollenPrincipalJpaDao;
import org.chorem.pollen.persistence.dao.PollenUserJpaDao;
import org.chorem.pollen.persistence.dao.SessionTokenJpaDao;
import org.chorem.pollen.persistence.dao.VoteJpaDao;
@@ -63,6 +64,8 @@
PollJpaDao getPollDao();
+ PollenPrincipalJpaDao getPollenPrincipalDao();
+
PollenUserJpaDao getPollenUserDao();
SessionTokenJpaDao getSessionTokenDao();
Added: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java (rev 0)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,51 @@
+package org.chorem.pollen.persistence.entity;
+
+/*
+ * #%L
+ * Pollen :: Persistence
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import javax.persistence.Entity;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+@Entity
+public class Poll extends AbstractJpaPoll {
+
+ private static final long serialVersionUID = 1L;
+
+ public boolean isFreePoll() {
+ return PollType.FREE == pollType;
+ }
+
+ public boolean isRestrictedPoll() {
+ return PollType.RESTRICTED == pollType;
+ }
+
+ public boolean isGroupPoll() {
+ return PollType.GROUP == pollType;
+ }
+
+} //Poll
Property changes on: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUser.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUser.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenUser.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -25,6 +25,12 @@
import javax.persistence.Entity;
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
@Entity
public class PollenUser extends AbstractJpaPollenUser {
Modified: trunk/pollen-persistence/src/main/xmi/pollen.properties
===================================================================
--- trunk/pollen-persistence/src/main/xmi/pollen.properties 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-persistence/src/main/xmi/pollen.properties 2013-06-15 10:58:03 UTC (rev 3830)
@@ -21,7 +21,6 @@
# #L%
###m
model.tagValue.idFactory=true
-model.tagValue.generatePropertyChangeListeners=true
model.tagValue.generateVisitors=true
model.tagvalue.version=2.0
#model.tagvalue.entitySuperClass=org.chorem.pollen.persistence.entity.AbstractJpaPollenEntity
Modified: trunk/pollen-persistence/src/main/xmi/pollen.zargo
===================================================================
(Binary files differ)
Modified: trunk/pollen-rest-api/src/it/pom/pom.xml
===================================================================
--- trunk/pollen-rest-api/src/it/pom/pom.xml 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-rest-api/src/it/pom/pom.xml 2013-06-15 10:58:03 UTC (rev 3830)
@@ -3,7 +3,7 @@
#%L
Pollen :: UI (struts2)
$Id$
- $HeadURL: http://svn.chorem.org/svn/pollen/branches/pollen-2.0/pollen-ui-struts2/src/… $
+ $HeadURL$
%%
Copyright (C) 2009 - 2012 CodeLutin
%%
Property changes on: trunk/pollen-rest-api/src/it/pom/pom.xml
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: trunk/pollen-rest-api/src/it/user/README.txt
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenApplicationContext.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenApplicationContext.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenApplicationContext.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,125 +0,0 @@
-package org.chorem.pollen.rest;
-
-/*
- * #%L
- * Pollen :: Rest Api
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.persistence.JpaPollenPersistenceContext;
-import org.chorem.pollen.services.DefaultPollenServiceContext;
-import org.chorem.pollen.services.PollenServiceContext;
-import org.chorem.pollen.services.config.PollenServiceConfig;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-import javax.persistence.PersistenceException;
-import java.io.Closeable;
-import java.util.Map;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class PollenApplicationContext implements Closeable {
-
- private static final Log log = LogFactory.getLog(PollenApplicationContext.class);
-
- protected static final String APPLICATION_CONTEXT_PARAMETER = "pollen_PollenApplicationContext";
-
- protected PollenServiceConfig applicationConfig;
-
- protected EntityManagerFactory entityManagerFactory;
-
- public PollenServiceConfig getPollenServiceConfig() {
- if (applicationConfig == null) {
- applicationConfig = new PollenServiceConfig();
- }
- return applicationConfig;
- }
-
- public EntityManager newEntityManager() {
-
- if (entityManagerFactory == null) {
-
- PollenServiceConfig applicationConfig = getPollenServiceConfig();
-
- Map<String, String> jpaParameters = applicationConfig.getJpaParameters();
-
- if (log.isInfoEnabled()) {
- log.info("creating entity manager factory");
- }
-
- try {
-
- entityManagerFactory = Persistence.createEntityManagerFactory("pollenPersistenceUnit", jpaParameters);
-
- } catch (PersistenceException e) {
-
- if (log.isErrorEnabled()) {
- log.error("unable to create entity manager factory", e);
- }
-
- throw e;
-
- }
-
- }
-
- EntityManager entityManager = entityManagerFactory.createEntityManager();
-
- return entityManager;
-
- }
-
- public void close() {
-
- if (entityManagerFactory != null && entityManagerFactory.isOpen()) {
-
- if (log.isInfoEnabled()) {
- log.info("stopping magalie, will close entity manager factory");
- }
-
- entityManagerFactory.close();
-
- }
-
- }
-
- public PollenServiceContext newServiceContext(EntityManager entityManager) {
-
- DefaultPollenServiceContext serviceContext = new DefaultPollenServiceContext();
-
- JpaPollenPersistenceContext jpaMagaliePersistenceContext =
- new JpaPollenPersistenceContext(entityManager);
-
- serviceContext.setPersistenceContext(jpaMagaliePersistenceContext);
-
- serviceContext.setPollenServiceConfig(applicationConfig);
-
- return serviceContext;
-
- }
-}
Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenJpaTransactionFilter.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenJpaTransactionFilter.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenJpaTransactionFilter.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,87 +0,0 @@
-package org.chorem.pollen.rest;
-
-/*
- * #%L
- * Pollen :: Rest Api
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import com.google.common.base.Preconditions;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.web.filter.JpaTransactionFilter;
-
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceException;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-
-public class PollenJpaTransactionFilter extends JpaTransactionFilter {
-
- private static final Log log =
- LogFactory.getLog(PollenJpaTransactionFilter.class);
-
- protected PollenApplicationContext applicationContext;
-
- @Override
- public void init(FilterConfig filterConfig) throws ServletException {
-
- super.init(filterConfig);
-
- if (log.isInfoEnabled()) {
- log.info("Init JPA Filter");
- }
-
-// applicationContext = PollenServices.getApplicationContext(
-// filterConfig.getServletContext());
-//
-// Preconditions.checkNotNull(applicationContext, "Could not find application context at ServletContext#pollen_PollenApplicationContext");
- }
-
- protected PollenApplicationContext getApplicationContext(ServletRequest request) {
- if (applicationContext == null) {
- applicationContext = PollenServices.getApplicationContext(
- request.getServletContext());
-
- Preconditions.checkNotNull(applicationContext, "Could not find application context at ServletContext#pollen_PollenApplicationContext");
- }
- return applicationContext;
- }
-
- @Override
- protected EntityManager createEntityManager(ServletRequest request) {
-
- EntityManager entityManager;
-
- try {
-
- entityManager = getApplicationContext(request).newEntityManager();
-
- } catch (PersistenceException e) {
-
- if (log.isErrorEnabled()) {
- log.error("unable to create entity manager", e);
- }
- throw e;
- }
- return entityManager;
- }
-}
Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenRender.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenRender.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenRender.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,234 +0,0 @@
-package org.chorem.pollen.rest;
-
-/*
- * #%L
- * Pollen :: Rest Api
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.gson.Gson;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.debux.webmotion.server.call.Call;
-import org.debux.webmotion.server.call.HttpContext;
-import org.debux.webmotion.server.mapping.Mapping;
-import org.debux.webmotion.server.render.Render;
-import org.nuiton.jpa.api.JpaEntity;
-import org.nuiton.util.ObjectUtil;
-import org.nuiton.util.beans.Binder;
-import org.nuiton.util.beans.BinderFactory;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-/**
- * To render any entities.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class PollenRender<T> extends Render {
-
- /**
- * To specify entity collections to include in binded entities.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
- @Retention(RetentionPolicy.RUNTIME)
- @Target(ElementType.METHOD)
- public @interface ExposeCollection {
-
- public String[] values() default {};
- }
-
- protected T model;
-
- public PollenRender(T model) {
- this.model = model;
- }
-
- @Override
- public void create(Mapping mapping, Call call) throws IOException, ServletException {
-
- HttpContext context = call.getContext();
- HttpServletResponse response = context.getResponse();
- response.setContentType("application/json");
-
- String[] includeCollection = null;
- ExposeCollection annotation = call.getCurrent().getMethod().getAnnotation(ExposeCollection.class);
- if (annotation != null) {
- includeCollection = annotation.values();
- }
- Object map = toMap(model, includeCollection);
-
- Gson gson = new Gson();
- String json = gson.toJson(map);
- PrintWriter out = context.getOut();
- out.print(json);
- }
-
- protected <M> Object toMap(M model, String... includeCollection) {
- if (model instanceof Iterable<?>) {
-
- // collection of objects
- Iterable<?> objects = (Iterable<?>) model;
- List<Object> result = Lists.newArrayList();
- for (Object object : objects) {
- Object objectMap = toMap(object, includeCollection);
- result.add(objectMap);
- }
- return result;
- }
-
- // single object
-
- if (model instanceof JpaEntity) {
-
- // entity need to transform it
-
- JpaEntity jpaEntity = (JpaEntity) model;
-
- PollenEntityBinder<JpaEntity> binder = BinderFactory.newBinder(jpaEntity.getClass(), jpaEntity.getClass(), null, PollenEntityBinder.class);
- Map<String, Object> map = binder.obtainProperties(jpaEntity);
- Map<String, Object> result = Maps.newTreeMap();
-
- for (Map.Entry<String, Object> entry : map.entrySet()) {
- String propertyName = entry.getKey();
- Object propertyValue = entry.getValue();
- if (propertyValue instanceof JpaEntity) {
- result.put(propertyName, toMap(propertyValue));
- continue;
- }
-
- result.put(propertyName, propertyValue);
- }
-
- // treat collections
-
- if (includeCollection != null) {
- for (String propertyName : includeCollection) {
- Iterable<?> collectionValue = binder.getCollectionValue(jpaEntity, propertyName);
- result.put(propertyName, toMap(collectionValue));
-
- }
- }
- return result;
- }
-
- return model;
- }
-
- protected static class PollenEntityBinder<E extends JpaEntity> extends Binder<E, E> {
-
- /** Logger. */
- private static final Log log =
- LogFactory.getLog(PollenEntityBinder.class);
-
- private static final long serialVersionUID = 1L;
-
- protected List<String> simpleProperties;
-
- public PollenEntityBinder() {
- }
-
- @Override
- protected void setModel(BinderModel<E, E> model) {
- super.setModel(model);
- this.simpleProperties = Lists.newArrayList();
- for (String property : model.getSourceDescriptors()) {
- if (model.getCollectionType(property) == null) {
- simpleProperties.add(property);
- }
- }
- }
-
- /**
- * Obtain from the given object all properties registered in the binder
- * model.
- *
- * @param source the bean to read
- * @return the map of properties obtained indexed by their property name,
- * or an empty map is the given {@code from} is {@code null}.
- * @since 2.3
- */
- public Map<String, Object> obtainProperties(E source) {
- if (source == null) {
- // special limit case
- return Collections.emptyMap();
- }
-
- Map<String, Object> result = Maps.newTreeMap();
- for (String sourceProperty : simpleProperties) {
-
-
- try {
- Object read;
- Method readMethod = model.getSourceReadMethod(sourceProperty);
- read = readMethod.invoke(source);
- if (log.isDebugEnabled()) {
- log.debug("property " + sourceProperty + ", type : " +
- readMethod.getReturnType() + ", value = " + read);
- }
- if (readMethod.getReturnType().isPrimitive() &&
- ObjectUtil.getNullValue(
- readMethod.getReturnType()).equals(read)) {
- // for primitive type case, force nullity
- read = null;
- }
-
- if (read != null) {
- result.put(sourceProperty, read);
- }
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e);
- }
- }
- return result;
- }
-
- public Iterable<?> getCollectionValue(E source, String sourceProperty) {
- try {
- Method readMethod = model.getSourceReadMethod(sourceProperty);
- Object result = readMethod.invoke(source);
- return (Iterable<?>) result;
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e);
- }
- }
- }
-}
Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenSecurityFilter.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenSecurityFilter.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenSecurityFilter.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,47 +0,0 @@
-package org.chorem.pollen.rest;
-
-import org.apache.commons.lang3.StringUtils;
-import org.chorem.pollen.persistence.entity.SessionToken;
-import org.chorem.pollen.services.PollenServiceContext;
-import org.chorem.pollen.services.exception.InvalidSessionTokenException;
-import org.debux.webmotion.server.WebMotionFilter;
-import org.debux.webmotion.server.call.HttpContext;
-
-import javax.servlet.http.HttpServletRequest;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class PollenSecurityFilter extends WebMotionFilter {
-
- public static final String REQUEST_AUTH_PARAMETER = "auth";
-
- void injectConnectedUser(HttpContext context) throws InvalidSessionTokenException {
-
- String[] strings = context.getParameters().get(REQUEST_AUTH_PARAMETER);
-
- String authParam = strings == null || strings.length < 1 ? null : strings[1];
-
- if (StringUtils.isNotBlank(authParam)) {
-
- // find out the userId from this auth
-
- HttpServletRequest request = context.getRequest();
-
- PollenServiceContext serviceContext =
- PollenServices.getServiceContext(request);
-
- SessionToken sessionToken =
- serviceContext.getAuthService().getUserByAuth(authParam);
-
- if (sessionToken != null) {
-
- // reinject it in request
- PollenServices.setSessionToken(request, sessionToken);
- }
- }
- }
-}
Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceContextFilter.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceContextFilter.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceContextFilter.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,55 +0,0 @@
-package org.chorem.pollen.rest;
-
-/*
- * #%L
- * Pollen :: Rest Api
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.chorem.pollen.services.PollenServiceContext;
-import org.debux.webmotion.server.WebMotionFilter;
-import org.debux.webmotion.server.call.HttpContext;
-
-import javax.persistence.EntityManager;
-
-/**
- * Inject le service context dans les controlleurs.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class PollenServiceContextFilter extends WebMotionFilter {
-
- public void inject(HttpContext context) {
-
- PollenApplicationContext applicationContext =
- PollenServices.getApplicationContext(context.getServletContext());
-
- EntityManager entityManager =
- PollenServices.getEntityManager(context.getRequest());
-
- PollenServiceContext serviceContext =
- applicationContext.newServiceContext(entityManager);
-
- PollenServices.setServiceContext(context.getRequest(), serviceContext);
-
- doProcess();
- }
-}
Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceListener.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceListener.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceListener.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,124 +0,0 @@
-package org.chorem.pollen.rest;
-
-/*
- * #%L
- * Pollen :: Rest Api
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.services.PollenServiceContext;
-import org.chorem.pollen.services.exception.UserEmailAlreadyUsedException;
-import org.chorem.pollen.services.exception.UserLoginAlreadyUsedException;
-import org.debux.webmotion.server.WebMotionServerListener;
-import org.debux.webmotion.server.call.Call;
-import org.debux.webmotion.server.call.HttpContext;
-import org.debux.webmotion.server.call.ServerContext;
-import org.debux.webmotion.server.handler.ExecutorParametersInjectorHandler;
-import org.debux.webmotion.server.mapping.Mapping;
-
-import javax.persistence.EntityManager;
-import javax.servlet.http.HttpServletRequest;
-import java.lang.reflect.Type;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class PollenServiceListener implements WebMotionServerListener {
-
- /** Logger. */
- private static final Log log =
- LogFactory.getLog(PollenServiceListener.class);
-
- @Override
- public void onStart(Mapping mapping, ServerContext serverContext) {
-
- serverContext.addInjector(new PollenServiceContextInjector());
- serverContext.addInjector(new SessionTokenInjector());
-
- // Create application context
- PollenApplicationContext applicationContext =
- new PollenApplicationContext();
-
- // push it in context
- PollenServices.setApplicationContext(
- serverContext.getServletContext(), applicationContext);
-
- EntityManager entityManager = applicationContext.newEntityManager();
-
- try {
- PollenServiceContext serviceContext =
- applicationContext.newServiceContext(entityManager);
- serviceContext.getUserService().createDefaultUsers();
- } catch (UserEmailAlreadyUsedException e) {
- //Can't happen
- } catch (UserLoginAlreadyUsedException e) {
- //Can't happen
- } finally {
- entityManager.close();
- }
- }
-
- @Override
- public void onStop(ServerContext serverContext) {
-
- // Get application context
- PollenApplicationContext applicationContext =
- PollenServices.getApplicationContext(
- serverContext.getServletContext());
-
- // close it (and all underlined resources)
- if (applicationContext != null) {
- applicationContext.close();
- }
- }
-
- protected static class PollenServiceContextInjector implements ExecutorParametersInjectorHandler.Injector {
- @Override
- public Object getValue(Mapping mapping, Call call, String name, Class<?> type, Type generic) {
- PollenServiceContext result = null;
- if (PollenServiceContext.class.isAssignableFrom(type)) {
- HttpContext httpContext = call.getContext();
- HttpServletRequest request = httpContext.getRequest();
-
- result = PollenServices.getServiceContext(request);
- }
- return result;
- }
- }
-
- protected static class SessionTokenInjector implements ExecutorParametersInjectorHandler.Injector {
- @Override
- public Object getValue(Mapping mapping, Call call, String name, Class<?> type, Type generic) {
- PollenServiceContext result = null;
- if (PollenServiceContext.class.isAssignableFrom(type)) {
- HttpContext httpContext = call.getContext();
- HttpServletRequest request = httpContext.getRequest();
-
- result = PollenServices.getServiceContext(request);
- }
- return result;
- }
- }
-}
Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServices.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServices.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServices.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,89 +0,0 @@
-package org.chorem.pollen.rest;
-
-/*
- * #%L
- * Pollen :: Rest Api
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.chorem.pollen.persistence.entity.SessionToken;
-import org.chorem.pollen.services.PollenServiceContext;
-import org.nuiton.web.filter.JpaTransactionFilter;
-
-import javax.persistence.EntityManager;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class PollenServices {
-
- protected static final String APPLICATION_CONTEXT_PARAMETER = "pollen_PollenApplicationContext";
-
- protected static final String REQUEST_POLLEN_SERVICE_CONTEXT = "pollen_PollenServiceContext";
-
- protected static final String REQUEST_POLLEN_CONNECTED_USER = "pollen_PollenConnectedUser";
-
- protected static final String REQUEST_ENTITY_MANAGER = JpaTransactionFilter.JPA_TRANSACTION_REQUEST_ATTRIBUTE;
-
- public static PollenApplicationContext getApplicationContext(ServletContext servletContext) {
- PollenApplicationContext result = (PollenApplicationContext)
- servletContext.getAttribute(APPLICATION_CONTEXT_PARAMETER);
- return result;
- }
-
- public static void setApplicationContext(ServletContext servletContext,
- PollenApplicationContext applicationContext) {
- servletContext.setAttribute(APPLICATION_CONTEXT_PARAMETER, applicationContext);
- }
-
-
- public static PollenServiceContext getServiceContext(HttpServletRequest request) {
- PollenServiceContext result = (PollenServiceContext)
- request.getAttribute(REQUEST_POLLEN_SERVICE_CONTEXT);
- return result;
- }
-
- public static void setServiceContext(HttpServletRequest request,
- PollenServiceContext serviceContext) {
- request.setAttribute(REQUEST_POLLEN_SERVICE_CONTEXT, serviceContext);
- }
-
- public static EntityManager getEntityManager(HttpServletRequest request) {
- EntityManager result = (EntityManager)
- request.getAttribute(REQUEST_ENTITY_MANAGER);
- return result;
- }
-
- public static SessionToken getSessionToken(HttpServletRequest request) {
- SessionToken result = (SessionToken)
- request.getAttribute(REQUEST_POLLEN_CONNECTED_USER);
- return result;
- }
-
- public static void setSessionToken(HttpServletRequest request,
- SessionToken sessionToken) {
- request.setAttribute(REQUEST_POLLEN_CONNECTED_USER, sessionToken);
- }
-}
\ No newline at end of file
Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/AuthService.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/AuthService.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/AuthService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,50 +0,0 @@
-package org.chorem.pollen.rest.api;
-
-/*
- * #%L
- * Pollen :: Rest Api
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.chorem.pollen.services.PollenServiceContext;
-import org.chorem.pollen.services.exception.EntityNotFoundException;
-import org.chorem.pollen.services.exception.UserInvalidPasswordException;
-import org.debux.webmotion.server.WebMotionController;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class AuthService extends WebMotionController {
-
- public String login(PollenServiceContext context, String login, String password) throws UserInvalidPasswordException, EntityNotFoundException {
- return context.getAuthService().login(login, password);
- }
-
- public void lostPassword(PollenServiceContext context, String login) throws EntityNotFoundException {
- context.getAuthService().lostPassword(login);
- }
-
- public void logout(PollenServiceContext context, String login, String token) throws EntityNotFoundException {
- context.getAuthService().logout(login, token);
- }
-}
Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/CommentService.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/CommentService.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/CommentService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,61 +0,0 @@
-package org.chorem.pollen.rest.api;
-
-/*
- * #%L
- * Pollen :: Rest Api
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.chorem.pollen.persistence.entity.Comment;
-import org.chorem.pollen.services.PollenServiceContext;
-import org.chorem.pollen.services.exception.EntityNotFoundException;
-import org.debux.webmotion.server.WebMotionController;
-
-import java.util.List;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class CommentService extends WebMotionController {
-
- public List<Comment> getComments(PollenServiceContext context, String pollId) throws EntityNotFoundException {
- List<Comment> comments = context.getCommentService().getComments(pollId);
- return comments;
- }
-
- public Comment getComment(PollenServiceContext context, String commentId) throws EntityNotFoundException {
- return context.getCommentService().getComment(commentId);
- }
-
- public Comment addComment(PollenServiceContext context, String pollId, Comment comment) throws EntityNotFoundException {
- return context.getCommentService().addComment(pollId, comment);
- }
-
- public Comment editComment(PollenServiceContext context,Comment comment) throws EntityNotFoundException {
- return context.getCommentService().editComment(comment);
- }
-
- public void deleteComment(PollenServiceContext context, String pollId, String commentId) throws EntityNotFoundException {
- context.getCommentService().deleteComment(pollId, commentId);
- }
-}
Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/ErrorAction.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/ErrorAction.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/ErrorAction.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,44 +0,0 @@
-package org.chorem.pollen.rest.api;
-
-/*
- * #%L
- * Pollen :: Rest Api
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.debux.webmotion.server.WebMotionController;
-import org.debux.webmotion.server.render.Render;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class ErrorAction extends WebMotionController {
-
- public Render on404(Exception e) {
- return renderError(404, e.getMessage());
- }
-
- public Render on500(Exception e) {
- return renderError(500, e.getMessage());
- }
-}
Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/FavoriteListService.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/FavoriteListService.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/FavoriteListService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,99 +0,0 @@
-package org.chorem.pollen.rest.api;
-
-/*
- * #%L
- * Pollen :: Rest Api
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.chorem.pollen.persistence.entity.FavoriteList;
-import org.chorem.pollen.persistence.entity.FavoriteListMember;
-import org.chorem.pollen.services.PollenServiceContext;
-import org.chorem.pollen.services.exception.EntityNotFoundException;
-import org.chorem.pollen.services.exception.FavoriteListImportException;
-import org.chorem.pollen.services.exception.FavoriteListMemberEmailAlreadyUsedException;
-import org.chorem.pollen.services.exception.FavoriteListMemberNameAlreadyUsedException;
-import org.chorem.pollen.services.exception.FavoriteListMemberNotOwnedByFavoriteListException;
-import org.chorem.pollen.services.exception.FavoriteListNameAlreadyUsedException;
-import org.chorem.pollen.services.exception.FavoriteListNotOwnedByUserException;
-import org.debux.webmotion.server.WebMotionController;
-
-import java.io.File;
-import java.util.List;
-
-/**
- * TODO
- * TODO All method needs a userId connected
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class FavoriteListService extends WebMotionController {
-
- public List<FavoriteList> getFavoriteLists(PollenServiceContext context, String userId) throws EntityNotFoundException {
- List<FavoriteList> favoriteLists = context.getFavoriteListService().getFavoriteLists(userId);
- return favoriteLists;
- }
-
- public FavoriteList getFavoriteList(PollenServiceContext context, String favoriteListId) throws EntityNotFoundException {
- return context.getFavoriteListService().getFavoriteList(favoriteListId);
- }
-
- public FavoriteList createFavoriteList(PollenServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, FavoriteListNameAlreadyUsedException {
- return context.getFavoriteListService().createFavoriteList(userId, favoriteList);
- }
-
- public FavoriteList editFavoriteList(PollenServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, FavoriteListNameAlreadyUsedException, FavoriteListNotOwnedByUserException {
- return context.getFavoriteListService().editFavoriteList(userId, favoriteList);
- }
-
- public void deleteFavoriteList(PollenServiceContext context, String userId, String favoriteListId) throws EntityNotFoundException, FavoriteListNotOwnedByUserException {
- context.getFavoriteListService().deleteFavoriteList(userId, favoriteListId);
- }
-
- public int importFavoriteListMembersFromCsv(PollenServiceContext context, String userId, String favoriteListId, File csvFile) throws EntityNotFoundException, FavoriteListImportException, FavoriteListNotOwnedByUserException {
- return context.getFavoriteListService().importFavoriteListMembersFromCsv(userId, favoriteListId, csvFile);
- }
-
- public int importFavoriteListMembersFromLdap(PollenServiceContext context, String userId, String favoriteListId, String ldap) throws EntityNotFoundException, FavoriteListImportException, FavoriteListNotOwnedByUserException {
- return context.getFavoriteListService().importFavoriteListMembersFromLdap(userId, favoriteListId, ldap);
- }
-
- public List<FavoriteListMember> getMembers(PollenServiceContext context, String favoriteListId) throws EntityNotFoundException {
- List<FavoriteListMember> members = context.getFavoriteListService().getFavoriteListMembers(favoriteListId);
- return members;
- }
-
- public FavoriteListMember getMember(PollenServiceContext context, String memberId) throws EntityNotFoundException {
- return context.getFavoriteListService().getFavoriteListMember(memberId);
- }
-
- public FavoriteListMember addMember(PollenServiceContext context, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberEmailAlreadyUsedException, FavoriteListMemberNameAlreadyUsedException {
- return context.getFavoriteListService().addFavoriteListMember(favoriteListId, member);
- }
-
- public FavoriteListMember editMember(PollenServiceContext context, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberEmailAlreadyUsedException, FavoriteListMemberNameAlreadyUsedException, FavoriteListMemberNotOwnedByFavoriteListException {
- return context.getFavoriteListService().editFavoriteListMember(favoriteListId, member);
- }
-
- public void removeMember(PollenServiceContext context, String favoriteListId, String memberId) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException {
- context.getFavoriteListService().removeFavoriteListMember(favoriteListId, memberId);
- }
-}
Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollService.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollService.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,112 +0,0 @@
-package org.chorem.pollen.rest.api;
-
-/*
- * #%L
- * Pollen :: Rest Api
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.chorem.pollen.persistence.entity.Choice;
-import org.chorem.pollen.persistence.entity.Poll;
-import org.chorem.pollen.services.PollenServiceContext;
-import org.chorem.pollen.services.exception.EntityNotFoundException;
-import org.debux.webmotion.server.WebMotionController;
-
-import java.io.File;
-import java.util.List;
-import java.util.Set;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class PollService extends WebMotionController {
-
- public Set<Poll> getPolls(PollenServiceContext context, String userId) throws EntityNotFoundException {
- Set<Poll> polls = context.getPollService().getPolls(userId);
- return polls;
- }
-
- public Set<Poll> getCreatedPolls(PollenServiceContext context, String userId) throws EntityNotFoundException {
- Set<Poll> polls = context.getPollService().getCreatedPolls(userId);
- return polls;
- }
-
- public Set<Poll> getInvitedPolls(PollenServiceContext context, String userId) throws EntityNotFoundException {
- Set<Poll> polls = context.getPollService().getInvitedPolls(userId);
- return polls;
- }
-
- public Set<Poll> getParticipatedPolls(PollenServiceContext context, String userId) throws EntityNotFoundException {
- Set<Poll> polls = context.getPollService().getParticipatedPolls(userId);
- return polls;
- }
-
- public Poll getPoll(PollenServiceContext context, String pollId) throws EntityNotFoundException {
- return context.getPollService().getPoll(pollId);
- }
-
- public Poll createPoll(PollenServiceContext context, String userId, Poll poll) throws EntityNotFoundException {
- return context.getPollService().createPoll(userId, poll);
- }
-
- public Poll editPoll(PollenServiceContext context, Poll poll) throws EntityNotFoundException {
- return context.getPollService().editPoll(poll);
- }
-
- public void deletePoll(PollenServiceContext context, String pollId) throws EntityNotFoundException {
- context.getPollService().deletePoll(pollId);
- }
-
- public Poll clonePoll(PollenServiceContext context, String pollId) throws EntityNotFoundException {
- return context.getPollService().clonePoll(pollId);
- }
-
- public File closePoll(PollenServiceContext context, String pollId) throws EntityNotFoundException {
- return context.getPollService().closePoll(pollId);
- }
-
- public File exportPoll(PollenServiceContext context, String pollId) throws EntityNotFoundException {
- return context.getPollService().exportPoll(pollId);
- }
-
- public List<Choice> getChoices(PollenServiceContext context, String pollId) throws EntityNotFoundException {
- List<Choice> choices = context.getPollService().getChoices(pollId);
- return choices;
- }
-
- public Choice getChoice(PollenServiceContext context, String choiceId) throws EntityNotFoundException {
- return context.getPollService().getChoice(choiceId);
- }
-
- public Choice addChoice(PollenServiceContext context, String pollId, Choice choice) throws EntityNotFoundException {
- return context.getPollService().addChoice(pollId, choice);
- }
-
- public Choice editChoice(PollenServiceContext context, Choice choice) throws EntityNotFoundException {
- return context.getPollService().editChoice(choice);
- }
-
- public void deleteChoice(PollenServiceContext context, String pollId, String choiceId) throws EntityNotFoundException {
- context.getPollService().deleteChoice(pollId, choiceId);
- }
-}
Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenApplicationContext.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenApplicationContext.java)
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenApplicationContext.java (rev 0)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenApplicationContext.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,125 @@
+package org.chorem.pollen.rest.api;
+
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.persistence.JpaPollenPersistenceContext;
+import org.chorem.pollen.services.DefaultPollenServiceContext;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.config.PollenServiceConfig;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import javax.persistence.PersistenceException;
+import java.io.Closeable;
+import java.util.Map;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollenApplicationContext implements Closeable {
+
+ private static final Log log = LogFactory.getLog(PollenApplicationContext.class);
+
+ protected static final String APPLICATION_CONTEXT_PARAMETER = "pollen_PollenApplicationContext";
+
+ protected PollenServiceConfig applicationConfig;
+
+ protected EntityManagerFactory entityManagerFactory;
+
+ public PollenServiceConfig getPollenServiceConfig() {
+ if (applicationConfig == null) {
+ applicationConfig = new PollenServiceConfig();
+ }
+ return applicationConfig;
+ }
+
+ public EntityManager newEntityManager() {
+
+ if (entityManagerFactory == null) {
+
+ PollenServiceConfig applicationConfig = getPollenServiceConfig();
+
+ Map<String, String> jpaParameters = applicationConfig.getJpaParameters();
+
+ if (log.isInfoEnabled()) {
+ log.info("creating entity manager factory");
+ }
+
+ try {
+
+ entityManagerFactory = Persistence.createEntityManagerFactory("pollenPersistenceUnit", jpaParameters);
+
+ } catch (PersistenceException e) {
+
+ if (log.isErrorEnabled()) {
+ log.error("unable to create entity manager factory", e);
+ }
+
+ throw e;
+
+ }
+
+ }
+
+ EntityManager entityManager = entityManagerFactory.createEntityManager();
+
+ return entityManager;
+
+ }
+
+ public void close() {
+
+ if (entityManagerFactory != null && entityManagerFactory.isOpen()) {
+
+ if (log.isInfoEnabled()) {
+ log.info("stopping magalie, will close entity manager factory");
+ }
+
+ entityManagerFactory.close();
+
+ }
+
+ }
+
+ public PollenServiceContext newServiceContext(EntityManager entityManager) {
+
+ DefaultPollenServiceContext serviceContext = new DefaultPollenServiceContext();
+
+ JpaPollenPersistenceContext jpaMagaliePersistenceContext =
+ new JpaPollenPersistenceContext(entityManager);
+
+ serviceContext.setPersistenceContext(jpaMagaliePersistenceContext);
+
+ serviceContext.setPollenServiceConfig(applicationConfig);
+
+ return serviceContext;
+
+ }
+}
Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenJpaTransactionFilter.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenJpaTransactionFilter.java)
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenJpaTransactionFilter.java (rev 0)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenJpaTransactionFilter.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,87 @@
+package org.chorem.pollen.rest.api;
+
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.web.filter.JpaTransactionFilter;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceException;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+
+public class PollenJpaTransactionFilter extends JpaTransactionFilter {
+
+ private static final Log log =
+ LogFactory.getLog(PollenJpaTransactionFilter.class);
+
+ protected PollenApplicationContext applicationContext;
+
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+
+ super.init(filterConfig);
+
+ if (log.isInfoEnabled()) {
+ log.info("Init JPA Filter");
+ }
+
+// applicationContext = PollenServices.getApplicationContext(
+// filterConfig.getServletContext());
+//
+// Preconditions.checkNotNull(applicationContext, "Could not find application context at ServletContext#pollen_PollenApplicationContext");
+ }
+
+ protected PollenApplicationContext getApplicationContext(ServletRequest request) {
+ if (applicationContext == null) {
+ applicationContext = PollenServices.getApplicationContext(
+ request.getServletContext());
+
+ Preconditions.checkNotNull(applicationContext, "Could not find application context at ServletContext#pollen_PollenApplicationContext");
+ }
+ return applicationContext;
+ }
+
+ @Override
+ protected EntityManager createEntityManager(ServletRequest request) {
+
+ EntityManager entityManager;
+
+ try {
+
+ entityManager = getApplicationContext(request).newEntityManager();
+
+ } catch (PersistenceException e) {
+
+ if (log.isErrorEnabled()) {
+ log.error("unable to create entity manager", e);
+ }
+ throw e;
+ }
+ return entityManager;
+ }
+}
Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenRender.java)
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java (rev 0)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,234 @@
+package org.chorem.pollen.rest.api;
+
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.gson.Gson;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.debux.webmotion.server.call.Call;
+import org.debux.webmotion.server.call.HttpContext;
+import org.debux.webmotion.server.mapping.Mapping;
+import org.debux.webmotion.server.render.Render;
+import org.nuiton.jpa.api.JpaEntity;
+import org.nuiton.util.ObjectUtil;
+import org.nuiton.util.beans.Binder;
+import org.nuiton.util.beans.BinderFactory;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * To render any entities.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollenRender<T> extends Render {
+
+ /**
+ * To specify entity collections to include in binded entities.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target(ElementType.METHOD)
+ public @interface ExposeCollection {
+
+ public String[] values() default {};
+ }
+
+ protected T model;
+
+ public PollenRender(T model) {
+ this.model = model;
+ }
+
+ @Override
+ public void create(Mapping mapping, Call call) throws IOException, ServletException {
+
+ HttpContext context = call.getContext();
+ HttpServletResponse response = context.getResponse();
+ response.setContentType("application/json");
+
+ String[] includeCollection = null;
+ ExposeCollection annotation = call.getCurrent().getMethod().getAnnotation(ExposeCollection.class);
+ if (annotation != null) {
+ includeCollection = annotation.values();
+ }
+ Object map = toMap(model, includeCollection);
+
+ Gson gson = new Gson();
+ String json = gson.toJson(map);
+ PrintWriter out = context.getOut();
+ out.print(json);
+ }
+
+ protected <M> Object toMap(M model, String... includeCollection) {
+ if (model instanceof Iterable<?>) {
+
+ // collection of objects
+ Iterable<?> objects = (Iterable<?>) model;
+ List<Object> result = Lists.newArrayList();
+ for (Object object : objects) {
+ Object objectMap = toMap(object, includeCollection);
+ result.add(objectMap);
+ }
+ return result;
+ }
+
+ // single object
+
+ if (model instanceof JpaEntity) {
+
+ // entity need to transform it
+
+ JpaEntity jpaEntity = (JpaEntity) model;
+
+ PollenEntityBinder<JpaEntity> binder = BinderFactory.newBinder(jpaEntity.getClass(), jpaEntity.getClass(), null, PollenEntityBinder.class);
+ Map<String, Object> map = binder.obtainProperties(jpaEntity);
+ Map<String, Object> result = Maps.newTreeMap();
+
+ for (Map.Entry<String, Object> entry : map.entrySet()) {
+ String propertyName = entry.getKey();
+ Object propertyValue = entry.getValue();
+ if (propertyValue instanceof JpaEntity) {
+ result.put(propertyName, toMap(propertyValue));
+ continue;
+ }
+
+ result.put(propertyName, propertyValue);
+ }
+
+ // treat collections
+
+ if (includeCollection != null) {
+ for (String propertyName : includeCollection) {
+ Iterable<?> collectionValue = binder.getCollectionValue(jpaEntity, propertyName);
+ result.put(propertyName, toMap(collectionValue));
+
+ }
+ }
+ return result;
+ }
+
+ return model;
+ }
+
+ protected static class PollenEntityBinder<E extends JpaEntity> extends Binder<E, E> {
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(PollenEntityBinder.class);
+
+ private static final long serialVersionUID = 1L;
+
+ protected List<String> simpleProperties;
+
+ public PollenEntityBinder() {
+ }
+
+ @Override
+ protected void setModel(BinderModel<E, E> model) {
+ super.setModel(model);
+ this.simpleProperties = Lists.newArrayList();
+ for (String property : model.getSourceDescriptors()) {
+ if (model.getCollectionType(property) == null) {
+ simpleProperties.add(property);
+ }
+ }
+ }
+
+ /**
+ * Obtain from the given object all properties registered in the binder
+ * model.
+ *
+ * @param source the bean to read
+ * @return the map of properties obtained indexed by their property name,
+ * or an empty map is the given {@code from} is {@code null}.
+ * @since 2.3
+ */
+ public Map<String, Object> obtainProperties(E source) {
+ if (source == null) {
+ // special limit case
+ return Collections.emptyMap();
+ }
+
+ Map<String, Object> result = Maps.newTreeMap();
+ for (String sourceProperty : simpleProperties) {
+
+
+ try {
+ Object read;
+ Method readMethod = model.getSourceReadMethod(sourceProperty);
+ read = readMethod.invoke(source);
+ if (log.isDebugEnabled()) {
+ log.debug("property " + sourceProperty + ", type : " +
+ readMethod.getReturnType() + ", value = " + read);
+ }
+ if (readMethod.getReturnType().isPrimitive() &&
+ ObjectUtil.getNullValue(
+ readMethod.getReturnType()).equals(read)) {
+ // for primitive type case, force nullity
+ read = null;
+ }
+
+ if (read != null) {
+ result.put(sourceProperty, read);
+ }
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return result;
+ }
+
+ public Iterable<?> getCollectionValue(E source, String sourceProperty) {
+ try {
+ Method readMethod = model.getSourceReadMethod(sourceProperty);
+ Object result = readMethod.invoke(source);
+ return (Iterable<?>) result;
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+}
Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceContextFilter.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceContextFilter.java)
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceContextFilter.java (rev 0)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceContextFilter.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,84 @@
+package org.chorem.pollen.rest.api;
+
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.apache.commons.lang3.StringUtils;
+import org.chorem.pollen.persistence.entity.SessionToken;
+import org.chorem.pollen.services.PollenSecurityContext;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.InvalidSessionTokenException;
+import org.debux.webmotion.server.WebMotionFilter;
+import org.debux.webmotion.server.call.HttpContext;
+
+import javax.persistence.EntityManager;
+
+/**
+ * Inject le service context dans les controlleurs.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollenServiceContextFilter extends WebMotionFilter {
+
+ public static final String REQUEST_AUTH_PARAMETER = "auth";
+
+ public void inject(HttpContext context) throws InvalidSessionTokenException {
+
+ PollenApplicationContext applicationContext =
+ PollenServices.getApplicationContext(context.getServletContext());
+
+ EntityManager entityManager =
+ PollenServices.getEntityManager(context.getRequest());
+
+ PollenServiceContext serviceContext =
+ applicationContext.newServiceContext(entityManager);
+ PollenServices.setServiceContext(context.getRequest(), serviceContext);
+
+ addSecurityContext(context, serviceContext);
+
+ doProcess();
+ }
+
+ protected void addSecurityContext(HttpContext context,
+ PollenServiceContext serviceContext) throws InvalidSessionTokenException {
+
+ String[] strings = context.getParameters().get(REQUEST_AUTH_PARAMETER);
+
+ String authParam = strings == null || strings.length < 1 ? null : strings[1];
+
+ SessionToken sessionToken = null;
+
+ if (StringUtils.isNotBlank(authParam)) {
+
+ // find out the userId from this auth
+
+ sessionToken = serviceContext.getAuthService().getUserByAuth(authParam);
+ }
+ PollenSecurityContext securityContext;
+ securityContext = PollenSecurityContext.newContext(
+ sessionToken == null ? null : sessionToken.getPollenUser()
+ );
+ serviceContext.setSecurityContext(securityContext);
+ }
+}
Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceListener.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceListener.java)
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceListener.java (rev 0)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServiceListener.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,124 @@
+package org.chorem.pollen.rest.api;
+
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.UserEmailAlreadyUsedException;
+import org.chorem.pollen.services.exception.UserLoginAlreadyUsedException;
+import org.debux.webmotion.server.WebMotionServerListener;
+import org.debux.webmotion.server.call.Call;
+import org.debux.webmotion.server.call.HttpContext;
+import org.debux.webmotion.server.call.ServerContext;
+import org.debux.webmotion.server.handler.ExecutorParametersInjectorHandler;
+import org.debux.webmotion.server.mapping.Mapping;
+
+import javax.persistence.EntityManager;
+import javax.servlet.http.HttpServletRequest;
+import java.lang.reflect.Type;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollenServiceListener implements WebMotionServerListener {
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(PollenServiceListener.class);
+
+ @Override
+ public void onStart(Mapping mapping, ServerContext serverContext) {
+
+ serverContext.addInjector(new PollenServiceContextInjector());
+ serverContext.addInjector(new SessionTokenInjector());
+
+ // Create application context
+ PollenApplicationContext applicationContext =
+ new PollenApplicationContext();
+
+ // push it in context
+ PollenServices.setApplicationContext(
+ serverContext.getServletContext(), applicationContext);
+
+ EntityManager entityManager = applicationContext.newEntityManager();
+
+ try {
+ PollenServiceContext serviceContext =
+ applicationContext.newServiceContext(entityManager);
+ serviceContext.getUserService().createDefaultUsers();
+ } catch (UserEmailAlreadyUsedException e) {
+ //Can't happen
+ } catch (UserLoginAlreadyUsedException e) {
+ //Can't happen
+ } finally {
+ entityManager.close();
+ }
+ }
+
+ @Override
+ public void onStop(ServerContext serverContext) {
+
+ // Get application context
+ PollenApplicationContext applicationContext =
+ PollenServices.getApplicationContext(
+ serverContext.getServletContext());
+
+ // close it (and all underlined resources)
+ if (applicationContext != null) {
+ applicationContext.close();
+ }
+ }
+
+ protected static class PollenServiceContextInjector implements ExecutorParametersInjectorHandler.Injector {
+ @Override
+ public Object getValue(Mapping mapping, Call call, String name, Class<?> type, Type generic) {
+ PollenServiceContext result = null;
+ if (PollenServiceContext.class.isAssignableFrom(type)) {
+ HttpContext httpContext = call.getContext();
+ HttpServletRequest request = httpContext.getRequest();
+
+ result = PollenServices.getServiceContext(request);
+ }
+ return result;
+ }
+ }
+
+ protected static class SessionTokenInjector implements ExecutorParametersInjectorHandler.Injector {
+ @Override
+ public Object getValue(Mapping mapping, Call call, String name, Class<?> type, Type generic) {
+ PollenServiceContext result = null;
+ if (PollenServiceContext.class.isAssignableFrom(type)) {
+ HttpContext httpContext = call.getContext();
+ HttpServletRequest request = httpContext.getRequest();
+
+ result = PollenServices.getServiceContext(request);
+ }
+ return result;
+ }
+ }
+}
Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServices.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServices.java)
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServices.java (rev 0)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenServices.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,89 @@
+package org.chorem.pollen.rest.api;
+
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.chorem.pollen.persistence.entity.SessionToken;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.nuiton.web.filter.JpaTransactionFilter;
+
+import javax.persistence.EntityManager;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollenServices {
+
+ protected static final String APPLICATION_CONTEXT_PARAMETER = "pollen_PollenApplicationContext";
+
+ protected static final String REQUEST_POLLEN_SERVICE_CONTEXT = "pollen_PollenServiceContext";
+
+ protected static final String REQUEST_POLLEN_CONNECTED_USER = "pollen_PollenConnectedUser";
+
+ protected static final String REQUEST_ENTITY_MANAGER = JpaTransactionFilter.JPA_TRANSACTION_REQUEST_ATTRIBUTE;
+
+ public static PollenApplicationContext getApplicationContext(ServletContext servletContext) {
+ PollenApplicationContext result = (PollenApplicationContext)
+ servletContext.getAttribute(APPLICATION_CONTEXT_PARAMETER);
+ return result;
+ }
+
+ public static void setApplicationContext(ServletContext servletContext,
+ PollenApplicationContext applicationContext) {
+ servletContext.setAttribute(APPLICATION_CONTEXT_PARAMETER, applicationContext);
+ }
+
+
+ public static PollenServiceContext getServiceContext(HttpServletRequest request) {
+ PollenServiceContext result = (PollenServiceContext)
+ request.getAttribute(REQUEST_POLLEN_SERVICE_CONTEXT);
+ return result;
+ }
+
+ public static void setServiceContext(HttpServletRequest request,
+ PollenServiceContext serviceContext) {
+ request.setAttribute(REQUEST_POLLEN_SERVICE_CONTEXT, serviceContext);
+ }
+
+ public static EntityManager getEntityManager(HttpServletRequest request) {
+ EntityManager result = (EntityManager)
+ request.getAttribute(REQUEST_ENTITY_MANAGER);
+ return result;
+ }
+
+ public static SessionToken getSessionToken(HttpServletRequest request) {
+ SessionToken result = (SessionToken)
+ request.getAttribute(REQUEST_POLLEN_CONNECTED_USER);
+ return result;
+ }
+
+ public static void setSessionToken(HttpServletRequest request,
+ SessionToken sessionToken) {
+ request.setAttribute(REQUEST_POLLEN_CONNECTED_USER, sessionToken);
+ }
+}
\ No newline at end of file
Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/UserService.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/UserService.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/UserService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,79 +0,0 @@
-package org.chorem.pollen.rest.api;
-
-/*
- * #%L
- * Pollen :: Rest Api
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.chorem.pollen.persistence.entity.PollenUser;
-import org.chorem.pollen.services.PollenServiceContext;
-import org.chorem.pollen.services.exception.EntityNotFoundException;
-import org.chorem.pollen.services.exception.UserEmailAlreadyUsedException;
-import org.chorem.pollen.services.exception.UserInvalidEmailActiviationTokenException;
-import org.chorem.pollen.services.exception.UserInvalidPasswordException;
-import org.chorem.pollen.services.exception.UserLoginAlreadyUsedException;
-import org.debux.webmotion.server.WebMotionController;
-
-import java.util.List;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class UserService extends WebMotionController {
-
- public List<PollenUser> getUsers(PollenServiceContext context) {
- List<PollenUser> users = context.getUserService().getUsers();
- return users;
- }
-
- public PollenUser getUser(PollenServiceContext context,
- String userId) throws EntityNotFoundException {
- return context.getUserService().getUser(userId);
- }
-
- public PollenUser createUser(PollenServiceContext context,
- PollenUser user,
- boolean generatePassword) throws UserEmailAlreadyUsedException, UserLoginAlreadyUsedException {
- return context.getUserService().createUser(user, generatePassword);
-
- }
-
- public PollenUser editUser(PollenServiceContext context,
- PollenUser user) throws UserInvalidPasswordException, UserEmailAlreadyUsedException, EntityNotFoundException {
- return context.getUserService().editUser(user);
- }
-
- public void validateUserEmail(PollenServiceContext context,
- String userId,
- String token) throws EntityNotFoundException, UserInvalidEmailActiviationTokenException {
- context.getUserService().validateUserEmail(userId, token);
- }
-
- public void changePassword(PollenServiceContext context,
- String userId,
- String oldPassword,
- String newPassword) throws UserInvalidPasswordException, EntityNotFoundException {
- context.getUserService().changePassword(userId, oldPassword, newPassword);
- }
-}
Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteCountingService.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteCountingService.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteCountingService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,42 +0,0 @@
-package org.chorem.pollen.rest.api;
-
-/*
- * #%L
- * Pollen :: Rest Api
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.chorem.pollen.services.PollResult;
-import org.chorem.pollen.services.PollenServiceContext;
-import org.chorem.pollen.services.exception.EntityNotFoundException;
-import org.debux.webmotion.server.WebMotionController;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class VoteCountingService extends WebMotionController {
-
- public PollResult getResult(PollenServiceContext context, String pollId) throws EntityNotFoundException {
- return context.getVoteCountingService().getResult(pollId);
- }
-}
Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteService.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteService.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,61 +0,0 @@
-package org.chorem.pollen.rest.api;
-
-/*
- * #%L
- * Pollen :: Rest Api
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.chorem.pollen.persistence.entity.Vote;
-import org.chorem.pollen.services.PollenServiceContext;
-import org.chorem.pollen.services.exception.EntityNotFoundException;
-import org.debux.webmotion.server.WebMotionController;
-
-import java.util.List;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class VoteService extends WebMotionController {
-
- public List<Vote> getVotes(PollenServiceContext context, String pollId) throws EntityNotFoundException {
- List<Vote> votes = context.getVoteService().getVotes(pollId);
- return votes;
- }
-
- public Vote getVote(PollenServiceContext context, String voteId) throws EntityNotFoundException {
- return context.getVoteService().getVote(voteId);
- }
-
- public Vote addVote(PollenServiceContext context, String pollId, Vote vote) throws EntityNotFoundException {
- return context.getVoteService().addVote(pollId, vote);
- }
-
- public Vote editVote(PollenServiceContext context, Vote vote) throws EntityNotFoundException {
- return context.getVoteService().editVote(vote);
- }
-
- public void deleteVote(PollenServiceContext context, String pollId, String voteId) throws EntityNotFoundException {
- context.getVoteService().deleteVote(pollId, voteId);
- }
-}
Deleted: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoterListService.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoterListService.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoterListService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,88 +0,0 @@
-package org.chorem.pollen.rest.api;
-
-/*
- * #%L
- * Pollen :: Rest Api
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.chorem.pollen.persistence.entity.VoterList;
-import org.chorem.pollen.persistence.entity.VoterListMember;
-import org.chorem.pollen.services.PollenServiceContext;
-import org.chorem.pollen.services.exception.EntityNotFoundException;
-import org.debux.webmotion.server.WebMotionController;
-
-import java.util.List;
-import java.util.Set;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class VoterListService extends WebMotionController {
-
- public VoterList importFavoriteList(PollenServiceContext context, String pollId, String favoriteListId) throws EntityNotFoundException {
- return context.getVoterListService().importFavoriteList(pollId, favoriteListId);
- }
-
- public List<VoterList> getVoterLists(PollenServiceContext context, String pollId) throws EntityNotFoundException {
- List<VoterList> voterLists = context.getVoterListService().getVoterLists(pollId);
- return voterLists;
- }
-
- public VoterList getVoterList(PollenServiceContext context, String voterListId) throws EntityNotFoundException {
- return context.getVoterListService().getVoterList(voterListId);
- }
-
- public VoterList addVoterList(PollenServiceContext context, String pollId, VoterList voterList) throws EntityNotFoundException {
- return context.getVoterListService().addVoterList(pollId, voterList);
- }
-
- public VoterList editVoterList(PollenServiceContext context, VoterList voterList) throws EntityNotFoundException {
- return context.getVoterListService().editVoterList(voterList);
- }
-
- public void deleteVoterList(PollenServiceContext context, String pollId, String voterListId) throws EntityNotFoundException {
- context.getVoterListService().deleteVoterList(pollId, voterListId);
- }
-
- public Set<VoterListMember> getMembers(PollenServiceContext context, String voterListId) throws EntityNotFoundException {
- Set<VoterListMember> members = context.getVoterListService().getMembers(voterListId);
- return members;
- }
-
- public VoterListMember getMember(PollenServiceContext context, String memberId) throws EntityNotFoundException {
- return context.getVoterListService().getMember(memberId);
- }
-
- public VoterListMember addMember(PollenServiceContext context, String voterListId, VoterListMember member) throws EntityNotFoundException {
- return context.getVoterListService().addMember(voterListId, member);
- }
-
- public VoterListMember editMember(PollenServiceContext context, VoterListMember member) throws EntityNotFoundException {
- return context.getVoterListService().editMember(member);
- }
-
- public void deleteMember(PollenServiceContext context, String voterListId, String memberId) throws EntityNotFoundException {
- context.getVoterListService().deleteMember(voterListId, memberId);
- }
-}
Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthService.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/AuthService.java)
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthService.java (rev 0)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,50 @@
+package org.chorem.pollen.rest.api.v1;
+
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.chorem.pollen.services.exception.UserInvalidPasswordException;
+import org.debux.webmotion.server.WebMotionController;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class AuthService extends WebMotionController {
+
+ public String login(PollenServiceContext context, String login, String password) throws UserInvalidPasswordException, EntityNotFoundException {
+ return context.getAuthService().login(login, password);
+ }
+
+ public void lostPassword(PollenServiceContext context, String login) throws EntityNotFoundException {
+ context.getAuthService().lostPassword(login);
+ }
+
+ public void logout(PollenServiceContext context, String login, String token) throws EntityNotFoundException {
+ context.getAuthService().logout(login, token);
+ }
+}
Added: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceService.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceService.java (rev 0)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,62 @@
+package org.chorem.pollen.rest.api.v1;
+
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.chorem.pollen.persistence.entity.Choice;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.chorem.pollen.services.exception.InvalidChoiceFormException;
+import org.debux.webmotion.server.WebMotionController;
+
+import java.util.List;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class ChoiceService extends WebMotionController {
+
+ public List<Choice> getChoices(PollenServiceContext context, String pollId) throws EntityNotFoundException {
+ List<Choice> choices = context.getChoiceService().getChoices(pollId);
+ return choices;
+ }
+
+ public Choice getChoice(PollenServiceContext context, String pollId, String choiceId) throws EntityNotFoundException {
+ return context.getChoiceService().getChoice(pollId, choiceId);
+ }
+
+ public Choice addChoice(PollenServiceContext context, String pollId, Choice choice) throws EntityNotFoundException, InvalidChoiceFormException {
+ return context.getChoiceService().addChoice(pollId, choice);
+ }
+
+ public Choice editChoice(PollenServiceContext context, String pollId, Choice choice) throws EntityNotFoundException, InvalidChoiceFormException {
+ return context.getChoiceService().editChoice(pollId, choice);
+ }
+
+ public void deleteChoice(PollenServiceContext context, String pollId, String choiceId) throws EntityNotFoundException {
+ context.getChoiceService().deleteChoice(pollId, choiceId);
+ }
+}
\ No newline at end of file
Property changes on: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentService.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/CommentService.java)
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentService.java (rev 0)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,61 @@
+package org.chorem.pollen.rest.api.v1;
+
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.chorem.pollen.persistence.entity.Comment;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.debux.webmotion.server.WebMotionController;
+
+import java.util.List;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class CommentService extends WebMotionController {
+
+ public List<Comment> getComments(PollenServiceContext context, String pollId) throws EntityNotFoundException {
+ List<Comment> comments = context.getCommentService().getComments(pollId);
+ return comments;
+ }
+
+ public Comment getComment(PollenServiceContext context, String commentId) throws EntityNotFoundException {
+ return context.getCommentService().getComment(commentId);
+ }
+
+ public Comment addComment(PollenServiceContext context, String pollId, Comment comment) throws EntityNotFoundException {
+ return context.getCommentService().addComment(pollId, comment);
+ }
+
+ public Comment editComment(PollenServiceContext context,Comment comment) throws EntityNotFoundException {
+ return context.getCommentService().editComment(comment);
+ }
+
+ public void deleteComment(PollenServiceContext context, String pollId, String commentId) throws EntityNotFoundException {
+ context.getCommentService().deleteComment(pollId, commentId);
+ }
+}
Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ErrorAction.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/ErrorAction.java)
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ErrorAction.java (rev 0)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ErrorAction.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,55 @@
+package org.chorem.pollen.rest.api.v1;
+
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.common.collect.Multimap;
+import org.chorem.pollen.services.exception.AbstractInvalidFormException;
+import org.debux.webmotion.server.WebMotionController;
+import org.debux.webmotion.server.render.Render;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class ErrorAction extends WebMotionController {
+
+ public Render on404(Exception e) {
+ return renderError(404, e.getMessage());
+ }
+
+ public Render on500(Exception e) {
+ return renderError(500, e.getMessage());
+ }
+
+ public Render on500Form(Exception e) {
+ AbstractInvalidFormException ex = (AbstractInvalidFormException) e;
+
+ //TODO Send back this
+ Multimap<String, String> errors = ex.getErrors();
+
+ return renderError(500, e.getMessage());
+ }
+}
Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListService.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/FavoriteListService.java)
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListService.java (rev 0)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,99 @@
+package org.chorem.pollen.rest.api.v1;
+
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.chorem.pollen.persistence.entity.FavoriteList;
+import org.chorem.pollen.persistence.entity.FavoriteListMember;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.chorem.pollen.services.exception.FavoriteListImportException;
+import org.chorem.pollen.services.exception.FavoriteListMemberEmailAlreadyUsedException;
+import org.chorem.pollen.services.exception.FavoriteListMemberNameAlreadyUsedException;
+import org.chorem.pollen.services.exception.FavoriteListMemberNotOwnedByFavoriteListException;
+import org.chorem.pollen.services.exception.FavoriteListNameAlreadyUsedException;
+import org.chorem.pollen.services.exception.FavoriteListNotOwnedByUserException;
+import org.debux.webmotion.server.WebMotionController;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ * TODO
+ * TODO All method needs a userId connected
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class FavoriteListService extends WebMotionController {
+
+ public List<FavoriteList> getFavoriteLists(PollenServiceContext context, String userId) throws EntityNotFoundException {
+ List<FavoriteList> favoriteLists = context.getFavoriteListService().getFavoriteLists(userId);
+ return favoriteLists;
+ }
+
+ public FavoriteList getFavoriteList(PollenServiceContext context, String favoriteListId) throws EntityNotFoundException {
+ return context.getFavoriteListService().getFavoriteList(favoriteListId);
+ }
+
+ public FavoriteList createFavoriteList(PollenServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, FavoriteListNameAlreadyUsedException {
+ return context.getFavoriteListService().createFavoriteList(userId, favoriteList);
+ }
+
+ public FavoriteList editFavoriteList(PollenServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, FavoriteListNameAlreadyUsedException, FavoriteListNotOwnedByUserException {
+ return context.getFavoriteListService().editFavoriteList(userId, favoriteList);
+ }
+
+ public void deleteFavoriteList(PollenServiceContext context, String userId, String favoriteListId) throws EntityNotFoundException, FavoriteListNotOwnedByUserException {
+ context.getFavoriteListService().deleteFavoriteList(userId, favoriteListId);
+ }
+
+ public int importFavoriteListMembersFromCsv(PollenServiceContext context, String userId, String favoriteListId, File csvFile) throws EntityNotFoundException, FavoriteListImportException, FavoriteListNotOwnedByUserException {
+ return context.getFavoriteListService().importFavoriteListMembersFromCsv(userId, favoriteListId, csvFile);
+ }
+
+ public int importFavoriteListMembersFromLdap(PollenServiceContext context, String userId, String favoriteListId, String ldap) throws EntityNotFoundException, FavoriteListImportException, FavoriteListNotOwnedByUserException {
+ return context.getFavoriteListService().importFavoriteListMembersFromLdap(userId, favoriteListId, ldap);
+ }
+
+ public List<FavoriteListMember> getMembers(PollenServiceContext context, String favoriteListId) throws EntityNotFoundException {
+ List<FavoriteListMember> members = context.getFavoriteListService().getFavoriteListMembers(favoriteListId);
+ return members;
+ }
+
+ public FavoriteListMember getMember(PollenServiceContext context, String memberId) throws EntityNotFoundException {
+ return context.getFavoriteListService().getFavoriteListMember(memberId);
+ }
+
+ public FavoriteListMember addMember(PollenServiceContext context, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberEmailAlreadyUsedException, FavoriteListMemberNameAlreadyUsedException {
+ return context.getFavoriteListService().addFavoriteListMember(favoriteListId, member);
+ }
+
+ public FavoriteListMember editMember(PollenServiceContext context, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberEmailAlreadyUsedException, FavoriteListMemberNameAlreadyUsedException, FavoriteListMemberNotOwnedByFavoriteListException {
+ return context.getFavoriteListService().editFavoriteListMember(favoriteListId, member);
+ }
+
+ public void removeMember(PollenServiceContext context, String favoriteListId, String memberId) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException {
+ context.getFavoriteListService().removeFavoriteListMember(favoriteListId, memberId);
+ }
+}
Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollService.java)
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java (rev 0)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,95 @@
+package org.chorem.pollen.rest.api.v1;
+
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.chorem.pollen.persistence.entity.ChoiceType;
+import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.chorem.pollen.services.exception.InvalidPollFormException;
+import org.debux.webmotion.server.WebMotionController;
+
+import java.io.File;
+import java.util.Set;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollService extends WebMotionController {
+
+ public Poll getNewPoll(PollenServiceContext context, String userId, ChoiceType choiceType) throws EntityNotFoundException {
+ return context.getPollService().getNewPoll(userId, choiceType);
+ }
+
+ public Set<Poll> getPolls(PollenServiceContext context, String userId) throws EntityNotFoundException {
+ Set<Poll> polls = context.getPollService().getPolls(userId);
+ return polls;
+ }
+
+ public Set<Poll> getCreatedPolls(PollenServiceContext context, String userId) throws EntityNotFoundException {
+ Set<Poll> polls = context.getPollService().getCreatedPolls(userId);
+ return polls;
+ }
+
+ public Set<Poll> getInvitedPolls(PollenServiceContext context, String userId) throws EntityNotFoundException {
+ Set<Poll> polls = context.getPollService().getInvitedPolls(userId);
+ return polls;
+ }
+
+ public Set<Poll> getParticipatedPolls(PollenServiceContext context, String userId) throws EntityNotFoundException {
+ Set<Poll> polls = context.getPollService().getParticipatedPolls(userId);
+ return polls;
+ }
+
+ public Poll getPoll(PollenServiceContext context, String pollId) throws EntityNotFoundException {
+ return context.getPollService().getPoll(pollId);
+ }
+
+ public Poll createPoll(PollenServiceContext context, String userId, Poll poll) throws EntityNotFoundException, InvalidPollFormException {
+ return context.getPollService().createPoll(userId, poll);
+ }
+
+ public Poll editPoll(PollenServiceContext context, Poll poll) throws EntityNotFoundException, InvalidPollFormException {
+ return context.getPollService().editPoll(poll);
+ }
+
+ public void deletePoll(PollenServiceContext context, String pollId) throws EntityNotFoundException {
+ context.getPollService().deletePoll(pollId);
+ }
+
+ public Poll clonePoll(PollenServiceContext context, String pollId) throws EntityNotFoundException {
+ return context.getPollService().clonePoll(pollId);
+ }
+
+ public File closePoll(PollenServiceContext context, String pollId) throws EntityNotFoundException {
+ return context.getPollService().closePoll(pollId);
+ }
+
+ public File exportPoll(PollenServiceContext context, String pollId) throws EntityNotFoundException {
+ return context.getPollService().exportPoll(pollId);
+ }
+}
Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/UserService.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/UserService.java)
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/UserService.java (rev 0)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/UserService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,79 @@
+package org.chorem.pollen.rest.api.v1;
+
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.chorem.pollen.persistence.entity.PollenUser;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.chorem.pollen.services.exception.UserEmailAlreadyUsedException;
+import org.chorem.pollen.services.exception.UserInvalidEmailActiviationTokenException;
+import org.chorem.pollen.services.exception.UserInvalidPasswordException;
+import org.chorem.pollen.services.exception.UserLoginAlreadyUsedException;
+import org.debux.webmotion.server.WebMotionController;
+
+import java.util.List;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class UserService extends WebMotionController {
+
+ public List<PollenUser> getUsers(PollenServiceContext context) {
+ List<PollenUser> users = context.getUserService().getUsers();
+ return users;
+ }
+
+ public PollenUser getUser(PollenServiceContext context,
+ String userId) throws EntityNotFoundException {
+ return context.getUserService().getUser(userId);
+ }
+
+ public PollenUser createUser(PollenServiceContext context,
+ PollenUser user,
+ boolean generatePassword) throws UserEmailAlreadyUsedException, UserLoginAlreadyUsedException {
+ return context.getUserService().createUser(user, generatePassword);
+
+ }
+
+ public PollenUser editUser(PollenServiceContext context,
+ PollenUser user) throws UserInvalidPasswordException, UserEmailAlreadyUsedException, EntityNotFoundException {
+ return context.getUserService().editUser(user);
+ }
+
+ public void validateUserEmail(PollenServiceContext context,
+ String userId,
+ String token) throws EntityNotFoundException, UserInvalidEmailActiviationTokenException {
+ context.getUserService().validateUserEmail(userId, token);
+ }
+
+ public void changePassword(PollenServiceContext context,
+ String userId,
+ String oldPassword,
+ String newPassword) throws UserInvalidPasswordException, EntityNotFoundException {
+ context.getUserService().changePassword(userId, oldPassword, newPassword);
+ }
+}
Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingService.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteCountingService.java)
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingService.java (rev 0)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,42 @@
+package org.chorem.pollen.rest.api.v1;
+
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.chorem.pollen.services.PollResult;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.debux.webmotion.server.WebMotionController;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class VoteCountingService extends WebMotionController {
+
+ public PollResult getResult(PollenServiceContext context, String pollId) throws EntityNotFoundException {
+ return context.getVoteCountingService().getResult(pollId);
+ }
+}
Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteService.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteService.java)
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteService.java (rev 0)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,61 @@
+package org.chorem.pollen.rest.api.v1;
+
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.chorem.pollen.persistence.entity.Vote;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.debux.webmotion.server.WebMotionController;
+
+import java.util.List;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class VoteService extends WebMotionController {
+
+ public List<Vote> getVotes(PollenServiceContext context, String pollId) throws EntityNotFoundException {
+ List<Vote> votes = context.getVoteService().getVotes(pollId);
+ return votes;
+ }
+
+ public Vote getVote(PollenServiceContext context, String voteId) throws EntityNotFoundException {
+ return context.getVoteService().getVote(voteId);
+ }
+
+ public Vote addVote(PollenServiceContext context, String pollId, Vote vote) throws EntityNotFoundException {
+ return context.getVoteService().addVote(pollId, vote);
+ }
+
+ public Vote editVote(PollenServiceContext context, Vote vote) throws EntityNotFoundException {
+ return context.getVoteService().editVote(vote);
+ }
+
+ public void deleteVote(PollenServiceContext context, String pollId, String voteId) throws EntityNotFoundException {
+ context.getVoteService().deleteVote(pollId, voteId);
+ }
+}
Copied: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java (from rev 3825, trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoterListService.java)
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java (rev 0)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,88 @@
+package org.chorem.pollen.rest.api.v1;
+
+/*
+ * #%L
+ * Pollen :: Rest Api
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.chorem.pollen.persistence.entity.VoterList;
+import org.chorem.pollen.persistence.entity.VoterListMember;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.debux.webmotion.server.WebMotionController;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class VoterListService extends WebMotionController {
+
+ public VoterList importFavoriteList(PollenServiceContext context, String pollId, String favoriteListId) throws EntityNotFoundException {
+ return context.getVoterListService().importFavoriteList(pollId, favoriteListId);
+ }
+
+ public List<VoterList> getVoterLists(PollenServiceContext context, String pollId) throws EntityNotFoundException {
+ List<VoterList> voterLists = context.getVoterListService().getVoterLists(pollId);
+ return voterLists;
+ }
+
+ public VoterList getVoterList(PollenServiceContext context, String pollId, String voterListId) throws EntityNotFoundException {
+ return context.getVoterListService().getVoterList(pollId, voterListId);
+ }
+
+ public VoterList addVoterList(PollenServiceContext context, String pollId, VoterList voterList) throws EntityNotFoundException {
+ return context.getVoterListService().addVoterList(pollId, voterList);
+ }
+
+ public VoterList editVoterList(PollenServiceContext context, String pollId, VoterList voterList) throws EntityNotFoundException {
+ return context.getVoterListService().editVoterList(pollId, voterList);
+ }
+
+ public void deleteVoterList(PollenServiceContext context, String pollId, String voterListId) throws EntityNotFoundException {
+ context.getVoterListService().deleteVoterList(pollId, voterListId);
+ }
+
+ public Set<VoterListMember> getMembers(PollenServiceContext context, String pollId, String voterListId) throws EntityNotFoundException {
+ Set<VoterListMember> members = context.getVoterListService().getMembers(pollId, voterListId);
+ return members;
+ }
+
+ public VoterListMember getMember(PollenServiceContext context, String pollId, String voterListId, String memberId) throws EntityNotFoundException {
+ return context.getVoterListService().getMember(pollId, voterListId, memberId);
+ }
+
+ public VoterListMember addMember(PollenServiceContext context, String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException {
+ return context.getVoterListService().addMember(pollId, voterListId, member);
+ }
+
+ public VoterListMember editMember(PollenServiceContext context, String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException {
+ return context.getVoterListService().editMember(pollId, voterListId, member);
+ }
+
+ public void deleteMember(PollenServiceContext context, String pollId, String voterListId, String memberId) throws EntityNotFoundException {
+ context.getVoterListService().deleteMember(pollId, voterListId, memberId);
+ }
+}
Modified: trunk/pollen-rest-api/src/main/resources/mapping
===================================================================
--- trunk/pollen-rest-api/src/main/resources/mapping 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-rest-api/src/main/resources/mapping 2013-06-15 10:58:03 UTC (rev 3830)
@@ -7,8 +7,6 @@
[filters]
* /* PollenServiceContextFilter.inject
-#* /* PollenIdOrTokenInjector.inject
-#* /* PollenSecurityFilter.inject (prend le param auth pour retrouver le PollenUser)
#- une fois un object lié à PollenUser, c'est immuable.
@@ -19,89 +17,93 @@
org.chorem.pollen.service.exception.UserLoginAlreadyUsedException ErrorAction.on500
org.chorem.pollen.service.exception.UserInvalidPasswordException ErrorAction.on500
org.chorem.pollen.service.exception.UserInvalidEmailActiviationTokenException ErrorAction.on500
+org.chorem.pollen.service.exception.AbstractInvalidFormException ErrorAction.on500Form
[actions]
# AuthService
-PUT /login AuthService.login
-GET /lostpassword/{token} AuthService.lostPassword
-GET /logout AuthService.logout
+PUT /v1/login AuthService.login
+GET /v1/lostpassword/{token} AuthService.lostPassword
+GET /v1/logout AuthService.logout
+# ChoiceService
+
+GET /v1/polls/{pollId}/choices ChoiceService.getChoices
+POST /v1/polls/{pollId}/choices ChoiceService.addChoice
+GET /v1/polls/{pollId}/choices/{choiceId} ChoiceService.getChoice
+PUT /v1/polls/{pollId}/choices/{choiceId} ChoiceService.editChoice
+DELETE /v1/polls/{pollId}/choices/{choiceId} ChoiceService.deleteChoice
+
# CommentService
-GET /polls/{pollId}/comments CommentService.getComments
-POST /polls/{pollId}/comments CommentService.addComment
-GET /comments/{commentId} CommentService.getComment
-PUT /comments/{commentId} CommentService.editComment
-DELETE /polls/{pollId}/comments/{commentId} CommentService.deleteComment
+GET /v1/polls/{pollId}/comments CommentService.getComments
+POST /v1/polls/{pollId}/comments CommentService.addComment
+GET /v1/polls/{pollId}/comments/{commentId} CommentService.getComment
+PUT /v1/polls/{pollId}/comments/{commentId} CommentService.editComment
+DELETE /v1/polls/{pollId}/comments/{commentId} CommentService.deleteComment
# FavoriteListService
-GET /favoriteLists FavoriteListService.getFavoriteLists
-GET /favoriteLists/{flId} FavoriteListService.getFavoriteList
-POST /favoriteLists/{flId}/importCsv FavoriteListService.importFavoriteListMemberFromCsv
-POST /favoriteLists/{flId}/importLdap FavoriteListService.importFavoriteListMemberFromLdap
-POST /favoriteLists FavoriteListService.createFavoriteList
-PUT /favoriteLists/{flId} FavoriteListService.editFavoriteList
-DELETE /favoriteLists/{flId} FavoriteListService.deleteFavoriteList
-GET /favoriteLists/{flId}/members FavoriteListService.getMembers
-GET /favoriteListMembers/{mId} FavoriteListService.getMember
-POST /favoriteLists/{flId}/members FavoriteListService.addMember
-PUT /favoriteLists/{flId}/members/{mId} FavoriteListService.editMember
-DELETE /favoriteLists/{flId}/members/{mId} FavoriteListService.removeMember
+GET /v1/favoriteLists FavoriteListService.getFavoriteLists
+GET /v1/favoriteLists/{flId} FavoriteListService.getFavoriteList
+POST /v1/favoriteLists/{flId}/importCsv FavoriteListService.importFavoriteListMemberFromCsv
+POST /v1/favoriteLists/{flId}/importLdap FavoriteListService.importFavoriteListMemberFromLdap
+POST /v1/favoriteLists FavoriteListService.createFavoriteList
+PUT /v1/favoriteLists/{flId} FavoriteListService.editFavoriteList
+DELETE /v1/favoriteLists/{flId} FavoriteListService.deleteFavoriteList
+GET /v1/favoriteLists/{flId}/members FavoriteListService.getMembers
+GET /v1/favoriteLists/{flId}/members/{mId} FavoriteListService.getMember
+POST /v1/favoriteLists/{flId}/members FavoriteListService.addMember
+PUT /v1/favoriteLists/{flId}/members/{mId} FavoriteListService.editMember
+DELETE /v1/favoriteLists/{flId}/members/{mId} FavoriteListService.removeMember
# PollService
-GET /polls PollService.getPolls
-GET /polls/created PollService.getCreatedPolls
-GET /polls/invited PollService.getInvitedPolls
-GET /polls/participated PollService.getParticipatedPolls
-POST /polls PollService.createPoll
-PUT /polls/{pollId} PollService.editPoll
-GET /polls/{pollId} PollService.getPoll
-DELETE /polls/{pollId} PollService.deletePoll
-POST /polls/{pollId} PollService.clonePoll
-GET /polls/{pollId}/export PollService.exportPoll
-PUT /polls/{pollId}/close PollService.closePoll
+GET /v1/polls/new PollService.getNewPoll
+GET /v1/polls PollService.getPolls
+GET /v1/polls/created PollService.getCreatedPolls
+GET /v1/polls/invited PollService.getInvitedPolls
+GET /v1/polls/participated PollService.getParticipatedPolls
+POST /v1/polls PollService.createPoll
+PUT /v1/polls/{pollId} PollService.editPoll
+GET /v1/polls/{pollId} PollService.getPoll
+DELETE /v1/polls/{pollId} PollService.deletePoll
+POST /v1/polls/{pollId} PollService.clonePoll
+GET /v1/polls/{pollId}/export PollService.exportPoll
+PUT /v1/polls/{pollId}/close PollService.closePoll
-GET /polls/{pollId}/choices PollService.getChoices
-POST /polls/{pollId}/choices PollService.addChoice
-GET /choices/{choiceId} PollService.getChoice
-PUT /choices/{choiceId} PollService.editChoice
-DELETE /polls/{pollId}/choices/{choiceId} PollService.deleteChoice
-
# UserService
-GET /users UserService.getUsers
-GET /users/{userId} UserService.getUser
-POST /users UserService.createUser
-PUT /users/{userId} UserService.editUser
-PUT /users/{userId}?token={} UserService.validateUserEmail
+GET /v1/users UserService.getUsers
+GET /v1/users/{userId} UserService.getUser
+POST /v1/users UserService.createUser
+PUT /v1/users/{userId} UserService.editUser
+PUT /v1/users/{userId}?token={} UserService.validateUserEmail
# VoteCountingService
-GET /polls/{pollId}/results VoteCountingService.getResult
+GET /v1/polls/{pollId}/results VoteCountingService.getResult
# VoterListService
-PUT /polls/{pollId}/favoriteLists/{flId} VoterListService.importFavoriteList
-GET /polls/{pollId}/voterLists VoterListService.getVoterLists
-GET /voterLists/{vlId} VoterListService.getVoterList
-POST /voterLists VoterListService.createVoterList
-PUT /voterLists/{vlId} VoterListService.editVoterList
-DELETE /polls/{pollId}/voterLists/{vlId} VoterListService.deleteVoterList
+PUT /v1/polls/{pollId}/favoriteLists/{flId} VoterListService.importFavoriteList
+GET /v1/polls/{pollId}/voterLists VoterListService.getVoterLists
+GET /v1/polls/{pollId}/voterLists/{vlId} VoterListService.getVoterList
+POST /v1/polls/{pollId}/voterLists VoterListService.createVoterList
+PUT /v1/polls/{pollId}/voterLists/{vlId} VoterListService.editVoterList
+DELETE /v1/polls/{pollId}/voterLists/{vlId} VoterListService.deleteVoterList
-GET /voterLists/{vlId}/members VoterListService.getMembers
-GET /voterListMembers/{mId} VoterListService.getMember
-POST /voterLists/{vlId}/members VoterListService.addMember
-PUT /voterListMembers/{mId} VoterListService.editMember
-DELETE /voterLists/{vlId}/members/{mId} VoterListService.deleteMember
+GET /v1/polls/{pollId}/voterLists/{vlId}/members VoterListService.getMembers
+GET /v1/polls/{pollId}/voterLists/{vlId}/members/{mId} VoterListService.getMember
+POST /v1/polls/{pollId}/voterLists/{vlId}/members VoterListService.addMember
+PUT /v1/polls/{pollId}/voterLists/{vlId}/members/{mId} VoterListService.editMember
+DELETE /v1/polls/{pollId}/voterLists/{vlId}/members/{mId} VoterListService.deleteMember
# VoteService
-GET /polls/{pollId}/votes VoteService.getVotes
-PUT /polls/{pollId}/votes VoteService.addVote
-GET /votes/{voteId} VoteService.getVote
-PUT /votes/{voteId} VoteService.editVote
-DELETE /polls/{pollId}/votes/{voteId} VoteService.deleteVote
+GET /v1/polls/{pollId}/votes VoteService.getVotes
+PUT /v1/polls/{pollId}/votes VoteService.addVote
+GET /v1/polls/{pollId}/votes/{voteId} VoteService.getVote
+PUT /v1/polls/{pollId}/votes/{voteId} VoteService.editVote
+DELETE /v1/polls/{pollId}/votes/{voteId} VoteService.deleteVote
Modified: trunk/pollen-rest-api/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/pollen-rest-api/src/main/webapp/WEB-INF/web.xml 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-rest-api/src/main/webapp/WEB-INF/web.xml 2013-06-15 10:58:03 UTC (rev 3830)
@@ -33,7 +33,7 @@
<filter>
<filter-name>jpaTransaction</filter-name>
<filter-class>
- org.chorem.pollen.rest.PollenJpaTransactionFilter
+ org.chorem.pollen.rest.api.PollenJpaTransactionFilter
</filter-class>
</filter>
Modified: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java
===================================================================
--- trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -24,7 +24,6 @@
*/
import org.chorem.pollen.persistence.JpaPollenPersistenceContext;
-import org.chorem.pollen.rest.PollenApplicationContext;
import org.chorem.pollen.services.service.FixturesService;
import org.chorem.pollen.services.PollenFixtures;
import org.chorem.pollen.services.PollenServiceContext;
Modified: trunk/pollen-rest-api/src/test/resources/pollen.properties
===================================================================
--- trunk/pollen-rest-api/src/test/resources/pollen.properties 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-rest-api/src/test/resources/pollen.properties 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,3 +1,25 @@
+###
+# #%L
+# Pollen :: Rest Api
+# $Id$
+# $HeadURL$
+# %%
+# Copyright (C) 2009 - 2013 CodeLutin
+# %%
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# #L%
+###
javax.persistence.jdbc.driver=org.h2.Driver
javax.persistence.jdbc.url=jdbc:h2:file:target/pollen/h2data
javax.persistence.jdbc.user=sa
Modified: trunk/pollen-services/pom.xml
===================================================================
--- trunk/pollen-services/pom.xml 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-services/pom.xml 2013-06-15 10:58:03 UTC (rev 3830)
@@ -99,6 +99,11 @@
</dependency>
<dependency>
+ <groupId>org.apache.shiro</groupId>
+ <artifactId>shiro-core</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -28,11 +28,13 @@
import org.chorem.pollen.persistence.PollenPersistenceContext;
import org.chorem.pollen.services.config.PollenServiceConfig;
import org.chorem.pollen.services.service.AuthService;
+import org.chorem.pollen.services.service.ChoiceService;
import org.chorem.pollen.services.service.CommentService;
import org.chorem.pollen.services.service.EmailService;
import org.chorem.pollen.services.service.FavoriteListService;
import org.chorem.pollen.services.service.FixturesService;
import org.chorem.pollen.services.service.PollService;
+import org.chorem.pollen.services.service.SecurityService;
import org.chorem.pollen.services.service.UserService;
import org.chorem.pollen.services.service.VoteCountingService;
import org.chorem.pollen.services.service.VoteService;
@@ -50,6 +52,8 @@
protected PollenPersistenceContext persistenceContext;
+ protected PollenSecurityContext securityContext;
+
protected Locale locale;
public void setPollenServiceConfig(PollenServiceConfig pollenServiceConfig) {
@@ -60,6 +64,10 @@
this.persistenceContext = persistenceContext;
}
+ public void setSecurityContext(PollenSecurityContext securityContext) {
+ this.securityContext = securityContext;
+ }
+
public void setLocale(Locale locale) {
this.locale = locale;
}
@@ -80,6 +88,11 @@
return now;
}
+ @Override
+ public PollenSecurityContext getSecurityContext() {
+ return securityContext;
+ }
+
public String generatePassword() {
return RandomStringUtils.randomAlphanumeric(8);
}
@@ -95,6 +108,11 @@
}
@Override
+ public ChoiceService getChoiceService() {
+ return newService(ChoiceService.class);
+ }
+
+ @Override
public CommentService getCommentService() {
return newService(CommentService.class);
}
@@ -140,6 +158,11 @@
}
@Override
+ public SecurityService getSecurityService() {
+ return newService(SecurityService.class);
+ }
+
+ @Override
public String encodePassword(String password) {
return StringUtil.encodeMD5(password);
}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,10 +1,178 @@
package org.chorem.pollen.services;
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.common.collect.ImmutableSet;
+import org.apache.commons.collections.CollectionUtils;
+import org.chorem.pollen.persistence.entity.PollenUser;
+import org.nuiton.jpa.api.JpaEntity;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.Set;
+
/**
* TODO
*
* @author tchemit <chemit(a)codelutin.com>
* @since 2.0
*/
-public class PollenSecurityContext {
+public class PollenSecurityContext implements Serializable {
+
+ private static final long serialVersionUID = 5348851531764083245L;
+
+ /**
+ * Connected user account.
+ * <p/>
+ * Can be {@code null} if user is not connected.
+ *
+ * @since 2.0
+ */
+ protected final PollenUser connectedUser;
+
+ /**
+ * Resource to edit/delete (can be null for some creation contexts).
+ *
+ * @since 2.0
+ */
+ protected ObjectSecurityContext<?> resource;
+
+ /**
+ * User roles on the poll.
+ *
+ * @since 2.0
+ */
+ protected Set<PollenUserSecurityRole> userRoles;
+
+ public static PollenSecurityContext newContext(PollenUser userAccount) {
+ PollenSecurityContext result = new PollenSecurityContext(
+ userAccount);
+ return result;
+ }
+
+ public static <E extends JpaEntity> ObjectSecurityContext<E> ObjectSecurityContext(Class<E> type,
+ String id,
+ String token) {
+ return new ObjectSecurityContext<E>(type, id, token);
+ }
+
+ public void setResource(ObjectSecurityContext<?> resource) {
+ this.resource = resource;
+ }
+
+ public void setUserRoles(Set<PollenUserSecurityRole> userRoles) {
+ this.userRoles = userRoles == null ? null : ImmutableSet.copyOf(userRoles);
+ }
+
+ public boolean isAdministrator() {
+ return userRoles != null && userRoles.contains(PollenUserSecurityRole.ADMINISTRATOR);
+ }
+
+ public boolean isCreator() {
+ return userRoles != null && userRoles.contains(PollenUserSecurityRole.CREATOR);
+ }
+
+ public boolean isVoter() {
+ return userRoles != null && userRoles.contains(PollenUserSecurityRole.VOTER);
+ }
+
+ public boolean isRestrictedVoter() {
+ return userRoles != null && userRoles.contains(PollenUserSecurityRole.RESTRICTED_VOTER);
+ }
+
+ public boolean hasNoRole() {
+ return CollectionUtils.isEmpty(userRoles);
+ }
+
+ public Set<PollenUserSecurityRole> getUserRoles() {
+ return userRoles == null ?
+ Collections.<PollenUserSecurityRole>emptySet() :
+ userRoles;
+ }
+
+ public PollenUser getPollenUser() {
+ return connectedUser;
+ }
+
+ protected PollenSecurityContext(PollenUser connectedUser) {
+ this.connectedUser = connectedUser;
+ }
+
+ public boolean isConnected() {
+ return connectedUser != null;
+ }
+
+ /**
+ * To define a security role for a given pollen user which can be
+ * identified by his user account or a accountId.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+ public enum PollenUserSecurityRole {
+
+ /**
+ * Connected user with administration rights.
+ * <p/>
+ * This role can access to everything, but can not vote.
+ */
+ ADMINISTRATOR,
+
+ /**
+ * Creator of the poll.
+ * <p/>
+ * This role can access to everything, but can not vote.
+ */
+ CREATOR,
+
+ /** A user that has voted on a poll. */
+ VOTER,
+ /**
+ * A user that was invited to a restricted poll.
+ * <p/>
+ * It might have alreay voted or not.
+ */
+ RESTRICTED_VOTER
+
+ }
+
+ public static class ObjectSecurityContext<E extends JpaEntity> implements Serializable {
+
+ private static final long serialVersionUID = 8554648867841712974L;
+
+ protected final Class<E> type;
+
+ protected final String id;
+
+ protected final String token;
+
+ public ObjectSecurityContext(Class<E> type,
+ String id,
+ String token) {
+ this.type = type;
+ this.id = id;
+ this.token = token;
+ }
+ }
}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityRealm.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityRealm.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityRealm.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,82 @@
+package org.chorem.pollen.services;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.apache.shiro.authc.AuthenticationException;
+import org.apache.shiro.authc.AuthenticationInfo;
+import org.apache.shiro.authc.AuthenticationToken;
+import org.apache.shiro.authc.SimpleAuthenticationInfo;
+import org.apache.shiro.authc.UsernamePasswordToken;
+import org.apache.shiro.authz.AuthorizationInfo;
+import org.apache.shiro.realm.AuthorizingRealm;
+import org.apache.shiro.subject.PrincipalCollection;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.chorem.pollen.services.exception.UserInvalidPasswordException;
+import org.chorem.pollen.services.service.AuthService;
+
+/**
+ * TODO
+ *
+ * http://www.slideshare.net/chunsaker/securing-rest-apis ?
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollenSecurityRealm extends AuthorizingRealm implements PollenServiceSupport {
+
+ protected PollenServiceContext serviceContext;
+
+ @Override
+ public void setServiceContext(PollenServiceContext serviceContext) {
+ this.serviceContext = serviceContext;
+ }
+
+ @Override
+ protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
+
+ principals.getPrimaryPrincipal();
+
+ return null;
+ }
+
+ @Override
+ protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
+
+ UsernamePasswordToken upToken = (UsernamePasswordToken) token;
+ String username = upToken.getUsername();
+ char[] password = upToken.getPassword();
+
+ AuthService authService = serviceContext.getAuthService();
+ try {
+ authService.login(username, new String(password));
+ } catch (EntityNotFoundException e) {
+ throw new AuthenticationException(e);
+ } catch (UserInvalidPasswordException e) {
+ throw new AuthenticationException(e);
+ }
+ SimpleAuthenticationInfo result =
+ new SimpleAuthenticationInfo(username, password, getName());
+ return result;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityRealm.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -26,11 +26,13 @@
import org.chorem.pollen.persistence.PollenPersistenceContext;
import org.chorem.pollen.services.config.PollenServiceConfig;
import org.chorem.pollen.services.service.AuthService;
+import org.chorem.pollen.services.service.ChoiceService;
import org.chorem.pollen.services.service.CommentService;
import org.chorem.pollen.services.service.EmailService;
import org.chorem.pollen.services.service.FavoriteListService;
import org.chorem.pollen.services.service.FixturesService;
import org.chorem.pollen.services.service.PollService;
+import org.chorem.pollen.services.service.SecurityService;
import org.chorem.pollen.services.service.UserService;
import org.chorem.pollen.services.service.VoteCountingService;
import org.chorem.pollen.services.service.VoteService;
@@ -49,12 +51,18 @@
Date getNow();
+ PollenSecurityContext getSecurityContext();
+
+ void setSecurityContext(PollenSecurityContext securityContext);
+
PollenPersistenceContext getPersistenceContext();
PollenServiceConfig getPollenServiceConfig();
AuthService getAuthService();
+ ChoiceService getChoiceService();
+
CommentService getCommentService();
FavoriteListService getFavoriteListService();
@@ -68,11 +76,12 @@
VoterListService getVoterListService();
VoteService getVoteService();
-
EmailService getEmailService();
FixturesService getFixturesService();
+ SecurityService getSecurityService();
+
String generatePassword();
String encodePassword(String password);
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -27,6 +27,9 @@
import com.google.common.collect.Maps;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.persistence.entity.CommentVisibility;
+import org.chorem.pollen.persistence.entity.PollType;
+import org.chorem.pollen.persistence.entity.VoteVisibility;
import org.chorem.pollen.services.PollenTechnicalException;
import org.nuiton.util.config.ApplicationConfig;
import org.nuiton.util.config.ArgumentsParserException;
@@ -81,4 +84,31 @@
boolean isDevMode = applicationConfig.getOptionAsBoolean(PollenServiceConfigOption.DEV_MODE.key);
return isDevMode;
}
+
+ public int getDefaultVoteCountingType() {
+ int result = applicationConfig.getOptionAsInt(
+ PollenServiceConfigOption.DEFAULT_VOTE_COUNTING_TYPE.key);
+ return result;
+ }
+
+ public PollType getDefaultPollType() {
+ PollType result = applicationConfig.getOption(
+ PollType.class,
+ PollenServiceConfigOption.DEFAULT_POLL_TYPE.key);
+ return result;
+ }
+
+ public VoteVisibility getDefaultVoteVisibility() {
+ VoteVisibility result = applicationConfig.getOption(
+ VoteVisibility.class,
+ PollenServiceConfigOption.DEFAULT_VOTE_VISIBILITY.key);
+ return result;
+ }
+
+ public CommentVisibility getDefaultCommentVisibility() {
+ CommentVisibility result = applicationConfig.getOption(
+ CommentVisibility.class,
+ PollenServiceConfigOption.DEFAULT_COMMENT_VISIBILITY.key);
+ return result;
+ }
}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -23,9 +23,14 @@
* #L%
*/
+import org.chorem.pollen.persistence.entity.CommentVisibility;
+import org.chorem.pollen.persistence.entity.PollType;
+import org.chorem.pollen.persistence.entity.VoteVisibility;
import org.nuiton.util.config.ConfigOptionDef;
+import static org.nuiton.i18n.I18n.n_;
+
/**
* TODO
*
@@ -34,23 +39,67 @@
*/
public enum PollenServiceConfigOption implements ConfigOptionDef {
+ /**
+ * Default poll type to use at a new poll creation.
+ *
+ * @since 2.0
+ */
+ DEFAULT_POLL_TYPE(
+ "pollen.default.pollType",
+ n_("pollen.configuration.defaultPollType"),
+ PollType.FREE.name(),
+ PollType.class),
+
+ /**
+ * Default vote counting type to use at a new poll creation.
+ *
+ * @since 2.0
+ */
+ DEFAULT_VOTE_COUNTING_TYPE(
+ "pollen.default.voteCountingType",
+ n_("pollen.configuration.defaultVoteCountingType"),
+ "0",
+ Integer.class),
+
+ /**
+ * Default poll vote visibility to use at a new poll creation.
+ *
+ * @since 2.0
+ */
+ DEFAULT_VOTE_VISIBILITY(
+ "pollen.default.pollVoteVisibility",
+ n_("pollen.configuration.defaultPollVoteVisibility"),
+ VoteVisibility.EVERYBODY.name(),
+ VoteVisibility.class),
+
+ /**
+ * Default poll comment visibility to use at a new poll creation.
+ *
+ * @since 2.0
+ */
+ DEFAULT_COMMENT_VISIBILITY(
+ "pollen.default.pollCommentVisibility",
+ n_("pollen.configuration.defaultPollCommentVisibility"),
+ CommentVisibility.EVERYBODY.name(),
+ CommentVisibility.class),
+
SMTP_HOST(
- "smtp.host",
+ "pollen.smtp.host",
"Nom d'hôte du serveur SMTP",
"", String.class),
SMTP_PORT(
- "smtp.port",
+ "pollen.smtp.port",
"Le port du serveur SMTP",
"25", Integer.class),
SMTP_FROM(
- "smtp.from",
+ "pollen.smtp.from",
"L'adresse d'expéditeur pour les mails de notifications",
"", String.class),
DEV_MODE(
- "devMode",
+ "pollen.devMode",
"Mode développement, court-circuite l'envoi de mail",
"true", Boolean.class),;
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/AbstractInvalidFormException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/AbstractInvalidFormException.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/AbstractInvalidFormException.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,47 @@
+package org.chorem.pollen.services.exception;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.common.collect.Multimap;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public abstract class AbstractInvalidFormException extends Exception{
+ private static final long serialVersionUID = 1L;
+
+ protected final Multimap<String, String> errors;
+
+
+ public AbstractInvalidFormException(Multimap<String, String> errors) {
+ this.errors = errors;
+ }
+
+ public Multimap<String, String> getErrors() {
+ return errors;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/AbstractInvalidFormException.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListImportException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListImportException.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListImportException.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,5 +1,28 @@
package org.chorem.pollen.services.exception;
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
/**
* TODO
*
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListImportException.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,5 +1,28 @@
package org.chorem.pollen.services.exception;
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
/**
* TODO
*
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,5 +1,28 @@
package org.chorem.pollen.services.exception;
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
/**
* TODO
*
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,5 +1,28 @@
package org.chorem.pollen.services.exception;
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
/**
* TODO
*
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,5 +1,28 @@
package org.chorem.pollen.services.exception;
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
/**
* TODO
*
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,5 +1,28 @@
package org.chorem.pollen.services.exception;
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
/**
* TODO
*
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidChoiceFormException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidChoiceFormException.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidChoiceFormException.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,43 @@
+package org.chorem.pollen.services.exception;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.common.collect.Multimap;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class InvalidChoiceFormException extends AbstractInvalidFormException {
+
+ private static final long serialVersionUID = 1L;
+
+
+ public InvalidChoiceFormException(Multimap<String, String> errors) {
+ super(errors);
+ }
+
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidChoiceFormException.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidPollFormException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidPollFormException.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidPollFormException.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,42 @@
+package org.chorem.pollen.services.exception;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.common.collect.Multimap;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class InvalidPollFormException extends AbstractInvalidFormException {
+
+ private static final long serialVersionUID = 1L;
+
+ public InvalidPollFormException(Multimap<String, String> errors) {
+ super(errors);
+ }
+
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidPollFormException.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidSessionTokenException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidSessionTokenException.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidSessionTokenException.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,5 +1,28 @@
package org.chorem.pollen.services.exception;
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
/**
* TODO
*
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidSessionTokenException.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/package-info.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/package-info.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/package-info.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,30 @@
+/**
+ * Package where to find all services exception.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+package org.chorem.pollen.services.exception;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/package-info.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/package-info.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/package-info.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/package-info.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -1,5 +1,5 @@
/**
- * Base Package for the pollen business service.
+ * Base package of the service layer.
*
* @author tchemit <chemit(a)codelutin.com>
* @since 2.0
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -24,6 +24,8 @@
*/
import com.google.common.base.Preconditions;
+import com.google.common.collect.Multimap;
+import org.apache.commons.lang3.StringUtils;
import org.chorem.pollen.persistence.PollenPersistenceContext;
import org.chorem.pollen.services.PollenServiceContext;
import org.chorem.pollen.services.PollenServiceSupport;
@@ -31,6 +33,7 @@
import org.chorem.pollen.services.exception.EntityNotFoundException;
import org.nuiton.jpa.api.JpaEntities;
import org.nuiton.jpa.api.JpaEntity;
+import org.nuiton.util.StringUtil;
import java.util.Date;
@@ -77,6 +80,10 @@
return serviceContext.getAuthService();
}
+ public ChoiceService getChoiceService() {
+ return serviceContext.getChoiceService();
+ }
+
protected CommentService getCommentService() {
return serviceContext.getCommentService();
}
@@ -89,6 +96,10 @@
return serviceContext.getPollService();
}
+ protected SecurityService getSecurityService() {
+ return serviceContext.getSecurityService();
+ }
+
protected UserService getUserService() {
return serviceContext.getUserService();
}
@@ -116,4 +127,27 @@
throw new EntityNotFoundException(type, entityId);
}
}
+
+ protected boolean check(Multimap<String, String> errors, String field, boolean condition, String error) {
+ boolean valid = condition;
+ if (!valid) {
+ errors.put(field, error);
+ }
+ return valid;
+ }
+
+ protected boolean checkNotNull(Multimap<String, String> errors, String field, Object value, String error) {
+ boolean valid = check(errors, field, value != null, error);
+ return valid;
+ }
+
+ protected boolean checkNotBlank(Multimap<String, String> errors, String field, String value, String error) {
+ boolean valid = check(errors, field, StringUtils.isNotBlank(value), error);
+ return valid;
+ }
+
+ protected boolean checkValidEmail(Multimap<String, String> errors, String field, String value, String error) {
+ boolean valid = check(errors, field, StringUtil.isEmail(value), error);
+ return valid;
+ }
}
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,202 @@
+package org.chorem.pollen.services.service;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+import org.chorem.pollen.persistence.dao.ChoiceJpaDao;
+import org.chorem.pollen.persistence.entity.Choice;
+import org.chorem.pollen.persistence.entity.ChoiceType;
+import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.persistence.entity.PollenPrincipal;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.chorem.pollen.services.exception.InvalidChoiceFormException;
+import org.nuiton.jpa.api.JpaEntities;
+
+import java.util.List;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class ChoiceService extends AbstractPollenService {
+
+ public List<Choice> getChoices(String pollId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
+
+ Poll poll = getPollService().getPoll(pollId);
+
+ return poll.getChoice();
+ }
+
+ public Choice getChoice(String pollId, String choiceId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
+ Preconditions.checkNotNull(choiceId);
+ Poll poll = getPollService().getPoll(pollId);
+
+ Choice result = getChoice(poll, choiceId);
+ return result;
+ }
+
+ public Choice addChoice(String pollId, Choice choice) throws EntityNotFoundException, InvalidChoiceFormException {
+ Preconditions.checkNotNull(pollId);
+ Preconditions.checkNotNull(choice);
+ checkHasNoId(choice);
+
+ Poll poll = getPollService().getPoll(pollId);
+
+ checkChoiceForm(poll.getChoiceType(), choice);
+
+ Choice result = saveChoice(poll, choice, null);
+
+ getPersistenceContext().getPollDao().merge(poll);
+ getPersistenceContext().commit();
+ return result;
+ }
+
+ public Choice editChoice(String pollId, Choice choice) throws EntityNotFoundException, InvalidChoiceFormException {
+ Preconditions.checkNotNull(choice);
+ checkHasId(choice);
+
+ Poll poll = getPollService().getPoll(pollId);
+
+ checkChoiceForm(poll.getChoiceType(), choice);
+
+ Choice result = saveChoice(poll, choice, null);
+
+ getPersistenceContext().getChoiceDao().merge(choice);
+ getPersistenceContext().commit();
+ return result;
+ }
+
+ public void deleteChoice(String pollId, String choiceId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
+ Preconditions.checkNotNull(choiceId);
+
+ Poll poll = getPollService().getPoll(pollId);
+ Choice choice = getChoice(poll, choiceId);
+
+ poll.removeChoice(choice);
+
+ getPersistenceContext().getPollDao().merge(poll);
+ getPersistenceContext().commit();
+ }
+
+ protected Choice getChoice(Poll poll, String choiceId) throws EntityNotFoundException {
+
+ Choice result = poll.getChoiceById(choiceId);
+ checkEntityExists(Choice.class, result, choiceId);
+ return result;
+ }
+
+ protected Choice saveChoice(Poll poll,
+ Choice choice,
+ PollenPrincipal principal) throws EntityNotFoundException {
+
+ ChoiceJpaDao choiceDao = getPersistenceContext().getChoiceDao();
+
+ boolean choiceExists = JpaEntities.isEntityHasId(choice);
+
+ Choice choiceToPersist;
+ if (choiceExists) {
+
+ // get existing choice
+
+ choiceToPersist = getChoice(poll, choice.getId());
+ } else {
+
+ // create a new choice
+ choiceToPersist = choiceDao.newInstance();
+
+ if (principal == null) {
+
+ // create a new principal
+
+ principal = getSecurityService().generatePrincipal();
+
+ if (choice.getCreator() == null) {
+
+ //TODO Should we use the poll creator ?
+
+ } else {
+
+ principal.setName(choice.getCreator().getName());
+ principal.setEmail(choice.getCreator().getEmail());
+ }
+ }
+ choiceToPersist.setCreator(principal);
+ poll.addChoice(choiceToPersist);
+ }
+
+ switch (poll.getChoiceType()) {
+
+ case TEXT:
+ choiceToPersist.setName(choice.getName());
+ choiceToPersist.setDescription(choice.getDescription());
+ choiceToPersist.setCreator(poll.getCreator());
+
+ break;
+
+ case DATE:
+ throw new IllegalStateException("Not implemented");
+
+ case IMAGE:
+ throw new IllegalStateException("Not implemented");
+ }
+ return choiceToPersist;
+ }
+
+ protected void checkChoiceForm(ChoiceType choiceType, Choice choice) throws InvalidChoiceFormException {
+
+ //TODO use nuiton validator ?
+ Multimap<String, String> errors = ArrayListMultimap.create();
+
+ switch (choiceType) {
+
+ case TEXT:
+
+ //TODO Should check unique choice name ?
+
+ checkNotBlank(errors,
+ "name",
+ choice.getName(),
+ "choice name can not be empty");
+
+ break;
+ case DATE:
+ throw new IllegalStateException("Not implemented");
+
+ case IMAGE:
+ throw new IllegalStateException("Not implemented");
+ }
+
+ if (!errors.isEmpty()) {
+
+ throw new InvalidChoiceFormException(errors);
+ }
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -24,14 +24,23 @@
*/
import com.google.common.base.Preconditions;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
+import org.apache.commons.lang3.StringUtils;
+import org.chorem.pollen.persistence.dao.PollJpaDao;
import org.chorem.pollen.persistence.entity.Choice;
+import org.chorem.pollen.persistence.entity.ChoiceType;
import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.persistence.entity.PollenPrincipal;
import org.chorem.pollen.persistence.entity.PollenUser;
+import org.chorem.pollen.persistence.entity.VoterList;
+import org.chorem.pollen.persistence.entity.VoterListMember;
import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.chorem.pollen.services.exception.InvalidPollFormException;
+import org.nuiton.jpa.api.JpaEntities;
import java.io.File;
-import java.util.List;
import java.util.Set;
/**
@@ -42,6 +51,10 @@
*/
public class PollService extends AbstractPollenService {
+ public Set<Poll> getPolls(String userId) throws EntityNotFoundException {
+ return Sets.newHashSet(getPersistenceContext().getPollDao().findAll());
+ }
+
public Set<Poll> getCreatedPolls(String userId) throws EntityNotFoundException {
Preconditions.checkNotNull(userId);
@@ -73,39 +86,63 @@
return result;
}
- public Poll createPoll(String userId, Poll poll) throws EntityNotFoundException {
- Preconditions.checkNotNull(userId);
- Preconditions.checkNotNull(poll);
- checkHasNoId(poll);
+ public Poll getNewPoll(String userId, ChoiceType choiceType) throws EntityNotFoundException {
+ Poll result = getPersistenceContext().getPollDao().newInstance();
+
+ result.setChoiceType(choiceType);
+
+ // -- default values -- //
+
+ result.setVoteCountingType(getPollenServiceConfig().getDefaultVoteCountingType());
+ result.setPollType(getPollenServiceConfig().getDefaultPollType());
+ result.setVoteVisibility(getPollenServiceConfig().getDefaultVoteVisibility());
+ result.setCommentVisibility(getPollenServiceConfig().getDefaultCommentVisibility());
+ result.setBeginDate(serviceContext.getNow());
+
+ // -- creator -- //
+
+ PollenPrincipal creator = getPersistenceContext().getPollenPrincipalDao().newInstance();
+ result.setCreator(creator);
+
if (userId != null) {
-
- // get user
PollenUser user = getUserService().getUser(userId);
- // link it to creator
-
+ creator.setName(user.getName());
+ creator.setEmail(user.getEmail());
}
+ return result;
+ }
- getPersistenceContext().getPollDao().persist(poll);
+ public Poll createPoll(String userId, Poll poll) throws EntityNotFoundException, InvalidPollFormException {
+ Preconditions.checkNotNull(poll);
+ checkHasNoId(poll);
+
+ checkPollForm(poll);
+
+ Poll pollToPersist = savePoll(userId, poll);
+
+ getPersistenceContext().getPollDao().persist(pollToPersist);
getPersistenceContext().commit();
- return poll;
+ return pollToPersist;
}
- public Poll editPoll(Poll poll) throws EntityNotFoundException {
+ public Poll editPoll(Poll poll) throws EntityNotFoundException, InvalidPollFormException {
Preconditions.checkNotNull(poll);
checkHasId(poll);
- getPoll(poll.getId());
+ checkPollForm(poll);
- getPersistenceContext().getPollDao().merge(poll);
+ Poll toSave = savePoll(null, poll);
+
+ getPersistenceContext().getPollDao().merge(toSave);
getPersistenceContext().commit();
- Poll result = getPoll(poll.getId());
- return result;
+ return toSave;
}
+
public void deletePoll(String pollId) throws EntityNotFoundException {
Preconditions.checkNotNull(pollId);
@@ -113,6 +150,11 @@
getPersistenceContext().getPollDao().remove(poll);
getPersistenceContext().commit();
+
+ if (poll.getCreator().getEmail() != null) {
+
+ //TODO Notify ?
+ }
}
public Poll clonePoll(String pollId) throws EntityNotFoundException {
@@ -140,66 +182,183 @@
return null;
}
- public List<Choice> getChoices(String pollId) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
+ protected Poll savePoll(String userId, Poll poll) throws EntityNotFoundException {
- Poll poll = getPoll(pollId);
+ boolean pollExists = JpaEntities.isEntityHasId(poll);
- return poll.getChoice();
- }
+ Poll toSave;
- public Choice getChoice(String choiceId) throws EntityNotFoundException {
- Preconditions.checkNotNull(choiceId);
+ if (pollExists) {
+ toSave = getPoll(poll.getId());
- Choice result = getPersistenceContext().getChoiceDao().findById(choiceId);
- checkEntityExists(Choice.class, result, choiceId);
- return result;
- }
+ } else {
+ PollJpaDao dao = getPersistenceContext().getPollDao();
- public Choice addChoice(String pollId, Choice choice) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
- Preconditions.checkNotNull(choice);
- checkHasNoId(choice);
+ toSave = dao.newInstance();
- Poll poll = getPoll(pollId);
+ PollenPrincipal creatorToPersist =
+ getSecurityService().generatePrincipal();
- poll.addChoice(choice);
+ toSave.setCreator(creatorToPersist);
+ }
- getPersistenceContext().getPollDao().merge(poll);
+ // -- creator -- //
- getPersistenceContext().commit();
- Choice result = getChoice(choice.getId());
- return result;
- }
+ if (userId != null) {
- public Choice editChoice(Choice choice) throws EntityNotFoundException {
- Preconditions.checkNotNull(choice);
- checkHasId(choice);
+ // link to connected user
+ PollenUser user = getUserService().getUser(userId);
+ toSave.getCreator().setPollenUser(user);
+ }
- getChoice(choice.getId());
+ toSave.getCreator().setName(poll.getCreator().getName());
+ toSave.getCreator().setEmail(poll.getCreator().getEmail());
- getPersistenceContext().getChoiceDao().merge(choice);
- getPersistenceContext().commit();
+ // -- simple properties -- //
- Choice result = getChoice(choice.getId());
- return result;
- }
+ toSave.setVoteCountingType(poll.getVoteCountingType());
+ toSave.setVoteVisibility(poll.getVoteVisibility());
+ toSave.setCommentVisibility(poll.getCommentVisibility());
+ toSave.setChoiceType(poll.getChoiceType());
- public void deleteChoice(String pollId, String choiceId) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
- Preconditions.checkNotNull(choiceId);
+ toSave.setAnonymousVoteAllowed(poll.isAnonymousVoteAllowed());
+ toSave.setChoiceAddAllowed(poll.isChoiceAddAllowed());
+ toSave.setBeginChoiceDate(poll.getBeginChoiceDate());
+ toSave.setBeginDate(poll.getBeginDate());
- Poll poll = getPoll(pollId);
- Choice choice = getChoice(choiceId);
+ toSave.setContinuousResults(poll.isContinuousResults());
+ toSave.setDescription(poll.getDescription());
+ toSave.setEndDate(poll.getEndDate());
+ toSave.setEndChoiceDate(poll.getEndChoiceDate());
+ toSave.setPollType(poll.getPollType());
+ toSave.setMaxChoiceNumber(poll.getMaxChoiceNumber());
+ toSave.setTitle(poll.getTitle());
- poll.removeChoice(choice);
+ // -- choice -- //
- getPersistenceContext().getPollDao().merge(poll);
+ for (Choice choice : poll.getChoice()) {
- getPersistenceContext().commit();
+ getChoiceService().saveChoice(toSave, choice, toSave.getCreator());
+ }
+
+ // -- voting list -- //
+
+ if (!poll.isVoterListEmpty()) {
+
+ for (VoterList voterList : poll.getVoterList()) {
+
+ getVoterListService().saveVoterList(toSave, voterList);
+ }
+ }
+
+ return toSave;
}
- public Set<Poll> getPolls(String userId) throws EntityNotFoundException {
- return Sets.newHashSet(getPersistenceContext().getPollDao().findAll());
+ protected void checkPollForm(Poll poll) throws InvalidPollFormException {
+
+ //TODO use nuiton validator ?
+ Multimap<String, String> errors = ArrayListMultimap.create();
+
+ checkNotNull(errors, "pollType", poll.getPollType(), "pollType can not be null");
+ checkNotNull(errors, "choiceType", poll.getChoiceType(), "choiceType can not be null");
+ checkNotNull(errors, "commentVisibility", poll.getCommentVisibility(), "commentVisibility can not be null");
+ checkNotNull(errors, "voteVisibility", poll.getVoteVisibility(), "voteVisibility can not be null");
+ checkNotNull(errors, "voteCountingType", poll.getVoteCountingType(), "voteCountingType can not be null");
+
+ checkNotBlank(errors, "title", poll.getTitle(), "title can not be empty");
+ check(errors, "choice", poll.isChoiceEmpty(), "need at least one choice");
+
+ if (poll.isFreePoll()) {
+ check(errors, "pollType", poll.isVoterListEmpty(), "can't have voterList with free poll");
+ } else {
+ check(errors, "pollType", !poll.isVoterListEmpty(), "must have voterList with not free poll");
+ }
+
+ if (!poll.isChoiceEmpty()) {
+
+ // validate choices
+
+ int choiceIndex = 0;
+
+ for (Choice choice : poll.getChoice()) {
+
+ String choiceField = "choice[" + (choiceIndex++) + "]";
+
+ switch (poll.getChoiceType()) {
+
+ case TEXT:
+
+ checkNotBlank(errors,
+ choiceField + ".name",
+ choice.getName(),
+ "choice name can not be empty");
+
+ break;
+ case DATE:
+ throw new IllegalStateException("Not implemented");
+
+ case IMAGE:
+ throw new IllegalStateException("Not implemented");
+ }
+ }
+ }
+
+ if (!poll.isVoterListEmpty()) {
+
+ Set<String> voterListNames = Sets.newHashSet();
+
+ // validate voter lists
+
+ int voterListIndex = 0;
+
+ for (VoterList voterList : poll.getVoterList()) {
+
+ String voterListField = "voterList[" + (voterListIndex++) + "]";
+
+ checkNotBlank(errors, voterListField + ".name", voterList.getName(), "voterList name can not be empty");
+ check(errors, voterListField + ".weight", voterList.getWeight() > 0, "voterList weight must be greater than 0");
+ check(errors, voterListField + ".member", !voterList.isVoterListMemberEmpty(), "voterList must contains at least one member");
+
+ boolean added = voterListNames.add(voterList.getName());
+
+ check(errors, voterListField, added, "voterList name already used");
+
+ Set<String> voterListMemberNames = Sets.newHashSet();
+ Set<String> voterListMemberEmails = Sets.newHashSet();
+
+ int voterListMemberIndex = 0;
+
+ for (VoterListMember voterListMember : voterList.getVoterListMember()) {
+
+ String voterListMemberField = voterListField + ".member[" + (voterListMemberIndex++) + "]";
+
+ String voterListMemberName = voterListMember.getName();
+ boolean nameNotNull = checkNotBlank(errors, voterListMemberField + ".name", voterListMemberName, "member name can not be empty");
+
+ if (nameNotNull) {
+ boolean nameAdded = voterListMemberNames.add(voterListMemberName);
+ check(errors, voterListMemberField + ".name", nameAdded, "member name already used in this list");
+ }
+
+ String voterListMemberEmail = voterListMember.getEmail();
+
+ boolean emailNotNull = checkNotBlank(errors, voterListMemberField + ".email", voterListMemberEmail, "member email can not be empty");
+
+ if (emailNotNull) {
+
+ voterListMemberEmail = StringUtils.lowerCase(voterListMemberEmail);
+
+ checkValidEmail(errors, voterListMemberField + ".email", voterListMemberEmail, "member email is not valid");
+ boolean emailAdded = voterListMemberEmails.add(voterListMemberEmail);
+ check(errors, voterListMemberField + ".email", emailAdded, "member email already used in this list");
+ }
+ }
+ }
+ }
+
+ if (!errors.isEmpty()) {
+
+ throw new InvalidPollFormException(errors);
+ }
}
}
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,45 @@
+package org.chorem.pollen.services.service;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.chorem.pollen.persistence.dao.PollenPrincipalJpaDao;
+import org.chorem.pollen.persistence.entity.PollenPrincipal;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class SecurityService extends AbstractPollenService {
+
+ public PollenPrincipal generatePrincipal() {
+ PollenPrincipalJpaDao pollenPrincipalDao = getPersistenceContext().getPollenPrincipalDao();
+ PollenPrincipal principal = pollenPrincipalDao.newInstance();
+ principal.setToken(serviceContext.generateToken());
+ principal.setCreationDate(serviceContext.getNow());
+ return principal;
+
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java 2013-06-14 15:12:49 UTC (rev 3829)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -24,6 +24,7 @@
*/
import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.StringUtils;
import org.chorem.pollen.persistence.dao.VoterListJpaDao;
import org.chorem.pollen.persistence.dao.VoterListMemberJpaDao;
import org.chorem.pollen.persistence.entity.FavoriteList;
@@ -32,6 +33,7 @@
import org.chorem.pollen.persistence.entity.VoterList;
import org.chorem.pollen.persistence.entity.VoterListMember;
import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.nuiton.jpa.api.JpaEntities;
import java.util.List;
import java.util.Set;
@@ -78,7 +80,7 @@
return result;
}
- public List<VoterList> getVoterLists(String pollId) throws EntityNotFoundException{
+ public List<VoterList> getVoterLists(String pollId) throws EntityNotFoundException {
Preconditions.checkNotNull(pollId);
Poll poll = getPollService().getPoll(pollId);
@@ -87,7 +89,7 @@
return result;
}
- public VoterList getVoterList(String voterListId) throws EntityNotFoundException{
+ public VoterList getVoterList(String pollId, String voterListId) throws EntityNotFoundException {
Preconditions.checkNotNull(voterListId);
VoterList result = getPersistenceContext().getVoterListDao().findById(voterListId);
@@ -96,40 +98,39 @@
return result;
}
- public VoterList addVoterList(String pollId, VoterList voterList) throws EntityNotFoundException{
+ public VoterList addVoterList(String pollId, VoterList voterList) throws EntityNotFoundException {
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(voterList);
checkHasNoId(voterList);
Poll poll = getPollService().getPoll(pollId);
+ VoterList result = saveVoterList(poll, voterList);
- poll.addVoterList(voterList);
-
getPersistenceContext().getPollDao().merge(poll);
getPersistenceContext().commit();
- VoterList result = getVoterList(voterList.getId());
return result;
}
- public VoterList editVoterList(VoterList voterList) throws EntityNotFoundException{
+ public VoterList editVoterList(String pollId, VoterList voterList) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(voterList);
checkHasId(voterList);
- getVoterList(voterList.getId());
+ Poll poll = getPollService().getPoll(pollId);
+ VoterList result = saveVoterList(poll, voterList);
getPersistenceContext().getVoterListDao().merge(voterList);
getPersistenceContext().commit();
- VoterList result = getVoterList(voterList.getId());
return result;
}
- public void deleteVoterList(String pollId, String voterListId) throws EntityNotFoundException{
+ public void deleteVoterList(String pollId, String voterListId) throws EntityNotFoundException {
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(voterListId);
Poll poll = getPollService().getPoll(pollId);
- VoterList voterList = getVoterList(voterListId);
+ VoterList voterList = getVoterList(pollId, voterListId);
poll.removeVoterList(voterList);
@@ -138,58 +139,69 @@
getPersistenceContext().commit();
}
- public Set<VoterListMember> getMembers(String voterListId) throws EntityNotFoundException{
+ public Set<VoterListMember> getMembers(String pollId, String voterListId) throws EntityNotFoundException {
Preconditions.checkNotNull(voterListId);
- VoterList voterList = getVoterList(voterListId);
+ VoterList voterList = getVoterList(pollId, voterListId);
Set<VoterListMember> result = voterList.getVoterListMember();
return result;
}
- public VoterListMember getMember(String memberId) throws EntityNotFoundException{
+ public VoterListMember getMember(String pollId, String voterListId, String memberId) throws EntityNotFoundException {
Preconditions.checkNotNull(memberId);
- VoterListMember result = getPersistenceContext().getVoterListMemberDao().findById(memberId);
+ VoterList voterList = getVoterList(pollId, voterListId);
+
+ VoterListMember result = getMember(voterList, memberId);
checkEntityExists(VoterListMember.class, result, memberId);
return result;
}
- public VoterListMember addMember(String voterListId, VoterListMember member)throws EntityNotFoundException {
+
+ public VoterListMember getMember(VoterList voterList, String memberId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(memberId);
+
+ VoterListMember result = voterList.getVoterListMemberById(memberId);
+ checkEntityExists(VoterListMember.class, result, memberId);
+ return result;
+ }
+
+ public VoterListMember addMember(String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException {
Preconditions.checkNotNull(voterListId);
Preconditions.checkNotNull(member);
checkHasNoId(member);
- VoterList voterList = getVoterList(voterListId);
+ VoterList voterList = getVoterList(pollId, voterListId);
- voterList.addVoterListMember(member);
+ VoterListMember result = saveVoterListMember(voterList, member);
+
getPersistenceContext().getVoterListDao().merge(voterList);
-
getPersistenceContext().commit();
- VoterListMember result = getMember(member.getId());
return result;
}
- public VoterListMember editMember(VoterListMember member) throws EntityNotFoundException{
+ public VoterListMember editMember(String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException {
+ Preconditions.checkNotNull(voterListId);
Preconditions.checkNotNull(member);
checkHasId(member);
- getMember(member.getId());
+ VoterList voterList = getVoterList(pollId, voterListId);
+ VoterListMember result = saveVoterListMember(voterList, member);
+
getPersistenceContext().getVoterListMemberDao().merge(member);
-
getPersistenceContext().commit();
- VoterListMember result = getMember(member.getId());
return result;
}
- public void deleteMember(String voterListId, String memberId) throws EntityNotFoundException{
+ public void deleteMember(String pollId, String voterListId, String memberId) throws EntityNotFoundException {
Preconditions.checkNotNull(voterListId);
Preconditions.checkNotNull(memberId);
- VoterList voterList = getVoterList(voterListId);
+ VoterList voterList = getVoterList(pollId, voterListId);
- VoterListMember member = getMember(memberId);
+ VoterListMember member = getMember(voterList, memberId);
voterList.removeVoterListMember(member);
getPersistenceContext().getVoterListDao().merge(voterList);
@@ -197,4 +209,62 @@
getPersistenceContext().commit();
}
+ protected VoterList saveVoterList(Poll poll, VoterList voterList) throws EntityNotFoundException {
+
+
+ boolean voterListExists = JpaEntities.isEntityHasId(voterList);
+
+ VoterList voterListToPersist;
+
+ if (voterListExists) {
+
+ voterListToPersist =
+ getVoterListService().getVoterList(poll.getId(), voterList.getId());
+ } else {
+ VoterListJpaDao voterListDao =
+ getPersistenceContext().getVoterListDao();
+ voterListToPersist = voterListDao.newInstance();
+
+ poll.addVoterList(voterListToPersist);
+ }
+
+ voterListToPersist.setName(voterList.getName());
+ voterListToPersist.setWeight(voterList.getWeight());
+
+ for (VoterListMember voterListMember : voterList.getVoterListMember()) {
+
+ saveVoterListMember(voterListToPersist, voterListMember);
+ }
+
+ return voterListToPersist;
+ }
+
+ protected VoterListMember saveVoterListMember(VoterList voterList,
+ VoterListMember voterListMember) throws EntityNotFoundException {
+
+ boolean voterListMemberExists =
+ JpaEntities.isEntityHasId(voterListMember);
+
+ VoterListMember voterListMemberToPersist;
+
+ if (voterListMemberExists) {
+
+ voterListMemberToPersist =
+ getMember(voterList, voterListMember.getId());
+ } else {
+
+ VoterListMemberJpaDao voterListMemberDao =
+ getPersistenceContext().getVoterListMemberDao();
+
+ voterListMemberToPersist = voterListMemberDao.newInstance();
+
+ voterList.addVoterListMember(voterListMemberToPersist);
+ }
+
+ voterListMemberToPersist.setName(voterListMember.getName());
+ voterListMemberToPersist.setEmail(StringUtils.lowerCase(voterListMember.getEmail()));
+ voterListMemberToPersist.setWeight(voterListMember.getWeight());
+
+ return voterListMemberToPersist;
+ }
}
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/package-info.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/package-info.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/package-info.java 2013-06-15 10:58:03 UTC (rev 3830)
@@ -0,0 +1,30 @@
+/**
+ * Package where to find all services.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+package org.chorem.pollen.services.service;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/package-info.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: trunk/pollen-ui-js/src/main/webapp/img/glyphicons_050_link.png
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Property changes on: trunk/pollen-ui-js/src/main/webapp/js/libs/date.js
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Property changes on: trunk/pollen-ui-js/src/main/webapp/js/libs/jquery.scrollto.js
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
r3829 - in trunk/pollen-ui-js/src/main/webapp: . bundle css js/controls js/libs views
by kmorinï¼ users.chorem.org 14 Jun '13
by kmorinï¼ users.chorem.org 14 Jun '13
14 Jun '13
Author: kmorin
Date: 2013-06-14 17:12:49 +0200 (Fri, 14 Jun 2013)
New Revision: 3829
Url: http://chorem.org/projects/pollen/repository/revisions/3829
Log:
i18n + layout + start adding results in the table
Added:
trunk/pollen-ui-js/src/main/webapp/bundle/
trunk/pollen-ui-js/src/main/webapp/bundle/Messages.properties
trunk/pollen-ui-js/src/main/webapp/js/libs/jquery.i18n.properties-min-1.0.9.js
Modified:
trunk/pollen-ui-js/src/main/webapp/css/style.css
trunk/pollen-ui-js/src/main/webapp/index.html
trunk/pollen-ui-js/src/main/webapp/js/controls/poll_form.js
trunk/pollen-ui-js/src/main/webapp/js/controls/poll_summary.js
trunk/pollen-ui-js/src/main/webapp/js/controls/vote.js
trunk/pollen-ui-js/src/main/webapp/views/menu.ejs
trunk/pollen-ui-js/src/main/webapp/views/poll_form.ejs
trunk/pollen-ui-js/src/main/webapp/views/summary.ejs
trunk/pollen-ui-js/src/main/webapp/views/vote.ejs
Added: trunk/pollen-ui-js/src/main/webapp/bundle/Messages.properties
===================================================================
--- trunk/pollen-ui-js/src/main/webapp/bundle/Messages.properties (rev 0)
+++ trunk/pollen-ui-js/src/main/webapp/bundle/Messages.properties 2013-06-14 15:12:49 UTC (rev 3829)
@@ -0,0 +1,61 @@
+#common
+pollen.common.cancel=Annuler
+pollen.common.validate=Valider
+pollen.common.format.date=dd/MM/yyyy
+pollen.common.format.dateTime=dd/MM/yyyy HH:mm
+pollen.common.format.time=HH:mm
+pollen.common.date.from=Ã partir du {0}
+pollen.common.date.fromTo=du {0} au {1}
+pollen.common.date.to=jusqu'au {0}
+
+#poll attributes
+pollen.poll.description.label=Description
+pollen.poll.description.placeholder=Description
+pollen.poll.title.label=Titre
+pollen.poll.title.placeholder=Titre
+
+#choice attributes
+pollen.choice.description.label=Description
+pollen.choice.description.placeholder=Description
+pollen.choice.name.label=Titre
+pollen.choice.name.placeholder=Titre
+
+#menu
+pollen.menu.home=Accueil
+pollen.menu.polls=Sondages
+
+#poll creation form
+pollen.poll.form.create.button.save=Créer le sondage
+pollen.poll.form.create.field.title.label=Titre
+pollen.poll.form.create.field.title.placeholder=Titre
+pollen.poll.form.create.title=Création de sondage
+
+#poll summary
+pollen.poll.summary.title=Sondage \'{0}\'
+pollen.poll.summary.linkToVote=Lien pour participer :
+pollen.poll.summary.part.export.title=Export
+pollen.poll.summary.part.export.item.export=Exporter
+pollen.poll.summary.part.poll.title=Sondage
+pollen.poll.summary.part.poll.item.close=Clore
+pollen.poll.summary.part.poll.item.delete=Supprimer
+pollen.poll.summary.part.poll.item.duplicate=Dupliquer
+pollen.poll.summary.part.poll.item.edit=Modifier
+pollen.poll.summary.part.poll.item.history=Historique
+pollen.poll.summary.part.poll.item.notification=Notification
+pollen.poll.summary.part.voters.title=Participants
+pollen.poll.summary.part.voters.item.invite=Inviter des participants
+pollen.poll.summary.part.voters.item.contact=Contacter les invités
+
+#vote
+pollen.vote.poll.author=Sondage lancé par {0}
+pollen.vote.poll.closed.alert=<strong>Ce sondage est clos.</strong> Vous ne pouvez plus voter.
+pollen.vote.choices.list.title=Propositions
+pollen.vote.choices.list.button.addChoice=Ajouter un choix
+pollen.vote.votes.list.title=Votes
+pollen.vote.votes.list.header.voter=Votant
+pollen.vote.form.add.field.userName.placeholder=Votre nom
+pollen.vote.form.add.button.vote=Voter
+pollen.vote.comments.list.title=Commentaires
+pollen.vote.comments.list.button.addComment=Ajouter un commentaire
+pollen.vote.comments.add.field.userName.placeholder=Votre nom
+pollen.vote.comments.add.field.message.placeholder=Votre commentaire
\ No newline at end of file
Modified: trunk/pollen-ui-js/src/main/webapp/css/style.css
===================================================================
--- trunk/pollen-ui-js/src/main/webapp/css/style.css 2013-06-14 13:10:08 UTC (rev 3828)
+++ trunk/pollen-ui-js/src/main/webapp/css/style.css 2013-06-14 15:12:49 UTC (rev 3829)
@@ -31,17 +31,22 @@
background-position: -313px -119px;
}
-#content >div {
- display: none;
+.list.alternate-colors > div {
+ padding: 10px 20px;
}
-#choicesSummary {
- padding: 20px;
- margin-bottom: 30px;
- background-color: rgb(238, 238, 238);
- border-radius: 6px 6px 6px 6px;
+.list.alternate-colors > .even {
+ background-color: rgb(245, 245, 245);
}
+.list.alternate-colors .footer {
+ color: rgb(150, 150, 150);
+}
+
+#content > div {
+ display: none;
+}
+
#voteForm .choice {
background-position: center;
background-repeat: no-repeat;
Modified: trunk/pollen-ui-js/src/main/webapp/index.html
===================================================================
--- trunk/pollen-ui-js/src/main/webapp/index.html 2013-06-14 13:10:08 UTC (rev 3828)
+++ trunk/pollen-ui-js/src/main/webapp/index.html 2013-06-14 15:12:49 UTC (rev 3829)
@@ -28,7 +28,6 @@
</div>
-
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.js"></script>
<script src="js/libs/bootstrap.min.js"></script>
<script src="js/libs/can.jquery.js"></script>
@@ -38,6 +37,7 @@
<script src="js/libs/can.observe.delegate.js"></script>
<script src="js/libs/jquery.scrollto.js"></script>
<script src="js/libs/date.js"></script>
+ <script src="js/libs/jquery.i18n.properties-min-1.0.9.js"></script>
<script src="js/models/polls.js"></script>
<script src="js/models/comments.js"></script>
@@ -50,15 +50,30 @@
<script type="text/javascript">
- var menu = new Menu('#menu');
+ // This will initialize the plugin
+ // and show two dialog boxes: one with the text "Olá World"
+ // and other with the text "Good morning John!"
+ $.i18n.properties({
+ name:'Messages',
+ path:'bundle/',
+ mode:'both',
+ language:'fr_FR',
+ callback: function() {
- var pf = new PollForm('#pollForm');
- var summary = new PollSummary('#pollSummary');
- var vote = new PollVote('#vote');
+ var menu = new Menu('#menu');
- can.route(':type/:action');
- can.route(':type/:id/:action');
+ var pf = new PollForm('#pollForm');
+ var summary = new PollSummary('#pollSummary');
+ var vote = new PollVote('#vote');
+ can.route(':type/:action');
+ can.route(':type/:id/:action');
+
+ }
+ });
+
+
+
</script>
</body>
Modified: trunk/pollen-ui-js/src/main/webapp/js/controls/poll_form.js
===================================================================
--- trunk/pollen-ui-js/src/main/webapp/js/controls/poll_form.js 2013-06-14 13:10:08 UTC (rev 3828)
+++ trunk/pollen-ui-js/src/main/webapp/js/controls/poll_form.js 2013-06-14 15:12:49 UTC (rev 3829)
@@ -13,18 +13,6 @@
},
- '{can.route} change': function(data, ev, prop, how, newVal, oldVal ) {
- if (prop === "type" && (how === "set" || how === "add")) {
- if (newVal != "poll") {
- this.element.hide();
- }
- } else if (prop === "action" && (how === "set" || how === "add")) {
- if (newVal != "edit") {
- this.element.hide();
- }
- }
- },
-
':type/:action route': function(data) {
if (data.type === "poll" && data.action === "edit") {
this.editPoll(new Poll());
@@ -74,10 +62,10 @@
},
editPoll: function(poll) {
- console.log("edit poll " + poll.id + " : " + poll.description);
this.options.poll = poll;
this.on();
this.refreshForm();
+ this.element.siblings().hide();
this.element.show();
},
Modified: trunk/pollen-ui-js/src/main/webapp/js/controls/poll_summary.js
===================================================================
--- trunk/pollen-ui-js/src/main/webapp/js/controls/poll_summary.js 2013-06-14 13:10:08 UTC (rev 3828)
+++ trunk/pollen-ui-js/src/main/webapp/js/controls/poll_summary.js 2013-06-14 15:12:49 UTC (rev 3829)
@@ -1,17 +1,5 @@
var PollSummary = can.Control({
- '{can.route} change': function(data, ev, prop, how, newVal, oldVal ) {
- if (prop === "type" && (how === "set" || how === "add")) {
- if (newVal != "poll") {
- this.element.hide();
- }
- } else if (prop === "action" && (how === "set" || how === "add")) {
- if (newVal != "summary") {
- this.element.hide();
- }
- }
- },
-
':type/:id/:action route': function(data) {
if (data.type === "poll" && data.action === "summary") {
var self = this;
@@ -27,6 +15,7 @@
this.element.html(can.view('views/summary.ejs', {
poll: poll
}));
+ this.element.siblings().hide();
this.element.show();
}
Modified: trunk/pollen-ui-js/src/main/webapp/js/controls/vote.js
===================================================================
--- trunk/pollen-ui-js/src/main/webapp/js/controls/vote.js 2013-06-14 13:10:08 UTC (rev 3828)
+++ trunk/pollen-ui-js/src/main/webapp/js/controls/vote.js 2013-06-14 15:12:49 UTC (rev 3829)
@@ -2,18 +2,6 @@
// route
- '{can.route} change': function(data, ev, prop, how, newVal, oldVal ) {
- if (prop === "type" && (how === "set" || how === "add")) {
- if (newVal != "poll") {
- this.element.hide();
- }
- } else if (prop === "action" && (how === "set" || how === "add")) {
- if (newVal != "vote") {
- this.element.hide();
- }
- }
- },
-
':type/:id/:action route': function(data) {
if (data.type === "poll" && data.action === "vote") {
var self = this;
@@ -80,7 +68,11 @@
var author = form.find("[name='author']").val();
var message = form.find("[name='message']").val();
- var comment = new Comment({ author: author, text: message });
+ var comment = new Comment({
+ author: author,
+ text: message,
+ postDate: new Date().getTime()
+ });
var self = this;
comment.save({ pollId: this.options.poll.id },
function(data) {
@@ -116,6 +108,7 @@
comments: comments,
votes: votes
}));
+ this.element.siblings().hide();
this.element.show();
},
Added: trunk/pollen-ui-js/src/main/webapp/js/libs/jquery.i18n.properties-min-1.0.9.js
===================================================================
--- trunk/pollen-ui-js/src/main/webapp/js/libs/jquery.i18n.properties-min-1.0.9.js (rev 0)
+++ trunk/pollen-ui-js/src/main/webapp/js/libs/jquery.i18n.properties-min-1.0.9.js 2013-06-14 15:12:49 UTC (rev 3829)
@@ -0,0 +1,9 @@
+(function(k){function n(c,a){k.ajax({url:c,async:!1,cache:a.cache,contentType:"text/plain;charset="+a.encoding,dataType:"text",success:function(b){r(b,a.mode)}})}function r(c,a){for(var b="",e=c.split(/\n/),d=/(\{\d+\})/g,q=/\{(\d+)\}/g,m=/(\\u.{4})/ig,f=0;f<e.length;f++)if(e[f]=e[f].replace(/^\s\s*/,"").replace(/\s\s*$/,""),e[f].length>0&&e[f].match("^#")!="#"){var g=e[f].split("=");if(g.length>0){for(var o=unescape(g[0]).replace(/^\s\s*/,"").replace(/\s\s*$/,""),h=g.length==1?"":g[1];h.match(/\\$/)==
+"\\";)h=h.substring(0,h.length-1),h+=e[++f].replace(/\s\s*$/,"");for(var l=2;l<g.length;l++)h+="="+g[l];h=h.replace(/^\s\s*/,"").replace(/\s\s*$/,"");if(a=="map"||a=="both"){if(g=h.match(m))for(l=0;l<g.length;l++)h=h.replace(g[l],s(g[l]));k.i18n.map[o]=h}if(a=="vars"||a=="both")if(h=h.replace(/"/g,'\\"'),t(o),d.test(h)){for(var g=h.split(d),l=!0,j="",n=[],p=0;p<g.length;p++)if(d.test(g[p])&&(n.length==0||n.indexOf(g[p])==-1))l||(j+=","),j+=g[p].replace(q,"v$1"),n.push(g[p]),l=!1;b+=o+"=function("+
+j+"){";o='"'+h.replace(q,'"+v$1+"')+'"';b+="return "+o+";};"}else b+=o+'="'+h+'";'}}eval(b)}function t(c){if(/\./.test(c))for(var a="",c=c.split(/\./),b=0;b<c.length;b++)b>0&&(a+="."),a+=c[b],eval("typeof "+a+' == "undefined"')&&eval(a+"={};")}function s(c){var a=[],c=parseInt(c.substr(2),16);c>=0&&c<Math.pow(2,16)&&a.push(c);for(var c="",b=0;b<a.length;++b)c+=String.fromCharCode(a[b]);return c}k.i18n={};k.i18n.map={};k.i18n.properties=function(c){c=k.extend({name:"Messages",language:"",path:"",mode:"vars",
+cache:!1,encoding:"UTF-8",callback:null},c);if(c.language===null||c.language=="")c.language=k.i18n.browserLang();if(c.language===null)c.language="";var a=c.name&&c.name.constructor==Array?c.name:[c.name];for(i=0;i<a.length;i++)n(c.path+a[i]+".properties",c),c.language.length>=2&&n(c.path+a[i]+"_"+c.language.substring(0,2)+".properties",c),c.language.length>=5&&n(c.path+a[i]+"_"+c.language.substring(0,5)+".properties",c);c.callback&&c.callback()};k.i18n.prop=function(c){var a=k.i18n.map[c];if(a==null)return"["+
+c+"]";var b;if(typeof a=="string"){for(b=0;(b=a.indexOf("\\",b))!=-1;)a=a[b+1]=="t"?a.substring(0,b)+"\t"+a.substring(b++ +2):a[b+1]=="r"?a.substring(0,b)+"\r"+a.substring(b++ +2):a[b+1]=="n"?a.substring(0,b)+"\n"+a.substring(b++ +2):a[b+1]=="f"?a.substring(0,b)+"\u000c"+a.substring(b++ +2):a[b+1]=="\\"?a.substring(0,b)+"\\"+a.substring(b++ +2):a.substring(0,b)+a.substring(b+1);var e=[],d,j;for(b=0;b<a.length;)if(a[b]=="'")if(b==a.length-1)a=a.substring(0,b);else if(a[b+1]=="'")a=a.substring(0,b)+
+a.substring(++b);else{for(d=b+2;(d=a.indexOf("'",d))!=-1;)if(d==a.length-1||a[d+1]!="'"){a=a.substring(0,b)+a.substring(b+1,d)+a.substring(d+1);b=d-1;break}else a=a.substring(0,d)+a.substring(++d);d==-1&&(a=a.substring(0,b)+a.substring(b+1))}else if(a[b]=="{")if(d=a.indexOf("}",b+1),d==-1)b++;else if(j=parseInt(a.substring(b+1,d)),!isNaN(j)&&j>=0){var m=a.substring(0,b);m!=""&&e.push(m);e.push(j);b=0;a=a.substring(d+1)}else b=d+1;else b++;a!=""&&e.push(a);a=e;k.i18n.map[c]=e}if(a.length==0)return"";
+if(a.lengh==1&&typeof a[0]=="string")return a[0];m="";for(b=0;b<a.length;b++)m+=typeof a[b]=="string"?a[b]:a[b]+1<arguments.length?arguments[a[b]+1]:"{"+a[b]+"}";return m};k.i18n.browserLang=function(){var c=navigator.language||navigator.userLanguage,c=c.toLowerCase();c.length>3&&(c=c.substring(0,3)+c.substring(3).toUpperCase());return c};var j;if(!j)j=function(c,a,b){if(Object.prototype.toString.call(a)!=="[object RegExp]")return typeof j._nativeSplit=="undefined"?c.split(a,b):j._nativeSplit.call(c,
+a,b);var e=[],d=0,k=(a.ignoreCase?"i":"")+(a.multiline?"m":"")+(a.sticky?"y":""),a=RegExp(a.source,k+"g"),m,f,g;c+="";j._compliantExecNpcg||(m=RegExp("^"+a.source+"$(?!\\s)",k));if(b===void 0||+b<0)b=Infinity;else if(b=Math.floor(+b),!b)return[];for(;f=a.exec(c);){k=f.index+f[0].length;if(k>d&&(e.push(c.slice(d,f.index)),!j._compliantExecNpcg&&f.length>1&&f[0].replace(m,function(){for(var a=1;a<arguments.length-2;a++)arguments[a]===void 0&&(f[a]=void 0)}),f.length>1&&f.index<c.length&&Array.prototype.push.apply(e,
+f.slice(1)),g=f[0].length,d=k,e.length>=b))break;a.lastIndex===f.index&&a.lastIndex++}d===c.length?(g||!a.test(""))&&e.push(""):e.push(c.slice(d));return e.length>b?e.slice(0,b):e},j._compliantExecNpcg=/()??/.exec("")[1]===void 0,j._nativeSplit=String.prototype.split;String.prototype.split=function(c,a){return j(this,c,a)}})(jQuery);
\ No newline at end of file
Modified: trunk/pollen-ui-js/src/main/webapp/views/menu.ejs
===================================================================
--- trunk/pollen-ui-js/src/main/webapp/views/menu.ejs 2013-06-14 13:10:08 UTC (rev 3828)
+++ trunk/pollen-ui-js/src/main/webapp/views/menu.ejs 2013-06-14 15:12:49 UTC (rev 3829)
@@ -1,2 +1,2 @@
-<li><%== can.route.link('Sondage', { type: 'poll', action: 'edit' }) %></li>
-<li><%== can.route.link('Autre', { type: 'other', action: 'donothing' }) %></li>
\ No newline at end of file
+<li><%== can.route.link(pollen.menu.home, {}) %></li>
+<li><%== can.route.link(pollen.menu.polls, { type: 'poll', action: 'edit' }) %></li>
\ No newline at end of file
Modified: trunk/pollen-ui-js/src/main/webapp/views/poll_form.ejs
===================================================================
--- trunk/pollen-ui-js/src/main/webapp/views/poll_form.ejs 2013-06-14 13:10:08 UTC (rev 3828)
+++ trunk/pollen-ui-js/src/main/webapp/views/poll_form.ejs 2013-06-14 15:12:49 UTC (rev 3829)
@@ -1,19 +1,19 @@
-<h1>Création de sondage</h1>
+<h1><%= pollen.poll.form.create.title %></h1>
<form id='pollCreationForm' class="form-horizontal">
<div class="control-group">
- <label class="control-label" for="pollCreationFormTitle">Title</label>
+ <label class="control-label" for="pollCreationFormTitle"><%= pollen.poll.title.label %></label>
<div class="controls">
- <input type='text' name='title' id='pollCreationFormTitle' placeholder='title'
+ <input type='text' name='title' id='pollCreationFormTitle' placeholder='<%= pollen.poll.title.placeholder %>'
<%= poll.attr("title") ? "value='" + poll.attr("title") + "'" : "class='empty'" %>/>
</div>
</div>
<div class="control-group">
- <label class="control-label" for='pollCreationFormDescription'>Description</label>
+ <label class="control-label" for='pollCreationFormDescription'><%= pollen.poll.description.label %></label>
<div class="controls">
- <textarea id='pollCreationFormDescription' name='description'
+ <textarea id='pollCreationFormDescription' name='description' placeholder="<%= pollen.poll.description.placeholder %>"
<% if (!poll.attr("description")) {%>
class='empty'
<% } %>><%= poll.attr('description') %></textarea>
@@ -21,7 +21,7 @@
</div>
<div class="form-actions">
- <a href="javascript://" class="btn btn-primary save">Save</a>
+ <a href="javascript://" class="btn btn-primary save"><%= pollen.poll.form.create.button.save %></a>
<a href="javascript://" class="btn btn-primary create">New poll</a>
<a href="javascript://" data-id="1" class="btn btn">Edit poll 1</a>
<a href="javascript://" data-id="2" class="btn btn">Edit poll 2</a>
Modified: trunk/pollen-ui-js/src/main/webapp/views/summary.ejs
===================================================================
--- trunk/pollen-ui-js/src/main/webapp/views/summary.ejs 2013-06-14 13:10:08 UTC (rev 3828)
+++ trunk/pollen-ui-js/src/main/webapp/views/summary.ejs 2013-06-14 15:12:49 UTC (rev 3829)
@@ -1,36 +1,36 @@
-<h1>Sondage <%= poll.title %></h1>
+<h1><%= pollen.poll.summary.title(poll.title) %></h1>
<div class="control-group">
- <label class="control-label" for='pollSummaryLink'>Lien pour participer</label>
+ <label class="control-label" for='pollSummaryLink'><%= pollen.poll.summary.linkToVote %></label>
<input type='url' id='pollSummaryLink' value="<%== window.location.href.split('#')[0] + can.route.url({ type: 'poll', action: 'vote', id: poll.id }) %>"/>
<%== can.route.link('<i class="icon-link bigger link"></i>', {type: 'poll', action: 'vote', id: poll.id}) %>
</div>
<div class='row-fluid'>
<div class='span4'>
- <h2>Sondage</h2>
+ <h2><%= pollen.poll.summary.part.poll.title %></h2>
<ul class='noListStyle'>
- <li><%== can.route.link('<i class="icon-ok"></i>Clore', {}) %></li>
- <li><%== can.route.link('<i class="icon-pencil"></i>Modifer', {type: 'poll', action: 'edit', id: poll.id}) %></li>
- <li><%== can.route.link('<i class="icon-envelope"></i>Notification', {}) %></li>
- <li><%== can.route.link('<i class="icon-time"></i>Historique', {}) %></li>
- <li><%== can.route.link('<i class="icon-clone"></i>Créer un duplicata', {}) %></li>
- <li><%== can.route.link('<i class="icon-trash"></i>Effacer', {}) %></li>
+ <li><%== can.route.link('<i class="icon-ok"></i>' + pollen.poll.summary.part.poll.item.close, {}) %></li>
+ <li><%== can.route.link('<i class="icon-pencil"></i>' + pollen.poll.summary.part.poll.item.edit, {type: 'poll', action: 'edit', id: poll.id}) %></li>
+ <li><%== can.route.link('<i class="icon-envelope"></i>' + pollen.poll.summary.part.poll.item.notification, {}) %></li>
+ <li><%== can.route.link('<i class="icon-time"></i>' + pollen.poll.summary.part.poll.item.history, {}) %></li>
+ <li><%== can.route.link('<i class="icon-clone"></i>' + pollen.poll.summary.part.poll.item.duplicate, {}) %></li>
+ <li><%== can.route.link('<i class="icon-trash"></i>' + pollen.poll.summary.part.poll.item.delete, {}) %></li>
</ul>
</div>
<div class='span4'>
- <h2>Participants</h2>
+ <h2><%= pollen.poll.summary.part.voters.title %></h2>
<ul class='noListStyle'>
- <li><%== can.route.link('<i class="icon-user"></i>Inviter des participants', {}) %></li>
- <li><%== can.route.link('<i class="icon-envelope"></i>Contacter les invités', {}) %></li>
+ <li><%== can.route.link('<i class="icon-user"></i>' + pollen.poll.summary.part.voters.item.invite, {}) %></li>
+ <li><%== can.route.link('<i class="icon-envelope"></i>' + pollen.poll.summary.part.voters.item.contact, {}) %></li>
</ul>
</div>
<div class='span4'>
- <h2>Export</h2>
+ <h2><%= pollen.poll.summary.part.export.title %></h2>
<ul class='noListStyle'>
- <li><i class="icon-upload"></i>clore</li>
+ <li><%== can.route.link('<i class="icon-upload"></i>'+ pollen.poll.summary.part.export.item.export, {}) %></li>
</ul>
</div>
</div>
\ No newline at end of file
Modified: trunk/pollen-ui-js/src/main/webapp/views/vote.ejs
===================================================================
--- trunk/pollen-ui-js/src/main/webapp/views/vote.ejs 2013-06-14 13:10:08 UTC (rev 3828)
+++ trunk/pollen-ui-js/src/main/webapp/views/vote.ejs 2013-06-14 15:12:49 UTC (rev 3829)
@@ -3,18 +3,18 @@
<h1><%= poll.attr('title') %></h1>
<p>
- Sondage lancé par <%= poll.attr('creatorName') %>
+ <%= pollen.vote.poll.author(poll.attr('creatorName')) %>
<!-- number of votes -->
| <a id="voteSummary" class='link'><i class='icon-user'></i> <%= votes.attr('length') %></a>
<!-- number of comments-->
| <a id="commentSummary" class='link'><i class='icon-comment'></i> <%= comments.attr('length') %></a>
<!-- poll dates -->
<% if (poll.attr('beginDate') && poll.attr('endDate')) { %>
- | <i class='icon-time'></i> du <%= new Date(poll.attr('beginDate')).toString("dd/MM/yyyy") %> au <%= new Date(poll.attr('endDate')).toString("dd/MM/yyyy") %>
+ | <i class='icon-time'></i> <%= pollen.common.date.fromTo(new Date(poll.attr('beginDate')).toString(pollen.common.format.date), new Date(poll.attr('endDate')).toString(pollen.common.format.date)) %>
<% } else if (poll.attr('beginDate')) { %>
- | <i class='icon-time'></i> Ã partir du <%= new Date(poll.attr('beginDate')).toString("dd/MM/yyyy") %>
+ | <i class='icon-time'></i> <%= pollen.common.date.from(new Date(poll.attr('beginDate')).toString(pollen.common.format.date)) %>
<% } else if (poll.attr('endDate')) { %>
- | <i class='icon-time'></i> jusqu'au <%= new Date(poll.attr('endDate')).toString("dd/MM/yyyy") %>
+ | <i class='icon-time'></i> <%= pollen.common.date.to(new Date(poll.attr('endDate')).toString(pollen.common.format.date)) %>
<% } %>
</p>
@@ -26,14 +26,14 @@
<% if (poll.attr('closed')) { %>
<div class="alert fade in">
<button type="button" class="close" data-dismiss="alert">×</button>
- <strong>Ce sondage est clos.</strong> Vous ne pouvez plus voter.
+ <%== pollen.vote.poll.closed.alert %>
</div>
<% } %>
<!-- list of the choices -->
-<div id='choicesSummary'>
+<div class='well'>
- <h3>Propositions</h3>
+ <h3><%= pollen.vote.choices.list.title %></h3>
<ol>
<% poll.choices.each(function(choice) { %>
@@ -45,14 +45,14 @@
<!-- link to show/hide the new choice form -->
<button class="collapsed btn btn-link" data-toggle="collapse" data-target="#addChoiceForm">
- Ajouter un choix <i class="icon-collapse"></i>
+ <%= pollen.vote.choices.list.button.addChoice %> <i class="icon-collapse"></i>
</button>
<!-- form to add a new choice to the poll -->
<form id="addChoiceForm" class="collapse">
- <input type="text" name="name" placeholder="Nom"/>
- <textarea name="description" placeholder="Description"></textarea>
- <button type="submit" class="btn btn-primary">Valider</button>
+ <input type="text" name="name" placeholder="<%= pollen.choice.name.placeholder %>"/>
+ <textarea name="description" placeholder="<%= pollen.choice.description.placeholder %>"></textarea>
+ <button type="submit" class="btn btn-primary"><%= pollen.common.validate %></button>
</form>
<% } %>
</div>
@@ -60,14 +60,17 @@
<!-- table of the votes -->
<form id="voteForm">
+ <h2><%= pollen.vote.votes.list.title %></h2>
+
<table id="voteTable" class="table table-bordered table-striped">
- <caption>Votes</caption>
+ <% var results = new can.Observe.List(new Array(poll.attr('choices.length'))); %>
<thead>
<tr>
- <th>Votant</th>
- <% poll.choices.each(function(choice) { %>
+ <th><%= pollen.vote.votes.list.header.voter %></th>
+ <% poll.choices.each(function(choice, i) { %>
<th data-container='body' data-placement='top' title='<%= choice.attr("description") %>'>
<%= choice.attr('name') %>
+ <% results[i] = 0 %>
</th>
<% }); %>
</tr>
@@ -81,22 +84,34 @@
var voteChoice = vote.voteToChoices.attr(i);
if (voteChoice == null) {
%>
- <td class='choice voteBeforeChoice'></td>
+ <td class='choice voteBeforeChoice'></td>
<% } else { %>
- <td class='choice <%= voteChoice.attr("voteValue") ? "selected" : "notSelected" %>'>
- <%= voteChoice.attr("voteValue") ? "OK" : "" %>
- </td>
- <%
+ <td class='choice <%= voteChoice.attr("voteValue") ? "selected" : "notSelected" %>'>
+ <%= voteChoice.attr("voteValue") ? "OK" : "" %>
+ </td>
+ <%
+ if (voteChoice.attr("voteValue")) {
+ // todo 20130614 kmorin check why if we do a results.attr(i, results[i] +1) ==> too much recursion
+ results[i] = results[i] + 1
+ }
}
});
%>
</tr>
- <%
- });
- if (!poll.attr('closed')) {
- %>
+ <% }); %>
+
+ <tr>
+ <td>Resultats</td>
+ <% poll.choices.each(function(choice, i) { %>
+ <td class='result'>
+ <%= results.attr(i) %>
+ </td>
+ <% }); %>
+ </tr>
+
+ <% if (!poll.attr('closed')) { %>
<tr>
- <td><input name="userName" type='text'/></td>
+ <td><input name="userName" type='text' placeholder='<%= pollen.vote.form.add.field.userName.placeholder %>'/></td>
<%poll.choices.each(function(choice, i) { %>
<td><input name="<%= i %>" type='checkbox'/></td>
<% }); %>
@@ -107,7 +122,7 @@
<% if (!poll.attr('closed')) { %>
<div class="form-actions">
- <button type="submit" id="voteButton" class="btn btn-primary">Voter</button>
+ <button type="submit" id="voteButton" class="btn btn-primary"><%= pollen.vote.form.add.button.vote %></button>
</div>
<% } %>
@@ -115,27 +130,30 @@
<!-- Comments -->
<div id="comments">
- <h2>Commentaires</h2>
+ <h2><%= pollen.vote.comments.list.title %></h2>
<button class="collapsed btn btn-link" data-toggle="collapse" data-target="#addCommentForm">
- Ajouter un commentaire <i class="icon-collapse"></i>
+ <%= pollen.vote.comments.list.button.addComment %> <i class="icon-collapse"></i>
</button>
<form id="addCommentForm" class="collapse">
- <input type="text" name="author" placeholder="Votre nom"/>
- <textarea name="message" placeholder="Entrez votre message"></textarea>
+ <input type="text" name="author" placeholder="<%= pollen.vote.comments.add.field.userName.placeholder %>"/>
+ <textarea name="message" placeholder="<%= pollen.vote.comments.add.field.message.placeholder %>"></textarea>
<button type="submit" class="btn btn-primary">Valider</button>
</form>
- <dl>
- <% comments.each(function(comment) { %>
+ <div class='list alternate-colors'>
+ <% comments.each(function(comment, i) { %>
- <dt><%= comment.attr('author') %> - <em><%= new Date(comment.attr('postDate')).toString("dd/MM/yyyy hh:mm") %></em></dt>
- <dd>
- <%= comment.attr('text') %>
- </dd>
- </div>
+ <div class="<%= i % 2 ? 'odd' : 'even' %>">
+ <p>
+ <%= comment.attr('text') %>
+ </p>
+ <div class='footer'>
+ <small><%= comment.attr('author') %> | <%= new Date(comment.attr('postDate')).toString(pollen.common.format.dateTime) %></small>
+ </div>
+ </div>
<% }); %>
- </dl>
+ </div>
</div>
\ No newline at end of file
1
0
Author: tchemit
Date: 2013-06-14 15:10:08 +0200 (Fri, 14 Jun 2013)
New Revision: 3828
Url: http://chorem.org/projects/pollen/repository/revisions/3828
Log:
go back to zargo model
Modified:
branches/pollen-1.5.x/pom.xml
Modified: branches/pollen-1.5.x/pom.xml
===================================================================
--- branches/pollen-1.5.x/pom.xml 2013-06-14 09:24:20 UTC (rev 3827)
+++ branches/pollen-1.5.x/pom.xml 2013-06-14 13:10:08 UTC (rev 3828)
@@ -495,8 +495,8 @@
<artifactId>eugene-maven-plugin</artifactId>
<version>${eugenePluginVersion}</version>
<configuration>
- <!--<inputs>zargo</inputs>-->
- <inputs>yamlmodel</inputs>
+ <inputs>zargo</inputs>
+ <!--inputs>yamlmodel</inputs-->
<resolver>org.nuiton.util.FasterCachedResourceResolver</resolver>
</configuration>
<dependencies>
1
0
Author: tchemit
Date: 2013-06-14 11:24:20 +0200 (Fri, 14 Jun 2013)
New Revision: 3827
Url: http://chorem.org/projects/pollen/repository/revisions/3827
Log:
remove old branches
Removed:
branches/pollen-1.2.3-1.2.x/
branches/pollen-1.2.5-1.2.x/
branches/pollen-2.0-beta-1/
1
0
Author: tchemit
Date: 2013-06-14 11:22:03 +0200 (Fri, 14 Jun 2013)
New Revision: 3826
Url: http://chorem.org/projects/pollen/repository/revisions/3826
Log:
remove legacy modules
Removed:
trunk/pollen-persistence-legacy/
trunk/pollen-services-legacy/
trunk/pollen-ui-struts2/
1
0
Author: tchemit
Date: 2013-06-14 11:19:15 +0200 (Fri, 14 Jun 2013)
New Revision: 3825
Url: http://chorem.org/projects/pollen/repository/revisions/3825
Log:
Branch pollen-2.0 is the *new* trunk
Added:
trunk/
Removed:
branches/pollen-2.0/
Property changes on: trunk
___________________________________________________________________
Added: svn:ignore
+ target
nbactions.xml
.settings
.classpath
.project
*.ipr
*.iws
*.iml
.idea
atlassian-ide-plugin.xml
Added: svn:mergeinfo
+
1
0
Author: tchemit
Date: 2013-06-14 11:18:12 +0200 (Fri, 14 Jun 2013)
New Revision: 3824
Url: http://chorem.org/projects/pollen/repository/revisions/3824
Log:
Trunk goes to a branche (you never know...)
Added:
branches/pollen-1.5.x/
Removed:
trunk/
Property changes on: branches/pollen-1.5.x
___________________________________________________________________
Added: svn:ignore
+ target
nbactions.xml
.settings
.classpath
.project
*.ipr
*.iws
*.iml
.idea
atlassian-ide-plugin.xml
Added: svn:mergeinfo
+
1
0
Author: tchemit
Date: 2013-06-14 11:12:59 +0200 (Fri, 14 Jun 2013)
New Revision: 3823
Url: http://chorem.org/projects/pollen/repository/revisions/3823
Log:
- prepare new module layout
- implements FavoriteList service
- begin of security implementation
Added:
branches/pollen-2.0/pollen-rest-api/src/it/
branches/pollen-2.0/pollen-rest-api/src/it/pom/
branches/pollen-2.0/pollen-rest-api/src/it/pom/pom.xml
branches/pollen-2.0/pollen-rest-api/src/it/user/
branches/pollen-2.0/pollen-rest-api/src/it/user/README.txt
branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenSecurityFilter.java
branches/pollen-2.0/pollen-services-legacy/
branches/pollen-2.0/pollen-services/
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollResult.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenFixtures.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenTechnicalException.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/config/
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListImportException.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidSessionTokenException.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/package-info.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/AuthService.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/EmailService.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/UserService.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingService.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java
branches/pollen-2.0/pollen-services/src/main/resources/fixtures.yaml
branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java
branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/UserServiceTest.java
Removed:
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/BookmarkableDao.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoteDao.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoterListDao.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoterListMemberDao.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/AbstractJpaPollenEntity.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/BookmarkableEntity.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Choice.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/ChoiceEntity.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Comment.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/CommentEntity.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/JpaPollenEntity.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollEntity.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenEntities.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Vote.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/VoteEntity.java
branches/pollen-2.0/pollen-persistence/src/test/java/org/chorem/pollen/persistence/entity/PollenEntitiesTest.java
branches/pollen-2.0/pollen-service/
branches/pollen-2.0/pollen-services/
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/AbstractPollenService.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/AuthService.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/CommentService.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/DefaultPollenServiceContext.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/EmailService.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/FavoriteListService.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/FixturesService.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollResult.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollService.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenFixtures.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenServiceContext.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenServiceSupport.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenTechnicalException.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/UserService.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/VoteCountingService.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/VoteService.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/VoterListService.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/config/
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/exception/
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/package-info.java
branches/pollen-2.0/pollen-services/src/main/resources/fixtures.yaml
branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java
branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/UserServiceTest.java
Modified:
branches/pollen-2.0/pollen-persistence-legacy/pom.xml
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/ChoiceDao.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/ChoiceJpaDao.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/CommentDao.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/CommentJpaDao.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollDao.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollJpaDao.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollenUserJpaDao.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/SessionTokenJpaDao.java
branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoteJpaDao.java
branches/pollen-2.0/pollen-persistence/src/main/xmi/pollen.properties
branches/pollen-2.0/pollen-rest-api/pom.xml
branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenApplicationContext.java
branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenRender.java
branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceContextFilter.java
branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceListener.java
branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServices.java
branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/AuthService.java
branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/CommentService.java
branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/FavoriteListService.java
branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollService.java
branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/UserService.java
branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteCountingService.java
branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteService.java
branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoterListService.java
branches/pollen-2.0/pollen-rest-api/src/main/resources/mapping
branches/pollen-2.0/pollen-rest-api/src/main/webapp/WEB-INF/web.xml
branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java
branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/FakePollenServiceContext.java
branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/UserServiceTest.java
branches/pollen-2.0/pollen-rest-api/src/test/resources/pollen.properties
branches/pollen-2.0/pollen-services/pom.xml
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/config/package-info.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/EntityNotFoundException.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserEmailAlreadyUsedException.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserInvalidEmailActiviationTokenException.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserInvalidPasswordException.java
branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserLoginAlreadyUsedException.java
branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/FakePollenServiceContext.java
branches/pollen-2.0/pom.xml
Modified: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenEntityIdFactory.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,10 +1,14 @@
package org.chorem.pollen.persistence;
import com.google.common.base.Preconditions;
-import org.chorem.pollen.persistence.entity.PollenEntities;
+import org.apache.commons.codec.DecoderException;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.binary.Hex;
import org.nuiton.jpa.api.JpaEntity;
import org.nuiton.jpa.api.JpaEntityIdFactory;
+import java.util.UUID;
+
/**
* TODO
*
@@ -13,10 +17,29 @@
*/
public class PollenEntityIdFactory implements JpaEntityIdFactory {
+ public static String generateId() {
+
+ // generate uuid
+ String uuid = UUID.randomUUID().toString().replaceAll("-", "");
+
+ // decode in hexa base
+ byte[] decode;
+ try {
+ decode = Hex.decodeHex(uuid.toCharArray());
+ } catch (DecoderException e) {
+ // can't happen!
+ throw new RuntimeException(e);
+ }
+
+ // encode it in base64 (url safe version)
+ String result = Base64.encodeBase64URLSafeString(decode);
+ return result;
+ }
+
@Override
public String newId(JpaEntity entity) {
Preconditions.checkNotNull(entity);
- return entity.getClass().getName() + '#' + PollenEntities.generateId();
+ return generateId();
}
}
Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/BookmarkableDao.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/BookmarkableDao.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/BookmarkableDao.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,37 +0,0 @@
-package org.chorem.pollen.persistence.dao;
-
-/*
- * #%L
- * Pollen :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.nuiton.jpa.api.JpaEntity;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public interface BookmarkableDao<E extends JpaEntity> {
-
- E findBySimpleId(String simpleId);
-}
Modified: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/ChoiceDao.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/ChoiceDao.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/ChoiceDao.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -23,13 +23,11 @@
* #L%
*/
-import org.chorem.pollen.persistence.entity.Choice;
-
/**
* TODO
*
* @author tchemit <chemit(a)codelutin.com>
* @since 2.0
*/
-public interface ChoiceDao extends BookmarkableDao<Choice> {
+public interface ChoiceDao {
}
Modified: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/ChoiceJpaDao.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/ChoiceJpaDao.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/ChoiceJpaDao.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -23,9 +23,6 @@
* #L%
*/
-import org.chorem.pollen.persistence.entity.Choice;
-import org.chorem.pollen.persistence.entity.PollenEntities;
-
import javax.persistence.EntityManager;
public class ChoiceJpaDao extends AbstractChoiceJpaDao {
@@ -34,10 +31,4 @@
super(entityManager);
}
- @Override
- public Choice findBySimpleId(String simpleId) {
- String id = PollenEntities.getEntityId(getEntityClass(), simpleId);
- return findById(id);
- }
-
} //ChoiceJpaDao
Modified: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/CommentDao.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/CommentDao.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/CommentDao.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -23,13 +23,11 @@
* #L%
*/
-import org.chorem.pollen.persistence.entity.Comment;
-
/**
* TODO
*
* @author tchemit <chemit(a)codelutin.com>
* @since 2.0
*/
-public interface CommentDao extends BookmarkableDao<Comment> {
+public interface CommentDao {
}
Modified: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/CommentJpaDao.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/CommentJpaDao.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/CommentJpaDao.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -23,9 +23,6 @@
* #L%
*/
-import org.chorem.pollen.persistence.entity.Comment;
-import org.chorem.pollen.persistence.entity.PollenEntities;
-
import javax.persistence.EntityManager;
public class CommentJpaDao extends AbstractCommentJpaDao {
@@ -34,10 +31,4 @@
super(entityManager);
}
- @Override
- public Comment findBySimpleId(String simpleId) {
- String id = PollenEntities.getEntityId(getEntityClass(), simpleId);
- return findById(id);
- }
-
} //CommentJpaDao
Modified: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollDao.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollDao.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollDao.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -33,7 +33,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.0
*/
-public interface PollDao extends BookmarkableDao<Poll> {
+public interface PollDao {
Set<Poll> findAllCreated(String userId);
Modified: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollJpaDao.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollJpaDao.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollJpaDao.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -25,7 +25,6 @@
import com.google.common.collect.Sets;
import org.chorem.pollen.persistence.entity.Poll;
-import org.chorem.pollen.persistence.entity.PollenEntities;
import javax.persistence.EntityManager;
import java.util.Set;
@@ -60,10 +59,5 @@
return Sets.newHashSet();
}
- @Override
- public Poll findBySimpleId(String simpleId) {
- String id = PollenEntities.getEntityId(getEntityClass(), simpleId);
- return findById(id);
- }
} //PollJpaDao
Modified: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollenUserJpaDao.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollenUserJpaDao.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/PollenUserJpaDao.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -26,7 +26,6 @@
import org.chorem.pollen.persistence.entity.PollenUser;
import javax.persistence.EntityManager;
-import javax.persistence.TypedQuery;
/**
* TODO
@@ -41,23 +40,6 @@
}
@Override
- public PollenUser findByLogin(String login) {
- TypedQuery<PollenUser> query =
- createQuery(PollenUser.PROPERTY_LOGIN, login);
- PollenUser result = findUniqueOrNull(query);
-
- return result;
- }
-
- @Override
- public PollenUser findByEmail(String email) {
- TypedQuery<PollenUser> query =
- createQuery(PollenUser.PROPERTY_EMAIL, email);
- PollenUser result = findUniqueOrNull(query);
- return result;
- }
-
- @Override
public boolean loginExists(String login) {
PollenUser user = findByLogin(login);
return user != null;
Modified: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/SessionTokenJpaDao.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/SessionTokenJpaDao.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/SessionTokenJpaDao.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -23,10 +23,7 @@
* #L%
*/
-import org.chorem.pollen.persistence.entity.SessionToken;
-
import javax.persistence.EntityManager;
-import javax.persistence.TypedQuery;
/**
* TODO
@@ -40,11 +37,4 @@
super(entityManager);
}
- @Override
- public SessionToken findByToken(String token) {
- TypedQuery<SessionToken> query = createQuery(SessionToken.PROPERTY_TOKEN, token);
- SessionToken result = findUniqueOrNull(query);
- return result;
- }
-
} //SessionTokenJpaDao
Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoteDao.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoteDao.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoteDao.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,35 +0,0 @@
-package org.chorem.pollen.persistence.dao;
-
-/*
- * #%L
- * Pollen :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.chorem.pollen.persistence.entity.Vote;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public interface VoteDao extends BookmarkableDao<Vote> {
-}
Modified: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoteJpaDao.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoteJpaDao.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoteJpaDao.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -23,9 +23,6 @@
* #L%
*/
-import org.chorem.pollen.persistence.entity.PollenEntities;
-import org.chorem.pollen.persistence.entity.Vote;
-
import javax.persistence.EntityManager;
public class VoteJpaDao extends AbstractVoteJpaDao {
@@ -34,10 +31,4 @@
super(entityManager);
}
- @Override
- public Vote findBySimpleId(String simpleId) {
- String id = PollenEntities.getEntityId(getEntityClass(), simpleId);
- return findById(id);
- }
-
} //VoteJpaDao
Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoterListDao.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoterListDao.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoterListDao.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,33 +0,0 @@
-package org.chorem.pollen.persistence.dao;
-
-/*
- * #%L
- * Pollen :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public interface VoterListDao {
-}
Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoterListMemberDao.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoterListMemberDao.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/dao/VoterListMemberDao.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,34 +0,0 @@
-package org.chorem.pollen.persistence.dao;
-
-/*
- * #%L
- * Pollen :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public interface VoterListMemberDao {
-
-}
Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/AbstractJpaPollenEntity.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/AbstractJpaPollenEntity.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/AbstractJpaPollenEntity.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,44 +0,0 @@
-package org.chorem.pollen.persistence.entity;
-
-/*
- * #%L
- * Pollen :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.nuiton.jpa.api.AbstractJpaEntity;
-
-import java.io.Serializable;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public abstract class AbstractJpaPollenEntity extends AbstractJpaEntity implements JpaPollenEntity {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public String getSimpleId() {
- return PollenEntities.getSimpleId(this);
- }
-}
Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/BookmarkableEntity.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/BookmarkableEntity.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/BookmarkableEntity.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,41 +0,0 @@
-package org.chorem.pollen.persistence.entity;
-
-/*
- * #%L
- * Pollen :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public interface BookmarkableEntity {
-
- String getId();
-
- String getSimpleId();
-
-// PollenUser getPollenUser();
-
-// void setPollenUser(PollenUser pollenUser);
-}
Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Choice.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Choice.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Choice.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,43 +0,0 @@
-package org.chorem.pollen.persistence.entity;
-
-/*
- * #%L
- * Pollen :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import javax.persistence.Entity;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-@Entity
-public class Choice extends AbstractJpaChoice {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public String getSimpleId() {
- return PollenEntities.getSimpleId(this);
- }
-} //Choice
Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/ChoiceEntity.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/ChoiceEntity.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/ChoiceEntity.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,33 +0,0 @@
-package org.chorem.pollen.persistence.entity;
-
-/*
- * #%L
- * Pollen :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public interface ChoiceEntity extends BookmarkableEntity {
-}
Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Comment.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Comment.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Comment.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,43 +0,0 @@
-package org.chorem.pollen.persistence.entity;
-
-/*
- * #%L
- * Pollen :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import javax.persistence.Entity;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-@Entity
-public class Comment extends AbstractJpaComment {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public String getSimpleId() {
- return PollenEntities.getSimpleId(this);
- }
-} //Comment
Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/CommentEntity.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/CommentEntity.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/CommentEntity.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,33 +0,0 @@
-package org.chorem.pollen.persistence.entity;
-
-/*
- * #%L
- * Pollen :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public interface CommentEntity extends BookmarkableEntity {
-}
Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/JpaPollenEntity.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/JpaPollenEntity.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/JpaPollenEntity.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,38 +0,0 @@
-package org.chorem.pollen.persistence.entity;
-
-/*
- * #%L
- * Pollen :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.nuiton.jpa.api.JpaEntity;
-
-import java.io.Serializable;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public interface JpaPollenEntity extends JpaEntity, Serializable {
- String getSimpleId();
-}
Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,43 +0,0 @@
-package org.chorem.pollen.persistence.entity;
-
-/*
- * #%L
- * Pollen :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import javax.persistence.Entity;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-@Entity
-public class Poll extends AbstractJpaPoll {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public String getSimpleId() {
- return PollenEntities.getSimpleId(this);
- }
-} //Poll
Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollEntity.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollEntity.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollEntity.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,33 +0,0 @@
-package org.chorem.pollen.persistence.entity;
-
-/*
- * #%L
- * Pollen :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public interface PollEntity extends BookmarkableEntity {
-}
Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenEntities.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenEntities.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollenEntities.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,80 +0,0 @@
-package org.chorem.pollen.persistence.entity;
-
-/*
- * #%L
- * Pollen :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.apache.commons.codec.DecoderException;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.codec.binary.Hex;
-import org.apache.commons.lang3.StringUtils;
-import org.nuiton.jpa.api.JpaEntity;
-
-import java.util.UUID;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class PollenEntities {
-
- public static boolean isSimpleId(String id) {
- return !id.contains("#");
- }
-
- public static String getSimpleId(JpaEntity e) {
- String result = e.getId();
- if (result != null) {
- result = StringUtils.substringAfter(result, "#");
- }
- return result;
- }
-
- public static <E extends JpaEntity> String getEntityId(Class<E> type,
- String simpleId) {
- StringBuilder result = new StringBuilder(type.getName());
- result.append('#');
- result.append(simpleId);
- return result.toString();
- }
-
- public static String generateId() {
- // get uuid
- String uuid = UUID.randomUUID().toString().replaceAll("-", "");
-
- // decode in hexa decimal (reduce by 2 size of it)
- byte[] decode;
- try {
- decode = Hex.decodeHex(uuid.toCharArray());
- } catch (DecoderException e) {
- // can't happen!
- throw new RuntimeException(e);
- }
-
- // encode it in base64 (url safe version)
- String result = Base64.encodeBase64URLSafeString(decode);
- return result;
- }
-
-}
Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Vote.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Vote.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Vote.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,43 +0,0 @@
-package org.chorem.pollen.persistence.entity;
-
-/*
- * #%L
- * Pollen :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import javax.persistence.Entity;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-@Entity
-public class Vote extends AbstractJpaVote {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public String getSimpleId() {
- return PollenEntities.getSimpleId(this);
- }
-} //Vote
Deleted: branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/VoteEntity.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/VoteEntity.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/VoteEntity.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,33 +0,0 @@
-package org.chorem.pollen.persistence.entity;
-
-/*
- * #%L
- * Pollen :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public interface VoteEntity extends BookmarkableEntity {
-}
Modified: branches/pollen-2.0/pollen-persistence/src/main/xmi/pollen.properties
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/main/xmi/pollen.properties 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/main/xmi/pollen.properties 2013-06-14 09:12:59 UTC (rev 3823)
@@ -22,8 +22,9 @@
###m
model.tagValue.idFactory=true
model.tagValue.generatePropertyChangeListeners=true
+model.tagValue.generateVisitors=true
model.tagvalue.version=2.0
-model.tagvalue.entitySuperClass=org.chorem.pollen.persistence.entity.AbstractJpaPollenEntity
+#model.tagvalue.entitySuperClass=org.chorem.pollen.persistence.entity.AbstractJpaPollenEntity
org.chorem.pollen.persistence.entity.Poll.attribute.choice.stereotype=ordered
org.chorem.pollen.persistence.entity.Poll.attribute.voterList.stereotype=ordered
Deleted: branches/pollen-2.0/pollen-persistence/src/test/java/org/chorem/pollen/persistence/entity/PollenEntitiesTest.java
===================================================================
--- branches/pollen-2.0/pollen-persistence/src/test/java/org/chorem/pollen/persistence/entity/PollenEntitiesTest.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence/src/test/java/org/chorem/pollen/persistence/entity/PollenEntitiesTest.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,57 +0,0 @@
-package org.chorem.pollen.persistence.entity;
-
-/*
- * #%L
- * Pollen :: Persistence
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.chorem.pollen.persistence.PollenEntityIdFactory;
-import org.junit.Assert;
-import org.junit.Test;
-import org.nuiton.jpa.api.JpaEntityIdFactoryResolver;
-
-/**
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class PollenEntitiesTest {
-
- @Test
- public void getSimpleId() {
-
- JpaEntityIdFactoryResolver.setFactory(new PollenEntityIdFactory());
-
- try {
- Poll poll = new Poll();
- poll.prepersist();
-
- String id = poll.getId();
- Assert.assertNotNull(id);
-
- String simpleId = PollenEntities.getSimpleId(poll);
- String id2 = PollenEntities.getEntityId(Poll.class, simpleId);
-
- Assert.assertEquals(id, id2);
- } finally {
- JpaEntityIdFactoryResolver.setFactory(null);
- }
- }
-}
Modified: branches/pollen-2.0/pollen-persistence-legacy/pom.xml
===================================================================
--- branches/pollen-2.0/pollen-persistence-legacy/pom.xml 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-persistence-legacy/pom.xml 2013-06-14 09:12:59 UTC (rev 3823)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.chorem</groupId>
<artifactId>pollen</artifactId>
- <version>1.5.5-SNAPSHOT</version>
+ <version>2.0-SNAPSHOT</version>
</parent>
<groupId>org.chorem.pollen</groupId>
Modified: branches/pollen-2.0/pollen-rest-api/pom.xml
===================================================================
--- branches/pollen-2.0/pollen-rest-api/pom.xml 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-rest-api/pom.xml 2013-06-14 09:12:59 UTC (rev 3823)
@@ -27,7 +27,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>pollen-service</artifactId>
+ <artifactId>pollen-services</artifactId>
<version>${project.version}</version>
</dependency>
@@ -41,11 +41,6 @@
<artifactId>webmotion-unittest</artifactId>
</dependency>
- <!--dependency>
- <groupId>org.debux.webmotion</groupId>
- <artifactId>webmotion-extra-jpa</artifactId>
- </dependency-->
-
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
@@ -208,18 +203,7 @@
</resource>
</resources>
</build>
- <properties>
-
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-jcl</artifactId>
- <scope>runtime</scope>
- </dependency>
- </dependencies>
</profile>
-
</profiles>
</project>
Added: branches/pollen-2.0/pollen-rest-api/src/it/pom/pom.xml
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/it/pom/pom.xml (rev 0)
+++ branches/pollen-2.0/pollen-rest-api/src/it/pom/pom.xml 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,272 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ #%L
+ Pollen :: UI (struts2)
+ $Id$
+ $HeadURL: http://svn.chorem.org/svn/pollen/branches/pollen-2.0/pollen-ui-struts2/src/… $
+ %%
+ Copyright (C) 2009 - 2012 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ #L%
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.chorem</groupId>
+ <artifactId>pollen</artifactId>
+ <version>@pom.version@</version>
+ </parent>
+
+ <groupId>org.chorem.pollen.it</groupId>
+ <artifactId>pollen-it</artifactId>
+ <name>Pollen :: IT</name>
+ <description>Super Pom des ITs</description>
+ <packaging>pom</packaging>
+
+ <properties>
+ <defaultWebContextPath>pollen</defaultWebContextPath>
+ <pollenServerPort>8765</pollenServerPort>
+ <defaultLogDir>${basedir}/target</defaultLogDir>
+
+ <pollenConfigurationFile>pollen-it.properties</pollenConfigurationFile>
+ <pollenDataDirectory>
+ ${project.build.testOutputDirectory}/data
+ </pollenDataDirectory>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.chorem.pollen</groupId>
+ <artifactId>pollen-rest-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-runner</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>false</filtering>
+ </resource>
+ </resources>
+
+ <plugins>
+
+ </plugins>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ <configuration>
+ <stopKey>A</stopKey>
+ <stopPort>1269</stopPort>
+ <contextXml>${basedir}/src/jetty/jetty-context.xml</contextXml>
+ <webAppConfig>
+ <contextPath>/${defaultWebContextPath}</contextPath>
+ </webAppConfig>
+ <systemProperties>
+ <systemProperty>
+ <name>basedir</name>
+ <value>${basedir}</value>
+ </systemProperty>
+ <systemProperty>
+ <name>pollen.log.dir</name>
+ <value>${project.build.directory}</value>
+ </systemProperty>
+ <systemProperty>
+ <name>pollenConfigurationFile</name>
+ <value>${pollenConfigurationFile}</value>
+ </systemProperty>
+ <systemProperty>
+ <name>jetty.port</name>
+ <value>${pollenServerPort}</value>
+ </systemProperty>
+ <systemProperty>
+ <name>pollenServerPort</name>
+ <value>${pollenServerPort}</value>
+ </systemProperty>
+ <systemProperty>
+ <name>pollenDataDirectory</name>
+ <value>${pollenDataDirectory}</value>
+ </systemProperty>
+ </systemProperties>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <executions>
+
+ <execution>
+ <id>default-test</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+ </pluginManagement>
+ </build>
+
+ <profiles>
+
+ <profile>
+ <id>start-server</id>
+ <activation>
+ <property>
+ <name>runIts</name>
+ <value>true</value>
+ </property>
+ </activation>
+
+ <properties>
+ <jetty.daemon>${runIts}</jetty.daemon>
+ </properties>
+ <build>
+ <defaultGoal>pre-integration-test</defaultGoal>
+ <plugins>
+
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>start-pollen</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <!--<daemon>true</daemon>-->
+ <webAppSourceDirectory>
+ ${explodedWarPath}
+ </webAppSourceDirectory>
+ <webAppConfig>
+ <descriptor>
+ ${explodedWarPath}/WEB-INF/web.xml
+ </descriptor>
+ </webAppConfig>
+ <classesDirectory>
+ ${explodedWarPath}/WEB-INF/classes
+ </classesDirectory>
+ <useTestScope>true</useTestScope>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ <profile>
+ <id>run-tests</id>
+ <activation>
+ <property>
+ <name>runIts</name>
+ <value>true</value>
+ </property>
+ </activation>
+ <build>
+ <defaultGoal>integration-test</defaultGoal>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>run-tests</id>
+ <phase>integration-test</phase>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <includes>
+ <include>**/PollenTestSuite.java</include>
+ </includes>
+ <systemPropertyVariables>
+ <pollenServerPort>${pollenServerPort}</pollenServerPort>
+ <pollenConfigurationFile>
+ ${pollenConfigurationFile}
+ </pollenConfigurationFile>
+ <pollenDataDirectory>
+ ${pollenDataDirectory}
+ </pollenDataDirectory>
+ <extraDrivers>${extraDrivers}</extraDrivers>
+ </systemPropertyVariables>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+ </build>
+ </profile>
+
+ <profile>
+ <id>stop-server</id>
+ <activation>
+ <property>
+ <name>runIts</name>
+ <value>true</value>
+ </property>
+ </activation>
+ <build>
+ <defaultGoal>post-integration-test</defaultGoal>
+ <plugins>
+
+ <plugin>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>stop-pollen</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>stop</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ </profiles>
+
+</project>
Property changes on: branches/pollen-2.0/pollen-rest-api/src/it/pom/pom.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: branches/pollen-2.0/pollen-rest-api/src/it/user/README.txt
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/it/user/README.txt (rev 0)
+++ branches/pollen-2.0/pollen-rest-api/src/it/user/README.txt 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1 @@
+Test the user REST Api
\ No newline at end of file
Property changes on: branches/pollen-2.0/pollen-rest-api/src/it/user/README.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenApplicationContext.java
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenApplicationContext.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenApplicationContext.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -26,9 +26,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.persistence.JpaPollenPersistenceContext;
-import org.chorem.pollen.service.DefaultPollenServiceContext;
-import org.chorem.pollen.service.PollenServiceContext;
-import org.chorem.pollen.service.config.PollenServiceConfig;
+import org.chorem.pollen.services.DefaultPollenServiceContext;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.config.PollenServiceConfig;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenRender.java
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenRender.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenRender.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -28,7 +28,6 @@
import com.google.gson.Gson;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.persistence.entity.JpaPollenEntity;
import org.debux.webmotion.server.call.Call;
import org.debux.webmotion.server.call.HttpContext;
import org.debux.webmotion.server.mapping.Mapping;
@@ -53,14 +52,13 @@
import java.util.Map;
/**
- * To render
+ * To render any entities.
*
* @author tchemit <chemit(a)codelutin.com>
* @since 2.0
*/
public class PollenRender<T> extends Render {
-
/**
* To specify entity collections to include in binded entities.
*
@@ -115,20 +113,20 @@
// single object
- if (model instanceof JpaPollenEntity) {
+ if (model instanceof JpaEntity) {
// entity need to transform it
- JpaPollenEntity jpaEntity = (JpaPollenEntity) model;
+ JpaEntity jpaEntity = (JpaEntity) model;
- PollenEntityBinder<JpaPollenEntity> binder = BinderFactory.newBinder(jpaEntity.getClass(), jpaEntity.getClass(), null, PollenEntityBinder.class);
+ PollenEntityBinder<JpaEntity> binder = BinderFactory.newBinder(jpaEntity.getClass(), jpaEntity.getClass(), null, PollenEntityBinder.class);
Map<String, Object> map = binder.obtainProperties(jpaEntity);
Map<String, Object> result = Maps.newTreeMap();
for (Map.Entry<String, Object> entry : map.entrySet()) {
String propertyName = entry.getKey();
Object propertyValue = entry.getValue();
- if (propertyValue instanceof JpaPollenEntity) {
+ if (propertyValue instanceof JpaEntity) {
result.put(propertyName, toMap(propertyValue));
continue;
}
@@ -136,9 +134,6 @@
result.put(propertyName, propertyValue);
}
- // replace id to simpleId
- result.put(JpaEntity.PROPERTY_ID, jpaEntity.getSimpleId());
-
// treat collections
if (includeCollection != null) {
@@ -149,15 +144,12 @@
}
}
return result;
-
}
return model;
-
-
}
- protected static class PollenEntityBinder<E extends JpaPollenEntity> extends Binder<E, E> {
+ protected static class PollenEntityBinder<E extends JpaEntity> extends Binder<E, E> {
/** Logger. */
private static final Log log =
@@ -168,7 +160,6 @@
protected List<String> simpleProperties;
public PollenEntityBinder() {
-
}
@Override
@@ -176,7 +167,7 @@
super.setModel(model);
this.simpleProperties = Lists.newArrayList();
for (String property : model.getSourceDescriptors()) {
- if (model.getCollectionType(property)==null) {
+ if (model.getCollectionType(property) == null) {
simpleProperties.add(property);
}
}
Added: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenSecurityFilter.java
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenSecurityFilter.java (rev 0)
+++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenSecurityFilter.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,47 @@
+package org.chorem.pollen.rest;
+
+import org.apache.commons.lang3.StringUtils;
+import org.chorem.pollen.persistence.entity.SessionToken;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.InvalidSessionTokenException;
+import org.debux.webmotion.server.WebMotionFilter;
+import org.debux.webmotion.server.call.HttpContext;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollenSecurityFilter extends WebMotionFilter {
+
+ public static final String REQUEST_AUTH_PARAMETER = "auth";
+
+ void injectConnectedUser(HttpContext context) throws InvalidSessionTokenException {
+
+ String[] strings = context.getParameters().get(REQUEST_AUTH_PARAMETER);
+
+ String authParam = strings == null || strings.length < 1 ? null : strings[1];
+
+ if (StringUtils.isNotBlank(authParam)) {
+
+ // find out the userId from this auth
+
+ HttpServletRequest request = context.getRequest();
+
+ PollenServiceContext serviceContext =
+ PollenServices.getServiceContext(request);
+
+ SessionToken sessionToken =
+ serviceContext.getAuthService().getUserByAuth(authParam);
+
+ if (sessionToken != null) {
+
+ // reinject it in request
+ PollenServices.setSessionToken(request, sessionToken);
+ }
+ }
+ }
+}
Property changes on: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenSecurityFilter.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceContextFilter.java
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceContextFilter.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceContextFilter.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -23,7 +23,7 @@
* #L%
*/
-import org.chorem.pollen.service.PollenServiceContext;
+import org.chorem.pollen.services.PollenServiceContext;
import org.debux.webmotion.server.WebMotionFilter;
import org.debux.webmotion.server.call.HttpContext;
Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceListener.java
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceListener.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServiceListener.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -23,28 +23,21 @@
* #L%
*/
-import com.google.common.collect.Maps;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.persistence.entity.Comment;
-import org.chorem.pollen.persistence.entity.Poll;
-import org.chorem.pollen.persistence.entity.PollenEntities;
-import org.chorem.pollen.persistence.entity.PollenUser;
-import org.chorem.pollen.service.PollenServiceContext;
-import org.chorem.pollen.service.exception.UserEmailAlreadyUsedException;
-import org.chorem.pollen.service.exception.UserLoginAlreadyUsedException;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.UserEmailAlreadyUsedException;
+import org.chorem.pollen.services.exception.UserLoginAlreadyUsedException;
import org.debux.webmotion.server.WebMotionServerListener;
import org.debux.webmotion.server.call.Call;
import org.debux.webmotion.server.call.HttpContext;
import org.debux.webmotion.server.call.ServerContext;
import org.debux.webmotion.server.handler.ExecutorParametersInjectorHandler;
import org.debux.webmotion.server.mapping.Mapping;
-import org.nuiton.jpa.api.JpaEntity;
import javax.persistence.EntityManager;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Type;
-import java.util.Map;
/**
* TODO
@@ -62,7 +55,7 @@
public void onStart(Mapping mapping, ServerContext serverContext) {
serverContext.addInjector(new PollenServiceContextInjector());
- serverContext.addInjector(new PollenIdInjector());
+ serverContext.addInjector(new SessionTokenInjector());
// Create application context
PollenApplicationContext applicationContext =
@@ -75,7 +68,8 @@
EntityManager entityManager = applicationContext.newEntityManager();
try {
- PollenServiceContext serviceContext = applicationContext.newServiceContext(entityManager);
+ PollenServiceContext serviceContext =
+ applicationContext.newServiceContext(entityManager);
serviceContext.getUserService().createDefaultUsers();
} catch (UserEmailAlreadyUsedException e) {
//Can't happen
@@ -103,53 +97,28 @@
protected static class PollenServiceContextInjector implements ExecutorParametersInjectorHandler.Injector {
@Override
public Object getValue(Mapping mapping, Call call, String name, Class<?> type, Type generic) {
+ PollenServiceContext result = null;
if (PollenServiceContext.class.isAssignableFrom(type)) {
HttpContext httpContext = call.getContext();
HttpServletRequest request = httpContext.getRequest();
- return PollenServices.getServiceContext(request);
+
+ result = PollenServices.getServiceContext(request);
}
- return null;
+ return result;
}
}
- protected static class PollenIdInjector implements ExecutorParametersInjectorHandler.Injector {
-
- final Map<String, Class<? extends JpaEntity>> paramMapping;
-
- public PollenIdInjector() {
- paramMapping = Maps.newTreeMap();
- paramMapping.put("userId", PollenUser.class);
- paramMapping.put("pollId", Poll.class);
- paramMapping.put("commentId", Comment.class);
- }
-
+ protected static class SessionTokenInjector implements ExecutorParametersInjectorHandler.Injector {
@Override
- public Object getValue(Mapping mapping,
- Call call,
- String name,
- Class<?> type,
- Type generic) {
+ public Object getValue(Mapping mapping, Call call, String name, Class<?> type, Type generic) {
+ PollenServiceContext result = null;
+ if (PollenServiceContext.class.isAssignableFrom(type)) {
+ HttpContext httpContext = call.getContext();
+ HttpServletRequest request = httpContext.getRequest();
- if (String.class.isAssignableFrom(type) && paramMapping.containsKey(name)) {
-
- Class<? extends JpaEntity> entityType = paramMapping.get(name);
-
- Call.ParameterTree parameterTree = call.getParameterTree();
- Map<String, Call.ParameterTree> tree = parameterTree.getTree();
-
- Call.ParameterTree paramValue = tree.get(name);
- if (paramValue != null) {
- String id = String.valueOf(((String[]) paramValue.getValue())[0]);
- if (PollenEntities.isSimpleId(id)) {
-
- // get the full id
- String fullId = PollenEntities.getEntityId(
- entityType, id);
- return fullId;
- }
- }
+ result = PollenServices.getServiceContext(request);
}
- return null;
+ return result;
}
}
}
Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServices.java
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServices.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/PollenServices.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -23,7 +23,8 @@
* #L%
*/
-import org.chorem.pollen.service.PollenServiceContext;
+import org.chorem.pollen.persistence.entity.SessionToken;
+import org.chorem.pollen.services.PollenServiceContext;
import org.nuiton.web.filter.JpaTransactionFilter;
import javax.persistence.EntityManager;
@@ -42,6 +43,8 @@
protected static final String REQUEST_POLLEN_SERVICE_CONTEXT = "pollen_PollenServiceContext";
+ protected static final String REQUEST_POLLEN_CONNECTED_USER = "pollen_PollenConnectedUser";
+
protected static final String REQUEST_ENTITY_MANAGER = JpaTransactionFilter.JPA_TRANSACTION_REQUEST_ATTRIBUTE;
public static PollenApplicationContext getApplicationContext(ServletContext servletContext) {
@@ -72,4 +75,15 @@
request.getAttribute(REQUEST_ENTITY_MANAGER);
return result;
}
+
+ public static SessionToken getSessionToken(HttpServletRequest request) {
+ SessionToken result = (SessionToken)
+ request.getAttribute(REQUEST_POLLEN_CONNECTED_USER);
+ return result;
+ }
+
+ public static void setSessionToken(HttpServletRequest request,
+ SessionToken sessionToken) {
+ request.setAttribute(REQUEST_POLLEN_CONNECTED_USER, sessionToken);
+ }
}
\ No newline at end of file
Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/AuthService.java
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/AuthService.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/AuthService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -23,9 +23,9 @@
* #L%
*/
-import org.chorem.pollen.service.PollenServiceContext;
-import org.chorem.pollen.service.exception.EntityNotFoundException;
-import org.chorem.pollen.service.exception.UserInvalidPasswordException;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.chorem.pollen.services.exception.UserInvalidPasswordException;
import org.debux.webmotion.server.WebMotionController;
/**
Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/CommentService.java
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/CommentService.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/CommentService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -24,8 +24,8 @@
*/
import org.chorem.pollen.persistence.entity.Comment;
-import org.chorem.pollen.service.PollenServiceContext;
-import org.chorem.pollen.service.exception.EntityNotFoundException;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
import org.debux.webmotion.server.WebMotionController;
import java.util.List;
Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/FavoriteListService.java
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/FavoriteListService.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/FavoriteListService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -25,14 +25,22 @@
import org.chorem.pollen.persistence.entity.FavoriteList;
import org.chorem.pollen.persistence.entity.FavoriteListMember;
-import org.chorem.pollen.service.PollenServiceContext;
-import org.chorem.pollen.service.exception.EntityNotFoundException;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.chorem.pollen.services.exception.FavoriteListImportException;
+import org.chorem.pollen.services.exception.FavoriteListMemberEmailAlreadyUsedException;
+import org.chorem.pollen.services.exception.FavoriteListMemberNameAlreadyUsedException;
+import org.chorem.pollen.services.exception.FavoriteListMemberNotOwnedByFavoriteListException;
+import org.chorem.pollen.services.exception.FavoriteListNameAlreadyUsedException;
+import org.chorem.pollen.services.exception.FavoriteListNotOwnedByUserException;
import org.debux.webmotion.server.WebMotionController;
+import java.io.File;
import java.util.List;
/**
* TODO
+ * TODO All method needs a userId connected
*
* @author tchemit <chemit(a)codelutin.com>
* @since 2.0
@@ -48,18 +56,26 @@
return context.getFavoriteListService().getFavoriteList(favoriteListId);
}
- public FavoriteList createFavoriteList(PollenServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException {
+ public FavoriteList createFavoriteList(PollenServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, FavoriteListNameAlreadyUsedException {
return context.getFavoriteListService().createFavoriteList(userId, favoriteList);
}
- public FavoriteList editFavoriteList(PollenServiceContext context, FavoriteList favoriteList) throws EntityNotFoundException {
- return context.getFavoriteListService().editFavoriteList(favoriteList);
+ public FavoriteList editFavoriteList(PollenServiceContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, FavoriteListNameAlreadyUsedException, FavoriteListNotOwnedByUserException {
+ return context.getFavoriteListService().editFavoriteList(userId, favoriteList);
}
- public void deleteFavoriteList(PollenServiceContext context, String userId, String favoriteListId) throws EntityNotFoundException {
+ public void deleteFavoriteList(PollenServiceContext context, String userId, String favoriteListId) throws EntityNotFoundException, FavoriteListNotOwnedByUserException {
context.getFavoriteListService().deleteFavoriteList(userId, favoriteListId);
}
+ public int importFavoriteListMembersFromCsv(PollenServiceContext context, String userId, String favoriteListId, File csvFile) throws EntityNotFoundException, FavoriteListImportException, FavoriteListNotOwnedByUserException {
+ return context.getFavoriteListService().importFavoriteListMembersFromCsv(userId, favoriteListId, csvFile);
+ }
+
+ public int importFavoriteListMembersFromLdap(PollenServiceContext context, String userId, String favoriteListId, String ldap) throws EntityNotFoundException, FavoriteListImportException, FavoriteListNotOwnedByUserException {
+ return context.getFavoriteListService().importFavoriteListMembersFromLdap(userId, favoriteListId, ldap);
+ }
+
public List<FavoriteListMember> getMembers(PollenServiceContext context, String favoriteListId) throws EntityNotFoundException {
List<FavoriteListMember> members = context.getFavoriteListService().getFavoriteListMembers(favoriteListId);
return members;
@@ -69,15 +85,15 @@
return context.getFavoriteListService().getFavoriteListMember(memberId);
}
- public FavoriteListMember addMember(PollenServiceContext context, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException {
+ public FavoriteListMember addMember(PollenServiceContext context, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberEmailAlreadyUsedException, FavoriteListMemberNameAlreadyUsedException {
return context.getFavoriteListService().addFavoriteListMember(favoriteListId, member);
}
- public FavoriteListMember editMember(PollenServiceContext context, FavoriteListMember member) throws EntityNotFoundException {
- return context.getFavoriteListService().editFavoriteListMember(member);
+ public FavoriteListMember editMember(PollenServiceContext context, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberEmailAlreadyUsedException, FavoriteListMemberNameAlreadyUsedException, FavoriteListMemberNotOwnedByFavoriteListException {
+ return context.getFavoriteListService().editFavoriteListMember(favoriteListId, member);
}
- public void removeMember(PollenServiceContext context, String favoriteListId, String memberId) throws EntityNotFoundException {
- context.getFavoriteListService().removeFavoriteListMember( favoriteListId, memberId);
+ public void removeMember(PollenServiceContext context, String favoriteListId, String memberId) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException {
+ context.getFavoriteListService().removeFavoriteListMember(favoriteListId, memberId);
}
}
Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollService.java
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollService.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -25,11 +25,10 @@
import org.chorem.pollen.persistence.entity.Choice;
import org.chorem.pollen.persistence.entity.Poll;
-import org.chorem.pollen.service.PollenServiceContext;
-import org.chorem.pollen.service.exception.EntityNotFoundException;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
import org.debux.webmotion.server.WebMotionController;
-import javax.servlet.annotation.WebFilter;
import java.io.File;
import java.util.List;
import java.util.Set;
@@ -62,6 +61,10 @@
return polls;
}
+ public Poll getPoll(PollenServiceContext context, String pollId) throws EntityNotFoundException {
+ return context.getPollService().getPoll(pollId);
+ }
+
public Poll createPoll(PollenServiceContext context, String userId, Poll poll) throws EntityNotFoundException {
return context.getPollService().createPoll(userId, poll);
}
Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/UserService.java
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/UserService.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/UserService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -24,12 +24,12 @@
*/
import org.chorem.pollen.persistence.entity.PollenUser;
-import org.chorem.pollen.service.PollenServiceContext;
-import org.chorem.pollen.service.exception.EntityNotFoundException;
-import org.chorem.pollen.service.exception.UserEmailAlreadyUsedException;
-import org.chorem.pollen.service.exception.UserInvalidEmailActiviationTokenException;
-import org.chorem.pollen.service.exception.UserInvalidPasswordException;
-import org.chorem.pollen.service.exception.UserLoginAlreadyUsedException;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.chorem.pollen.services.exception.UserEmailAlreadyUsedException;
+import org.chorem.pollen.services.exception.UserInvalidEmailActiviationTokenException;
+import org.chorem.pollen.services.exception.UserInvalidPasswordException;
+import org.chorem.pollen.services.exception.UserLoginAlreadyUsedException;
import org.debux.webmotion.server.WebMotionController;
import java.util.List;
Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteCountingService.java
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteCountingService.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteCountingService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -23,9 +23,9 @@
* #L%
*/
-import org.chorem.pollen.service.PollResult;
-import org.chorem.pollen.service.PollenServiceContext;
-import org.chorem.pollen.service.exception.EntityNotFoundException;
+import org.chorem.pollen.services.PollResult;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
import org.debux.webmotion.server.WebMotionController;
/**
Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteService.java
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteService.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoteService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -24,8 +24,8 @@
*/
import org.chorem.pollen.persistence.entity.Vote;
-import org.chorem.pollen.service.PollenServiceContext;
-import org.chorem.pollen.service.exception.EntityNotFoundException;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
import org.debux.webmotion.server.WebMotionController;
import java.util.List;
Modified: branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoterListService.java
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoterListService.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/VoterListService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -25,8 +25,8 @@
import org.chorem.pollen.persistence.entity.VoterList;
import org.chorem.pollen.persistence.entity.VoterListMember;
-import org.chorem.pollen.service.PollenServiceContext;
-import org.chorem.pollen.service.exception.EntityNotFoundException;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
import org.debux.webmotion.server.WebMotionController;
import java.util.List;
Modified: branches/pollen-2.0/pollen-rest-api/src/main/resources/mapping
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/main/resources/mapping 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-rest-api/src/main/resources/mapping 2013-06-14 09:12:59 UTC (rev 3823)
@@ -33,20 +33,22 @@
GET /polls/{pollId}/comments CommentService.getComments
POST /polls/{pollId}/comments CommentService.addComment
GET /comments/{commentId} CommentService.getComment
-PUT /comments CommentService.editComment
+PUT /comments/{commentId} CommentService.editComment
DELETE /polls/{pollId}/comments/{commentId} CommentService.deleteComment
# FavoriteListService
GET /favoriteLists FavoriteListService.getFavoriteLists
GET /favoriteLists/{flId} FavoriteListService.getFavoriteList
+POST /favoriteLists/{flId}/importCsv FavoriteListService.importFavoriteListMemberFromCsv
+POST /favoriteLists/{flId}/importLdap FavoriteListService.importFavoriteListMemberFromLdap
POST /favoriteLists FavoriteListService.createFavoriteList
-PUT /favoriteLists FavoriteListService.editFavoriteList
+PUT /favoriteLists/{flId} FavoriteListService.editFavoriteList
DELETE /favoriteLists/{flId} FavoriteListService.deleteFavoriteList
GET /favoriteLists/{flId}/members FavoriteListService.getMembers
GET /favoriteListMembers/{mId} FavoriteListService.getMember
POST /favoriteLists/{flId}/members FavoriteListService.addMember
-PUT /favoriteListMembers FavoriteListService.editMember
+PUT /favoriteLists/{flId}/members/{mId} FavoriteListService.editMember
DELETE /favoriteLists/{flId}/members/{mId} FavoriteListService.removeMember
# PollService
@@ -56,7 +58,7 @@
GET /polls/invited PollService.getInvitedPolls
GET /polls/participated PollService.getParticipatedPolls
POST /polls PollService.createPoll
-PUT /polls PollService.editPoll
+PUT /polls/{pollId} PollService.editPoll
GET /polls/{pollId} PollService.getPoll
DELETE /polls/{pollId} PollService.deletePoll
POST /polls/{pollId} PollService.clonePoll
@@ -66,7 +68,7 @@
GET /polls/{pollId}/choices PollService.getChoices
POST /polls/{pollId}/choices PollService.addChoice
GET /choices/{choiceId} PollService.getChoice
-PUT /choices PollService.editChoice
+PUT /choices/{choiceId} PollService.editChoice
DELETE /polls/{pollId}/choices/{choiceId} PollService.deleteChoice
# UserService
@@ -74,7 +76,7 @@
GET /users UserService.getUsers
GET /users/{userId} UserService.getUser
POST /users UserService.createUser
-PUT /users UserService.editUser
+PUT /users/{userId} UserService.editUser
PUT /users/{userId}?token={} UserService.validateUserEmail
# VoteCountingService
@@ -86,13 +88,14 @@
PUT /polls/{pollId}/favoriteLists/{flId} VoterListService.importFavoriteList
GET /polls/{pollId}/voterLists VoterListService.getVoterLists
GET /voterLists/{vlId} VoterListService.getVoterList
+POST /voterLists VoterListService.createVoterList
PUT /voterLists/{vlId} VoterListService.editVoterList
DELETE /polls/{pollId}/voterLists/{vlId} VoterListService.deleteVoterList
GET /voterLists/{vlId}/members VoterListService.getMembers
GET /voterListMembers/{mId} VoterListService.getMember
POST /voterLists/{vlId}/members VoterListService.addMember
-PUT /voterListMembers VoterListService.editMember
+PUT /voterListMembers/{mId} VoterListService.editMember
DELETE /voterLists/{vlId}/members/{mId} VoterListService.deleteMember
# VoteService
@@ -100,5 +103,5 @@
GET /polls/{pollId}/votes VoteService.getVotes
PUT /polls/{pollId}/votes VoteService.addVote
GET /votes/{voteId} VoteService.getVote
-PUT /votes VoteService.editVote
+PUT /votes/{voteId} VoteService.editVote
DELETE /polls/{pollId}/votes/{voteId} VoteService.deleteVote
Modified: branches/pollen-2.0/pollen-rest-api/src/main/webapp/WEB-INF/web.xml
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/main/webapp/WEB-INF/web.xml 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-rest-api/src/main/webapp/WEB-INF/web.xml 2013-06-14 09:12:59 UTC (rev 3823)
@@ -30,14 +30,6 @@
<display-name>Pollen REST Api</display-name>
- <listener>
- <listener-class>org.apache.commons.fileupload.servlet.FileCleanerCleanup</listener-class>
- </listener>
-
- <listener>
- <listener-class>org.debux.webmotion.server.WebMotionServletContextListener</listener-class>
- </listener>
-
<filter>
<filter-name>jpaTransaction</filter-name>
<filter-class>
@@ -45,24 +37,9 @@
</filter-class>
</filter>
- <filter>
- <filter-name>WebMotionServer</filter-name>
- <filter-class>org.debux.webmotion.server.WebMotionServer</filter-class>
- <async-supported>true</async-supported>
- </filter>
-
<filter-mapping>
<filter-name>jpaTransaction</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
- <filter-mapping>
- <filter-name>WebMotionServer</filter-name>
- <url-pattern>/*</url-pattern>
- <dispatcher>REQUEST</dispatcher>
- <dispatcher>INCLUDE</dispatcher>
- <dispatcher>FORWARD</dispatcher>
- <dispatcher>ERROR</dispatcher>
- </filter-mapping>
-
</web-app>
\ No newline at end of file
Modified: branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -25,11 +25,10 @@
import org.chorem.pollen.persistence.JpaPollenPersistenceContext;
import org.chorem.pollen.rest.PollenApplicationContext;
-import org.chorem.pollen.service.FixturesService;
-import org.chorem.pollen.service.PollenFixtures;
-import org.chorem.pollen.service.PollenServiceContext;
-import org.debux.webmotion.unittest.WebMotionTest;
-import org.junit.Before;
+import org.chorem.pollen.services.service.FixturesService;
+import org.chorem.pollen.services.PollenFixtures;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.debux.webmotion.unittest.WebMotionJUnit;
import org.junit.Rule;
import org.nuiton.jpa.junit.JpaEntityManagerRule;
@@ -42,7 +41,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.0
*/
-public class AbstractPollenRestApiTest extends WebMotionTest {
+public class AbstractPollenRestApiTest extends WebMotionJUnit {
protected JpaEntityManagerRule jpaEntityManagerRule;
@@ -114,8 +113,8 @@
}
- @Before
- public void launchServer() throws Exception {
- runServer();
- }
+// @Before
+// public void launchServer() throws Exception {
+// runServer();
+// }
}
Modified: branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/FakePollenServiceContext.java
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/FakePollenServiceContext.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/FakePollenServiceContext.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -26,7 +26,7 @@
import com.google.common.base.Preconditions;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.service.DefaultPollenServiceContext;
+import org.chorem.pollen.services.DefaultPollenServiceContext;
import java.util.Date;
Modified: branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/UserServiceTest.java
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/UserServiceTest.java 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/UserServiceTest.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -52,7 +52,7 @@
Request request = createRequest("/users").Get();
String result = request.execute().returnContent().asString();
- assertTrue(result.contains("users"));
+ assertTrue(result.contains("email"));
}
Modified: branches/pollen-2.0/pollen-rest-api/src/test/resources/pollen.properties
===================================================================
--- branches/pollen-2.0/pollen-rest-api/src/test/resources/pollen.properties 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pollen-rest-api/src/test/resources/pollen.properties 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,5 +1,5 @@
javax.persistence.jdbc.driver=org.h2.Driver
-javax.persistence.jdbc.url=jdbc:h2:file:${testDirectory}/pollen/h2data
+javax.persistence.jdbc.url=jdbc:h2:file:target/pollen/h2data
javax.persistence.jdbc.user=sa
javax.persistence.jdbc.password=
hibernate.dialect=org.hibernate.dialect.H2Dialect
Modified: branches/pollen-2.0/pollen-services/pom.xml
===================================================================
--- branches/pollen-2.0/pollen-service/pom.xml 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/pom.xml 2013-06-14 09:12:59 UTC (rev 3823)
@@ -9,7 +9,7 @@
</parent>
<groupId>org.chorem.pollen</groupId>
- <artifactId>pollen-service</artifactId>
+ <artifactId>pollen-services</artifactId>
<name>Pollen :: Service </name>
<description>Pollen Service Layer</description>
Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/AbstractPollenService.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/AbstractPollenService.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/AbstractPollenService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,117 +0,0 @@
-package org.chorem.pollen.service;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import com.google.common.base.Preconditions;
-import org.chorem.pollen.persistence.PollenPersistenceContext;
-import org.chorem.pollen.service.config.PollenServiceConfig;
-import org.chorem.pollen.service.exception.EntityNotFoundException;
-import org.nuiton.jpa.api.JpaEntities;
-import org.nuiton.jpa.api.JpaEntity;
-
-import java.util.Date;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public abstract class AbstractPollenService implements PollenServiceSupport {
-
- protected PollenServiceContext serviceContext;
-
- protected void checkHasId(JpaEntity entity) {
- Preconditions.checkState(JpaEntities.isEntityHasId(entity));
- }
-
- protected void checkHasNoId(JpaEntity entity) {
- Preconditions.checkState(JpaEntities.isEntityHasNoId(entity));
- }
-
- @Override
- public void setServiceContext(PollenServiceContext serviceContext) {
- this.serviceContext = serviceContext;
- }
-
- protected Date getNow() {
- return serviceContext.getNow();
- }
-
- protected String generateId() {
- return serviceContext.generateUUID();
- }
-
- protected PollenPersistenceContext getPersistenceContext() {
- return serviceContext.getPersistenceContext();
- }
-
- protected PollenServiceConfig getPollenServiceConfig() {
- return serviceContext.getPollenServiceConfig();
- }
-
- protected AuthService getAuthService() {
- return serviceContext.getAuthService();
- }
-
- protected CommentService getCommentService() {
- return serviceContext.getCommentService();
- }
-
- protected FavoriteListService getFavoriteListService() {
- return serviceContext.getFavoriteListService();
- }
-
- protected PollService getPollService() {
- return serviceContext.getPollService();
- }
-
- protected UserService getUserService() {
- return serviceContext.getUserService();
- }
-
- protected VoteCountingService getVoteCountingService() {
- return serviceContext.getVoteCountingService();
- }
-
- protected VoterListService getVoterListService() {
- return serviceContext.getVoterListService();
- }
-
- protected VoteService getVoteService() {
- return serviceContext.getVoteService();
- }
-
- protected EmailService getEmailService() {
- return serviceContext.getEmailService();
- }
-
- protected <E extends JpaEntity> void checkEntityExists(Class<E> type,
- E entity,
- String entityId) throws EntityNotFoundException {
- if (entity == null) {
- throw new EntityNotFoundException(type, entityId);
- }
- }
-}
Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/AuthService.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/AuthService.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/AuthService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,116 +0,0 @@
-package org.chorem.pollen.service;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import com.google.common.base.Preconditions;
-import org.chorem.pollen.persistence.dao.PollenUserJpaDao;
-import org.chorem.pollen.persistence.dao.SessionTokenJpaDao;
-import org.chorem.pollen.persistence.entity.PollenUser;
-import org.chorem.pollen.persistence.entity.SessionToken;
-import org.chorem.pollen.service.exception.EntityNotFoundException;
-import org.chorem.pollen.service.exception.UserInvalidPasswordException;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class AuthService extends AbstractPollenService {
-
- public String login(String login, String password) throws EntityNotFoundException, UserInvalidPasswordException {
- Preconditions.checkNotNull(login);
- Preconditions.checkNotNull(password);
-
- PollenUser user = getPersistenceContext().getPollenUserDao().findByLogin(login);
- if (user == null) {
- throw new EntityNotFoundException(PollenUser.class, login);
- }
-
- String encodedPassword = serviceContext.encodePassword(password);
- if (!encodedPassword.equals(user.getPassword())) {
- throw new UserInvalidPasswordException();
- }
-
- // Create a new session Token
- SessionTokenJpaDao dao = getPersistenceContext().getSessionTokenDao();
-
- SessionToken sessionToken = dao.newInstance();
- String token = serviceContext.generateUUID();
- String encodedToken = serviceContext.encodePassword(token);
- sessionToken.setPollenUser(user);
- sessionToken.setToken(encodedToken);
- sessionToken.setCreationDate(serviceContext.getNow());
-
- dao.persist(sessionToken);
- getPersistenceContext().commit();
-
- return token;
- }
-
- public void lostPassword(String login) throws EntityNotFoundException {
- Preconditions.checkNotNull(login);
-
- PollenUserJpaDao dao = getPersistenceContext().getPollenUserDao();
-
- PollenUser user = dao.findByLogin(login);
- if (user == null) {
- throw new EntityNotFoundException(PollenUser.class, login);
- }
-
- // Generate a new password
- String newPassword = serviceContext.generatePassword();
- String encodedPassword = serviceContext.encodePassword(newPassword);
- user.setPassword(encodedPassword);
- dao.merge(user);
- getPersistenceContext().commit();
-
- notifyPasswordChanged(user, newPassword);
- }
-
- public void logout(String login, String token) throws EntityNotFoundException {
- Preconditions.checkNotNull(login);
- Preconditions.checkNotNull(token);
- PollenUser user = getPersistenceContext().getPollenUserDao().findByLogin(login);
- if (user == null) {
- throw new EntityNotFoundException(PollenUser.class, login);
- }
-
- String encodedToken = serviceContext.encodePassword(token);
-
- SessionTokenJpaDao dao = getPersistenceContext().getSessionTokenDao();
-
- SessionToken sessionToken = dao.findByToken(encodedToken);
- if (sessionToken == null) {
- throw new EntityNotFoundException(SessionToken.class, token);
- }
-
- dao.remove(sessionToken);
- getPersistenceContext().commit();
- }
-
- protected void notifyPasswordChanged(PollenUser user, String newPassword) {
- //TODO
- }
-}
Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/CommentService.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/CommentService.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/CommentService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,94 +0,0 @@
-package org.chorem.pollen.service;
-
-/*
- * #%L
- * Pollen :: Service API
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import com.google.common.base.Preconditions;
-import org.chorem.pollen.persistence.entity.Comment;
-import org.chorem.pollen.persistence.entity.Poll;
-import org.chorem.pollen.service.exception.EntityNotFoundException;
-
-import java.util.List;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class CommentService extends AbstractPollenService {
-
- public List<Comment> getComments(String pollId) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
- Poll poll = getPollService().getPoll(pollId);
- return poll.getComment();
- }
-
- public Comment getComment(String commentId) throws EntityNotFoundException {
- Preconditions.checkNotNull(commentId);
- Comment result = getPersistenceContext().getCommentDao().findById(commentId);
- checkEntityExists(Comment.class, result, commentId);
- return result;
- }
-
- public Comment addComment(String pollId, Comment comment) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
- checkHasNoId(comment);
- Poll poll = getPollService().getPoll(pollId);
-
- poll.addComment(comment);
- getPersistenceContext().getPollDao().merge(poll);
- getPersistenceContext().commit();
-
- Comment result = getComment(comment.getId());
- return result;
- }
-
- public Comment editComment(Comment comment) throws EntityNotFoundException {
-
- // check comment exists
- getComment(comment.getId());
-
- getPersistenceContext().getCommentDao().merge(comment);
- getPersistenceContext().commit();
-
- Comment result = getComment(comment.getId());
- return result;
- }
-
- public void deleteComment(String pollId, String commentId) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
- Preconditions.checkNotNull(commentId);
- Poll poll = getPollService().getPoll(pollId);
-
- Comment comment = getComment(commentId);
- Preconditions.checkNotNull(comment);
-
- poll.removeComment(comment);
-
- getPersistenceContext().getPollDao().merge(poll);
-
- getPersistenceContext().commit();
- }
-
-}
Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/DefaultPollenServiceContext.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/DefaultPollenServiceContext.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/DefaultPollenServiceContext.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,158 +0,0 @@
-package org.chorem.pollen.service;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.apache.commons.lang3.RandomStringUtils;
-import org.chorem.pollen.persistence.PollenPersistenceContext;
-import org.chorem.pollen.service.config.PollenServiceConfig;
-import org.nuiton.util.StringUtil;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Date;
-import java.util.UUID;
-
-public class DefaultPollenServiceContext implements PollenServiceContext {
-
- protected PollenServiceConfig pollenServiceConfig;
-
- protected PollenPersistenceContext persistenceContext;
-
- public void setPollenServiceConfig(PollenServiceConfig pollenServiceConfig) {
- this.pollenServiceConfig = pollenServiceConfig;
- }
-
- public void setPersistenceContext(PollenPersistenceContext persistenceContext) {
- this.persistenceContext = persistenceContext;
- }
-
- @Override
- public PollenServiceConfig getPollenServiceConfig() {
- return pollenServiceConfig;
- }
-
- @Override
- public String generateUUID() {
- return UUID.randomUUID().toString();
- }
-
- @Override
- public Date getNow() {
- Date now = new Date();
- return now;
- }
-
- public String generatePassword() {
- return RandomStringUtils.randomAlphanumeric(8);
- }
-
- @Override
- public PollenPersistenceContext getPersistenceContext() {
- return persistenceContext;
- }
-
- @Override
- public AuthService getAuthService() {
- return newService(AuthService.class);
- }
-
- @Override
- public CommentService getCommentService() {
- return newService(CommentService.class);
- }
-
- @Override
- public FavoriteListService getFavoriteListService() {
- return newService(FavoriteListService.class);
- }
-
- @Override
- public PollService getPollService() {
- return newService(PollService.class);
- }
-
- @Override
- public UserService getUserService() {
- return newService(UserService.class);
- }
-
- @Override
- public VoteCountingService getVoteCountingService() {
- return newService(VoteCountingService.class);
- }
-
- @Override
- public VoterListService getVoterListService() {
- return newService(VoterListService.class);
- }
-
- @Override
- public VoteService getVoteService() {
- return newService(VoteService.class);
- }
-
- @Override
- public EmailService getEmailService() {
- return newService(EmailService.class);
- }
-
- @Override
- public String encodePassword(String password) {
- return StringUtil.encodeMD5(password);
- }
-
- protected <E extends PollenServiceSupport> E newService(Class<E> serviceClass) {
-
- E service;
-
- try {
-
- Constructor<E> constructor = serviceClass.getConstructor();
-
- service = constructor.newInstance();
-
- } catch (NoSuchMethodException e) {
-
- throw new PollenTechnicalException("all services must provide a default public constructor", e);
-
- } catch (InvocationTargetException e) {
-
- throw new PollenTechnicalException("unable to instantiate pollen service", e);
-
- } catch (InstantiationException e) {
-
- throw new PollenTechnicalException("unable to instantiate pollen service", e);
-
- } catch (IllegalAccessException e) {
-
- throw new PollenTechnicalException("unable to instantiate pollen service", e);
- }
-
- service.setServiceContext(this);
-
- return service;
-
- }
-
-}
Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/EmailService.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/EmailService.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/EmailService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,39 +0,0 @@
-package org.chorem.pollen.service;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.chorem.pollen.persistence.entity.PollenUser;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class EmailService extends AbstractPollenService {
-
- public void onUserCreated(PollenUser user) {
- //TODO
- }
-}
Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/FavoriteListService.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/FavoriteListService.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/FavoriteListService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,159 +0,0 @@
-package org.chorem.pollen.service;
-
-/*
- * #%L
- * Pollen :: Service API
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import com.google.common.base.Preconditions;
-import org.chorem.pollen.persistence.entity.FavoriteList;
-import org.chorem.pollen.persistence.entity.FavoriteListMember;
-import org.chorem.pollen.persistence.entity.PollenUser;
-import org.chorem.pollen.service.exception.EntityNotFoundException;
-
-import java.util.List;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class FavoriteListService extends AbstractPollenService {
-
- public List<FavoriteList> getFavoriteLists(String userId)throws EntityNotFoundException {
- Preconditions.checkNotNull(userId);
- PollenUser user = getUserService().getUser(userId);
-
- List<FavoriteList> result = user.getFavoriteList();
- return result;
- }
-
- public FavoriteList getFavoriteList(String favoriteListId) throws EntityNotFoundException{
- Preconditions.checkNotNull(favoriteListId);
- FavoriteList result = getPersistenceContext().getFavoriteListDao().findById(favoriteListId);
- checkEntityExists(FavoriteList.class, result, favoriteListId);
- return result;
- }
-
- public FavoriteList createFavoriteList(String userId,
- FavoriteList favoriteList) throws EntityNotFoundException{
- Preconditions.checkNotNull(userId);
- Preconditions.checkNotNull(favoriteList);
- checkHasNoId(favoriteList);
-
- PollenUser user = getUserService().getUser(userId);
-
- user.addFavoriteList(favoriteList);
- getPersistenceContext().getPollenUserDao().merge(user);
-
- getPersistenceContext().commit();
- FavoriteList result = getFavoriteList(favoriteList.getId());
- return result;
- }
-
- public FavoriteList editFavoriteList(FavoriteList favoriteList) throws EntityNotFoundException{
- Preconditions.checkNotNull(favoriteList);
- checkHasId(favoriteList);
-
- getFavoriteList(favoriteList.getId());
-
- getPersistenceContext().getFavoriteListDao().merge(favoriteList);
-
- getPersistenceContext().commit();
- FavoriteList result = getFavoriteList(favoriteList.getId());
- return result;
- }
-
- public void deleteFavoriteList(String userId, String favoriteListId) throws EntityNotFoundException{
- Preconditions.checkNotNull(userId);
- Preconditions.checkNotNull(favoriteListId);
-
- PollenUser user = getUserService().getUser(userId);
-
- FavoriteList persisted = getFavoriteList(favoriteListId);
-
- user.removeFavoriteList(persisted);
- getPersistenceContext().getPollenUserDao().merge(user);
-
- getPersistenceContext().commit();
- }
-
- public List<FavoriteListMember> getFavoriteListMembers(String favoriteListId)throws EntityNotFoundException {
- Preconditions.checkNotNull(favoriteListId);
-
- FavoriteList favoriteList = getFavoriteList(favoriteListId);
-
- return favoriteList.getFavoriteListMember();
- }
-
- public FavoriteListMember getFavoriteListMember(String memberId)throws EntityNotFoundException {
- Preconditions.checkNotNull(memberId);
- FavoriteListMember result = getPersistenceContext().getFavoriteListMemberDao().findById(memberId);
- checkEntityExists(FavoriteListMember.class, result, memberId);
- return result;
- }
-
- public FavoriteListMember addFavoriteListMember(String favoriteListId,
- FavoriteListMember member)throws EntityNotFoundException {
- Preconditions.checkNotNull(favoriteListId);
- Preconditions.checkNotNull(member);
- checkHasNoId(member);
-
- FavoriteList favoriteList = getFavoriteList(favoriteListId);
-
- favoriteList.addFavoriteListMember(member);
-
- getPersistenceContext().getFavoriteListDao().merge(favoriteList);
-
- getPersistenceContext().commit();
- FavoriteListMember result = getFavoriteListMember(member.getId());
- return result;
- }
-
- public FavoriteListMember editFavoriteListMember(FavoriteListMember member)throws EntityNotFoundException {
- Preconditions.checkNotNull(member);
- checkHasId(member);
-
-
- getFavoriteListMember(member.getId());
-
- member = getPersistenceContext().getFavoriteListMemberDao().merge(member);
- getPersistenceContext().commit();
- FavoriteListMember result = getFavoriteListMember(member.getId());
- return result;
- }
-
- public void removeFavoriteListMember(String favoriteListId, String memberId) throws EntityNotFoundException{
- Preconditions.checkNotNull(favoriteListId);
- Preconditions.checkNotNull(memberId);
-
- FavoriteList favoriteList = getFavoriteList(favoriteListId);
-
- FavoriteListMember member = getFavoriteListMember(memberId);
-
- favoriteList.removeFavoriteListMember(member);
-
- getPersistenceContext().getFavoriteListDao().merge(favoriteList);
- getPersistenceContext().commit();
- }
-
-}
Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/FixturesService.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/FixturesService.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/FixturesService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,100 +0,0 @@
-package org.chorem.pollen.service;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.persistence.PollenPersistenceContext;
-import org.chorem.pollen.persistence.dao.PollenUserJpaDao;
-import org.chorem.pollen.persistence.entity.PollenUser;
-
-import java.util.Collection;
-import java.util.Map;
-
-public class FixturesService extends AbstractPollenService {
-
- private static final Log log = LogFactory.getLog(FixturesService.class);
-
- protected Map<String, PollenFixtures> fixtureSets = Maps.newHashMap();
-
- public PollenFixtures cleanDatabaseAndLoadFixtures(String fixturesSetName) {
-
- return loadFixtures(fixturesSetName, true);
-
- }
-
- public PollenFixtures loadFixtures(String fixturesSetName) {
-
- return loadFixtures(fixturesSetName, false);
-
- }
-
- protected PollenFixtures loadFixtures(String fixturesSetName, boolean cleanDatabase) {
-
- boolean devMode = serviceContext.getPollenServiceConfig().isDevMode();
-
- Preconditions.checkState(devMode);
-
- PollenFixtures fixtures = fixtureSets.get(fixturesSetName);
-
- if (fixtures == null) {
-
- fixtures = new PollenFixtures(fixturesSetName);
-
- fixtureSets.put(fixturesSetName, fixtures);
-
- if (log.isInfoEnabled()) {
- log.info("will restore database with fixture set");
- }
-
- PollenPersistenceContext persistenceContext = serviceContext.getPersistenceContext();
-
- if (cleanDatabase) {
-
- persistenceContext.clearDatabase();
-
- }
-
- PollenUserJpaDao userDao = persistenceContext.getPollenUserDao();
-
- Collection<PollenUser> users = fixtures.fixture("users");
-
- for (PollenUser user : users) {
-
- user.setPassword(serviceContext.encodePassword(user.getPassword()));
- userDao.persist(user);
- }
-
- persistenceContext.commit();
-
-
- }
-
- return fixtures;
-
- }
-
-}
Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollResult.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollResult.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollResult.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,36 +0,0 @@
-package org.chorem.pollen.service;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import java.io.Serializable;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class PollResult implements Serializable {
- private static final long serialVersionUID = 1L;
-}
Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollService.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollService.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,200 +0,0 @@
-package org.chorem.pollen.service;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import com.google.common.base.Preconditions;
-import org.chorem.pollen.persistence.entity.Choice;
-import org.chorem.pollen.persistence.entity.Poll;
-import org.chorem.pollen.persistence.entity.PollenUser;
-import org.chorem.pollen.service.exception.EntityNotFoundException;
-
-import java.io.File;
-import java.util.List;
-import java.util.Set;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class PollService extends AbstractPollenService {
-
- public Set<Poll> getCreatedPolls(String userId) throws EntityNotFoundException {
- Preconditions.checkNotNull(userId);
-
- getUserService().getUser(userId);
-
- return getPersistenceContext().getPollDao().findAllCreated(userId);
- }
-
- public Set<Poll> getInvitedPolls(String userId) throws EntityNotFoundException {
- Preconditions.checkNotNull(userId);
-
- getUserService().getUser(userId);
-
- return getPersistenceContext().getPollDao().findAllInvited(userId);
- }
-
- public Set<Poll> getParticipatedPolls(String userId) throws EntityNotFoundException {
- Preconditions.checkNotNull(userId);
-
- getUserService().getUser(userId);
-
- return getPersistenceContext().getPollDao().findAllParticipated(userId);
- }
-
- public Poll getPoll(String pollId) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
- Poll result = getPersistenceContext().getPollDao().findById(pollId);
- checkEntityExists(Poll.class, result, pollId);
- return result;
- }
-
- public Poll createPoll(String userId, Poll poll) throws EntityNotFoundException {
- Preconditions.checkNotNull(userId);
- Preconditions.checkNotNull(poll);
- checkHasNoId(poll);
-
- if (userId != null) {
-
- // get user
- PollenUser user = getUserService().getUser(userId);
-
- // link it to creator
-
- }
-
- getPersistenceContext().getPollDao().persist(poll);
-
- getPersistenceContext().commit();
- return poll;
- }
-
- public Poll editPoll(Poll poll) throws EntityNotFoundException {
- Preconditions.checkNotNull(poll);
- checkHasId(poll);
-
- getPoll(poll.getId());
-
- getPersistenceContext().getPollDao().merge(poll);
- getPersistenceContext().commit();
-
- Poll result = getPoll(poll.getId());
- return result;
- }
-
- public void deletePoll(String pollId) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
-
- Poll poll = getPoll(pollId);
-
- getPersistenceContext().getPollDao().remove(poll);
- getPersistenceContext().commit();
- }
-
- public Poll clonePoll(String pollId) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
-
- Poll poll = getPoll(pollId);
- //TODO
- getPersistenceContext().commit();
- return null;
- }
-
- public File closePoll(String pollId) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
-
- Poll poll = getPoll(pollId);
- //TODO
- getPersistenceContext().commit();
- return null;
- }
-
- public File exportPoll(String pollId) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
- Poll poll = getPoll(pollId);
- //TODO
- return null;
- }
-
- public List<Choice> getChoices(String pollId) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
-
- Poll poll = getPoll(pollId);
-
- return poll.getChoice();
- }
-
- public Choice getChoice(String choiceId) throws EntityNotFoundException {
- Preconditions.checkNotNull(choiceId);
-
- Choice result = getPersistenceContext().getChoiceDao().findById(choiceId);
- checkEntityExists(Choice.class, result, choiceId);
- return result;
- }
-
- public Choice addChoice(String pollId, Choice choice) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
- Preconditions.checkNotNull(choice);
- checkHasNoId(choice);
-
- Poll poll = getPoll(pollId);
-
- poll.addChoice(choice);
-
- getPersistenceContext().getPollDao().merge(poll);
-
- getPersistenceContext().commit();
- Choice result = getChoice(choice.getId());
- return result;
- }
-
- public Choice editChoice(Choice choice) throws EntityNotFoundException {
- Preconditions.checkNotNull(choice);
- checkHasId(choice);
-
- getChoice(choice.getId());
-
- getPersistenceContext().getChoiceDao().merge(choice);
- getPersistenceContext().commit();
-
- Choice result = getChoice(choice.getId());
- return result;
- }
-
- public void deleteChoice(String pollId, String choiceId) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
- Preconditions.checkNotNull(choiceId);
-
- Poll poll = getPoll(pollId);
- Choice choice = getChoice(choiceId);
-
- poll.removeChoice(choice);
-
- getPersistenceContext().getPollDao().merge(poll);
-
- getPersistenceContext().commit();
- }
-}
Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenFixtures.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollenFixtures.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenFixtures.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,78 +0,0 @@
-package org.chorem.pollen.service;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import com.esotericsoftware.yamlbeans.YamlException;
-import com.esotericsoftware.yamlbeans.YamlReader;
-import org.apache.commons.io.Charsets;
-import org.apache.commons.io.IOUtils;
-import org.chorem.pollen.persistence.entity.Choice;
-import org.chorem.pollen.persistence.entity.Comment;
-import org.chorem.pollen.persistence.entity.FavoriteList;
-import org.chorem.pollen.persistence.entity.FavoriteListMember;
-import org.chorem.pollen.persistence.entity.Poll;
-import org.chorem.pollen.persistence.entity.PollenUser;
-import org.chorem.pollen.persistence.entity.Vote;
-import org.chorem.pollen.persistence.entity.VoterList;
-import org.chorem.pollen.persistence.entity.VoterListMember;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Map;
-
-public class PollenFixtures {
-
- protected Map<String, Object> fixtures;
-
- public PollenFixtures(String fixturesName) {
- String yamlPath = "/" + fixturesName + ".yaml";
- InputStream inputStream = PollenFixtures.class.getResourceAsStream(yamlPath);
- String yaml;
- try {
- yaml = IOUtils.toString(inputStream, Charsets.UTF_8);
- } catch (IOException e) {
- throw new IllegalArgumentException(fixturesName + " is not a valid fixtures set name", e);
- }
- YamlReader reader = new YamlReader(yaml);
- reader.getConfig().setClassTag("poll", Poll.class);
- reader.getConfig().setClassTag("user", PollenUser.class);
- reader.getConfig().setClassTag("favorite-list", FavoriteList.class);
- reader.getConfig().setClassTag("favorite-list-member", FavoriteListMember.class);
- reader.getConfig().setClassTag("comment", Comment.class);
- reader.getConfig().setClassTag("choice", Choice.class);
- reader.getConfig().setClassTag("voter-list", VoterList.class);
- reader.getConfig().setClassTag("voter-list-member", VoterListMember.class);
- reader.getConfig().setClassTag("vote", Vote.class);
-
- try {
- fixtures = (Map<String, Object>) reader.read();
- } catch (YamlException e) {
- throw new PollenTechnicalException("unable to read yaml file", e);
- }
- }
-
- public <E> E fixture(String id) {
- return (E) fixtures.get(id);
- }
-}
Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenServiceContext.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollenServiceContext.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenServiceContext.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,66 +0,0 @@
-package org.chorem.pollen.service;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.chorem.pollen.persistence.PollenPersistenceContext;
-import org.chorem.pollen.service.config.PollenServiceConfig;
-
-import java.util.Date;
-
-/**
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public interface PollenServiceContext {
-
- String generateUUID();
-
- Date getNow();
-
- PollenPersistenceContext getPersistenceContext();
-
- PollenServiceConfig getPollenServiceConfig();
-
- AuthService getAuthService();
-
- CommentService getCommentService();
-
- FavoriteListService getFavoriteListService();
-
- PollService getPollService();
-
- UserService getUserService();
-
- VoteCountingService getVoteCountingService();
-
- VoterListService getVoterListService();
-
- VoteService getVoteService();
-
- EmailService getEmailService();
-
- String generatePassword();
-
- String encodePassword(String password);
-}
Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenServiceSupport.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollenServiceSupport.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenServiceSupport.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,35 +0,0 @@
-package org.chorem.pollen.service;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public interface PollenServiceSupport {
-
- void setServiceContext(PollenServiceContext serviceContext);
-}
Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenTechnicalException.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollenTechnicalException.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/PollenTechnicalException.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,44 +0,0 @@
-package org.chorem.pollen.service;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-public class PollenTechnicalException extends RuntimeException {
-
- private static final long serialVersionUID = 1L;
-
- public PollenTechnicalException() {
- }
-
- public PollenTechnicalException(String message) {
- super(message);
- }
-
- public PollenTechnicalException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public PollenTechnicalException(Throwable cause) {
- super(cause);
- }
-}
Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/UserService.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/UserService.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/UserService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,244 +0,0 @@
-package org.chorem.pollen.service;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import com.google.common.base.Preconditions;
-import org.apache.commons.lang3.ObjectUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.chorem.pollen.persistence.dao.PollenUserJpaDao;
-import org.chorem.pollen.persistence.entity.PollenUser;
-import org.chorem.pollen.service.exception.EntityNotFoundException;
-import org.chorem.pollen.service.exception.UserEmailAlreadyUsedException;
-import org.chorem.pollen.service.exception.UserInvalidEmailActiviationTokenException;
-import org.chorem.pollen.service.exception.UserInvalidPasswordException;
-import org.chorem.pollen.service.exception.UserLoginAlreadyUsedException;
-import org.nuiton.util.beans.Binder;
-import org.nuiton.util.beans.BinderFactory;
-
-import java.util.List;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class UserService extends AbstractPollenService implements PollenServiceSupport {
-
- public List<PollenUser> getUsers() {
- return getPollenUserDao().findAll();
- }
-
- public PollenUser getUser(String userId) throws EntityNotFoundException {
- Preconditions.checkNotNull(userId);
-
- PollenUser result = getPollenUserDao().findById(userId);
- checkEntityExists(PollenUser.class, result, userId);
- return result;
- }
-
- public PollenUser createUser(PollenUser user, boolean generatePassword) throws UserLoginAlreadyUsedException, UserEmailAlreadyUsedException {
- Preconditions.checkNotNull(user);
- checkHasNoId(user);
- Preconditions.checkNotNull(user.getLogin());
- Preconditions.checkNotNull(user.getEmail());
-
- PollenUserJpaDao dao = getPollenUserDao();
-
- // check login is available
- boolean loginExists = dao.loginExists(user.getLogin());
- if (loginExists) {
- throw new UserLoginAlreadyUsedException(user.getLogin());
- }
-
- // check email is available
- boolean emailExists = dao.emailExists(user.getEmail());
- if (emailExists) {
- throw new UserEmailAlreadyUsedException(user.getEmail());
- }
-
- PollenUser toCreate = dao.newInstance();
-
- // add a emailValidationToken
- String emailValidationToken = generateId();
-
- String password;
- if (generatePassword) {
- // let's generate the new password
- password = serviceContext.generatePassword();
- } else {
- password = user.getPassword();
- }
-
- // encode the password
- String encodedPassword = serviceContext.encodePassword(password);
-
- toCreate.setLogin(user.getLogin());
- toCreate.setEmailActivationToken(emailValidationToken);
- toCreate.setPassword(encodedPassword);
-
- copyPollenUser(user, toCreate, true);
-
- dao.persist(toCreate);
- getPersistenceContext().commit();
-
- notifyUserCreated(toCreate);
-
- return toCreate;
- }
-
- public PollenUser editUser(PollenUser user) throws UserInvalidPasswordException, UserEmailAlreadyUsedException, EntityNotFoundException {
- Preconditions.checkNotNull(user);
- checkHasId(user);
-
- PollenUser persisted = getUser(user.getId());
-
- PollenUserJpaDao dao = getPollenUserDao();
-
- // check current password
- String encodedPassword = serviceContext.encodePassword(user.getPassword());
- if (!encodedPassword.equals(persisted.getPassword())) {
- throw new UserInvalidPasswordException();
- }
-
- boolean emailChanged = ObjectUtils.notEqual(persisted.getEmail(),
- user.getEmail());
-
- if (emailChanged) {
-
- // check this email is not used by another user
- boolean emailUsed = dao.emailExists(user.getEmail());
- if (emailUsed) {
- throw new UserEmailAlreadyUsedException(user.getEmail());
- }
-
- // add a new emailValidationtoken
- String emailValidationToken = generateId();
- persisted.setEmailActivationToken(emailValidationToken);
- }
-
- copyPollenUser(user, persisted, true);
-
- persisted = dao.merge(persisted);
- getPersistenceContext().commit();
-
- if (emailChanged) {
-
- notifyEmailChanged(persisted);
- }
- return persisted;
- }
-
- public void changePassword(String userId,
- String oldPassword,
- String newPassword) throws UserInvalidPasswordException, EntityNotFoundException {
- Preconditions.checkNotNull(userId);
- Preconditions.checkNotNull(oldPassword);
- Preconditions.checkNotNull(newPassword);
-
- PollenUser user = getUser(userId);
-
- // check current password
- String encodedPassword = serviceContext.encodePassword(user.getPassword());
- if (!encodedPassword.equals(user.getPassword())) {
- throw new UserInvalidPasswordException();
- }
-
- // encode new password and store it in user account
- String newEncodedPassword = serviceContext.encodePassword(newPassword);
- user.setPassword(newEncodedPassword);
-
- user = getPollenUserDao().merge(user);
- getPersistenceContext().commit();
-
- notifyPasswordChanged(user);
- }
-
- public void validateUserEmail(String userId,
- String token) throws EntityNotFoundException, UserInvalidEmailActiviationTokenException {
-
- Preconditions.checkNotNull(userId);
- Preconditions.checkNotNull(token);
-
- PollenUser user = getUser(userId);
-
- Preconditions.checkNotNull(user);
-
- boolean valid = ObjectUtils.equals(
- user.getEmailActivationToken(), token);
-
- if (!valid) {
- throw new UserInvalidEmailActiviationTokenException();
- }
-
- // reset token in database
- user.setEmailActivationToken(null);
-
- getPollenUserDao().merge(user);
- getPersistenceContext().commit();
- }
-
- protected void notifyUserCreated(PollenUser user) {
-
- //TODO
- }
-
- protected void notifyEmailChanged(PollenUser user) {
-
- //TODO
- }
-
- protected void notifyPasswordChanged(PollenUser user) {
-
- //TODO
- }
-
- protected PollenUserJpaDao getPollenUserDao() {
- return getPersistenceContext().getPollenUserDao();
- }
-
- /**
- * Copy {@code source} user account to {@code destination} one.
- * The email is lower cased in the {@code destination} user account.
- *
- * @param source user account to copy
- * @param destination which receive the copy
- */
- protected void copyPollenUser(PollenUser source,
- PollenUser destination,
- boolean copyEmail) {
- Binder<PollenUser, PollenUser> binder =
- BinderFactory.newBinder(PollenUser.class);
-
- binder.copy(source, destination,
- PollenUser.PROPERTY_ADMINISTRATOR,
- PollenUser.PROPERTY_NAME,
- PollenUser.PROPERTY_LANGUAGE);
-
- if (copyEmail) {
- // Don't keep case for email
- destination.setEmail(StringUtils.lowerCase(source.getEmail()));
- }
- }
-}
Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/VoteCountingService.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/VoteCountingService.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/VoteCountingService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,45 +0,0 @@
-package org.chorem.pollen.service;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import com.google.common.base.Preconditions;
-import org.chorem.pollen.persistence.entity.Poll;
-import org.chorem.pollen.service.exception.EntityNotFoundException;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class VoteCountingService extends AbstractPollenService {
-
- //GET /poll/{pollId}/results
- public PollResult getResult(String pollId) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
- Poll poll = getPollService().getPoll(pollId);
- //TODO
- return null;
- }
-}
Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/VoteService.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/VoteService.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/VoteService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,100 +0,0 @@
-package org.chorem.pollen.service;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import com.google.common.base.Preconditions;
-import org.chorem.pollen.persistence.entity.Poll;
-import org.chorem.pollen.persistence.entity.Vote;
-import org.chorem.pollen.service.exception.EntityNotFoundException;
-
-import java.util.List;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class VoteService extends AbstractPollenService {
-
- public List<Vote> getVotes(String pollId) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
-
- Poll poll = getPollService().getPoll(pollId);
- List<Vote> result = poll.getVote();
- return result;
- }
-
- public Vote getVote(String voteId) throws EntityNotFoundException{
- Preconditions.checkNotNull(voteId);
-
- Vote result = getPersistenceContext().getVoteDao().findById(voteId);
- checkEntityExists(Vote.class, result, voteId);
- return result;
- }
-
- public Vote addVote(String pollId, Vote vote)throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
- Preconditions.checkNotNull(vote);
- checkHasNoId(vote);
-
- Poll poll = getPollService().getPoll(pollId);
-
- poll.addVote(vote);
- getPersistenceContext().getPollDao().merge(poll);
-
- getPersistenceContext().commit();
- Vote result = getVote(vote.getId());
- return result;
- }
-
- public Vote editVote(Vote vote)throws EntityNotFoundException {
- Preconditions.checkNotNull(vote);
- checkHasId(vote);
-
- getVote(vote.getId());
-
- getPersistenceContext().getVoteDao().merge(vote);
- getPersistenceContext().commit();
-
- Vote result = getVote(vote.getId());
- return result;
- }
-
- public void deleteVote(String pollId, String voteId)throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
- Preconditions.checkNotNull(voteId);
-
- Poll poll = getPollService().getPoll(pollId);
-
- Vote vote = getVote(voteId);
-
- poll.removeVote(vote);
-
- getPersistenceContext().getPollDao().merge(poll);
-
- getPersistenceContext().commit();
- }
-
-}
Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/VoterListService.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/VoterListService.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/VoterListService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,200 +0,0 @@
-package org.chorem.pollen.service;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import com.google.common.base.Preconditions;
-import org.chorem.pollen.persistence.dao.VoterListJpaDao;
-import org.chorem.pollen.persistence.dao.VoterListMemberJpaDao;
-import org.chorem.pollen.persistence.entity.FavoriteList;
-import org.chorem.pollen.persistence.entity.FavoriteListMember;
-import org.chorem.pollen.persistence.entity.Poll;
-import org.chorem.pollen.persistence.entity.VoterList;
-import org.chorem.pollen.persistence.entity.VoterListMember;
-import org.chorem.pollen.service.exception.EntityNotFoundException;
-
-import java.util.List;
-import java.util.Set;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class VoterListService extends AbstractPollenService {
-
- public VoterList importFavoriteList(String pollId,
- String favoriteListId) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
- Preconditions.checkNotNull(favoriteListId);
-
- Poll poll = getPollService().getPoll(pollId);
-
- FavoriteList favoriteList = getFavoriteListService().getFavoriteList(favoriteListId);
-
- VoterListJpaDao dao = getPersistenceContext().getVoterListDao();
- VoterList result = dao.newInstance();
-
- result.setName(favoriteList.getName());
- result.setWeight(1d);
-
- VoterListMemberJpaDao voterListMemberDao =
- getPersistenceContext().getVoterListMemberDao();
-
- for (FavoriteListMember favoriteListMember : favoriteList.getFavoriteListMember()) {
-
- VoterListMember voterListMember = voterListMemberDao.newInstance();
- voterListMember.setWeight(1d);
- voterListMember.setEmail(favoriteListMember.getEmail());
- result.addVoterListMember(voterListMember);
- }
-
- poll.addVoterList(result);
-
- getPersistenceContext().getPollDao().merge(poll);
-
- getPersistenceContext().commit();
- return result;
- }
-
- public List<VoterList> getVoterLists(String pollId) throws EntityNotFoundException{
- Preconditions.checkNotNull(pollId);
-
- Poll poll = getPollService().getPoll(pollId);
-
- List<VoterList> result = poll.getVoterList();
- return result;
- }
-
- public VoterList getVoterList(String voterListId) throws EntityNotFoundException{
- Preconditions.checkNotNull(voterListId);
-
- VoterList result = getPersistenceContext().getVoterListDao().findById(voterListId);
- checkEntityExists(VoterList.class, result, voterListId);
-
- return result;
- }
-
- public VoterList addVoterList(String pollId, VoterList voterList) throws EntityNotFoundException{
- Preconditions.checkNotNull(pollId);
- Preconditions.checkNotNull(voterList);
- checkHasNoId(voterList);
-
- Poll poll = getPollService().getPoll(pollId);
-
- poll.addVoterList(voterList);
-
- getPersistenceContext().getPollDao().merge(poll);
- getPersistenceContext().commit();
- VoterList result = getVoterList(voterList.getId());
- return result;
- }
-
- public VoterList editVoterList(VoterList voterList) throws EntityNotFoundException{
- Preconditions.checkNotNull(voterList);
- checkHasId(voterList);
-
- getVoterList(voterList.getId());
-
- getPersistenceContext().getVoterListDao().merge(voterList);
- getPersistenceContext().commit();
- VoterList result = getVoterList(voterList.getId());
- return result;
- }
-
- public void deleteVoterList(String pollId, String voterListId) throws EntityNotFoundException{
- Preconditions.checkNotNull(pollId);
- Preconditions.checkNotNull(voterListId);
-
- Poll poll = getPollService().getPoll(pollId);
-
- VoterList voterList = getVoterList(voterListId);
-
- poll.removeVoterList(voterList);
-
- getPersistenceContext().getPollDao().merge(poll);
-
- getPersistenceContext().commit();
- }
-
- public Set<VoterListMember> getMembers(String voterListId) throws EntityNotFoundException{
- Preconditions.checkNotNull(voterListId);
-
- VoterList voterList = getVoterList(voterListId);
-
- Set<VoterListMember> result = voterList.getVoterListMember();
- return result;
- }
-
- public VoterListMember getMember(String memberId) throws EntityNotFoundException{
- Preconditions.checkNotNull(memberId);
-
- VoterListMember result = getPersistenceContext().getVoterListMemberDao().findById(memberId);
- checkEntityExists(VoterListMember.class, result, memberId);
- return result;
- }
-
- public VoterListMember addMember(String voterListId, VoterListMember member)throws EntityNotFoundException {
- Preconditions.checkNotNull(voterListId);
- Preconditions.checkNotNull(member);
- checkHasNoId(member);
-
- VoterList voterList = getVoterList(voterListId);
-
- voterList.addVoterListMember(member);
- getPersistenceContext().getVoterListDao().merge(voterList);
-
- getPersistenceContext().commit();
- VoterListMember result = getMember(member.getId());
- return result;
- }
-
- public VoterListMember editMember(VoterListMember member) throws EntityNotFoundException{
- Preconditions.checkNotNull(member);
- checkHasId(member);
-
- getMember(member.getId());
-
- getPersistenceContext().getVoterListMemberDao().merge(member);
-
- getPersistenceContext().commit();
- VoterListMember result = getMember(member.getId());
- return result;
- }
-
- public void deleteMember(String voterListId, String memberId) throws EntityNotFoundException{
- Preconditions.checkNotNull(voterListId);
- Preconditions.checkNotNull(memberId);
-
- VoterList voterList = getVoterList(voterListId);
-
- VoterListMember member = getMember(memberId);
- voterList.removeVoterListMember(member);
-
- getPersistenceContext().getVoterListDao().merge(voterList);
-
- getPersistenceContext().commit();
- }
-
-}
Deleted: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/package-info.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/package-info.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/service/package-info.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,30 +0,0 @@
-/**
- * Base Package for the pollen business service.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-package org.chorem.pollen.service;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java (from rev 3821, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/DefaultPollenServiceContext.java)
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,188 @@
+package org.chorem.pollen.services;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.chorem.pollen.persistence.PollenEntityIdFactory;
+import org.chorem.pollen.persistence.PollenPersistenceContext;
+import org.chorem.pollen.services.config.PollenServiceConfig;
+import org.chorem.pollen.services.service.AuthService;
+import org.chorem.pollen.services.service.CommentService;
+import org.chorem.pollen.services.service.EmailService;
+import org.chorem.pollen.services.service.FavoriteListService;
+import org.chorem.pollen.services.service.FixturesService;
+import org.chorem.pollen.services.service.PollService;
+import org.chorem.pollen.services.service.UserService;
+import org.chorem.pollen.services.service.VoteCountingService;
+import org.chorem.pollen.services.service.VoteService;
+import org.chorem.pollen.services.service.VoterListService;
+import org.nuiton.util.StringUtil;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Date;
+import java.util.Locale;
+
+public class DefaultPollenServiceContext implements PollenServiceContext {
+
+ protected PollenServiceConfig pollenServiceConfig;
+
+ protected PollenPersistenceContext persistenceContext;
+
+ protected Locale locale;
+
+ public void setPollenServiceConfig(PollenServiceConfig pollenServiceConfig) {
+ this.pollenServiceConfig = pollenServiceConfig;
+ }
+
+ public void setPersistenceContext(PollenPersistenceContext persistenceContext) {
+ this.persistenceContext = persistenceContext;
+ }
+
+ public void setLocale(Locale locale) {
+ this.locale = locale;
+ }
+
+ @Override
+ public PollenServiceConfig getPollenServiceConfig() {
+ return pollenServiceConfig;
+ }
+
+ @Override
+ public String generateToken() {
+ return PollenEntityIdFactory.generateId();
+ }
+
+ @Override
+ public Date getNow() {
+ Date now = new Date();
+ return now;
+ }
+
+ public String generatePassword() {
+ return RandomStringUtils.randomAlphanumeric(8);
+ }
+
+ @Override
+ public PollenPersistenceContext getPersistenceContext() {
+ return persistenceContext;
+ }
+
+ @Override
+ public AuthService getAuthService() {
+ return newService(AuthService.class);
+ }
+
+ @Override
+ public CommentService getCommentService() {
+ return newService(CommentService.class);
+ }
+
+ @Override
+ public FavoriteListService getFavoriteListService() {
+ return newService(FavoriteListService.class);
+ }
+
+ @Override
+ public PollService getPollService() {
+ return newService(PollService.class);
+ }
+
+ @Override
+ public UserService getUserService() {
+ return newService(UserService.class);
+ }
+
+ @Override
+ public VoteCountingService getVoteCountingService() {
+ return newService(VoteCountingService.class);
+ }
+
+ @Override
+ public VoterListService getVoterListService() {
+ return newService(VoterListService.class);
+ }
+
+ @Override
+ public VoteService getVoteService() {
+ return newService(VoteService.class);
+ }
+
+ @Override
+ public EmailService getEmailService() {
+ return newService(EmailService.class);
+ }
+
+ @Override
+ public FixturesService getFixturesService() {
+ return newService(FixturesService.class);
+ }
+
+ @Override
+ public String encodePassword(String password) {
+ return StringUtil.encodeMD5(password);
+ }
+
+ @Override
+ public Locale getLocale() {
+ if (locale==null) {
+ locale = Locale.getDefault();
+ }
+ return locale;
+ }
+
+ public <E extends PollenServiceSupport> E newService(Class<E> serviceClass) {
+
+ E service;
+
+ try {
+
+ Constructor<E> constructor = serviceClass.getConstructor();
+
+ service = constructor.newInstance();
+
+ } catch (NoSuchMethodException e) {
+
+ throw new PollenTechnicalException("all services must provide a default public constructor", e);
+
+ } catch (InvocationTargetException e) {
+
+ throw new PollenTechnicalException("unable to instantiate pollen service", e);
+
+ } catch (InstantiationException e) {
+
+ throw new PollenTechnicalException("unable to instantiate pollen service", e);
+
+ } catch (IllegalAccessException e) {
+
+ throw new PollenTechnicalException("unable to instantiate pollen service", e);
+ }
+
+ service.setServiceContext(this);
+
+ return service;
+
+ }
+
+}
Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollResult.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollResult.java)
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollResult.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollResult.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,36 @@
+package org.chorem.pollen.services;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import java.io.Serializable;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollResult implements Serializable {
+ private static final long serialVersionUID = 1L;
+}
Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenFixtures.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollenFixtures.java)
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenFixtures.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenFixtures.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,78 @@
+package org.chorem.pollen.services;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.esotericsoftware.yamlbeans.YamlException;
+import com.esotericsoftware.yamlbeans.YamlReader;
+import org.apache.commons.io.Charsets;
+import org.apache.commons.io.IOUtils;
+import org.chorem.pollen.persistence.entity.Choice;
+import org.chorem.pollen.persistence.entity.Comment;
+import org.chorem.pollen.persistence.entity.FavoriteList;
+import org.chorem.pollen.persistence.entity.FavoriteListMember;
+import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.persistence.entity.PollenUser;
+import org.chorem.pollen.persistence.entity.Vote;
+import org.chorem.pollen.persistence.entity.VoterList;
+import org.chorem.pollen.persistence.entity.VoterListMember;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+
+public class PollenFixtures {
+
+ protected Map<String, Object> fixtures;
+
+ public PollenFixtures(String fixturesName) {
+ String yamlPath = "/" + fixturesName + ".yaml";
+ InputStream inputStream = PollenFixtures.class.getResourceAsStream(yamlPath);
+ String yaml;
+ try {
+ yaml = IOUtils.toString(inputStream, Charsets.UTF_8);
+ } catch (IOException e) {
+ throw new IllegalArgumentException(fixturesName + " is not a valid fixtures set name", e);
+ }
+ YamlReader reader = new YamlReader(yaml);
+ reader.getConfig().setClassTag("poll", Poll.class);
+ reader.getConfig().setClassTag("user", PollenUser.class);
+ reader.getConfig().setClassTag("favorite-list", FavoriteList.class);
+ reader.getConfig().setClassTag("favorite-list-member", FavoriteListMember.class);
+ reader.getConfig().setClassTag("comment", Comment.class);
+ reader.getConfig().setClassTag("choice", Choice.class);
+ reader.getConfig().setClassTag("voter-list", VoterList.class);
+ reader.getConfig().setClassTag("voter-list-member", VoterListMember.class);
+ reader.getConfig().setClassTag("vote", Vote.class);
+
+ try {
+ fixtures = (Map<String, Object>) reader.read();
+ } catch (YamlException e) {
+ throw new PollenTechnicalException("unable to read yaml file", e);
+ }
+ }
+
+ public <E> E fixture(String id) {
+ return (E) fixtures.get(id);
+ }
+}
Added: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,10 @@
+package org.chorem.pollen.services;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollenSecurityContext {
+}
Property changes on: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java (from rev 3821, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollenServiceContext.java)
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,81 @@
+package org.chorem.pollen.services;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.chorem.pollen.persistence.PollenPersistenceContext;
+import org.chorem.pollen.services.config.PollenServiceConfig;
+import org.chorem.pollen.services.service.AuthService;
+import org.chorem.pollen.services.service.CommentService;
+import org.chorem.pollen.services.service.EmailService;
+import org.chorem.pollen.services.service.FavoriteListService;
+import org.chorem.pollen.services.service.FixturesService;
+import org.chorem.pollen.services.service.PollService;
+import org.chorem.pollen.services.service.UserService;
+import org.chorem.pollen.services.service.VoteCountingService;
+import org.chorem.pollen.services.service.VoteService;
+import org.chorem.pollen.services.service.VoterListService;
+
+import java.util.Date;
+import java.util.Locale;
+
+/**
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public interface PollenServiceContext {
+
+ String generateToken();
+
+ Date getNow();
+
+ PollenPersistenceContext getPersistenceContext();
+
+ PollenServiceConfig getPollenServiceConfig();
+
+ AuthService getAuthService();
+
+ CommentService getCommentService();
+
+ FavoriteListService getFavoriteListService();
+
+ PollService getPollService();
+
+ UserService getUserService();
+
+ VoteCountingService getVoteCountingService();
+
+ VoterListService getVoterListService();
+
+ VoteService getVoteService();
+
+ EmailService getEmailService();
+
+ FixturesService getFixturesService();
+
+ String generatePassword();
+
+ String encodePassword(String password);
+
+ Locale getLocale();
+}
Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollenServiceSupport.java)
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceSupport.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,35 @@
+package org.chorem.pollen.services;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public interface PollenServiceSupport {
+
+ void setServiceContext(PollenServiceContext serviceContext);
+}
Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenTechnicalException.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollenTechnicalException.java)
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenTechnicalException.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/PollenTechnicalException.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,44 @@
+package org.chorem.pollen.services;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+public class PollenTechnicalException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ public PollenTechnicalException() {
+ }
+
+ public PollenTechnicalException(String message) {
+ super(message);
+ }
+
+ public PollenTechnicalException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public PollenTechnicalException(Throwable cause) {
+ super(cause);
+ }
+}
Modified: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/config/PollenServiceConfig.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,4 +1,4 @@
-package org.chorem.pollen.service.config;
+package org.chorem.pollen.services.config;
/*
* #%L
@@ -27,7 +27,7 @@
import com.google.common.collect.Maps;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.chorem.pollen.service.PollenTechnicalException;
+import org.chorem.pollen.services.PollenTechnicalException;
import org.nuiton.util.config.ApplicationConfig;
import org.nuiton.util.config.ArgumentsParserException;
Modified: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/config/PollenServiceConfigOption.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,4 +1,4 @@
-package org.chorem.pollen.service.config;
+package org.chorem.pollen.services.config;
/*
* #%L
Modified: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/config/package-info.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/config/package-info.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/config/package-info.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -4,7 +4,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.0
*/
-package org.chorem.pollen.service.config;
+package org.chorem.pollen.services.config;
/*
* #%L
Modified: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/EntityNotFoundException.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/exception/EntityNotFoundException.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/EntityNotFoundException.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,4 +1,4 @@
-package org.chorem.pollen.service.exception;
+package org.chorem.pollen.services.exception;
/*
* #%L
Added: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListImportException.java
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListImportException.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListImportException.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,30 @@
+package org.chorem.pollen.services.exception;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class FavoriteListImportException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+
+ private String causeMessage;
+
+ public FavoriteListImportException(String causeMessage, Throwable cause) {
+ super(cause);
+ this.causeMessage = causeMessage;
+ }
+
+ public FavoriteListImportException(Throwable cause) {
+ this(cause.getMessage(), cause);
+ }
+
+ /** @return the error message source from import execution. */
+ public String getCauseMessage() {
+ return causeMessage;
+ }
+
+}
Property changes on: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListImportException.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,22 @@
+package org.chorem.pollen.services.exception;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class FavoriteListMemberEmailAlreadyUsedException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ protected final String email;
+
+ public FavoriteListMemberEmailAlreadyUsedException(String email) {
+ this.email = email;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+}
\ No newline at end of file
Property changes on: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberEmailAlreadyUsedException.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,22 @@
+package org.chorem.pollen.services.exception;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class FavoriteListMemberNameAlreadyUsedException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ protected final String name;
+
+ public FavoriteListMemberNameAlreadyUsedException(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
\ No newline at end of file
Property changes on: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNameAlreadyUsedException.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,11 @@
+package org.chorem.pollen.services.exception;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class FavoriteListMemberNotOwnedByFavoriteListException extends Throwable {
+ private static final long serialVersionUID = 1L;
+}
Property changes on: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListMemberNotOwnedByFavoriteListException.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,22 @@
+package org.chorem.pollen.services.exception;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class FavoriteListNameAlreadyUsedException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ protected final String name;
+
+ public FavoriteListNameAlreadyUsedException(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
\ No newline at end of file
Property changes on: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNameAlreadyUsedException.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,12 @@
+package org.chorem.pollen.services.exception;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class FavoriteListNotOwnedByUserException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+}
Property changes on: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/FavoriteListNotOwnedByUserException.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidSessionTokenException.java
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidSessionTokenException.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidSessionTokenException.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,12 @@
+package org.chorem.pollen.services.exception;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class InvalidSessionTokenException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+}
Property changes on: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidSessionTokenException.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserEmailAlreadyUsedException.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/exception/UserEmailAlreadyUsedException.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserEmailAlreadyUsedException.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,4 +1,4 @@
-package org.chorem.pollen.service.exception;
+package org.chorem.pollen.services.exception;
/*
* #%L
Modified: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserInvalidEmailActiviationTokenException.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/exception/UserInvalidEmailActiviationTokenException.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserInvalidEmailActiviationTokenException.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,4 +1,4 @@
-package org.chorem.pollen.service.exception;
+package org.chorem.pollen.services.exception;
/*
* #%L
Modified: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserInvalidPasswordException.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/exception/UserInvalidPasswordException.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserInvalidPasswordException.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,4 +1,4 @@
-package org.chorem.pollen.service.exception;
+package org.chorem.pollen.services.exception;
/*
* #%L
Modified: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserLoginAlreadyUsedException.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/exception/UserLoginAlreadyUsedException.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/exception/UserLoginAlreadyUsedException.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,4 +1,4 @@
-package org.chorem.pollen.service.exception;
+package org.chorem.pollen.services.exception;
/*
* #%L
Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/package-info.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/package-info.java)
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/package-info.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/package-info.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,30 @@
+/**
+ * Base Package for the pollen business service.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+package org.chorem.pollen.services;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java (from rev 3821, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/AbstractPollenService.java)
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/AbstractPollenService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,119 @@
+package org.chorem.pollen.services.service;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.common.base.Preconditions;
+import org.chorem.pollen.persistence.PollenPersistenceContext;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.PollenServiceSupport;
+import org.chorem.pollen.services.config.PollenServiceConfig;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.nuiton.jpa.api.JpaEntities;
+import org.nuiton.jpa.api.JpaEntity;
+
+import java.util.Date;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public abstract class AbstractPollenService implements PollenServiceSupport {
+
+ protected PollenServiceContext serviceContext;
+
+ protected void checkHasId(JpaEntity entity) {
+ Preconditions.checkState(JpaEntities.isEntityHasId(entity));
+ }
+
+ protected void checkHasNoId(JpaEntity entity) {
+ Preconditions.checkState(JpaEntities.isEntityHasNoId(entity));
+ }
+
+ @Override
+ public void setServiceContext(PollenServiceContext serviceContext) {
+ this.serviceContext = serviceContext;
+ }
+
+ protected Date getNow() {
+ return serviceContext.getNow();
+ }
+
+ protected String generateToken() {
+ return serviceContext.generateToken();
+ }
+
+ protected PollenPersistenceContext getPersistenceContext() {
+ return serviceContext.getPersistenceContext();
+ }
+
+ protected PollenServiceConfig getPollenServiceConfig() {
+ return serviceContext.getPollenServiceConfig();
+ }
+
+ protected AuthService getAuthService() {
+ return serviceContext.getAuthService();
+ }
+
+ protected CommentService getCommentService() {
+ return serviceContext.getCommentService();
+ }
+
+ protected FavoriteListService getFavoriteListService() {
+ return serviceContext.getFavoriteListService();
+ }
+
+ protected PollService getPollService() {
+ return serviceContext.getPollService();
+ }
+
+ protected UserService getUserService() {
+ return serviceContext.getUserService();
+ }
+
+ protected VoteCountingService getVoteCountingService() {
+ return serviceContext.getVoteCountingService();
+ }
+
+ protected VoterListService getVoterListService() {
+ return serviceContext.getVoterListService();
+ }
+
+ protected VoteService getVoteService() {
+ return serviceContext.getVoteService();
+ }
+
+ protected EmailService getEmailService() {
+ return serviceContext.getEmailService();
+ }
+
+ protected <E extends JpaEntity> void checkEntityExists(Class<E> type,
+ E entity,
+ String entityId) throws EntityNotFoundException {
+ if (entity == null) {
+ throw new EntityNotFoundException(type, entityId);
+ }
+ }
+}
Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/AuthService.java (from rev 3821, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/AuthService.java)
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/AuthService.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/AuthService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,127 @@
+package org.chorem.pollen.services.service;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.common.base.Preconditions;
+import org.chorem.pollen.persistence.dao.PollenUserJpaDao;
+import org.chorem.pollen.persistence.dao.SessionTokenJpaDao;
+import org.chorem.pollen.persistence.entity.PollenUser;
+import org.chorem.pollen.persistence.entity.SessionToken;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.chorem.pollen.services.exception.InvalidSessionTokenException;
+import org.chorem.pollen.services.exception.UserInvalidPasswordException;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class AuthService extends AbstractPollenService {
+
+ public String login(String login, String password) throws EntityNotFoundException, UserInvalidPasswordException {
+ Preconditions.checkNotNull(login);
+ Preconditions.checkNotNull(password);
+
+ PollenUser user = getPersistenceContext().getPollenUserDao().findByLogin(login);
+ if (user == null) {
+ throw new EntityNotFoundException(PollenUser.class, login);
+ }
+
+ String encodedPassword = serviceContext.encodePassword(password);
+ if (!encodedPassword.equals(user.getPassword())) {
+ throw new UserInvalidPasswordException();
+ }
+
+ // Create a new session Token
+ SessionTokenJpaDao dao = getPersistenceContext().getSessionTokenDao();
+
+ SessionToken sessionToken = dao.newInstance();
+ String token = serviceContext.generateToken();
+ String encodedToken = serviceContext.encodePassword(token);
+ sessionToken.setPollenUser(user);
+ sessionToken.setToken(encodedToken);
+ sessionToken.setCreationDate(serviceContext.getNow());
+
+ dao.persist(sessionToken);
+ getPersistenceContext().commit();
+
+ return token;
+ }
+
+ public void lostPassword(String login) throws EntityNotFoundException {
+ Preconditions.checkNotNull(login);
+
+ PollenUserJpaDao dao = getPersistenceContext().getPollenUserDao();
+
+ PollenUser user = dao.findByLogin(login);
+ if (user == null) {
+ throw new EntityNotFoundException(PollenUser.class, login);
+ }
+
+ // Generate a new password
+ String newPassword = serviceContext.generatePassword();
+ String encodedPassword = serviceContext.encodePassword(newPassword);
+ user.setPassword(encodedPassword);
+ dao.merge(user);
+ getPersistenceContext().commit();
+
+ notifyPasswordChanged(user, newPassword);
+ }
+
+ public void logout(String login, String token) throws EntityNotFoundException {
+ Preconditions.checkNotNull(login);
+ Preconditions.checkNotNull(token);
+ PollenUser user = getPersistenceContext().getPollenUserDao().findByLogin(login);
+ if (user == null) {
+ throw new EntityNotFoundException(PollenUser.class, login);
+ }
+
+ String encodedToken = serviceContext.encodePassword(token);
+
+ SessionTokenJpaDao dao = getPersistenceContext().getSessionTokenDao();
+
+ SessionToken sessionToken = dao.findByToken(encodedToken);
+ if (sessionToken == null) {
+ throw new EntityNotFoundException(SessionToken.class, token);
+ }
+
+ dao.remove(sessionToken);
+ getPersistenceContext().commit();
+ }
+
+ public SessionToken getUserByAuth(String authParam) throws InvalidSessionTokenException {
+
+ SessionToken sessionToken = getPersistenceContext().getSessionTokenDao().findByToken(authParam);
+ if (sessionToken == null) {
+ throw new InvalidSessionTokenException();
+ }
+
+ return sessionToken;
+ }
+
+ protected void notifyPasswordChanged(PollenUser user, String newPassword) {
+ //TODO
+ }
+}
Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/CommentService.java)
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,94 @@
+package org.chorem.pollen.services.service;
+
+/*
+ * #%L
+ * Pollen :: Service API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.common.base.Preconditions;
+import org.chorem.pollen.persistence.entity.Comment;
+import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+
+import java.util.List;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class CommentService extends AbstractPollenService {
+
+ public List<Comment> getComments(String pollId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
+ Poll poll = getPollService().getPoll(pollId);
+ return poll.getComment();
+ }
+
+ public Comment getComment(String commentId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(commentId);
+ Comment result = getPersistenceContext().getCommentDao().findById(commentId);
+ checkEntityExists(Comment.class, result, commentId);
+ return result;
+ }
+
+ public Comment addComment(String pollId, Comment comment) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
+ checkHasNoId(comment);
+ Poll poll = getPollService().getPoll(pollId);
+
+ poll.addComment(comment);
+ getPersistenceContext().getPollDao().merge(poll);
+ getPersistenceContext().commit();
+
+ Comment result = getComment(comment.getId());
+ return result;
+ }
+
+ public Comment editComment(Comment comment) throws EntityNotFoundException {
+
+ // check comment exists
+ getComment(comment.getId());
+
+ getPersistenceContext().getCommentDao().merge(comment);
+ getPersistenceContext().commit();
+
+ Comment result = getComment(comment.getId());
+ return result;
+ }
+
+ public void deleteComment(String pollId, String commentId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
+ Preconditions.checkNotNull(commentId);
+ Poll poll = getPollService().getPoll(pollId);
+
+ Comment comment = getComment(commentId);
+ Preconditions.checkNotNull(comment);
+
+ poll.removeComment(comment);
+
+ getPersistenceContext().getPollDao().merge(poll);
+
+ getPersistenceContext().commit();
+ }
+
+}
Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/EmailService.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/EmailService.java)
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/EmailService.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/EmailService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,39 @@
+package org.chorem.pollen.services.service;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.chorem.pollen.persistence.entity.PollenUser;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class EmailService extends AbstractPollenService {
+
+ public void onUserCreated(PollenUser user) {
+ //TODO
+ }
+}
Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/FavoriteListService.java)
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,547 @@
+package org.chorem.pollen.services.service;
+
+/*
+ * #%L
+ * Pollen :: Service API
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Sets;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.chorem.pollen.persistence.entity.FavoriteList;
+import org.chorem.pollen.persistence.entity.FavoriteListMember;
+import org.chorem.pollen.persistence.entity.PollenUser;
+import org.chorem.pollen.services.PollenTechnicalException;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.chorem.pollen.services.exception.FavoriteListImportException;
+import org.chorem.pollen.services.exception.FavoriteListMemberEmailAlreadyUsedException;
+import org.chorem.pollen.services.exception.FavoriteListMemberNameAlreadyUsedException;
+import org.chorem.pollen.services.exception.FavoriteListMemberNotOwnedByFavoriteListException;
+import org.chorem.pollen.services.exception.FavoriteListNameAlreadyUsedException;
+import org.chorem.pollen.services.exception.FavoriteListNotOwnedByUserException;
+import org.nuiton.util.StringUtil;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InitialDirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.List;
+import java.util.Locale;
+import java.util.Properties;
+import java.util.Set;
+
+import static org.nuiton.i18n.I18n.l_;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class FavoriteListService extends AbstractPollenService {
+
+ public List<FavoriteList> getFavoriteLists(String userId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(userId);
+ PollenUser user = getUserService().getUser(userId);
+
+ List<FavoriteList> result = user.getFavoriteList();
+ return result;
+ }
+
+ public FavoriteList getFavoriteList(String favoriteListId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(favoriteListId);
+ FavoriteList result = getPersistenceContext().getFavoriteListDao().findById(favoriteListId);
+ checkEntityExists(FavoriteList.class, result, favoriteListId);
+ return result;
+ }
+
+ public FavoriteList createFavoriteList(String userId,
+ FavoriteList favoriteList) throws EntityNotFoundException, FavoriteListNameAlreadyUsedException {
+ Preconditions.checkNotNull(userId);
+ Preconditions.checkNotNull(favoriteList);
+ checkHasNoId(favoriteList);
+
+ String favoriteListName = favoriteList.getName();
+
+ // can't accept favorite list without name
+ Preconditions.checkArgument(StringUtils.isNotEmpty(favoriteListName));
+
+ PollenUser user = getUserService().getUser(userId);
+
+ // check there is not already a favorite list with same name
+ boolean nameFound = false;
+ if (!user.isFavoriteListEmpty()) {
+ for (FavoriteList list : user.getFavoriteList()) {
+ if (favoriteListName.equals(list.getName())) {
+ nameFound = true;
+ break;
+ }
+ }
+ }
+
+ if (nameFound) {
+ throw new FavoriteListNameAlreadyUsedException(favoriteListName);
+ }
+
+ FavoriteList toSave = getPersistenceContext().getFavoriteListDao().newInstance();
+ copyFavoriteList(favoriteList, toSave);
+
+ user.addFavoriteList(toSave);
+ getPersistenceContext().getPollenUserDao().merge(user);
+
+ getPersistenceContext().commit();
+ return toSave;
+ }
+
+ public FavoriteList editFavoriteList(String userId,
+ FavoriteList favoriteList) throws EntityNotFoundException, FavoriteListNameAlreadyUsedException, FavoriteListNotOwnedByUserException {
+ Preconditions.checkNotNull(favoriteList);
+ checkHasId(favoriteList);
+
+ String favoriteListName = favoriteList.getName();
+
+ // can't accept favorite list without name
+ Preconditions.checkArgument(StringUtils.isNotEmpty(favoriteListName));
+
+ // get user
+ PollenUser user = getUserService().getUser(userId);
+
+ // get list
+ FavoriteList toSave = getFavoriteList(favoriteList.getId());
+
+ // check user own this list
+ boolean ownedByUser = user.containsFavoriteListById(favoriteList.getId());
+
+ if (!ownedByUser) {
+ throw new FavoriteListNotOwnedByUserException();
+ }
+
+ if (ObjectUtils.notEqual(favoriteListName, toSave.getName())) {
+
+ // check that this name is not existing in another list
+ boolean nameFound = false;
+ if (!user.isFavoriteListEmpty()) {
+ for (FavoriteList list : user.getFavoriteList()) {
+ if (toSave != list &&
+ favoriteListName.equals(list.getName())) {
+
+ // found another list with same name
+ nameFound = true;
+ break;
+ }
+ }
+ }
+ if (nameFound) {
+ throw new FavoriteListNameAlreadyUsedException(favoriteListName);
+ }
+ }
+
+ copyFavoriteList(favoriteList, toSave);
+ getPersistenceContext().getFavoriteListDao().merge(toSave);
+
+ getPersistenceContext().commit();
+ return toSave;
+ }
+
+ public void deleteFavoriteList(String userId, String favoriteListId) throws EntityNotFoundException, FavoriteListNotOwnedByUserException {
+ Preconditions.checkNotNull(userId);
+ Preconditions.checkNotNull(favoriteListId);
+
+ PollenUser user = getUserService().getUser(userId);
+
+ FavoriteList persisted = getFavoriteList(favoriteListId);
+
+ // check user own this list
+ boolean ownedByUser = user.containsFavoriteListById(favoriteListId);
+ if (!ownedByUser) {
+ throw new FavoriteListNotOwnedByUserException();
+ }
+
+ user.removeFavoriteList(persisted);
+ getPersistenceContext().getPollenUserDao().merge(user);
+
+ getPersistenceContext().commit();
+ }
+
+ public List<FavoriteListMember> getFavoriteListMembers(String favoriteListId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(favoriteListId);
+
+ FavoriteList favoriteList = getFavoriteList(favoriteListId);
+
+ return favoriteList.getFavoriteListMember();
+ }
+
+ public FavoriteListMember getFavoriteListMember(String memberId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(memberId);
+ FavoriteListMember result = getPersistenceContext().getFavoriteListMemberDao().findById(memberId);
+ checkEntityExists(FavoriteListMember.class, result, memberId);
+ return result;
+ }
+
+ public FavoriteListMember addFavoriteListMember(String favoriteListId,
+ FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberNameAlreadyUsedException, FavoriteListMemberEmailAlreadyUsedException {
+ Preconditions.checkNotNull(favoriteListId);
+ Preconditions.checkNotNull(member);
+ checkHasNoId(member);
+
+ // can't accept member without name
+ String memberName = member.getName();
+ Preconditions.checkArgument(StringUtils.isNotEmpty(memberName));
+
+ // can't accept member without email
+ String memberEmail = member.getEmail();
+ Preconditions.checkArgument(StringUtils.isNotEmpty(memberEmail));
+
+ // lowerCase email
+ memberEmail = StringUtils.lowerCase(memberEmail);
+
+ //TODO Validate email form
+
+ FavoriteList favoriteList = getFavoriteList(favoriteListId);
+
+ if (!favoriteList.isFavoriteListMemberEmpty()) {
+
+ for (FavoriteListMember listMember : favoriteList.getFavoriteListMember()) {
+
+ // check there is no other member with same name
+ if (memberName.equals(listMember.getName())) {
+ throw new FavoriteListMemberNameAlreadyUsedException(memberName);
+ }
+ // check there is no other member with same email
+ if (memberEmail.equals(listMember.getEmail())) {
+ throw new FavoriteListMemberEmailAlreadyUsedException(memberEmail);
+ }
+ }
+ }
+
+ FavoriteListMember newMember =
+ getPersistenceContext().getFavoriteListMemberDao().newInstance();
+ copyFavoriteListMember(member, newMember);
+ favoriteList.addFavoriteListMember(newMember);
+
+ getPersistenceContext().getFavoriteListDao().merge(favoriteList);
+
+ getPersistenceContext().commit();
+ return newMember;
+ }
+
+ public FavoriteListMember editFavoriteListMember(String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException, FavoriteListMemberNameAlreadyUsedException, FavoriteListMemberEmailAlreadyUsedException {
+ Preconditions.checkNotNull(member);
+ checkHasId(member);
+
+ // can't accept member without name
+ String memberName = member.getName();
+ Preconditions.checkArgument(StringUtils.isNotEmpty(memberName));
+
+ // can't accept member without email
+ String memberEmail = member.getEmail();
+ Preconditions.checkArgument(StringUtils.isNotEmpty(memberEmail));
+
+ // lowerCase email
+ memberEmail = StringUtils.lowerCase(memberEmail);
+
+ //TODO Validate email form
+
+ FavoriteList favoriteList = getFavoriteList(favoriteListId);
+
+ String memberId = member.getId();
+
+ FavoriteListMember toSave = getFavoriteListMember(memberId);
+
+ // check favorite list own this member
+ boolean ownedByUser = favoriteList.containsFavoriteListMemberById(memberId);
+ if (!ownedByUser) {
+ throw new FavoriteListMemberNotOwnedByFavoriteListException();
+ }
+
+
+ if (!memberName.equals(toSave.getName())) {
+
+ // name has changed must check name is available in the list
+ for (FavoriteListMember listMember : favoriteList.getFavoriteListMember()) {
+
+ // check there is no other member with same name
+ if (!memberId.equals(listMember.getId()) &&
+ memberName.equals(listMember.getName())) {
+ throw new FavoriteListMemberNameAlreadyUsedException(memberName);
+ }
+ }
+ }
+
+ if (!memberEmail.equals(toSave.getEmail())) {
+
+ // email has changed must check name is available in the list
+ for (FavoriteListMember listMember : favoriteList.getFavoriteListMember()) {
+
+ if (!memberId.equals(listMember.getId()) &&
+ memberEmail.equals(listMember.getEmail())) {
+ throw new FavoriteListMemberEmailAlreadyUsedException(memberEmail);
+ }
+ }
+ }
+ copyFavoriteListMember(member, toSave);
+
+ getPersistenceContext().getFavoriteListMemberDao().merge(toSave);
+
+ getPersistenceContext().commit();
+ return toSave;
+ }
+
+ public void removeFavoriteListMember(String favoriteListId, String memberId) throws EntityNotFoundException, FavoriteListMemberNotOwnedByFavoriteListException {
+ Preconditions.checkNotNull(favoriteListId);
+ Preconditions.checkNotNull(memberId);
+
+ FavoriteList favoriteList = getFavoriteList(favoriteListId);
+
+ FavoriteListMember member = getFavoriteListMember(memberId);
+
+ // check favorite list own this member
+ boolean ownedByUser = favoriteList.containsFavoriteListMemberById(memberId);
+ if (!ownedByUser) {
+ throw new FavoriteListMemberNotOwnedByFavoriteListException();
+ }
+
+ favoriteList.removeFavoriteListMember(member);
+
+ getPersistenceContext().getFavoriteListDao().merge(favoriteList);
+ getPersistenceContext().commit();
+ }
+
+ public int importFavoriteListMembersFromCsv(String userId, String favoriteListId,
+ File file) throws EntityNotFoundException, FavoriteListImportException, FavoriteListNotOwnedByUserException {
+ Preconditions.checkNotNull(userId);
+ Preconditions.checkNotNull(favoriteListId);
+ Preconditions.checkNotNull(file);
+
+ PollenUser user = getUserService().getUser(userId);
+
+ FavoriteList favoriteList = getFavoriteList(favoriteListId);
+
+ // check user own this list
+ boolean ownedByUser = user.containsFavoriteListById(favoriteListId);
+ if (!ownedByUser) {
+ throw new FavoriteListNotOwnedByUserException();
+ }
+
+ Locale locale = serviceContext.getLocale();
+
+ Set<String> usedName = Sets.newHashSet();
+ Set<String> usedEmail = Sets.newHashSet();
+
+ if (!favoriteList.isFavoriteListMemberEmpty()) {
+ for (FavoriteListMember member : favoriteList.getFavoriteListMember()) {
+ usedName.add(member.getName());
+ usedEmail.add(member.getEmail());
+ }
+ }
+
+ int result = 0;
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new FileReader(file));
+ String line;
+ int lineNumber = 0;
+ while ((line = reader.readLine()) != null) {
+ line = line.trim();
+ if (StringUtils.isBlank(line) || line.startsWith("#")) {
+
+ // comment line
+ continue;
+ }
+ lineNumber++;
+ result++;
+
+ int spaceIndex = line.indexOf(' ');
+ String email;
+ String memberName;
+ if (spaceIndex == -1) {
+ // only email
+ email = line;
+ memberName = line;
+ } else {
+ // email + name
+ email = line.substring(0, spaceIndex);
+ memberName = line.substring(spaceIndex);
+ }
+ memberName = memberName.trim();
+
+ if (!usedName.add(memberName)) {
+ // name already exists
+ String error = l_(locale, "pollen.error.favoriteList.import.csv.already.used.name", lineNumber, memberName);
+ throw new FavoriteListImportException(error, null);
+ }
+
+ email = email.toLowerCase().trim();
+ if (!usedEmail.add(email)) {
+ // email already exists
+ String error = l_(locale, "pollen.error.favoriteList.import.csv.already.used.email", lineNumber, email);
+ throw new FavoriteListImportException(error, null);
+ }
+
+ if (!StringUtil.isEmail(email)) {
+
+ // email is not valid
+ String error = l_(locale, "pollen.error.favoriteList.import.csv.invalid.email", lineNumber, email);
+ throw new FavoriteListImportException(error, null);
+ }
+
+ FavoriteListMember member = getPersistenceContext().getFavoriteListMemberDao().newInstance();
+ member.setName(memberName);
+ member.setEmail(email);
+
+ favoriteList.addFavoriteListMember(member);
+ }
+
+ reader.close();
+
+ } catch (FileNotFoundException e) {
+ // should never happens ?
+ throw new PollenTechnicalException(e);
+ } catch (IOException e) {
+ // should never happens ?
+ throw new PollenTechnicalException(e);
+ } finally {
+ IOUtils.closeQuietly(reader);
+ }
+
+ getPersistenceContext().getFavoriteListDao().merge(favoriteList);
+
+ getPersistenceContext().commit();
+
+ return result;
+ }
+
+ public int importFavoriteListMembersFromLdap(String userId,
+ String favoriteListId,
+ String ldap) throws EntityNotFoundException, FavoriteListImportException, FavoriteListNotOwnedByUserException {
+ Preconditions.checkNotNull(favoriteListId);
+ Preconditions.checkNotNull(ldap);
+
+ PollenUser user = getUserService().getUser(userId);
+
+ FavoriteList favoriteList = getFavoriteList(favoriteListId);
+
+ // check user own this list
+ boolean ownedByUser = user.containsFavoriteListById(favoriteListId);
+ if (!ownedByUser) {
+ throw new FavoriteListNotOwnedByUserException();
+ }
+
+ Locale locale = serviceContext.getLocale();
+
+ Set<String> usedName = Sets.newHashSet();
+ Set<String> usedEmail = Sets.newHashSet();
+
+ if (!favoriteList.isFavoriteListMemberEmpty()) {
+ for (FavoriteListMember member : favoriteList.getFavoriteListMember()) {
+ usedName.add(member.getName());
+ usedEmail.add(member.getEmail());
+ }
+ }
+
+ int result = 0;
+
+ try {
+
+ // Initialisation du contexte
+ Properties env = new Properties();
+
+ DirContext ictx = new InitialDirContext(env);
+
+ // Recherche en profondeur
+ SearchControls control = new SearchControls();
+ control.setSearchScope(SearchControls.SUBTREE_SCOPE);
+
+ // Création des comptes avec les résultats de la recherche
+ NamingEnumeration<SearchResult> e = ictx.search(ldap, null, control);
+ while (e.hasMore()) {
+ SearchResult r = e.next();
+
+ Attribute attrName = r.getAttributes().get("cn");
+ Attribute attrEmail = r.getAttributes().get("mail");
+
+ if (attrName != null) {
+
+ result++;
+
+ String memberName = attrName.get().toString().trim();
+
+ if (!usedName.add(memberName)) {
+ // name already exists
+ String error = l_(locale, "pollen.error.favoriteList.import.ldap.already.used.name", memberName);
+ throw new FavoriteListImportException(error, null);
+ }
+
+ String email = attrEmail.get().toString().toLowerCase().trim();
+
+ if (!usedEmail.add(email)) {
+ // email already exists
+ String error = l_(locale, "pollen.error.favoriteList.import.ldap.already.used.email", email);
+ throw new FavoriteListImportException(error, null);
+ }
+
+ if (!StringUtil.isEmail(email)) {
+
+ // email is not valid
+ String error = l_(locale, "pollen.error.favoriteList.import.ldap.invalid.email", email);
+ throw new FavoriteListImportException(error, null);
+ }
+
+ FavoriteListMember member = getPersistenceContext().getFavoriteListMemberDao().newInstance();
+ member.setName(memberName);
+ member.setEmail(email);
+
+ favoriteList.addFavoriteListMember(member);
+ }
+ }
+ } catch (NamingException ex) {
+ throw new FavoriteListImportException("LDAP", ex);
+ }
+
+ getPersistenceContext().getFavoriteListDao().merge(favoriteList);
+
+ getPersistenceContext().commit();
+ return result;
+ }
+
+ protected void copyFavoriteList(FavoriteList source,
+ FavoriteList destination) {
+
+ destination.setName(source.getName());
+ }
+
+ protected void copyFavoriteListMember(FavoriteListMember source,
+ FavoriteListMember destination) {
+
+ destination.setName(source.getName());
+ destination.setEmail(StringUtils.lowerCase(source.getEmail()));
+ }
+}
Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/FixturesService.java)
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/FixturesService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,101 @@
+package org.chorem.pollen.services.service;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.persistence.PollenPersistenceContext;
+import org.chorem.pollen.persistence.dao.PollenUserJpaDao;
+import org.chorem.pollen.persistence.entity.PollenUser;
+import org.chorem.pollen.services.PollenFixtures;
+
+import java.util.Collection;
+import java.util.Map;
+
+public class FixturesService extends AbstractPollenService {
+
+ private static final Log log = LogFactory.getLog(FixturesService.class);
+
+ protected Map<String, PollenFixtures> fixtureSets = Maps.newHashMap();
+
+ public PollenFixtures cleanDatabaseAndLoadFixtures(String fixturesSetName) {
+
+ return loadFixtures(fixturesSetName, true);
+
+ }
+
+ public PollenFixtures loadFixtures(String fixturesSetName) {
+
+ return loadFixtures(fixturesSetName, false);
+
+ }
+
+ protected PollenFixtures loadFixtures(String fixturesSetName, boolean cleanDatabase) {
+
+ boolean devMode = serviceContext.getPollenServiceConfig().isDevMode();
+
+ Preconditions.checkState(devMode);
+
+ PollenFixtures fixtures = fixtureSets.get(fixturesSetName);
+
+ if (fixtures == null) {
+
+ fixtures = new PollenFixtures(fixturesSetName);
+
+ fixtureSets.put(fixturesSetName, fixtures);
+
+ if (log.isInfoEnabled()) {
+ log.info("will restore database with fixture set");
+ }
+
+ PollenPersistenceContext persistenceContext = serviceContext.getPersistenceContext();
+
+ if (cleanDatabase) {
+
+ persistenceContext.clearDatabase();
+
+ }
+
+ PollenUserJpaDao userDao = persistenceContext.getPollenUserDao();
+
+ Collection<PollenUser> users = fixtures.fixture("users");
+
+ for (PollenUser user : users) {
+
+ user.setPassword(serviceContext.encodePassword(user.getPassword()));
+ userDao.persist(user);
+ }
+
+ persistenceContext.commit();
+
+
+ }
+
+ return fixtures;
+
+ }
+
+}
Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java (from rev 3820, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/PollService.java)
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,205 @@
+package org.chorem.pollen.services.service;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Sets;
+import org.chorem.pollen.persistence.entity.Choice;
+import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.persistence.entity.PollenUser;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+
+import java.io.File;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollService extends AbstractPollenService {
+
+ public Set<Poll> getCreatedPolls(String userId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(userId);
+
+ getUserService().getUser(userId);
+
+ return getPersistenceContext().getPollDao().findAllCreated(userId);
+ }
+
+ public Set<Poll> getInvitedPolls(String userId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(userId);
+
+ getUserService().getUser(userId);
+
+ return getPersistenceContext().getPollDao().findAllInvited(userId);
+ }
+
+ public Set<Poll> getParticipatedPolls(String userId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(userId);
+
+ getUserService().getUser(userId);
+
+ return getPersistenceContext().getPollDao().findAllParticipated(userId);
+ }
+
+ public Poll getPoll(String pollId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
+ Poll result = getPersistenceContext().getPollDao().findById(pollId);
+ checkEntityExists(Poll.class, result, pollId);
+ return result;
+ }
+
+ public Poll createPoll(String userId, Poll poll) throws EntityNotFoundException {
+ Preconditions.checkNotNull(userId);
+ Preconditions.checkNotNull(poll);
+ checkHasNoId(poll);
+
+ if (userId != null) {
+
+ // get user
+ PollenUser user = getUserService().getUser(userId);
+
+ // link it to creator
+
+ }
+
+ getPersistenceContext().getPollDao().persist(poll);
+
+ getPersistenceContext().commit();
+ return poll;
+ }
+
+ public Poll editPoll(Poll poll) throws EntityNotFoundException {
+ Preconditions.checkNotNull(poll);
+ checkHasId(poll);
+
+ getPoll(poll.getId());
+
+ getPersistenceContext().getPollDao().merge(poll);
+ getPersistenceContext().commit();
+
+ Poll result = getPoll(poll.getId());
+ return result;
+ }
+
+ public void deletePoll(String pollId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
+
+ Poll poll = getPoll(pollId);
+
+ getPersistenceContext().getPollDao().remove(poll);
+ getPersistenceContext().commit();
+ }
+
+ public Poll clonePoll(String pollId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
+
+ Poll poll = getPoll(pollId);
+ //TODO
+ getPersistenceContext().commit();
+ return null;
+ }
+
+ public File closePoll(String pollId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
+
+ Poll poll = getPoll(pollId);
+ //TODO
+ getPersistenceContext().commit();
+ return null;
+ }
+
+ public File exportPoll(String pollId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
+ Poll poll = getPoll(pollId);
+ //TODO
+ return null;
+ }
+
+ public List<Choice> getChoices(String pollId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
+
+ Poll poll = getPoll(pollId);
+
+ return poll.getChoice();
+ }
+
+ public Choice getChoice(String choiceId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(choiceId);
+
+ Choice result = getPersistenceContext().getChoiceDao().findById(choiceId);
+ checkEntityExists(Choice.class, result, choiceId);
+ return result;
+ }
+
+ public Choice addChoice(String pollId, Choice choice) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
+ Preconditions.checkNotNull(choice);
+ checkHasNoId(choice);
+
+ Poll poll = getPoll(pollId);
+
+ poll.addChoice(choice);
+
+ getPersistenceContext().getPollDao().merge(poll);
+
+ getPersistenceContext().commit();
+ Choice result = getChoice(choice.getId());
+ return result;
+ }
+
+ public Choice editChoice(Choice choice) throws EntityNotFoundException {
+ Preconditions.checkNotNull(choice);
+ checkHasId(choice);
+
+ getChoice(choice.getId());
+
+ getPersistenceContext().getChoiceDao().merge(choice);
+ getPersistenceContext().commit();
+
+ Choice result = getChoice(choice.getId());
+ return result;
+ }
+
+ public void deleteChoice(String pollId, String choiceId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
+ Preconditions.checkNotNull(choiceId);
+
+ Poll poll = getPoll(pollId);
+ Choice choice = getChoice(choiceId);
+
+ poll.removeChoice(choice);
+
+ getPersistenceContext().getPollDao().merge(poll);
+
+ getPersistenceContext().commit();
+ }
+
+ public Set<Poll> getPolls(String userId) throws EntityNotFoundException {
+ return Sets.newHashSet(getPersistenceContext().getPollDao().findAll());
+ }
+}
Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/UserService.java (from rev 3821, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/UserService.java)
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/UserService.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/UserService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,252 @@
+package org.chorem.pollen.services.service;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.chorem.pollen.persistence.dao.PollenUserJpaDao;
+import org.chorem.pollen.persistence.entity.PollenUser;
+import org.chorem.pollen.services.PollenServiceSupport;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.chorem.pollen.services.exception.UserEmailAlreadyUsedException;
+import org.chorem.pollen.services.exception.UserInvalidEmailActiviationTokenException;
+import org.chorem.pollen.services.exception.UserInvalidPasswordException;
+import org.chorem.pollen.services.exception.UserLoginAlreadyUsedException;
+
+import java.util.List;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)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(a)pollen.org");
+ user.setPassword("admin");
+ createUser(user, false);
+ }
+
+ protected void notifyUserCreated(PollenUser user) {
+
+ //TODO
+ }
+
+ protected void notifyEmailChanged(PollenUser user) {
+
+ //TODO
+ }
+
+ protected void notifyPasswordChanged(PollenUser user) {
+
+ //TODO
+ }
+
+ protected PollenUserJpaDao getPollenUserDao() {
+ return getPersistenceContext().getPollenUserDao();
+ }
+
+ /**
+ * Copy {@code source} user account to {@code destination} one.
+ * The email is lower cased in the {@code destination} user account.
+ *
+ * @param source user account to copy
+ * @param destination which receive the copy
+ */
+ protected void copyPollenUser(PollenUser source,
+ PollenUser destination,
+ boolean copyEmail) {
+
+ destination.setAdministrator(source.isAdministrator());
+ destination.setName(source.getName());
+ destination.setLanguage(source.getLanguage());
+
+ if (copyEmail) {
+ // Don't keep case for email
+ destination.setEmail(StringUtils.lowerCase(source.getEmail()));
+ }
+ }
+}
Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingService.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/VoteCountingService.java)
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingService.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,46 @@
+package org.chorem.pollen.services.service;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.common.base.Preconditions;
+import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.services.PollResult;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class VoteCountingService extends AbstractPollenService {
+
+ //GET /poll/{pollId}/results
+ public PollResult getResult(String pollId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
+ Poll poll = getPollService().getPoll(pollId);
+ //TODO
+ return null;
+ }
+}
Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/VoteService.java)
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,100 @@
+package org.chorem.pollen.services.service;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.common.base.Preconditions;
+import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.persistence.entity.Vote;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+
+import java.util.List;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class VoteService extends AbstractPollenService {
+
+ public List<Vote> getVotes(String pollId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
+
+ Poll poll = getPollService().getPoll(pollId);
+ List<Vote> result = poll.getVote();
+ return result;
+ }
+
+ public Vote getVote(String voteId) throws EntityNotFoundException{
+ Preconditions.checkNotNull(voteId);
+
+ Vote result = getPersistenceContext().getVoteDao().findById(voteId);
+ checkEntityExists(Vote.class, result, voteId);
+ return result;
+ }
+
+ public Vote addVote(String pollId, Vote vote)throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
+ Preconditions.checkNotNull(vote);
+ checkHasNoId(vote);
+
+ Poll poll = getPollService().getPoll(pollId);
+
+ poll.addVote(vote);
+ getPersistenceContext().getPollDao().merge(poll);
+
+ getPersistenceContext().commit();
+ Vote result = getVote(vote.getId());
+ return result;
+ }
+
+ public Vote editVote(Vote vote)throws EntityNotFoundException {
+ Preconditions.checkNotNull(vote);
+ checkHasId(vote);
+
+ getVote(vote.getId());
+
+ getPersistenceContext().getVoteDao().merge(vote);
+ getPersistenceContext().commit();
+
+ Vote result = getVote(vote.getId());
+ return result;
+ }
+
+ public void deleteVote(String pollId, String voteId)throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
+ Preconditions.checkNotNull(voteId);
+
+ Poll poll = getPollService().getPoll(pollId);
+
+ Vote vote = getVote(voteId);
+
+ poll.removeVote(vote);
+
+ getPersistenceContext().getPollDao().merge(poll);
+
+ getPersistenceContext().commit();
+ }
+
+}
Copied: branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java (from rev 3819, branches/pollen-2.0/pollen-service/src/main/java/org/chorem/pollen/service/VoterListService.java)
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,200 @@
+package org.chorem.pollen.services.service;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.common.base.Preconditions;
+import org.chorem.pollen.persistence.dao.VoterListJpaDao;
+import org.chorem.pollen.persistence.dao.VoterListMemberJpaDao;
+import org.chorem.pollen.persistence.entity.FavoriteList;
+import org.chorem.pollen.persistence.entity.FavoriteListMember;
+import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.persistence.entity.VoterList;
+import org.chorem.pollen.persistence.entity.VoterListMember;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class VoterListService extends AbstractPollenService {
+
+ public VoterList importFavoriteList(String pollId,
+ String favoriteListId) throws EntityNotFoundException {
+ Preconditions.checkNotNull(pollId);
+ Preconditions.checkNotNull(favoriteListId);
+
+ Poll poll = getPollService().getPoll(pollId);
+
+ FavoriteList favoriteList = getFavoriteListService().getFavoriteList(favoriteListId);
+
+ VoterListJpaDao dao = getPersistenceContext().getVoterListDao();
+ VoterList result = dao.newInstance();
+
+ result.setName(favoriteList.getName());
+ result.setWeight(1d);
+
+ VoterListMemberJpaDao voterListMemberDao =
+ getPersistenceContext().getVoterListMemberDao();
+
+ for (FavoriteListMember favoriteListMember : favoriteList.getFavoriteListMember()) {
+
+ VoterListMember voterListMember = voterListMemberDao.newInstance();
+ voterListMember.setWeight(1d);
+ voterListMember.setEmail(favoriteListMember.getEmail());
+ result.addVoterListMember(voterListMember);
+ }
+
+ poll.addVoterList(result);
+
+ getPersistenceContext().getPollDao().merge(poll);
+
+ getPersistenceContext().commit();
+ return result;
+ }
+
+ public List<VoterList> getVoterLists(String pollId) throws EntityNotFoundException{
+ Preconditions.checkNotNull(pollId);
+
+ Poll poll = getPollService().getPoll(pollId);
+
+ List<VoterList> result = poll.getVoterList();
+ return result;
+ }
+
+ public VoterList getVoterList(String voterListId) throws EntityNotFoundException{
+ Preconditions.checkNotNull(voterListId);
+
+ VoterList result = getPersistenceContext().getVoterListDao().findById(voterListId);
+ checkEntityExists(VoterList.class, result, voterListId);
+
+ return result;
+ }
+
+ public VoterList addVoterList(String pollId, VoterList voterList) throws EntityNotFoundException{
+ Preconditions.checkNotNull(pollId);
+ Preconditions.checkNotNull(voterList);
+ checkHasNoId(voterList);
+
+ Poll poll = getPollService().getPoll(pollId);
+
+ poll.addVoterList(voterList);
+
+ getPersistenceContext().getPollDao().merge(poll);
+ getPersistenceContext().commit();
+ VoterList result = getVoterList(voterList.getId());
+ return result;
+ }
+
+ public VoterList editVoterList(VoterList voterList) throws EntityNotFoundException{
+ Preconditions.checkNotNull(voterList);
+ checkHasId(voterList);
+
+ getVoterList(voterList.getId());
+
+ getPersistenceContext().getVoterListDao().merge(voterList);
+ getPersistenceContext().commit();
+ VoterList result = getVoterList(voterList.getId());
+ return result;
+ }
+
+ public void deleteVoterList(String pollId, String voterListId) throws EntityNotFoundException{
+ Preconditions.checkNotNull(pollId);
+ Preconditions.checkNotNull(voterListId);
+
+ Poll poll = getPollService().getPoll(pollId);
+
+ VoterList voterList = getVoterList(voterListId);
+
+ poll.removeVoterList(voterList);
+
+ getPersistenceContext().getPollDao().merge(poll);
+
+ getPersistenceContext().commit();
+ }
+
+ public Set<VoterListMember> getMembers(String voterListId) throws EntityNotFoundException{
+ Preconditions.checkNotNull(voterListId);
+
+ VoterList voterList = getVoterList(voterListId);
+
+ Set<VoterListMember> result = voterList.getVoterListMember();
+ return result;
+ }
+
+ public VoterListMember getMember(String memberId) throws EntityNotFoundException{
+ Preconditions.checkNotNull(memberId);
+
+ VoterListMember result = getPersistenceContext().getVoterListMemberDao().findById(memberId);
+ checkEntityExists(VoterListMember.class, result, memberId);
+ return result;
+ }
+
+ public VoterListMember addMember(String voterListId, VoterListMember member)throws EntityNotFoundException {
+ Preconditions.checkNotNull(voterListId);
+ Preconditions.checkNotNull(member);
+ checkHasNoId(member);
+
+ VoterList voterList = getVoterList(voterListId);
+
+ voterList.addVoterListMember(member);
+ getPersistenceContext().getVoterListDao().merge(voterList);
+
+ getPersistenceContext().commit();
+ VoterListMember result = getMember(member.getId());
+ return result;
+ }
+
+ public VoterListMember editMember(VoterListMember member) throws EntityNotFoundException{
+ Preconditions.checkNotNull(member);
+ checkHasId(member);
+
+ getMember(member.getId());
+
+ getPersistenceContext().getVoterListMemberDao().merge(member);
+
+ getPersistenceContext().commit();
+ VoterListMember result = getMember(member.getId());
+ return result;
+ }
+
+ public void deleteMember(String voterListId, String memberId) throws EntityNotFoundException{
+ Preconditions.checkNotNull(voterListId);
+ Preconditions.checkNotNull(memberId);
+
+ VoterList voterList = getVoterList(voterListId);
+
+ VoterListMember member = getMember(memberId);
+ voterList.removeVoterListMember(member);
+
+ getPersistenceContext().getVoterListDao().merge(voterList);
+
+ getPersistenceContext().commit();
+ }
+
+}
Deleted: branches/pollen-2.0/pollen-services/src/main/resources/fixtures.yaml
===================================================================
--- branches/pollen-2.0/pollen-service/src/main/resources/fixtures.yaml 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/main/resources/fixtures.yaml 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,31 +0,0 @@
-tony:
- &tony !user
- id: pollen_user_tony
- login: tony
- password: fake
- name: T
- email: tony(a)pollen.fake
- administrator: false
-
-jean:
- &jean !user
- id: pollen_user_jean
- login: jean
- password: fake
- name: J
- email: jean(a)pollen.fake
- administrator: true
-
-julien:
- &julien !user
- id: pollen_user_julien
- login: julien
- password: fake
- name: J
- email: julien(a)pollen.fake
- administrator: true
-
-users:
- - *tony
- - *jean
- - *julien
\ No newline at end of file
Copied: branches/pollen-2.0/pollen-services/src/main/resources/fixtures.yaml (from rev 3821, branches/pollen-2.0/pollen-service/src/main/resources/fixtures.yaml)
===================================================================
--- branches/pollen-2.0/pollen-services/src/main/resources/fixtures.yaml (rev 0)
+++ branches/pollen-2.0/pollen-services/src/main/resources/fixtures.yaml 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,28 @@
+tony:
+ &tony !user
+ login: tony
+ password: fake
+ name: T
+ email: tony(a)pollen.fake
+ administrator: false
+
+jean:
+ &jean !user
+ login: jean
+ password: fake
+ name: J
+ email: jean(a)pollen.fake
+ administrator: true
+
+julien:
+ &julien !user
+ login: julien
+ password: fake
+ name: J
+ email: julien(a)pollen.fake
+ administrator: true
+
+users:
+ - *tony
+ - *jean
+ - *julien
\ No newline at end of file
Deleted: branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,114 +0,0 @@
-package org.chorem.pollen.service;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.chorem.pollen.persistence.JpaEntityIdFactoryIfNotEmpty;
-import org.chorem.pollen.persistence.JpaPollenPersistenceContext;
-import org.chorem.pollen.service.config.PollenServiceConfig;
-import org.junit.Rule;
-import org.nuiton.jpa.junit.JpaEntityManagerRule;
-
-import javax.persistence.EntityManager;
-import java.util.Map;
-
-public abstract class AbstractPollenServiceTest {
-
- protected static final double DELTA = 0.0001;
-
- protected static PollenServiceConfig config;
-
- protected JpaEntityManagerRule jpaEntityManagerRule;
-
- protected FakePollenServiceContext serviceContext;
-
- protected PollenFixtures fixtures;
-
- protected static PollenServiceConfig getPollenServiceConfig() {
-
- if (config == null) {
-
- config = new PollenServiceConfig();
- }
-
- return config;
-
- }
-
- protected FakePollenServiceContext getServiceContext() {
-
- if (serviceContext == null) {
-
- synchronized (this) {
- serviceContext = new FakePollenServiceContext();
-
- serviceContext.setPollenServiceConfig(getPollenServiceConfig());
-
- EntityManager entityManager = getJpaEntityManagerRule().getEntityManager();
-
- JpaEntityIdFactoryIfNotEmpty idGenerator = new JpaEntityIdFactoryIfNotEmpty();
- JpaPollenPersistenceContext persistenceContext = new JpaPollenPersistenceContext(idGenerator, entityManager);
-
- serviceContext.setPersistenceContext(persistenceContext);
- }
- }
-
- return serviceContext;
-
- }
-
- protected void loadFixtures(String fixturesSetName) {
-
- FixturesService fixturesService = getServiceContext().newService(FixturesService.class);
-
- fixtures = fixturesService.loadFixtures(fixturesSetName);
-
- }
-
- protected <E> E fixture(String id) {
-
- return fixtures.fixture(id);
-
- }
-
- protected <E extends PollenServiceSupport> E newService(Class<E> serviceClass) {
-
- return getServiceContext().newService(serviceClass);
-
- }
-
- @Rule
- public JpaEntityManagerRule getJpaEntityManagerRule() {
-
- if (jpaEntityManagerRule == null) {
-
- Map<String, String> jpaParameters = getPollenServiceConfig().getJpaParameters();
-
- jpaEntityManagerRule = new JpaEntityManagerRule("pollenPersistenceUnit", jpaParameters);
- }
-
- return jpaEntityManagerRule;
-
- }
-
-}
Copied: branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java (from rev 3821, branches/pollen-2.0/pollen-service/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java)
===================================================================
--- branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,117 @@
+package org.chorem.pollen.service;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.chorem.pollen.persistence.JpaPollenPersistenceContext;
+import org.chorem.pollen.services.PollenFixtures;
+import org.chorem.pollen.services.config.PollenServiceConfig;
+import org.chorem.pollen.services.service.FixturesService;
+import org.chorem.pollen.services.PollenServiceSupport;
+import org.junit.Rule;
+import org.nuiton.jpa.junit.JpaEntityManagerRule;
+
+import javax.persistence.EntityManager;
+import java.util.Map;
+
+public abstract class AbstractPollenServiceTest {
+
+ protected static final double DELTA = 0.0001;
+
+ protected static PollenServiceConfig config;
+
+ protected JpaEntityManagerRule jpaEntityManagerRule;
+
+ protected FakePollenServiceContext serviceContext;
+
+ protected PollenFixtures fixtures;
+
+ protected static PollenServiceConfig getPollenServiceConfig() {
+
+ if (config == null) {
+
+ config = new PollenServiceConfig();
+ }
+
+ return config;
+
+ }
+
+ protected FakePollenServiceContext getServiceContext() {
+
+ if (serviceContext == null) {
+
+ synchronized (this) {
+ serviceContext = new FakePollenServiceContext();
+
+ serviceContext.setPollenServiceConfig(getPollenServiceConfig());
+
+ EntityManager entityManager = getJpaEntityManagerRule().getEntityManager();
+
+// JpaEntityIdFactoryIfNotEmpty idGenerator = new JpaEntityIdFactoryIfNotEmpty();
+// JpaPollenPersistenceContext persistenceContext = new JpaPollenPersistenceContext(idGenerator, entityManager);
+ JpaPollenPersistenceContext persistenceContext = new JpaPollenPersistenceContext(entityManager);
+
+ serviceContext.setPersistenceContext(persistenceContext);
+ }
+ }
+
+ return serviceContext;
+
+ }
+
+ protected void loadFixtures(String fixturesSetName) {
+
+ FixturesService fixturesService = getServiceContext().newService(FixturesService.class);
+
+ fixtures = fixturesService.loadFixtures(fixturesSetName);
+
+ }
+
+ protected <E> E fixture(String id) {
+
+ return fixtures.fixture(id);
+
+ }
+
+ protected <E extends PollenServiceSupport> E newService(Class<E> serviceClass) {
+
+ return getServiceContext().newService(serviceClass);
+
+ }
+
+ @Rule
+ public JpaEntityManagerRule getJpaEntityManagerRule() {
+
+ if (jpaEntityManagerRule == null) {
+
+ Map<String, String> jpaParameters = getPollenServiceConfig().getJpaParameters();
+
+ jpaEntityManagerRule = new JpaEntityManagerRule("pollenPersistenceUnit", jpaParameters);
+ }
+
+ return jpaEntityManagerRule;
+
+ }
+
+}
Modified: branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/FakePollenServiceContext.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/test/java/org/chorem/pollen/service/FakePollenServiceContext.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/FakePollenServiceContext.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -26,6 +26,7 @@
import com.google.common.base.Preconditions;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.services.DefaultPollenServiceContext;
import java.util.Date;
Deleted: branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/UserServiceTest.java
===================================================================
--- branches/pollen-2.0/pollen-service/src/test/java/org/chorem/pollen/service/UserServiceTest.java 2013-06-08 12:12:35 UTC (rev 3819)
+++ branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/UserServiceTest.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -1,201 +0,0 @@
-package org.chorem.pollen.service;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.apache.commons.collections.CollectionUtils;
-import org.chorem.pollen.persistence.entity.PollenUser;
-import org.chorem.pollen.service.exception.EntityNotFoundException;
-import org.chorem.pollen.service.exception.UserEmailAlreadyUsedException;
-import org.chorem.pollen.service.exception.UserInvalidEmailActiviationTokenException;
-import org.chorem.pollen.service.exception.UserInvalidPasswordException;
-import org.chorem.pollen.service.exception.UserLoginAlreadyUsedException;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.text.ParseException;
-import java.util.Date;
-import java.util.List;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class UserServiceTest extends AbstractPollenServiceTest {
-
- protected UserService service;
-
- protected PollenUser user;
-
- @Before
- public void setUp() throws ParseException {
-
- loadFixtures("fixtures");
-
- service = serviceContext.getUserService();
-
- serviceContext.setDate(new Date(1363948427576l));
-
- user = fixture("tony");
- }
-
- @Test
- public void testGetPollenUsers() {
-
- List<PollenUser> users = service.getUsers();
-
- Assert.assertNotNull(users);
- Assert.assertTrue(CollectionUtils.isNotEmpty(users));
- }
-
- @Test
- public void testGetPollenUser() throws EntityNotFoundException {
-
- try {
- service.getUser("pollen_user_tony_" + System.nanoTime());
-
- } catch (EntityNotFoundException e) {
- Assert.assertTrue(true);
- }
-
- PollenUser user = service.getUser("pollen_user_tony");
-
- Assert.assertNotNull(user);
- Assert.assertEquals(this.user, user);
- }
-
- @Test
- public void testCreatePollenUser() throws Exception {
-
- try {
- service.createUser(user, false);
- Assert.fail();
- } catch (IllegalStateException e) {
- // Should having id
- Assert.assertTrue(true);
- }
-
- PollenUser newUser = new PollenUser();
- newUser.setLogin("pollen");
- newUser.setEmail("pollen(a)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(a)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(a)pollen.org");
- PollenUser savedUser2 = service.createUser(newUser2, true);
- Assert.assertNotNull(savedUser2);
- Assert.assertNotNull(savedUser2.getId());
- }
-
- @Test
- public void testEditUser() throws EntityNotFoundException, UserInvalidPasswordException, UserEmailAlreadyUsedException {
-
- PollenUser user = service.getUser("pollen_user_tony");
-
- Assert.assertNotNull(user);
- Assert.assertNull(user.getEmailActivationToken());
-
- serviceContext.getPersistenceContext().detach(user);
-
- String originalLogin = user.getLogin();
-
- user.setLogin("yetanotherlogin");
- String email = "tony(a)pollen.org";
- user.setEmail(email);
-
- try {
- service.editUser(user);
- Assert.fail();
- } catch (UserInvalidPasswordException e) {
- Assert.assertTrue(true);
- }
-
- user.setPassword("fake");
- PollenUser savedUser = service.editUser(user);
- Assert.assertNotNull(savedUser);
- Assert.assertEquals(originalLogin, savedUser.getLogin());
- Assert.assertEquals(email, savedUser.getEmail());
- Assert.assertNotNull(savedUser.getEmailActivationToken());
- }
-
- @Test
- public void testValidateEmail() throws EntityNotFoundException, UserInvalidPasswordException, UserEmailAlreadyUsedException, UserInvalidEmailActiviationTokenException {
-
- PollenUser user = service.getUser("pollen_user_tony");
- Assert.assertNotNull(user);
- Assert.assertNull(user.getEmailActivationToken());
-
- serviceContext.getPersistenceContext().detach(user);
-
- String email = "tony(a)pollen.org";
- user.setEmail(email);
- user.setPassword("fake");
-
- PollenUser savedUser = service.editUser(user);
- Assert.assertNotNull(savedUser);
-
- Assert.assertEquals(email, savedUser.getEmail());
- Assert.assertNotNull(savedUser.getEmailActivationToken());
-
- try {
- service.validateUserEmail(user.getId(), "fakeToken");
- Assert.fail();
- } catch (UserInvalidEmailActiviationTokenException e) {
- Assert.assertTrue(true);
- }
-
- Assert.assertFalse(savedUser.isEmailActivated());
-
- service.validateUserEmail(user.getId(), savedUser.getEmailActivationToken());
-
-
-
- PollenUser reloadedUser = service.getUser("pollen_user_tony");
- Assert.assertTrue(reloadedUser.isEmailActivated());
-
- }
-}
Copied: branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/UserServiceTest.java (from rev 3821, branches/pollen-2.0/pollen-service/src/test/java/org/chorem/pollen/service/UserServiceTest.java)
===================================================================
--- branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/UserServiceTest.java (rev 0)
+++ branches/pollen-2.0/pollen-services/src/test/java/org/chorem/pollen/service/UserServiceTest.java 2013-06-14 09:12:59 UTC (rev 3823)
@@ -0,0 +1,202 @@
+package org.chorem.pollen.service;
+
+/*
+ * #%L
+ * Pollen :: Service
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import org.apache.commons.collections.CollectionUtils;
+import org.chorem.pollen.persistence.entity.PollenUser;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.chorem.pollen.services.exception.UserEmailAlreadyUsedException;
+import org.chorem.pollen.services.exception.UserInvalidEmailActiviationTokenException;
+import org.chorem.pollen.services.exception.UserInvalidPasswordException;
+import org.chorem.pollen.services.exception.UserLoginAlreadyUsedException;
+import org.chorem.pollen.services.service.UserService;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.text.ParseException;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)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(a)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(a)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(a)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(a)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(a)pollen.org";
+ user.setEmail(email);
+ user.setPassword("fake");
+
+ PollenUser savedUser = service.editUser(user);
+ Assert.assertNotNull(savedUser);
+
+ Assert.assertEquals(email, savedUser.getEmail());
+ Assert.assertNotNull(savedUser.getEmailActivationToken());
+
+ try {
+ service.validateUserEmail(user.getId(), "fakeToken");
+ Assert.fail();
+ } catch (UserInvalidEmailActiviationTokenException e) {
+ Assert.assertTrue(true);
+ }
+
+ Assert.assertFalse(savedUser.isEmailActivated());
+
+ service.validateUserEmail(user.getId(), savedUser.getEmailActivationToken());
+
+
+
+ PollenUser reloadedUser = service.getUser(this.user.getId());
+ Assert.assertTrue(reloadedUser.isEmailActivated());
+
+ }
+}
Modified: branches/pollen-2.0/pom.xml
===================================================================
--- branches/pollen-2.0/pom.xml 2013-06-12 18:00:23 UTC (rev 3822)
+++ branches/pollen-2.0/pom.xml 2013-06-14 09:12:59 UTC (rev 3823)
@@ -130,13 +130,10 @@
</contributors>
<modules>
- <!--module>pollen-votecounting-api</module>
- <module>pollen-votecounting-aggregator</module-->
- <!--module>pollen-persistence</module>
- <module>pollen-services</module>
- <module>pollen-ui-struts2</module-->
+ <module>pollen-votecounting-api</module>
+ <module>pollen-votecounting-aggregator</module>
<module>pollen-persistence</module>
- <module>pollen-service</module>
+ <module>pollen-services</module>
<module>pollen-rest-api</module>
</modules>
@@ -291,6 +288,7 @@
<groupId>org.debux.webmotion</groupId>
<artifactId>webmotion-unittest</artifactId>
<version>${webmotionVersion}</version>
+ <scope>test</scope>
</dependency>
<dependency>
1
0