/** * Creates data transfer object, that represents info about the poll. * * @param poll the poll */ public PollDto(Poll poll) { this.id = poll.getId(); this.totalVotesCount = poll.getTotalVotesCount(); for (PollItem option : poll.getPollItems()) { this.pollOptions.add(new PollOptionDto(option)); } }
/** * Add the poll options to this poll. * * @param options the poll option */ public void addPollOptions(PollItem... options) { addPollOptions(Arrays.asList(options)); }
/** * {@inheritDoc} */ @Override public boolean isValid(Poll poll, ConstraintValidatorContext context) { String pollTitle = poll.getTitle(); List<PollItem> pollItems = poll.getPollItems(); boolean isTitleFilled = StringUtils.isNotBlank(pollTitle); boolean isItemsFilled = !CollectionUtils.isEmpty(pollItems); // if (isItemsFilled && !isTitleFilled) { addConstraintViolatedErrorMessage(context); return false; } return true; }
public static Poll createDefaultVoting() { Topic topic = getDefaultTopic(); Poll poll = new Poll("New voting"); List<PollItem> pollItems = new ArrayList<>(); pollItems.add(new PollItem("item1")); pollItems.add(new PollItem("item2")); pollItems.add(new PollItem("item3")); poll.setPollItems(pollItems); topic.setPoll(poll); poll.setTopic(topic); persist(topic); return poll; }
/** * {@inheritDoc} */ @Override @PreAuthorize("hasPermission(#pollId, 'POLL', 'GeneralPermission.WRITE')") public Poll vote(Long pollId, List<Long> selectedOptionsIds) { Poll poll = getDao().get(pollId); if (poll.isActive()) { prohibitRevote(poll); for (PollItem option : poll.getPollItems()) { if (selectedOptionsIds.contains(option.getId())) { option.increaseVotesCount(); pollOptionDao.saveOrUpdate(option); } } } return poll; }
/** * Create dto from {@link TopicDraft} * * @param topicDraft draft topic for conversion */ public TopicDto(TopicDraft topicDraft) { this.topic = new Topic(topicDraft.getTopicStarter(), topicDraft.getTitle()); this.setBodyText(topicDraft.getContent()); String pollTitle = topicDraft.getPollTitle(); String pollItemsValue = topicDraft.getPollItemsValue(); Poll poll = new Poll(); if (pollTitle != null || pollItemsValue != null) { poll.setTitle(pollTitle); poll.setPollItemsValue(pollItemsValue); } this.topic.setPoll(poll); }
/** * {@inheritDoc} */ @Override public void mergePollItems(Poll poll, List<PollItem> newItems) { List<PollItem> existing = poll.getPollItems(); ListIterator<PollItem> updated = newItems.listIterator(); while (updated.hasNext()) { PollItem item = updated.next(); for (PollItem old : existing) { if (item.getName().equals(old.getName())) { updated.set(old); } } } existing.clear(); existing.addAll(newItems); }
/** * Creates a poll for the topic or updates an existing one. * On update all poll items with the same name remain unchanged, * except probably their position in list. Users, previously voted * for the deleted items can NOT vote again. * * @param poll poll data from UI form * @param persistentTopic topic from a database */ private void createPoll(Poll poll, Topic persistentTopic) { if (poll != null && poll.isHasPoll()) { if (persistentTopic.getPoll() == null) { persistentTopic.setPoll(poll); poll.setTopic(persistentTopic); pollService.createPoll(poll); } } }
/** * {@inheritDoc} * * @throws AccessDeniedException besides other reasons, always throws this when Code Review is edited because it * shouldn't be possible to edit it. More details on requirements can be found here * <a href="http://jtalks.org/display/jcommune/1.1+Larks">here</a>. */ @Override @PreAuthorize("(hasPermission(#topic.id, 'TOPIC', 'GeneralPermission.WRITE') and " + "hasPermission(#topic.branch.id, 'BRANCH', 'BranchPermission.EDIT_OWN_POSTS')) or " + "(not hasPermission(#topic.id, 'TOPIC', 'GeneralPermission.WRITE') and " + "hasPermission(#topic.branch.id, 'BRANCH', 'BranchPermission.EDIT_OTHERS_POSTS'))") public void updateTopic(Topic topic, Poll poll) { if (topic.isCodeReview()) { throw new AccessDeniedException("It is not allowed to edit Code Review!"); } Post post = topic.getFirstPost(); post.updateModificationDate(); if (poll != null && poll.getEndingDate() != null) { topic.getPoll().setEndingDate(poll.getEndingDate()); } dao.saveOrUpdate(topic); logger.debug("Topic id={} updated", topic.getId()); }
/** * Determines a existence the poll in the topic. * * @return <tt>true</tt> if the poll exists * <tt>false</tt> if the poll doesn't exist */ public boolean isHasPoll() { return StringUtils.isNotBlank(getTitle()) && !CollectionUtils.isEmpty(pollItems); }
/** * {@inheritDoc} */ @Override public void createPoll(Poll poll) { this.getDao().saveOrUpdate(poll); Closure1<PollItem> closure = closure(PollItem.class); of(pollOptionDao).saveOrUpdate(var(PollItem.class)); closure.each(poll.getPollItems()); securityService.createAclBuilder().grant(GeneralPermission.WRITE) .to(groupDao.getGroupByName(AdministrationGroup.USER.getName())) .on(poll).flush(); }
/** * {@inheritDoc} */ @Override public boolean isValid(Poll poll, ConstraintValidatorContext context) { String pollTitle = poll.getTitle(); List<PollItem> pollItems = poll.getPollItems(); boolean isTitleFilled = StringUtils.isNotBlank(pollTitle); boolean isItemsFilled = !CollectionUtils.isEmpty(pollItems); // if (isTitleFilled && !isItemsFilled) { addConstraintViolatedErrorMessage(context); return false; } return true; }
public static PollItem createDefaultVotingOption() { Poll voting = createDefaultVoting(); persist(voting); PollItem option = new PollItem("First voting option"); voting.addPollOptions(option); return option; }