コード例 #1
0
ファイル: Ingredient.java プロジェクト: blomqvie/ruokalista
  /**
   * removes given ingredient.
   *
   * @param ingredient
   */
  public static void remove(Long id) {

    Ingredient i = find.byId(id);
    if (i.shoppingLists.isEmpty()) {
      i.delete();
    } else {
      // TODO: add an obsolete-attribute, which could be manipulated here?
      throw new RuokalistaException("Ingredient is already referenced from shopping lists.");
    }
  }
コード例 #2
0
ファイル: Ingredient.java プロジェクト: blomqvie/ruokalista
  /**
   * Saves an ingredient. Before that, it's attached to a recipe.
   *
   * @param recipe
   * @param ingredient
   */
  public static Ingredient saveToRecipe(Long recipe, Ingredient ingredient) {

    Recipe r = Recipe.findById(recipe);
    if (r == null) {
      throw new RuokalistaException("Recipe not found.");
    }

    ingredient.recipe = r;
    save(ingredient);
    return ingredient;
  }
コード例 #3
0
ファイル: Ingredient.java プロジェクト: blomqvie/ruokalista
 /**
  * Saves given ingredient.
  *
  * @param ingredient
  */
 public static void save(Ingredient ingredient) {
   ingredient.save();
 }