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 databasestatic boolean
deleteIngredient(int ingredientID)
Deletes an Ingredient from the databasestatic boolean
deleteIngredient(Ingredient ingredient)
Deletes an Ingredient from the databasestatic Ingredient
getIngredient(int ingredientID)
Gets an Ingredient by its ID from the databasestatic Ingredient[]
getIngredients()
Gets all Ingredients as an Array of type Ingredient from the databasestatic Ingredient[]
getIngredients(IngredientFilter filter)
Gets all or filtered Ingredients as Ingredient Array from the databasestatic Ingredient[]
getIngredientsForRecipe(int recipeID)
Gets all ingredients for a specific recipe as Object-Array of type Ingredientstatic boolean
ingredientExists(int ingredientID)
Checks whether an Ingredient exists or notstatic boolean
isInUse(int ingredientID)
Checks if an ingredient is used by any recipestatic boolean
updateIngredient(Ingredient ingredient)
Updates an Ingredient using its changed objectMethods 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
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, InvalidIngredientExceptionDeletes an Ingredient from the database- Parameters:
ingredient
- Valid Ingredient object- Returns:
- true if ingredient was deleted successfully
- Throws:
IngredientNotFoundException
- If Ingredient does not existInvalidIngredientException
- If a required property of Ingredient is missing
-
deleteIngredient
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
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
Gets all Ingredients as an Array of type Ingredient from the database- Returns:
- Ingredient Array
-
getIngredients
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
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, IngredientNotFoundExceptionUpdates 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 missingIngredientNotFoundException
- If an ingredient with its ID does not exist in the database
-
isInUse
public static boolean isInUse(int ingredientID) throws IngredientNotFoundException, java.sql.SQLExceptionChecks 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 existjava.sql.SQLException
- If dependencies cannot be checked
-