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 String
API key gathered from application.properties which is used for accessing the OpenWeather APIprivate final CityRepository
private final Logger
private final com.fasterxml.jackson.databind.ObjectMapper
private final org.springframework.web.client.RestTemplate
private 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 TypeMethodDescriptionvoid
Fetches the weather data of allCity
objects which haveimportingData
set asTRUE
and saves it to the databaseprotected void
fetchAndSave
(City city) Fetches the weather data of the specifiedCity
and saves it to the databaseprivate WeatherData
requestData
(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 allCity
objects which haveimportingData
set asTRUE
and 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
-City
to fetch weather data about- Returns:
WeatherData
about the specifiedCity
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
- in case of API response processing error
-