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
May 2014
- 5 participants
- 203 discussions
Build failed in Jenkins: pollen-ci » Pollen :: Rest Api #22
by admin+ci-chorem.org@codelutin.com 02 May '14
by admin+ci-chorem.org@codelutin.com 02 May '14
02 May '14
See <http://ci.chorem.org/jenkins/job/pollen-ci/org.chorem.pollen$pollen-rest-ap…>
Changes:
[Tony CHEMIT] debug poll create + fix voteCounting id
------------------------------------------
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Pollen :: Rest Api 2.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/debux/webm…
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/groups/pollen-group/org/debux/webmoti…
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/debux/webm…
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/groups/pollen-group/org/debux/webmoti…
[WARNING] The POM for org.debux.webmotion:webmotion:jar:2.5-SNAPSHOT is missing, no dependency information available
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/debux/webm…
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/groups/pollen-group/org/debux/webmoti…
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/debux/webm…
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/groups/pollen-group/org/debux/webmoti…
[WARNING] The POM for org.debux.webmotion:webmotion-unittest:jar:2.5-SNAPSHOT is missing, no dependency information available
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/debux/webm…
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/repositories/snapshots/org/debux/webm…
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/groups/pollen-group/org/debux/webmoti…
[INFO] Downloading: http://nexus.nuiton.org/nexus/content/groups/pollen-group/org/debux/webmoti…
[JENKINS] Archiving disabled
1
1
Author: tchemit
Date: 2014-05-02 11:20:55 +0200 (Fri, 02 May 2014)
New Revision: 3895
Url: http://forge.chorem.org/projects/pollen/repository/revisions/3895
Log:
- introduce email + notification service
- review security (not done at all...)
- better rest api (remove security info from api)
- ...
Added:
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidFormException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/NotificationService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/ChoiceAddedEmail.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/ChoiceDeletedEmail.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/ChoiceEditedEmail.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/CommentAddedEmail.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/CommentDeletedEmail.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/CommentEditedEmail.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/EmailService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/LostPasswordEmail.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollChoicePeriodEndedEmail.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollChoicePeriodStartedEmail.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollClosedEmail.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollCreatedEmail.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollVotePeriodEndedEmail.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollVotePeriodStartedEmail.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollVoteReminderEmail.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollenMail.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/RestrictedPollInvitationEmail.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/UserAccountCreatedEmail.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/VoteAddedEmail.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/VoteDeletedEmail.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/VoteEditedEmail.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/DefaultPollenSecurityContext.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PermissionVerb.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenInvalidPermissionException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenSecurityContext.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenSecurityRealm.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenUnauthorizedException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityRole.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/test/FakePollenSecurityContext.java
trunk/pollen-services/src/main/resources/email/
trunk/pollen-services/src/main/resources/email/LostPasswordEmail.mustache
trunk/pollen-services/src/main/resources/email/LostPasswordEmail_fr.mustache
trunk/pollen-services/src/main/resources/email/PollChoicePeriodEndedEmail.mustache
trunk/pollen-services/src/main/resources/email/PollChoicePeriodEndedEmail_en.mustache
trunk/pollen-services/src/main/resources/email/PollChoicePeriodStartedEmail.mustache
trunk/pollen-services/src/main/resources/email/PollChoicePeriodStartedEmail_fr.mustache
trunk/pollen-services/src/main/resources/email/PollVotePeriodEndedEmail.mustache
trunk/pollen-services/src/main/resources/email/PollVotePeriodEndedEmail_fr.mustache
trunk/pollen-services/src/main/resources/email/PollVotePeriodStartedEmail.mustache
trunk/pollen-services/src/main/resources/email/PollVotePeriodStartedEmail_fr.mustache
trunk/pollen-services/src/main/resources/email/PollVoteReminderEmail.mustache
trunk/pollen-services/src/main/resources/email/PollVoteReminderEmail_fr.mustache
trunk/pollen-services/src/main/resources/email/RestrictedPollInvitationEmail.mustache
trunk/pollen-services/src/main/resources/email/RestrictedPollInvitationEmail_fr.mustache
trunk/pollen-services/src/main/resources/email/UserAccountCreatedEmail.mustache
trunk/pollen-services/src/main/resources/email/UserAccountCreatedEmail_fr.mustache
trunk/pollen-services/src/main/resources/email/VoteAddedEmail.mustache
trunk/pollen-services/src/main/resources/email/VoteAddedEmail_fr.mustache
trunk/pollen-services/src/main/resources/email/VoteDeletedEmail.mustache
trunk/pollen-services/src/main/resources/email/VoteDeletedEmail_fr.mustache
trunk/pollen-services/src/main/resources/email/VoteEditedEmail.mustache
trunk/pollen-services/src/main/resources/email/VoteEditedEmail_fr.mustache
Removed:
trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.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/service/PermissionVerb.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java
Modified:
trunk/pollen-persistence/pom.xml
trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollTopiaDao.java
trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Polls.java
trunk/pollen-persistence/src/main/xmi/pollen.properties
trunk/pollen-persistence/src/main/xmi/pollen.zargo
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationContext.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestContext.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthService.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceService.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentService.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/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/PollenUserService.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteService.java
trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java
trunk/pollen-rest-api/src/main/resources/mapping
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/PollServiceTest.java
trunk/pollen-services/pom.xml
trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/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/exception/EntityNotFoundException.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/InvalidCommentFormException.java
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
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidPollFormException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidPollenUserFormException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoteFormException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoterListFormException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoterListMemberFormException.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AuthService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/test/FakePollenServiceContext.java
trunk/pollen-services/src/main/java/org/chorem/pollen/services/test/PollenApplication.java
trunk/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties
trunk/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties
trunk/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java
trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollServiceTest.java
trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollenUserServiceTest.java
trunk/pom.xml
Modified: trunk/pollen-persistence/pom.xml
===================================================================
--- trunk/pollen-persistence/pom.xml 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-persistence/pom.xml 2014-05-02 09:20:55 UTC (rev 3895)
@@ -95,6 +95,7 @@
org.nuiton.eugene.java.JavaEnumerationTransformer,
org.nuiton.topia.templates.TopiaMetaTransformer
</templates>
+ <failIfUnsafe>true</failIfUnsafe>
</configuration>
<goals>
<goal>generate</goal>
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollTopiaDao.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollTopiaDao.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollTopiaDao.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -33,17 +33,17 @@
*/
public class PollTopiaDao extends AbstractPollTopiaDao<Poll> {
- public Set<Poll> findAllCreated(String userId) {
+ public Set<Poll> findAllCreated(PollenUser user) {
//TODO
return Sets.newHashSet();
}
- public Set<Poll> findAllInvited(String userId) {
+ public Set<Poll> findAllInvited(PollenUser user) {
//TODO
return Sets.newHashSet();
}
- public Set<Poll> findAllParticipated(String userId) {
+ public Set<Poll> findAllParticipated(PollenUser user) {
//TODO
return Sets.newHashSet();
}
Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Polls.java
===================================================================
--- trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Polls.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Polls.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -90,8 +90,8 @@
if (poll.isVoterListNotEmpty()) {
for (VoterList list : poll.getVoterList()) {
- if (!list.isVoterListMemberEmpty()) {
- result.addAll(list.getVoterListMember());
+ if (!list.isMemberEmpty()) {
+ result.addAll(list.getMember());
}
}
}
Modified: trunk/pollen-persistence/src/main/xmi/pollen.properties
===================================================================
--- trunk/pollen-persistence/src/main/xmi/pollen.properties 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-persistence/src/main/xmi/pollen.properties 2014-05-02 09:20:55 UTC (rev 3895)
@@ -32,14 +32,9 @@
org.chorem.pollen.persistence.entity.Poll.attribute.vote.stereotype=ordered
org.chorem.pollen.persistence.entity.Poll.attribute.comment.stereotype=ordered
org.chorem.pollen.persistence.entity.PollenUser.attribute.favoriteList.stereotype=ordered
-org.chorem.pollen.persistence.entity.FavoriteList.attribute.favoriteListMember.stereotype=ordered
-org.chorem.pollen.persistence.entity.VoterList.attribute.voterListMember.stereotype=unique
+org.chorem.pollen.persistence.entity.FavoriteList.attribute.member.stereotype=ordered, unique
+org.chorem.pollen.persistence.entity.VoterList.attribute.member.stereotype=unique
-#org.chorem.pollen.persistence.entity.Poll.attribute.choice.stereotype=indexed
-
-#org.chorem.pollen.persistence.entity.Poll.attribute.vote.stereotype=ordered
-#org.chorem.pollen.persistence.entity.Poll.attribute.vote.tagvalue.orderBy=topiaCreateDate
-
# clef naturelle non modifiable sur Poll#pollId
#org.chorem.pollen.persistence.entity.Poll.class.tagValue.naturalIdMutable=true
#org.chorem.pollen.persistence.entity.Poll.attribute.pollId.stereotype=unique
Modified: trunk/pollen-persistence/src/main/xmi/pollen.zargo
===================================================================
(Binary files differ)
Modified: 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/PollenRender.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -25,6 +25,7 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
+import com.google.common.collect.Multimap;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
@@ -34,6 +35,7 @@
import com.google.gson.JsonSerializer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.chorem.pollen.services.exception.InvalidFormException;
import org.debux.webmotion.server.call.Call;
import org.debux.webmotion.server.call.HttpContext;
import org.debux.webmotion.server.mapping.Mapping;
@@ -56,6 +58,7 @@
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.Date;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -98,8 +101,15 @@
if (annotation != null) {
includeCollection = annotation.values();
}
- Object map = toMap(model, includeCollection);
+ Object map;
+ if (model instanceof InvalidFormException) {
+ response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+ map = toMap(((InvalidFormException) model).getErrors());
+ } else {
+ map = toMap(model, includeCollection);
+ }
+
Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
@Override
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
@@ -115,6 +125,14 @@
out.print(json);
}
+ protected Object toMap(Multimap<String, String> model) {
+ Map<String, Object> result = new HashMap<>();
+ for (String key : model.keySet()) {
+ result.put(key, model.get(key));
+ }
+ return result;
+ }
+
protected <M> Object toMap(M model, String... includeCollection) {
if (model instanceof Iterable<?>) {
Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationContext.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationContext.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationContext.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -31,12 +31,15 @@
import org.chorem.pollen.persistence.PollenPersistenceContext;
import org.chorem.pollen.persistence.PollenTopiaApplicationContext;
import org.chorem.pollen.persistence.PollenTopiaPersistenceContext;
+import org.chorem.pollen.persistence.entity.SessionToken;
import org.chorem.pollen.services.DefaultPollenServiceContext;
import org.chorem.pollen.services.PollenServiceContext;
import org.chorem.pollen.services.config.PollenServiceConfig;
import org.chorem.pollen.services.exception.EntityNotFoundException;
import org.chorem.pollen.services.exception.InvalidPollenUserFormException;
import org.chorem.pollen.services.service.PollenUserService;
+import org.chorem.pollen.services.service.security.DefaultPollenSecurityContext;
+import org.chorem.pollen.services.service.security.PollenSecurityContext;
import org.nuiton.i18n.I18n;
import org.nuiton.i18n.init.DefaultI18nInitializer;
import org.nuiton.i18n.init.I18nInitializer;
@@ -118,6 +121,12 @@
}
+ public PollenSecurityContext newSecurityContext(SessionToken sessionToken) {
+
+ return DefaultPollenSecurityContext.newContext(sessionToken);
+
+ }
+
@Override
public void close() {
Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -24,12 +24,14 @@
*/
import org.apache.commons.beanutils.Converter;
+import org.chorem.pollen.persistence.PollenEntityEnum;
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.topia.persistence.TopiaEntity;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Type;
@@ -69,6 +71,30 @@
}, Date.class);
+ Converter entityconverter = new Converter() {
+ @Override
+ public TopiaEntity convert(Class type, Object value) {
+ TopiaEntity result;
+ if (value != null && value.getClass().isAssignableFrom(TopiaEntity.class)) {
+ result = (TopiaEntity) value;
+ } else {
+ Class<?> implementationClass = PollenEntityEnum.getImplementationClass(type);
+ try {
+ result = (TopiaEntity) implementationClass.newInstance();
+ } catch (InstantiationException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return result;
+ }
+
+ };
+ for (Class<? extends TopiaEntity> entityClass : PollenEntityEnum.getContractClasses()) {
+ serverContext.addConverter(entityconverter, entityClass);
+ }
+
// ---
// init injectors
// ---
Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestContext.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestContext.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestContext.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -21,7 +21,6 @@
* #L%
*/
-import org.chorem.pollen.services.PollenSecurityContext;
import org.chorem.pollen.services.PollenServiceContext;
import org.chorem.pollen.services.service.AuthService;
import org.chorem.pollen.services.service.ChoiceService;
@@ -30,10 +29,11 @@
import org.chorem.pollen.services.service.FixturesService;
import org.chorem.pollen.services.service.PollService;
import org.chorem.pollen.services.service.PollenUserService;
-import org.chorem.pollen.services.service.SecurityService;
import org.chorem.pollen.services.service.VoteCountingService;
import org.chorem.pollen.services.service.VoteService;
import org.chorem.pollen.services.service.VoterListService;
+import org.chorem.pollen.services.service.security.PollenSecurityContext;
+import org.chorem.pollen.services.service.security.SecurityService;
/**
* Created on 4/25/14.
Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -26,9 +26,9 @@
import org.apache.commons.lang3.StringUtils;
import org.chorem.pollen.persistence.PollenPersistenceContext;
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.chorem.pollen.services.service.security.PollenSecurityContext;
import org.debux.webmotion.server.WebMotionFilter;
import org.debux.webmotion.server.call.HttpContext;
@@ -103,7 +103,7 @@
setRequestContext(context.getRequest(), requestContext);
- addSecurityContext(context, requestContext);
+ addSecurityContext(context, applicationContext, requestContext);
doProcess();
@@ -113,6 +113,7 @@
}
protected void addSecurityContext(HttpContext context,
+ PollenRestApiApplicationContext applicationContext,
PollenRestApiRequestContext serviceContext) throws InvalidSessionTokenException {
String[] strings = context.getParameters().get(REQUEST_AUTH_PARAMETER);
@@ -128,7 +129,7 @@
sessionToken = serviceContext.getAuthService().getUserByAuth(authParam);
}
PollenSecurityContext securityContext =
- PollenSecurityContext.newContext(sessionToken);
+ applicationContext.newSecurityContext(sessionToken);
serviceContext.setSecurityContext(securityContext);
}
}
Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthService.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthService.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/AuthService.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -25,7 +25,6 @@
import org.chorem.pollen.persistence.entity.SessionToken;
import org.chorem.pollen.rest.api.PollenRestApiRequestContext;
-import org.chorem.pollen.services.exception.EntityNotFoundException;
import org.chorem.pollen.services.exception.UserInvalidPasswordException;
import org.debux.webmotion.server.WebMotionController;
@@ -37,15 +36,15 @@
*/
public class AuthService extends WebMotionController {
- public SessionToken login(PollenRestApiRequestContext context, String login, String password) throws UserInvalidPasswordException, EntityNotFoundException {
+ public SessionToken login(PollenRestApiRequestContext context, String login, String password) throws UserInvalidPasswordException {
return context.getAuthService().login(login, password);
}
- public void lostPassword(PollenRestApiRequestContext context, String login) throws EntityNotFoundException {
+ public void lostPassword(PollenRestApiRequestContext context, String login) {
context.getAuthService().lostPassword(login);
}
- public void logout(PollenRestApiRequestContext context, String login, String token) throws EntityNotFoundException {
+ public void logout(PollenRestApiRequestContext context, String login, String token) {
context.getAuthService().logout(login, token);
}
}
Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceService.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceService.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceService.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -25,8 +25,7 @@
import org.chorem.pollen.persistence.entity.Choice;
import org.chorem.pollen.rest.api.PollenRestApiRequestContext;
-import org.chorem.pollen.services.exception.EntityNotFoundException;
-import org.chorem.pollen.services.exception.InvalidChoiceFormException;
+import org.chorem.pollen.services.exception.InvalidFormException;
import org.debux.webmotion.server.WebMotionController;
import java.util.List;
@@ -39,28 +38,28 @@
*/
public class ChoiceService extends WebMotionController {
- public List<Choice> getChoices(PollenRestApiRequestContext context, String pollId) throws EntityNotFoundException {
+ public List<Choice> getChoices(PollenRestApiRequestContext context, String pollId) {
context.getSecurityService().prepareSubject((String) null);
List<Choice> choices = context.getChoiceService().getChoices(pollId);
return choices;
}
- public Choice getChoice(PollenRestApiRequestContext context, String pollId, String choiceId) throws EntityNotFoundException {
+ public Choice getChoice(PollenRestApiRequestContext context, String pollId, String choiceId) {
context.getSecurityService().prepareSubject(choiceId);
return context.getChoiceService().getChoice(pollId, choiceId);
}
- public Choice addChoice(PollenRestApiRequestContext context, String pollId, Choice choice) throws EntityNotFoundException, InvalidChoiceFormException {
+ public Choice addChoice(PollenRestApiRequestContext context, String pollId, Choice choice) throws InvalidFormException {
context.getSecurityService().prepareSubject(pollId);
return context.getChoiceService().addChoice(pollId, choice);
}
- public Choice editChoice(PollenRestApiRequestContext context, String pollId, Choice choice) throws EntityNotFoundException, InvalidChoiceFormException {
+ public Choice editChoice(PollenRestApiRequestContext context, String pollId, Choice choice) throws InvalidFormException {
context.getSecurityService().prepareSubject(choice);
return context.getChoiceService().editChoice(pollId, choice);
}
- public void deleteChoice(PollenRestApiRequestContext context, String pollId, String choiceId) throws EntityNotFoundException {
+ public void deleteChoice(PollenRestApiRequestContext context, String pollId, String choiceId) {
context.getSecurityService().prepareSubject(choiceId);
context.getChoiceService().deleteChoice(pollId, choiceId);
}
Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentService.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentService.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentService.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -25,7 +25,6 @@
import org.chorem.pollen.persistence.entity.Comment;
import org.chorem.pollen.rest.api.PollenRestApiRequestContext;
-import org.chorem.pollen.services.exception.EntityNotFoundException;
import org.chorem.pollen.services.exception.InvalidCommentFormException;
import org.debux.webmotion.server.WebMotionController;
@@ -39,28 +38,28 @@
*/
public class CommentService extends WebMotionController {
- public List<Comment> getComments(PollenRestApiRequestContext context, String pollId) throws EntityNotFoundException {
+ public List<Comment> getComments(PollenRestApiRequestContext context, String pollId) {
context.getSecurityService().prepareSubject(pollId);
List<Comment> comments = context.getCommentService().getComments(pollId);
return comments;
}
- public Comment getComment(PollenRestApiRequestContext context, String pollId, String commentId) throws EntityNotFoundException {
+ public Comment getComment(PollenRestApiRequestContext context, String pollId, String commentId) {
context.getSecurityService().prepareSubject(commentId);
return context.getCommentService().getComment(pollId, commentId);
}
- public Comment addComment(PollenRestApiRequestContext context, String pollId, Comment comment) throws EntityNotFoundException, InvalidCommentFormException {
+ public Comment addComment(PollenRestApiRequestContext context, String pollId, Comment comment) throws InvalidCommentFormException {
context.getSecurityService().prepareSubject(pollId);
return context.getCommentService().addComment(pollId, comment);
}
- public Comment editComment(PollenRestApiRequestContext context, String pollId, Comment comment) throws EntityNotFoundException, InvalidCommentFormException {
+ public Comment editComment(PollenRestApiRequestContext context, String pollId, Comment comment) throws InvalidCommentFormException {
context.getSecurityService().prepareSubject(comment);
return context.getCommentService().editComment(pollId, comment);
}
- public void deleteComment(PollenRestApiRequestContext context, String pollId, String commentId) throws EntityNotFoundException {
+ public void deleteComment(PollenRestApiRequestContext context, String pollId, String commentId) {
context.getSecurityService().prepareSubject(commentId);
context.getCommentService().deleteComment(pollId, commentId);
}
Modified: 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/ErrorAction.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ErrorAction.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -23,11 +23,12 @@
* #L%
*/
-import com.google.common.collect.Multimap;
-import org.chorem.pollen.services.exception.AbstractInvalidFormException;
+import org.chorem.pollen.services.exception.InvalidFormException;
import org.debux.webmotion.server.WebMotionController;
import org.debux.webmotion.server.render.Render;
+import javax.servlet.http.HttpServletResponse;
+
/**
* TODO
*
@@ -36,20 +37,17 @@
*/
public class ErrorAction extends WebMotionController {
+ public InvalidFormException on400Form(InvalidFormException e) {
+
+ return e;
+ }
+
public Render on404(Exception e) {
- return renderError(404, e.getMessage());
+ return renderError(HttpServletResponse.SC_NOT_FOUND, e.getMessage());
}
public Render on500(Exception e) {
- return renderError(500, e.getMessage());
+ return renderError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 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());
- }
}
Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListService.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListService.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListService.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -26,13 +26,13 @@
import org.chorem.pollen.persistence.entity.FavoriteList;
import org.chorem.pollen.persistence.entity.FavoriteListMember;
import org.chorem.pollen.rest.api.PollenRestApiRequestContext;
-import org.chorem.pollen.services.exception.EntityNotFoundException;
import org.chorem.pollen.services.exception.FavoriteListImportException;
import org.chorem.pollen.services.exception.InvalidFavoriteListFormException;
import org.chorem.pollen.services.exception.InvalidFavoriteListMemberFormException;
import org.debux.webmotion.server.WebMotionController;
import java.io.File;
+import java.util.LinkedHashSet;
import java.util.List;
/**
@@ -43,53 +43,53 @@
*/
public class FavoriteListService extends WebMotionController {
- public List<FavoriteList> getFavoriteLists(PollenRestApiRequestContext context, String userId) throws EntityNotFoundException {
+ public List<FavoriteList> getFavoriteLists(PollenRestApiRequestContext context, String userId) {
List<FavoriteList> favoriteLists = context.getFavoriteListService().getFavoriteLists(userId);
return favoriteLists;
}
- public FavoriteList getFavoriteList(PollenRestApiRequestContext context, String userId, String favoriteListId) throws EntityNotFoundException {
+ public FavoriteList getFavoriteList(PollenRestApiRequestContext context, String userId, String favoriteListId) {
return context.getFavoriteListService().getFavoriteList(userId, favoriteListId);
}
- public FavoriteList createFavoriteList(PollenRestApiRequestContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, InvalidFavoriteListFormException {
+ public FavoriteList createFavoriteList(PollenRestApiRequestContext context, String userId, FavoriteList favoriteList) throws InvalidFavoriteListFormException {
return context.getFavoriteListService().createFavoriteList(userId, favoriteList);
}
- public FavoriteList editFavoriteList(PollenRestApiRequestContext context, String userId, FavoriteList favoriteList) throws EntityNotFoundException, InvalidFavoriteListFormException {
+ public FavoriteList editFavoriteList(PollenRestApiRequestContext context, String userId, FavoriteList favoriteList) throws InvalidFavoriteListFormException {
return context.getFavoriteListService().editFavoriteList(userId, favoriteList);
}
- public void deleteFavoriteList(PollenRestApiRequestContext context, String userId, String favoriteListId) throws EntityNotFoundException {
+ public void deleteFavoriteList(PollenRestApiRequestContext context, String userId, String favoriteListId) {
context.getFavoriteListService().deleteFavoriteList(userId, favoriteListId);
}
- public int importFavoriteListMembersFromCsv(PollenRestApiRequestContext context, String userId, String favoriteListId, File csvFile) throws EntityNotFoundException, FavoriteListImportException {
+ public int importFavoriteListMembersFromCsv(PollenRestApiRequestContext context, String userId, String favoriteListId, File csvFile) throws FavoriteListImportException {
return context.getFavoriteListService().importFavoriteListMembersFromCsv(userId, favoriteListId, csvFile);
}
- public int importFavoriteListMembersFromLdap(PollenRestApiRequestContext context, String userId, String favoriteListId, String ldap) throws EntityNotFoundException, FavoriteListImportException {
+ public int importFavoriteListMembersFromLdap(PollenRestApiRequestContext context, String userId, String favoriteListId, String ldap) throws FavoriteListImportException {
return context.getFavoriteListService().importFavoriteListMembersFromLdap(userId, favoriteListId, ldap);
}
- public List<FavoriteListMember> getMembers(PollenRestApiRequestContext context, String userId, String favoriteListId) throws EntityNotFoundException {
- List<FavoriteListMember> members = context.getFavoriteListService().getFavoriteListMembers(userId, favoriteListId);
+ public LinkedHashSet<FavoriteListMember> getMembers(PollenRestApiRequestContext context, String userId, String favoriteListId) {
+ LinkedHashSet<FavoriteListMember> members = context.getFavoriteListService().getFavoriteListMembers(userId, favoriteListId);
return members;
}
- public FavoriteListMember getMember(PollenRestApiRequestContext context, String userId, String favoriteListId, String memberId) throws EntityNotFoundException {
+ public FavoriteListMember getMember(PollenRestApiRequestContext context, String userId, String favoriteListId, String memberId) {
return context.getFavoriteListService().getFavoriteListMember(userId, favoriteListId, memberId);
}
- public FavoriteListMember addMember(PollenRestApiRequestContext context, String userId, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, InvalidFavoriteListMemberFormException {
+ public FavoriteListMember addMember(PollenRestApiRequestContext context, String userId, String favoriteListId, FavoriteListMember member) throws InvalidFavoriteListMemberFormException {
return context.getFavoriteListService().addFavoriteListMember(userId, favoriteListId, member);
}
- public FavoriteListMember editMember(PollenRestApiRequestContext context, String userId, String favoriteListId, FavoriteListMember member) throws EntityNotFoundException, InvalidFavoriteListMemberFormException {
+ public FavoriteListMember editMember(PollenRestApiRequestContext context, String userId, String favoriteListId, FavoriteListMember member) throws InvalidFavoriteListMemberFormException {
return context.getFavoriteListService().editFavoriteListMember(userId, favoriteListId, member);
}
- public void removeMember(PollenRestApiRequestContext context, String userId, String favoriteListId, String memberId) throws EntityNotFoundException {
+ public void removeMember(PollenRestApiRequestContext context, String userId, String favoriteListId, String memberId) {
context.getFavoriteListService().removeFavoriteListMember(userId, favoriteListId, memberId);
}
}
Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollService.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -25,8 +25,7 @@
import org.chorem.pollen.persistence.entity.Poll;
import org.chorem.pollen.rest.api.PollenRestApiRequestContext;
-import org.chorem.pollen.services.exception.EntityNotFoundException;
-import org.chorem.pollen.services.exception.InvalidPollFormException;
+import org.chorem.pollen.services.exception.InvalidFormException;
import org.debux.webmotion.server.WebMotionController;
import java.io.File;
@@ -40,60 +39,60 @@
*/
public class PollService extends WebMotionController {
- public Poll getNewPoll(PollenRestApiRequestContext context, String userId) throws EntityNotFoundException {
- return context.getPollService().getNewPoll(userId);
+ public Poll getNewPoll(PollenRestApiRequestContext context) {
+ return context.getPollService().getNewPoll();
}
- public Set<Poll> getPolls(PollenRestApiRequestContext context, String userId) throws EntityNotFoundException {
- Set<Poll> polls = context.getPollService().getPolls(userId);
+ public Set<Poll> getPolls(PollenRestApiRequestContext context) {
+ Set<Poll> polls = context.getPollService().getPolls();
return polls;
}
- public Set<Poll> getCreatedPolls(PollenRestApiRequestContext context, String userId) throws EntityNotFoundException {
- Set<Poll> polls = context.getPollService().getCreatedPolls(userId);
+ public Set<Poll> getCreatedPolls(PollenRestApiRequestContext context) {
+ Set<Poll> polls = context.getPollService().getCreatedPolls();
return polls;
}
- public Set<Poll> getInvitedPolls(PollenRestApiRequestContext context, String userId) throws EntityNotFoundException {
- Set<Poll> polls = context.getPollService().getInvitedPolls(userId);
+ public Set<Poll> getInvitedPolls(PollenRestApiRequestContext context) {
+ Set<Poll> polls = context.getPollService().getInvitedPolls();
return polls;
}
- public Set<Poll> getParticipatedPolls(PollenRestApiRequestContext context, String userId) throws EntityNotFoundException {
- Set<Poll> polls = context.getPollService().getParticipatedPolls(userId);
+ public Set<Poll> getParticipatedPolls(PollenRestApiRequestContext context) {
+ Set<Poll> polls = context.getPollService().getParticipatedPolls();
return polls;
}
- public Poll getPoll(PollenRestApiRequestContext context, String pollId) throws EntityNotFoundException {
+ public Poll getPoll(PollenRestApiRequestContext context, String pollId) {
context.getSecurityService().prepareSubject((String) null);
return context.getPollService().getPoll(pollId);
}
- public Poll createPoll(PollenRestApiRequestContext context, String userId, Poll poll) throws EntityNotFoundException, InvalidPollFormException {
- return context.getPollService().createPoll(userId, poll);
+ public Poll createPoll(PollenRestApiRequestContext context, Poll poll) throws InvalidFormException {
+ return context.getPollService().createPoll(poll);
}
- public Poll editPoll(PollenRestApiRequestContext context, Poll poll) throws EntityNotFoundException, InvalidPollFormException {
+ public Poll editPoll(PollenRestApiRequestContext context, Poll poll) throws InvalidFormException {
context.getSecurityService().prepareSubject(poll);
return context.getPollService().editPoll(poll);
}
- public void deletePoll(PollenRestApiRequestContext context, String pollId) throws EntityNotFoundException {
+ public void deletePoll(PollenRestApiRequestContext context, String pollId) {
context.getSecurityService().prepareSubject(pollId);
context.getPollService().deletePoll(pollId);
}
- public Poll clonePoll(PollenRestApiRequestContext context, String pollId) throws EntityNotFoundException {
+ public Poll clonePoll(PollenRestApiRequestContext context, String pollId) {
context.getSecurityService().prepareSubject(pollId);
return context.getPollService().clonePoll(pollId);
}
- public File closePoll(PollenRestApiRequestContext context, String pollId) throws EntityNotFoundException {
+ public void closePoll(PollenRestApiRequestContext context, String pollId) {
context.getSecurityService().prepareSubject(pollId);
- return context.getPollService().closePoll(pollId);
+ context.getPollService().closePoll(pollId);
}
- public File exportPoll(PollenRestApiRequestContext context, String pollId) throws EntityNotFoundException {
+ public File exportPoll(PollenRestApiRequestContext context, String pollId) {
context.getSecurityService().prepareSubject(pollId);
return context.getPollService().exportPoll(pollId);
}
Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserService.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserService.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserService.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -25,7 +25,6 @@
import org.chorem.pollen.persistence.entity.PollenUser;
import org.chorem.pollen.rest.api.PollenRestApiRequestContext;
-import org.chorem.pollen.services.exception.EntityNotFoundException;
import org.chorem.pollen.services.exception.InvalidPollenUserFormException;
import org.chorem.pollen.services.exception.UserInvalidEmailActivationTokenException;
import org.chorem.pollen.services.exception.UserInvalidPasswordException;
@@ -46,37 +45,36 @@
return users;
}
- public PollenUser getUser(PollenRestApiRequestContext context, String userId) throws EntityNotFoundException {
+ public PollenUser getUser(PollenRestApiRequestContext context, String userId) {
return context.getPollenUserService().getUser(userId);
}
public PollenUser createUser(PollenRestApiRequestContext context,
PollenUser user,
- boolean generatePassword) throws EntityNotFoundException, InvalidPollenUserFormException {
+ boolean generatePassword) throws InvalidPollenUserFormException {
return context.getPollenUserService().createUser(user, generatePassword);
}
public PollenUser editUser(PollenRestApiRequestContext context,
- PollenUser user) throws EntityNotFoundException, InvalidPollenUserFormException {
+ PollenUser user) throws InvalidPollenUserFormException {
return context.getPollenUserService().editUser(user);
}
- public void deleteUser(PollenRestApiRequestContext context,
- String userId) throws EntityNotFoundException, InvalidPollenUserFormException {
+ public void deleteUser(PollenRestApiRequestContext context, String userId) throws InvalidPollenUserFormException {
context.getPollenUserService().deleteUser(userId);
}
public void validateUserEmail(PollenRestApiRequestContext context,
String userId,
- String token) throws EntityNotFoundException, UserInvalidEmailActivationTokenException {
+ String token) throws UserInvalidEmailActivationTokenException {
context.getPollenUserService().validateUserEmail(userId, token);
}
public void changePassword(PollenRestApiRequestContext context,
String userId,
String oldPassword,
- String newPassword) throws EntityNotFoundException, UserInvalidPasswordException {
+ String newPassword) throws UserInvalidPasswordException {
context.getPollenUserService().changePassword(userId, oldPassword, newPassword);
}
}
Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteService.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteService.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteService.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -25,7 +25,6 @@
import org.chorem.pollen.persistence.entity.Vote;
import org.chorem.pollen.rest.api.PollenRestApiRequestContext;
-import org.chorem.pollen.services.exception.EntityNotFoundException;
import org.chorem.pollen.services.exception.InvalidVoteFormException;
import org.debux.webmotion.server.WebMotionController;
@@ -39,28 +38,28 @@
*/
public class VoteService extends WebMotionController {
- public List<Vote> getVotes(PollenRestApiRequestContext context, String pollId) throws EntityNotFoundException {
+ public List<Vote> getVotes(PollenRestApiRequestContext context, String pollId) {
context.getSecurityService().prepareSubject(pollId);
List<Vote> votes = context.getVoteService().getVotes(pollId);
return votes;
}
- public Vote getVote(PollenRestApiRequestContext context, String pollId, String voteId) throws EntityNotFoundException {
+ public Vote getVote(PollenRestApiRequestContext context, String pollId, String voteId) {
context.getSecurityService().prepareSubject(voteId);
return context.getVoteService().getVote(pollId, voteId);
}
- public Vote addVote(PollenRestApiRequestContext context, String pollId, Vote vote) throws EntityNotFoundException, InvalidVoteFormException {
+ public Vote addVote(PollenRestApiRequestContext context, String pollId, Vote vote) throws InvalidVoteFormException {
context.getSecurityService().prepareSubject(pollId);
return context.getVoteService().addVote(pollId, vote);
}
- public Vote editVote(PollenRestApiRequestContext context, String pollId, Vote vote) throws EntityNotFoundException, InvalidVoteFormException {
+ public Vote editVote(PollenRestApiRequestContext context, String pollId, Vote vote) throws InvalidVoteFormException {
context.getSecurityService().prepareSubject(vote);
return context.getVoteService().editVote(pollId, vote);
}
- public void deleteVote(PollenRestApiRequestContext context, String pollId, String voteId) throws EntityNotFoundException {
+ public void deleteVote(PollenRestApiRequestContext context, String pollId, String voteId) {
context.getSecurityService().prepareSubject(voteId);
context.getVoteService().deleteVote(pollId, voteId);
}
Modified: trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java
===================================================================
--- trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListService.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -26,7 +26,6 @@
import org.chorem.pollen.persistence.entity.VoterList;
import org.chorem.pollen.persistence.entity.VoterListMember;
import org.chorem.pollen.rest.api.PollenRestApiRequestContext;
-import org.chorem.pollen.services.exception.EntityNotFoundException;
import org.chorem.pollen.services.exception.InvalidVoterListFormException;
import org.chorem.pollen.services.exception.InvalidVoterListMemberFormException;
import org.debux.webmotion.server.WebMotionController;
@@ -42,58 +41,58 @@
*/
public class VoterListService extends WebMotionController {
- public VoterList importFavoriteList(PollenRestApiRequestContext context, String userId, String pollId, String favoriteListId) throws EntityNotFoundException {
+ public VoterList importFavoriteList(PollenRestApiRequestContext context, String userId, String pollId, String favoriteListId) {
return context.getVoterListService().importFavoriteList(userId, pollId, favoriteListId);
}
- public List<VoterList> getVoterLists(PollenRestApiRequestContext context, String pollId) throws EntityNotFoundException {
+ public List<VoterList> getVoterLists(PollenRestApiRequestContext context, String pollId) {
context.getSecurityService().prepareSubject(pollId);
List<VoterList> voterLists = context.getVoterListService().getVoterLists(pollId);
return voterLists;
}
- public VoterList getVoterList(PollenRestApiRequestContext context, String pollId, String voterListId) throws EntityNotFoundException {
+ public VoterList getVoterList(PollenRestApiRequestContext context, String pollId, String voterListId) {
context.getSecurityService().prepareSubject(voterListId);
return context.getVoterListService().getVoterList(pollId, voterListId);
}
- public VoterList createVoterList(PollenRestApiRequestContext context, String pollId, VoterList voterList) throws EntityNotFoundException, InvalidVoterListFormException {
+ public VoterList createVoterList(PollenRestApiRequestContext context, String pollId, VoterList voterList) throws InvalidVoterListFormException {
context.getSecurityService().prepareSubject(pollId);
return context.getVoterListService().addVoterList(pollId, voterList);
}
- public VoterList editVoterList(PollenRestApiRequestContext context, String pollId, VoterList voterList) throws EntityNotFoundException, InvalidVoterListFormException {
+ public VoterList editVoterList(PollenRestApiRequestContext context, String pollId, VoterList voterList) throws InvalidVoterListFormException {
context.getSecurityService().prepareSubject(voterList);
return context.getVoterListService().editVoterList(pollId, voterList);
}
- public void deleteVoterList(PollenRestApiRequestContext context, String pollId, String voterListId) throws EntityNotFoundException {
+ public void deleteVoterList(PollenRestApiRequestContext context, String pollId, String voterListId) {
context.getSecurityService().prepareSubject(voterListId);
context.getVoterListService().deleteVoterList(pollId, voterListId);
}
- public Set<VoterListMember> getMembers(PollenRestApiRequestContext context, String pollId, String voterListId) throws EntityNotFoundException {
+ public Set<VoterListMember> getMembers(PollenRestApiRequestContext context, String pollId, String voterListId) {
context.getSecurityService().prepareSubject(voterListId);
Set<VoterListMember> members = context.getVoterListService().getVoterListMembers(pollId, voterListId);
return members;
}
- public VoterListMember getMember(PollenRestApiRequestContext context, String pollId, String voterListId, String memberId) throws EntityNotFoundException {
+ public VoterListMember getMember(PollenRestApiRequestContext context, String pollId, String voterListId, String memberId) {
context.getSecurityService().prepareSubject(memberId);
return context.getVoterListService().getVoterListMember(pollId, voterListId, memberId);
}
- public VoterListMember addMember(PollenRestApiRequestContext context, String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException, InvalidVoterListMemberFormException {
+ public VoterListMember addMember(PollenRestApiRequestContext context, String pollId, String voterListId, VoterListMember member) throws InvalidVoterListMemberFormException {
context.getSecurityService().prepareSubject(member);
return context.getVoterListService().addVoterListMember(pollId, voterListId, member);
}
- public VoterListMember editMember(PollenRestApiRequestContext context, String pollId, String voterListId, VoterListMember member) throws EntityNotFoundException, InvalidVoterListMemberFormException {
+ public VoterListMember editMember(PollenRestApiRequestContext context, String pollId, String voterListId, VoterListMember member) throws InvalidVoterListMemberFormException {
context.getSecurityService().prepareSubject(member);
return context.getVoterListService().editVoterListMember(pollId, voterListId, member);
}
- public void deleteMember(PollenRestApiRequestContext context, String pollId, String voterListId, String memberId) throws EntityNotFoundException {
+ public void deleteMember(PollenRestApiRequestContext context, String pollId, String voterListId, String memberId) {
context.getSecurityService().prepareSubject(memberId);
context.getVoterListService().deleteVoterListMember(pollId, voterListId, memberId);
}
Modified: trunk/pollen-rest-api/src/main/resources/mapping
===================================================================
--- trunk/pollen-rest-api/src/main/resources/mapping 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-rest-api/src/main/resources/mapping 2014-05-02 09:20:55 UTC (rev 3895)
@@ -12,18 +12,20 @@
[errors]
-org.chorem.pollen.services.exception.EntityNotFoundException ErrorAction.on404
-org.chorem.pollen.services.exception.UserInvalidPasswordException ErrorAction.on500
+org.chorem.pollen.services.exception.EntityNotFoundException ErrorAction.on404
+org.chorem.pollen.services.exception.UserInvalidPasswordException ErrorAction.on500
org.chorem.pollen.services.exception.UserInvalidEmailActivationTokenException ErrorAction.on500
-org.chorem.pollen.services.exception.InvalidChoiceFormException ErrorAction.on500Form
-org.chorem.pollen.services.exception.InvalidPollenUserFormException ErrorAction.on500Form
-org.chorem.pollen.services.exception.InvalidFavoriteListFormException ErrorAction.on500Form
-org.chorem.pollen.services.exception.InvalidFavoriteListMemberFormException ErrorAction.on500Form
-org.chorem.pollen.services.exception.InvalidVoterListFormException ErrorAction.on500Form
-org.chorem.pollen.services.exception.InvalidVoterListMemberFormException ErrorAction.on500Form
-org.chorem.pollen.services.exception.InvalidVoteFormException ErrorAction.on500Form
-org.chorem.pollen.services.exception.InvalidPollFormException ErrorAction.on500Form
+org.chorem.pollen.services.exception.InvalidFormException ErrorAction.on400Form
+#org.chorem.pollen.services.exception.InvalidChoiceFormException ErrorAction.on500Form
+#org.chorem.pollen.services.exception.InvalidPollenUserFormException ErrorAction.on500Form
+#org.chorem.pollen.services.exception.InvalidFavoriteListFormException ErrorAction.on500Form
+#org.chorem.pollen.services.exception.InvalidFavoriteListMemberFormException ErrorAction.on500Form
+#org.chorem.pollen.services.exception.InvalidVoterListFormException ErrorAction.on500Form
+#org.chorem.pollen.services.exception.InvalidVoterListMemberFormException ErrorAction.on500Form
+#org.chorem.pollen.services.exception.InvalidVoteFormException ErrorAction.on500Form
+#org.chorem.pollen.services.exception.InvalidPollFormException ErrorAction.on500Form
+
[actions]
# Doc
Modified: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java
===================================================================
--- trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -27,8 +27,11 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.persistence.PollenPersistenceContext;
+import org.chorem.pollen.persistence.entity.SessionToken;
import org.chorem.pollen.services.PollenServiceContext;
import org.chorem.pollen.services.config.PollenServiceConfig;
+import org.chorem.pollen.services.service.security.PollenSecurityContext;
+import org.chorem.pollen.services.test.FakePollenSecurityContext;
import org.chorem.pollen.services.test.FakePollenServiceContext;
import org.chorem.pollen.services.test.PollenApplication;
import org.debux.webmotion.unittest.WebMotionTest;
@@ -83,9 +86,15 @@
Locale.FRANCE,
application.getConfiguration(),
application.getApplicationContext(),
- application.newPersistenceContext());
+ application.newPersistenceContext(),
+ new FakePollenSecurityContext());
return serviceContext;
}
+
+ @Override
+ public PollenSecurityContext newSecurityContext(SessionToken sessionToken) {
+ return new FakePollenSecurityContext();
+ }
};
applicationContext.init();
PollenRestApiApplicationContext.setApplicationContext(applicationContext);
Modified: trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollServiceTest.java
===================================================================
--- trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollServiceTest.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollServiceTest.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -1,7 +1,12 @@
package org.chorem.pollen.rest.api;
import org.apache.http.client.fluent.Request;
+import org.chorem.pollen.persistence.entity.Choice;
+import org.chorem.pollen.persistence.entity.ChoiceType;
+import org.chorem.pollen.persistence.entity.CommentVisibility;
import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.persistence.entity.PollType;
+import org.chorem.pollen.persistence.entity.VoteVisibility;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -76,10 +81,20 @@
assertNotNull(content);
}
- @Ignore
@Test
public void postPoll() throws URISyntaxException, IOException {
- Request request = createRequest("/v1/polls").Post();
+ String paramPrefix = "poll.";
+ Request request = createRequest("/v1/polls").
+ addParameter(paramPrefix + Poll.PROPERTY_POLL_TYPE, PollType.FREE.name()).
+ addParameter(paramPrefix + Poll.PROPERTY_COMMENT_VISIBILITY, CommentVisibility.EVERYBODY.name()).
+ addParameter(paramPrefix + Poll.PROPERTY_VOTE_VISIBILITY, VoteVisibility.EVERYBODY.name()).
+ addParameter(paramPrefix + Poll.PROPERTY_VOTE_COUNTING_TYPE, "1").
+ addParameter(paramPrefix + Poll.PROPERTY_TITLE, "title").
+ addParameter(paramPrefix + Poll.PROPERTY_CHOICE + "[1]." + Choice.PROPERTY_CHOICE_TYPE, ChoiceType.TEXT.name()).
+ addParameter(paramPrefix + Poll.PROPERTY_CHOICE + "[1]." + Choice.PROPERTY_NAME, "choiceB").
+ addParameter(paramPrefix + Poll.PROPERTY_CHOICE + "[0]." + Choice.PROPERTY_CHOICE_TYPE, ChoiceType.TEXT.name()).
+ addParameter(paramPrefix + Poll.PROPERTY_CHOICE + "[0]." + Choice.PROPERTY_NAME, "choiceA").
+ Post();
String content = request.execute().returnContent().asString();
saveTestResult(content);
assertNotNull(content);
Modified: trunk/pollen-services/pom.xml
===================================================================
--- trunk/pollen-services/pom.xml 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/pom.xml 2014-05-02 09:20:55 UTC (rev 3895)
@@ -41,13 +41,23 @@
<artifactId>yamlbeans</artifactId>
</dependency>
- <dependency>
+ <!--dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
+ </dependency-->
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-email</artifactId>
</dependency>
<dependency>
+ <groupId>com.github.spullara.mustache.java</groupId>
+ <artifactId>compiler</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
@@ -67,20 +77,13 @@
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
- <!--dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-email</artifactId>
- </dependency-->
+
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<!--dependency>
- <groupId>javax.mail</groupId>
- <artifactId>mail</artifactId>
- </dependency-->
- <!--dependency>
<groupId>rome</groupId>
<artifactId>rome</artifactId>
</dependency-->
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/DefaultPollenServiceContext.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -31,6 +31,7 @@
import org.chorem.pollen.persistence.PollenPersistenceContext;
import org.chorem.pollen.persistence.PollenTopiaApplicationContext;
import org.chorem.pollen.services.config.PollenServiceConfig;
+import org.chorem.pollen.services.service.security.PollenSecurityContext;
import org.nuiton.util.StringUtil;
import java.lang.reflect.Constructor;
@@ -55,27 +56,28 @@
this.pollenServiceConfig = pollenServiceConfig;
}
+ public void setTopiaApplicationContext(PollenTopiaApplicationContext topiaApplicationContext) {
+ this.topiaApplicationContext = topiaApplicationContext;
+ }
+
public void setPersistenceContext(PollenPersistenceContext persistenceContext) {
this.persistenceContext = persistenceContext;
}
+ public void setLocale(Locale locale) {
+ this.locale = locale;
+ }
+
+ @Override
public void setSecurityContext(PollenSecurityContext securityContext) {
this.securityContext = securityContext;
}
- public void setTopiaApplicationContext(PollenTopiaApplicationContext topiaApplicationContext) {
- this.topiaApplicationContext = topiaApplicationContext;
- }
-
@Override
public PollenTopiaApplicationContext getTopiaApplicationContext() {
return topiaApplicationContext;
}
- public void setLocale(Locale locale) {
- this.locale = locale;
- }
-
@Override
public PollenServiceConfig getPollenServiceConfig() {
return pollenServiceConfig;
@@ -97,6 +99,7 @@
return securityContext;
}
+ @Override
public String generatePassword() {
return RandomStringUtils.randomAlphanumeric(8);
}
Deleted: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -1,82 +0,0 @@
-package org.chorem.pollen.services;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import org.apache.shiro.subject.Subject;
-import org.chorem.pollen.persistence.entity.PollenUser;
-import org.chorem.pollen.persistence.entity.SessionToken;
-
-import java.io.Serializable;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class PollenSecurityContext implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- protected Subject subject;
-
- /**
- * Connected user account.
- * <p/>
- * Can be {@code null} if user is not connected.
- *
- * @since 2.0
- */
- protected final SessionToken sessionToken;
-
- public static PollenSecurityContext newContext(SessionToken sessionToken) {
- PollenSecurityContext result = new PollenSecurityContext(
- sessionToken);
- return result;
- }
-
- public Subject getSubject() {
- return subject;
- }
-
- public SessionToken getSessionToken() {
- return sessionToken;
- }
-
- public PollenUser getPollenUser() {
- return isConnected() ? sessionToken.getPollenUser() : null;
- }
-
- public boolean isConnected() {
- return sessionToken != null;
- }
-
- public void setSubject(Subject subject) {
- this.subject = subject;
- }
-
- protected PollenSecurityContext(SessionToken sessionToken) {
- this.sessionToken = sessionToken;
- }
-}
Deleted: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityRealm.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityRealm.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityRealm.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -1,82 +0,0 @@
-package org.chorem.pollen.services;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-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
- * <p/>
- * http://www.slideshare.net/chunsaker/securing-rest-apis ?
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class PollenSecurityRealm extends AuthorizingRealm implements PollenService {
-
- 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.newService(AuthService.class);
- 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;
- }
-}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenServiceContext.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -26,6 +26,7 @@
import org.chorem.pollen.persistence.PollenPersistenceContext;
import org.chorem.pollen.persistence.PollenTopiaApplicationContext;
import org.chorem.pollen.services.config.PollenServiceConfig;
+import org.chorem.pollen.services.service.security.PollenSecurityContext;
import java.util.Date;
import java.util.Locale;
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -146,4 +146,25 @@
PollenServiceConfigOption.DEFAULT_COMMENT_VISIBILITY.key);
return result;
}
+
+ /**
+ * @return Le nom d'hôte du serveur SMTP.
+ */
+ public String getSmtpHost() {
+ return applicationConfig.getOption(PollenServiceConfigOption.SMTP_HOST.key);
+ }
+
+ /**
+ * @return Le port du serveur SMTP.
+ */
+ public int getSmtpPort() {
+ return applicationConfig.getOptionAsInt(PollenServiceConfigOption.SMTP_PORT.key);
+ }
+
+ /**
+ * @return L'adresse d'expéditeur pour les mails de notifications
+ */
+ public String getSmtpFrom() {
+ return applicationConfig.getOption(PollenServiceConfigOption.SMTP_FROM.key);
+ }
}
Deleted: 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 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/AbstractInvalidFormException.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -1,52 +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%
- */
-
-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;
- }
-
- @Override
- public String toString() {
- return super.toString() + " errors: " + errors;
- }
-}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/EntityNotFoundException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/EntityNotFoundException.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/EntityNotFoundException.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -23,6 +23,7 @@
* #L%
*/
+import org.chorem.pollen.services.PollenTechnicalException;
import org.nuiton.topia.persistence.TopiaEntity;
/**
@@ -31,7 +32,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.0
*/
-public class EntityNotFoundException extends Exception {
+public class EntityNotFoundException extends PollenTechnicalException {
private static final long serialVersionUID = -5760536098822762990L;
Modified: 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 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidChoiceFormException.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -31,7 +31,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.0
*/
-public class InvalidChoiceFormException extends AbstractInvalidFormException {
+public class InvalidChoiceFormException extends InvalidFormException {
private static final long serialVersionUID = 1L;
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidCommentFormException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidCommentFormException.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidCommentFormException.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -31,7 +31,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.0
*/
-public class InvalidCommentFormException extends AbstractInvalidFormException {
+public class InvalidCommentFormException extends InvalidFormException {
private static final long serialVersionUID = 1L;
public InvalidCommentFormException(Multimap<String, String> errors) {
Modified: 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 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidFavoriteListFormException.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -31,7 +31,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.0
*/
-public class InvalidFavoriteListFormException extends AbstractInvalidFormException {
+public class InvalidFavoriteListFormException extends InvalidFormException {
private static final long serialVersionUID = 1L;
Modified: 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 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidFavoriteListMemberFormException.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -31,7 +31,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.0
*/
-public class InvalidFavoriteListMemberFormException extends AbstractInvalidFormException {
+public class InvalidFavoriteListMemberFormException extends InvalidFormException {
private static final long serialVersionUID = 1L;
Copied: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidFormException.java (from rev 3890, trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/AbstractInvalidFormException.java)
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidFormException.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidFormException.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,52 @@
+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 InvalidFormException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ protected final Multimap<String, String> errors;
+
+ public InvalidFormException(Multimap<String, String> errors) {
+ this.errors = errors;
+ }
+
+ public Multimap<String, String> getErrors() {
+ return errors;
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() + " errors: " + errors;
+ }
+}
Modified: 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 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidPollFormException.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -31,7 +31,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.0
*/
-public class InvalidPollFormException extends AbstractInvalidFormException {
+public class InvalidPollFormException extends InvalidFormException {
private static final long serialVersionUID = 1L;
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidPollenUserFormException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidPollenUserFormException.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidPollenUserFormException.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -31,7 +31,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.0
*/
-public class InvalidPollenUserFormException extends AbstractInvalidFormException {
+public class InvalidPollenUserFormException extends InvalidFormException {
private static final long serialVersionUID = 1L;
public InvalidPollenUserFormException(Multimap<String, String> errors) {
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoteFormException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoteFormException.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoteFormException.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -31,7 +31,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.0
*/
-public class InvalidVoteFormException extends AbstractInvalidFormException {
+public class InvalidVoteFormException extends InvalidFormException {
private static final long serialVersionUID = 1L;
public InvalidVoteFormException(Multimap<String, String> errors) {
Modified: 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 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoterListFormException.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -31,7 +31,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.0
*/
-public class InvalidVoterListFormException extends AbstractInvalidFormException {
+public class InvalidVoterListFormException extends InvalidFormException {
private static final long serialVersionUID = 1L;
Modified: 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 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/exception/InvalidVoterListMemberFormException.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -31,7 +31,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.0
*/
-public class InvalidVoterListMemberFormException extends AbstractInvalidFormException {
+public class InvalidVoterListMemberFormException extends InvalidFormException {
private static final long serialVersionUID = 1L;
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AuthService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AuthService.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/AuthService.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -27,7 +27,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.pollen.persistence.entity.PollenUser;
-import org.chorem.pollen.persistence.entity.PollenUserTopiaDao;
import org.chorem.pollen.persistence.entity.SessionToken;
import org.chorem.pollen.persistence.entity.SessionTokenTopiaDao;
import org.chorem.pollen.services.exception.EntityNotFoundException;
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -31,8 +31,8 @@
import org.chorem.pollen.persistence.entity.ChoiceTopiaDao;
import org.chorem.pollen.persistence.entity.Poll;
import org.chorem.pollen.persistence.entity.PollenPrincipal;
-import org.chorem.pollen.services.exception.EntityNotFoundException;
-import org.chorem.pollen.services.exception.InvalidChoiceFormException;
+import org.chorem.pollen.services.exception.InvalidFormException;
+import org.chorem.pollen.services.service.security.PermissionVerb;
import java.util.List;
import java.util.Set;
@@ -45,7 +45,7 @@
*/
public class ChoiceService extends PollenServiceSupport {
- public List<Choice> getChoices(String pollId) throws EntityNotFoundException {
+ public List<Choice> getChoices(String pollId) {
Preconditions.checkNotNull(pollId);
Poll poll = getPollService().getPoll(pollId);
@@ -53,7 +53,7 @@
return poll.getChoice();
}
- public Choice getChoice(String pollId, String choiceId) throws EntityNotFoundException {
+ public Choice getChoice(String pollId, String choiceId) {
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(choiceId);
checkPermission(PermissionVerb.editChoice, choiceId);
@@ -63,10 +63,10 @@
return result;
}
- public Choice addChoice(String pollId, Choice choice) throws EntityNotFoundException, InvalidChoiceFormException {
+ public Choice addChoice(String pollId, Choice choice) throws InvalidFormException {
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(choice);
- checkHasNoId(choice);
+ checkIsNotPersisted(choice);
Poll poll = getPollService().getPoll(pollId);
checkPermission(PermissionVerb.addChoice, pollId);
@@ -81,9 +81,9 @@
return result;
}
- public Choice editChoice(String pollId, Choice choice) throws EntityNotFoundException, InvalidChoiceFormException {
+ public Choice editChoice(String pollId, Choice choice) throws InvalidFormException {
Preconditions.checkNotNull(choice);
- checkHasId(choice);
+ checkIsPersisted(choice);
checkPermission(PermissionVerb.editChoice, choice.getTopiaId());
Poll poll = getPollService().getPoll(pollId);
@@ -98,7 +98,7 @@
return result;
}
- public void deleteChoice(String pollId, String choiceId) throws EntityNotFoundException {
+ public void deleteChoice(String pollId, String choiceId) {
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(choiceId);
checkPermission(PermissionVerb.deleteChoice, choiceId);
@@ -113,14 +113,14 @@
//TODO Notify Choice deleted
}
- protected Choice getChoice(Poll poll, String choiceId) throws EntityNotFoundException {
+ protected Choice getChoice(Poll poll, String choiceId) {
Choice result = poll.getChoiceByTopiaId(choiceId);
checkEntityExists(Choice.class, result, choiceId);
return result;
}
- protected Choice saveChoice(Poll poll, Choice choice) throws EntityNotFoundException {
+ protected Choice saveChoice(Poll poll, Choice choice) {
ChoiceTopiaDao choiceDao = getChoiceDao();
@@ -169,7 +169,7 @@
return choiceToPersist;
}
- protected void checkChoiceForm(Poll poll, Choice choice) throws InvalidChoiceFormException {
+ protected void checkChoiceForm(Poll poll, Choice choice) throws InvalidFormException {
//TODO use nuiton validator ?
Multimap<String, String> errors = ArrayListMultimap.create();
@@ -218,7 +218,7 @@
if (!errors.isEmpty()) {
- throw new InvalidChoiceFormException(errors);
+ throw new InvalidFormException(errors);
}
}
}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/CommentService.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -32,6 +32,7 @@
import org.chorem.pollen.persistence.entity.PollenPrincipal;
import org.chorem.pollen.services.exception.EntityNotFoundException;
import org.chorem.pollen.services.exception.InvalidCommentFormException;
+import org.chorem.pollen.services.service.security.PermissionVerb;
import java.util.List;
@@ -63,7 +64,7 @@
public Comment addComment(String pollId, Comment comment) throws EntityNotFoundException, InvalidCommentFormException {
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(comment);
- checkHasNoId(comment);
+ checkIsNotPersisted(comment);
checkPermission(PermissionVerb.addComment, pollId);
Poll poll = getPollService().getPoll(pollId);
checkCommentForm(poll, comment);
@@ -78,7 +79,7 @@
public Comment editComment(String pollId, Comment comment) throws EntityNotFoundException, InvalidCommentFormException {
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(comment);
- checkHasId(comment);
+ checkIsPersisted(comment);
checkPermission(PermissionVerb.editComment, comment.getTopiaId());
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/FavoriteListService.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -51,6 +51,7 @@
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
@@ -88,7 +89,7 @@
FavoriteList favoriteList) throws EntityNotFoundException, InvalidFavoriteListFormException {
Preconditions.checkNotNull(userId);
Preconditions.checkNotNull(favoriteList);
- checkHasNoId(favoriteList);
+ checkIsNotPersisted(favoriteList);
PollenUser user = getUserService().getUser(userId);
@@ -107,7 +108,7 @@
public FavoriteList editFavoriteList(String userId,
FavoriteList favoriteList) throws EntityNotFoundException, InvalidFavoriteListFormException {
Preconditions.checkNotNull(favoriteList);
- checkHasId(favoriteList);
+ checkIsPersisted(favoriteList);
// get user
PollenUser user = getUserService().getUser(userId);
@@ -139,7 +140,7 @@
commit();
}
- public List<FavoriteListMember> getFavoriteListMembers(String userId, String favoriteListId) throws EntityNotFoundException {
+ public LinkedHashSet<FavoriteListMember> getFavoriteListMembers(String userId, String favoriteListId) throws EntityNotFoundException {
Preconditions.checkNotNull(userId);
Preconditions.checkNotNull(favoriteListId);
@@ -147,7 +148,7 @@
FavoriteList favoriteList = getFavoriteList(user, favoriteListId);
- return favoriteList.getFavoriteListMember();
+ return favoriteList.getMember();
}
public FavoriteListMember getFavoriteListMember(String userId, String favoriteListId, String memberId) throws EntityNotFoundException {
@@ -169,7 +170,7 @@
Preconditions.checkNotNull(userId);
Preconditions.checkNotNull(favoriteListId);
Preconditions.checkNotNull(member);
- checkHasNoId(member);
+ checkIsNotPersisted(member);
PollenUser user = getUserService().getUser(userId);
@@ -180,7 +181,7 @@
FavoriteListMember newMember =
getFavoriteListMemberDao().newInstance();
copyFavoriteListMember(member, newMember);
- favoriteList.addFavoriteListMember(newMember);
+ favoriteList.addMember(newMember);
getFavoriteListDao().update(favoriteList);
@@ -194,7 +195,7 @@
Preconditions.checkNotNull(userId);
Preconditions.checkNotNull(favoriteListId);
Preconditions.checkNotNull(member);
- checkHasId(member);
+ checkIsPersisted(member);
PollenUser user = getUserService().getUser(userId);
@@ -228,7 +229,7 @@
FavoriteListMember member = getFavoriteListMember(favoriteList, memberId);
- favoriteList.removeFavoriteListMember(member);
+ favoriteList.removeMember(member);
getFavoriteListDao().update(favoriteList);
commit();
@@ -250,8 +251,8 @@
Set<String> usedName = Sets.newHashSet();
Set<String> usedEmail = Sets.newHashSet();
- if (!favoriteList.isFavoriteListMemberEmpty()) {
- for (FavoriteListMember member : favoriteList.getFavoriteListMember()) {
+ if (!favoriteList.isMemberEmpty()) {
+ for (FavoriteListMember member : favoriteList.getMember()) {
usedName.add(member.getName());
usedEmail.add(member.getEmail());
}
@@ -311,7 +312,7 @@
member.setName(memberName);
member.setEmail(email);
- favoriteList.addFavoriteListMember(member);
+ favoriteList.addMember(member);
}
reader.close();
@@ -348,8 +349,8 @@
Set<String> usedName = Sets.newHashSet();
Set<String> usedEmail = Sets.newHashSet();
- if (!favoriteList.isFavoriteListMemberEmpty()) {
- for (FavoriteListMember member : favoriteList.getFavoriteListMember()) {
+ if (!favoriteList.isMemberEmpty()) {
+ for (FavoriteListMember member : favoriteList.getMember()) {
usedName.add(member.getName());
usedEmail.add(member.getEmail());
}
@@ -407,7 +408,7 @@
member.setName(memberName);
member.setEmail(email);
- favoriteList.addFavoriteListMember(member);
+ favoriteList.addMember(member);
}
}
} catch (NamingException ex) {
@@ -431,7 +432,7 @@
protected FavoriteListMember getFavoriteListMember(FavoriteList favoriteList, String memberId) throws EntityNotFoundException {
- FavoriteListMember result = favoriteList.getFavoriteListMemberByTopiaId(memberId);
+ FavoriteListMember result = favoriteList.getMemberByTopiaId(memberId);
checkEntityExists(FavoriteListMember.class, result, memberId);
return result;
}
@@ -473,14 +474,14 @@
check(errors, "name", !nameFound, "name already used by another favorite list");
- if (!favoriteList.isFavoriteListMemberEmpty()) {
+ if (!favoriteList.isMemberEmpty()) {
int memberIndex = 0;
Set<String> memberNames = Sets.newHashSet();
Set<String> memberEmails = Sets.newHashSet();
- for (FavoriteListMember member : favoriteList.getFavoriteListMember()) {
+ for (FavoriteListMember member : favoriteList.getMember()) {
String choiceField = "favoriteListMember[" + (memberIndex++) + "].";
@@ -521,11 +522,11 @@
Set<String> memberNames = Sets.newHashSet();
Set<String> memberEmails = Sets.newHashSet();
- if (!favoriteList.isFavoriteListMemberEmpty()) {
+ if (!favoriteList.isMemberEmpty()) {
// get all used names
- for (FavoriteListMember member : favoriteList.getFavoriteListMember()) {
+ for (FavoriteListMember member : favoriteList.getMember()) {
if (voterListMemberExists && member.getTopiaId().equals(member.getTopiaId())) {
continue;
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/NotificationService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/NotificationService.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/NotificationService.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,102 @@
+package org.chorem.pollen.services.service;
+
+import org.chorem.pollen.persistence.entity.Choice;
+import org.chorem.pollen.persistence.entity.Comment;
+import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.persistence.entity.PollenUser;
+import org.chorem.pollen.persistence.entity.Vote;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class NotificationService extends PollenServiceSupport {
+
+ public enum NotificationType {
+
+ // -- poll -- //
+ createPoll,
+ editPoll,
+ deletePoll,
+ closePoll,
+
+ // -- choice -- //
+ addChoice,
+ editChoice,
+ deleteChoice,
+
+ // -- comment -- //
+ addComment,
+ editComment,
+ deleteComment,
+
+ // -- vote -- //
+ addVote,
+ editVote,
+ deleteVote,
+ }
+
+ public void onAccountCreated(PollenUser pollenUser) {
+
+ }
+
+ public void onLostPasswordAsked(PollenUser pollenUser) {
+
+ }
+
+ public void onPollCreated(Poll poll) {
+
+ }
+
+ public void onPollEdited(Poll poll) {
+
+ }
+
+ public void onPollDeleted(Poll poll) {
+
+ }
+
+ public void onPollClosed(Poll poll) {
+
+ }
+
+ public void onChoiceAdded(Poll poll, Choice choice) {
+
+ }
+
+ public void onChoiceEdited(Poll poll, Choice choice) {
+
+ }
+
+ public void onChoiceDeleted(Poll poll, Choice choice) {
+
+ }
+
+ public void onCommentAdded(Poll poll, Comment comment) {
+
+ }
+
+ public void onCommentEdited(Poll poll, Comment comment) {
+
+ }
+
+ public void onCommentDeleted(Poll poll, Comment comment) {
+
+ }
+
+ public void onVoteAdded(Poll poll, Vote vote) {
+
+ }
+
+ public void onVoteEdited(Poll poll, Vote vote) {
+
+ }
+
+ public void onVoteDeleted(Poll poll, Vote vote) {
+
+ }
+
+
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/NotificationService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Deleted: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PermissionVerb.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PermissionVerb.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PermissionVerb.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -1,57 +0,0 @@
-package org.chorem.pollen.services.service;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public enum PermissionVerb {
- readPoll,
- readChoice,
- readComment,
- readVote,
-
- addPoll,
- addChoice,
- addComment,
- addVote,
-
- editPoll,
- editChoice,
- editComment,
- editVote,
-
- deletePoll,
- deleteChoice,
- deleteComment,
- deleteVote,
-
- closePoll,
- clonePoll,
- exportPoll,
-
-}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -23,8 +23,8 @@
* #L%
*/
-import com.google.common.base.Preconditions;
import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
@@ -37,10 +37,12 @@
import org.chorem.pollen.persistence.entity.Polls;
import org.chorem.pollen.persistence.entity.VoterList;
import org.chorem.pollen.persistence.entity.VoterListMember;
-import org.chorem.pollen.services.exception.EntityNotFoundException;
-import org.chorem.pollen.services.exception.InvalidPollFormException;
+import org.chorem.pollen.services.exception.InvalidFormException;
+import org.chorem.pollen.services.service.security.PermissionVerb;
+import org.chorem.pollen.services.service.security.SecurityRole;
import java.io.File;
+import java.util.List;
import java.util.Set;
/**
@@ -51,43 +53,52 @@
*/
public class PollService extends PollenServiceSupport {
- public Set<Poll> getPolls(String userId) throws EntityNotFoundException {
- return Sets.newHashSet(getPollDao().findAll());
+ public ImmutableSet<Poll> getPolls() {
+
+ checkRole(SecurityRole.administrator);
+ List<Poll> polls = getPollDao().findAll();
+ return ImmutableSet.<Poll>builder().addAll(polls).build();
+
}
- public Set<Poll> getCreatedPolls(String userId) throws EntityNotFoundException {
- Preconditions.checkNotNull(userId);
+ public ImmutableSet<Poll> getCreatedPolls() {
- getUserService().getUser(userId);
+ checkRole(SecurityRole.connected);
+ PollenUser connectedUser = getConnectedUser();
+ Set<Poll> polls = getPollDao().findAllCreated(connectedUser);
+ return ImmutableSet.<Poll>builder().addAll(polls).build();
- return getPollDao().findAllCreated(userId);
}
- public Set<Poll> getInvitedPolls(String userId) throws EntityNotFoundException {
- Preconditions.checkNotNull(userId);
+ public ImmutableSet<Poll> getInvitedPolls() {
- getUserService().getUser(userId);
+ checkRole(SecurityRole.connected);
+ PollenUser connectedUser = getConnectedUser();
+ Set<Poll> polls = getPollDao().findAllInvited(connectedUser);
+ return ImmutableSet.<Poll>builder().addAll(polls).build();
- return getPollDao().findAllInvited(userId);
}
- public Set<Poll> getParticipatedPolls(String userId) throws EntityNotFoundException {
- Preconditions.checkNotNull(userId);
+ public ImmutableSet<Poll> getParticipatedPolls() {
- getUserService().getUser(userId);
+ checkRole(SecurityRole.connected);
+ PollenUser connectedUser = getConnectedUser();
+ Set<Poll> polls = getPollDao().findAllParticipated(connectedUser);
+ return ImmutableSet.<Poll>builder().addAll(polls).build();
- return getPollDao().findAllParticipated(userId);
}
- public Poll getPoll(String pollId) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
+ public Poll getPoll(String pollId) {
+
+ checkNotNull(pollId);
checkPermission(PermissionVerb.readPoll, pollId);
- Poll result = getPollDao().findByTopiaId(pollId);
+ Poll result = getPollDao().forTopiaIdEquals(pollId).findUniqueOrNull();
checkEntityExists(Poll.class, result, pollId);
return result;
+
}
- public Poll getNewPoll(String userId) throws EntityNotFoundException {
+ public Poll getNewPoll() {
Poll result = getPollDao().newInstance();
@@ -104,95 +115,100 @@
PollenPrincipal creator = getPollenPrincipalDao().newInstance();
result.setCreator(creator);
- if (userId != null) {
- PollenUser user = getUserService().getUser(userId);
+ PollenUser connectedUser = getConnectedUser();
- creator.setName(user.getName());
- creator.setEmail(user.getEmail());
+ if (connectedUser != null) {
+
+ creator.setName(connectedUser.getName());
+ creator.setEmail(connectedUser.getEmail());
}
result.setChoice(Lists.<Choice>newArrayList());
result.setVoterList(Lists.<VoterList>newArrayList());
return result;
+
}
- public Poll createPoll(String userId, Poll poll) throws EntityNotFoundException, InvalidPollFormException {
+ public Poll createPoll(Poll poll) throws InvalidFormException {
- Preconditions.checkNotNull(poll);
- checkHasNoId(poll);
-
+ checkNotNull(poll);
+ checkIsNotPersisted(poll);
checkPollForm(poll);
- Poll pollToPersist = savePoll(userId, poll);
+ Poll savedPoll = savePoll(poll);
- getPollDao().create(pollToPersist);
+ getPollDao().create(savedPoll);
commit();
- return pollToPersist;
+ getNotificationService().onPollCreated(poll);
+ return savedPoll;
+
}
- public Poll editPoll(Poll poll) throws EntityNotFoundException, InvalidPollFormException {
- Preconditions.checkNotNull(poll);
- checkHasId(poll);
+ public Poll editPoll(Poll poll) throws InvalidFormException {
+ checkNotNull(poll);
+ checkIsPersisted(poll);
checkPermission(PermissionVerb.editPoll, poll.getTopiaId());
-
checkPollForm(poll);
- Poll toSave = savePoll(null, poll);
+ Poll savedPoll = savePoll(poll);
- getPollDao().update(toSave);
+ getPollDao().update(savedPoll);
commit();
+ getNotificationService().onPollEdited(poll);
+ return savedPoll;
- return toSave;
}
+ public void deletePoll(String pollId) {
- public void deletePoll(String pollId) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
-
+ checkNotNull(pollId);
checkPermission(PermissionVerb.deletePoll, pollId);
Poll poll = getPoll(pollId);
getPollDao().delete(poll);
commit();
+ getNotificationService().onPollDeleted(poll);
- if (poll.getCreator().getEmail() != null) {
-
- //TODO Notify ?
- }
}
- public Poll clonePoll(String pollId) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
+ public Poll clonePoll(String pollId) {
+ checkNotNull(pollId);
checkPermission(PermissionVerb.clonePoll, pollId);
Poll poll = getPoll(pollId);
//TODO
commit();
- return null;
+ getNotificationService().onPollCreated(poll);
+ return poll;
+
}
- public File closePoll(String pollId) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
+ public void closePoll(String pollId) {
+
+ checkNotNull(pollId);
checkPermission(PermissionVerb.closePoll, pollId);
Poll poll = getPoll(pollId);
//TODO
commit();
- return null;
+ getNotificationService().onPollClosed(poll);
+
}
- public File exportPoll(String pollId) throws EntityNotFoundException {
- Preconditions.checkNotNull(pollId);
+ public File exportPoll(String pollId) {
+
+ checkNotNull(pollId);
checkPermission(PermissionVerb.exportPoll, pollId);
Poll poll = getPoll(pollId);
//TODO
return null;
+
}
- protected Poll savePoll(String userId, Poll poll) throws EntityNotFoundException {
+ protected Poll savePoll(Poll poll) {
boolean pollExists = poll.isPersisted();
@@ -214,11 +230,12 @@
// -- creator -- //
- if (userId != null) {
+ PollenUser connectedUser = getConnectedUser();
+ if (connectedUser != null) {
+
// link to connected user
- PollenUser user = getUserService().getUser(userId);
- toSave.getCreator().setPollenUser(user);
+ toSave.getCreator().setPollenUser(connectedUser);
}
PollenPrincipal creator = poll.getCreator();
@@ -265,27 +282,28 @@
}
return toSave;
+
}
- protected void checkPollForm(Poll poll) throws InvalidPollFormException {
+ protected void checkPollForm(Poll poll) throws InvalidFormException {
//TODO use nuiton validator ?
Multimap<String, String> errors = ArrayListMultimap.create();
- checkNotNull(errors, "pollType", poll.getPollType(), "pollType 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");
+ checkNotNull(errors, Poll.PROPERTY_POLL_TYPE, poll.getPollType(), "pollType can not be null");
+ checkNotNull(errors, Poll.PROPERTY_COMMENT_VISIBILITY, poll.getCommentVisibility(), "commentVisibility can not be null");
+ checkNotNull(errors, Poll.PROPERTY_VOTE_VISIBILITY, poll.getVoteVisibility(), "voteVisibility can not be null");
+ checkNotNull(errors, Poll.PROPERTY_VOTE_COUNTING_TYPE, poll.getVoteCountingType(), "voteCountingType can not be null");
- checkNotBlank(errors, "title", poll.getTitle(), "title can not be empty");
- checkNotEmpty(errors, "choice", poll.getChoice(), "need at least one choice");
+ checkNotBlank(errors, Poll.PROPERTY_TITLE, poll.getTitle(), "title can not be empty");
+ checkNotEmpty(errors, Poll.PROPERTY_CHOICE, poll.getChoice(), "need at least one choice");
if (Polls.isPollFree(poll)) {
- checkEmpty(errors, "voterList", poll.getVoterList(), "can't have voterList with free poll");
+ checkEmpty(errors, Poll.PROPERTY_VOTER_LIST, poll.getVoterList(), "can't have voterList with free poll");
} else if (Polls.isPollRestricted(poll)) {
- check(errors, "voterList", 1 == poll.sizeVoterList(), "must have a unique voterList with a resitricted poll");
+ check(errors, Poll.PROPERTY_VOTER_LIST, 1 == poll.sizeVoterList(), "must have a unique voterList with a resitricted poll");
} else if (Polls.isPollGroup(poll)) {
- checkNotEmpty(errors, "voterList", poll.getVoterList(), "must have at least one voterList with a group poll");
+ checkNotEmpty(errors, Poll.PROPERTY_VOTER_LIST, poll.getVoterList(), "must have at least one voterList with a group poll");
}
if (!poll.isChoiceEmpty()) {
@@ -296,19 +314,19 @@
for (Choice choice : poll.getChoice()) {
- String choiceField = "choice[" + (choiceIndex++) + "]";
+ String choiceField = Poll.PROPERTY_CHOICE + "[" + (choiceIndex++) + "].";
checkNotNull(errors,
- choiceField + ".choiceType",
+ choiceField + Choice.PROPERTY_CHOICE_TYPE,
choice.getChoiceType(),
"choiceType can not be null");
- if (choice.getChoiceType()!=null) {
+ if (choice.getChoiceType() != null) {
switch (choice.getChoiceType()) {
case TEXT:
checkNotBlank(errors,
- choiceField + ".name",
+ choiceField + Choice.PROPERTY_NAME,
choice.getName(),
"choice name can not be empty");
@@ -333,17 +351,17 @@
for (VoterList voterList : poll.getVoterList()) {
- String voterListField = "voterList[" + (voterListIndex++) + "].";
+ String voterListField = Poll.PROPERTY_VOTER_LIST + "[" + (voterListIndex++) + "].";
- boolean notBlankName = checkNotBlank(errors, voterListField + "name", voterList.getName(), "voterList name can not be empty");
+ boolean notBlankName = checkNotBlank(errors, voterListField + VoterList.PROPERTY_NAME, voterList.getName(), "voterList name can not be empty");
if (notBlankName) {
boolean added = voterListNames.add(voterList.getName());
- check(errors, voterListField + "name", added, "voterList name already used");
+ check(errors, voterListField + VoterList.PROPERTY_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");
+ check(errors, voterListField + VoterList.PROPERTY_WEIGHT, voterList.getWeight() > 0, "voterList weight must be greater than 0");
+ boolean withMember = checkNotEmpty(errors, voterListField + VoterList.PROPERTY_MEMBER, voterList.getMember(), "voterList must contains at least one member");
if (withMember) {
Set<String> voterListMemberNames = Sets.newHashSet();
@@ -351,32 +369,32 @@
int voterListMemberIndex = 0;
- for (VoterListMember voterListMember : voterList.getVoterListMember()) {
+ for (VoterListMember voterListMember : voterList.getMember()) {
- String voterListMemberField = voterListField + "member[" + (voterListMemberIndex++) + "].";
+ String voterListMemberField = voterListField + VoterList.PROPERTY_MEMBER + "[" + (voterListMemberIndex++) + "].";
String voterListMemberName = voterListMember.getName();
- boolean nameNotNull = checkNotBlank(errors, voterListMemberField + "name", voterListMemberName, "member name can not be empty");
+ boolean nameNotNull = checkNotBlank(errors, voterListMemberField + VoterListMember.PROPERTY_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");
+ check(errors, voterListMemberField + VoterListMember.PROPERTY_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");
+ boolean emailNotNull = checkNotBlank(errors, voterListMemberField + VoterListMember.PROPERTY_EMAIL, voterListMemberEmail, "member email can not be empty");
if (emailNotNull) {
voterListMemberEmail = StringUtils.lowerCase(voterListMemberEmail);
- checkValidEmail(errors, voterListMemberField + "email", voterListMemberEmail, "member email is not valid");
+ checkValidEmail(errors, voterListMemberField + VoterListMember.PROPERTY_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 + VoterListMember.PROPERTY_EMAIL, emailAdded, "member email already used in this list");
}
- check(errors, voterListMemberField + "weight", voterListMember.getWeight() > 0, "member weight must be greater than 0");
+ check(errors, voterListMemberField + VoterListMember.PROPERTY_WEIGHT, voterListMember.getWeight() > 0, "member weight must be greater than 0");
}
}
}
@@ -384,7 +402,8 @@
if (!errors.isEmpty()) {
- throw new InvalidPollFormException(errors);
+ throw new InvalidFormException(errors);
}
+
}
}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -34,6 +34,7 @@
import org.chorem.pollen.persistence.entity.FavoriteListTopiaDao;
import org.chorem.pollen.persistence.entity.PollTopiaDao;
import org.chorem.pollen.persistence.entity.PollenPrincipalTopiaDao;
+import org.chorem.pollen.persistence.entity.PollenUser;
import org.chorem.pollen.persistence.entity.PollenUserTopiaDao;
import org.chorem.pollen.persistence.entity.SessionTokenTopiaDao;
import org.chorem.pollen.persistence.entity.VoteToChoiceTopiaDao;
@@ -44,6 +45,10 @@
import org.chorem.pollen.services.PollenServiceContext;
import org.chorem.pollen.services.config.PollenServiceConfig;
import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.chorem.pollen.services.service.mail.EmailService;
+import org.chorem.pollen.services.service.security.PermissionVerb;
+import org.chorem.pollen.services.service.security.SecurityRole;
+import org.chorem.pollen.services.service.security.SecurityService;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.util.StringUtil;
@@ -111,6 +116,14 @@
return newService(FavoriteListService.class);
}
+ protected EmailService getEmailService() {
+ return newService(EmailService.class);
+ }
+
+ protected NotificationService getNotificationService() {
+ return newService(NotificationService.class);
+ }
+
protected PollService getPollService() {
return newService(PollService.class);
}
@@ -199,16 +212,28 @@
// -- check method -- //
+ protected PollenUser getConnectedUser() {
+ return serviceContext.getSecurityContext().getPollenUser();
+ }
+
protected void checkPermission(PermissionVerb verb, String id) {
String permission = createPermission(verb, id);
-// serviceContext.getSecurityContext().getSubject().checkPermission(permission);
+ serviceContext.getSecurityContext().checkPermission(permission);
}
- protected void checkHasId(TopiaEntity entity) {
+ protected void checkRole(SecurityRole role) {
+ serviceContext.getSecurityContext().checkRole(role);
+ }
+
+ protected void checkNotNull(Object object) {
+ Preconditions.checkNotNull(object);
+ }
+
+ protected void checkIsPersisted(TopiaEntity entity) {
Preconditions.checkState(entity.isPersisted());
}
- protected void checkHasNoId(TopiaEntity entity) {
+ protected void checkIsNotPersisted(TopiaEntity entity) {
Preconditions.checkState(!entity.isPersisted());
}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -23,7 +23,6 @@
* #L%
*/
-import com.google.common.base.Preconditions;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import org.apache.commons.lang3.ObjectUtils;
@@ -34,6 +33,7 @@
import org.chorem.pollen.services.exception.InvalidPollenUserFormException;
import org.chorem.pollen.services.exception.UserInvalidEmailActivationTokenException;
import org.chorem.pollen.services.exception.UserInvalidPasswordException;
+import org.chorem.pollen.services.service.security.SecurityRole;
import org.nuiton.topia.persistence.TopiaNoResultException;
import java.util.List;
@@ -47,11 +47,15 @@
public class PollenUserService extends PollenServiceSupport implements PollenService {
public List<PollenUser> getUsers() {
- return getPollenUserDao().findAll();
+
+ checkRole(SecurityRole.administrator);
+ List<PollenUser> pollenUsers = getPollenUserDao().findAll();
+ return pollenUsers;
+
}
public PollenUser getUser(String userId) throws EntityNotFoundException {
- Preconditions.checkNotNull(userId);
+ checkNotNull(userId);
try {
PollenUser result = getPollenUserDao().findByTopiaId(userId);
@@ -62,7 +66,7 @@
}
public PollenUser getUserByLogin(String login) throws EntityNotFoundException {
- Preconditions.checkNotNull(login);
+ checkNotNull(login);
try {
PollenUser result = getPollenUserDao().forLoginEquals(login).findAny();
return result;
@@ -71,9 +75,9 @@
}
}
- public PollenUser createUser(PollenUser user, boolean generatePassword) throws InvalidPollenUserFormException, EntityNotFoundException {
- Preconditions.checkNotNull(user);
- checkHasNoId(user);
+ public PollenUser createUser(PollenUser user, boolean generatePassword) throws InvalidPollenUserFormException {
+ checkNotNull(user);
+ checkIsNotPersisted(user);
checkPollenUserForm(user);
PollenUser result = savePollenUser(user, generatePassword);
@@ -84,9 +88,9 @@
return result;
}
- public PollenUser editUser(PollenUser user) throws EntityNotFoundException, InvalidPollenUserFormException {
- Preconditions.checkNotNull(user);
- checkHasId(user);
+ public PollenUser editUser(PollenUser user) throws InvalidPollenUserFormException {
+ checkNotNull(user);
+ checkIsPersisted(user);
checkPollenUserForm(user);
PollenUser result = savePollenUser(user, false);
@@ -97,8 +101,8 @@
return result;
}
- public void deleteUser(String userId) throws EntityNotFoundException, InvalidPollenUserFormException {
- Preconditions.checkNotNull(userId);
+ public void deleteUser(String userId) {
+ checkNotNull(userId);
PollenUser user = getUser(userId);
getPollenUserDao().delete(user);
@@ -107,10 +111,10 @@
public void changePassword(String userId,
String oldPassword,
- String newPassword) throws EntityNotFoundException, UserInvalidPasswordException {
- Preconditions.checkNotNull(userId);
- Preconditions.checkNotNull(oldPassword);
- Preconditions.checkNotNull(newPassword);
+ String newPassword) throws UserInvalidPasswordException {
+ checkNotNull(userId);
+ checkNotNull(oldPassword);
+ checkNotNull(newPassword);
PollenUser user = getUser(userId);
@@ -130,10 +134,10 @@
}
public void validateUserEmail(String userId,
- String token) throws EntityNotFoundException, UserInvalidEmailActivationTokenException {
+ String token) throws UserInvalidEmailActivationTokenException {
- Preconditions.checkNotNull(userId);
- Preconditions.checkNotNull(token);
+ checkNotNull(userId);
+ checkNotNull(token);
PollenUser user = getUser(userId);
@@ -151,7 +155,7 @@
commit();
}
- public void createDefaultUsers() throws EntityNotFoundException, InvalidPollenUserFormException {
+ public void createDefaultUsers() throws InvalidPollenUserFormException {
if (getPollenUserDao().count() == 0) {
@@ -166,7 +170,7 @@
}
}
- protected void checkPollenUserForm(PollenUser user) throws EntityNotFoundException, InvalidPollenUserFormException {
+ protected void checkPollenUserForm(PollenUser user) throws InvalidPollenUserFormException {
//TODO use nuiton validator ?
Multimap<String, String> errors = ArrayListMultimap.create();
@@ -218,8 +222,7 @@
}
}
- protected PollenUser savePollenUser(PollenUser user,
- boolean generatePassword) throws EntityNotFoundException {
+ protected PollenUser savePollenUser(PollenUser user, boolean generatePassword) {
boolean userExists = user.isPersisted();
Deleted: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -1,258 +0,0 @@
-package org.chorem.pollen.services.service;
-
-/*
- * #%L
- * Pollen :: Service
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2013 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import org.apache.shiro.subject.Subject;
-import org.chorem.pollen.persistence.entity.Choice;
-import org.chorem.pollen.persistence.entity.Comment;
-import org.chorem.pollen.persistence.entity.Poll;
-import org.chorem.pollen.persistence.entity.PollenPrincipal;
-import org.chorem.pollen.persistence.entity.PollenPrincipalTopiaDao;
-import org.chorem.pollen.persistence.entity.PollenUser;
-import org.chorem.pollen.persistence.entity.Polls;
-import org.chorem.pollen.persistence.entity.Vote;
-import org.chorem.pollen.persistence.entity.VoterListMember;
-import org.chorem.pollen.services.PollenSecurityContext;
-import org.nuiton.topia.persistence.TopiaEntity;
-
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * TODO
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class SecurityService extends PollenServiceSupport {
-
- public PollenPrincipal generatePrincipal() {
- PollenPrincipalTopiaDao pollenPrincipalDao = getPersistenceContext().getPollenPrincipalDao();
- PollenPrincipal principal = pollenPrincipalDao.newInstance();
- principal.setCreationDate(serviceContext.getNow());
- pollenPrincipalDao.create(principal);
- return principal;
- }
-
- public void prepareSubject(TopiaEntity entity) {
- Preconditions.checkNotNull(entity);
- prepareSubject(entity.getTopiaId());
- }
-
- public void prepareSubject(String principalId) {
- PollenSecurityContext securityContext = serviceContext.getSecurityContext();
- Preconditions.checkNotNull(securityContext);
- PollenUser pollenUser = securityContext.getPollenUser();
- Subject subject = getSubject(principalId, pollenUser);
- securityContext.setSubject(subject);
- }
-
- protected Subject getSubject(String principalId, PollenUser user) {
- Set<String> permissions = Sets.newHashSet();
-
- boolean userConnected = user != null;
- boolean userIsAdmin = userConnected && user.isAdministrator();
-
- if (userIsAdmin) {
- permissions.add("*:*:*");
- } else {
-
- Set<PollenPrincipal> principals = Sets.newHashSet();
-
- PollenPrincipalTopiaDao pollenPrincipalDao =
- getPersistenceContext().getPollenPrincipalDao();
-
- if (principalId != null) {
- PollenPrincipal pollenPrincipal =
- pollenPrincipalDao.findByTopiaId(principalId);
- principals.add(pollenPrincipal);
- }
-
- if (userConnected) {
-
- // find all principals
- List<PollenPrincipal> allByPollenUser =
- pollenPrincipalDao.findAllByPollenUser(user);
- principals.addAll(allByPollenUser);
- }
-
- Map<PollenPrincipal, TopiaEntity> principalTopiaEntityMap = Maps.newHashMap();
-
- for (PollenPrincipal principal : principals) {
-
- // find out which entity is using this principal
- TopiaEntity entity = getPrincipalEntity(principal);
- principalTopiaEntityMap.put(principal, entity);
-
- if (entity instanceof Poll) {
-
- // add all poll entities
- Poll poll = (Poll) entity;
-
- if (!poll.isChoiceEmpty()) {
- for (Choice choice : poll.getChoice()) {
- principalTopiaEntityMap.put(choice.getCreator(), choice);
- }
- }
-
- if (!poll.isCommentEmpty()) {
- for (Comment comment : poll.getComment()) {
- principalTopiaEntityMap.put(comment.getAuthor(), comment);
- }
- }
-
- if (!poll.isVoteEmpty()) {
- for (Vote vote : poll.getVote()) {
- principalTopiaEntityMap.put(vote.getVoter(), vote);
- }
- }
- }
- }
-
- Date now = serviceContext.getNow();
- for (Map.Entry<PollenPrincipal, TopiaEntity> entry : principalTopiaEntityMap.entrySet()) {
- TopiaEntity entity = entry.getValue();
-
- if (entity instanceof Choice) {
- permissions.add(createWildcardSubjectPermission(entity));
- continue;
- }
- if (entity instanceof Comment) {
- permissions.add(createWildcardSubjectPermission(entity));
- continue;
- }
- if (entity instanceof Vote) {
- permissions.add(createWildcardSubjectPermission(entity));
- continue;
- }
- if (entity instanceof Poll) {
- //TODO Get alls possible permissions on poll
-
- Poll poll = (Poll) entity;
-
- Set<VoterListMember> members = Polls.getAllVoters(poll);
-
- boolean freePoll = Polls.isPollFree(poll);
-
- if (freePoll) {
-
- // everybody can read poll ?
- permissions.add(createSubjectPermission(PermissionVerb.readPoll, entity));
- } else {
-
- // only his creator / participants / voters can read it
-
- for (VoterListMember member : members) {
- permissions.add(createSubjectPermission(member.getTopiaId(), PermissionVerb.readPoll, entity));
- }
- }
-
- // add editVote / deleteVote for any voter
- if (!poll.isVoteEmpty()) {
- for (Vote vote : poll.getVote()) {
- String id = vote.getVoter().getTopiaId();
- permissions.add(createSubjectPermission(id, PermissionVerb.editVote, vote));
- permissions.add(createSubjectPermission(id, PermissionVerb.deleteVote, vote));
- }
- }
-
- //TODO Not do this here, but later in business code
-// if (poll.isAddChoiceRunning(now)) {
-//
-// permissions.add(createSubjectPermission(PermissionVerb.addChoice, entity));
-// }
-//
-// if (poll.getCommentVisibility() != CommentVisibility.NOBODY) {
-// //FIXME Should see with voter ?
-// permissions.add(createSubjectPermission(PermissionVerb.addComment, entity));
-// }
-//
-// if (poll.isRunning(now)) {
-// permissions.add(createSubjectPermission(PermissionVerb.addVote, entity));
-// }
-
- //TODO Do for editVote,...
- }
- }
- }
-
-// SimplePrincipalCollection principalCollection = new SimplePrincipalCollection();
-// principalCollection.addAll(permissions, "pollenRealm");
-// Subject subject = new Subject.Builder().principals(principalCollection).buildSubject();
-// return subject;
- return null;
- }
-
- protected TopiaEntity getPrincipalEntity(PollenPrincipal principal) {
-
- TopiaEntity result = null;
-
- // try a poll
- Poll poll = getPollDao().findByCreator(principal);
- if (poll == null) {
-
- // try a choice
- Choice choice = getChoiceDao().findByCreator(principal);
- if (choice == null) {
-
- // try a vote
- Vote vote = getVoteDao().findByVoter(principal);
- if (vote == null) {
-
- // try a comment
- Comment comment = getCommentDao().findByAuthor(principal);
- if (comment != null) {
- result = comment;
- }
- } else {
- result = vote;
- }
- } else {
- result = choice;
- }
- } else {
- result = poll;
- }
-
- Preconditions.checkNotNull(result);
- return result;
- }
-
- protected String createSubjectPermission(String people, PermissionVerb verb, TopiaEntity entity) {
- return people + ":" + verb.name() + ":" + entity.getTopiaId();
- }
-
- protected String createSubjectPermission(PermissionVerb verb, TopiaEntity entity) {
- return createSubjectPermission("*", verb, entity);
- }
-
- protected String createWildcardSubjectPermission(TopiaEntity entity) {
- return "*:*:" + entity.getTopiaId();
- }
-}
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -31,6 +31,7 @@
import org.chorem.pollen.persistence.entity.Vote;
import org.chorem.pollen.services.exception.EntityNotFoundException;
import org.chorem.pollen.services.exception.InvalidVoteFormException;
+import org.chorem.pollen.services.service.security.PermissionVerb;
import java.util.Date;
import java.util.List;
@@ -65,7 +66,7 @@
public Vote addVote(String pollId, Vote vote) throws EntityNotFoundException, InvalidVoteFormException {
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(vote);
- checkHasNoId(vote);
+ checkIsNotPersisted(vote);
checkPermission(PermissionVerb.addVote, pollId);
Poll poll = getPollService().getPoll(pollId);
@@ -81,7 +82,7 @@
public Vote editVote(String pollId, Vote vote) throws EntityNotFoundException, InvalidVoteFormException {
Preconditions.checkNotNull(vote);
- checkHasId(vote);
+ checkIsPersisted(vote);
checkPermission(PermissionVerb.editVote, vote.getTopiaId());
Poll poll = getPollService().getPoll(pollId);
@@ -123,7 +124,7 @@
Date now = serviceContext.getNow();
// poll must be started
- check(errors, "poll", Polls.isStarted(poll, now), "poll is not stardted");
+ check(errors, "poll", Polls.isStarted(poll, now), "poll is not started");
checkNotBlank(errors, "voter.name", vote.getVoter().getName(), "voter name can not be empty");
@@ -137,12 +138,12 @@
protected Vote saveVote(Poll poll, Vote vote) throws EntityNotFoundException {
- boolean commentExists = vote.isPersisted();
+ boolean voteExist = vote.isPersisted();
Vote toSave;
//TODO Finish save
- if (commentExists) {
+ if (voteExist) {
toSave = getVote(poll, vote.getTopiaId());
} else {
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/VoterListService.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -68,12 +68,12 @@
VoterListMemberTopiaDao voterListMemberDao =
getVoterListMemberDao();
- for (FavoriteListMember favoriteListMember : favoriteList.getFavoriteListMember()) {
+ for (FavoriteListMember favoriteListMember : favoriteList.getMember()) {
VoterListMember voterListMember = voterListMemberDao.newInstance();
voterListMember.setWeight(1d);
voterListMember.setEmail(favoriteListMember.getEmail());
- result.addVoterListMember(voterListMember);
+ result.addMember(voterListMember);
}
poll.addVoterList(result);
@@ -105,7 +105,7 @@
public VoterList addVoterList(String pollId, VoterList voterList) throws EntityNotFoundException, InvalidVoterListFormException {
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(voterList);
- checkHasNoId(voterList);
+ checkIsNotPersisted(voterList);
Poll poll = getPollService().getPoll(pollId);
checkVoterList(poll, voterList);
@@ -120,7 +120,7 @@
public VoterList editVoterList(String pollId, VoterList voterList) throws EntityNotFoundException, InvalidVoterListFormException {
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(voterList);
- checkHasId(voterList);
+ checkIsPersisted(voterList);
Poll poll = getPollService().getPoll(pollId);
checkVoterList(poll, voterList);
@@ -152,7 +152,7 @@
VoterList voterList = getVoterList(pollId, voterListId);
- Set<VoterListMember> result = voterList.getVoterListMember();
+ Set<VoterListMember> result = voterList.getMember();
return result;
}
@@ -172,7 +172,7 @@
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(voterListId);
Preconditions.checkNotNull(member);
- checkHasNoId(member);
+ checkIsNotPersisted(member);
VoterList voterList = getVoterList(pollId, voterListId);
@@ -190,7 +190,7 @@
Preconditions.checkNotNull(pollId);
Preconditions.checkNotNull(voterListId);
Preconditions.checkNotNull(member);
- checkHasId(member);
+ checkIsPersisted(member);
VoterList voterList = getVoterList(pollId, voterListId);
@@ -211,7 +211,7 @@
VoterList voterList = getVoterList(pollId, voterListId);
VoterListMember member = getVoterListMember(voterList, memberId);
- voterList.removeVoterListMember(member);
+ voterList.removeMember(member);
// getVoterListDao().merge(voterList);
@@ -228,7 +228,7 @@
protected VoterListMember getVoterListMember(VoterList voterList, String memberId) throws EntityNotFoundException {
Preconditions.checkNotNull(memberId);
- VoterListMember result = voterList.getVoterListMemberByTopiaId(memberId);
+ VoterListMember result = voterList.getMemberByTopiaId(memberId);
checkEntityExists(VoterListMember.class, result, memberId);
return result;
}
@@ -254,7 +254,7 @@
toSave.setName(voterList.getName());
toSave.setWeight(voterList.getWeight());
- for (VoterListMember voterListMember : voterList.getVoterListMember()) {
+ for (VoterListMember voterListMember : voterList.getMember()) {
saveVoterListMember(toSave, voterListMember);
}
@@ -279,7 +279,7 @@
toSave = voterListMemberDao.newInstance();
- voterList.addVoterListMember(toSave);
+ voterList.addMember(toSave);
}
toSave.setName(voterListMember.getName());
@@ -314,7 +314,7 @@
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");
+ checkNotEmpty(errors, "member", voterList.getMember(), "voterList must contains at least one member");
boolean added = voterListNames.add(voterList.getName());
@@ -325,7 +325,7 @@
int voterListMemberIndex = 0;
- for (VoterListMember voterListMember : voterList.getVoterListMember()) {
+ for (VoterListMember voterListMember : voterList.getMember()) {
String voterListMemberField = "member[" + (voterListMemberIndex++) + "].";
@@ -364,11 +364,11 @@
Set<String> voterListMemberNames = Sets.newHashSet();
Set<String> voterListMemberEmails = Sets.newHashSet();
- if (!voterList.isVoterListMemberEmpty()) {
+ if (!voterList.isMemberEmpty()) {
// get all used names
- for (VoterListMember member : voterList.getVoterListMember()) {
+ for (VoterListMember member : voterList.getMember()) {
if (voterListMemberExists &&
member.getTopiaId().equals(voterListMember.getTopiaId())) {
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/ChoiceAddedEmail.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/ChoiceAddedEmail.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/ChoiceAddedEmail.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,45 @@
+package org.chorem.pollen.services.service.mail;
+
+import org.chorem.pollen.persistence.entity.Choice;
+import org.chorem.pollen.persistence.entity.Poll;
+import org.nuiton.i18n.I18n;
+
+import java.util.Locale;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class ChoiceAddedEmail extends PollenMail {
+
+ protected Poll poll;
+
+ protected Choice choice;
+
+ protected ChoiceAddedEmail(Locale locale) {
+ super(locale);
+ }
+
+ @Override
+ public String getSubject() {
+ return I18n.l(locale, "pollen.service.mail.ChoiceAddedEmail.subject");
+ }
+
+ public Poll getPoll() {
+ return poll;
+ }
+
+ public void setPoll(Poll poll) {
+ this.poll = poll;
+ }
+
+ public Choice getChoice() {
+ return choice;
+ }
+
+ public void setChoice(Choice choice) {
+ this.choice = choice;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/ChoiceAddedEmail.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/ChoiceDeletedEmail.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/ChoiceDeletedEmail.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/ChoiceDeletedEmail.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,45 @@
+package org.chorem.pollen.services.service.mail;
+
+import org.chorem.pollen.persistence.entity.Choice;
+import org.chorem.pollen.persistence.entity.Poll;
+import org.nuiton.i18n.I18n;
+
+import java.util.Locale;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class ChoiceDeletedEmail extends PollenMail {
+
+ protected Poll poll;
+
+ protected Choice choice;
+
+ protected ChoiceDeletedEmail(Locale locale) {
+ super(locale);
+ }
+
+ @Override
+ public String getSubject() {
+ return I18n.l(locale, "pollen.service.mail.ChoiceDeletedEmail.subject");
+ }
+
+ public Poll getPoll() {
+ return poll;
+ }
+
+ public void setPoll(Poll poll) {
+ this.poll = poll;
+ }
+
+ public Choice getChoice() {
+ return choice;
+ }
+
+ public void setChoice(Choice choice) {
+ this.choice = choice;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/ChoiceDeletedEmail.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/ChoiceEditedEmail.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/ChoiceEditedEmail.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/ChoiceEditedEmail.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,45 @@
+package org.chorem.pollen.services.service.mail;
+
+import org.chorem.pollen.persistence.entity.Choice;
+import org.chorem.pollen.persistence.entity.Poll;
+import org.nuiton.i18n.I18n;
+
+import java.util.Locale;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class ChoiceEditedEmail extends PollenMail {
+
+ protected Poll poll;
+
+ protected Choice choice;
+
+ protected ChoiceEditedEmail(Locale locale) {
+ super(locale);
+ }
+
+ @Override
+ public String getSubject() {
+ return I18n.l(locale, "pollen.service.mail.ChoiceEditedEmail.subject");
+ }
+
+ public Poll getPoll() {
+ return poll;
+ }
+
+ public void setPoll(Poll poll) {
+ this.poll = poll;
+ }
+
+ public Choice getChoice() {
+ return choice;
+ }
+
+ public void setChoice(Choice choice) {
+ this.choice = choice;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/ChoiceEditedEmail.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/CommentAddedEmail.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/CommentAddedEmail.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/CommentAddedEmail.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,45 @@
+package org.chorem.pollen.services.service.mail;
+
+import org.chorem.pollen.persistence.entity.Comment;
+import org.chorem.pollen.persistence.entity.Poll;
+import org.nuiton.i18n.I18n;
+
+import java.util.Locale;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class CommentAddedEmail extends PollenMail {
+
+ protected Poll poll;
+
+ protected Comment comment;
+
+ protected CommentAddedEmail(Locale locale) {
+ super(locale);
+ }
+
+ @Override
+ public String getSubject() {
+ return I18n.l(locale, "pollen.service.mail.CommentAddedEmail.subject");
+ }
+
+ public Poll getPoll() {
+ return poll;
+ }
+
+ public void setPoll(Poll poll) {
+ this.poll = poll;
+ }
+
+ public Comment getComment() {
+ return comment;
+ }
+
+ public void setComment(Comment comment) {
+ this.comment = comment;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/CommentAddedEmail.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/CommentDeletedEmail.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/CommentDeletedEmail.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/CommentDeletedEmail.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,45 @@
+package org.chorem.pollen.services.service.mail;
+
+import org.chorem.pollen.persistence.entity.Comment;
+import org.chorem.pollen.persistence.entity.Poll;
+import org.nuiton.i18n.I18n;
+
+import java.util.Locale;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class CommentDeletedEmail extends PollenMail {
+
+ protected Poll poll;
+
+ protected Comment comment;
+
+ protected CommentDeletedEmail(Locale locale) {
+ super(locale);
+ }
+
+ @Override
+ public String getSubject() {
+ return I18n.l(locale, "pollen.service.mail.CommentDeletedEmail.subject");
+ }
+
+ public Poll getPoll() {
+ return poll;
+ }
+
+ public void setPoll(Poll poll) {
+ this.poll = poll;
+ }
+
+ public Comment getComment() {
+ return comment;
+ }
+
+ public void setComment(Comment comment) {
+ this.comment = comment;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/CommentDeletedEmail.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/CommentEditedEmail.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/CommentEditedEmail.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/CommentEditedEmail.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,45 @@
+package org.chorem.pollen.services.service.mail;
+
+import org.chorem.pollen.persistence.entity.Comment;
+import org.chorem.pollen.persistence.entity.Poll;
+import org.nuiton.i18n.I18n;
+
+import java.util.Locale;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class CommentEditedEmail extends PollenMail {
+
+ protected Poll poll;
+
+ protected Comment comment;
+
+ protected CommentEditedEmail(Locale locale) {
+ super(locale);
+ }
+
+ @Override
+ public String getSubject() {
+ return I18n.l(locale, "pollen.service.mail.CommentEditedEmail.subject");
+ }
+
+ public Poll getPoll() {
+ return poll;
+ }
+
+ public void setPoll(Poll poll) {
+ this.poll = poll;
+ }
+
+ public Comment getComment() {
+ return comment;
+ }
+
+ public void setComment(Comment comment) {
+ this.comment = comment;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/CommentEditedEmail.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/EmailService.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/EmailService.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/EmailService.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,267 @@
+package org.chorem.pollen.services.service.mail;
+
+import com.github.mustachejava.DefaultMustacheFactory;
+import com.github.mustachejava.Mustache;
+import com.github.mustachejava.MustacheException;
+import com.github.mustachejava.MustacheFactory;
+import com.google.common.base.Charsets;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.mail.Email;
+import org.apache.commons.mail.EmailException;
+import org.apache.commons.mail.SimpleEmail;
+import org.chorem.pollen.persistence.entity.Choice;
+import org.chorem.pollen.persistence.entity.Comment;
+import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.persistence.entity.PollenPrincipal;
+import org.chorem.pollen.persistence.entity.PollenUser;
+import org.chorem.pollen.persistence.entity.Vote;
+import org.chorem.pollen.services.PollenTechnicalException;
+import org.chorem.pollen.services.config.PollenServiceConfig;
+import org.chorem.pollen.services.service.PollenServiceSupport;
+
+import java.io.StringWriter;
+import java.util.Locale;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class EmailService extends PollenServiceSupport {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(EmailService.class);
+
+ public ChoiceAddedEmail newChoiceAddedEmail(Locale locale, Poll poll, Choice choice) {
+ ChoiceAddedEmail email = new ChoiceAddedEmail(locale);
+ email.setPoll(poll);
+ email.setChoice(choice);
+ return email;
+ }
+
+ public ChoiceEditedEmail newChoiceEditedEmail(Locale locale, Poll poll, Choice choice) {
+ ChoiceEditedEmail email = new ChoiceEditedEmail(locale);
+ email.setPoll(poll);
+ email.setChoice(choice);
+ return email;
+ }
+
+ public ChoiceDeletedEmail newChoiceDeletedEmail(Locale locale, Poll poll, Choice choice) {
+ ChoiceDeletedEmail email = new ChoiceDeletedEmail(locale);
+ email.setPoll(poll);
+ email.setChoice(choice);
+ return email;
+ }
+
+ public CommentAddedEmail newCommentAddedEmail(Locale locale, Poll poll, Comment comment) {
+ CommentAddedEmail email = new CommentAddedEmail(locale);
+ email.setPoll(poll);
+ email.setComment(comment);
+ return email;
+ }
+
+ public CommentEditedEmail newCommnetEditedEmail(Locale locale, Poll poll, Comment comment) {
+ CommentEditedEmail email = new CommentEditedEmail(locale);
+ email.setPoll(poll);
+ email.setComment(comment);
+ return email;
+ }
+
+ public CommentDeletedEmail newCommentDeletedEmail(Locale locale, Poll poll, Comment comment) {
+ CommentDeletedEmail email = new CommentDeletedEmail(locale);
+ email.setPoll(poll);
+ email.setComment(comment);
+ return email;
+ }
+
+ public VoteAddedEmail newVoteAddedEmail(Locale locale, Poll poll, Vote vote) {
+ VoteAddedEmail email = new VoteAddedEmail(locale);
+ email.setPoll(poll);
+ email.setVote(vote);
+ return email;
+ }
+
+ public VoteEditedEmail newVoteEditedEmail(Locale locale, Poll poll, Vote vote) {
+ VoteEditedEmail email = new VoteEditedEmail(locale);
+ email.setPoll(poll);
+ email.setVote(vote);
+ return email;
+ }
+
+ public VoteDeletedEmail newVoteDeletedEmail(Locale locale, Poll poll, Vote vote) {
+ VoteDeletedEmail email = new VoteDeletedEmail(locale);
+ email.setPoll(poll);
+ email.setVote(vote);
+ return email;
+ }
+
+ public PollCreatedEmail newPollCreatedEmail(Locale locale, Poll poll) {
+ PollCreatedEmail email = new PollCreatedEmail(locale);
+ email.setPoll(poll);
+ return email;
+ }
+
+ public PollClosedEmail newPollClosedEmail(Locale locale, Poll poll) {
+ PollClosedEmail email = new PollClosedEmail(locale);
+ email.setPoll(poll);
+ return email;
+ }
+
+ public PollChoicePeriodStartedEmail newPollChoicePeriodStartedEmail(Locale locale, Poll poll) {
+ PollChoicePeriodStartedEmail email = new PollChoicePeriodStartedEmail(locale);
+ email.setPoll(poll);
+ return email;
+ }
+
+ public PollChoicePeriodEndedEmail newPollChoicePeriodEndedEmail(Locale locale, Poll poll) {
+ PollChoicePeriodEndedEmail email = new PollChoicePeriodEndedEmail(locale);
+ email.setPoll(poll);
+ return email;
+ }
+
+ public PollVotePeriodStartedEmail newPollVotePeriodStartedEmail(Locale locale, Poll poll) {
+ PollVotePeriodStartedEmail email = new PollVotePeriodStartedEmail(locale);
+ email.setPoll(poll);
+ return email;
+ }
+
+ public PollVotePeriodEndedEmail newPollVotePeriodEndedEmail(Locale locale, Poll poll) {
+ PollVotePeriodEndedEmail email = new PollVotePeriodEndedEmail(locale);
+ email.setPoll(poll);
+ return email;
+ }
+
+ public PollVoteReminderEmail newPollVoteReminderEmail(Locale locale, Poll poll) {
+ PollVoteReminderEmail email = new PollVoteReminderEmail(locale);
+ email.setPoll(poll);
+ return email;
+ }
+
+ public RestrictedPollInvitationEmail newRestrictedPollInvitationEmail(Locale locale, Poll poll, PollenPrincipal principal) {
+ RestrictedPollInvitationEmail email = new RestrictedPollInvitationEmail(locale);
+ email.setPoll(poll);
+ email.setPrincipal(principal);
+ return email;
+ }
+
+ public UserAccountCreatedEmail newUserAccountCreatedEmail(Locale locale, PollenUser user) {
+ UserAccountCreatedEmail email = new UserAccountCreatedEmail(locale);
+ email.setUser(user);
+ return email;
+ }
+
+ public LostPasswordEmail newLostPasswordEmail(Locale locale, PollenUser user, String password) {
+ LostPasswordEmail email = new LostPasswordEmail(locale);
+ email.setUser(user);
+ email.setPassword(password);
+ return email;
+ }
+
+ public void send(PollenMail mail) {
+
+ if (getPollenServiceConfig().isDevMode()) {
+
+ if (log.isInfoEnabled()) {
+ log.info("an email should have been sent if not in devMode: tos = " +
+ mail.getTos() + ". subject = '" + mail.getSubject() + "'. body = \n" + getBody(mail));
+ }
+
+ if (log.isWarnEnabled()) {
+ if (!mail.isRecipientProvided()) {
+ log.warn("email has no recipient, would not have been sent " + mail);
+ }
+ }
+
+ } else {
+
+ doSend(mail);
+
+ }
+
+ }
+
+ protected void doSend(PollenMail mail) {
+
+ PollenServiceConfig applicationConfig = getPollenServiceConfig();
+
+ String body = getBody(mail);
+
+ if (mail.isRecipientProvided()) {
+
+ Email newEmail = new SimpleEmail();
+
+ newEmail.setHostName(applicationConfig.getSmtpHost());
+
+ newEmail.setSmtpPort(applicationConfig.getSmtpPort());
+
+ newEmail.setCharset(Charsets.UTF_8.name());
+
+ newEmail.setSubject(mail.getSubject());
+
+ try {
+
+ newEmail.setFrom(applicationConfig.getSmtpFrom());
+
+ for (String to : mail.getTos()) {
+ newEmail.addTo(to);
+ }
+
+ for (String bcc : mail.getBccs()) {
+ newEmail.addBcc(bcc);
+ }
+
+ newEmail.setMsg(body);
+
+ newEmail.send();
+
+ } catch (EmailException e) {
+ throw new PollenTechnicalException(e);
+ }
+
+ } else {
+
+ if (log.isErrorEnabled()) {
+ log.error("email has no recipient, won't be sent " + mail);
+ }
+
+ }
+
+ }
+
+ protected String getBody(PollenMail mail) {
+
+ Mustache mustache = getMustache(mail);
+
+ StringWriter stringWriter = new StringWriter();
+
+ mustache.execute(stringWriter, mail);
+
+ return stringWriter.toString();
+
+ }
+
+ protected Mustache getMustache(PollenMail mail) {
+
+ MustacheFactory mustacheFactory = new DefaultMustacheFactory("mail/");
+
+ Locale locale = mail.getLocale();
+ String templateName = mail.getClass().getSimpleName() + "_" + locale.getLanguage() + ".mustache";
+
+ Mustache mustache;
+ try {
+ mustache = mustacheFactory.compile(templateName);
+ } catch (MustacheException e) {
+
+ // fallback with no locale
+ templateName = mail.getClass().getSimpleName() + ".mustache";
+
+ mustache = mustacheFactory.compile(templateName);
+ }
+
+ return mustache;
+
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/EmailService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/LostPasswordEmail.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/LostPasswordEmail.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/LostPasswordEmail.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,44 @@
+package org.chorem.pollen.services.service.mail;
+
+import org.chorem.pollen.persistence.entity.PollenUser;
+import org.nuiton.i18n.I18n;
+
+import java.util.Locale;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class LostPasswordEmail extends PollenMail {
+
+ private PollenUser user;
+
+ private String password;
+
+ protected LostPasswordEmail(Locale locale) {
+ super(locale);
+ }
+
+ public PollenUser getUser() {
+ return user;
+ }
+
+ public void setUser(PollenUser user) {
+ this.user = user;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ @Override
+ public String getSubject() {
+ return I18n.l(locale, "pollen.service.mail.LostPasswordEmail.subject");
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/LostPasswordEmail.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollChoicePeriodEndedEmail.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollChoicePeriodEndedEmail.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollChoicePeriodEndedEmail.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,34 @@
+package org.chorem.pollen.services.service.mail;
+
+import org.chorem.pollen.persistence.entity.Poll;
+import org.nuiton.i18n.I18n;
+
+import java.util.Locale;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollChoicePeriodEndedEmail extends PollenMail {
+
+ protected Poll poll;
+
+ protected PollChoicePeriodEndedEmail(Locale locale) {
+ super(locale);
+ }
+
+ @Override
+ public String getSubject() {
+ return I18n.l(locale, "pollen.service.mail.PollChoicePeriodEndedEmail.subject");
+ }
+
+ public Poll getPoll() {
+ return poll;
+ }
+
+ public void setPoll(Poll poll) {
+ this.poll = poll;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollChoicePeriodEndedEmail.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollChoicePeriodStartedEmail.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollChoicePeriodStartedEmail.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollChoicePeriodStartedEmail.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,34 @@
+package org.chorem.pollen.services.service.mail;
+
+import org.chorem.pollen.persistence.entity.Poll;
+import org.nuiton.i18n.I18n;
+
+import java.util.Locale;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollChoicePeriodStartedEmail extends PollenMail {
+
+ protected Poll poll;
+
+ protected PollChoicePeriodStartedEmail(Locale locale) {
+ super(locale);
+ }
+
+ @Override
+ public String getSubject() {
+ return I18n.l(locale, "pollen.service.mail.PollChoicePeriodStartedEmail.subject");
+ }
+
+ public Poll getPoll() {
+ return poll;
+ }
+
+ public void setPoll(Poll poll) {
+ this.poll = poll;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollChoicePeriodStartedEmail.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollClosedEmail.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollClosedEmail.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollClosedEmail.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,34 @@
+package org.chorem.pollen.services.service.mail;
+
+import org.chorem.pollen.persistence.entity.Poll;
+import org.nuiton.i18n.I18n;
+
+import java.util.Locale;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollClosedEmail extends PollenMail {
+
+ protected Poll poll;
+
+ protected PollClosedEmail(Locale locale) {
+ super(locale);
+ }
+
+ @Override
+ public String getSubject() {
+ return I18n.l(locale, "pollen.service.mail.PollClosedEmail.subject");
+ }
+
+ public Poll getPoll() {
+ return poll;
+ }
+
+ public void setPoll(Poll poll) {
+ this.poll = poll;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollClosedEmail.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollCreatedEmail.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollCreatedEmail.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollCreatedEmail.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,34 @@
+package org.chorem.pollen.services.service.mail;
+
+import org.chorem.pollen.persistence.entity.Poll;
+import org.nuiton.i18n.I18n;
+
+import java.util.Locale;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollCreatedEmail extends PollenMail {
+
+ protected Poll poll;
+
+ protected PollCreatedEmail(Locale locale) {
+ super(locale);
+ }
+
+ @Override
+ public String getSubject() {
+ return I18n.l(locale, "pollen.service.mail.PollCreatedEmail.subject");
+ }
+
+ public Poll getPoll() {
+ return poll;
+ }
+
+ public void setPoll(Poll poll) {
+ this.poll = poll;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollCreatedEmail.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollVotePeriodEndedEmail.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollVotePeriodEndedEmail.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollVotePeriodEndedEmail.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,34 @@
+package org.chorem.pollen.services.service.mail;
+
+import org.chorem.pollen.persistence.entity.Poll;
+import org.nuiton.i18n.I18n;
+
+import java.util.Locale;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollVotePeriodEndedEmail extends PollenMail {
+
+ protected Poll poll;
+
+ protected PollVotePeriodEndedEmail(Locale locale) {
+ super(locale);
+ }
+
+ @Override
+ public String getSubject() {
+ return I18n.l(locale, "pollen.service.mail.PollVotePeriodEndedEmail.subject");
+ }
+
+ public Poll getPoll() {
+ return poll;
+ }
+
+ public void setPoll(Poll poll) {
+ this.poll = poll;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollVotePeriodEndedEmail.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollVotePeriodStartedEmail.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollVotePeriodStartedEmail.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollVotePeriodStartedEmail.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,34 @@
+package org.chorem.pollen.services.service.mail;
+
+import org.chorem.pollen.persistence.entity.Poll;
+import org.nuiton.i18n.I18n;
+
+import java.util.Locale;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollVotePeriodStartedEmail extends PollenMail {
+
+ protected Poll poll;
+
+ protected PollVotePeriodStartedEmail(Locale locale) {
+ super(locale);
+ }
+
+ @Override
+ public String getSubject() {
+ return I18n.l(locale, "pollen.service.mail.PollVotePeriodStartedEmail.subject");
+ }
+
+ public Poll getPoll() {
+ return poll;
+ }
+
+ public void setPoll(Poll poll) {
+ this.poll = poll;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollVotePeriodStartedEmail.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollVoteReminderEmail.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollVoteReminderEmail.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollVoteReminderEmail.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,34 @@
+package org.chorem.pollen.services.service.mail;
+
+import org.chorem.pollen.persistence.entity.Poll;
+import org.nuiton.i18n.I18n;
+
+import java.util.Locale;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollVoteReminderEmail extends PollenMail {
+
+ protected Poll poll;
+
+ protected PollVoteReminderEmail(Locale locale) {
+ super(locale);
+ }
+
+ @Override
+ public String getSubject() {
+ return I18n.l(locale, "pollen.service.mail.PollVoteReminderEmail.subject");
+ }
+
+ public Poll getPoll() {
+ return poll;
+ }
+
+ public void setPoll(Poll poll) {
+ this.poll = poll;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollVoteReminderEmail.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollenMail.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollenMail.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollenMail.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,67 @@
+package org.chorem.pollen.services.service.mail;
+
+import com.google.common.collect.Sets;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
+
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public abstract class PollenMail {
+
+ protected Locale locale;
+
+ protected Set<String> tos;
+
+ protected Set<String> bccs;
+
+ public PollenMail(Locale locale) {
+ this.locale = locale;
+ }
+
+ public Locale getLocale() {
+ return locale;
+ }
+
+ public Set<String> getTos() {
+ if (tos == null) {
+ tos = Sets.newHashSet();
+ }
+ return tos;
+ }
+
+ public void addTo(String email) {
+ getTos().add(email);
+ }
+
+ public abstract String getSubject();
+
+ public Set<String> getBccs() {
+ if (bccs == null) {
+ bccs = Sets.newHashSet();
+ }
+ return bccs;
+ }
+
+ public void addBcc(String email) {
+ getBccs().add(email);
+ }
+
+ @Override
+ public String toString() {
+ return ReflectionToStringBuilder.toString(this);
+ }
+
+ public boolean isRecipientProvided() {
+ boolean isRecipientProvided = CollectionUtils.isNotEmpty(getBccs())
+ || CollectionUtils.isNotEmpty(getTos());
+ return isRecipientProvided;
+ }
+
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/PollenMail.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/RestrictedPollInvitationEmail.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/RestrictedPollInvitationEmail.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/RestrictedPollInvitationEmail.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,45 @@
+package org.chorem.pollen.services.service.mail;
+
+import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.persistence.entity.PollenPrincipal;
+import org.nuiton.i18n.I18n;
+
+import java.util.Locale;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class RestrictedPollInvitationEmail extends PollenMail {
+
+ protected Poll poll;
+
+ protected PollenPrincipal principal;
+
+ protected RestrictedPollInvitationEmail(Locale locale) {
+ super(locale);
+ }
+
+ @Override
+ public String getSubject() {
+ return I18n.l(locale, "pollen.service.mail.RestrictedPollInvitationEmail.subject");
+ }
+
+ public Poll getPoll() {
+ return poll;
+ }
+
+ public void setPoll(Poll poll) {
+ this.poll = poll;
+ }
+
+ public PollenPrincipal getPrincipal() {
+ return principal;
+ }
+
+ public void setPrincipal(PollenPrincipal principal) {
+ this.principal = principal;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/RestrictedPollInvitationEmail.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/UserAccountCreatedEmail.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/UserAccountCreatedEmail.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/UserAccountCreatedEmail.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,34 @@
+package org.chorem.pollen.services.service.mail;
+
+import org.chorem.pollen.persistence.entity.PollenUser;
+import org.nuiton.i18n.I18n;
+
+import java.util.Locale;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class UserAccountCreatedEmail extends PollenMail {
+
+ private PollenUser user;
+
+ protected UserAccountCreatedEmail(Locale locale) {
+ super(locale);
+ }
+
+ @Override
+ public String getSubject() {
+ return I18n.l(locale, "pollen.service.mail.UserAccountCreatedEmail.subject");
+ }
+
+ public PollenUser getUser() {
+ return user;
+ }
+
+ public void setUser(PollenUser user) {
+ this.user = user;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/UserAccountCreatedEmail.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/VoteAddedEmail.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/VoteAddedEmail.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/VoteAddedEmail.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,45 @@
+package org.chorem.pollen.services.service.mail;
+
+import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.persistence.entity.Vote;
+import org.nuiton.i18n.I18n;
+
+import java.util.Locale;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class VoteAddedEmail extends PollenMail {
+
+ protected Poll poll;
+
+ protected Vote vote;
+
+ protected VoteAddedEmail(Locale locale) {
+ super(locale);
+ }
+
+ @Override
+ public String getSubject() {
+ return I18n.l(locale, "pollen.service.mail.VoteAddedEmail.subject");
+ }
+
+ public Vote getVote() {
+ return vote;
+ }
+
+ public void setVote(Vote vote) {
+ this.vote = vote;
+ }
+
+ public Poll getPoll() {
+ return poll;
+ }
+
+ public void setPoll(Poll poll) {
+ this.poll = poll;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/VoteAddedEmail.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/VoteDeletedEmail.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/VoteDeletedEmail.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/VoteDeletedEmail.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,45 @@
+package org.chorem.pollen.services.service.mail;
+
+import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.persistence.entity.Vote;
+import org.nuiton.i18n.I18n;
+
+import java.util.Locale;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class VoteDeletedEmail extends PollenMail {
+
+ protected Poll poll;
+
+ protected Vote vote;
+
+ protected VoteDeletedEmail(Locale locale) {
+ super(locale);
+ }
+
+ @Override
+ public String getSubject() {
+ return I18n.l(locale, "pollen.service.mail.VoteDeletedEmail.subject");
+ }
+
+ public Vote getVote() {
+ return vote;
+ }
+
+ public void setVote(Vote vote) {
+ this.vote = vote;
+ }
+
+ public Poll getPoll() {
+ return poll;
+ }
+
+ public void setPoll(Poll poll) {
+ this.poll = poll;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/VoteDeletedEmail.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/VoteEditedEmail.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/VoteEditedEmail.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/VoteEditedEmail.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,45 @@
+package org.chorem.pollen.services.service.mail;
+
+import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.persistence.entity.Vote;
+import org.nuiton.i18n.I18n;
+
+import java.util.Locale;
+
+/**
+ * Created on 4/30/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class VoteEditedEmail extends PollenMail {
+
+ protected Poll poll;
+
+ protected Vote vote;
+
+ protected VoteEditedEmail(Locale locale) {
+ super(locale);
+ }
+
+ @Override
+ public String getSubject() {
+ return I18n.l(locale, "pollen.service.mail.VoteEditedEmail.subject");
+ }
+
+ public Vote getVote() {
+ return vote;
+ }
+
+ public void setVote(Vote vote) {
+ this.vote = vote;
+ }
+
+ public Poll getPoll() {
+ return poll;
+ }
+
+ public void setPoll(Poll poll) {
+ this.poll = poll;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/mail/VoteEditedEmail.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Copied: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/DefaultPollenSecurityContext.java (from rev 3890, trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityContext.java)
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/DefaultPollenSecurityContext.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/DefaultPollenSecurityContext.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,147 @@
+package org.chorem.pollen.services.service.security;
+
+/*
+ * #%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.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.shiro.subject.SimplePrincipalCollection;
+import org.apache.shiro.subject.Subject;
+import org.chorem.pollen.persistence.entity.PollenUser;
+import org.chorem.pollen.persistence.entity.SessionToken;
+
+import java.io.Serializable;
+import java.util.Set;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class DefaultPollenSecurityContext implements Serializable, PollenSecurityContext {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(DefaultPollenSecurityContext.class);
+
+ protected Subject subject;
+
+ /**
+ * Connected user account.
+ * <p/>
+ * Can be {@code null} if user is not connected.
+ *
+ * @since 2.0
+ */
+ protected final SessionToken sessionToken;
+
+ public static PollenSecurityContext newContext(SessionToken sessionToken) {
+ PollenSecurityContext result = new DefaultPollenSecurityContext(
+ sessionToken);
+ return result;
+ }
+
+ @Override
+ public Subject getSubject() {
+ return subject;
+ }
+
+ @Override
+ public SessionToken getSessionToken() {
+ return sessionToken;
+ }
+
+ @Override
+ public PollenUser getPollenUser() {
+ return isConnected() ? sessionToken.getPollenUser() : null;
+ }
+
+ @Override
+ public boolean isConnected() {
+ return sessionToken != null;
+ }
+
+ @Override
+ public boolean isAdmin() {
+ return getPollenUser() != null && getPollenUser().isAdministrator();
+ }
+
+ @Override
+ public void setSubject(Subject subject) {
+ this.subject = subject;
+ }
+
+ @Override
+ public void checkPermission(String permission) {
+ if (log.isInfoEnabled()) {
+ log.info("Check permission: " + permission);
+ }
+
+ boolean valid = getSubject().isPermitted(permission);
+
+ if (!valid) {
+ throw new PollenInvalidPermissionException(permission);
+ }
+
+ }
+
+ @Override
+ public void checkRole(SecurityRole role) {
+
+ boolean valid = false;
+ switch (role) {
+
+ case anonymous:
+ valid = true;
+ break;
+ case connected:
+ valid = isConnected();
+ break;
+ case administrator:
+ valid = isAdmin();
+ break;
+ }
+
+// //FIXME Find out how to push roles to subject...
+// boolean valid = getSubject().hasRole(role.name());
+
+ if (!valid) {
+ throw new PollenUnauthorizedException(role);
+ }
+ }
+
+ @Override
+ public Subject newSubject(Set<SecurityRole> roles, Set<String> permissions) {
+ //TODO Add roles to subject
+ SimplePrincipalCollection principalCollection = new SimplePrincipalCollection();
+ principalCollection.addAll(permissions, "pollenRealm");
+ Subject result = new Subject.Builder().principals(principalCollection).buildSubject();
+ return result;
+ }
+
+ protected DefaultPollenSecurityContext(SessionToken sessionToken) {
+ this.sessionToken = sessionToken;
+ }
+}
Copied: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PermissionVerb.java (from rev 3890, trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/PermissionVerb.java)
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PermissionVerb.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PermissionVerb.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,57 @@
+package org.chorem.pollen.services.service.security;
+
+/*
+ * #%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 enum PermissionVerb {
+ readPoll,
+ readChoice,
+ readComment,
+ readVote,
+
+ addPoll,
+ addChoice,
+ addComment,
+ addVote,
+
+ editPoll,
+ editChoice,
+ editComment,
+ editVote,
+
+ deletePoll,
+ deleteChoice,
+ deleteComment,
+ deleteVote,
+
+ closePoll,
+ clonePoll,
+ exportPoll,
+
+}
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenInvalidPermissionException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenInvalidPermissionException.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenInvalidPermissionException.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,24 @@
+package org.chorem.pollen.services.service.security;
+
+import org.chorem.pollen.services.PollenTechnicalException;
+
+/**
+ * Created on 5/1/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollenInvalidPermissionException extends PollenTechnicalException {
+
+ private static final long serialVersionUID = 1L;
+
+ private final String permission;
+
+ public PollenInvalidPermissionException(String permission) {
+ this.permission = permission;
+ }
+
+ public String getPermission() {
+ return permission;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenInvalidPermissionException.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenSecurityContext.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenSecurityContext.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenSecurityContext.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,34 @@
+package org.chorem.pollen.services.service.security;
+
+import org.apache.shiro.subject.Subject;
+import org.chorem.pollen.persistence.entity.PollenUser;
+import org.chorem.pollen.persistence.entity.SessionToken;
+
+import java.util.Set;
+
+/**
+ * Created on 5/1/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public interface PollenSecurityContext {
+
+ Subject getSubject();
+
+ SessionToken getSessionToken();
+
+ PollenUser getPollenUser();
+
+ boolean isConnected();
+
+ boolean isAdmin();
+
+ void setSubject(Subject subject);
+
+ void checkPermission(String permission);
+
+ void checkRole(SecurityRole role);
+
+ Subject newSubject(Set<SecurityRole> roles, Set<String> permissions);
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenSecurityContext.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Copied: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenSecurityRealm.java (from rev 3890, trunk/pollen-services/src/main/java/org/chorem/pollen/services/PollenSecurityRealm.java)
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenSecurityRealm.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenSecurityRealm.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,84 @@
+package org.chorem.pollen.services.service.security;
+
+/*
+ * #%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.PollenService;
+import org.chorem.pollen.services.PollenServiceContext;
+import org.chorem.pollen.services.exception.EntityNotFoundException;
+import org.chorem.pollen.services.exception.UserInvalidPasswordException;
+import org.chorem.pollen.services.service.AuthService;
+
+/**
+ * TODO
+ * <p/>
+ * http://www.slideshare.net/chunsaker/securing-rest-apis ?
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollenSecurityRealm extends AuthorizingRealm implements PollenService {
+
+ 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.newService(AuthService.class);
+ 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;
+ }
+}
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenUnauthorizedException.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenUnauthorizedException.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenUnauthorizedException.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,24 @@
+package org.chorem.pollen.services.service.security;
+
+import org.chorem.pollen.services.PollenTechnicalException;
+
+/**
+ * Created on 5/1/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class PollenUnauthorizedException extends PollenTechnicalException {
+
+ private static final long serialVersionUID = 1L;
+
+ protected final SecurityRole role;
+
+ public PollenUnauthorizedException(SecurityRole role) {
+ this.role = role;
+ }
+
+ public SecurityRole getRole() {
+ return role;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenUnauthorizedException.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityRole.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityRole.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityRole.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,13 @@
+package org.chorem.pollen.services.service.security;
+
+/**
+ * Created on 5/1/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public enum SecurityRole {
+ anonymous,
+ connected,
+ administrator
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityRole.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Copied: trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java (from rev 3890, trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/SecurityService.java)
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,265 @@
+package org.chorem.pollen.services.service.security;
+
+/*
+ * #%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 com.google.common.collect.Sets;
+import org.apache.shiro.subject.Subject;
+import org.chorem.pollen.persistence.entity.Choice;
+import org.chorem.pollen.persistence.entity.Comment;
+import org.chorem.pollen.persistence.entity.Poll;
+import org.chorem.pollen.persistence.entity.PollenPrincipal;
+import org.chorem.pollen.persistence.entity.PollenPrincipalTopiaDao;
+import org.chorem.pollen.persistence.entity.PollenUser;
+import org.chorem.pollen.persistence.entity.Polls;
+import org.chorem.pollen.persistence.entity.Vote;
+import org.chorem.pollen.persistence.entity.VoterListMember;
+import org.chorem.pollen.services.service.PollenServiceSupport;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+import java.util.Date;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class SecurityService extends PollenServiceSupport {
+
+ public PollenPrincipal generatePrincipal() {
+ PollenPrincipalTopiaDao pollenPrincipalDao = getPersistenceContext().getPollenPrincipalDao();
+ PollenPrincipal principal = pollenPrincipalDao.newInstance();
+ principal.setCreationDate(serviceContext.getNow());
+ pollenPrincipalDao.create(principal);
+ return principal;
+ }
+
+ public void prepareSubject(TopiaEntity entity) {
+ Preconditions.checkNotNull(entity);
+ prepareSubject(entity.getTopiaId());
+ }
+
+ public void prepareSubject(String principalId) {
+ PollenSecurityContext securityContext = serviceContext.getSecurityContext();
+ Preconditions.checkNotNull(securityContext);
+ PollenUser pollenUser = securityContext.getPollenUser();
+ Subject subject = getSubject(principalId, pollenUser);
+ securityContext.setSubject(subject);
+ }
+
+ protected Subject getSubject(String principalId, PollenUser user) {
+ Set<String> permissions = Sets.newHashSet();
+
+ boolean userConnected = user != null;
+ boolean userIsAdmin = userConnected && user.isAdministrator();
+
+ Set<SecurityRole> roles = EnumSet.noneOf(SecurityRole.class);
+ if (userConnected) {
+ roles.add(SecurityRole.connected);
+ if (userIsAdmin) {
+ roles.add(SecurityRole.administrator);
+ }
+ } else {
+ roles.add(SecurityRole.anonymous);
+ }
+
+ if (userIsAdmin) {
+ permissions.add("*:*:*");
+ } else {
+
+ Set<PollenPrincipal> principals = Sets.newHashSet();
+
+ PollenPrincipalTopiaDao pollenPrincipalDao =
+ getPersistenceContext().getPollenPrincipalDao();
+
+ if (principalId != null) {
+ PollenPrincipal pollenPrincipal =
+ pollenPrincipalDao.findByTopiaId(principalId);
+ principals.add(pollenPrincipal);
+ }
+
+ if (userConnected) {
+
+ // find all principals
+ List<PollenPrincipal> allByPollenUser =
+ pollenPrincipalDao.forPollenUserEquals(user).findAll();
+ principals.addAll(allByPollenUser);
+ }
+
+ Map<PollenPrincipal, TopiaEntity> principalTopiaEntityMap = Maps.newHashMap();
+
+ for (PollenPrincipal principal : principals) {
+
+ // find out which entity is using this principal
+ TopiaEntity entity = getPrincipalEntity(principal);
+ principalTopiaEntityMap.put(principal, entity);
+
+ if (entity instanceof Poll) {
+
+ // add all poll entities
+ Poll poll = (Poll) entity;
+
+ if (!poll.isChoiceEmpty()) {
+ for (Choice choice : poll.getChoice()) {
+ principalTopiaEntityMap.put(choice.getCreator(), choice);
+ }
+ }
+
+ if (!poll.isCommentEmpty()) {
+ for (Comment comment : poll.getComment()) {
+ principalTopiaEntityMap.put(comment.getAuthor(), comment);
+ }
+ }
+
+ if (!poll.isVoteEmpty()) {
+ for (Vote vote : poll.getVote()) {
+ principalTopiaEntityMap.put(vote.getVoter(), vote);
+ }
+ }
+ }
+ }
+
+ Date now = serviceContext.getNow();
+ for (Map.Entry<PollenPrincipal, TopiaEntity> entry : principalTopiaEntityMap.entrySet()) {
+ TopiaEntity entity = entry.getValue();
+
+ if (entity instanceof Choice) {
+ permissions.add(createWildcardSubjectPermission(entity));
+ continue;
+ }
+ if (entity instanceof Comment) {
+ permissions.add(createWildcardSubjectPermission(entity));
+ continue;
+ }
+ if (entity instanceof Vote) {
+ permissions.add(createWildcardSubjectPermission(entity));
+ continue;
+ }
+ if (entity instanceof Poll) {
+ //TODO Get alls possible permissions on poll
+
+ Poll poll = (Poll) entity;
+
+ Set<VoterListMember> members = Polls.getAllVoters(poll);
+
+ boolean freePoll = Polls.isPollFree(poll);
+
+ if (freePoll) {
+
+ // everybody can read poll ?
+ permissions.add(createSubjectPermission(PermissionVerb.readPoll, entity));
+ } else {
+
+ // only his creator / participants / voters can read it
+
+ for (VoterListMember member : members) {
+ permissions.add(createSubjectPermission(member.getTopiaId(), PermissionVerb.readPoll, entity));
+ }
+ }
+
+ // add editVote / deleteVote for any voter
+ if (!poll.isVoteEmpty()) {
+ for (Vote vote : poll.getVote()) {
+ String id = vote.getVoter().getTopiaId();
+ permissions.add(createSubjectPermission(id, PermissionVerb.editVote, vote));
+ permissions.add(createSubjectPermission(id, PermissionVerb.deleteVote, vote));
+ }
+ }
+
+ //TODO Not do this here, but later in business code
+// if (poll.isAddChoiceRunning(now)) {
+//
+// permissions.add(createSubjectPermission(PermissionVerb.addChoice, entity));
+// }
+//
+// if (poll.getCommentVisibility() != CommentVisibility.NOBODY) {
+// //FIXME Should see with voter ?
+// permissions.add(createSubjectPermission(PermissionVerb.addComment, entity));
+// }
+//
+// if (poll.isRunning(now)) {
+// permissions.add(createSubjectPermission(PermissionVerb.addVote, entity));
+// }
+
+ //TODO Do for editVote,...
+ }
+ }
+ }
+ Subject subject = serviceContext.getSecurityContext().newSubject(roles, permissions);
+ return subject;
+ }
+
+ protected TopiaEntity getPrincipalEntity(PollenPrincipal principal) {
+
+ TopiaEntity result = null;
+
+ // try a poll
+ Poll poll = getPollDao().forCreatorEquals(principal).findUniqueOrNull();
+ if (poll == null) {
+
+ // try a choice
+ Choice choice = getChoiceDao().forCreatorEquals(principal).findUniqueOrNull();
+ if (choice == null) {
+
+ // try a vote
+ Vote vote = getVoteDao().forVoterEquals(principal).findUniqueOrNull();
+ if (vote == null) {
+
+ // try a comment
+ Comment comment = getCommentDao().forAuthorEquals(principal).findUniqueOrNull();
+ if (comment != null) {
+ result = comment;
+ }
+ } else {
+ result = vote;
+ }
+ } else {
+ result = choice;
+ }
+ } else {
+ result = poll;
+ }
+
+ Preconditions.checkNotNull(result);
+ return result;
+ }
+
+ protected String createSubjectPermission(String people, PermissionVerb verb, TopiaEntity entity) {
+ return people + ":" + verb.name() + ":" + entity.getTopiaId();
+ }
+
+ protected String createSubjectPermission(PermissionVerb verb, TopiaEntity entity) {
+ return createSubjectPermission("*", verb, entity);
+ }
+
+ protected String createWildcardSubjectPermission(TopiaEntity entity) {
+ return "*:*:" + entity.getTopiaId();
+ }
+}
Added: trunk/pollen-services/src/main/java/org/chorem/pollen/services/test/FakePollenSecurityContext.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/test/FakePollenSecurityContext.java (rev 0)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/test/FakePollenSecurityContext.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -0,0 +1,64 @@
+package org.chorem.pollen.services.test;
+
+import org.apache.shiro.subject.Subject;
+import org.chorem.pollen.persistence.entity.PollenUser;
+import org.chorem.pollen.persistence.entity.SessionToken;
+import org.chorem.pollen.services.service.security.PollenSecurityContext;
+import org.chorem.pollen.services.service.security.SecurityRole;
+
+import java.util.Set;
+
+/**
+ * Created on 5/1/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class FakePollenSecurityContext implements PollenSecurityContext {
+
+ @Override
+ public Subject getSubject() {
+ return null;
+ }
+
+ @Override
+ public SessionToken getSessionToken() {
+ return null;
+ }
+
+ @Override
+ public PollenUser getPollenUser() {
+ return null;
+ }
+
+ @Override
+ public boolean isConnected() {
+ return false;
+ }
+
+ @Override
+ public boolean isAdmin() {
+ return false;
+ }
+
+ @Override
+ public void setSubject(Subject subject) {
+
+ }
+
+ @Override
+ public void checkPermission(String permission) {
+ // no check
+ }
+
+ @Override
+ public void checkRole(SecurityRole role) {
+ // no check
+ }
+
+ @Override
+ public Subject newSubject(Set<SecurityRole> roles, Set<String> permissions) {
+ // no security
+ return null;
+ }
+}
Property changes on: trunk/pollen-services/src/main/java/org/chorem/pollen/services/test/FakePollenSecurityContext.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/test/FakePollenServiceContext.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/test/FakePollenServiceContext.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/test/FakePollenServiceContext.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -30,6 +30,7 @@
import org.chorem.pollen.persistence.PollenTopiaPersistenceContext;
import org.chorem.pollen.services.DefaultPollenServiceContext;
import org.chorem.pollen.services.config.PollenServiceConfig;
+import org.chorem.pollen.services.service.security.PollenSecurityContext;
import java.util.Date;
import java.util.Locale;
@@ -46,11 +47,13 @@
Locale locale,
PollenServiceConfig serviceConfig,
PollenTopiaApplicationContext applicationcontext,
- PollenTopiaPersistenceContext persistenceContext) {
+ PollenTopiaPersistenceContext persistenceContext,
+ PollenSecurityContext securityContext) {
FakePollenServiceContext serviceContext = new FakePollenServiceContext();
serviceContext.setPersistenceContext(persistenceContext);
serviceContext.setPollenServiceConfig(serviceConfig);
serviceContext.setTopiaApplicationContext(applicationcontext);
+ serviceContext.setSecurityContext(securityContext);
serviceContext.setLocale(locale);
serviceContext.setDate(now);
return serviceContext;
Modified: trunk/pollen-services/src/main/java/org/chorem/pollen/services/test/PollenApplication.java
===================================================================
--- trunk/pollen-services/src/main/java/org/chorem/pollen/services/test/PollenApplication.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/java/org/chorem/pollen/services/test/PollenApplication.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -62,7 +62,6 @@
private final String configurationPath;
-
protected PollenFixtures fixtures;
protected String methodName;
Added: trunk/pollen-services/src/main/resources/email/LostPasswordEmail.mustache
===================================================================
Added: trunk/pollen-services/src/main/resources/email/LostPasswordEmail_fr.mustache
===================================================================
Added: trunk/pollen-services/src/main/resources/email/PollChoicePeriodEndedEmail.mustache
===================================================================
Added: trunk/pollen-services/src/main/resources/email/PollChoicePeriodEndedEmail_en.mustache
===================================================================
Added: trunk/pollen-services/src/main/resources/email/PollChoicePeriodStartedEmail.mustache
===================================================================
Added: trunk/pollen-services/src/main/resources/email/PollChoicePeriodStartedEmail_fr.mustache
===================================================================
Added: trunk/pollen-services/src/main/resources/email/PollVotePeriodEndedEmail.mustache
===================================================================
Added: trunk/pollen-services/src/main/resources/email/PollVotePeriodEndedEmail_fr.mustache
===================================================================
Added: trunk/pollen-services/src/main/resources/email/PollVotePeriodStartedEmail.mustache
===================================================================
Added: trunk/pollen-services/src/main/resources/email/PollVotePeriodStartedEmail_fr.mustache
===================================================================
Added: trunk/pollen-services/src/main/resources/email/PollVoteReminderEmail.mustache
===================================================================
Added: trunk/pollen-services/src/main/resources/email/PollVoteReminderEmail_fr.mustache
===================================================================
Added: trunk/pollen-services/src/main/resources/email/RestrictedPollInvitationEmail.mustache
===================================================================
Added: trunk/pollen-services/src/main/resources/email/RestrictedPollInvitationEmail_fr.mustache
===================================================================
Added: trunk/pollen-services/src/main/resources/email/UserAccountCreatedEmail.mustache
===================================================================
Added: trunk/pollen-services/src/main/resources/email/UserAccountCreatedEmail_fr.mustache
===================================================================
Added: trunk/pollen-services/src/main/resources/email/VoteAddedEmail.mustache
===================================================================
Added: trunk/pollen-services/src/main/resources/email/VoteAddedEmail_fr.mustache
===================================================================
Added: trunk/pollen-services/src/main/resources/email/VoteDeletedEmail.mustache
===================================================================
Added: trunk/pollen-services/src/main/resources/email/VoteDeletedEmail_fr.mustache
===================================================================
Added: trunk/pollen-services/src/main/resources/email/VoteEditedEmail.mustache
===================================================================
Added: trunk/pollen-services/src/main/resources/email/VoteEditedEmail_fr.mustache
===================================================================
Modified: trunk/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties
===================================================================
--- trunk/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/resources/i18n/pollen-services_en_GB.properties 2014-05-02 09:20:55 UTC (rev 3895)
@@ -1,11 +1,30 @@
-pollen.configuration.data.directory=
-pollen.configuration.defaultPollCommentVisibility=
-pollen.configuration.defaultPollType=
-pollen.configuration.defaultPollVoteVisibility=
-pollen.configuration.defaultVoteCountingType=
+pollen.configuration.data.directory=Directory where Pollen stores his data
+pollen.configuration.defaultPollCommentVisibility=Default Poll comment visibility used when creating a new poll
+pollen.configuration.defaultPollType=Default Poll type used when creating a new poll
+pollen.configuration.defaultPollVoteVisibility=Default Poll vote visibility used when creating a new poll
+pollen.configuration.defaultVoteCountingType=Default vote counting type used when creating a new poll
pollen.error.favoriteList.import.csv.already.used.email=
pollen.error.favoriteList.import.csv.already.used.name=
pollen.error.favoriteList.import.csv.invalid.email=
pollen.error.favoriteList.import.ldap.already.used.email=
pollen.error.favoriteList.import.ldap.already.used.name=
pollen.error.favoriteList.import.ldap.invalid.email=
+pollen.service.mail.ChoiceAddedEmail.subject=[Pollen] A choice was added in poll %s
+pollen.service.mail.ChoiceDeletedEmail.subject=[Pollen] A choice was deleted in poll %s
+pollen.service.mail.ChoiceEditedEmail.subject=[Pollen] A choice was edited in poll %s
+pollen.service.mail.CommentAddedEmail.subject=[Pollen] A comment was added in poll %s
+pollen.service.mail.CommentDeletedEmail.subject=[Pollen] A comment was deleted in poll %s
+pollen.service.mail.CommentEditedEmail.subject=[Pollen] A comment was edited in poll %s
+pollen.service.mail.LostPasswordEmail.subject=[Pollen] Lost password for %s
+pollen.service.mail.PollChoicePeriodEndedEmail.subject=[Pollen] Add Choice period ended for poll %s
+pollen.service.mail.PollChoicePeriodStartedEmail.subject=[Pollen] Add Choice period started for poll %s
+pollen.service.mail.PollClosedEmail.subject=[Pollen] Poll %s is closed
+pollen.service.mail.PollCreatedEmail.subject=[Pollen] Poll creation (%s)
+pollen.service.mail.PollVotePeriodEndedEmail.subject=[Pollen] Vote period ended for poll %s
+pollen.service.mail.PollVotePeriodStartedEmail.subject=[Pollen] Vote period started for poll %s
+pollen.service.mail.PollVoteReminderEmail.subject=[Pollen] Reminder to vote on poll %s
+pollen.service.mail.RestrictedPollInvitationEmail.subject=[Pollen] Invitation to vote on poll %s
+pollen.service.mail.UserAccountCreatedEmail.subject=[Pollen] Confirmation of account creation %s
+pollen.service.mail.VoteAddedEmail.subject=[Pollen] A vote was added in poll %s
+pollen.service.mail.VoteDeletedEmail.subject=[Pollen] A vote was edited in poll %s
+pollen.service.mail.VoteEditedEmail.subject=[Pollen] A vote was deleted in poll %s
Modified: trunk/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties
===================================================================
--- trunk/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/main/resources/i18n/pollen-services_fr_FR.properties 2014-05-02 09:20:55 UTC (rev 3895)
@@ -1,11 +1,30 @@
-pollen.configuration.data.directory=
-pollen.configuration.defaultPollCommentVisibility=
-pollen.configuration.defaultPollType=
-pollen.configuration.defaultPollVoteVisibility=
-pollen.configuration.defaultVoteCountingType=
+pollen.configuration.data.directory=Répertoire de données de l'application
+pollen.configuration.defaultPollCommentVisibility=Visibilité des commentaires par défaut lors de la création d'un nouveau sondage
+pollen.configuration.defaultPollType=Type de sondage par défaut lors de la création d'un nouveau sondage
+pollen.configuration.defaultPollVoteVisibility=Visibilité des votes par défaut lors de la création d'un nouveau sondage
+pollen.configuration.defaultVoteCountingType=Type de dépouillement par défaut lors de la création d'un nouveau sondage
pollen.error.favoriteList.import.csv.already.used.email=
pollen.error.favoriteList.import.csv.already.used.name=
pollen.error.favoriteList.import.csv.invalid.email=
pollen.error.favoriteList.import.ldap.already.used.email=
pollen.error.favoriteList.import.ldap.already.used.name=
pollen.error.favoriteList.import.ldap.invalid.email=
+pollen.service.mail.ChoiceAddedEmail.subject=[Pollen] Un choix a été ajouté au sondage %s
+pollen.service.mail.ChoiceDeletedEmail.subject=[Pollen] Un choix a été supprimé du sondage %s
+pollen.service.mail.ChoiceEditedEmail.subject=[Pollen] Un choix a été modifié sur le sondage %s
+pollen.service.mail.CommentAddedEmail.subject=[Pollen] Un commentaire a été ajouté au sondage %s
+pollen.service.mail.CommentDeletedEmail.subject=[Pollen] Un commentaire a été supprimé du sondage %s
+pollen.service.mail.CommentEditedEmail.subject=[Pollen] Un commentaire a été modifié sur le sondage %s
+pollen.service.mail.LostPasswordEmail.subject=[Pollen] Mot de passe perdu du compte %s
+pollen.service.mail.PollChoicePeriodEndedEmail.subject=[Pollen] Période d'ajout de choix terminée pour le sondage %s
+pollen.service.mail.PollChoicePeriodStartedEmail.subject=[Pollen] Période d'ajout de choix commencée pour le sondage %s
+pollen.service.mail.PollClosedEmail.subject=[Pollen] Le sondage %s est clôt
+pollen.service.mail.PollCreatedEmail.subject=[Pollen] Création du sondage %s
+pollen.service.mail.PollVotePeriodEndedEmail.subject=[Pollen] Période de vote terminée pour le sondage %s
+pollen.service.mail.PollVotePeriodStartedEmail.subject=[Pollen] Période de vote commencée pour le sondage %s
+pollen.service.mail.PollVoteReminderEmail.subject=[Pollen] Rappel du vote au sondage %s
+pollen.service.mail.RestrictedPollInvitationEmail.subject=[Pollen] Invitation au sondage %s
+pollen.service.mail.UserAccountCreatedEmail.subject=[Pollen] Confirmation de création du compte %s
+pollen.service.mail.VoteAddedEmail.subject=[Pollen] Un nouveau vote a été ajouté au sondage %s
+pollen.service.mail.VoteDeletedEmail.subject=[Pollen] Un vote a été modifié sur le sondage %s
+pollen.service.mail.VoteEditedEmail.subject=[Pollen] Un vote a été supprimé du sondage %s
Modified: trunk/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java
===================================================================
--- trunk/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/test/java/org/chorem/pollen/service/AbstractPollenServiceTest.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -25,7 +25,8 @@
import com.google.common.collect.Multimap;
import org.chorem.pollen.services.PollenService;
-import org.chorem.pollen.services.exception.AbstractInvalidFormException;
+import org.chorem.pollen.services.exception.InvalidFormException;
+import org.chorem.pollen.services.test.FakePollenSecurityContext;
import org.chorem.pollen.services.test.FakePollenServiceContext;
import org.chorem.pollen.services.test.PollenApplication;
import org.junit.Assert;
@@ -61,7 +62,8 @@
Locale.FRANCE,
application.getConfiguration(),
application.getApplicationContext(),
- application.newPersistenceContext());
+ application.newPersistenceContext(),
+ new FakePollenSecurityContext());
}
return serviceContext;
@@ -72,7 +74,7 @@
return getServiceContext().newService(serviceClass);
}
- protected void assertErrorKeyFound(AbstractInvalidFormException e, String... keys) {
+ protected void assertErrorKeyFound(InvalidFormException e, String... keys) {
Multimap<String, String> errors = e.getErrors();
Assert.assertEquals("Expected " + keys.length + " errors, but had " + errors.keySet(), keys.length, errors.keySet().size());
Modified: trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollServiceTest.java
===================================================================
--- trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollServiceTest.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollServiceTest.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -29,13 +29,12 @@
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.PollenSecurityContext;
-import org.chorem.pollen.services.exception.EntityNotFoundException;
-import org.chorem.pollen.services.exception.InvalidPollFormException;
+import org.chorem.pollen.services.exception.InvalidFormException;
import org.chorem.pollen.services.service.ChoiceService;
import org.chorem.pollen.services.service.PollService;
-import org.chorem.pollen.services.service.SecurityService;
import org.chorem.pollen.services.service.VoterListService;
+import org.chorem.pollen.services.service.security.SecurityService;
+import org.chorem.pollen.services.test.FakePollenSecurityContext;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -62,27 +61,27 @@
getServiceContext().setDate(new Date(1363948427576l));
- getServiceContext().setSecurityContext(PollenSecurityContext.newContext(null));
+ getServiceContext().setSecurityContext(new FakePollenSecurityContext());
}
@Test
- public void createPoll() throws InvalidPollFormException, EntityNotFoundException {
+ public void createPoll() throws InvalidFormException {
Poll poll = fixture("poll_normal");
- Poll createdPoll = service.createPoll(null, poll);
+ Poll createdPoll = service.createPoll(poll);
Assert.assertNotNull(createdPoll);
}
-
+
@Test
- public void testCreateFreePoll() throws EntityNotFoundException, InvalidPollFormException {
+ public void testCreateFreePoll() throws InvalidFormException {
- Poll poll = service.getNewPoll(null);
+ Poll poll = service.getNewPoll();
poll.setPollType(PollType.FREE);
try {
- service.createPoll(null, poll);
- } catch (InvalidPollFormException e) {
+ service.createPoll(poll);
+ } catch (InvalidFormException e) {
// missing title
// missing choice
assertErrorKeyFound(e, "title", "choice");
@@ -94,16 +93,16 @@
poll.addChoice(choice1);
try {
- service.createPoll(null, poll);
- } catch (InvalidPollFormException e) {
+ service.createPoll(poll);
+ } catch (InvalidFormException e) {
// missing choice type
assertErrorKeyFound(e, "choice[0].choiceType");
}
choice1.setChoiceType(ChoiceType.TEXT);
try {
- service.createPoll(null, poll);
- } catch (InvalidPollFormException e) {
+ service.createPoll(poll);
+ } catch (InvalidFormException e) {
// missing choice name
assertErrorKeyFound(e, "choice[0].name");
}
@@ -119,8 +118,8 @@
poll.addChoice(choice2);
try {
- service.createPoll(null, poll);
- } catch (InvalidPollFormException e) {
+ service.createPoll(poll);
+ } catch (InvalidFormException e) {
// duplicated choice name
assertErrorKeyFound(e, "choice[1].name");
}
@@ -128,7 +127,7 @@
choice2.setName("B");
- Poll createdPoll = service.createPoll(null, poll);
+ Poll createdPoll = service.createPoll(poll);
Assert.assertNotNull(createdPoll);
Assert.assertNotNull(createdPoll.getTopiaId());
@@ -177,9 +176,9 @@
}
@Test
- public void testCreateRestrictedPoll() throws EntityNotFoundException, InvalidPollFormException {
+ public void testCreateRestrictedPoll() throws InvalidFormException {
- Poll poll = service.getNewPoll(null);
+ Poll poll = service.getNewPoll();
poll.setPollType(PollType.RESTRICTED);
poll.setTitle("poll1");
@@ -199,8 +198,8 @@
poll.addChoice(choice2);
try {
- service.createPoll(null, poll);
- } catch (InvalidPollFormException e) {
+ service.createPoll(poll);
+ } catch (InvalidFormException e) {
// missing voterList
assertErrorKeyFound(e, "voterList");
}
@@ -211,8 +210,8 @@
poll.addVoterList(voterList);
try {
- service.createPoll(null, poll);
- } catch (InvalidPollFormException e) {
+ service.createPoll(poll);
+ } catch (InvalidFormException e) {
// missing name
// missing weight
// missing voterListMember
@@ -223,11 +222,11 @@
voterList.setWeight(1);
VoterListMember voterListMember1 = getServiceContext().getPersistenceContext().getVoterListMemberDao().newInstance();
- voterList.addVoterListMember(voterListMember1);
+ voterList.addMember(voterListMember1);
try {
- service.createPoll(null, poll);
- } catch (InvalidPollFormException e) {
+ service.createPoll(poll);
+ } catch (InvalidFormException e) {
// missing member name
// missing member email
assertErrorKeyFound(e, "voterList[0].member[0].name", "voterList[0].member[0].email", "voterList[0].member[0].weight");
@@ -238,8 +237,8 @@
voterListMember1.setEmail("voter1_pollen.org");
try {
- service.createPoll(null, poll);
- } catch (InvalidPollFormException e) {
+ service.createPoll(poll);
+ } catch (InvalidFormException e) {
// invalid member email
assertErrorKeyFound(e, "voterList[0].member[0].email");
}
@@ -250,11 +249,11 @@
voterListMember2.setName("voter1");
voterListMember2.setWeight(0.7);
voterListMember2.setEmail("voter1(a)pollen.org");
- voterList.addVoterListMember(voterListMember2);
+ voterList.addMember(voterListMember2);
try {
- service.createPoll(null, poll);
- } catch (InvalidPollFormException e) {
+ service.createPoll(poll);
+ } catch (InvalidFormException e) {
// same name
// same email
assertErrorKeyFound(e, "voterList[0].member[1].name", "voterList[0].member[1].email");
@@ -263,7 +262,7 @@
voterListMember2.setName("voter2");
voterListMember2.setEmail("voter2(a)pollen.org");
- Poll createdPoll = service.createPoll(null, poll);
+ Poll createdPoll = service.createPoll(poll);
Assert.assertNotNull(createdPoll);
Assert.assertNotNull(createdPoll.getTopiaId());
@@ -318,26 +317,26 @@
Assert.assertEquals(voterList.getName(), createdVoterList.getName());
Assert.assertEquals(voterList.getWeight(), createdVoterList.getWeight(), 0);
- Assert.assertNotNull(createdVoterList.getVoterListMember());
- Assert.assertEquals(2, createdVoterList.sizeVoterListMember());
+ Assert.assertNotNull(createdVoterList.getMember());
+ Assert.assertEquals(2, createdVoterList.sizeMember());
-// VoterListMember createdVoterListMember1 = Iterables.get(createdVoterList.getVoterListMember(), 0);
+// VoterListMember createdVoterListMember1 = Iterables.get(createdVoterList.getMember(), 0);
//
// Assert.assertNotNull(createdVoterListMember1);
// Assert.assertNotNull(createdVoterListMember1.getTopiaId());
-// VoterListMember reloadedVoterListMember1 = voterListService.getVoterListMember(createdPoll.getTopiaId(), createdVoterList.getTopiaId(), createdVoterListMember1.getTopiaId());
+// VoterListMember reloadedVoterListMember1 = voterListService.getMember(createdPoll.getTopiaId(), createdVoterList.getTopiaId(), createdVoterListMember1.getTopiaId());
// Assert.assertEquals(createdVoterListMember1, reloadedVoterListMember1);
//
// Assert.assertEquals(reloadedVoterListMember1.getName(), createdVoterListMember1.getName());
// Assert.assertEquals(reloadedVoterListMember1.getEmail(), createdVoterListMember1.getEmail());
// Assert.assertEquals(reloadedVoterListMember1.getWeight(), createdVoterListMember1.getWeight(), 0);
//
-// VoterListMember createdVoterListMember2 = Iterables.get(createdVoterList.getVoterListMember(), 1);
+// VoterListMember createdVoterListMember2 = Iterables.get(createdVoterList.getMember(), 1);
//
// Assert.assertNotNull(createdVoterListMember2);
// Assert.assertNotNull(createdVoterListMember2.getTopiaId());
//
-// VoterListMember reloadedVoterListMember2 = voterListService.getVoterListMember(createdPoll.getTopiaId(), createdVoterList.getTopiaId(), createdVoterListMember2.getTopiaId());
+// VoterListMember reloadedVoterListMember2 = voterListService.getMember(createdPoll.getTopiaId(), createdVoterList.getTopiaId(), createdVoterListMember2.getTopiaId());
// Assert.assertEquals(createdVoterListMember2, reloadedVoterListMember2);
//
// Assert.assertEquals(reloadedVoterListMember2.getName(), createdVoterListMember2.getName());
Modified: trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollenUserServiceTest.java
===================================================================
--- trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollenUserServiceTest.java 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pollen-services/src/test/java/org/chorem/pollen/service/PollenUserServiceTest.java 2014-05-02 09:20:55 UTC (rev 3895)
@@ -27,7 +27,7 @@
import org.chorem.pollen.persistence.entity.PollenUser;
import org.chorem.pollen.persistence.entity.PollenUsers;
import org.chorem.pollen.services.exception.EntityNotFoundException;
-import org.chorem.pollen.services.exception.InvalidPollenUserFormException;
+import org.chorem.pollen.services.exception.InvalidFormException;
import org.chorem.pollen.services.exception.UserInvalidEmailActivationTokenException;
import org.chorem.pollen.services.service.PollenUserService;
import org.junit.Assert;
@@ -72,7 +72,7 @@
}
@Test
- public void testGetPollenUser() throws EntityNotFoundException {
+ public void testGetPollenUser() {
try {
service.getUser("pollen_user_tony_" + System.nanoTime());
@@ -88,7 +88,7 @@
}
@Test
- public void testCreatePollenUser() throws Exception {
+ public void testCreatePollenUser() throws InvalidFormException {
try {
service.createUser(user, false);
@@ -113,7 +113,7 @@
try {
service.createUser(newUser2, true);
Assert.fail();
- } catch (InvalidPollenUserFormException e) {
+ } catch (InvalidFormException e) {
// not available login
// not available email
assertErrorKeyFound(e, "login", "email");
@@ -123,7 +123,7 @@
try {
service.createUser(newUser2, true);
Assert.fail();
- } catch (InvalidPollenUserFormException e) {
+ } catch (InvalidFormException e) {
// not available email
assertErrorKeyFound(e, "email");
}
@@ -135,7 +135,7 @@
}
@Test
- public void testEditUser() throws EntityNotFoundException, InvalidPollenUserFormException {
+ public void testEditUser() throws InvalidFormException {
PollenUser user = service.getUser(this.user.getTopiaId());
@@ -153,7 +153,7 @@
try {
service.editUser(user);
Assert.fail();
- } catch (InvalidPollenUserFormException e) {
+ } catch (InvalidFormException e) {
// invalid password
assertErrorKeyFound(e, "password");
}
@@ -167,7 +167,7 @@
}
@Test
- public void testValidateEmail() throws EntityNotFoundException, UserInvalidEmailActivationTokenException, InvalidPollenUserFormException {
+ public void testValidateEmail() throws UserInvalidEmailActivationTokenException, InvalidFormException {
PollenUser user = service.getUser(this.user.getTopiaId());
Assert.assertNotNull(user);
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-05-02 09:08:56 UTC (rev 3894)
+++ trunk/pom.xml 2014-05-02 09:20:55 UTC (rev 3895)
@@ -160,7 +160,7 @@
<projectId>pollen</projectId>
<!-- customized versions -->
- <webmotionVersion>2.5-SNAPSHOT</webmotionVersion>
+ <webmotionVersion>2.4.1-SNAPSHOT</webmotionVersion>
<nuitonI18nVersion>3.0</nuitonI18nVersion>
<eugenePluginVersion>2.9-SNAPSHOT</eugenePluginVersion>
@@ -405,9 +405,9 @@
<!-- Others -->
<dependency>
- <groupId>javax.mail</groupId>
- <artifactId>mail</artifactId>
- <version>1.5.0-b01</version>
+ <groupId>com.github.spullara.mustache.java</groupId>
+ <artifactId>compiler</artifactId>
+ <version>0.8.13</version>
</dependency>
<dependency>
1
0
r3894 - in trunk/pollen-ui-angular/src/main/webapp: . js js/controllers partials
by garandel@users.chorem.org 02 May '14
by garandel@users.chorem.org 02 May '14
02 May '14
Author: garandel
Date: 2014-05-02 11:08:56 +0200 (Fri, 02 May 2014)
New Revision: 3894
Url: http://forge.chorem.org/projects/pollen/repository/revisions/3894
Log:
Create poll with skeleton from rest api ( http://demo.codelutin.com/pollen-rest-api-latest/v1/polls/new )
Modified:
trunk/pollen-ui-angular/src/main/webapp/index.html
trunk/pollen-ui-angular/src/main/webapp/js/app.js
trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html
trunk/pollen-ui-angular/src/main/webapp/partials/poll.html
Modified: trunk/pollen-ui-angular/src/main/webapp/index.html
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/index.html 2014-04-30 16:17:52 UTC (rev 3893)
+++ trunk/pollen-ui-angular/src/main/webapp/index.html 2014-05-02 09:08:56 UTC (rev 3894)
@@ -18,16 +18,19 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
#L%
-->
+
<html lang="en" ng-app="pollen">
<head>
<title>Pollen</title>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<link rel="stylesheet" href="css/style.css"/>
+ <script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-route.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-resource.min…"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.10.0/ui-bootst…"></script>
+ <script src="http://cdnjs.cloudflare.com/ajax/libs/restangular/1.4.0/restangular.min.js"></script>
<script src="js/libs/ckeditor/ckeditor.js"></script>
<script src="js/app.js"></script>
Modified: trunk/pollen-ui-angular/src/main/webapp/js/app.js
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/js/app.js 2014-04-30 16:17:52 UTC (rev 3893)
+++ trunk/pollen-ui-angular/src/main/webapp/js/app.js 2014-05-02 09:08:56 UTC (rev 3894)
@@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
-angular.module('pollen', ["ngRoute", "pollControllers", 'ui.bootstrap'])
+angular.module('pollen', ["restangular", 'ngRoute', 'pollControllers', 'ui.bootstrap'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/', {templateUrl: './partials/home.html', controller: "HomeCtrl"})
@@ -30,6 +30,14 @@
}])
+.config(['RestangularProvider', function (RestangularProvider) {
+ RestangularProvider.setBaseUrl('http://demo.codelutin.com/pollen-rest-api-latest/v1');
+}])
+
+.factory('PollsRest', ['Restangular', function(Restangular) {
+ return Restangular.service('polls');
+}])
+
.directive('focusMe', function($timeout) {
return {
link: function($scope, element, attrs) {
Modified: trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-04-30 16:17:52 UTC (rev 3893)
+++ trunk/pollen-ui-angular/src/main/webapp/js/controllers/pollCtrl.js 2014-05-02 09:08:56 UTC (rev 3894)
@@ -64,15 +64,15 @@
}])
-.controller('PollAdminCtrl', ['$scope', '$controller', '$modal', '$filter', '$timeout', 'pollStorage', function ($scope, $controller, $modal, $filter, $timeout, pollStorage) {
+.controller('PollAdminCtrl', ['$scope', '$controller', '$modal', '$filter', '$timeout', 'PollsRest', 'pollStorage', function ($scope, $controller, $modal, $filter, $timeout, PollsRest, pollStorage) {
$controller('PollCtrl', {$scope:$scope});
var initPoll = function () {
- return {
- title :'',
- description : '',
- choices : []
- };
+
+ PollsRest.one('new').get().then(function (skeletonPoll) {
+ $scope.poll = skeletonPoll;
+ $scope.poll.choices = [];
+ });
}
var initChoice = function () {
@@ -93,8 +93,9 @@
});
if (!angular.isDefined($scope.poll.choices)) {
- $scope.poll = initPoll();
+ initPoll();
}
+
$scope.vote = {};
$scope.vote.choices = $scope.poll.choices;
Modified: trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html 2014-04-30 16:17:52 UTC (rev 3893)
+++ trunk/pollen-ui-angular/src/main/webapp/partials/poll-popupChoice.html 2014-05-02 09:08:56 UTC (rev 3894)
@@ -1,3 +1,24 @@
+<!--
+ #%L
+ Pollen :: UI (Angular)
+ %%
+ Copyright (C) 2009 - 2014 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ #L%
+ -->
+
<form class="form-horizontal">
<div class="modal-header">
<h4 class="modal-title">{{title}}</h4>
Modified: trunk/pollen-ui-angular/src/main/webapp/partials/poll.html
===================================================================
--- trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-04-30 16:17:52 UTC (rev 3893)
+++ trunk/pollen-ui-angular/src/main/webapp/partials/poll.html 2014-05-02 09:08:56 UTC (rev 3894)
@@ -1,3 +1,24 @@
+<!--
+ #%L
+ Pollen :: UI (Angular)
+ %%
+ Copyright (C) 2009 - 2014 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ #L%
+ -->
+
<form class="form-inline" name="pollForm" novalidate>
<alert type="'danger'" ng-if="globalVariables.errorForm"> Champ non remplie </alert>
1
0