@Override
  protected void addStagedModels() throws Exception {
    PollsQuestion question = PollsTestUtil.addQuestion(stagingGroup.getGroupId());

    PollsChoice choice =
        PollsTestUtil.addChoice(stagingGroup.getGroupId(), question.getQuestionId());

    PollsTestUtil.addVote(
        stagingGroup.getGroupId(), question.getQuestionId(), choice.getChoiceId());
  }
  public PollsVote addVote(
      long userId, long questionId, long choiceId, ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Choice

    Date now = new Date();

    PollsChoice choice = pollsChoicePersistence.findByPrimaryKey(choiceId);

    if (choice.getQuestionId() != questionId) {
      throw new NoSuchQuestionException();
    }

    // Question

    PollsQuestion question = pollsQuestionPersistence.findByPrimaryKey(questionId);

    if (question.isExpired(serviceContext, now)) {
      throw new QuestionExpiredException();
    }

    question.setLastVoteDate(serviceContext.getCreateDate(now));

    pollsQuestionPersistence.update(question, false);

    // Vote

    PollsVote vote = pollsVotePersistence.fetchByQ_U(questionId, userId);

    if (vote != null) {
      throw new DuplicateVoteException();
    } else {
      User user = userPersistence.findByPrimaryKey(userId);

      long voteId = counterLocalService.increment();

      vote = pollsVotePersistence.create(voteId);

      vote.setCompanyId(user.getCompanyId());
      vote.setUserId(user.getUserId());
      vote.setUserName(user.getFullName());
      vote.setCreateDate(serviceContext.getCreateDate(now));
      vote.setModifiedDate(serviceContext.getModifiedDate(now));
      vote.setQuestionId(questionId);
      vote.setChoiceId(choiceId);
      vote.setVoteDate(serviceContext.getCreateDate(now));

      pollsVotePersistence.update(vote, false);
    }

    return vote;
  }
  protected PollsChoice addPollsChoice(String name, String description) {
    Map<Locale, String> descriptionMap = new HashMap<Locale, String>();

    for (Locale locale : _locales) {
      descriptionMap.put(locale, description.concat(LocaleUtil.toLanguageId(locale)));
    }

    PollsChoice pollsChoice = PollsChoiceUtil.create(0);

    pollsChoice.setName(name);
    pollsChoice.setDescriptionMap(descriptionMap);

    return pollsChoice;
  }
Esempio n. 4
0
  public static com.liferay.portlet.polls.model.PollsChoice model(PollsChoiceHBM pollsChoiceHBM) {
    com.liferay.portlet.polls.model.PollsChoice pollsChoice =
        PollsChoicePool.get(pollsChoiceHBM.getPrimaryKey());

    if (pollsChoice == null) {
      pollsChoice =
          new com.liferay.portlet.polls.model.PollsChoice(
              pollsChoiceHBM.getQuestionId(),
              pollsChoiceHBM.getChoiceId(),
              pollsChoiceHBM.getDescription());
      PollsChoicePool.put(pollsChoice.getPrimaryKey(), pollsChoice);
    }

    return pollsChoice;
  }
  /**
   * Updates the polls choice in the database or adds it if it does not yet exist. Also notifies the
   * appropriate model listeners.
   *
   * @param pollsChoice the polls choice
   * @param merge whether to merge the polls choice with the current session. See {@link
   *     com.liferay.portal.service.persistence.BatchSession#update(com.liferay.portal.kernel.dao.orm.Session,
   *     com.liferay.portal.model.BaseModel, boolean)} for an explanation.
   * @return the polls choice that was updated
   * @throws SystemException if a system exception occurred
   */
  @Indexable(type = IndexableType.REINDEX)
  public PollsChoice updatePollsChoice(PollsChoice pollsChoice, boolean merge)
      throws SystemException {
    pollsChoice.setNew(false);

    return pollsChoicePersistence.update(pollsChoice, merge);
  }
  /**
   * Adds the polls choice to the database. Also notifies the appropriate model listeners.
   *
   * @param pollsChoice the polls choice
   * @return the polls choice that was added
   * @throws SystemException if a system exception occurred
   */
  @Indexable(type = IndexableType.REINDEX)
  public PollsChoice addPollsChoice(PollsChoice pollsChoice) throws SystemException {
    pollsChoice.setNew(true);

    return pollsChoicePersistence.update(pollsChoice, false);
  }