/** * {@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); }
/** * {@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; }
/** * {@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; }
/** * 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)); } }
/** * {@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; }
/** * {@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(); }