01/01: use everywhere PollenEntityId
This is an automated email from the git hooks/post-receive script. unknown user pushed a commit to branch devel in repository Pollen. commit 444f953dd0aeafcf12c3e18aef2e85a22b50ada3 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri May 23 21:31:23 2014 +0200 use everywhere PollenEntityId --- .../org/chorem/pollen/rest/api/PollenRender.java | 4 +- .../rest/api/PollenRestApiApplicationListener.java | 46 ++------ .../rest/api/PollenRestApiRequestFilter.java | 4 +- .../chorem/pollen/rest/api/PollenRestApiUtil.java | 77 +++++++------- .../rest/api/injector/PollenBeanIdInjector.java | 49 +++++++++ .../PollenRestApiRequestContextInjector.java | 32 ++++++ .../rest/api/injector/PollenServiceInjector.java | 34 ++++++ .../org/chorem/pollen/rest/api/v1/ChoiceApi.java | 23 ++-- .../org/chorem/pollen/rest/api/v1/CommentApi.java | 24 +++-- .../chorem/pollen/rest/api/v1/FavoriteListApi.java | 31 +++--- .../org/chorem/pollen/rest/api/v1/PollApi.java | 27 +++-- .../chorem/pollen/rest/api/v1/PollenUserApi.java | 18 ++-- .../org/chorem/pollen/rest/api/v1/VoteApi.java | 23 ++-- .../chorem/pollen/rest/api/v1/VoteCountingApi.java | 10 +- .../chorem/pollen/rest/api/v1/VoterListApi.java | 49 +++++---- pollen-rest-api/src/main/resources/mapping | 25 +++++ .../src/main/resources/pollen-rest-api.properties | 1 + .../pollen/rest/api/AbstractPollenRestApiTest.java | 10 ++ .../org/chorem/pollen/rest/api/PollApiTest.java | 10 +- .../chorem/pollen/rest/api/PollenUserApiTest.java | 6 +- .../rest/api/converter/JsonConverterTest.java | 4 +- pollen-services/pom.xml | 10 ++ .../chorem/pollen/services/bean/ChoiceBean.java | 2 - .../chorem/pollen/services/bean/CommentBean.java | 2 - .../chorem/pollen/services/bean/CreateBeanRef.java | 55 +++------- .../pollen/services/bean/FavoriteListBean.java | 2 - .../services/bean/FavoriteListMemberBean.java | 2 - .../org/chorem/pollen/services/bean/PollBean.java | 2 - .../chorem/pollen/services/bean/PollenBean.java | 14 +-- .../chorem/pollen/services/bean/PollenBeanId.java | 104 ------------------ .../pollen/services/bean/PollenEntityId.java | 116 +++++++++++++++++++++ .../pollen/services/bean/PollenUserBean.java | 2 - .../org/chorem/pollen/services/bean/VoteBean.java | 36 ++++--- .../pollen/services/bean/VoteToChoiceBean.java | 18 ++-- .../chorem/pollen/services/bean/VoterListBean.java | 2 - .../pollen/services/bean/VoterListMemberBean.java | 2 - .../services/config/PollenServiceConfig.java | 5 + .../services/config/PollenServiceConfigOption.java | 7 ++ .../pollen/services/service/VoteService.java | 4 +- .../src/test/resources/pollen-services.properties | 1 + 40 files changed, 527 insertions(+), 366 deletions(-) diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java index bae0a13..71a5922 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRender.java @@ -26,7 +26,7 @@ package org.chorem.pollen.rest.api; import com.google.common.collect.Multimap; import com.google.gson.Gson; import org.chorem.pollen.services.bean.CreateBeanRef; -import org.chorem.pollen.services.bean.PollenBeanId; +import org.chorem.pollen.services.bean.PollenEntityId; import org.chorem.pollen.services.service.InvalidFormException; import org.debux.webmotion.server.call.Call; import org.debux.webmotion.server.call.HttpContext; @@ -109,7 +109,7 @@ public class PollenRender<T> extends Render { // encode id CreateBeanRef createBeanRef = (CreateBeanRef) model; - String encodeId = PollenBeanId.encodeId(topiaIdFactory, createBeanRef.getId()); + String encodeId = PollenEntityId.encode(topiaIdFactory, createBeanRef.getId()); CreateBeanRef result = CreateBeanRef.of(encodeId, createBeanRef.getPermission()); return result; diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java index 832fdfd..886ce14 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationListener.java @@ -27,7 +27,9 @@ import com.google.common.collect.Sets; import org.chorem.pollen.rest.api.converter.DateConverter; import org.chorem.pollen.rest.api.converter.JsonArrayConverter; import org.chorem.pollen.rest.api.converter.JsonConverter; -import org.chorem.pollen.services.PollenService; +import org.chorem.pollen.rest.api.injector.PollenBeanIdInjector; +import org.chorem.pollen.rest.api.injector.PollenRestApiRequestContextInjector; +import org.chorem.pollen.rest.api.injector.PollenServiceInjector; import org.chorem.pollen.services.bean.ChoiceBean; import org.chorem.pollen.services.bean.CommentBean; import org.chorem.pollen.services.bean.FavoriteListBean; @@ -37,14 +39,10 @@ import org.chorem.pollen.services.bean.PollenUserBean; import org.chorem.pollen.services.bean.VoteBean; import org.chorem.pollen.services.bean.VoteToChoiceBean; 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.TopiaIdFactory; -import java.lang.reflect.Type; import java.util.Date; import java.util.Set; @@ -96,41 +94,9 @@ public class PollenRestApiApplicationListener implements WebMotionServerListener // --- init injectors --- // - serverContext.addInjector(new ExecutorParametersInjectorHandler.Injector() { - @Override - public PollenRestApiRequestContext getValue(Mapping m, Call call, String name, Class<?> type, Type generic) { - - PollenRestApiRequestContext result = null; - if (PollenRestApiRequestContext.class.isAssignableFrom(type)) { - HttpContext httpContext = call.getContext(); - - result = PollenRestApiRequestContext.getRequestContext(httpContext); - } - - return result; - - } - }); - - serverContext.addInjector(new ExecutorParametersInjectorHandler.Injector() { - @Override - public PollenService getValue(Mapping m, Call call, String name, Class type, Type generic) { - - PollenService result = null; - if (PollenService.class.isAssignableFrom(type)) { - HttpContext httpContext = call.getContext(); - - PollenRestApiRequestContext requestContext = - PollenRestApiRequestContext.getRequestContext(httpContext); - result = requestContext.getServiceContext().newService(type); - } - - return result; - - } - }); - - + serverContext.addInjector(new PollenRestApiRequestContextInjector()); + serverContext.addInjector(new PollenServiceInjector()); + serverContext.addInjector(new PollenBeanIdInjector(topiaIdFactory)); } diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java index 664a251..c96137d 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java @@ -59,7 +59,7 @@ public class PollenRestApiRequestFilter extends WebMotionFilter { public void inject(Call call, HttpContext context) throws PollenInvalidSessionTokenException { - PollenRestApiRequestContext requestContext = prepareRequestContext(context); + prepareRequestContext(context); doProcess(); @@ -77,7 +77,7 @@ public class PollenRestApiRequestFilter extends WebMotionFilter { } - PollenRestApiUtil.prepareResponse(context, requestContext); + PollenRestApiUtil.prepareResponse(context); } diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiUtil.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiUtil.java index 0fb1cdf..affba69 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiUtil.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiUtil.java @@ -14,12 +14,11 @@ import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; import org.apache.commons.lang3.StringUtils; -import org.chorem.pollen.services.bean.PollenBeanId; +import org.chorem.pollen.services.bean.PollenEntityId; import org.debux.webmotion.server.call.HttpContext; import org.nuiton.topia.persistence.TopiaIdFactory; import javax.servlet.http.HttpServletResponse; -import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.Date; import java.util.List; @@ -36,7 +35,8 @@ public class PollenRestApiUtil { public static final String HEADER_ACCESS_CONTROL_ALLOW_HEADERS = "Access-Control-Allow-Headers"; - public static <O> List<O> toList(O[] array) { + @SafeVarargs + public static <O> List<O> toList(O... array) { List<O> list = null; @@ -55,30 +55,10 @@ public class PollenRestApiUtil { public static void prepareResponse(HttpContext context) { - PollenRestApiRequestContext requestContext = PollenRestApiRequestContext.getRequestContext(context); - - prepareResponse(context, requestContext); - - } - - public static void prepareResponse(HttpContext context, PollenRestApiRequestContext requestContext) { - HttpServletResponse response = context.getResponse(); response.addHeader(HttpContext.HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "*"); response.addHeader(HttpContext.HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"); -// PollenSecurityContext securityContext = requestContext.getSecurityContext(); -// SessionToken sessionToken = securityContext.getSessionToken(); -// if (sessionToken != null) { -// -// context.getResponse().setHeader(sessionToken.getPollenToken().getToken()); -// -// } else { -// -// context.getResponse().setHeader(requestContext.getSession().setSessionToken(null); -// -// } - } public static void addOptionCorsHeaders(HttpContext context) { @@ -104,29 +84,54 @@ public class PollenRestApiUtil { return clazz == Class.class; } }); + gsonBuilder.registerTypeAdapter(Date.class, new JsonSerializer<Date>() { @Override public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) { + + JsonElement result; + if (src == null) { - return JsonNull.INSTANCE; + + result = JsonNull.INSTANCE; + + } else { + + result = new JsonPrimitive(src.getTime()); + } - return new JsonPrimitive(src.getTime()); + + return result; + } }); - gsonBuilder.registerTypeAdapter(PollenBeanId.class, new JsonSerializer<PollenBeanId>() { + + gsonBuilder.registerTypeAdapter(PollenEntityId.class, new JsonSerializer<PollenEntityId>() { @Override - public JsonElement serialize(PollenBeanId src, Type typeOfSrc, JsonSerializationContext context) { + public JsonElement serialize(PollenEntityId src, Type typeOfSrc, JsonSerializationContext context) { + + JsonElement result; + if (src == null || src.getEntityId() == null) { - return JsonNull.INSTANCE; + + result = JsonNull.INSTANCE; + + } else { + + src.encode(idFactory); + result = new JsonPrimitive(src.getReducedId()); + } - src.encodeId(idFactory); - return new JsonPrimitive(src.getEncodedId()); + + return result; + } }); + gsonBuilder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() { @Override @@ -135,20 +140,19 @@ public class PollenRestApiUtil { } }); - gsonBuilder.registerTypeAdapter(PollenBeanId.class, new JsonDeserializer<PollenBeanId>() { + gsonBuilder.registerTypeAdapter(PollenEntityId.class, new JsonDeserializer<PollenEntityId>() { @Override - public PollenBeanId deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + public PollenEntityId deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - Type[] actualTypeArguments = ((ParameterizedType) typeOfT).getActualTypeArguments(); - PollenBeanId id = new PollenBeanId<>((Class) actualTypeArguments[0]); + PollenEntityId id = PollenEntityId.newId(typeOfT); String asString = json.getAsString(); if (asString != null) { - id.setEncodedId(asString); - id.decodeId(idFactory); + id.setReducedId(asString); + id.decode(idFactory); } @@ -157,6 +161,7 @@ public class PollenRestApiUtil { } }); + if (prettyPrint) { gsonBuilder.setPrettyPrinting(); diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenBeanIdInjector.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenBeanIdInjector.java new file mode 100644 index 0000000..6ac37d3 --- /dev/null +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenBeanIdInjector.java @@ -0,0 +1,49 @@ +package org.chorem.pollen.rest.api.injector; + +import org.chorem.pollen.services.bean.PollenEntityId; +import org.debux.webmotion.server.call.Call; +import org.debux.webmotion.server.handler.ExecutorParametersInjectorHandler; +import org.debux.webmotion.server.mapping.Mapping; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaIdFactory; + +import java.lang.reflect.Type; + +/** + * Created on 5/23/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollenBeanIdInjector implements ExecutorParametersInjectorHandler.Injector { + + protected final TopiaIdFactory topiaIdFactory; + + public PollenBeanIdInjector(TopiaIdFactory topiaIdFactory) { + this.topiaIdFactory = topiaIdFactory; + } + + @Override + public PollenEntityId<TopiaEntity> getValue(Mapping m, Call call, String name, Class type, Type generic) { + + PollenEntityId<TopiaEntity> result = null; + + if (PollenEntityId.class.isAssignableFrom(type)) { + + result = PollenEntityId.newId(generic); + Call.ParameterTree parameterTree = call.getParameterTree().getTree().get(name); + + if (parameterTree != null && parameterTree.getValue() != null) { + + String encodedId = ((String[]) parameterTree.getValue())[0]; + result.setReducedId(encodedId); + result.decode(topiaIdFactory); + + } + } + + return result; + + } + +} diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenRestApiRequestContextInjector.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenRestApiRequestContextInjector.java new file mode 100644 index 0000000..76fd593 --- /dev/null +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenRestApiRequestContextInjector.java @@ -0,0 +1,32 @@ +package org.chorem.pollen.rest.api.injector; + +import org.chorem.pollen.rest.api.PollenRestApiRequestContext; +import org.debux.webmotion.server.call.Call; +import org.debux.webmotion.server.call.HttpContext; +import org.debux.webmotion.server.handler.ExecutorParametersInjectorHandler; +import org.debux.webmotion.server.mapping.Mapping; + +import java.lang.reflect.Type; + +/** + * Created on 5/23/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollenRestApiRequestContextInjector implements ExecutorParametersInjectorHandler.Injector { + + @Override + public PollenRestApiRequestContext getValue(Mapping m, Call call, String name, Class<?> type, Type generic) { + + PollenRestApiRequestContext result = null; + if (PollenRestApiRequestContext.class.isAssignableFrom(type)) { + HttpContext httpContext = call.getContext(); + + result = PollenRestApiRequestContext.getRequestContext(httpContext); + } + + return result; + + } +} diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenServiceInjector.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenServiceInjector.java new file mode 100644 index 0000000..f35b2a0 --- /dev/null +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/injector/PollenServiceInjector.java @@ -0,0 +1,34 @@ +package org.chorem.pollen.rest.api.injector; + +import org.chorem.pollen.rest.api.PollenRestApiRequestContext; +import org.chorem.pollen.services.PollenService; +import org.debux.webmotion.server.call.Call; +import org.debux.webmotion.server.call.HttpContext; +import org.debux.webmotion.server.handler.ExecutorParametersInjectorHandler; +import org.debux.webmotion.server.mapping.Mapping; + +import java.lang.reflect.Type; + +/** + * Created on 5/23/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollenServiceInjector implements ExecutorParametersInjectorHandler.Injector { + @Override + public PollenService getValue(Mapping m, Call call, String name, Class type, Type generic) { + + PollenService result = null; + if (PollenService.class.isAssignableFrom(type)) { + HttpContext httpContext = call.getContext(); + + PollenRestApiRequestContext requestContext = + PollenRestApiRequestContext.getRequestContext(httpContext); + result = requestContext.getServiceContext().newService(type); + } + + return result; + + } +} diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceApi.java index 6f1b06c..d591990 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceApi.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/ChoiceApi.java @@ -23,8 +23,11 @@ package org.chorem.pollen.rest.api.v1; * #L% */ +import org.chorem.pollen.persistence.entity.Choice; +import org.chorem.pollen.persistence.entity.Poll; import org.chorem.pollen.services.bean.ChoiceBean; import org.chorem.pollen.services.bean.CreateBeanRef; +import org.chorem.pollen.services.bean.PollenEntityId; import org.chorem.pollen.services.service.ChoiceService; import org.chorem.pollen.services.service.InvalidFormException; import org.debux.webmotion.server.WebMotionController; @@ -39,37 +42,37 @@ import java.util.List; */ public class ChoiceApi extends WebMotionController { - public List<ChoiceBean> getChoices(ChoiceService choiceService, String pollId) { + public List<ChoiceBean> getChoices(ChoiceService choiceService, PollenEntityId<Poll> pollId) { - List<ChoiceBean> choices = choiceService.getChoices(pollId); + List<ChoiceBean> choices = choiceService.getChoices(pollId.getEntityId()); return choices; } - public ChoiceBean getChoice(ChoiceService choiceService, String pollId, String choiceId) { + public ChoiceBean getChoice(ChoiceService choiceService, PollenEntityId<Poll> pollId, PollenEntityId<Choice> choiceId) { - ChoiceBean choice = choiceService.getChoice(pollId, choiceId); + ChoiceBean choice = choiceService.getChoice(pollId.getEntityId(), choiceId.getEntityId()); return choice; } - public CreateBeanRef addChoice(ChoiceService choiceService, String pollId, ChoiceBean choice) throws InvalidFormException { + public CreateBeanRef addChoice(ChoiceService choiceService, PollenEntityId<Poll> pollId, ChoiceBean choice) throws InvalidFormException { - CreateBeanRef principalRef = choiceService.addChoice(pollId, choice); + CreateBeanRef principalRef = choiceService.addChoice(pollId.getEntityId(), choice); return principalRef; } - public ChoiceBean editChoice(ChoiceService choiceService, String pollId, ChoiceBean choice) throws InvalidFormException { + public ChoiceBean editChoice(ChoiceService choiceService, PollenEntityId<Poll> pollId, ChoiceBean choice) throws InvalidFormException { - ChoiceBean editChoice = choiceService.editChoice(pollId, choice); + ChoiceBean editChoice = choiceService.editChoice(pollId.getEntityId(), choice); return editChoice; } - public void deleteChoice(ChoiceService choiceService, String pollId, String choiceId) throws InvalidFormException { + public void deleteChoice(ChoiceService choiceService, PollenEntityId<Poll> pollId, PollenEntityId<Choice> choiceId) throws InvalidFormException { - choiceService.deleteChoice(pollId, choiceId); + choiceService.deleteChoice(pollId.getEntityId(), choiceId.getEntityId()); } diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentApi.java index d80404c..7e2283b 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentApi.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/CommentApi.java @@ -23,14 +23,18 @@ package org.chorem.pollen.rest.api.v1; * #L% */ +import org.chorem.pollen.persistence.entity.Comment; +import org.chorem.pollen.persistence.entity.Poll; import org.chorem.pollen.services.bean.CommentBean; import org.chorem.pollen.services.bean.CreateBeanRef; +import org.chorem.pollen.services.bean.PollenEntityId; import org.chorem.pollen.services.service.CommentService; import org.chorem.pollen.services.service.InvalidFormException; import org.debux.webmotion.server.WebMotionController; import java.util.List; + /** * TODO * @@ -39,37 +43,37 @@ import java.util.List; */ public class CommentApi extends WebMotionController { - public List<CommentBean> getComments(CommentService commentService, String pollId) { + public List<CommentBean> getComments(CommentService commentService, PollenEntityId<Poll> pollId) { - List<CommentBean> comments = commentService.getComments(pollId); + List<CommentBean> comments = commentService.getComments(pollId.getEntityId()); return comments; } - public CommentBean getComment(CommentService commentService, String pollId, String commentId) { + public CommentBean getComment(CommentService commentService, PollenEntityId<Poll> pollId, PollenEntityId<Comment> commentId) { - CommentBean comment = commentService.getComment(pollId, commentId); + CommentBean comment = commentService.getComment(pollId.getEntityId(), commentId.getReducedId()); return comment; } - public CreateBeanRef addComment(CommentService commentService, String pollId, CommentBean comment) throws InvalidFormException { + public CreateBeanRef addComment(CommentService commentService, PollenEntityId<Poll> pollId, CommentBean comment) throws InvalidFormException { - CreateBeanRef principalRef = commentService.addComment(pollId, comment); + CreateBeanRef principalRef = commentService.addComment(pollId.getEntityId(), comment); return principalRef; } - public CommentBean editComment(CommentService commentService, String pollId, CommentBean comment) throws InvalidFormException { + public CommentBean editComment(CommentService commentService, PollenEntityId<Poll> pollId, CommentBean comment) throws InvalidFormException { - CommentBean editComment = commentService.editComment(pollId, comment); + CommentBean editComment = commentService.editComment(pollId.getEntityId(), comment); return editComment; } - public void deleteComment(CommentService commentService, String pollId, String commentId) { + public void deleteComment(CommentService commentService, PollenEntityId<Poll> pollId, PollenEntityId<Comment> commentId) { - commentService.deleteComment(pollId, commentId); + commentService.deleteComment(pollId.getEntityId(), commentId.getEntityId()); } diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java index 77306bd..f4e53ad 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/FavoriteListApi.java @@ -23,9 +23,12 @@ package org.chorem.pollen.rest.api.v1; * #L% */ +import org.chorem.pollen.persistence.entity.FavoriteList; +import org.chorem.pollen.persistence.entity.FavoriteListMember; import org.chorem.pollen.services.bean.CreateBeanRef; import org.chorem.pollen.services.bean.FavoriteListBean; import org.chorem.pollen.services.bean.FavoriteListMemberBean; +import org.chorem.pollen.services.bean.PollenEntityId; import org.chorem.pollen.services.service.FavoriteListImportException; import org.chorem.pollen.services.service.FavoriteListService; import org.chorem.pollen.services.service.InvalidFormException; @@ -50,9 +53,9 @@ public class FavoriteListApi extends WebMotionController { } - public FavoriteListBean getFavoriteList(FavoriteListService favoriteListService, String favoriteListId) { + public FavoriteListBean getFavoriteList(FavoriteListService favoriteListService, PollenEntityId<FavoriteList> favoriteListId) { - FavoriteListBean favoriteList = favoriteListService.getFavoriteList(favoriteListId); + FavoriteListBean favoriteList = favoriteListService.getFavoriteList(favoriteListId.getEntityId()); return favoriteList; } @@ -71,43 +74,43 @@ public class FavoriteListApi extends WebMotionController { } - public void deleteFavoriteList(FavoriteListService favoriteListService, String favoriteListId) { + public void deleteFavoriteList(FavoriteListService favoriteListService, PollenEntityId<FavoriteList> favoriteListId) { - favoriteListService.deleteFavoriteList(favoriteListId); + favoriteListService.deleteFavoriteList(favoriteListId.getEntityId()); } - public int importFavoriteListMembersFromCsv(FavoriteListService favoriteListService, String favoriteListId, File csvFile) throws FavoriteListImportException { + public int importFavoriteListMembersFromCsv(FavoriteListService favoriteListService, PollenEntityId<FavoriteList> favoriteListId, File csvFile) throws FavoriteListImportException { - int i = favoriteListService.importFavoriteListMembersFromCsv(favoriteListId, csvFile); + int i = favoriteListService.importFavoriteListMembersFromCsv(favoriteListId.getEntityId(), csvFile); return i; } - public int importFavoriteListMembersFromLdap(FavoriteListService favoriteListService, String favoriteListId, String ldap) throws FavoriteListImportException { + public int importFavoriteListMembersFromLdap(FavoriteListService favoriteListService, PollenEntityId<FavoriteList> favoriteListId, String ldap) throws FavoriteListImportException { - int i = favoriteListService.importFavoriteListMembersFromLdap(favoriteListId, ldap); + int i = favoriteListService.importFavoriteListMembersFromLdap(favoriteListId.getEntityId(), ldap); return i; } - public Set<FavoriteListMemberBean> getMembers(FavoriteListService favoriteListService, String favoriteListId) { + public Set<FavoriteListMemberBean> getMembers(FavoriteListService favoriteListService, PollenEntityId<FavoriteList> favoriteListId) { - Set<FavoriteListMemberBean> members = favoriteListService.getFavoriteListMembers(favoriteListId); + Set<FavoriteListMemberBean> members = favoriteListService.getFavoriteListMembers(favoriteListId.getEntityId()); return members; } - public FavoriteListMemberBean getMember(FavoriteListService favoriteListService, String favoriteListId, String memberId) { + public FavoriteListMemberBean getMember(FavoriteListService favoriteListService, PollenEntityId<FavoriteList> favoriteListId, PollenEntityId<FavoriteListMember> memberId) { - FavoriteListMemberBean member = favoriteListService.getFavoriteListMember(favoriteListId, memberId); + FavoriteListMemberBean member = favoriteListService.getFavoriteListMember(favoriteListId.getEntityId(), memberId.getEntityId()); return member; } - public CreateBeanRef addMember(FavoriteListService favoriteListService, String favoriteListId, FavoriteListMemberBean member) throws InvalidFormException { + public CreateBeanRef addMember(FavoriteListService favoriteListService, PollenEntityId<FavoriteList> favoriteListId, FavoriteListMemberBean member) throws InvalidFormException { - CreateBeanRef principalRef = favoriteListService.addFavoriteListMember(favoriteListId, member); + CreateBeanRef principalRef = favoriteListService.addFavoriteListMember(favoriteListId.getEntityId(), member); return principalRef; } diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollApi.java index aefc3ea..a3a078b 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollApi.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollApi.java @@ -23,10 +23,12 @@ package org.chorem.pollen.rest.api.v1; * #L% */ +import org.chorem.pollen.persistence.entity.Poll; import org.chorem.pollen.rest.api.PollenRestApiUtil; import org.chorem.pollen.services.bean.ChoiceBean; import org.chorem.pollen.services.bean.CreateBeanRef; import org.chorem.pollen.services.bean.PollBean; +import org.chorem.pollen.services.bean.PollenEntityId; import org.chorem.pollen.services.bean.VoterListBean; import org.chorem.pollen.services.service.InvalidFormException; import org.chorem.pollen.services.service.PollService; @@ -79,14 +81,17 @@ public class PollApi extends WebMotionController { } - public PollBean getPoll(PollService pollService, String pollId) { + public PollBean getPoll(PollService pollService, PollenEntityId<Poll> pollId) { - PollBean poll = pollService.getPoll(pollId); + PollBean poll = pollService.getPoll(pollId.getEntityId()); return poll; } - public CreateBeanRef createPoll(PollService pollService, PollBean poll, ChoiceBean[] choices, VoterListBean[] voterLists) throws InvalidFormException { + public CreateBeanRef createPoll(PollService pollService, + PollBean poll, + ChoiceBean[] choices, + VoterListBean[] voterLists) throws InvalidFormException { List<ChoiceBean> choiceList = PollenRestApiUtil.toList(choices); @@ -104,28 +109,28 @@ public class PollApi extends WebMotionController { } - public void deletePoll(PollService pollService, String pollId) { + public void deletePoll(PollService pollService, PollenEntityId<Poll> pollId) { - pollService.deletePoll(pollId); + pollService.deletePoll(pollId.getEntityId()); } - public PollBean clonePoll(PollService pollService, String pollId) { + public PollBean clonePoll(PollService pollService, PollenEntityId<Poll> pollId) { - PollBean clonedPoll = pollService.clonePoll(pollId); + PollBean clonedPoll = pollService.clonePoll(pollId.getEntityId()); return clonedPoll; } - public void closePoll(PollService pollService, String pollId) { + public void closePoll(PollService pollService, PollenEntityId<Poll> pollId) { - pollService.closePoll(pollId); + pollService.closePoll(pollId.getEntityId()); } - public File exportPoll(PollService pollService, String pollId) { + public File exportPoll(PollService pollService, PollenEntityId<Poll> pollId) { - File exportedPollFile = pollService.exportPoll(pollId); + File exportedPollFile = pollService.exportPoll(pollId.getEntityId()); return exportedPollFile; } diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java index e38eec7..325303b 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java @@ -23,7 +23,9 @@ package org.chorem.pollen.rest.api.v1; * #L% */ +import org.chorem.pollen.persistence.entity.PollenUser; import org.chorem.pollen.services.bean.CreateBeanRef; +import org.chorem.pollen.services.bean.PollenEntityId; import org.chorem.pollen.services.bean.PollenUserBean; import org.chorem.pollen.services.service.InvalidFormException; import org.chorem.pollen.services.service.PollenUserService; @@ -48,9 +50,9 @@ public class PollenUserApi extends WebMotionController { } - public PollenUserBean getUser(PollenUserService pollenUserService, String userId) { + public PollenUserBean getUser(PollenUserService pollenUserService, PollenEntityId<PollenUser> userId) { - PollenUserBean user = pollenUserService.getUser(userId); + PollenUserBean user = pollenUserService.getUser(userId.getEntityId()); return user; } @@ -72,26 +74,26 @@ public class PollenUserApi extends WebMotionController { } - public void deleteUser(PollenUserService pollenUserService, String userId) throws InvalidFormException { + public void deleteUser(PollenUserService pollenUserService, PollenEntityId<PollenUser> userId) throws InvalidFormException { - pollenUserService.deleteUser(userId); + pollenUserService.deleteUser(userId.getEntityId()); } public void validateUserEmail(PollenUserService pollenUserService, - String userId, + PollenEntityId<PollenUser> userId, String token) throws PollenInvalidEmailActivationTokenException { - pollenUserService.validateUserEmail(userId, token); + pollenUserService.validateUserEmail(userId.getEntityId(), token); } public void changePassword(PollenUserService pollenUserService, - String userId, + PollenEntityId<PollenUser> userId, String oldPassword, String newPassword) throws PollenInvalidPasswordException { - pollenUserService.changePassword(userId, oldPassword, newPassword); + pollenUserService.changePassword(userId.getEntityId(), oldPassword, newPassword); } } diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteApi.java index 446a59d..c1a1b19 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteApi.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteApi.java @@ -23,7 +23,10 @@ package org.chorem.pollen.rest.api.v1; * #L% */ +import org.chorem.pollen.persistence.entity.Poll; +import org.chorem.pollen.persistence.entity.Vote; import org.chorem.pollen.services.bean.CreateBeanRef; +import org.chorem.pollen.services.bean.PollenEntityId; import org.chorem.pollen.services.bean.VoteBean; import org.chorem.pollen.services.service.InvalidFormException; import org.chorem.pollen.services.service.VoteService; @@ -39,37 +42,37 @@ import java.util.List; */ public class VoteApi extends WebMotionController { - public List<VoteBean> getVotes(VoteService voteService, String pollId) { + public List<VoteBean> getVotes(VoteService voteService, PollenEntityId<Poll> pollId) { - List<VoteBean> votes = voteService.getVotes(pollId); + List<VoteBean> votes = voteService.getVotes(pollId.getEntityId()); return votes; } - public VoteBean getVote(VoteService voteService, String pollId, String voteId) { + public VoteBean getVote(VoteService voteService, PollenEntityId<Poll> pollId, PollenEntityId<Vote> voteId) { - VoteBean vote = voteService.getVote(pollId, voteId); + VoteBean vote = voteService.getVote(pollId.getEntityId(), voteId.getEntityId()); return vote; } - public CreateBeanRef addVote(VoteService voteService, String pollId, VoteBean vote) throws InvalidFormException { + public CreateBeanRef addVote(VoteService voteService, PollenEntityId<Poll> pollId, VoteBean vote) throws InvalidFormException { - CreateBeanRef principalRef = voteService.addVote(pollId, vote); + CreateBeanRef principalRef = voteService.addVote(pollId.getEntityId(), vote); return principalRef; } - public VoteBean editVote(VoteService voteService, String pollId, VoteBean vote) throws InvalidFormException { + public VoteBean editVote(VoteService voteService, PollenEntityId<Poll> pollId, VoteBean vote) throws InvalidFormException { - VoteBean editedVote = voteService.editVote(pollId, vote); + VoteBean editedVote = voteService.editVote(pollId.getEntityId(), vote); return editedVote; } - public void deleteVote(VoteService voteService, String pollId, String voteId) { + public void deleteVote(VoteService voteService, PollenEntityId<Poll> pollId, PollenEntityId<Vote> voteId) { - voteService.deleteVote(pollId, voteId); + voteService.deleteVote(pollId.getEntityId(), voteId.getEntityId()); } } diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingApi.java index 2db98ed..a4b83ac 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingApi.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingApi.java @@ -23,6 +23,8 @@ package org.chorem.pollen.rest.api.v1; * #L% */ +import org.chorem.pollen.persistence.entity.Poll; +import org.chorem.pollen.services.bean.PollenEntityId; import org.chorem.pollen.services.service.VoteCountingService; import org.chorem.pollen.votecounting.model.GroupVoteCountingResult; import org.chorem.pollen.votecounting.model.VoteCountingResult; @@ -36,16 +38,16 @@ import org.debux.webmotion.server.WebMotionController; */ public class VoteCountingApi extends WebMotionController { - public VoteCountingResult getMainResult(VoteCountingService voteCountingService, String pollId) { + public VoteCountingResult getMainResult(VoteCountingService voteCountingService, PollenEntityId<Poll> pollId) { - VoteCountingResult result = voteCountingService.getMainResult(pollId); + VoteCountingResult result = voteCountingService.getMainResult(pollId.getEntityId()); return result; } - public GroupVoteCountingResult getGroupResult(VoteCountingService voteCountingService, String pollId) { + public GroupVoteCountingResult getGroupResult(VoteCountingService voteCountingService, PollenEntityId<Poll> pollId) { - GroupVoteCountingResult result = voteCountingService.getGroupResult(pollId); + GroupVoteCountingResult result = voteCountingService.getGroupResult(pollId.getEntityId()); return result; } diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListApi.java index f081ca7..231d8d0 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListApi.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoterListApi.java @@ -23,7 +23,12 @@ package org.chorem.pollen.rest.api.v1; * #L% */ +import org.chorem.pollen.persistence.entity.FavoriteList; +import org.chorem.pollen.persistence.entity.Poll; +import org.chorem.pollen.persistence.entity.VoterList; +import org.chorem.pollen.persistence.entity.VoterListMember; import org.chorem.pollen.services.bean.CreateBeanRef; +import org.chorem.pollen.services.bean.PollenEntityId; import org.chorem.pollen.services.bean.VoterListBean; import org.chorem.pollen.services.bean.VoterListMemberBean; import org.chorem.pollen.services.service.InvalidFormException; @@ -41,78 +46,78 @@ import java.util.Set; */ public class VoterListApi extends WebMotionController { - public VoterListBean importFavoriteList(VoterListService voterListService, String pollId, String favoriteListId) { + public VoterListBean importFavoriteList(VoterListService voterListService, PollenEntityId<Poll> pollId, PollenEntityId<FavoriteList> favoriteListId) { - VoterListBean importVoterList = voterListService.importFavoriteList(pollId, favoriteListId); + VoterListBean importVoterList = voterListService.importFavoriteList(pollId.getEntityId(), favoriteListId.getEntityId()); return importVoterList; } - public List<VoterListBean> getVoterLists(VoterListService voterListService, String pollId) { + public List<VoterListBean> getVoterLists(VoterListService voterListService, PollenEntityId<Poll> pollId) { - List<VoterListBean> voterLists = voterListService.getVoterLists(pollId); + List<VoterListBean> voterLists = voterListService.getVoterLists(pollId.getEntityId()); return voterLists; } - public VoterListBean getVoterList(VoterListService voterListService, String pollId, String voterListId) { + public VoterListBean getVoterList(VoterListService voterListService, PollenEntityId<Poll> pollId, PollenEntityId<VoterList> voterListId) { - VoterListBean voterList = voterListService.getVoterList(pollId, voterListId); + VoterListBean voterList = voterListService.getVoterList(pollId.getEntityId(), voterListId.getEntityId()); return voterList; } - public CreateBeanRef createVoterList(VoterListService voterListService, String pollId, VoterListBean voterList) throws InvalidFormException { + public CreateBeanRef createVoterList(VoterListService voterListService, PollenEntityId<Poll> pollId, VoterListBean voterList) throws InvalidFormException { - CreateBeanRef principalRef = voterListService.addVoterList(pollId, voterList); + CreateBeanRef principalRef = voterListService.addVoterList(pollId.getEntityId(), voterList); return principalRef; } - public VoterListBean editVoterList(VoterListService voterListService, String pollId, VoterListBean voterList) throws InvalidFormException { + public VoterListBean editVoterList(VoterListService voterListService, PollenEntityId<Poll> pollId, VoterListBean voterList) throws InvalidFormException { - VoterListBean editedVoterList = voterListService.editVoterList(pollId, voterList); + VoterListBean editedVoterList = voterListService.editVoterList(pollId.getEntityId(), voterList); return editedVoterList; } - public void deleteVoterList(VoterListService voterListService, String pollId, String voterListId) { + public void deleteVoterList(VoterListService voterListService, PollenEntityId<Poll> pollId, PollenEntityId<VoterList> voterListId) { - voterListService.deleteVoterList(pollId, voterListId); + voterListService.deleteVoterList(pollId.getEntityId(), voterListId.getEntityId()); } - public Set<VoterListMemberBean> getMembers(VoterListService voterListService, String pollId, String voterListId) { + public Set<VoterListMemberBean> getMembers(VoterListService voterListService, PollenEntityId<Poll> pollId, PollenEntityId<VoterList> voterListId) { - Set<VoterListMemberBean> members = voterListService.getVoterListMembers(pollId, voterListId); + Set<VoterListMemberBean> members = voterListService.getVoterListMembers(pollId.getEntityId(), voterListId.getEntityId()); return members; } - public VoterListMemberBean getMember(VoterListService voterListService, String pollId, String voterListId, String memberId) { + public VoterListMemberBean getMember(VoterListService voterListService, PollenEntityId<Poll> pollId, PollenEntityId<VoterList> voterListId, PollenEntityId<VoterListMember> memberId) { - VoterListMemberBean member = voterListService.getVoterListMember(pollId, voterListId, memberId); + VoterListMemberBean member = voterListService.getVoterListMember(pollId.getEntityId(), voterListId.getEntityId(), memberId.getEntityId()); return member; } - public VoterListMemberBean addMember(VoterListService voterListService, String pollId, String voterListId, VoterListMemberBean member) throws InvalidFormException { + public VoterListMemberBean addMember(VoterListService voterListService, PollenEntityId<Poll> pollId, PollenEntityId<VoterList> voterListId, VoterListMemberBean member) throws InvalidFormException { - VoterListMemberBean principalRef = voterListService.addVoterListMember(pollId, voterListId, member); + VoterListMemberBean principalRef = voterListService.addVoterListMember(pollId.getEntityId(), voterListId.getEntityId(), member); return principalRef; } - public VoterListMemberBean editMember(VoterListService voterListService, String pollId, String voterListId, VoterListMemberBean member) throws InvalidFormException { + public VoterListMemberBean editMember(VoterListService voterListService, PollenEntityId<Poll> pollId, PollenEntityId<VoterList> voterListId, VoterListMemberBean member) throws InvalidFormException { - VoterListMemberBean editedMember = voterListService.editVoterListMember(pollId, voterListId, member); + VoterListMemberBean editedMember = voterListService.editVoterListMember(pollId.getEntityId(), voterListId.getEntityId(), member); return editedMember; } - public void deleteMember(VoterListService voterListService, String pollId, String voterListId, String memberId) { + public void deleteMember(VoterListService voterListService, PollenEntityId<Poll> pollId, PollenEntityId<VoterList> voterListId, PollenEntityId<VoterListMember> memberId) { - voterListService.deleteVoterListMember(pollId, voterListId, memberId); + voterListService.deleteVoterListMember(pollId.getEntityId(), voterListId.getEntityId(), memberId.getEntityId()); } diff --git a/pollen-rest-api/src/main/resources/mapping b/pollen-rest-api/src/main/resources/mapping index 38cd416..c60deeb 100644 --- a/pollen-rest-api/src/main/resources/mapping +++ b/pollen-rest-api/src/main/resources/mapping @@ -1,3 +1,28 @@ +### +# #%L +# Pollen :: Rest Api +# %% +# 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% +### + +### +# Pollen version : ${project.version} +### + [config] package.filters=org.chorem.pollen.rest.api package.actions=org.chorem.pollen.rest.api.v1 diff --git a/pollen-rest-api/src/main/resources/pollen-rest-api.properties b/pollen-rest-api/src/main/resources/pollen-rest-api.properties index 21cc829..80bb25e 100644 --- a/pollen-rest-api/src/main/resources/pollen-rest-api.properties +++ b/pollen-rest-api/src/main/resources/pollen-rest-api.properties @@ -24,3 +24,4 @@ hibernate.connection.username=sa hibernate.connection.password=sa hibernate.connection.driver_class=org.h2.Driver hibernate.hbm2ddl.auto=update +pollen.version=${project.version} diff --git a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java index 7fafbbe..939417f 100644 --- a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java +++ b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/AbstractPollenRestApiTest.java @@ -30,6 +30,7 @@ import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; import org.chorem.pollen.persistence.entity.PollenPrincipal; import org.chorem.pollen.persistence.entity.SessionToken; import org.chorem.pollen.services.PollenServiceContext; +import org.chorem.pollen.services.bean.PollenEntityId; import org.chorem.pollen.services.service.security.PollenSecurityContext; import org.chorem.pollen.services.test.FakePollenApplicationContext; import org.chorem.pollen.services.test.FakePollenSecurityContext; @@ -38,6 +39,7 @@ import org.debux.webmotion.unittest.WebMotionTest; import org.junit.After; import org.junit.Before; import org.junit.Rule; +import org.nuiton.topia.persistence.TopiaIdFactory; import org.nuiton.util.DateUtil; import java.io.File; @@ -79,6 +81,14 @@ public class AbstractPollenRestApiTest extends WebMotionTest { } + protected String encodeId(String entityId) { + + TopiaIdFactory topiaIdFactory = application.getTopiaApplicationContext().getTopiaIdFactory(); + String encode = PollenEntityId.encode(topiaIdFactory, entityId); + return encode; + + } + @Before public void startServer() throws Exception { diff --git a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java index 07bfec7..1aa53fd 100644 --- a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java +++ b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollApiTest.java @@ -108,7 +108,7 @@ public class PollApiTest extends AbstractPollenRestApiTest { public void getPoll() throws URISyntaxException, IOException { Poll poll = fixture(PollenFixtures.POLL_NORMAL_ID); - String pollId = poll.getTopiaId(); + String pollId = encodeId(poll.getTopiaId()); Request request = createRequest("/v1/polls/" + pollId).Get(); String content = request.execute().returnContent().asString(); showTestResult(content); @@ -167,7 +167,7 @@ public class PollApiTest extends AbstractPollenRestApiTest { @Test public void deletePoll() throws URISyntaxException, IOException { Poll poll = fixture(PollenFixtures.POLL_NORMAL_ID); - String pollId = poll.getTopiaId(); + String pollId = encodeId(poll.getTopiaId()); Request request = createRequest("/v1/polls/" + pollId) .addParameter(PollenRestApiRequestFilter.REQUEST_PERMISSION_PARAMETER, poll.getCreator().getPermission().getToken()) .Delete(); @@ -180,7 +180,7 @@ public class PollApiTest extends AbstractPollenRestApiTest { @Test public void clonePoll() throws URISyntaxException, IOException { Poll poll = fixture(PollenFixtures.POLL_NORMAL_ID); - String pollId = poll.getTopiaId(); + String pollId = encodeId(poll.getTopiaId()); Request request = createRequest("/v1/polls/" + pollId).Post(); String content = request.execute().returnContent().asString(); showTestResult(content); @@ -191,7 +191,7 @@ public class PollApiTest extends AbstractPollenRestApiTest { @Test public void exportPoll() throws URISyntaxException, IOException { Poll poll = fixture(PollenFixtures.POLL_NORMAL_ID); - String pollId = poll.getTopiaId(); + String pollId = encodeId(poll.getTopiaId()); Request request = createRequest("/v1/polls/" + pollId + "/export").Get(); String content = request.execute().returnContent().asString(); showTestResult(content); @@ -202,7 +202,7 @@ public class PollApiTest extends AbstractPollenRestApiTest { @Test public void closePoll() throws URISyntaxException, IOException { Poll poll = fixture(PollenFixtures.POLL_NORMAL_ID); - String pollId = poll.getTopiaId(); + String pollId = encodeId(poll.getTopiaId()); Request request = createRequest("/v1/polls/" + pollId + "/close").Post(); String content = request.execute().returnContent().asString(); showTestResult(content); diff --git a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserApiTest.java b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserApiTest.java index 2fa7fad..1e7b9f1 100644 --- a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserApiTest.java +++ b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/PollenUserApiTest.java @@ -85,7 +85,7 @@ public class PollenUserApiTest extends AbstractPollenRestApiTest { String sessionToken = login("admin", "admin"); PollenUser pollenUser = fixture("user_jean"); - String userId = pollenUser.getTopiaId(); + String userId = encodeId(pollenUser.getTopiaId()); Request request = createRequest("/v1/users/" + userId).Get(); request.addHeader(PollenRestApiRequestFilter.REQUEST_HEADER_SESSION_TOKEN, sessionToken); String content = request.execute().returnContent().asString(); @@ -124,7 +124,7 @@ public class PollenUserApiTest extends AbstractPollenRestApiTest { public void deleteUser() throws Exception { PollenUser pollenUser = fixture("user_jean"); - String userId = pollenUser.getTopiaId(); + String userId = encodeId(pollenUser.getTopiaId()); Request request = createRequest("/v1/users/" + userId).Delete(); String content = request.execute().returnContent().asString(); showTestResult(content); @@ -137,7 +137,7 @@ public class PollenUserApiTest extends AbstractPollenRestApiTest { public void validateUserEmail() throws Exception { PollenUser pollenUser = fixture("user_jean"); - String userId = pollenUser.getTopiaId(); + String userId = encodeId(pollenUser.getTopiaId()); String token = ""; Request request = createRequest("/v1/users/" + userId + "?token=" + token).Put(); String content = request.execute().returnContent().asString(); diff --git a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/converter/JsonConverterTest.java b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/converter/JsonConverterTest.java index b34e74d..35bd59d 100644 --- a/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/converter/JsonConverterTest.java +++ b/pollen-rest-api/src/test/java/org/chorem/pollen/rest/api/converter/JsonConverterTest.java @@ -46,14 +46,14 @@ public class JsonConverterTest { Assert.assertEquals(true, voteBean.getAnonymous()); Assert.assertEquals("toto", voteBean.getVoterName()); - Assert.assertEquals("voterId", voteBean.getVoterId()); + Assert.assertEquals("voterId", voteBean.getVoterId().getReducedId()); Assert.assertNotNull(voteBean.getChoice()); Assert.assertEquals(1, voteBean.getChoice().size()); VoteToChoiceBean voteToChoiceBean = voteBean.getChoice().iterator().next(); Assert.assertNotNull(voteToChoiceBean); Assert.assertEquals(1.5, voteToChoiceBean.getVoteValue(), 0); - Assert.assertEquals("AA", voteToChoiceBean.getChoiceId()); + Assert.assertEquals("AA", voteToChoiceBean.getChoiceId().getReducedId()); String convert = converter.convert(String.class, voteBean); Assert.assertNotNull(convert); diff --git a/pollen-services/pom.xml b/pollen-services/pom.xml index bb00f0a..19c8c13 100644 --- a/pollen-services/pom.xml +++ b/pollen-services/pom.xml @@ -151,6 +151,16 @@ </dependencies> <build> + + <testResources> + <testResource> + <directory>src/test/resources</directory> + <includes> + <include>**/*.properties</include> + </includes> + <filtering>true</filtering> + </testResource> + </testResources> <plugins> <plugin> <groupId>org.nuiton.i18n</groupId> diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java index dc5ceff..746e055 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/ChoiceBean.java @@ -12,8 +12,6 @@ import org.chorem.pollen.persistence.entity.ChoiceType; */ public class ChoiceBean extends PollenBean<Choice> { - private static final long serialVersionUID = 1L; - protected String permission; protected int choiceOrder; diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/CommentBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/CommentBean.java index 7f03bb3..513337e 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/CommentBean.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/CommentBean.java @@ -14,8 +14,6 @@ import java.util.Date; */ public class CommentBean extends PollenBean<Comment> { - private static final long serialVersionUID = 1L; - protected String permission; protected String authorName; diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/CreateBeanRef.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/CreateBeanRef.java index 08d8cfe..5e5ff90 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/CreateBeanRef.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/CreateBeanRef.java @@ -2,15 +2,11 @@ package org.chorem.pollen.services.bean; import org.chorem.pollen.persistence.entity.Choice; import org.chorem.pollen.persistence.entity.Comment; -import org.chorem.pollen.persistence.entity.FavoriteList; -import org.chorem.pollen.persistence.entity.FavoriteListMember; import org.chorem.pollen.persistence.entity.Poll; -import org.chorem.pollen.persistence.entity.PollenUser; +import org.chorem.pollen.persistence.entity.PollenToken; import org.chorem.pollen.persistence.entity.SessionToken; import org.chorem.pollen.persistence.entity.Vote; -import org.chorem.pollen.persistence.entity.VoterList; - -import java.io.Serializable; +import org.nuiton.topia.persistence.TopiaEntity; /** * Created on 5/15/14. @@ -18,9 +14,7 @@ import java.io.Serializable; * @author Tony Chemit <chemit@codelutin.com> * @since 2.0 */ -public class CreateBeanRef implements Serializable { - - private static final long serialVersionUID = 1L; +public class CreateBeanRef { protected String id; @@ -28,68 +22,49 @@ public class CreateBeanRef implements Serializable { public static CreateBeanRef of(Poll entity) { - CreateBeanRef ref = new CreateBeanRef(entity.getTopiaId(), - entity.getCreator().getPermission().getToken()); + CreateBeanRef ref = of(entity, entity.getCreator().getPermission()); return ref; } public static CreateBeanRef of(Choice entity) { - CreateBeanRef ref = new CreateBeanRef(entity.getTopiaId(), - entity.getCreator().getPermission().getToken()); + CreateBeanRef ref = of(entity, entity.getCreator().getPermission()); return ref; } public static CreateBeanRef of(Comment entity) { - CreateBeanRef ref = new CreateBeanRef(entity.getTopiaId(), - entity.getAuthor().getPermission().getToken()); + CreateBeanRef ref = of(entity, entity.getAuthor().getPermission()); return ref; } public static CreateBeanRef of(Vote entity) { - CreateBeanRef ref = new CreateBeanRef(entity.getTopiaId(), - entity.getVoter().getPermission().getToken()); - return ref; - - } - - public static CreateBeanRef of(VoterList entity) { - - CreateBeanRef ref = new CreateBeanRef(entity.getTopiaId(), null); - return ref; - - } - - public static CreateBeanRef of(PollenUser result) { - - CreateBeanRef ref = new CreateBeanRef(result.getTopiaId(), null); + CreateBeanRef ref = of(entity, entity.getVoter().getPermission()); return ref; } - public static CreateBeanRef of(FavoriteList result) { + public static CreateBeanRef of(SessionToken result) { - CreateBeanRef ref = new CreateBeanRef(result.getTopiaId(), null); + CreateBeanRef ref = of(result.getPollenUser(), result.getPollenToken()); return ref; } - public static CreateBeanRef of(FavoriteListMember result) { + public static CreateBeanRef of(TopiaEntity result) { - CreateBeanRef ref = new CreateBeanRef(result.getTopiaId(), null); + CreateBeanRef ref = new CreateBeanRef(result); return ref; } - public static CreateBeanRef of(SessionToken result) { + public static CreateBeanRef of(TopiaEntity id, PollenToken permission) { - CreateBeanRef ref = new CreateBeanRef(result.getPollenUser().getTopiaId(), - result.getPollenToken().getToken()); + CreateBeanRef ref = new CreateBeanRef(id.getTopiaId(), permission==null?null: permission.getToken()); return ref; } @@ -101,6 +76,10 @@ public class CreateBeanRef implements Serializable { } + protected CreateBeanRef(TopiaEntity id) { + this(id.getTopiaId(), null); + } + protected CreateBeanRef(String id, String permission) { setId(id); diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListBean.java index 03b6fdb..c6f961e 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListBean.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListBean.java @@ -15,8 +15,6 @@ import java.util.Set; */ public class FavoriteListBean extends PollenBean<FavoriteList> { - private static final long serialVersionUID = 1L; - protected String name; protected double weight; diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListMemberBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListMemberBean.java index 17b2be8..97423c2 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListMemberBean.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/FavoriteListMemberBean.java @@ -11,8 +11,6 @@ import org.chorem.pollen.persistence.entity.FavoriteListMemberImpl; */ public class FavoriteListMemberBean extends PollenBean<FavoriteListMember> { - private static final long serialVersionUID = 1L; - protected String name; protected String email; diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollBean.java index c154074..5013db7 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollBean.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollBean.java @@ -20,8 +20,6 @@ import java.util.Objects; */ public class PollBean extends PollenBean<Poll> { - private static final long serialVersionUID = 1L; - public PollBean() { super(Poll.class); } diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBean.java index f2e3448..2883aa3 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBean.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBean.java @@ -2,34 +2,30 @@ package org.chorem.pollen.services.bean; import org.nuiton.topia.persistence.TopiaEntity; -import java.io.Serializable; - /** * Created on 5/15/14. * * @author Tony Chemit <chemit@codelutin.com> * @since 2.0 */ -public abstract class PollenBean<E extends TopiaEntity> implements Serializable { - - private static final long serialVersionUID = 1L; +public abstract class PollenBean<E extends TopiaEntity> { protected final Class<E> entityType; - protected PollenBeanId<E> id; + protected PollenEntityId<E> id; protected PollenBean(Class<E> entityType) { this.entityType = entityType; } - public PollenBeanId<E> getId() { + public PollenEntityId<E> getId() { if (id == null) { - id = new PollenBeanId<>(entityType); + id = PollenEntityId.newId(entityType); } return id; } - public void setId(PollenBeanId<E> id) { + public void setId(PollenEntityId<E> id) { this.id = id; } diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBeanId.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBeanId.java deleted file mode 100644 index 1f57427..0000000 --- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenBeanId.java +++ /dev/null @@ -1,104 +0,0 @@ -package org.chorem.pollen.services.bean; - -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.lang3.StringUtils; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.TopiaIdFactory; - -import java.io.Serializable; - -/** - * Created on 5/23/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 2.0 - */ -public class PollenBeanId<E extends TopiaEntity> implements Serializable { - - private static final long serialVersionUID = 1L; - - protected final Class<E> entityType; - - protected String encodedId; - - protected String entityId; - - public static String encodeId(TopiaIdFactory topiaIdFactory, String entityId) { - - String randomPart = topiaIdFactory.getRandomPart(entityId); - String encodedId = new String(Base64.encodeBase64URLSafe(randomPart.getBytes())); - return encodedId; - - } - - public PollenBeanId(Class<E> entityType) { - this.entityType = entityType; - } - - public boolean isNotEmpty() { - return StringUtils.isNotEmpty(encodedId) || StringUtils.isNotEmpty(entityId); - } - - public String getEncodedId() { - return encodedId; - } - - public String getEntityId() { - return entityId; - } - - public void setEncodedId(String encodedId) { - this.encodedId = encodedId; - } - - public void setEntityId(String entityId) { - this.entityId = entityId; - } - - public void encodeId(TopiaIdFactory topiaIdFactory) { - - if (entityId != null) { - - String id = encodeId(topiaIdFactory, entityId); - setEncodedId(id); - - } - - } - - public void decodeId(TopiaIdFactory topiaIdFactory) { - - if (encodedId != null) { - - String decodedId = new String(Base64.decodeBase64(encodedId)); - String id = topiaIdFactory.newTopiaId(entityType, decodedId); - setEntityId(id); - - } - - } - - @Override - public boolean equals(Object o) { - - if (this == o) return true; - if (!(o instanceof PollenBeanId)) return false; - - PollenBeanId that = (PollenBeanId) o; - - return entityType.equals(that.entityType) - && encodedId != null && encodedId.equals(that.encodedId) - || entityId != null && entityId.equals(that.entityId); - - } - - @Override - public int hashCode() { - - int result = entityType.hashCode(); - result = 31 * result + (encodedId != null ? encodedId.hashCode() : 0); - result = 31 * result + (entityId != null ? entityId.hashCode() : 0); - return result; - - } -} diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenEntityId.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenEntityId.java new file mode 100644 index 0000000..98147a3 --- /dev/null +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenEntityId.java @@ -0,0 +1,116 @@ +package org.chorem.pollen.services.bean; + +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.lang3.StringUtils; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaIdFactory; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +/** + * Created on 5/23/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.0 + */ +public class PollenEntityId<E extends TopiaEntity> { + + protected final Class<E> entityType; + + protected String entityId; + + protected String reducedId; + + public static <E extends TopiaEntity> PollenEntityId<E> newId(Type typeOfT) { + + Type[] actualTypeArguments = ((ParameterizedType) typeOfT).getActualTypeArguments(); + return newId((Class<E>) actualTypeArguments[0]); + + } + + public static <E extends TopiaEntity> PollenEntityId<E> newId(Class<E> entityType) { + + return new PollenEntityId<>(entityType); + + } + + public static String encode(TopiaIdFactory topiaIdFactory, String entityId) { + + String randomPart = topiaIdFactory.getRandomPart(entityId); + String encodedId = new String(Base64.encodeBase64URLSafe(randomPart.getBytes())); + return encodedId; + + } + + public PollenEntityId(Class<E> entityType) { + this.entityType = entityType; + } + + public boolean isNotEmpty() { + return StringUtils.isNotEmpty(reducedId) || StringUtils.isNotEmpty(entityId); + } + + public String getReducedId() { + return reducedId; + } + + public String getEntityId() { + return entityId; + } + + public void setReducedId(String reducedId) { + this.reducedId = reducedId; + } + + public void setEntityId(String entityId) { + this.entityId = entityId; + } + + public void encode(TopiaIdFactory topiaIdFactory) { + + if (entityId != null) { + + String id = encode(topiaIdFactory, entityId); + setReducedId(id); + + } + + } + + public void decode(TopiaIdFactory topiaIdFactory) { + + if (reducedId != null) { + + String decodedId = new String(Base64.decodeBase64(reducedId)); + String id = topiaIdFactory.newTopiaId(entityType, decodedId); + setEntityId(id); + + } + + } + + @Override + public boolean equals(Object o) { + + if (this == o) return true; + if (!(o instanceof PollenEntityId)) return false; + + PollenEntityId that = (PollenEntityId) o; + + return entityType.equals(that.entityType) + && (reducedId != null && reducedId.equals(that.reducedId) + || entityId != null && entityId.equals(that.entityId)); + + } + + @Override + public int hashCode() { + + int result = entityType.hashCode(); + result = 31 * result + (reducedId == null ? 0 : reducedId.hashCode()); + result = 31 * result + (entityId == null ? 0 : entityId.hashCode()); + return result; + + } +} diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenUserBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenUserBean.java index 4ee51bb..98cd27a 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenUserBean.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenUserBean.java @@ -11,8 +11,6 @@ import org.chorem.pollen.persistence.entity.PollenUserImpl; */ public class PollenUserBean extends PollenBean<PollenUser> { - private static final long serialVersionUID = 1L; - protected String login; protected String name; diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteBean.java index 62ef064..d1dad27 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteBean.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteBean.java @@ -1,6 +1,5 @@ package org.chorem.pollen.services.bean; -import org.apache.commons.lang3.StringUtils; import org.chorem.pollen.persistence.entity.PollenPrincipal; import org.chorem.pollen.persistence.entity.PollenPrincipalImpl; import org.chorem.pollen.persistence.entity.Vote; @@ -23,11 +22,9 @@ import java.util.Set; */ public class VoteBean extends PollenBean<Vote> { - private static final long serialVersionUID = 1L; + protected PollenEntityId<PollenPrincipal> voterId; - protected String voterId; - - protected String voterListMemberId; + protected PollenEntityId<VoterListMember> voterListMemberId; protected String voterName; @@ -93,9 +90,10 @@ public class VoteBean extends PollenBean<Vote> { PollenPrincipal voter = new PollenPrincipalImpl(); entity.setVoter(voter); - voter.setTopiaId(getVoterId()); + voter.setTopiaId(getVoterId().getEntityId()); voter.setName(getVoterName()); + for (VoteToChoiceBean choiceBean : choice) { VoteToChoice voteToChoice = choiceBean.toEntity(); @@ -103,11 +101,11 @@ public class VoteBean extends PollenBean<Vote> { } - if (StringUtils.isNotBlank(voterListMemberId)) { + if (getVoterListMemberId().getEntityId() != null) { // FIXME VoterListMember member = new VoterListMemberImpl(); - member.setTopiaId(voterListMemberId); + member.setTopiaId(getVoterListMemberId().getEntityId()); } @@ -123,14 +121,21 @@ public class VoteBean extends PollenBean<Vote> { this.voterName = voterName; } - public String getVoterId() { + public PollenEntityId<PollenPrincipal> getVoterId() { + if (voterId == null) { + voterId = PollenEntityId.newId(PollenPrincipal.class); + } return voterId; } - public void setVoterId(String voterId) { + public void setVoterId(PollenEntityId<PollenPrincipal> voterId) { this.voterId = voterId; } + public void setVoterId(String voterId) { + getVoterId().setEntityId(voterId); + } + public String getPermission() { return permission; } @@ -159,14 +164,21 @@ public class VoteBean extends PollenBean<Vote> { return anonymous != null && anonymous; } - public String getVoterListMemberId() { + public PollenEntityId<VoterListMember> getVoterListMemberId() { + if (voterListMemberId == null) { + voterListMemberId = PollenEntityId.newId(VoterListMember.class); + } return voterListMemberId; } - public void setVoterListMemberId(String voterListMemberId) { + public void setVoterListMemberId(PollenEntityId<VoterListMember> voterListMemberId) { this.voterListMemberId = voterListMemberId; } + public void setVoterListMemberId(String voterListMemberId) { + getVoterListMemberId().setEntityId(voterListMemberId); + } + public double getWeight() { return weight; } diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteToChoiceBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteToChoiceBean.java index 2251190..2e29e35 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteToChoiceBean.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteToChoiceBean.java @@ -1,5 +1,6 @@ package org.chorem.pollen.services.bean; +import org.chorem.pollen.persistence.entity.Choice; import org.chorem.pollen.persistence.entity.ChoiceImpl; import org.chorem.pollen.persistence.entity.VoteToChoice; import org.chorem.pollen.persistence.entity.VoteToChoiceImpl; @@ -12,9 +13,7 @@ import org.chorem.pollen.persistence.entity.VoteToChoiceImpl; */ public class VoteToChoiceBean extends PollenBean<VoteToChoice> { - private static final long serialVersionUID = 1L; - - protected String choiceId; + protected PollenEntityId<Choice> choiceId; protected Double voteValue; @@ -38,20 +37,27 @@ public class VoteToChoiceBean extends PollenBean<VoteToChoice> { entity.setTopiaId(getEntityId()); entity.setVoteValue(getVoteValue()); entity.setChoice(new ChoiceImpl()); - entity.getChoice().setTopiaId(getChoiceId()); + entity.getChoice().setTopiaId(getChoiceId().getEntityId()); return entity; } - public String getChoiceId() { + public PollenEntityId<Choice> getChoiceId() { + if (choiceId == null) { + choiceId = PollenEntityId.newId(Choice.class); + } return choiceId; } - public void setChoiceId(String choiceId) { + public void setChoiceId(PollenEntityId<Choice> choiceId) { this.choiceId = choiceId; } + public void setChoiceId(String choiceId) { + getChoiceId().setEntityId(choiceId); + } + public Double getVoteValue() { return voteValue; } diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListBean.java index 1fb2679..51ea9f7 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListBean.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListBean.java @@ -15,8 +15,6 @@ import java.util.Set; */ public class VoterListBean extends PollenBean<VoterList> { - private static final long serialVersionUID = 1L; - protected String name; protected double weight; diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListMemberBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListMemberBean.java index 85ca451..12facbe 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListMemberBean.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoterListMemberBean.java @@ -11,8 +11,6 @@ import org.chorem.pollen.persistence.entity.VoterListMemberImpl; */ public class VoterListMemberBean extends PollenBean<VoterListMember> { - private static final long serialVersionUID = 1L; - protected String name; protected String email; diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java b/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java index 7fd20d9..706bb94 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfig.java @@ -37,6 +37,7 @@ import org.chorem.pollen.persistence.entity.VoteVisibility; import org.chorem.pollen.services.PollenTechnicalException; import org.nuiton.config.ApplicationConfig; import org.nuiton.config.ArgumentsParserException; +import org.nuiton.util.Version; import java.io.File; import java.util.List; @@ -194,4 +195,8 @@ public class PollenServiceConfig { public String getHashAlgorithmName() { return Sha512Hash.ALGORITHM_NAME; } + + public Version getVersion() { + return applicationConfig.getOptionAsVersion(PollenServiceConfigOption.APPLICATION_VERSION.key); + } } diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java b/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java index 89d79cd..58c4623 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServiceConfigOption.java @@ -29,6 +29,7 @@ import org.chorem.pollen.persistence.entity.PollType; import org.chorem.pollen.persistence.entity.ResultVisibility; import org.chorem.pollen.persistence.entity.VoteVisibility; import org.nuiton.config.ConfigOptionDef; +import org.nuiton.util.Version; import java.io.File; @@ -155,6 +156,12 @@ public enum PollenServiceConfigOption implements ConfigOptionDef { "Chemin vers le fichier de configuration des journaux", null, String.class), + + APPLICATION_VERSION( + "pollen.version", + "Version de l'application", + null, + Version.class), ; protected final String key; diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java index 51b5d72..a608993 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteService.java @@ -198,7 +198,7 @@ public class VoteService extends PollenServiceSupport { double weight; - if (StringUtils.isBlank(vote.getVoterListMemberId())) { + if (StringUtils.isBlank(vote.getVoterListMemberId().getEntityId())) { // not link to a member, use default value @@ -291,7 +291,7 @@ public class VoteService extends PollenServiceSupport { result = voteToChoiceDao.create(); - String choiceId = source.getChoiceId(); + String choiceId = source.getChoiceId().getEntityId(); Choice choiceLoaded = getChoiceDao().findByTopiaId(choiceId); diff --git a/pollen-services/src/test/resources/pollen-services.properties b/pollen-services/src/test/resources/pollen-services.properties index e7c2eae..a9d9843 100644 --- a/pollen-services/src/test/resources/pollen-services.properties +++ b/pollen-services/src/test/resources/pollen-services.properties @@ -24,3 +24,4 @@ hibernate.connection.username=sa hibernate.connection.password=sa hibernate.connection.driver_class=org.h2.Driver hibernate.hbm2ddl.auto=update +pollen.version=${project.version} -- To stop receiving notification emails like this one, please contact Chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
Chorem.org scm