mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-01-10 20:06:44 +03:00
Compare commits
3 Commits
7f0866ffa2
...
8a1daa0fe2
| Author | SHA1 | Date | |
|---|---|---|---|
| 8a1daa0fe2 | |||
| 7e88fe597c | |||
| aa48ac3aa0 |
@ -13,6 +13,7 @@ Paid:
|
||||
* Hourly Forecast 4 days
|
||||
* Daily Forecast 16 days
|
||||
* Climatic 30 days
|
||||
* Solar Radiation API
|
||||
|
||||
Other:
|
||||
* Request timeout settings
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
* Hourly forecast
|
||||
* One Call API
|
||||
* Daily forecast
|
||||
* Solar Radiation API
|
||||
* 5 day / 3-hour forecast
|
||||
* Air Pollution
|
||||
* Geocoding API
|
||||
@ -344,7 +345,7 @@ You are able to set preferable options(via chain methods) and execute appropriat
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|--------------------------------------------------------------------------------|
|
||||
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||
| `getCoordinates()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||
| `getTimezone()` | Returns location timezone object. |
|
||||
| `getTimezoneOffset()` | Returns zone offset. |
|
||||
| `getCurrent()` | Returns `Current` object with current weather state if available. |
|
||||
@ -432,7 +433,7 @@ You are able to set preferable options(via chain methods) and execute appropriat
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|-------------------------------------------------------------------------------|
|
||||
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||
| `getCoordinates()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||
| `getTimezone()` | Returns location timezone object. |
|
||||
| `getTimezoneOffset()` | Returns zone offset. |
|
||||
| `getHistoricalWeather()` | Returns `HistoricalWeather` object with historical weather state. |
|
||||
@ -495,7 +496,7 @@ final AirPollutionDetails airPollutionDetails = openWeatherClient
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|---------------------------------------------------------------------------|
|
||||
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||
| `getCoordinates()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||
| `getAirPollutionRecords()` | Returns list of `AirPollutionRecord` objects. |
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionRecord`'s useful public methods(setters are not listed):
|
||||
|
||||
@ -32,6 +32,7 @@ import com.github.prominence.openweathermap.api.request.forecast.free.FiveDayThr
|
||||
import com.github.prominence.openweathermap.api.request.forecast.hourly.FourDaysHourlyForecastRequester;
|
||||
import com.github.prominence.openweathermap.api.request.geocoding.GeocodingRequester;
|
||||
import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherRequester;
|
||||
import com.github.prominence.openweathermap.api.request.radiation.SolarRadiationRequester;
|
||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequester;
|
||||
|
||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.*;
|
||||
@ -106,6 +107,15 @@ public class OpenWeatherMapClient {
|
||||
return new ClimaticForecastRequester(new RequestSettings(apiKey, timeoutSettings));
|
||||
}
|
||||
|
||||
/**
|
||||
* Solar Radiation <a href="https://openweathermap.org/api/solar-radiation">API</a>.
|
||||
* @return requester for retrieving solar radiation information.
|
||||
*/
|
||||
@SubscriptionAvailability(plans = SPECIAL)
|
||||
public SolarRadiationRequester solarRadiation() {
|
||||
return new SolarRadiationRequester(new RequestSettings(apiKey, timeoutSettings));
|
||||
}
|
||||
|
||||
/**
|
||||
* 5 Day / 3 Hour Forecast <a href="https://openweathermap.org/forecast5">API</a>.
|
||||
* @return requester for retrieving 5 day/3-hour weather forecast information.
|
||||
|
||||
@ -41,7 +41,7 @@ public class ClimaticForecastLocationDeserializer extends JsonDeserializer<Locat
|
||||
|
||||
final JsonNode coordNode = rootNode.get("coord");
|
||||
if (coordNode != null) {
|
||||
location.setCoordinate(objectMapper.readValue(objectMapper.treeAsTokens(coordNode), Coordinates.class));
|
||||
location.setCoordinates(objectMapper.readValue(objectMapper.treeAsTokens(coordNode), Coordinates.class));
|
||||
}
|
||||
|
||||
final JsonNode populationNode = rootNode.get("population");
|
||||
|
||||
@ -41,7 +41,7 @@ public class DailyForecastLocationDeserializer extends JsonDeserializer<Location
|
||||
|
||||
final JsonNode coordNode = rootNode.get("coord");
|
||||
if (coordNode != null) {
|
||||
location.setCoordinate(objectMapper.readValue(objectMapper.treeAsTokens(coordNode), Coordinates.class));
|
||||
location.setCoordinates(objectMapper.readValue(objectMapper.treeAsTokens(coordNode), Coordinates.class));
|
||||
}
|
||||
|
||||
final JsonNode populationNode = rootNode.get("population");
|
||||
|
||||
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Alexey Zinchenko
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.deserializer.forecast.free;
|
||||
|
||||
import com.fasterxml.jackson.core.JacksonException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.github.prominence.openweathermap.api.deserializer.CoordinatesDeserializer;
|
||||
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||
import com.github.prominence.openweathermap.api.model.forecast.free.Location;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class FreeForecastLocationDeserializer extends JsonDeserializer<Location> {
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
public FreeForecastLocationDeserializer() {
|
||||
final SimpleModule module = new SimpleModule();
|
||||
module.addDeserializer(Coordinates.class, new CoordinatesDeserializer());
|
||||
objectMapper.registerModule(module);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||
final JsonNode rootNode = p.getCodec().readTree(p);
|
||||
final Location location = Location.withValues(rootNode.get("id").asInt(), rootNode.get("name").asText());
|
||||
|
||||
final JsonNode timezoneNode = rootNode.get("timezone");
|
||||
if (timezoneNode != null) {
|
||||
location.setZoneOffset(ZoneOffset.ofTotalSeconds(timezoneNode.asInt()));
|
||||
}
|
||||
|
||||
final JsonNode countryNode = rootNode.get("country");
|
||||
if (countryNode != null) {
|
||||
location.setCountryCode(countryNode.asText());
|
||||
}
|
||||
|
||||
final JsonNode sunriseNode = rootNode.get("sunrise");
|
||||
final JsonNode sunsetNode = rootNode.get("sunset");
|
||||
if (sunriseNode != null) {
|
||||
location.setSunriseTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(sunriseNode.asLong()), TimeZone.getDefault().toZoneId()));
|
||||
}
|
||||
if (sunsetNode != null) {
|
||||
location.setSunsetTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(sunsetNode.asLong()), TimeZone.getDefault().toZoneId()));
|
||||
}
|
||||
|
||||
final JsonNode coordNode = rootNode.get("coord");
|
||||
if (coordNode != null) {
|
||||
location.setCoordinates(objectMapper.readValue(objectMapper.treeAsTokens(coordNode), Coordinates.class));
|
||||
}
|
||||
|
||||
final JsonNode populationNode = rootNode.get("population");
|
||||
if (populationNode != null) {
|
||||
location.setPopulation(populationNode.asLong());
|
||||
}
|
||||
|
||||
return location;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Alexey Zinchenko
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.deserializer.forecast.free;
|
||||
|
||||
import com.fasterxml.jackson.core.JacksonException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.github.prominence.openweathermap.api.model.forecast.free.Rain;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class FreeForecastRainDeserializer extends JsonDeserializer<Rain> {
|
||||
@Override
|
||||
public Rain deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||
final JsonNode rainNode = p.getCodec().readTree(p);
|
||||
final JsonNode oneHourNode = rainNode.get("3h");
|
||||
if (oneHourNode != null) {
|
||||
return Rain.withThreeHourLevelValue(oneHourNode.asDouble());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Alexey Zinchenko
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.deserializer.forecast.free;
|
||||
|
||||
import com.fasterxml.jackson.core.JacksonException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.github.prominence.openweathermap.api.model.forecast.free.Snow;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class FreeForecastSnowDeserializer extends JsonDeserializer<Snow> {
|
||||
@Override
|
||||
public Snow deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||
final JsonNode snowNode = p.getCodec().readTree(p);
|
||||
final JsonNode oneHourNode = snowNode.get("3h");
|
||||
if (oneHourNode != null) {
|
||||
return Snow.withThreeHourLevelValue(oneHourNode.asDouble());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -74,7 +74,7 @@ public class HourlyForecastLocationDeserializer extends JsonDeserializer<Locatio
|
||||
|
||||
final JsonNode coordNode = rootNode.get("coord");
|
||||
if (coordNode != null) {
|
||||
location.setCoordinate(objectMapper.readValue(objectMapper.treeAsTokens(coordNode), Coordinates.class));
|
||||
location.setCoordinates(objectMapper.readValue(objectMapper.treeAsTokens(coordNode), Coordinates.class));
|
||||
}
|
||||
|
||||
return location;
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
package com.github.prominence.openweathermap.api.deserializer.radiation;
|
||||
|
||||
import com.fasterxml.jackson.core.JacksonException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.github.prominence.openweathermap.api.model.radiation.SolarRadiationRecord;
|
||||
import com.github.prominence.openweathermap.api.utils.JsonDeserializationUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class SolarRadiationRecordDeserializer extends JsonDeserializer<SolarRadiationRecord> {
|
||||
@Override
|
||||
public SolarRadiationRecord deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
|
||||
final JsonNode rootNode = jsonParser.getCodec().readTree(jsonParser);
|
||||
|
||||
SolarRadiationRecord record = new SolarRadiationRecord();
|
||||
final JsonNode radiationNode = rootNode.get("radiation");
|
||||
record.setMeasurementTime(JsonDeserializationUtils.parseDateTime(rootNode.get("dt")));
|
||||
record.setCloudSkyGlobalHorizontalIrradiance(radiationNode.get("ghi").asDouble());
|
||||
record.setCloudSkyDirectNormalIrradiance(radiationNode.get("dni").asDouble());
|
||||
record.setCloudSkyDiffuseHorizontalIrradiance(radiationNode.get("dhi").asDouble());
|
||||
record.setClearSkyGlobalHorizontalIrradiance(radiationNode.get("ghi_cs").asDouble());
|
||||
record.setClearSkyDirectNormalIrradiance(radiationNode.get("dni_cs").asDouble());
|
||||
record.setClearSkyDiffuseHorizontalIrradiance(radiationNode.get("dhi_cs").asDouble());
|
||||
return record;
|
||||
}
|
||||
}
|
||||
@ -77,7 +77,7 @@ public class WeatherLocationDeserializer extends JsonDeserializer<Location> {
|
||||
|
||||
final JsonNode coordNode = rootNode.get("coord");
|
||||
if (coordNode != null) {
|
||||
location.setCoordinate(objectMapper.readValue(objectMapper.treeAsTokens(coordNode), Coordinates.class));
|
||||
location.setCoordinates(objectMapper.readValue(objectMapper.treeAsTokens(coordNode), Coordinates.class));
|
||||
}
|
||||
|
||||
return location;
|
||||
|
||||
@ -27,11 +27,6 @@ package com.github.prominence.openweathermap.api.enums;
|
||||
* More information <a href="https://openweathermap.org/price">at official website</a>.
|
||||
*/
|
||||
public enum SubscriptionPlan {
|
||||
/**
|
||||
* Free subscription plan.
|
||||
*/
|
||||
FREE,
|
||||
|
||||
/**
|
||||
* An alias that represents any of paid plans: startup, developer, professional or enterprise.
|
||||
*/
|
||||
@ -57,6 +52,12 @@ public enum SubscriptionPlan {
|
||||
*/
|
||||
ENTERPRISE,
|
||||
|
||||
/**
|
||||
* Special subscription plan. You should contact a manager to get an access.
|
||||
*/
|
||||
SPECIAL,
|
||||
|
||||
|
||||
/**
|
||||
* All existing subscription plans.
|
||||
*/
|
||||
|
||||
@ -61,7 +61,7 @@ public class AirPollutionResponseMapper {
|
||||
|
||||
private AirPollutionDetails mapToAirPollution(JsonNode rootNode) {
|
||||
final AirPollutionDetails airPollutionDetails = new AirPollutionDetails();
|
||||
airPollutionDetails.setCoordinate(parseCoordinate(rootNode.get("coord")));
|
||||
airPollutionDetails.setCoordinates(parseCoordinate(rootNode.get("coord")));
|
||||
|
||||
final List<AirPollutionRecord> sampleList = new ArrayList<>();
|
||||
final JsonNode sampleListNode = rootNode.get("list");
|
||||
|
||||
@ -24,30 +24,23 @@ package com.github.prominence.openweathermap.api.mapper;
|
||||
|
||||
import com.fasterxml.jackson.databind.InjectableValues;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.github.prominence.openweathermap.api.deserializer.AtmosphericPressureDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.TemperatureDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.WeatherStateDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.WindDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.*;
|
||||
import com.github.prominence.openweathermap.api.deserializer.forecast.free.FreeForecastLocationDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.forecast.free.FreeForecastRainDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.forecast.free.FreeForecastSnowDeserializer;
|
||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||
import com.github.prominence.openweathermap.api.model.*;
|
||||
import com.github.prominence.openweathermap.api.model.forecast.free.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Official API response documentation: <a href="https://openweathermap.org/forecast5#JSON">https://openweathermap.org/forecast5#JSON</a>.
|
||||
*/
|
||||
public class FiveDayThreeHourStepForecastResponseMapper {
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
public class FiveDayThreeHourStepForecastResponseMapper extends AbstractMapper {
|
||||
/**
|
||||
* Instantiates a new forecast response mapper.
|
||||
*
|
||||
@ -59,7 +52,12 @@ public class FiveDayThreeHourStepForecastResponseMapper {
|
||||
module.addDeserializer(WeatherState.class, new WeatherStateDeserializer());
|
||||
module.addDeserializer(Temperature.class, new TemperatureDeserializer());
|
||||
module.addDeserializer(AtmosphericPressure.class, new AtmosphericPressureDeserializer());
|
||||
module.addDeserializer(Humidity.class, new HumidityDeserializer());
|
||||
module.addDeserializer(Clouds.class, new CloudsDeserializer());
|
||||
module.addDeserializer(Wind.class, new WindDeserializer());
|
||||
module.addDeserializer(Rain.class, new FreeForecastRainDeserializer());
|
||||
module.addDeserializer(Snow.class, new FreeForecastSnowDeserializer());
|
||||
module.addDeserializer(Location.class, new FreeForecastLocationDeserializer());
|
||||
objectMapper.registerModule(module);
|
||||
|
||||
}
|
||||
@ -83,13 +81,13 @@ public class FiveDayThreeHourStepForecastResponseMapper {
|
||||
return forecast;
|
||||
}
|
||||
|
||||
private Forecast mapToForecast(JsonNode root) throws IOException {
|
||||
private Forecast mapToForecast(JsonNode rootNode) throws IOException {
|
||||
final Forecast forecast = new Forecast();
|
||||
forecast.setLocation(parseLocation(root.get("city")));
|
||||
forecast.setLocation(objectMapper.readValue(objectMapper.treeAsTokens(rootNode.get("city")), Location.class));
|
||||
|
||||
final List<WeatherForecast> forecasts = new ArrayList<>(root.get("cnt").asInt());
|
||||
final List<WeatherForecast> forecasts = new ArrayList<>(rootNode.get("cnt").asInt());
|
||||
|
||||
final JsonNode forecastListNode = root.get("list");
|
||||
final JsonNode forecastListNode = rootNode.get("list");
|
||||
for (JsonNode forecastNode : forecastListNode) {
|
||||
forecasts.add(parseWeatherForecast(forecastNode));
|
||||
}
|
||||
@ -102,128 +100,38 @@ public class FiveDayThreeHourStepForecastResponseMapper {
|
||||
private WeatherForecast parseWeatherForecast(JsonNode rootNode) throws IOException {
|
||||
final WeatherForecast weatherForecast = new WeatherForecast();
|
||||
final JsonNode weatherArrayNode = rootNode.get("weather");
|
||||
if (weatherArrayNode != null) {
|
||||
final JsonNode weatherNode = weatherArrayNode.get(0);
|
||||
weatherForecast.setWeatherState(parseWeatherState(weatherNode));
|
||||
}
|
||||
weatherForecast.setWeatherStates(parseWeatherStates(weatherArrayNode));
|
||||
|
||||
final JsonNode mainNode = rootNode.get("main");
|
||||
weatherForecast.setTemperature(parseTemperature(mainNode));
|
||||
weatherForecast.setAtmosphericPressure(parsePressure(mainNode));
|
||||
weatherForecast.setHumidity(parseHumidity(mainNode));
|
||||
weatherForecast.setClouds(parseClouds(rootNode));
|
||||
weatherForecast.setWind(parseWind(rootNode));
|
||||
weatherForecast.setRain(parseRain(rootNode));
|
||||
weatherForecast.setSnow(parseSnow(rootNode));
|
||||
weatherForecast.setTemperature(objectMapper.readValue(objectMapper.treeAsTokens(mainNode), Temperature.class));
|
||||
weatherForecast.setAtmosphericPressure(objectMapper.readValue(objectMapper.treeAsTokens(mainNode), AtmosphericPressure.class));
|
||||
weatherForecast.setHumidity(objectMapper.readValue(objectMapper.treeAsTokens(mainNode), Humidity.class));
|
||||
weatherForecast.setClouds(objectMapper.readValue(objectMapper.treeAsTokens(rootNode.get("clouds")), Clouds.class));
|
||||
weatherForecast.setWind(objectMapper.readValue(objectMapper.treeAsTokens(rootNode.get("wind")), Wind.class));
|
||||
if (rootNode.has("rain")) {
|
||||
weatherForecast.setRain(objectMapper.readValue(objectMapper.treeAsTokens(rootNode.get("rain")), Rain.class));
|
||||
}
|
||||
if (rootNode.has("snow")) {
|
||||
weatherForecast.setSnow(objectMapper.readValue(objectMapper.treeAsTokens(rootNode.get("snow")), Snow.class));
|
||||
}
|
||||
|
||||
final JsonNode sysNode = rootNode.get("sys");
|
||||
if (sysNode != null) {
|
||||
weatherForecast.setDayTime("d".equals(sysNode.get("pod").asText()) ? DayTime.DAY : DayTime.NIGHT);
|
||||
}
|
||||
|
||||
weatherForecast.setForecastTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(rootNode.get("dt").asLong()), TimeZone.getDefault().toZoneId()));
|
||||
final JsonNode visibilityNode = rootNode.get("visibility");
|
||||
if (visibilityNode != null) {
|
||||
weatherForecast.setVisibilityInMetres(visibilityNode.asDouble());
|
||||
}
|
||||
final JsonNode popNode = rootNode.get("pop");
|
||||
if (popNode != null) {
|
||||
weatherForecast.setProbabilityOfPrecipitation(popNode.asDouble());
|
||||
}
|
||||
|
||||
weatherForecast.setForecastTime(parseDateTime(rootNode.get("dt")));
|
||||
weatherForecast.setForecastTimeISO(rootNode.get("dt_txt").asText());
|
||||
|
||||
return weatherForecast;
|
||||
}
|
||||
|
||||
private WeatherState parseWeatherState(JsonNode weatherNode) throws IOException {
|
||||
if (weatherNode == null) {
|
||||
return null;
|
||||
}
|
||||
return objectMapper.readValue(objectMapper.treeAsTokens(weatherNode), WeatherState.class);
|
||||
}
|
||||
|
||||
private Temperature parseTemperature(JsonNode rootNode) throws IOException {
|
||||
return objectMapper.readValue(objectMapper.treeAsTokens(rootNode), Temperature.class);
|
||||
}
|
||||
|
||||
private AtmosphericPressure parsePressure(JsonNode rootNode) throws IOException {
|
||||
return objectMapper.readValue(objectMapper.treeAsTokens(rootNode), AtmosphericPressure.class);
|
||||
}
|
||||
|
||||
private Humidity parseHumidity(JsonNode rootNode) {
|
||||
return Humidity.withValue((byte) (rootNode.get("humidity").asInt()));
|
||||
}
|
||||
|
||||
private Wind parseWind(JsonNode root) throws IOException {
|
||||
final JsonNode windNode = root.get("wind");
|
||||
return objectMapper.readValue(objectMapper.treeAsTokens(windNode), Wind.class);
|
||||
}
|
||||
|
||||
private Rain parseRain(JsonNode root) {
|
||||
final JsonNode rainNode = root.get("rain");
|
||||
if (rainNode != null) {
|
||||
final JsonNode threeHourNode = rainNode.get("3h");
|
||||
if (threeHourNode != null) {
|
||||
return Rain.withThreeHourLevelValue(threeHourNode.asDouble());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Snow parseSnow(JsonNode root) {
|
||||
final JsonNode snowNode = root.get("snow");
|
||||
if (snowNode != null) {
|
||||
final JsonNode threeHourNode = snowNode.get("3h");
|
||||
if (threeHourNode != null) {
|
||||
return Snow.withThreeHourLevelValue(threeHourNode.asDouble());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Clouds parseClouds(JsonNode rootNode) {
|
||||
final JsonNode cloudsNode = rootNode.get("clouds");
|
||||
final JsonNode allValueNode = cloudsNode.get("all");
|
||||
if (allValueNode != null) {
|
||||
return Clouds.withValue((byte) allValueNode.asInt());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Location parseLocation(JsonNode rootNode) {
|
||||
final Location location = Location.withValues(rootNode.get("id").asInt(), rootNode.get("name").asText());
|
||||
|
||||
final JsonNode timezoneNode = rootNode.get("timezone");
|
||||
if (timezoneNode != null) {
|
||||
location.setZoneOffset(ZoneOffset.ofTotalSeconds(timezoneNode.asInt()));
|
||||
}
|
||||
|
||||
final JsonNode countryNode = rootNode.get("country");
|
||||
if (countryNode != null) {
|
||||
location.setCountryCode(countryNode.asText());
|
||||
}
|
||||
|
||||
final JsonNode sunriseNode = rootNode.get("sunrise");
|
||||
final JsonNode sunsetNode = rootNode.get("sunset");
|
||||
if (sunriseNode != null) {
|
||||
location.setSunriseTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(sunriseNode.asLong()), TimeZone.getDefault().toZoneId()));
|
||||
}
|
||||
if (sunsetNode != null) {
|
||||
location.setSunsetTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(sunsetNode.asLong()), TimeZone.getDefault().toZoneId()));
|
||||
}
|
||||
|
||||
final JsonNode coordNode = rootNode.get("coord");
|
||||
if (coordNode != null) {
|
||||
location.setCoordinate(parseCoordinate(coordNode));
|
||||
}
|
||||
|
||||
final JsonNode populationNode = rootNode.get("population");
|
||||
if (populationNode != null) {
|
||||
location.setPopulation(populationNode.asLong());
|
||||
}
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
private Coordinates parseCoordinate(JsonNode rootNode) {
|
||||
final JsonNode latitudeNode = rootNode.get("lat");
|
||||
final JsonNode longitudeNode = rootNode.get("lon");
|
||||
if (latitudeNode != null && longitudeNode != null) {
|
||||
return Coordinates.of(latitudeNode.asDouble(), longitudeNode.asDouble());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,7 +111,7 @@ public class OneCallWeatherResponseMapper extends AbstractMapper {
|
||||
|
||||
private CurrentWeatherData mapToCurrent(JsonNode rootNode) throws IOException {
|
||||
final CurrentWeatherData currentData = new CurrentWeatherData();
|
||||
currentData.setCoordinate(objectMapper.readValue(objectMapper.treeAsTokens(rootNode), Coordinates.class));
|
||||
currentData.setCoordinates(objectMapper.readValue(objectMapper.treeAsTokens(rootNode), Coordinates.class));
|
||||
currentData.setTimezone(parseZoneId(rootNode.get("timezone")));
|
||||
currentData.setTimezoneOffset(parseZoneOffset(rootNode.get("timezone_offset")));
|
||||
|
||||
@ -261,7 +261,7 @@ public class OneCallWeatherResponseMapper extends AbstractMapper {
|
||||
|
||||
private HistoricalWeatherData mapToHistorical(JsonNode rootNode) throws IOException {
|
||||
final HistoricalWeatherData historicalData = new HistoricalWeatherData();
|
||||
historicalData.setCoordinate(Coordinates.of(rootNode.get("lat").asDouble(), rootNode.get("lon").asDouble()));
|
||||
historicalData.setCoordinates(Coordinates.of(rootNode.get("lat").asDouble(), rootNode.get("lon").asDouble()));
|
||||
historicalData.setTimezone(parseZoneId(rootNode.get("timezone")));
|
||||
historicalData.setTimezoneOffset(parseZoneOffset(rootNode.get("timezone_offset")));
|
||||
historicalData.setHistoricalWeather(parseHistoricalWeather(rootNode.get("current")));
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
package com.github.prominence.openweathermap.api.mapper;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.github.prominence.openweathermap.api.deserializer.CoordinatesDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.radiation.SolarRadiationRecordDeserializer;
|
||||
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||
import com.github.prominence.openweathermap.api.model.radiation.SolarRadiation;
|
||||
import com.github.prominence.openweathermap.api.model.radiation.SolarRadiationRecord;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SolarRadiationResponseMapper extends AbstractMapper {
|
||||
|
||||
public SolarRadiationResponseMapper() {
|
||||
final SimpleModule module = new SimpleModule();
|
||||
module.addDeserializer(SolarRadiationRecord.class, new SolarRadiationRecordDeserializer());
|
||||
module.addDeserializer(Coordinates.class, new CoordinatesDeserializer());
|
||||
objectMapper.registerModule(module);
|
||||
}
|
||||
|
||||
public SolarRadiation mapToObject(String jsonResponse) {
|
||||
SolarRadiation solarRadiation;
|
||||
try {
|
||||
final JsonNode root = objectMapper.readTree(jsonResponse);
|
||||
solarRadiation = mapToObject(root);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Cannot parse SolarRadiation response", e);
|
||||
}
|
||||
|
||||
return solarRadiation;
|
||||
}
|
||||
|
||||
private SolarRadiation mapToObject(JsonNode rootNode) throws IOException {
|
||||
final SolarRadiation solarRadiation = new SolarRadiation();
|
||||
solarRadiation.setCoordinates(objectMapper.readValue(objectMapper.treeAsTokens(rootNode.get("coord")), Coordinates.class));
|
||||
|
||||
final JsonNode listRecordsNode = rootNode.get("list");
|
||||
List<SolarRadiationRecord> radiationRecords = new ArrayList<>();
|
||||
for (JsonNode recordNode : listRecordsNode) {
|
||||
radiationRecords.add(objectMapper.readValue(objectMapper.treeAsTokens(recordNode), SolarRadiationRecord.class));
|
||||
}
|
||||
solarRadiation.setSolarRadiationRecords(radiationRecords);
|
||||
|
||||
return solarRadiation;
|
||||
}
|
||||
}
|
||||
@ -41,7 +41,7 @@ public class AirPollutionDetails {
|
||||
*
|
||||
* @return the coordinate
|
||||
*/
|
||||
public Coordinates getCoordinate() {
|
||||
public Coordinates getCoordinates() {
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ public class AirPollutionDetails {
|
||||
*
|
||||
* @param coordinates the coordinate
|
||||
*/
|
||||
public void setCoordinate(Coordinates coordinates) {
|
||||
public void setCoordinates(Coordinates coordinates) {
|
||||
this.coordinates = coordinates;
|
||||
}
|
||||
|
||||
|
||||
@ -127,7 +127,7 @@ public class Location {
|
||||
* Returns location coordinates.
|
||||
* @return location coordinates.
|
||||
*/
|
||||
public Coordinates getCoordinate() {
|
||||
public Coordinates getCoordinates() {
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ public class Location {
|
||||
* Sets location coordinates.
|
||||
* @param coordinates location coordinates
|
||||
*/
|
||||
public void setCoordinate(Coordinates coordinates) {
|
||||
public void setCoordinates(Coordinates coordinates) {
|
||||
this.coordinates = coordinates;
|
||||
}
|
||||
|
||||
|
||||
@ -127,7 +127,7 @@ public class Location {
|
||||
* Returns location coordinates.
|
||||
* @return location coordinates.
|
||||
*/
|
||||
public Coordinates getCoordinate() {
|
||||
public Coordinates getCoordinates() {
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ public class Location {
|
||||
* Sets location coordinates.
|
||||
* @param coordinates location coordinates
|
||||
*/
|
||||
public void setCoordinate(Coordinates coordinates) {
|
||||
public void setCoordinates(Coordinates coordinates) {
|
||||
this.coordinates = coordinates;
|
||||
}
|
||||
|
||||
|
||||
@ -162,7 +162,7 @@ public class Location {
|
||||
* Returns location coordinates.
|
||||
* @return location coordinates.
|
||||
*/
|
||||
public Coordinates getCoordinate() {
|
||||
public Coordinates getCoordinates() {
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
@ -170,7 +170,7 @@ public class Location {
|
||||
* Sets location coordinates.
|
||||
* @param coordinates location coordinates
|
||||
*/
|
||||
public void setCoordinate(Coordinates coordinates) {
|
||||
public void setCoordinates(Coordinates coordinates) {
|
||||
this.coordinates = coordinates;
|
||||
}
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@ package com.github.prominence.openweathermap.api.model.forecast.free;
|
||||
import com.github.prominence.openweathermap.api.model.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@ -33,7 +34,7 @@ import java.util.Objects;
|
||||
public class WeatherForecast {
|
||||
private LocalDateTime forecastTime;
|
||||
|
||||
private WeatherState weatherState;
|
||||
private List<WeatherState> weatherStates;
|
||||
private Temperature temperature;
|
||||
private AtmosphericPressure atmosphericPressure;
|
||||
private Humidity humidity;
|
||||
@ -46,6 +47,9 @@ public class WeatherForecast {
|
||||
private String forecastTimeISO;
|
||||
private DayTime dayTime;
|
||||
|
||||
private Double visibilityInMetres;
|
||||
private Double probabilityOfPrecipitation;
|
||||
|
||||
/**
|
||||
* Gets forecast time.
|
||||
*
|
||||
@ -69,17 +73,17 @@ public class WeatherForecast {
|
||||
*
|
||||
* @return the weather state
|
||||
*/
|
||||
public WeatherState getWeatherState() {
|
||||
return weatherState;
|
||||
public List<WeatherState> getWeatherStates() {
|
||||
return weatherStates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets weather state.
|
||||
*
|
||||
* @param weatherState the weather state
|
||||
* @param weatherStates the weather state
|
||||
*/
|
||||
public void setWeatherState(WeatherState weatherState) {
|
||||
this.weatherState = weatherState;
|
||||
public void setWeatherStates(List<WeatherState> weatherStates) {
|
||||
this.weatherStates = weatherStates;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -244,13 +248,29 @@ public class WeatherForecast {
|
||||
this.dayTime = dayTime;
|
||||
}
|
||||
|
||||
public Double getVisibilityInMetres() {
|
||||
return visibilityInMetres;
|
||||
}
|
||||
|
||||
public void setVisibilityInMetres(Double visibilityInMetres) {
|
||||
this.visibilityInMetres = visibilityInMetres;
|
||||
}
|
||||
|
||||
public Double getProbabilityOfPrecipitation() {
|
||||
return probabilityOfPrecipitation;
|
||||
}
|
||||
|
||||
public void setProbabilityOfPrecipitation(Double probabilityOfPrecipitation) {
|
||||
this.probabilityOfPrecipitation = probabilityOfPrecipitation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
WeatherForecast that = (WeatherForecast) o;
|
||||
return Objects.equals(forecastTime, that.forecastTime) &&
|
||||
Objects.equals(weatherState, that.weatherState) &&
|
||||
Objects.equals(weatherStates, that.weatherStates) &&
|
||||
Objects.equals(temperature, that.temperature) &&
|
||||
Objects.equals(atmosphericPressure, that.atmosphericPressure) &&
|
||||
Objects.equals(humidity, that.humidity) &&
|
||||
@ -259,12 +279,14 @@ public class WeatherForecast {
|
||||
Objects.equals(snow, that.snow) &&
|
||||
Objects.equals(clouds, that.clouds) &&
|
||||
Objects.equals(forecastTimeISO, that.forecastTimeISO) &&
|
||||
Objects.equals(visibilityInMetres, that.visibilityInMetres) &&
|
||||
Objects.equals(probabilityOfPrecipitation, that.probabilityOfPrecipitation) &&
|
||||
dayTime == that.dayTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(forecastTime, weatherState, temperature, atmosphericPressure, humidity, wind, rain, snow, clouds, forecastTimeISO, dayTime);
|
||||
return Objects.hash(forecastTime, weatherStates, temperature, atmosphericPressure, humidity, wind, rain, snow, clouds, forecastTimeISO, visibilityInMetres, probabilityOfPrecipitation, dayTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -272,9 +294,9 @@ public class WeatherForecast {
|
||||
final StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("Timestamp: ");
|
||||
stringBuilder.append(forecastTimeISO);
|
||||
if (weatherState != null) {
|
||||
if (weatherStates != null && weatherStates.size() > 0) {
|
||||
stringBuilder.append(", Weather: ");
|
||||
stringBuilder.append(weatherState.getDescription());
|
||||
stringBuilder.append(weatherStates.get(0).getDescription());
|
||||
}
|
||||
if (temperature != null) {
|
||||
stringBuilder.append(", ");
|
||||
|
||||
@ -160,7 +160,7 @@ public class Location {
|
||||
* Returns location coordinates.
|
||||
* @return location coordinates.
|
||||
*/
|
||||
public Coordinates getCoordinate() {
|
||||
public Coordinates getCoordinates() {
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
@ -168,7 +168,7 @@ public class Location {
|
||||
* Sets location coordinates.
|
||||
* @param coordinates location coordinates
|
||||
*/
|
||||
public void setCoordinate(Coordinates coordinates) {
|
||||
public void setCoordinates(Coordinates coordinates) {
|
||||
this.coordinates = coordinates;
|
||||
}
|
||||
@Override
|
||||
|
||||
@ -49,7 +49,7 @@ public class CurrentWeatherData {
|
||||
*
|
||||
* @return the coordinate
|
||||
*/
|
||||
public Coordinates getCoordinate() {
|
||||
public Coordinates getCoordinates() {
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ public class CurrentWeatherData {
|
||||
*
|
||||
* @param coordinates the coordinate
|
||||
*/
|
||||
public void setCoordinate(Coordinates coordinates) {
|
||||
public void setCoordinates(Coordinates coordinates) {
|
||||
this.coordinates = coordinates;
|
||||
}
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ public class HistoricalWeatherData {
|
||||
*
|
||||
* @return the coordinate
|
||||
*/
|
||||
public Coordinates getCoordinate() {
|
||||
public Coordinates getCoordinates() {
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ public class HistoricalWeatherData {
|
||||
*
|
||||
* @param coordinates the coordinate
|
||||
*/
|
||||
public void setCoordinate(Coordinates coordinates) {
|
||||
public void setCoordinates(Coordinates coordinates) {
|
||||
this.coordinates = coordinates;
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,48 @@
|
||||
package com.github.prominence.openweathermap.api.model.radiation;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class SolarRadiation {
|
||||
private Coordinates coordinates;
|
||||
List<SolarRadiationRecord> solarRadiationRecords;
|
||||
|
||||
public Coordinates getCoordinates() {
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
public void setCoordinates(Coordinates coordinates) {
|
||||
this.coordinates = coordinates;
|
||||
}
|
||||
|
||||
public List<SolarRadiationRecord> getSolarRadiationRecords() {
|
||||
return solarRadiationRecords;
|
||||
}
|
||||
|
||||
public void setSolarRadiationRecords(List<SolarRadiationRecord> solarRadiationRecords) {
|
||||
this.solarRadiationRecords = solarRadiationRecords;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
SolarRadiation that = (SolarRadiation) o;
|
||||
return Objects.equals(coordinates, that.coordinates) && Objects.equals(solarRadiationRecords, that.solarRadiationRecords);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(coordinates, solarRadiationRecords);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SolarRadiation{" +
|
||||
"coordinates=" + coordinates +
|
||||
", solarRadiationRecords=" + solarRadiationRecords +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,98 @@
|
||||
package com.github.prominence.openweathermap.api.model.radiation;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
public class SolarRadiationRecord {
|
||||
private LocalDateTime measurementTime;
|
||||
|
||||
private Double ghi;
|
||||
private Double dni;
|
||||
private Double dhi;
|
||||
|
||||
private Double ghi_cs;
|
||||
private Double dni_cs;
|
||||
private Double dhi_cs;
|
||||
|
||||
public LocalDateTime getMeasurementTime() {
|
||||
return measurementTime;
|
||||
}
|
||||
|
||||
public void setMeasurementTime(LocalDateTime measurementTime) {
|
||||
this.measurementTime = measurementTime;
|
||||
}
|
||||
|
||||
public Double getCloudSkyGlobalHorizontalIrradiance() {
|
||||
return ghi;
|
||||
}
|
||||
|
||||
public void setCloudSkyGlobalHorizontalIrradiance(Double ghi) {
|
||||
this.ghi = ghi;
|
||||
}
|
||||
|
||||
public Double getCloudSkyDirectNormalIrradiance() {
|
||||
return dni;
|
||||
}
|
||||
|
||||
public void setCloudSkyDirectNormalIrradiance(Double dni) {
|
||||
this.dni = dni;
|
||||
}
|
||||
|
||||
public Double getCloudSkyDiffuseHorizontalIrradiance() {
|
||||
return dhi;
|
||||
}
|
||||
|
||||
public void setCloudSkyDiffuseHorizontalIrradiance(Double dhi) {
|
||||
this.dhi = dhi;
|
||||
}
|
||||
|
||||
public Double getClearSkyGlobalHorizontalIrradiance() {
|
||||
return ghi_cs;
|
||||
}
|
||||
|
||||
public void setClearSkyGlobalHorizontalIrradiance(Double ghi_cs) {
|
||||
this.ghi_cs = ghi_cs;
|
||||
}
|
||||
|
||||
public Double getClearSkyDirectNormalIrradiance() {
|
||||
return dni_cs;
|
||||
}
|
||||
|
||||
public void setClearSkyDirectNormalIrradiance(Double dni_cs) {
|
||||
this.dni_cs = dni_cs;
|
||||
}
|
||||
|
||||
public Double getClearSkyDiffuseHorizontalIrradiance() {
|
||||
return dhi_cs;
|
||||
}
|
||||
|
||||
public void setClearSkyDiffuseHorizontalIrradiance(Double dhi_cs) {
|
||||
this.dhi_cs = dhi_cs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
SolarRadiationRecord that = (SolarRadiationRecord) o;
|
||||
return Objects.equals(measurementTime, that.measurementTime) && Objects.equals(ghi, that.ghi) && Objects.equals(dni, that.dni) && Objects.equals(dhi, that.dhi) && Objects.equals(ghi_cs, that.ghi_cs) && Objects.equals(dni_cs, that.dni_cs) && Objects.equals(dhi_cs, that.dhi_cs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(measurementTime, ghi, dni, dhi, ghi_cs, dni_cs, dhi_cs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SolarRadiationRecord{" +
|
||||
"measurementTime=" + measurementTime +
|
||||
", ghi=" + ghi +
|
||||
", dni=" + dni +
|
||||
", dhi=" + dhi +
|
||||
", ghi_cs=" + ghi_cs +
|
||||
", dni_cs=" + dni_cs +
|
||||
", dhi_cs=" + dhi_cs +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -174,7 +174,7 @@ public class Location {
|
||||
*
|
||||
* @return location coordinates.
|
||||
*/
|
||||
public Coordinates getCoordinate() {
|
||||
public Coordinates getCoordinates() {
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
@ -183,7 +183,7 @@ public class Location {
|
||||
*
|
||||
* @param coordinates location coordinates
|
||||
*/
|
||||
public void setCoordinate(Coordinates coordinates) {
|
||||
public void setCoordinates(Coordinates coordinates) {
|
||||
this.coordinates = coordinates;
|
||||
}
|
||||
|
||||
|
||||
@ -46,16 +46,19 @@ public class FiveDayThreeHourStepForecastRequester {
|
||||
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode) {
|
||||
requestSettings.putRequestParameter("q", cityName + "," + stateCode);
|
||||
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode, String countryCode) {
|
||||
requestSettings.putRequestParameter("q", cityName + "," + stateCode + "," + countryCode);
|
||||
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public FiveDayThreeHourStepForecastRequestCustomizer byCityId(long cityId) {
|
||||
requestSettings.putRequestParameter("id", Long.toString(cityId));
|
||||
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
||||
@ -67,11 +70,13 @@ public class FiveDayThreeHourStepForecastRequester {
|
||||
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public FiveDayThreeHourStepForecastRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode) {
|
||||
requestSettings.putRequestParameter("zip", zipCode + "," + countryCode);
|
||||
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public FiveDayThreeHourStepForecastRequestCustomizer byZipCodeInUSA(String zipCode) {
|
||||
requestSettings.putRequestParameter("zip", zipCode);
|
||||
return new FiveDayThreeHourStepForecastRequestCustomizer(requestSettings);
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
package com.github.prominence.openweathermap.api.request.radiation;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||
|
||||
public class CurrentSolarRadiationRequester {
|
||||
private final RequestSettings requestSettings;
|
||||
|
||||
public CurrentSolarRadiationRequester(RequestSettings requestSettings) {
|
||||
this.requestSettings = requestSettings;
|
||||
}
|
||||
|
||||
public SolarRadiationRequestCustomizer byCoordinates(Coordinates coordinates) {
|
||||
requestSettings.putRequestParameter("lat", String.valueOf(coordinates.getLatitude()));
|
||||
requestSettings.putRequestParameter("lon", String.valueOf(coordinates.getLongitude()));
|
||||
return new SolarRadiationRequestCustomizer(requestSettings);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package com.github.prominence.openweathermap.api.request.radiation;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||
|
||||
public class ForecastSolarRadiationRequester {
|
||||
private final RequestSettings requestSettings;
|
||||
|
||||
public ForecastSolarRadiationRequester(RequestSettings requestSettings) {
|
||||
this.requestSettings = requestSettings;
|
||||
}
|
||||
|
||||
public SolarRadiationRequestCustomizer byCoordinates(Coordinates coordinates) {
|
||||
requestSettings.putRequestParameter("lat", String.valueOf(coordinates.getLatitude()));
|
||||
requestSettings.putRequestParameter("lon", String.valueOf(coordinates.getLongitude()));
|
||||
return new SolarRadiationRequestCustomizer(requestSettings);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
package com.github.prominence.openweathermap.api.request.radiation;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
|
||||
public class HistoricalSolarRadiationRequester {
|
||||
private final RequestSettings requestSettings;
|
||||
|
||||
public HistoricalSolarRadiationRequester(RequestSettings requestSettings) {
|
||||
this.requestSettings = requestSettings;
|
||||
}
|
||||
|
||||
public SolarRadiationRequestCustomizer byCoordinates(Coordinates coordinates, LocalDateTime startDate, LocalDateTime endDate) {
|
||||
requestSettings.putRequestParameter("lat", String.valueOf(coordinates.getLatitude()));
|
||||
requestSettings.putRequestParameter("lon", String.valueOf(coordinates.getLongitude()));
|
||||
requestSettings.putRequestParameter("start", String.valueOf(startDate.atZone(ZoneId.systemDefault()).toEpochSecond()));
|
||||
requestSettings.putRequestParameter("end", String.valueOf(endDate.atZone(ZoneId.systemDefault()).toEpochSecond()));
|
||||
return new SolarRadiationRequestCustomizer(requestSettings);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Alexey Zinchenko
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.request.radiation;
|
||||
|
||||
import com.github.prominence.openweathermap.api.mapper.SolarRadiationResponseMapper;
|
||||
import com.github.prominence.openweathermap.api.model.radiation.SolarRadiation;
|
||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
class SolarRadiationAsyncRequestTerminator {
|
||||
private final RequestSettings requestSettings;
|
||||
|
||||
public SolarRadiationAsyncRequestTerminator(RequestSettings requestSettings) {
|
||||
this.requestSettings = requestSettings;
|
||||
}
|
||||
|
||||
public CompletableFuture<SolarRadiation> asJava() {
|
||||
return CompletableFuture.supplyAsync(() -> new SolarRadiationResponseMapper().mapToObject(getRawResponse()));
|
||||
}
|
||||
|
||||
public CompletableFuture<String> asJSON() {
|
||||
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||
}
|
||||
|
||||
private String getRawResponse() {
|
||||
return RequestUtils.getResponse(requestSettings);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.github.prominence.openweathermap.api.request.radiation;
|
||||
|
||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||
|
||||
public class SolarRadiationRequestCustomizer {
|
||||
private final RequestSettings requestSettings;
|
||||
|
||||
public SolarRadiationRequestCustomizer(RequestSettings requestSettings) {
|
||||
this.requestSettings = requestSettings;
|
||||
}
|
||||
|
||||
public SolarRadiationRequestTerminator retrieve() {
|
||||
return new SolarRadiationRequestTerminator(requestSettings);
|
||||
}
|
||||
|
||||
public SolarRadiationAsyncRequestTerminator retrieveAsync() {
|
||||
return new SolarRadiationAsyncRequestTerminator(requestSettings);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Alexey Zinchenko
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.request.radiation;
|
||||
|
||||
import com.github.prominence.openweathermap.api.mapper.SolarRadiationResponseMapper;
|
||||
import com.github.prominence.openweathermap.api.model.radiation.SolarRadiation;
|
||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||
|
||||
class SolarRadiationRequestTerminator {
|
||||
private final RequestSettings requestSettings;
|
||||
|
||||
public SolarRadiationRequestTerminator(RequestSettings requestSettings) {
|
||||
this.requestSettings = requestSettings;
|
||||
}
|
||||
|
||||
public SolarRadiation asJava() {
|
||||
return new SolarRadiationResponseMapper().mapToObject(getRawResponse());
|
||||
}
|
||||
|
||||
public String asJSON() {
|
||||
return getRawResponse();
|
||||
}
|
||||
|
||||
private String getRawResponse() {
|
||||
return RequestUtils.getResponse(requestSettings);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package com.github.prominence.openweathermap.api.request.radiation;
|
||||
|
||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||
|
||||
public class SolarRadiationRequester {
|
||||
private final RequestSettings requestSettings;
|
||||
|
||||
public SolarRadiationRequester(RequestSettings requestSettings) {
|
||||
this.requestSettings = requestSettings;
|
||||
this.requestSettings.appendToURL("data/2.5/solar_radiation");
|
||||
}
|
||||
|
||||
public CurrentSolarRadiationRequester current() {
|
||||
return new CurrentSolarRadiationRequester(requestSettings);
|
||||
}
|
||||
|
||||
public ForecastSolarRadiationRequester forecast() {
|
||||
requestSettings.appendToURL("/forecast");
|
||||
return new ForecastSolarRadiationRequester(requestSettings);
|
||||
}
|
||||
|
||||
public HistoricalSolarRadiationRequester historical() {
|
||||
requestSettings.appendToURL("/history");
|
||||
return new HistoricalSolarRadiationRequester(requestSettings);
|
||||
}
|
||||
}
|
||||
@ -72,7 +72,7 @@ class ClimaticForecastResponseMapperTest {
|
||||
|
||||
final Location location = forecast.getLocation();
|
||||
assertNotNull(location);
|
||||
assertEquals(Coordinates.of(51.5073, -0.1277), location.getCoordinate());
|
||||
assertEquals(Coordinates.of(51.5073, -0.1277), location.getCoordinates());
|
||||
assertEquals(2643743, location.getId());
|
||||
assertEquals("London", location.getName());
|
||||
assertEquals("GB", location.getCountryCode());
|
||||
|
||||
@ -1096,7 +1096,7 @@ public class CurrentWeatherResponseMapperTest {
|
||||
|
||||
Weather weather = mapper.mapToWeather(jsonString);
|
||||
|
||||
assertNotNull(weather.getLocation().getCoordinate());
|
||||
assertNotNull(weather.getLocation().getCoordinates());
|
||||
assertNotNull(weather.getLocation().getCountryCode());
|
||||
|
||||
// without coordinates and country code
|
||||
@ -1144,7 +1144,7 @@ public class CurrentWeatherResponseMapperTest {
|
||||
}
|
||||
""";
|
||||
weather = mapper.mapToWeather(jsonString);
|
||||
assertNull(weather.getLocation().getCoordinate());
|
||||
assertNull(weather.getLocation().getCoordinates());
|
||||
assertNull(weather.getLocation().getCountryCode());
|
||||
|
||||
// coordinates without latitude
|
||||
@ -1196,7 +1196,7 @@ public class CurrentWeatherResponseMapperTest {
|
||||
}
|
||||
""";
|
||||
weather = mapper.mapToWeather(jsonString);
|
||||
assertNull(weather.getLocation().getCoordinate());
|
||||
assertNull(weather.getLocation().getCoordinates());
|
||||
assertNotNull(weather.getLocation().getCountryCode());
|
||||
|
||||
// coordinates without longitude
|
||||
@ -1248,7 +1248,7 @@ public class CurrentWeatherResponseMapperTest {
|
||||
}
|
||||
""";
|
||||
weather = mapper.mapToWeather(jsonString);
|
||||
assertNull(weather.getLocation().getCoordinate());
|
||||
assertNull(weather.getLocation().getCoordinates());
|
||||
assertNotNull(weather.getLocation().getCountryCode());
|
||||
}
|
||||
}
|
||||
@ -79,7 +79,7 @@ class DailyForecastResponseMapperTest {
|
||||
|
||||
final Location location = forecast.getLocation();
|
||||
assertNotNull(location);
|
||||
assertEquals(Coordinates.of(51.5085, -0.1258), location.getCoordinate());
|
||||
assertEquals(Coordinates.of(51.5085, -0.1258), location.getCoordinates());
|
||||
assertEquals(2643743, location.getId());
|
||||
assertEquals("London", location.getName());
|
||||
assertEquals("GB", location.getCountryCode());
|
||||
|
||||
@ -0,0 +1,183 @@
|
||||
package com.github.prominence.openweathermap.api.mapper;
|
||||
|
||||
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||
import com.github.prominence.openweathermap.api.model.*;
|
||||
import com.github.prominence.openweathermap.api.model.forecast.free.*;
|
||||
import com.github.prominence.openweathermap.api.utils.TestMappingUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class FiveDayThreeHourStepForecastResponseMapperTest {
|
||||
|
||||
@Test
|
||||
void mapToForecast() {
|
||||
final String jsonResponse = """
|
||||
{
|
||||
"cod": "200",
|
||||
"message": 0,
|
||||
"cnt": 40,
|
||||
"list": [
|
||||
{
|
||||
"dt": 1647345600,
|
||||
"main": {
|
||||
"temp": 286.88,
|
||||
"feels_like": 285.93,
|
||||
"temp_min": 286.74,
|
||||
"temp_max": 286.88,
|
||||
"pressure": 1021,
|
||||
"sea_level": 1021,
|
||||
"grnd_level": 1018,
|
||||
"humidity": 62,
|
||||
"temp_kf": 0.14
|
||||
},
|
||||
"weather": [
|
||||
{
|
||||
"id": 804,
|
||||
"main": "Clouds",
|
||||
"description": "overcast clouds",
|
||||
"icon": "04d"
|
||||
}
|
||||
],
|
||||
"clouds": {
|
||||
"all": 85
|
||||
},
|
||||
"wind": {
|
||||
"speed": 3.25,
|
||||
"deg": 134,
|
||||
"gust": 4.45
|
||||
},
|
||||
"visibility": 10000,
|
||||
"pop": 0,
|
||||
"sys": {
|
||||
"pod": "d"
|
||||
},
|
||||
"rain": {
|
||||
"3h": 22.1
|
||||
},
|
||||
"snow": {
|
||||
"3h": 13.6
|
||||
},
|
||||
"dt_txt": "2022-03-15 12:00:00"
|
||||
},
|
||||
{
|
||||
"dt": 1647356400,
|
||||
"main": {
|
||||
"temp": 286.71,
|
||||
"feels_like": 285.77,
|
||||
"temp_min": 286.38,
|
||||
"temp_max": 286.71,
|
||||
"pressure": 1021,
|
||||
"sea_level": 1021,
|
||||
"grnd_level": 1017,
|
||||
"humidity": 63,
|
||||
"temp_kf": 0.33
|
||||
},
|
||||
"weather": [
|
||||
{
|
||||
"id": 804,
|
||||
"main": "Clouds",
|
||||
"description": "overcast clouds",
|
||||
"icon": "04d"
|
||||
}
|
||||
],
|
||||
"clouds": {
|
||||
"all": 90
|
||||
},
|
||||
"wind": {
|
||||
"speed": 3.34,
|
||||
"deg": 172,
|
||||
"gust": 4.03
|
||||
},
|
||||
"visibility": 10000,
|
||||
"pop": 0,
|
||||
"sys": {
|
||||
"pod": "d"
|
||||
},
|
||||
"dt_txt": "2022-03-15 15:00:00"
|
||||
}
|
||||
],
|
||||
"city": {
|
||||
"id": 2643743,
|
||||
"name": "London",
|
||||
"coord": {
|
||||
"lat": 51.5073,
|
||||
"lon": -0.1277
|
||||
},
|
||||
"country": "GB",
|
||||
"population": 1000000,
|
||||
"timezone": 0,
|
||||
"sunrise": 1647324903,
|
||||
"sunset": 1647367441
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
final Forecast forecast = new FiveDayThreeHourStepForecastResponseMapper(UnitSystem.METRIC).mapToForecast(jsonResponse);
|
||||
assertNotNull(forecast);
|
||||
|
||||
final Location location = forecast.getLocation();
|
||||
assertNotNull(location);
|
||||
assertEquals(Coordinates.of(51.5073, -0.1277), location.getCoordinates());
|
||||
assertEquals(2643743, location.getId());
|
||||
assertEquals("London", location.getName());
|
||||
assertEquals("GB", location.getCountryCode());
|
||||
assertEquals(1000000, location.getPopulation());
|
||||
assertEquals(TestMappingUtils.parseDateTime(1647324903), location.getSunriseTime());
|
||||
assertEquals(TestMappingUtils.parseDateTime(1647367441), location.getSunsetTime());
|
||||
assertEquals(ZoneOffset.ofTotalSeconds(0), location.getZoneOffset());
|
||||
|
||||
|
||||
final List<WeatherForecast> weatherForecastList = forecast.getWeatherForecasts();
|
||||
assertEquals(2, weatherForecastList.size());
|
||||
|
||||
final WeatherForecast weatherForecast = weatherForecastList.get(0);
|
||||
assertNotNull(weatherForecast);
|
||||
|
||||
assertEquals(TestMappingUtils.parseDateTime(1647345600), weatherForecast.getForecastTime());
|
||||
assertEquals(10000, weatherForecast.getVisibilityInMetres());
|
||||
assertEquals(0, weatherForecast.getProbabilityOfPrecipitation());
|
||||
assertEquals("2022-03-15 12:00:00", weatherForecast.getForecastTimeISO());
|
||||
assertEquals(DayTime.DAY, weatherForecast.getDayTime());
|
||||
|
||||
final Temperature temperature = weatherForecast.getTemperature();
|
||||
assertNotNull(temperature);
|
||||
assertEquals(286.88, temperature.getValue());
|
||||
assertEquals(285.93, temperature.getFeelsLike());
|
||||
assertEquals(286.74, temperature.getMinTemperature());
|
||||
assertEquals(286.88, temperature.getMaxTemperature());
|
||||
|
||||
final AtmosphericPressure pressure = weatherForecast.getAtmosphericPressure();
|
||||
assertEquals(1021, pressure.getValue());
|
||||
assertEquals(1021, pressure.getSeaLevelValue());
|
||||
assertEquals(1018, pressure.getGroundLevelValue());
|
||||
|
||||
final Humidity humidity = weatherForecast.getHumidity();
|
||||
assertEquals(62, humidity.getValue());
|
||||
|
||||
final Clouds clouds = weatherForecast.getClouds();
|
||||
assertEquals(85, clouds.getValue());
|
||||
|
||||
final Wind wind = weatherForecast.getWind();
|
||||
assertEquals(3.25, wind.getSpeed());
|
||||
assertEquals(134, wind.getDegrees());
|
||||
assertEquals(4.45, wind.getGust());
|
||||
|
||||
assertEquals(1, weatherForecast.getWeatherStates().size());
|
||||
|
||||
final WeatherState weatherState = weatherForecast.getWeatherStates().get(0);
|
||||
assertEquals(804, weatherState.getId());
|
||||
assertEquals("Clouds", weatherState.getName());
|
||||
assertEquals("overcast clouds", weatherState.getDescription());
|
||||
assertEquals("04d", weatherState.getIconId());
|
||||
|
||||
final Rain rain = weatherForecast.getRain();
|
||||
assertEquals(22.1, rain.getThreeHourLevel());
|
||||
|
||||
final Snow snow = weatherForecast.getSnow();
|
||||
assertEquals(13.6, snow.getThreeHourLevel());
|
||||
}
|
||||
}
|
||||
@ -109,7 +109,7 @@ class HourlyForecastResponseMapperTest {
|
||||
final Location location = hourlyForecast.getLocation();
|
||||
assertEquals(2643743, location.getId());
|
||||
assertEquals("London", location.getName());
|
||||
assertEquals(Coordinates.of(51.5085, -0.1258), location.getCoordinate());
|
||||
assertEquals(Coordinates.of(51.5085, -0.1258), location.getCoordinates());
|
||||
assertEquals("GB", location.getCountryCode());
|
||||
assertEquals(ZoneOffset.ofTotalSeconds(0), location.getZoneOffset());
|
||||
assertEquals(LocalDateTime.ofInstant(Instant.ofEpochSecond(1568958164), TimeZone.getDefault().toZoneId()), location.getSunriseTime());
|
||||
|
||||
@ -0,0 +1,56 @@
|
||||
package com.github.prominence.openweathermap.api.mapper;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||
import com.github.prominence.openweathermap.api.model.radiation.SolarRadiation;
|
||||
import com.github.prominence.openweathermap.api.model.radiation.SolarRadiationRecord;
|
||||
import com.github.prominence.openweathermap.api.utils.TestMappingUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class SolarRadiationResponseMapperTest {
|
||||
|
||||
@Test
|
||||
void mapToObject() {
|
||||
final String jsonResponse = """
|
||||
{
|
||||
"coord": {
|
||||
"lon": -114.6244,
|
||||
"lat": 32.7243
|
||||
},
|
||||
"list": [
|
||||
{
|
||||
"radiation": {
|
||||
"ghi": 206.68,
|
||||
"dni": 2.27,
|
||||
"dhi": 204.83,
|
||||
"ghi_cs": 826.71,
|
||||
"dni_cs": 885.47,
|
||||
"dhi_cs": 114.93
|
||||
},
|
||||
"dt": 1618232400
|
||||
}
|
||||
]
|
||||
}
|
||||
""";
|
||||
|
||||
final SolarRadiation solarRadiation = new SolarRadiationResponseMapper().mapToObject(jsonResponse);
|
||||
assertNotNull(solarRadiation);
|
||||
|
||||
assertEquals(Coordinates.of(32.7243, -114.6244), solarRadiation.getCoordinates());
|
||||
|
||||
final List<SolarRadiationRecord> records = solarRadiation.getSolarRadiationRecords();
|
||||
assertEquals(1, records.size());
|
||||
|
||||
final SolarRadiationRecord record = records.get(0);
|
||||
assertEquals(TestMappingUtils.parseDateTime(1618232400), record.getMeasurementTime());
|
||||
assertEquals(206.68, record.getCloudSkyGlobalHorizontalIrradiance());
|
||||
assertEquals(2.27, record.getCloudSkyDirectNormalIrradiance());
|
||||
assertEquals(204.83, record.getCloudSkyDiffuseHorizontalIrradiance());
|
||||
assertEquals(826.71, record.getClearSkyGlobalHorizontalIrradiance());
|
||||
assertEquals(885.47, record.getClearSkyDirectNormalIrradiance());
|
||||
assertEquals(114.93, record.getClearSkyDiffuseHorizontalIrradiance());
|
||||
}
|
||||
}
|
||||
@ -35,12 +35,12 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
public class AirPollutionDetailsUnitTest {
|
||||
@Test
|
||||
public void getCoordinate() {
|
||||
public void getCoordinates() {
|
||||
final AirPollutionDetails airPollutionDetails = new AirPollutionDetails();
|
||||
final Coordinates coordinates = Coordinates.of(22.3, 44.2);
|
||||
airPollutionDetails.setCoordinate(coordinates);
|
||||
airPollutionDetails.setCoordinates(coordinates);
|
||||
|
||||
assertEquals(coordinates, airPollutionDetails.getCoordinate());
|
||||
assertEquals(coordinates, airPollutionDetails.getCoordinates());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -66,11 +66,11 @@ public class AirPollutionDetailsUnitTest {
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
first.setCoordinate(coordinates);
|
||||
first.setCoordinates(coordinates);
|
||||
|
||||
assertNotEquals(first, second);
|
||||
|
||||
second.setCoordinate(coordinates);
|
||||
second.setCoordinates(coordinates);
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
@ -91,7 +91,7 @@ public class AirPollutionDetailsUnitTest {
|
||||
|
||||
assertEquals(first.hashCode(), second.hashCode());
|
||||
|
||||
first.setCoordinate(coordinates);
|
||||
first.setCoordinates(coordinates);
|
||||
|
||||
assertNotEquals(first.hashCode(), second.hashCode());
|
||||
}
|
||||
|
||||
@ -96,9 +96,9 @@ public class LocationUnitTest {
|
||||
public void whenSetCoordinate_thenValueIsSet() {
|
||||
final Location location = Location.withValues(33, "test");
|
||||
final Coordinates coordinates = Coordinates.of(33.2, 64.2);
|
||||
location.setCoordinate(coordinates);
|
||||
location.setCoordinates(coordinates);
|
||||
|
||||
assertEquals(coordinates, location.getCoordinate());
|
||||
assertEquals(coordinates, location.getCoordinates());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -115,7 +115,7 @@ public class LocationUnitTest {
|
||||
|
||||
assertNotEquals("", location.toString());
|
||||
|
||||
location.setCoordinate(Coordinates.of(33.2, 56.3));
|
||||
location.setCoordinates(Coordinates.of(33.2, 56.3));
|
||||
|
||||
assertNotEquals("", location.toString());
|
||||
|
||||
@ -203,11 +203,11 @@ public class LocationUnitTest {
|
||||
|
||||
final Coordinates coordinates = Coordinates.of(33.5, -22.4);
|
||||
|
||||
one.setCoordinate(coordinates);
|
||||
one.setCoordinates(coordinates);
|
||||
|
||||
assertNotEquals(one, two);
|
||||
|
||||
two.setCoordinate(coordinates);
|
||||
two.setCoordinates(coordinates);
|
||||
|
||||
assertEquals(one, two);
|
||||
|
||||
|
||||
@ -26,6 +26,7 @@ import com.github.prominence.openweathermap.api.model.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@ -138,7 +139,7 @@ public class WeatherForecastUnitTest {
|
||||
assertNotEquals("", weatherForecast.toString());
|
||||
assertNotNull(weatherForecast.toString());
|
||||
|
||||
weatherForecast.setWeatherState(weatherState);
|
||||
weatherForecast.setWeatherStates(List.of(weatherState));
|
||||
assertNotEquals("", weatherForecast.toString());
|
||||
assertNotNull(weatherForecast.toString());
|
||||
|
||||
@ -224,11 +225,11 @@ public class WeatherForecastUnitTest {
|
||||
assertEquals(first, second);
|
||||
|
||||
final WeatherState weatherState = new WeatherState(800, "Clear", "clear sky");
|
||||
first.setWeatherState(weatherState);
|
||||
first.setWeatherStates(List.of(weatherState));
|
||||
|
||||
assertNotEquals(first, second);
|
||||
|
||||
second.setWeatherState(weatherState);
|
||||
second.setWeatherStates(List.of(weatherState));
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
|
||||
@ -35,12 +35,12 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class CurrentWeatherDataUnitTest {
|
||||
@Test
|
||||
public void getCoordinate() {
|
||||
public void getCoordinates() {
|
||||
final CurrentWeatherData currentWeatherData = new CurrentWeatherData();
|
||||
final Coordinates coordinates = Coordinates.of(11.2, 43.2);
|
||||
currentWeatherData.setCoordinate(coordinates);
|
||||
currentWeatherData.setCoordinates(coordinates);
|
||||
|
||||
assertEquals(coordinates, currentWeatherData.getCoordinate());
|
||||
assertEquals(coordinates, currentWeatherData.getCoordinates());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -126,11 +126,11 @@ public class CurrentWeatherDataUnitTest {
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
first.setCoordinate(coordinates);
|
||||
first.setCoordinates(coordinates);
|
||||
|
||||
assertNotEquals(first, second);
|
||||
|
||||
second.setCoordinate(coordinates);
|
||||
second.setCoordinates(coordinates);
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
@ -198,7 +198,7 @@ public class CurrentWeatherDataUnitTest {
|
||||
|
||||
assertEquals(first.hashCode(), second.hashCode());
|
||||
|
||||
first.setCoordinate(Coordinates.of(11, 42));
|
||||
first.setCoordinates(Coordinates.of(11, 42));
|
||||
|
||||
assertNotEquals(first.hashCode(), second.hashCode());
|
||||
}
|
||||
@ -206,7 +206,7 @@ public class CurrentWeatherDataUnitTest {
|
||||
@Test
|
||||
public void getToString() {
|
||||
final CurrentWeatherData currentWeatherData = new CurrentWeatherData();
|
||||
currentWeatherData.setCoordinate(Coordinates.of(32, 22));
|
||||
currentWeatherData.setCoordinates(Coordinates.of(32, 22));
|
||||
|
||||
assertNotNull(currentWeatherData.toString());
|
||||
assertNotEquals("", currentWeatherData.toString());
|
||||
|
||||
@ -34,12 +34,12 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class HistoricalWeatherDataUnitTest {
|
||||
@Test
|
||||
public void getCoordinate() {
|
||||
public void getCoordinates() {
|
||||
final HistoricalWeatherData historicalWeatherData = new HistoricalWeatherData();
|
||||
final Coordinates coordinates = Coordinates.of(11.2, 43.2);
|
||||
historicalWeatherData.setCoordinate(coordinates);
|
||||
historicalWeatherData.setCoordinates(coordinates);
|
||||
|
||||
assertEquals(coordinates, historicalWeatherData.getCoordinate());
|
||||
assertEquals(coordinates, historicalWeatherData.getCoordinates());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -95,11 +95,11 @@ public class HistoricalWeatherDataUnitTest {
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
first.setCoordinate(coordinates);
|
||||
first.setCoordinates(coordinates);
|
||||
|
||||
assertNotEquals(first, second);
|
||||
|
||||
second.setCoordinate(coordinates);
|
||||
second.setCoordinates(coordinates);
|
||||
|
||||
assertEquals(first, second);
|
||||
|
||||
@ -143,7 +143,7 @@ public class HistoricalWeatherDataUnitTest {
|
||||
|
||||
assertEquals(first.hashCode(), second.hashCode());
|
||||
|
||||
first.setCoordinate(Coordinates.of(11, 42));
|
||||
first.setCoordinates(Coordinates.of(11, 42));
|
||||
|
||||
assertNotEquals(first.hashCode(), second.hashCode());
|
||||
}
|
||||
@ -151,7 +151,7 @@ public class HistoricalWeatherDataUnitTest {
|
||||
@Test
|
||||
public void getToString() {
|
||||
final HistoricalWeatherData historicalWeatherData = new HistoricalWeatherData();
|
||||
historicalWeatherData.setCoordinate(Coordinates.of(32, 22));
|
||||
historicalWeatherData.setCoordinates(Coordinates.of(32, 22));
|
||||
|
||||
assertNotNull(historicalWeatherData.toString());
|
||||
assertNotEquals("", historicalWeatherData.toString());
|
||||
|
||||
@ -96,9 +96,9 @@ public class LocationUnitTest {
|
||||
public void whenSetCoordinate_thenValueIsSet() {
|
||||
final Location location = Location.withValues(33, "test");
|
||||
final Coordinates coordinates = Coordinates.of(33.2, 64.2);
|
||||
location.setCoordinate(coordinates);
|
||||
location.setCoordinates(coordinates);
|
||||
|
||||
assertEquals(coordinates, location.getCoordinate());
|
||||
assertEquals(coordinates, location.getCoordinates());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -107,7 +107,7 @@ public class LocationUnitTest {
|
||||
|
||||
assertNotEquals("", location.toString());
|
||||
|
||||
location.setCoordinate(Coordinates.of(33.2, 56.3));
|
||||
location.setCoordinates(Coordinates.of(33.2, 56.3));
|
||||
|
||||
assertNotEquals("", location.toString());
|
||||
|
||||
@ -191,11 +191,11 @@ public class LocationUnitTest {
|
||||
|
||||
final Coordinates coordinates = Coordinates.of(33.5, -22.4);
|
||||
|
||||
one.setCoordinate(coordinates);
|
||||
one.setCoordinates(coordinates);
|
||||
|
||||
assertNotEquals(one, two);
|
||||
|
||||
two.setCoordinate(coordinates);
|
||||
two.setCoordinates(coordinates);
|
||||
|
||||
assertEquals(one, two);
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
assertNotNull(forecast.getLocation());
|
||||
assertNotNull(forecast.getWeatherForecasts());
|
||||
for (WeatherForecast weatherForecast : forecast.getWeatherForecasts()) {
|
||||
assertNotNull(weatherForecast.getWeatherState());
|
||||
assertNotNull(weatherForecast.getWeatherStates());
|
||||
assertNotNull(weatherForecast.getForecastTime());
|
||||
assertNotNull(weatherForecast.getTemperature());
|
||||
assertNotNull(weatherForecast.getAtmosphericPressure());
|
||||
@ -106,7 +106,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
assertNotNull(forecast.getLocation());
|
||||
assertNotNull(forecast.getWeatherForecasts());
|
||||
for (WeatherForecast weatherForecast : forecast.getWeatherForecasts()) {
|
||||
assertNotNull(weatherForecast.getWeatherState());
|
||||
assertNotNull(weatherForecast.getWeatherStates());
|
||||
assertNotNull(weatherForecast.getForecastTime());
|
||||
assertNotNull(weatherForecast.getTemperature());
|
||||
assertNotNull(weatherForecast.getAtmosphericPressure());
|
||||
@ -158,7 +158,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
assertNotNull(forecast.getLocation());
|
||||
assertNotNull(forecast.getWeatherForecasts());
|
||||
for (WeatherForecast weatherForecast : forecast.getWeatherForecasts()) {
|
||||
assertNotNull(weatherForecast.getWeatherState());
|
||||
assertNotNull(weatherForecast.getWeatherStates());
|
||||
assertNotNull(weatherForecast.getForecastTime());
|
||||
assertNotNull(weatherForecast.getTemperature());
|
||||
assertNotNull(weatherForecast.getAtmosphericPressure());
|
||||
@ -209,7 +209,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
assertNotNull(forecast.getLocation());
|
||||
assertNotNull(forecast.getWeatherForecasts());
|
||||
for (WeatherForecast weatherForecast : forecast.getWeatherForecasts()) {
|
||||
assertNotNull(weatherForecast.getWeatherState());
|
||||
assertNotNull(weatherForecast.getWeatherStates());
|
||||
assertNotNull(weatherForecast.getForecastTime());
|
||||
assertNotNull(weatherForecast.getTemperature());
|
||||
assertNotNull(weatherForecast.getAtmosphericPressure());
|
||||
@ -260,7 +260,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
assertNotNull(forecast.getLocation());
|
||||
assertNotNull(forecast.getWeatherForecasts());
|
||||
for (WeatherForecast weatherForecast : forecast.getWeatherForecasts()) {
|
||||
assertNotNull(weatherForecast.getWeatherState());
|
||||
assertNotNull(weatherForecast.getWeatherStates());
|
||||
assertNotNull(weatherForecast.getForecastTime());
|
||||
assertNotNull(weatherForecast.getTemperature());
|
||||
assertNotNull(weatherForecast.getAtmosphericPressure());
|
||||
@ -311,7 +311,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
assertNotNull(forecast.getLocation());
|
||||
assertNotNull(forecast.getWeatherForecasts());
|
||||
for (WeatherForecast weatherForecast : forecast.getWeatherForecasts()) {
|
||||
assertNotNull(weatherForecast.getWeatherState());
|
||||
assertNotNull(weatherForecast.getWeatherStates());
|
||||
assertNotNull(weatherForecast.getForecastTime());
|
||||
assertNotNull(weatherForecast.getTemperature());
|
||||
assertNotNull(weatherForecast.getAtmosphericPressure());
|
||||
@ -362,7 +362,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest {
|
||||
assertNotNull(forecast.getLocation());
|
||||
assertNotNull(forecast.getWeatherForecasts());
|
||||
for (WeatherForecast weatherForecast : forecast.getWeatherForecasts()) {
|
||||
assertNotNull(weatherForecast.getWeatherState());
|
||||
assertNotNull(weatherForecast.getWeatherStates());
|
||||
assertNotNull(weatherForecast.getForecastTime());
|
||||
assertNotNull(weatherForecast.getTemperature());
|
||||
assertNotNull(weatherForecast.getAtmosphericPressure());
|
||||
|
||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user