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 c76e422d6e597b384974b482e15af6f656d5277f Author: jcouteau <couteau@codelutin.com> Date: Tue Oct 2 15:24:24 2018 +0200 refs #221 - Vote associatif - Init QuestionService and QuestionBean --- .../pollen/persistence/entity/PollTopiaDao.java | 1 + .../org/chorem/pollen/services/bean/PollBean.java | 101 ++--------- .../chorem/pollen/services/bean/QuestionBean.java | 201 +++++++++++++++++++++ .../services/service/PollenServiceSupport.java | 30 +-- .../pollen/services/service/QuestionService.java | 151 ++++++++++++++++ 5 files changed, 380 insertions(+), 104 deletions(-) diff --git a/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollTopiaDao.java b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollTopiaDao.java index 05d64d45..72c0a479 100644 --- a/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollTopiaDao.java +++ b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/PollTopiaDao.java @@ -228,6 +228,7 @@ public class PollTopiaDao extends AbstractPollTopiaDao<Poll> { .collect(Collectors.toList()); } + //TODO JC181002 - Per question ? public boolean setFlagNotificationMaxVoterSend(Poll poll) { int nbModif = topiaJpaSupport.execute("UPDATE " + Poll.class.getCanonicalName() + 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 6b8960d1..dc8fd2b5 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 @@ -30,6 +30,7 @@ import org.chorem.pollen.persistence.entity.ResultVisibility; import org.chorem.pollen.persistence.entity.VoteVisibility; import org.chorem.pollen.votecounting.model.VoteCountingConfig; +import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Objects; @@ -74,22 +75,14 @@ public class PollBean extends PollenBean<Poll> { protected Date createDate; - protected Date beginChoiceDate; - - protected Date endChoiceDate; - protected Date beginDate; protected Date endDate; - protected boolean choiceAddAllowed; - protected boolean anonymousVoteAllowed; protected boolean continuousResults; - protected int voteCountingType; - protected PollType pollType; protected VoteVisibility voteVisibility; @@ -112,8 +105,6 @@ public class PollBean extends PollenBean<Poll> { protected long commentCount; - protected Set<String> participants; - protected Set<String> invalidEmails; protected long voteCount; @@ -126,10 +117,6 @@ public class PollBean extends PollenBean<Poll> { protected PollStatus status; - protected ChoiceType choiceType; - - protected boolean withMe; - protected int notifyMeHoursBeforePollEnds; protected boolean voteNotification; @@ -148,10 +135,10 @@ public class PollBean extends PollenBean<Poll> { protected String creatorAvatar; - protected VoteCountingConfig voteCountingConfig; - protected List<String> emailAddressSuffixes; + protected List<QuestionBean> questions; + public String getPermission() { return permission; } @@ -192,22 +179,6 @@ public class PollBean extends PollenBean<Poll> { this.description = description; } - public Date getBeginChoiceDate() { - return beginChoiceDate; - } - - public void setBeginChoiceDate(Date beginChoiceDate) { - this.beginChoiceDate = beginChoiceDate; - } - - public Date getEndChoiceDate() { - return endChoiceDate; - } - - public void setEndChoiceDate(Date endChoiceDate) { - this.endChoiceDate = endChoiceDate; - } - public Date getBeginDate() { return beginDate; } @@ -224,14 +195,6 @@ public class PollBean extends PollenBean<Poll> { this.endDate = endDate; } - public boolean isChoiceAddAllowed() { - return choiceAddAllowed; - } - - public void setChoiceAddAllowed(boolean choiceAddAllowed) { - this.choiceAddAllowed = choiceAddAllowed; - } - public boolean isAnonymousVoteAllowed() { return anonymousVoteAllowed; } @@ -248,14 +211,6 @@ public class PollBean extends PollenBean<Poll> { this.continuousResults = continuousResults; } - public int getVoteCountingType() { - return voteCountingType; - } - - public void setVoteCountingType(int voteCountingType) { - this.voteCountingType = voteCountingType; - } - public PollType getPollType() { return pollType; } @@ -344,17 +299,6 @@ public class PollBean extends PollenBean<Poll> { this.commentCount = commentCount; } - public boolean withParticipants() { - return CollectionUtils.isNotEmpty(participants); - } - public Set<String> getParticipants() { - return participants; - } - - public void setParticipants(Set<String> participants) { - this.participants = participants; - } - public void setVoteCount(long voteCount) { this.voteCount = voteCount; } @@ -379,14 +323,6 @@ public class PollBean extends PollenBean<Poll> { this.createDate = createDate; } - public ChoiceType getChoiceType() { - return choiceType; - } - - public void setChoiceType(ChoiceType choiceType) { - this.choiceType = choiceType; - } - public long getChoiceCount() { return choiceCount; } @@ -395,14 +331,6 @@ public class PollBean extends PollenBean<Poll> { this.choiceCount = choiceCount; } - public boolean isWithMe() { - return withMe; - } - - public void setWithMe(boolean withMe) { - this.withMe = withMe; - } - public int getNotifyMeHoursBeforePollEnds() { return notifyMeHoursBeforePollEnds; } @@ -491,14 +419,6 @@ public class PollBean extends PollenBean<Poll> { this.creatorAvatar = creatorAvatar; } - public VoteCountingConfig getVoteCountingConfig() { - return voteCountingConfig; - } - - public void setVoteCountingConfig(VoteCountingConfig voteCountingConfig) { - this.voteCountingConfig = voteCountingConfig; - } - public Set<String> getInvalidEmails() { return invalidEmails; } @@ -514,4 +434,19 @@ public class PollBean extends PollenBean<Poll> { public void setEmailAddressSuffixes(List<String> emailAddressSuffixes) { this.emailAddressSuffixes = emailAddressSuffixes; } + + public List<QuestionBean> getQuestions() { + return questions; + } + + public void setQuestions(List<QuestionBean> questions) { + this.questions = questions; + } + + public void addQuestion(QuestionBean question) { + if (null == this.questions){ + this.questions = new ArrayList<>(); + } + this.questions.add(question); + } } diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/QuestionBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/QuestionBean.java new file mode 100644 index 00000000..df9df22a --- /dev/null +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/QuestionBean.java @@ -0,0 +1,201 @@ +package org.chorem.pollen.services.bean; + +import org.apache.commons.collections4.CollectionUtils; +import org.chorem.pollen.persistence.entity.CommentVisibility; +import org.chorem.pollen.persistence.entity.Question; +import org.chorem.pollen.persistence.entity.ResultVisibility; +import org.chorem.pollen.persistence.entity.VoteVisibility; +import org.chorem.pollen.votecounting.model.VoteCountingConfig; + +import java.util.Date; +import java.util.Set; + +public class QuestionBean extends PollenBean<Question>{ + + protected String permission; + + protected Date createDate; + + protected String title; + + protected String description; + + protected Date beginChoiceDate; + + protected Date endChoiceDate; + + protected boolean choiceAddAllowed; + + protected int voteCountingType; + + protected VoteCountingConfig voteCountingConfig; + + protected String poll; + + protected Set<String> participants; + + protected VoteVisibility voteVisibility; + + protected CommentVisibility commentVisibility; + + protected ResultVisibility resultVisibility; + + protected boolean resultIsVisible; + + protected boolean commentIsVisible; + + protected boolean voteIsVisible; + + protected boolean participantsIsVisible; + + public QuestionBean() { + super(Question.class); + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Date getBeginChoiceDate() { + return beginChoiceDate; + } + + public void setBeginChoiceDate(Date beginChoiceDate) { + this.beginChoiceDate = beginChoiceDate; + } + + public Date getEndChoiceDate() { + return endChoiceDate; + } + + public void setEndChoiceDate(Date endChoiceDate) { + this.endChoiceDate = endChoiceDate; + } + + public boolean isChoiceAddAllowed() { + return choiceAddAllowed; + } + + public void setChoiceAddAllowed(boolean choiceAddAllowed) { + this.choiceAddAllowed = choiceAddAllowed; + } + + public int getVoteCountingType() { + return voteCountingType; + } + + public void setVoteCountingType(int voteCountingType) { + this.voteCountingType = voteCountingType; + } + + public VoteCountingConfig getVoteCountingConfig() { + return voteCountingConfig; + } + + public void setVoteCountingConfig(VoteCountingConfig voteCountingConfig) { + this.voteCountingConfig = voteCountingConfig; + } + + public String getPoll() { + return poll; + } + + public void setPoll(String poll) { + this.poll = poll; + } + + public boolean withParticipants() { + return CollectionUtils.isNotEmpty(participants); + } + public Set<String> getParticipants() { + return participants; + } + + public void setParticipants(Set<String> participants) { + this.participants = participants; + } + + public String getPermission() { + return permission; + } + + public void setPermission(String permission) { + this.permission = permission; + } + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + public VoteVisibility getVoteVisibility() { + return voteVisibility; + } + + public void setVoteVisibility(VoteVisibility voteVisibility) { + this.voteVisibility = voteVisibility; + } + + public CommentVisibility getCommentVisibility() { + return commentVisibility; + } + + public void setCommentVisibility(CommentVisibility commentVisibility) { + this.commentVisibility = commentVisibility; + } + + public ResultVisibility getResultVisibility() { + return resultVisibility; + } + + public void setResultVisibility(ResultVisibility resultVisibility) { + this.resultVisibility = resultVisibility; + } + + public boolean isResultIsVisible() { + return resultIsVisible; + } + + public void setResultIsVisible(boolean resultIsVisible) { + this.resultIsVisible = resultIsVisible; + } + + public boolean isCommentIsVisible() { + return commentIsVisible; + } + + public void setCommentIsVisible(boolean commentIsVisible) { + this.commentIsVisible = commentIsVisible; + } + + public boolean isVoteIsVisible() { + return voteIsVisible; + } + + public void setVoteIsVisible(boolean voteIsVisible) { + this.voteIsVisible = voteIsVisible; + } + + public boolean isParticipantsIsVisible() { + return participantsIsVisible; + } + + public void setParticipantsIsVisible(boolean participantsIsVisible) { + this.participantsIsVisible = participantsIsVisible; + } +} diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java index 6eac8118..37effb9c 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java @@ -29,27 +29,7 @@ import com.google.common.collect.Multimap; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.chorem.pollen.persistence.PollenPersistenceContext; -import org.chorem.pollen.persistence.entity.ChildFavoriteListTopiaDao; -import org.chorem.pollen.persistence.entity.ChoiceTopiaDao; -import org.chorem.pollen.persistence.entity.CommentTopiaDao; -import org.chorem.pollen.persistence.entity.EmailToResendTopiaDao; -import org.chorem.pollen.persistence.entity.FavoriteListMemberTopiaDao; -import org.chorem.pollen.persistence.entity.FavoriteListTopiaDao; -import org.chorem.pollen.persistence.entity.LoginProviderTopiaDao; -import org.chorem.pollen.persistence.entity.Poll; -import org.chorem.pollen.persistence.entity.PollTopiaDao; -import org.chorem.pollen.persistence.entity.PollenPrincipalTopiaDao; -import org.chorem.pollen.persistence.entity.PollenResourceTopiaDao; -import org.chorem.pollen.persistence.entity.PollenUser; -import org.chorem.pollen.persistence.entity.PollenUserEmailAddressTopiaDao; -import org.chorem.pollen.persistence.entity.PollenUserTopiaDao; -import org.chorem.pollen.persistence.entity.ReportTopiaDao; -import org.chorem.pollen.persistence.entity.SessionTokenTopiaDao; -import org.chorem.pollen.persistence.entity.UserCredentialTopiaDao; -import org.chorem.pollen.persistence.entity.VoteToChoiceTopiaDao; -import org.chorem.pollen.persistence.entity.VoteTopiaDao; -import org.chorem.pollen.persistence.entity.VoterListMemberTopiaDao; -import org.chorem.pollen.persistence.entity.VoterListTopiaDao; +import org.chorem.pollen.persistence.entity.*; import org.chorem.pollen.services.PollenService; import org.chorem.pollen.services.PollenServiceContext; import org.chorem.pollen.services.PollenUIContext; @@ -166,6 +146,10 @@ public abstract class PollenServiceSupport implements PollenService { return newService(PollService.class); } + protected QuestionService getQuestionService() { + return newService(QuestionService.class); + } + protected SecurityService getSecurityService() { return newService(SecurityService.class); } @@ -232,6 +216,10 @@ public abstract class PollenServiceSupport implements PollenService { return getPersistenceContext().getPollDao(); } + protected QuestionTopiaDao getQuestionDao() { + return getPersistenceContext().getQuestionDao(); + } + protected PollenPrincipalTopiaDao getPollenPrincipalDao() { return getPersistenceContext().getPollenPrincipalDao(); } 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 new file mode 100644 index 00000000..868dd23a --- /dev/null +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/QuestionService.java @@ -0,0 +1,151 @@ +package org.chorem.pollen.services.service; + +import com.google.common.collect.Lists; +import org.apache.commons.lang3.StringUtils; +import org.chorem.pollen.persistence.entity.Poll; +import org.chorem.pollen.persistence.entity.PollenPrincipal; +import org.chorem.pollen.persistence.entity.Polls; +import org.chorem.pollen.persistence.entity.Question; +import org.chorem.pollen.services.bean.PollBean; +import org.chorem.pollen.services.bean.QuestionBean; +import org.chorem.pollen.services.bean.ReportResumeBean; +import org.chorem.pollen.services.service.security.PollenPermissions; + +import java.util.Date; +import java.util.List; + +public class QuestionService extends PollenServiceSupport { + + public QuestionBean toQuestionBean(Question entity) { + QuestionBean bean = new QuestionBean(); + + Poll pollEntity = entity.getPoll(); + + bean.setEntityId(entity.getTopiaId()); + + PollenPrincipal creator = pollEntity.getCreator(); + + if (creator == null || creator.getPermission() == null) { + + bean.setPermission(null); + + } else { + + bean.setPermission(creator.getPermission().getToken()); + + } + + bean.setTitle(entity.getTitle()); + bean.setDescription(entity.getDescription()); + bean.setCreateDate(entity.getTopiaCreateDate()); + bean.setBeginDate(entity.getBeginDate()); + bean.setEndDate(entity.getEndDate()); + bean.setAnonymousVoteAllowed(entity.isAnonymousVoteAllowed()); + bean.setContinuousResults(entity.isContinuousResults()); + bean.setPollType(entity.getPollType()); + bean.setVoteVisibility(entity.getVoteVisibility()); + bean.setCommentVisibility(entity.getCommentVisibility()); + bean.setResultVisibility(entity.getResultVisibility()); + bean.setNotifyMeHoursBeforePollEnds(entity.getNotifyMeHoursBeforePollEnds()); + bean.setVoteCountingConfig(getVoteCountingService().getVoteCountingConfig(entity)); + if (StringUtils.isNotBlank(emailAddressSuffixes)) { + bean.setEmailAddressSuffixes(Lists.newArrayList(emailAddressSuffixes.split(PollService.EMAIL_SUFFIX_SEPARATOR))); + } + + Date now = getNow(); + if (Polls.isFinished(entity, now)) { + bean.setStatus(PollBean.PollStatus.CLOSED); + bean.setClosed(true); + } else { + 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); + } + } + } + + if (isNotPermitted(PollenPermissions.edit(entity))) { + bean.setPermission(null); + + } else { + ReportResumeBean report = getReportService().getReport(entity.getTopiaId()); + bean.setReport(report); + } + + boolean commentIsVisible = isPermitted(PollenPermissions.readComments(entity)); + bean.setCommentIsVisible(commentIsVisible); + + bean.setVoteIsVisible(isPermitted(PollenPermissions.readVotes(entity))); + + boolean resultIsVisible = isPermitted(PollenPermissions.readResult(entity)); + + bean.setResultIsVisible(resultIsVisible); + + boolean canReadParticipants = isPermitted(PollenPermissions.readParticipants(entity)); + bean.setParticipantsIsVisible(canReadParticipants); + + boolean canVote = isPermitted(PollenPermissions.addVote(entity)); + + bean.setCanVote(canVote); + if (entity.isPersisted()) { + if (commentIsVisible) { + long commentCount = getCommentService().getCommentCount(entity.getTopiaId()); + bean.setCommentCount(commentCount); + } + + long voteCount = getVoteService().getVoteCount(entity); + bean.setVoteCount(voteCount); + if (Polls.isPollRestricted(entity)) { + long participantCount = getVoterListService().getVoterListMemberCount(entity); + bean.setParticipantCount(participantCount); + long participantInvitedCount = getVoterListService().getVoterListMemberInvitedCount(entity); + bean.setParticipantInvitedCount(participantInvitedCount); + } + long choiceCount = getChoiceService().getChoiceCount(entity); + bean.setChoiceCount(choiceCount); + } + + bean.setGtuValidated(getGtuService().isGtuValidated(entity)); + bean.setMaxVoters(getMaxVoters(entity)); + + if (creator.getPollenUser() != null && creator.getPollenUser().getAvatar() != null) { + bean.setCreatorAvatar(getPollenResourceService().getReduceIdByTopiaId( + creator.getPollenUser().getAvatar().getTopiaId())); + } + + return bean; + } + + public List<Question> getQuestionsforPoll(Poll poll) { + checkIsConnectedRequired(); + + checkNotNull(poll); + + return getQuestionDao().forPollEquals(poll).findAll(); + + } + + public QuestionBean getQuestion(String questionId) { + checkIsConnectedRequired(); + + checkNotNull(questionId); + + Question question = getQuestion0(questionId); + checkPermission(PollenPermissions.read(question)); + + return toQuestionBean(question); + + } + + protected Question getQuestion0(String questionId) { + + return getQuestionDao().forTopiaIdEquals(questionId).findUnique(); + + } +} -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.