示例#1
0
 /**
  * checks if the user is able to upload
  *
  * @return true if user is authorized false if the user is not
  */
 public boolean shouldRenderUpload() {
   if (recipe != null && ui.isIsUserAuthenticated()) {
     return recipe.getCreator().getUserName().equals(ui.getUser().getUserName());
   } else {
     return false;
   }
 }
示例#2
0
 /**
  * Returns true if the user is the creator for this recipe
  *
  * @return boolean
  */
 public boolean isIsCreator() {
   if (ui.isIsUserAuthenticated() && recipe != null) {
     if (recipe.getCreator() == user) return true;
     else return false;
   } else {
     return false;
   }
 }
示例#3
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;
 }
示例#4
0
 /**
  * Returns true if the user has already favorited this recipe, false otherwise
  *
  * @return true if already favorited, false otherwise
  */
 public boolean isAlreadyFavorited() {
   if (ui.isIsUserAuthenticated()) {
     Users user = ui.getUser();
     if (user.getFavorites() != null) {
       return user.getFavorites().contains(recipe);
     } else {
       return false;
     }
   } else {
     return false;
   }
 }
示例#5
0
 /** deletes a comment */
 public void doDeleteComment() {
   if (ui.isIsUserAuthenticated()) {
     Users u = ui.getUser();
     if (isEditAuthorized() || ui.isIsAdmin()) {
       try {
         recipesEJB.removeCommentFromRecipe(recipe, deleteComment);
         this.commentModel = new LazyCommentDataModel(recipe, recipesEJB);
       } catch (javax.ejb.EJBAccessException ejbae) {
         FacesContext.getCurrentInstance()
             .addMessage(null, new FacesMessage("Only registered users can post comments."));
       }
     }
   }
 }
示例#6
0
 /**
  * returns true if it has been reviewed and false if it has not been reviewed by a professional;
  */
 public boolean isHasAlreadyReviewed() {
   boolean result = false;
   if (ui.isIsUserAuthenticated() && professionalStatus.isIsProfessional()) {
     Users user = ui.getUser();
     if (recipe != null) {
       for (Review rev : recipe.getReviews()) {
         if (rev.getReviewer().getUserName().equals(user.getUserName())) {
           result = true;
           break;
         }
       } // end for
     }
   } // end value != null
   return result;
 }
示例#7
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();
    }
  }