/** * Set poll in topic. * * @param poll poll */ public void setPoll(Poll poll) { topic.setPoll(poll); }
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; }
/** * 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); } } }
/** * 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); }