Class APIHandler

java.lang.Object
proseccoCoding.TLN.model.APIHandler

public class APIHandler extends Object
This class allows to interact with the TrustedListAPI and retrieve data from it. This class contains two methods for the API calls and others static methods used to mold the data and create Objects with the required specifications.
  • Field Details

    • countriesNames

      private static org.json.JSONArray countriesNames
      JSONArray that contains JSONObjects with the country names and codes
    • countriesData

      private static org.json.JSONArray countriesData
      JSONArray that contains JSONObjects with all the information about each country
  • Constructor Details

    • APIHandler

      public APIHandler()
  • Method Details

    • initCountriesNames

      public static void initCountriesNames() throws Exception
      Initializer method for variable countriesNames. It initializes countriesNames with countries codes and full names
      Throws:
      Exception
    • initCountriesData

      public static void initCountriesData()
      Initializer method for variable countriesData. It initializes countriesData with all the information about each country
    • retrieveCountriesNames

      public static ArrayList<String> retrieveCountriesNames()
      Static method that returns an ArrayList of Strings containing the names of the EU countries
      Returns:
      ArrayList with all the names of the countries
    • retrieveCountries

      public static HashMap<String,Country> retrieveCountries()
      Static method that returns an HashMap containing entries with country codes as keys and Country objects as values.
      Returns:
      HashMap containing entries with country codes as keys and Country objects (without complete data) as values
    • readFromFile

      private static HashMap<String,String> readFromFile()
      Private method that reads from local file the service types data and return an HashMap containing entries with service type codes as keys and service type names as values.
      Returns:
      HashMap containing entries with service type codes as keys and service type names as values
    • retriveServiceTypes

      public static ArrayList<javafx.util.Pair<String,String>> retriveServiceTypes()
      Static method that parses countryData and extracts all service types from all countries
      Returns:
      ArrayList of Pair<String, String> composed of a service type code as first value and a service type full name as second value
    • retriveCountryData

      public static Country retriveCountryData(String countryCode) throws IllegalArgumentException
      Static method that parses countryData and extracts the data to create a Country object
      Parameters:
      countryCode - The code that identifies each country
      Returns:
      the Country object just created
      Throws:
      IllegalArgumentException - in case of null parameter