Class IngredientController

java.lang.Object
de.hebkstudents.recipemanager.ingredient.IngredientController

public class IngredientController
extends java.lang.Object
Class which handles the ingredients
  • Constructor Summary

    Constructors
    Constructor Description
    IngredientController()  
  • Method Summary

    Modifier and Type Method Description
    static boolean addIngredient​(Ingredient ingredient)
    Adds a new Ingredient to the database
    static boolean deleteIngredient​(int ingredientID)
    Deletes an Ingredient from the database
    static boolean deleteIngredient​(Ingredient ingredient)
    Deletes an Ingredient from the database
    static Ingredient getIngredient​(int ingredientID)
    Gets an Ingredient by its ID from the database
    static Ingredient[] getIngredients()
    Gets all Ingredients as an Array of type Ingredient from the database
    static Ingredient[] getIngredients​(IngredientFilter filter)
    Gets all or filtered Ingredients as Ingredient Array from the database
    static Ingredient[] getIngredientsForRecipe​(int recipeID)
    Gets all ingredients for a specific recipe as Object-Array of type Ingredient
    static boolean ingredientExists​(int ingredientID)
    Checks whether an Ingredient exists or not
    static boolean isInUse​(int ingredientID)
    Checks if an ingredient is used by any recipe
    static boolean updateIngredient​(Ingredient ingredient)
    Updates an Ingredient using its changed object

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • IngredientController

      public IngredientController()
  • Method Details

    • addIngredient

      public static boolean addIngredient​(Ingredient ingredient)
      Adds a new Ingredient to the database
      Parameters:
      ingredient - Valid Ingredient object
      Returns:
      true if successfully added
    • deleteIngredient

      public static boolean deleteIngredient​(Ingredient ingredient) throws IngredientNotFoundException, InvalidIngredientException
      Deletes an Ingredient from the database
      Parameters:
      ingredient - Valid Ingredient object
      Returns:
      true if ingredient was deleted successfully
      Throws:
      IngredientNotFoundException - If Ingredient does not exist
      InvalidIngredientException - If a required property of Ingredient is missing
    • deleteIngredient

      public static boolean deleteIngredient​(int ingredientID) throws IngredientNotFoundException
      Deletes an Ingredient from the database
      Parameters:
      ingredientID - Existing ingredient ID
      Returns:
      true if ingredient was deleted successfully
      Throws:
      IngredientNotFoundException - If Ingredient does not exist
    • getIngredient

      public static Ingredient getIngredient​(int ingredientID) throws IngredientNotFoundException
      Gets an Ingredient by its ID from the database
      Parameters:
      ingredientID - Existing ingredientID
      Returns:
      Ingredient object if ingredient exists and is not corrupted
      Throws:
      IngredientNotFoundException - If Ingredient does not exist
    • getIngredients

      public static Ingredient[] getIngredients()
      Gets all Ingredients as an Array of type Ingredient from the database
      Returns:
      Ingredient Array
    • getIngredients

      public static Ingredient[] getIngredients​(IngredientFilter filter)
      Gets all or filtered Ingredients as Ingredient Array from the database
      Parameters:
      filter - Valid IngredientFilter object or null (null -> no filter -> all ingredients)
      Returns:
      Ingredient Array with all/filtered Ingredients
    • ingredientExists

      public static boolean ingredientExists​(int ingredientID)
      Checks whether an Ingredient exists or not
      Parameters:
      ingredientID - ID of the ingredient
      Returns:
      true if ingredient exists
    • getIngredientsForRecipe

      public static Ingredient[] getIngredientsForRecipe​(int recipeID) throws RecipeNotFoundException
      Gets all ingredients for a specific recipe as Object-Array of type Ingredient
      Parameters:
      recipeID - ID of the recipe
      Returns:
      Ingredient-Object-Array
      Throws:
      RecipeNotFoundException - If the recipe does not exist
    • updateIngredient

      public static boolean updateIngredient​(Ingredient ingredient) throws InvalidIngredientException, IngredientNotFoundException
      Updates an Ingredient using its changed object
      Parameters:
      ingredient - Valid Ingredient object
      Returns:
      true if the ingredient was successfully updated
      Throws:
      InvalidIngredientException - If a required property of Ingredient is missing
      IngredientNotFoundException - If an ingredient with its ID does not exist in the database
    • isInUse

      public static boolean isInUse​(int ingredientID) throws IngredientNotFoundException, java.sql.SQLException
      Checks if an ingredient is used by any recipe
      Parameters:
      ingredientID - ID of the recipe
      Returns:
      true if its used by an recipe and the ingredient exists
      Throws:
      IngredientNotFoundException - If the ingredient does not exist
      java.sql.SQLException - If dependencies cannot be checked