This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit 802700b33ea84356a1cf100e434e8dea9234418a Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Fri Oct 20 08:54:20 2017 +0200 Sppression des ambiguité de l'API REST --- .../org/chorem/pollen/rest/api/v1/CommentApi.java | 31 +++--- .../chorem/pollen/rest/api/v1/FavoriteListApi.java | 20 ++-- .../org/chorem/pollen/rest/api/v1/PollApi.java | 62 +++++------- .../org/chorem/pollen/rest/api/v1/VoteApi.java | 35 ++++--- .../chorem/pollen/rest/api/v1/VoterListApi.java | 105 ++++++++++----------- pollen-ui-riot-js/src/main/web/js/PollService.js | 26 +++-- pollen-ui-riot-js/src/main/web/js/VoteService.js | 2 +- .../src/main/web/js/VoterListService.js | 6 +- 8 files changed, 129 insertions(+), 158 deletions(-) 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 418026f1..da5f7ba5 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 @@ -68,32 +68,31 @@ public class CommentApi { } + @Path("polls/{pollId}/comments") + @POST + public PollenEntityRef<Comment> addComment(@Context CommentService commentService, + @PathParam("pollId") PollenEntityId<Poll> pollId, + CommentBean comment) throws InvalidFormException { + + return commentService.addComment(pollId.getEntityId(), comment); + + } + @Path("polls/{pollId}/comments/{commentId}") @GET public CommentBean getComment(@Context CommentService commentService, @PathParam("pollId") PollenEntityId<Poll> pollId, @PathParam("commentId") PollenEntityId<Comment> commentId) { - return commentService.getComment(pollId.getEntityId(), commentId.getReducedId()); + if ("new".equals(commentId.getReducedId())) { - } + return commentService.getNewComment(pollId.getEntityId()); - @Path("polls/{pollId}/comments/new") - @GET - public CommentBean getNewComment(@Context CommentService commentService, - @PathParam("pollId") PollenEntityId<Poll> pollId) { - - return commentService.getNewComment(pollId.getEntityId()); + } else { - } - - @Path("polls/{pollId}/comments") - @POST - public PollenEntityRef<Comment> addComment(@Context CommentService commentService, - @PathParam("pollId") PollenEntityId<Poll> pollId, - CommentBean comment) throws InvalidFormException { + return commentService.getComment(pollId.getEntityId(), commentId.getReducedId()); - return commentService.addComment(pollId.getEntityId(), comment); + } } 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 5a6fe2b6..09bfe235 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 @@ -75,6 +75,15 @@ public class FavoriteListApi { } + @Path("/favoriteLists") + @POST + public PollenEntityRef<FavoriteList> createFavoriteList(@Context FavoriteListService favoriteListService, + FavoriteListBean favoriteList) throws InvalidFormException { + + return favoriteListService.createFavoriteList(favoriteList); + + } + @Path("/favoriteLists/imports") @POST @Consumes("multipart/form-data") @@ -104,17 +113,6 @@ public class FavoriteListApi { } - - - @Path("/favoriteLists") - @POST - public PollenEntityRef<FavoriteList> createFavoriteList(@Context FavoriteListService favoriteListService, - FavoriteListBean favoriteList) throws InvalidFormException { - - return favoriteListService.createFavoriteList(favoriteList); - - } - @Path("/favoriteLists/{favoriteListId}") @PUT @POST public FavoriteListBean editFavoriteList(@Context FavoriteListService favoriteListService, 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 50573bcb..e41942e0 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 @@ -21,6 +21,7 @@ package org.chorem.pollen.rest.api.v1; * #L% */ +import org.apache.commons.lang3.StringUtils; import org.chorem.pollen.persistence.entity.ChoiceType; import org.chorem.pollen.persistence.entity.Poll; import org.chorem.pollen.rest.api.beans.PollCreateBean; @@ -64,51 +65,22 @@ import java.util.List; public class PollApi { - @GET - @Path("/polls/new") - public PollBean getNewPoll(@Context PollService pollService) { - - return pollService.getNewPoll(ChoiceType.TEXT); - - } - @Path("/polls") @GET public PaginationResultBean<PollBean> getPolls(@Context PollService pollService, @BeanParam PaginationParameterBean paginationParameter, - @QueryParam("search") String search) { - - return pollService.getPolls(paginationParameter, search); - - } - - @GET - @Path("/polls/created") - public PaginationResultBean<PollBean> getCreatedPolls(@Context PollService pollService, - @BeanParam PaginationParameterBean paginationParameter, - @QueryParam("search") String search) { - - return pollService.getCreatedPolls(paginationParameter, search); - - } - - @GET - @Path("/polls/invited") - public PaginationResultBean<PollBean> getInvitedPolls(@Context PollService pollService, - @BeanParam PaginationParameterBean paginationParameter, - @QueryParam("search") String search) { - - return pollService.getInvitedPolls(paginationParameter, search); - - } + @QueryParam("search") String search, + @QueryParam("use") String context) { - @GET - @Path("/polls/participated") - public PaginationResultBean<PollBean> getParticipatedPolls(@Context PollService pollService, - @BeanParam PaginationParameterBean paginationParameter, - @QueryParam("search") String search) { - - return pollService.getParticipatedPolls(paginationParameter, search); + if (StringUtils.isBlank(context)) { + return pollService.getPolls(paginationParameter, search); + } else if ("invited".equals(context)) { + return pollService.getInvitedPolls(paginationParameter, search); + } else if ("participated".equals(context)) { + return pollService.getParticipatedPolls(paginationParameter, search); + } else /*if ("created".equals(context))*/ { + return pollService.getCreatedPolls(paginationParameter, search); + } } @@ -129,7 +101,15 @@ public class PollApi { public PollBean getPoll(@Context PollService pollService, @PathParam("pollId") PollenEntityId<Poll> pollId) { - return pollService.getPoll(pollId.getEntityId()); + if ("new".equals(pollId.getReducedId())) { + + return pollService.getNewPoll(ChoiceType.TEXT); + + } else { + + return pollService.getPoll(pollId.getEntityId()); + + } } 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 80ac2ae5..cdcf3e2b 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 @@ -54,15 +54,6 @@ import javax.ws.rs.core.MediaType; @Produces(MediaType.APPLICATION_JSON) public class VoteApi { - @Path("/polls/{pollId}/votes/new") - @GET - public VoteBean getNewVote(@Context VoteService voteService, - @PathParam("pollId") PollenEntityId<Poll> pollId) { - - return voteService.getNewVote(pollId.getEntityId()); - - } - @Path("/polls/{pollId}/votes") @GET public PaginationResultBean<VoteBean> getVotes(@Context VoteService voteService, @@ -73,26 +64,34 @@ public class VoteApi { } + @Path("/polls/{pollId}/votes") + @POST + public PollenEntityRef<Vote> addVote(@Context VoteService voteService, + @PathParam("pollId") PollenEntityId<Poll> pollId, + VoteBean vote) throws InvalidFormException { + + return voteService.addVote(pollId.getEntityId(), vote); + + } + @Path("/polls/{pollId}/votes/{voteId}") @GET public VoteBean getVote(@Context VoteService voteService, @PathParam("pollId") PollenEntityId<Poll> pollId, @PathParam("voteId") PollenEntityId<Vote> voteId) { - return voteService.getVote(pollId.getEntityId(), voteId.getEntityId()); + if ("new".equals(voteId.getReducedId())) { - } + return voteService.getNewVote(pollId.getEntityId()); - @Path("/polls/{pollId}/votes") - @POST - public PollenEntityRef<Vote> addVote(@Context VoteService voteService, - @PathParam("pollId") PollenEntityId<Poll> pollId, - VoteBean vote) throws InvalidFormException { + } else { - return voteService.addVote(pollId.getEntityId(), vote); + return voteService.getVote(pollId.getEntityId(), voteId.getEntityId()); - } + } + } + @Path("/polls/{pollId}/votes/{voteId}") @POST @PUT public VoteBean editVote(@Context VoteService voteService, 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 c3aa802b..082ca982 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 @@ -57,23 +57,39 @@ import java.util.Set; @Produces(MediaType.APPLICATION_JSON) public class VoterListApi { - @Path("/polls/{pollId}/voterLists/main") - @GET - public VoterListBean getMainVoterList(@Context VoterListService voterListService, - @PathParam("pollId") PollenEntityId<Poll> pollId) { + @Path("/polls/{pollId}/voterLists") + @POST + public PollenEntityRef<VoterList> createVoterList(@Context VoterListService voterListService, + @PathParam("pollId") PollenEntityId<Poll> pollId, + VoterListBean voterList, + VoterListMemberBean... members) throws InvalidFormException { + + List<VoterListMemberBean> memberList = Lists.newArrayList(members); - return voterListService.getMainVoterList(pollId.getEntityId()); + return voterListService.addVoterList(pollId.getEntityId(), voterList, memberList); } - @Path("/polls/{pollId}/voterLists/{voterListId}/lists") - @GET - public List<VoterListBean> getVoterLists(@Context VoterListService voterListService, - @PathParam("pollId") PollenEntityId<Poll> pollId, - @PathParam("voterListId") PollenEntityId<VoterList> voterListId) { + @Path("/polls/{pollId}/voterLists") + @PUT + public void saveVoters(@Context VoterListService voterListService, + @PathParam("pollId") PollenEntityId<Poll> pollId, + VoterListSaveBean voterListSaveBean) throws InvalidFormException { + List<String> listIds = Lists.newLinkedList(); + for (VoterListBean list : voterListSaveBean.getListsToDelete()) { + listIds.add(list.getEntityId()); + } - return voterListService.getVoterLists(pollId.getEntityId(), voterListId.getEntityId()); + List<String> memberIds = Lists.newLinkedList(); + for (VoterListMemberBean member : voterListSaveBean.getMembersToDelete()) { + memberIds.add(member.getEntityId()); + } + voterListService.saveVoters(pollId.getEntityId(), + Lists.newArrayList(voterListSaveBean.getListsToSave()), + Lists.newArrayList(voterListSaveBean.getMembersToSave()), + listIds, + memberIds); } @Path("/polls/{pollId}/voterLists/{voterListId}") @@ -82,20 +98,15 @@ public class VoterListApi { @PathParam("pollId") PollenEntityId<Poll> pollId, @PathParam("voterListId") PollenEntityId<VoterList> voterListId) { - return voterListService.getVoterList(pollId.getEntityId(), voterListId.getEntityId()); + if ("main".equals(voterListId.getReducedId())) { - } + return voterListService.getMainVoterList(pollId.getEntityId()); - @Path("/polls/{pollId}/voterLists") - @POST - public PollenEntityRef<VoterList> createVoterList(@Context VoterListService voterListService, - @PathParam("pollId") PollenEntityId<Poll> pollId, - VoterListBean voterList, - VoterListMemberBean... members) throws InvalidFormException { + } else { - List<VoterListMemberBean> memberList = Lists.newArrayList(members); + return voterListService.getVoterList(pollId.getEntityId(), voterListId.getEntityId()); - return voterListService.addVoterList(pollId.getEntityId(), voterList, memberList); + } } @@ -119,6 +130,16 @@ public class VoterListApi { } + @Path("/polls/{pollId}/voterLists/{voterListId}/lists") + @GET + public List<VoterListBean> getVoterLists(@Context VoterListService voterListService, + @PathParam("pollId") PollenEntityId<Poll> pollId, + @PathParam("voterListId") PollenEntityId<VoterList> voterListId) { + + return voterListService.getVoterLists(pollId.getEntityId(), voterListId.getEntityId()); + + } + @Path("/polls/{pollId}/voterLists/{voterListId}/members") @GET public Set<VoterListMemberBean> getMembers(@Context VoterListService voterListService, @@ -129,6 +150,16 @@ public class VoterListApi { } + @Path("/polls/{pollId}/voterLists/{voterListId}/members") + @POST + public VoterListMemberBean addMember(@Context VoterListService voterListService, + @PathParam("pollId") PollenEntityId<Poll> pollId, + VoterListMemberBean member) throws InvalidFormException { + + return voterListService.addVoterListMember(pollId.getEntityId(), member); + + } + @Path("/polls/{pollId}/voterLists/{voterListId}/members/{memberId}") @GET public VoterListMemberBean getMember(@Context VoterListService voterListService, @@ -140,16 +171,6 @@ public class VoterListApi { } - @Path("/polls/{pollId}/voterLists/{voterListId}/members") - @POST - public VoterListMemberBean addMember(@Context VoterListService voterListService, - @PathParam("pollId") PollenEntityId<Poll> pollId, - VoterListMemberBean member) throws InvalidFormException { - - return voterListService.addVoterListMember(pollId.getEntityId(), member); - - } - @Path("/polls/{pollId}/voterLists/{voterListId}/members/{memberId}") @POST @PUT public VoterListMemberBean editMember(@Context VoterListService voterListService, @@ -171,28 +192,6 @@ public class VoterListApi { } - @Path("/polls/{pollId}/voterLists/save") - @POST - public void saveVoters(@Context VoterListService voterListService, - @PathParam("pollId") PollenEntityId<Poll> pollId, - VoterListSaveBean voterListSaveBean) throws InvalidFormException { - List<String> listIds = Lists.newLinkedList(); - for (VoterListBean list : voterListSaveBean.getListsToDelete()) { - listIds.add(list.getEntityId()); - } - - List<String> memberIds = Lists.newLinkedList(); - for (VoterListMemberBean member : voterListSaveBean.getMembersToDelete()) { - memberIds.add(member.getEntityId()); - } - - voterListService.saveVoters(pollId.getEntityId(), - Lists.newArrayList(voterListSaveBean.getListsToSave()), - Lists.newArrayList(voterListSaveBean.getMembersToSave()), - listIds, - memberIds); - } - @Path("/polls/{pollId}/voterLists/{voterListId}/resend") @GET public int resendInvitationVoterList(@Context VoterListService voterListService, diff --git a/pollen-ui-riot-js/src/main/web/js/PollService.js b/pollen-ui-riot-js/src/main/web/js/PollService.js index 4d087f46..41d79b40 100644 --- a/pollen-ui-riot-js/src/main/web/js/PollService.js +++ b/pollen-ui-riot-js/src/main/web/js/PollService.js @@ -32,7 +32,7 @@ class PollService extends FetchService { } empty(choiceType) { - let url = this._getUrlPrefix() + "/new"; + let url = this._getUrlPrefix("new"); return this.get(url, {choiceType: choiceType}); } @@ -60,32 +60,28 @@ class PollService extends FetchService { return this.post(url, poll2, {permission: poll.permission}); } - createdPolls(pagination, search) { + _getPolls(pagination, use, search) { let params = Object.assign({}, pagination); params.search = search || ""; - let url = this._getUrlPrefix() + "/created"; + params.use = use; + let url = this._getUrlPrefix(); return this.get(url, params); } + createdPolls(pagination, search) { + return this._getPolls(pagination, "created", search); + } + invitedPolls(pagination, search) { - let params = Object.assign({}, pagination); - params.search = search || ""; - let url = this._getUrlPrefix() + "/invited"; - return this.get(url, params); + return this._getPolls(pagination, "invited", search); } participatedPolls(pagination, search) { - let params = Object.assign({}, pagination); - params.search = search || ""; - let url = this._getUrlPrefix() + "/participated"; - return this.get(url, params); + return this._getPolls(pagination, "participated", search); } polls(pagination, search) { - let params = Object.assign({}, pagination); - params.search = search || ""; - let url = this._getUrlPrefix(); - return this.get(url, params); + return this._getPolls(pagination, "", search); } deletePoll(pollId, permission) { diff --git a/pollen-ui-riot-js/src/main/web/js/VoteService.js b/pollen-ui-riot-js/src/main/web/js/VoteService.js index dee0fdf7..05b155d7 100644 --- a/pollen-ui-riot-js/src/main/web/js/VoteService.js +++ b/pollen-ui-riot-js/src/main/web/js/VoteService.js @@ -46,7 +46,7 @@ class VoteService extends FetchService { } getNewVote(pollId, permission) { - let url = this._getUrlPrefix(pollId) + "/new"; + let url = this._getUrlPrefix(pollId, "new"); return this.get(url, {permission: permission}); } diff --git a/pollen-ui-riot-js/src/main/web/js/VoterListService.js b/pollen-ui-riot-js/src/main/web/js/VoterListService.js index 173f4743..b36895a1 100644 --- a/pollen-ui-riot-js/src/main/web/js/VoterListService.js +++ b/pollen-ui-riot-js/src/main/web/js/VoterListService.js @@ -82,7 +82,7 @@ class VoterListService extends FetchService { this.pollForm = pollForm; let mainVoterListPromise = Promise.resolve(); if (this.pollForm.model && this.pollForm.model.id) { - let url = this._getUrlPrefix(pollForm.model.id) + "/main"; + let url = this._getUrlPrefix(pollForm.model.id, "main"); mainVoterListPromise = this.get(url, {permission: pollForm.model.permission}); } mainVoterListPromise = mainVoterListPromise.then(list => { @@ -280,8 +280,8 @@ class VoterListService extends FetchService { } save() { - let url = this._getUrlPrefix(this.pollForm.model.id) + "/save"; - return this.post(url, + let url = this._getUrlPrefix(this.pollForm.model.id); + return this.put(url, { listsToSave: this.getVoterLists(), membersToSave: this.getVoterListMembers(), -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.