/** * 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."); } }
/** * 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; }
/** * Saves given ingredient. * * @param ingredient */ public static void save(Ingredient ingredient) { ingredient.save(); }