diff --git a/src/main/java/mi/hdm/recipes/CategoryManager.java b/src/main/java/mi/hdm/recipes/CategoryManager.java index 3059e1f8b9a7d6fa833740061d656d1eea11d8e1..a526d9fd6494cf2d9d6c8ecb3a5911ae43508999 100644 --- a/src/main/java/mi/hdm/recipes/CategoryManager.java +++ b/src/main/java/mi/hdm/recipes/CategoryManager.java @@ -40,12 +40,16 @@ public class CategoryManager { } public boolean deleteCategory(Category c) { + log.info("Category {} deleted successfully."); return allCategories.remove(c); + } public boolean deleteCategory(String name) { Category c = getCategoryByName(name).orElseThrow(() -> new NullPointerException("Category not found.")); + log.info("Category {} deleted successfully."); return allCategories.remove(c); + } public List<Category> getAllCategories(){ @@ -54,6 +58,7 @@ public class CategoryManager { public void clearCategories() { allCategories.clear(); + log.info("List allCategories cleared successfully."); } private Optional<Category> getCategoryByName(String name) { diff --git a/src/main/java/mi/hdm/recipes/IngredientManager.java b/src/main/java/mi/hdm/recipes/IngredientManager.java index 89260a36141195f848a35f2012e27ab2d3ab9951..1cef464748e6fb1cb831b827888187222e7b2593 100644 --- a/src/main/java/mi/hdm/recipes/IngredientManager.java +++ b/src/main/java/mi/hdm/recipes/IngredientManager.java @@ -29,8 +29,9 @@ public class IngredientManager { */ public boolean addIngredient(Ingredient in) { if (allIngredients.contains(in)) { - log.error("Ingredient: {} not added because it already exists", in.getName()); + log.error("Ingredient {} not added because it already exists.", in.getName()); return false; + //TODO: Exception or false? } else { log.info("Ingredient {} added successfully.", in.getName()); allIngredients.add(in); @@ -44,6 +45,7 @@ public class IngredientManager { } public Ingredient deleteIngredient(int i) { + log.info("Ingredient {} deleted successfully."); return allIngredients.remove(i); } @@ -53,10 +55,12 @@ public class IngredientManager { return ingredient.isPresent() && allIngredients.remove(ingredient);*/ Ingredient ingredient = getIngredientByName(name).orElseThrow(() -> new InvalidIngredientException("No ingredient with name " + name)); + log.info("Ingredient {} deleted successfully."); return allIngredients.remove(ingredient); } public void clearIngredients() { + log.info("List allIngredients cleared successfully."); allIngredients.clear(); } diff --git a/src/main/java/mi/hdm/recipes/NutritionCalculator.java b/src/main/java/mi/hdm/recipes/NutritionCalculator.java index 6233f3b0ed5a6dbe5e846c48584c98085e912d3f..f0e21c538969b2e80f122198197a0656d7de3ef4 100644 --- a/src/main/java/mi/hdm/recipes/NutritionCalculator.java +++ b/src/main/java/mi/hdm/recipes/NutritionCalculator.java @@ -3,8 +3,12 @@ package mi.hdm.recipes; import mi.hdm.mealPlan.MealPlan; import java.util.Map; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class NutritionCalculator { + + private static final Logger log = LogManager.getLogger(NutritionCalculator.class); /** * Method to calculate the nutrition table for a recipe out of its ingredients. * @@ -12,6 +16,7 @@ public class NutritionCalculator { */ public static NutritionTable calculateNutritionTable(Map<RecipeComponent, Integer> ingredients) { if (ingredients == null || ingredients.isEmpty()) { + log.info("Map ingredients is null or empty. Therefore new nutritionTable() was generated."); return NutritionTable.empty(); } @@ -32,7 +37,7 @@ public class NutritionCalculator { totalFibers += nutritionTable.get(Nutrition.FIBERS) * ingredients.get(entry) / 100; totalSalt += nutritionTable.get(Nutrition.SALT) * ingredients.get(entry) / 100; } - + log.info("NutritionTable calculated successfully."); return new NutritionTable(totalCals, totalCarbs, totalFats, totalProteins, totalFibers, totalSalt); } diff --git a/src/main/java/mi/hdm/recipes/Recipe.java b/src/main/java/mi/hdm/recipes/Recipe.java index 52b6cc12d57ed6f9216b8b0cc23bf3783eaa8625..841291f1432aaebd2b28dd5cac4f392b4f1b75cf 100644 --- a/src/main/java/mi/hdm/recipes/Recipe.java +++ b/src/main/java/mi/hdm/recipes/Recipe.java @@ -1,6 +1,8 @@ package mi.hdm.recipes; import mi.hdm.exceptions.InvalidRecipeException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.time.LocalDateTime; import java.util.ArrayList; @@ -8,6 +10,7 @@ import java.util.List; import java.util.Map; public class Recipe implements RecipeComponent { + private static final Logger log = LogManager.getLogger(Recipe.class); private final Map<RecipeComponent, Integer> ingredients; private String name; private String description; @@ -85,6 +88,7 @@ public class Recipe implements RecipeComponent { throw new InvalidRecipeException("Cannot set name to " + name); } this.name = name; + log.info("Name set successfully."); } public String getName() { @@ -97,6 +101,7 @@ public class Recipe implements RecipeComponent { public void setDescription(String description) { this.description = description; + log.info("Description set successfully."); } public List<String> getPreparation() { @@ -105,6 +110,7 @@ public class Recipe implements RecipeComponent { public void setPreparation(List<String> preparation) { this.preparation = preparation; + log.info("Preparation set successfully."); } public List<Category> getCategories() { @@ -117,10 +123,12 @@ public class Recipe implements RecipeComponent { } this.categories = categories; + log.info("Categories set successfully."); } public void addCategory(Category category) { categories.add(category); + log.info("Category {} added successfully."); } public int getPreparationTimeMins() { @@ -132,6 +140,7 @@ public class Recipe implements RecipeComponent { throw new InvalidRecipeException("PreparationTime must be a positive value"); } this.preparationTimeMins = preparationTimeMins; + log.info("PreparationTimeMins set successfully."); } public LocalDateTime getCreationTime() { @@ -143,6 +152,7 @@ public class Recipe implements RecipeComponent { throw new InvalidRecipeException("Nutrition Table does not exist"); } this.nutritionTable = nutritionTable; + log.info("NutritionTable set successfully."); } public NutritionTable getNutritionTable() { diff --git a/src/main/java/mi/hdm/recipes/RecipeManager.java b/src/main/java/mi/hdm/recipes/RecipeManager.java index 189852d61ebba9235d053c56eea003640658786d..edcae9976d7577d32a750134055639e25314a160 100644 --- a/src/main/java/mi/hdm/recipes/RecipeManager.java +++ b/src/main/java/mi/hdm/recipes/RecipeManager.java @@ -22,19 +22,25 @@ public class RecipeManager { } public void addRecipe(Recipe recipe){ + if (getRecipeByName(recipe.getName()).isEmpty()) { recipes.add(recipe); + log.info("Recipe {} added successfully."); } else { + log.error("Recipe {} not added because it already exists."); throw new InvalidRecipeException("Recipe name already exists"); } + //TODO: Exception or false? } public Recipe deleteRecipe(int i) { + log.info("Recipe {} deleted successfully."); return recipes.remove(i); } public boolean deleteRecipe(String name) { Recipe r = getRecipeByName(name).orElseThrow(); + log.info("Recipe {} deleted successfully."); return recipes.remove(r); } diff --git a/src/main/java/mi/hdm/recipes/RecipeSearch.java b/src/main/java/mi/hdm/recipes/RecipeSearch.java index 460a8fdac8536f8398865a2fb75d7146d510fb6c..b96012d67553789b5623e96d69d3dc19a8a6bc61 100644 --- a/src/main/java/mi/hdm/recipes/RecipeSearch.java +++ b/src/main/java/mi/hdm/recipes/RecipeSearch.java @@ -3,6 +3,7 @@ package mi.hdm.recipes; import java.util.List; public class RecipeSearch { + //TODO: implement class List<Recipe> recipesToSearch; public RecipeSearch (List<Recipe> recipesToSearch) {} diff --git a/src/main/java/mi/hdm/shoppingList/ShoppingList.java b/src/main/java/mi/hdm/shoppingList/ShoppingList.java index bd9d88b5409beab8cc2f31a62f47a0d3cca1a660..187fb3f05b176a19bfe924b9bcfa0e93023cb771 100644 --- a/src/main/java/mi/hdm/shoppingList/ShoppingList.java +++ b/src/main/java/mi/hdm/shoppingList/ShoppingList.java @@ -9,6 +9,7 @@ import java.util.Map; * Shopping list that the user can add ingredients to. The elements on the list can be marked as done or undone. */ public class ShoppingList { + //TODO: implement class private final Map<Ingredient, Boolean> list; private static final ShoppingList shoppingList = new ShoppingList();