Class AddressService

java.lang.Object
de.bytestore.hostinger.security.service.AddressService

@Service @Component public class AddressService extends Object
  • Constructor Details

    • AddressService

      public AddressService()
  • Method Details

    • onApplicationStarted

      @EventListener public void onApplicationStarted(org.springframework.boot.context.event.ApplicationStartedEvent event)
    • getCoordinates

      public CompletableFuture<List<Double>> getCoordinates(String addressIO)
      Retrieves the geographical coordinates (latitude and longitude) for a given address by querying the OpenStreetMap Nominatim API asynchronously.
      Parameters:
      addressIO - The address for which the geographical coordinates are to be retrieved.
      Returns:
      A CompletableFuture that, when completed, will provide a list containing the latitude and longitude of the specified address. If an error occurs, the CompletableFuture will complete exceptionally.
    • getAddress

      public CompletableFuture<Collection<AddressResult>> getAddress(String addressIO)
      Sends an asynchronous request to the OpenStreetMap Nominatim API to retrieve address details for the specified address string in JSON format.
      Parameters:
      addressIO - The address string for which the address details are to be retrieved.
      Returns:
      A CompletableFuture that, when completed, will provide a Collection of AddressResult containing the address details. If an error occurs, the CompletableFuture will complete exceptionally.
    • loadCountries

      public static void loadCountries()
      This method loads the list of Locale objects representing the countries and stores them in a static field. The list is obtained by calling the getISOCountries() method of the Locale class. Each country code is used to create a new Locale object, which is then added to the result list.
    • format

      public static String format(AddressResult addressIO)
      Formats an AddressResult object into a string representation.
      Parameters:
      addressIO - The AddressResult object containing address information to be formatted.
      Returns:
      A formatted string representing the address. The format includes the street name and number, city name, and country code if available.
    • byISO3166_1_Alpha_2Country

      public Locale byISO3166_1_Alpha_2Country(String countryCode)