Exemplo n.º 1
0
  public int getRating() {
    HttpSession session = FacesUtil.getSession();
    User user = (User) session.getAttribute("user");

    Rating userRating = getUserRating(user);
    if (userRating != null) {
      this.rating = userRating.getRating();
    }

    return this.rating;
  }
Exemplo n.º 2
0
  public Rating getUserRating(User user) {
    this.recipe = service.getById(this.recipe.getId());
    List<Rating> ratingList = this.recipe.getRatingList();
    if (ratingList != null && !ratingList.isEmpty()) {

      for (Rating rating : ratingList) {
        User rater = rating.getUserId();
        if (rater.getId() == user.getId()) {
          return rating;
        }
      }
    }

    return null;
  }
Exemplo n.º 3
0
  public void onrate(RateEvent rateEvent) {

    HttpSession session = FacesUtil.getSession();
    User user = (User) session.getAttribute("user");

    Rating userRating = getUserRating(user);

    int score = ((Integer) rateEvent.getRating()).intValue();
    Rating rate = new Rating();
    rate.setRating(score);
    rate.setRecipe(recipe);
    rate.setUserId(user);

    if (userRating == null) {
      serviceRating.create(rate);
    } else {
      rate.setId(userRating.getId());
      serviceRating.update(rate);
    }
  }