Package com.uphea.domain

Examples of com.uphea.domain.Vote


    // find answers question
    question = questionService.findAnswersQuestion(answer.getId());
    answerService.loadAnswers(question);
    userAnswer = question.lookupAnswerById(answer.getId());

    Vote vote;
    // find user vote if exist
    if (userSession != null) {
      // read vote from db, ignore request parameter
      userVote = answerService.findUserVoteForQuestion(userSession.getUser(), question);
    } else {
      // read votes from param
      if ((userVote != null) && (userVote.getId() != null)) {
        userVote = answerService.findVoteById(userVote.getId());
        if (userVote == null) {
          log.info("user vote can't be found.");
        }
      } else {
        userVote = null;
      }
    }

    // update or save a vote
    if (userVote != null) {
      log.info("update vote {}", userVote.getId());
      Answer currentAnswer = question.lookupAnswerById(userVote.getAnswerId());
      if (currentAnswer.equals(userAnswer)) {
        log.debug("vote equals to previous one.");
        statsService.calcAnswerDistribution(question);
        return OK;
      }
      vote = answerService.changeVoteAnswer(userVote, currentAnswer, userAnswer, requestRemoteAddr);
    } else {
      log.info("add new vote {}");
      vote = answerService.voteForAnswer(userAnswer, requestRemoteAddr, userSession == null ? null : userSession.getUser());
    }
    userVoteId = vote.getId();

    // recalc
    statsService.calcAnswerDistribution(question);

    // add cookie
View Full Code Here


  /**
   * Finds answer by vote id.
   */
  public Answer findAnswerByVoteId(Long voteId) {
    Vote vote = appDao.findById(Vote.class, voteId);
    if (vote == null) {
      return null;
    }
    return appDao.findById(Answer.class, vote.getAnswerId());
  }
View Full Code Here

  /**
   * Votes for answer.
   */
  public Vote voteForAnswer(Answer answer, String ipAddress, User user) {
    updateAnswerVoteCount(answer, true);
    Vote vote = new Vote();
    vote.setAnswer(answer);
    vote.setTime(new JDateTime());
    vote.setIpAddress(ipAddress);
    if (user != null) {
      vote.setUserId(user.getId());
    }
    return appDao.store(vote);
  }
View Full Code Here

TOP

Related Classes of com.uphea.domain.Vote

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.