예제 #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);
    }
  }
예제 #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;
 }
예제 #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);
    }
  }
예제 #4
0
  /** This method is called AFTER the bean is constructed */
  @PostConstruct
  private void init() {
    if (!FacesContext.getCurrentInstance().isPostback()) {
      // TODO: view counter ++
    }
    // Get the recipe
    String value = qm.get("recipe");
    if (value != null) {
      recipe = recipesEJB.findRecipe(Integer.parseInt(value));
    }

    // init some fields
    tags = new DefaultTagCloudModel();
    newComment = new Comment();
    newRating = new RecipeRating();
    tags = new DefaultTagCloudModel();

    if (recipe != null) {
      this.commentModel = new LazyCommentDataModel(recipe, recipesEJB);
      this.totalRatings = ratingEJB.countTotalRatings(recipe);
      Users user = ui.getUser();
      getNutritionixIngredientInfo(recipe);
      recipesEJB.incrementViews(recipe);

      // Get the recipe's tags
      ArrayList<Tag> tagList = new ArrayList<Tag>(recipe.getTags());
      if (!tagList.isEmpty()) {
        ListIterator i = tagList.listIterator();
        while (i.hasNext()) {
          Tag t = (Tag) i.next();
          String url = "search.xhtml?searchArg=" + t.getTagName();
          this.tags.addTag(new DefaultTagCloudItem(t.getTagName(), url, tagEJB.getWeight(t)));
        }
      } else {
        this.tags.addTag(new DefaultTagCloudItem("#tagMe", 1));
      }

      // Get related recipes
      relatedRecipes = search.getSearchRecipes(recipe);

    } // end if recipe is null
    else {
      this.tags.addTag(new DefaultTagCloudItem("#tagMe", 1));
    }
    if (ui.isIsUserAuthenticated()) {
      user = ui.getUser();
    }
  }