01/03: add VoteCountingTypeApi
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository pollen. See http://git.chorem.org/pollen.git commit 03df50919f584a82a9303832cbd38bfce2698db1 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Thu Jul 3 14:34:03 2014 +0200 add VoteCountingTypeApi --- .../pollen/rest/api/v1/VoteCountingTypeApi.java | 23 ++++++++ pollen-rest-api/src/main/resources/mapping | 5 ++ .../pollen/services/bean/VoteCountingTypeBean.java | 68 ++++++++++++++++++++++ .../services/service/VoteCountingTypeService.java | 67 +++++++++++++++++++++ 4 files changed, 163 insertions(+) diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingTypeApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingTypeApi.java new file mode 100644 index 0000000..1fcd5ad --- /dev/null +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/VoteCountingTypeApi.java @@ -0,0 +1,23 @@ +package org.chorem.pollen.rest.api.v1; + +import org.chorem.pollen.services.bean.VoteCountingTypeBean; +import org.chorem.pollen.services.service.VoteCountingTypeService; +import org.debux.webmotion.server.WebMotionController; + +import java.util.List; + +/** + * Created on 03/07/14. + * + * @author garandel + * @since 2.0 + */ +public class VoteCountingTypeApi extends WebMotionController { + public List<VoteCountingTypeBean> getVoteCountingTypes(VoteCountingTypeService voteCountingTypeService) { + return voteCountingTypeService.getVoteCountingTypes(); + } + + public VoteCountingTypeBean getVoteCountingType(VoteCountingTypeService voteCountingTypeService, int id) { + return voteCountingTypeService.getVoteCountingType(id); + } +} diff --git a/pollen-rest-api/src/main/resources/mapping b/pollen-rest-api/src/main/resources/mapping index 4340a23..0c6b559 100644 --- a/pollen-rest-api/src/main/resources/mapping +++ b/pollen-rest-api/src/main/resources/mapping @@ -129,6 +129,11 @@ PUT /v1/users/{userId}?token={} PollenUserApi.validateUserEmai GET /v1/polls/{pollId}/results VoteCountingApi.getMainResult GET /v1/polls/{pollId}/groupResults VoteCountingApi.getGroupResult +# VoteCountingTypeApi + +GET /v1/voteCountingTypes VoteCountingTypeApi.getVoteCountingTypes +GET /v1/voteCountingTypes/{id} VoteCountingTypeApi.getVoteCountingType + # VoterListApi PUT /v1/polls/{pollId}/favoriteLists/{favoriteListId} VoterListApi.importFavoriteList diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteCountingTypeBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteCountingTypeBean.java new file mode 100644 index 0000000..8e86c07 --- /dev/null +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/VoteCountingTypeBean.java @@ -0,0 +1,68 @@ +package org.chorem.pollen.services.bean; + +import org.chorem.pollen.services.service.VoteCountingService; +import org.chorem.pollen.votecounting.VoteCounting; +import org.chorem.pollen.votecounting.VoteCountingFactory; +import org.chorem.pollen.votecounting.model.ChoiceToVoteRenderType; + +import java.util.Locale; + +/** + * Created on 03/07/14. + * + * @author agarandel + * @since 2.0 + */ +public class VoteCountingTypeBean { + + protected int id; + + protected String name; + + protected String helper; + + protected String shortHelper; + + protected ChoiceToVoteRenderType renderType; + + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getHelper() { + return helper; + } + + public void setHelper(String helper) { + this.helper = helper; + } + + public String getShortHelper() { + return shortHelper; + } + + public void setShortHelper(String shortHelper) { + this.shortHelper = shortHelper; + } + + public ChoiceToVoteRenderType getRenderType() { + return renderType; + } + + public void setRenderType(ChoiceToVoteRenderType renderType) { + this.renderType = renderType; + } +} diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingTypeService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingTypeService.java new file mode 100644 index 0000000..3bbd957 --- /dev/null +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/VoteCountingTypeService.java @@ -0,0 +1,67 @@ +package org.chorem.pollen.services.service; + +import org.chorem.pollen.services.bean.VoteCountingTypeBean; +import org.chorem.pollen.votecounting.VoteCounting; +import org.chorem.pollen.votecounting.VoteCountingFactory; +import org.chorem.pollen.votecounting.VoteCountingNotFound; +import org.chorem.pollen.votecounting.VoteCountingStrategy; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +/** + * Created on 03/07/14. + * + * @author agarandel + * @since 2.0 + */ +public class VoteCountingTypeService extends PollenServiceSupport { + + public List<VoteCountingTypeBean> getVoteCountingTypes() { + List<VoteCountingTypeBean> voteCountingTypes = new ArrayList<VoteCountingTypeBean>(); + + try { + int i = 1; + while ( i > 0 ) { + + voteCountingTypes.add(idToVoteCountingType(i)); + + ++i; + } + } + catch (VoteCountingNotFound e) { + if (voteCountingTypes.size() == 0) { + throw e; + } + } + + return voteCountingTypes; + } + + public VoteCountingTypeBean getVoteCountingType(int id) { + try { + return idToVoteCountingType(id); + } + catch (VoteCountingNotFound e) { + return null; + } + } + + protected VoteCountingTypeBean idToVoteCountingType(int id) throws VoteCountingNotFound { + VoteCountingFactory factory = serviceContext.getVoteCountingFactory(); + Locale l = serviceContext.getLocale(); + + VoteCountingTypeBean newVoteCountingType = new VoteCountingTypeBean(); + + VoteCounting voteCounting = factory.getVoteCounting(id); + + newVoteCountingType.setId(voteCounting.getId()); + newVoteCountingType.setName(voteCounting.getName(l)); + newVoteCountingType.setHelper(voteCounting.getHelp(l)); + newVoteCountingType.setShortHelper(voteCounting.getShortHelp(l)); + newVoteCountingType.setRenderType(voteCounting.getVoteValueEditorType()); + + return newVoteCountingType; + } +} -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm