This is an automated email from the git hooks/post-receive script. New commit to branch feature/april in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit 50b45ff82f498fb34420e3258a1ea8629a9fa139 Author: jcouteau <couteau@codelutin.com> Date: Tue Oct 2 10:59:42 2018 +0200 refs #221 - Vote associatif - ChoiceService should be ok --- .../pollen/services/service/ChoiceService.java | 83 +++++++++++----------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java index d3a89399..180ac988 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java @@ -27,9 +27,9 @@ import org.chorem.pollen.persistence.entity.Choice; import org.chorem.pollen.persistence.entity.ChoiceImpl; import org.chorem.pollen.persistence.entity.ChoiceTopiaDao; import org.chorem.pollen.persistence.entity.ChoiceType; -import org.chorem.pollen.persistence.entity.Poll; import org.chorem.pollen.persistence.entity.PollenPrincipal; import org.chorem.pollen.persistence.entity.PollenResource; +import org.chorem.pollen.persistence.entity.Question; import org.chorem.pollen.services.bean.ChoiceBean; import org.chorem.pollen.services.bean.PollenEntityRef; import org.chorem.pollen.services.bean.ReportResumeBean; @@ -93,56 +93,56 @@ public class ChoiceService extends PollenServiceSupport { return entity; } - public List<ChoiceBean> getChoices(String pollId) { + public List<ChoiceBean> getChoices(String questionId) { checkIsConnectedRequired(); - checkNotNull(pollId); + checkNotNull(questionId); - Poll poll = getPollService().getPoll0(pollId); - checkPermission(PollenPermissions.read(poll)); + Question question = getQuestionService().getQuestion0(questionId); + checkPermission(PollenPermissions.read(question)); - List<Choice> choices = getChoiceDao().findAll(poll); + List<Choice> choices = getChoiceDao().findAll(question); return toBeanList(choices, this::toChoiceBean); } - public ChoiceBean getChoice(String pollId, String choiceId) { + public ChoiceBean getChoice(String questionId, String choiceId) { checkIsConnectedRequired(); - checkNotNull(pollId); + checkNotNull(questionId); checkNotNull(choiceId); - Poll poll = getPollService().getPoll0(pollId); - checkPermission(PollenPermissions.read(poll)); + Question question = getQuestionService().getQuestion0(questionId); + checkPermission(PollenPermissions.read(question)); - Choice choice = getChoice(poll, choiceId); + Choice choice = getChoice(question, choiceId); return toChoiceBean(choice); } - public PollenEntityRef<Choice> addChoice(String pollId, ChoiceBean choice) throws InvalidFormException { + public PollenEntityRef<Choice> addChoice(String questionId, ChoiceBean choice) throws InvalidFormException { checkIsConnectedRequired(); - checkNotNull(pollId); + checkNotNull(questionId); checkNotNull(choice); checkIsNotPersisted(choice); // FIXME 01/06/2018 SBavencoff Evite les modifications concurantes en BD du sondage - synchronized (getLock(pollId)) { + synchronized (getLock(questionId)) { - Poll poll = getPollService().getPoll0(pollId); - checkPermission(PollenPermissions.addChoice(poll)); + Question question = getQuestionService().getQuestion0(questionId); + checkPermission(PollenPermissions.addChoice(question)); - List<Choice> existingChoices = getChoiceDao().findAll(poll); + List<Choice> existingChoices = getChoiceDao().findAll(question); ErrorMap errorMap = checkChoice(existingChoices, choice); errorMap.failIfNotEmpty(); - Choice result = saveChoice(poll, choice); + Choice result = saveChoice(question, choice); commit(); - getNotificationService().onChoiceAdded(poll, result); - getFeedService().onChoiceAdded(poll, result); + getNotificationService().onChoiceAdded(question, result); + getFeedService().onChoiceAdded(question, result); return PollenEntityRef.of(result); @@ -151,41 +151,41 @@ public class ChoiceService extends PollenServiceSupport { } - public ChoiceBean editChoice(String pollId, ChoiceBean choice) throws InvalidFormException { + public ChoiceBean editChoice(String questionId, ChoiceBean choice) throws InvalidFormException { checkIsConnectedRequired(); checkNotNull(choice); checkIsPersisted(choice); - Poll poll = getPollService().getPoll0(pollId); - Choice choiceBd = getChoice(poll, choice.getEntityId()); + Question question = getQuestionService().getQuestion0(questionId); + Choice choiceBd = getChoice(question, choice.getEntityId()); checkPermission(PollenPermissions.edit(choiceBd)); - List<Choice> existingChoices = getChoiceDao().findAll(poll); + List<Choice> existingChoices = getChoiceDao().findAll(question); ErrorMap errorMap = checkChoice(existingChoices, choice); errorMap.failIfNotEmpty(); - Choice result = saveChoice(poll, choice); + Choice result = saveChoice(question, choice); commit(); - getNotificationService().onChoiceEdited(poll, result); + getNotificationService().onChoiceEdited(question, result); return toChoiceBean(result); } - public void deleteChoice(String pollId, String choiceId) throws InvalidFormException { + public void deleteChoice(String questionId, String choiceId) throws InvalidFormException { checkIsConnectedRequired(); - checkNotNull(pollId); + checkNotNull(questionId); checkNotNull(choiceId); - Poll poll = getPollService().getPoll0(pollId); - Choice choice = getChoice(poll, choiceId); + Question question = getQuestionService().getQuestion0(questionId); + Choice choice = getChoice(question, choiceId); checkPermission(PollenPermissions.delete(choice)); - List<Choice> existingChoices = getChoiceDao().findAll(poll); + List<Choice> existingChoices = getChoiceDao().findAll(question); if (existingChoices.size() == 1) { // can't delete this choice @@ -198,18 +198,18 @@ public class ChoiceService extends PollenServiceSupport { getChoiceDao().delete(choice); commit(); - getNotificationService().onChoiceDeleted(poll, choice); + getNotificationService().onChoiceDeleted(question, choice); } - protected Choice getChoice(Poll poll, String choiceId) { + protected Choice getChoice(Question question, String choiceId) { Choice result = getChoiceDao().forTopiaIdEquals(choiceId).findUnique(); - if (!poll.equals(result.getPoll())) { + if (!question.equals(result.getQuestion())) { - throw new InvalidEntityLinkException(Choice.PROPERTY_POLL, result, poll); + throw new InvalidEntityLinkException(Choice.PROPERTY_QUESTION, result, question); } @@ -217,7 +217,7 @@ public class ChoiceService extends PollenServiceSupport { } - protected Choice saveChoice(Poll poll, ChoiceBean choice) { + protected Choice saveChoice(Question question, ChoiceBean choice) { ChoiceTopiaDao choiceDao = getChoiceDao(); @@ -228,7 +228,7 @@ public class ChoiceService extends PollenServiceSupport { // get existing choice - toSave = getChoice(poll, choice.getEntityId()); + toSave = getChoice(question, choice.getEntityId()); if (toSave.getChoiceType() == ChoiceType.RESOURCE) { // check if new resource then delete old resource @@ -258,8 +258,9 @@ public class ChoiceService extends PollenServiceSupport { // principal.setEmail(creator.getEmail()); // } + //FIXME JC181002 - Useless setCreator, overriden later on toSave.setCreator(principal); - toSave.setPoll(poll); + toSave.setQuestion(question); } @@ -273,7 +274,7 @@ public class ChoiceService extends PollenServiceSupport { } toSave.setDescription(choice.getDescription()); - toSave.setCreator(poll.getCreator()); + toSave.setCreator(question.getPoll().getCreator()); return toSave; @@ -376,8 +377,8 @@ public class ChoiceService extends PollenServiceSupport { } - public long getChoiceCount(Poll poll) { + public long getChoiceCount(Question question) { checkIsConnectedRequired(); - return getChoiceDao().forPollEquals(poll).count(); + return getChoiceDao().forQuestionEquals(question).count(); } } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.