Esempio n. 1
0
  /** For canceling a rating event */
  public void oncancel() {
    Users user = ui.getUser();
    newRating = ratingEJB.findByUserAndRecipe(user, recipe);

    if (newRating != null) {
      ratingEJB.removeRecipeRating(newRating);
    }
  }
Esempio n. 2
0
 /**
  * returns the rating of this recipe
  *
  * @return integer rating from 1-5
  */
 public Integer getRating() {
   if (recipe != null && ui.isIsUserAuthenticated()) {
     RecipeRating temp = ratingEJB.findByUserAndRecipe(ui.getUser(), recipe);
     if (temp != null) {
       rating = temp.getRatingValue().getValue();
     }
   }
   return rating;
 }
Esempio n. 3
0
  /** This method is intended to be used as an actionListener for rating */
  public void handleRating() {
    Users rater = ui.getUser();
    newRating = ratingEJB.findByUserAndRecipe(rater, recipe);
    boolean edit = false; // determine whether we need to edit

    // No rating for this user exists
    if (newRating == null && rating > 0 && rating <= 5) {
      newRating = new RecipeRating();
      newRating.setRater(rater);
      newRating.setRecipe(recipe);
      newRating.setRatingDate(new Date().getTime());
    } // A rating exists
    else {
      edit = true;
    }

    switch (rating) {
      case 1:
        this.newRating.setRatingValue(RatingValue.ONE_STAR);
        break;
      case 2:
        this.newRating.setRatingValue(RatingValue.TWO_STARS);
        break;
      case 3:
        this.newRating.setRatingValue(RatingValue.THREE_STARS);
        break;
      case 4:
        this.newRating.setRatingValue(RatingValue.FOUR_STARS);
        break;
      case 5:
        this.newRating.setRatingValue(RatingValue.FIVE_STARS);
        break;
    } // end switch

    if (edit) {
      this.newRating = ratingEJB.editRecipeRating(newRating);
    } else {
      this.newRating = ratingEJB.createRecipeRating(newRating);
    }
  }