Package dev.karlkadak.backend.service
Class WeatherDataImporter
java.lang.Object
dev.karlkadak.backend.service.WeatherDataImporter
Used for importing weather data to the database from OpenWeather API
Also logs the results of imports using
Also logs the results of imports using
Logger-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringAPI key gathered from application.properties which is used for accessing the OpenWeather APIprivate final CityRepositoryprivate final Loggerprivate final com.fasterxml.jackson.databind.ObjectMapperprivate final org.springframework.web.client.RestTemplateprivate final WeatherDataRepository -
Constructor Summary
ConstructorsConstructorDescriptionWeatherDataImporter(WeatherDataRepository weatherDataRepository, CityRepository cityRepository, Logger logger, org.springframework.web.client.RestTemplate restTemplate, com.fasterxml.jackson.databind.ObjectMapper objectMapper) -
Method Summary
Modifier and TypeMethodDescriptionvoidFetches the weather data of allCityobjects which haveimportingDataset asTRUEand saves it to the databaseprotected voidfetchAndSave(City city) Fetches the weather data of the specifiedCityand saves it to the databaseprivate WeatherDatarequestData(City city) Requests and returns the weather data of the specified city
-
Field Details
-
weatherDataRepository
-
cityRepository
-
logger
-
restTemplate
private final org.springframework.web.client.RestTemplate restTemplate -
objectMapper
private final com.fasterxml.jackson.databind.ObjectMapper objectMapper -
apiKey
API key gathered from application.properties which is used for accessing the OpenWeather API
-
-
Constructor Details
-
WeatherDataImporter
@Autowired public WeatherDataImporter(WeatherDataRepository weatherDataRepository, CityRepository cityRepository, Logger logger, org.springframework.web.client.RestTemplate restTemplate, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
-
-
Method Details
-
defaultImport
public void defaultImport()Fetches the weather data of allCityobjects which haveimportingDataset asTRUEand saves it to the database -
fetchAndSave
-
requestData
private WeatherData requestData(City city) throws com.fasterxml.jackson.core.JsonProcessingException Requests and returns the weather data of the specified city- Parameters:
city-Cityto fetch weather data about- Returns:
WeatherDataabout the specifiedCity- Throws:
com.fasterxml.jackson.core.JsonProcessingException- in case of API response processing error
-