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 9cae151e2e562ebbdac183644ffee6ce07643c08 Author: jcouteau <couteau@codelutin.com> Date: Wed May 13 09:02:37 2020 +0200 fixes #334 - How this feature could have been so badly tested --- .../org/chorem/pollen/rest/api/v1/PollApi.java | 3 +- .../pollen/services/service/PollService.java | 46 +++++++++++++++++----- .../pollen/services/service/QuestionService.java | 3 ++ .../src/main/web/tag/poll/Poll.tag.html | 6 +-- .../src/main/web/tag/poll/Summary.tag.html | 6 +-- .../src/main/web/tag/poll/Votes.tag.html | 2 +- 6 files changed, 48 insertions(+), 18 deletions(-) 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 4c64188b..3f975d32 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 @@ -25,6 +25,7 @@ import org.apache.commons.lang3.StringUtils; import org.chorem.pollen.persistence.entity.Choice; import org.chorem.pollen.persistence.entity.ChoiceType; import org.chorem.pollen.persistence.entity.Poll; +import org.chorem.pollen.persistence.entity.Question; import org.chorem.pollen.rest.api.beans.PollCreateBean; import org.chorem.pollen.services.bean.ChoiceBean; import org.chorem.pollen.services.bean.PaginationParameterBean; @@ -198,7 +199,7 @@ public class PollApi { @POST public PollenEntityRef<Choice> addChoice(@Context ChoiceService choiceService, @PathParam("pollId") PollenEntityId<Poll> pollId, - @PathParam("questionId") PollenEntityId<Poll> questionId, + @PathParam("questionId") PollenEntityId<Question> questionId, ChoiceBean choice) throws InvalidFormException { return choiceService.addChoice(pollId.getEntityId(), questionId.getEntityId(), choice); diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java index af67afe4..b029a27a 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java @@ -123,14 +123,12 @@ public class PollService extends PollenServiceSupport { bean.setClosed(false); bean.setStatus(PollBean.PollStatus.CREATED); - //FIXME JC181001 - ADDING_CHOICES toujours pertinent sur le Poll ? - if (PollBean.PollStatus.ADDING_CHOICES != bean.getStatus()) { - Date beginDate = entity.getBeginDate(); - Date endDate = entity.getEndDate(); - if (beginDate != null && now.after(beginDate) && (endDate == null || now.before(endDate))) { - bean.setStatus(PollBean.PollStatus.VOTING); - } + Date beginDate = entity.getBeginDate(); + Date endDate = entity.getEndDate(); + if (beginDate != null && now.after(beginDate) && (endDate == null || now.before(endDate))) { + bean.setStatus(PollBean.PollStatus.VOTING); } + } /* Questions and choices */ @@ -140,6 +138,31 @@ public class PollService extends PollenServiceSupport { bean.setQuestions(questions); } + /* Check adding choices */ + //XXX JC-200512 adding choice status should be on question instead of poll + Date beginAddChoiceDate = null; + Date endAddChoiceDate = null; + Boolean addChoiceEnabled = false; + for(QuestionBean question: bean.getQuestions()) { + addChoiceEnabled = addChoiceEnabled || question.isChoiceAddAllowed(); + if (question.getBeginChoiceDate() != null && (beginAddChoiceDate == null || question.getBeginChoiceDate().before(beginAddChoiceDate))) { + beginAddChoiceDate = question.getBeginChoiceDate(); + } + if (question.getEndChoiceDate() != null && (endAddChoiceDate == null || question.getEndChoiceDate().after(endAddChoiceDate))) { + endAddChoiceDate = question.getEndChoiceDate(); + } + } + + if (addChoiceEnabled && + ( + (beginAddChoiceDate == null && (endAddChoiceDate == null || now.before(endAddChoiceDate))) || + (beginAddChoiceDate != null && now.after(beginAddChoiceDate) && (endAddChoiceDate == null || now.before(endAddChoiceDate))) + ) + ){ + bean.setStatus(PollBean.PollStatus.ADDING_CHOICES); + } + + if (isNotPermitted(PollenPermissions.edit(entity))) { bean.setPermission(null); bean.setCreatorEmail(null); @@ -576,10 +599,13 @@ public class PollService extends PollenServiceSupport { QuestionService questionService = getQuestionService(); for (QuestionBean question : poll.getQuestions()) { - - question.setQuestionOrder(existingQuestions.size()); Question persistedQuestion = questionService.saveQuestion(toSave, question); - existingQuestions.add(persistedQuestion); + existingQuestions.remove(persistedQuestion); + } + + // the remaining questions have been deleted by the user and must be removed + if (CollectionUtils.isNotEmpty(existingQuestions)) { + getQuestionDao().deleteAll(existingQuestions); } } diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/QuestionService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/QuestionService.java index 1bfabe84..f72dbdd0 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/QuestionService.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/QuestionService.java @@ -67,6 +67,9 @@ public class QuestionService extends PollenServiceSupport { bean.setCreateDate(entity.getTopiaCreateDate()); bean.setVoteCountingType(entity.getVoteCountingType()); bean.setVoteCountingConfig(getVoteCountingService().getVoteCountingConfig(entity)); + bean.setChoiceAddAllowed(entity.isChoiceAddAllowed()); + bean.setEndChoiceDate(entity.getEndChoiceDate()); + bean.setBeginChoiceDate(entity.getBeginChoiceDate()); /* Choices */ ChoiceService choiceService = getChoiceService(); diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag.html index bad8d44a..1b4f44b9 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/Poll.tag.html @@ -84,16 +84,16 @@ <p if={poll.endDate}> {_t.dateTo} <span class="brand">{formatDate(poll.endDate)}</span></p> </div> - <div class="left-icon" if={poll.choiceAddAllowed}> + <div class="left-icon" if={poll.questions[0] && poll.questions[0].choiceAddAllowed}> <i class="fa fa-check-square" aria-hidden="true"></i> <p>{_t.dateAddChoices}</p> <p> {poll.endChoiceDate || poll.endDate ? _t.dateFrom : _t.dateFromNoEnd} <span class="brand">{formatDate(poll.beginChoiceDate ? poll.beginChoiceDate : poll.beginDate)}</span> </p> - <p if={poll.endChoiceDate || poll.endDate}> + <p if={poll.questions[0].endChoiceDate || poll.endDate}> {_t.dateTo} - <span class="brand">{formatDate(poll.endChoiceDate ? poll.endChoiceDate : poll.endDate)}</span> + <span class="brand">{formatDate(poll.questions[0].endChoiceDate ? poll.questions[0].endChoiceDate : poll.endDate)}</span> </p> </div> diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/Summary.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/Summary.tag.html index fee9f4e2..cd46a7f3 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/Summary.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/Summary.tag.html @@ -48,10 +48,10 @@ <div class="summary-part"> <h3>{_t.dates}</h3> - <div if={opts.form.model.choiceAddAllowed}> + <div if={opts.form.model.questions[0].choiceAddAllowed}> {_t.addingChoices} - <span if={opts.form.model.beginChoiceDate}>{_t.fromDate} <strong>{formatDate(opts.form.model.beginChoiceDate)}</strong></span> - <span if={opts.form.model.endChoiceDate}> {_t.toDate} <strong>{formatDate(opts.form.model.endChoiceDate)}</strong></span> + <span if={opts.form.model.questions[0].beginChoiceDate}>{_t.fromDate} <strong>{formatDate(opts.form.model.questions[0].beginChoiceDate)}</strong></span> + <span if={opts.form.model.questions[0].endChoiceDate}> {_t.toDate} <strong>{formatDate(opts.form.model.questions[0].endChoiceDate)}</strong></span> </div> <div> {_t.voting} diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/Votes.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/Votes.tag.html index d2cbb4cb..e60b7832 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/Votes.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/Votes.tag.html @@ -156,7 +156,7 @@ this.update(); this.refs.choice.submit(); - this.poll.addChoice(this.choiceToAdd).then(() => { + this.poll.addChoice(this.poll.questions[0].id, this.choiceToAdd).then(() => { this.addingChoice = false; this.choiceToAdd = this.poll.initChoice(this.choiceToAdd); this.refs.choice.updateChoice(); -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.