Class JsonToDb

java.lang.Object
edu.ntnu.stud.model.database.JsonToDb

public class JsonToDb extends Object
This class is responsible for seeding the database with data from JSON files.
  • Constructor Details

    • JsonToDb

      public JsonToDb()
  • Method Details

    • initRecipeFromJson

      public static void initRecipeFromJson()
      Populates the cookbook and recipeIngredient tables from a Json file.
      See Also:
      • insertRecipe(JsonNode)
      • insertRecipeIngredients(JsonNode)
    • updateInventoryFromJson

      public static void updateInventoryFromJson() throws DbConnectionErrorException
      Updates the inventory table in the database with data from a JSON file.
      Throws:
      DbConnectionErrorException - If an error occurs while connecting to the database.
    • getJsonFromDb

      public static void getJsonFromDb(String listName) throws DbConnectionErrorException
      Gets the entire shopping list or inventory table from the database and populates the corresponding Json file.
      Parameters:
      listName - The name of both the list and the table to get.
      Throws:
      DbConnectionErrorException - If an error occurs while connecting to the database.
    • updateFromJson

      public static void updateFromJson(String jsonFileName) throws IllegalArgumentException
      Updates either the shopping list or inventory table in the database with data from a JSON file.
      Parameters:
      jsonFileName - The name of the JSON file to update from, is also used to determine what table to insert into.
      Throws:
      IllegalArgumentException