mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-01-10 11:56:44 +03:00
Implemented Solar Radiation API functionality. Small refactoring.
This commit is contained in:
parent
7f0866ffa2
commit
aa48ac3aa0
@ -13,6 +13,7 @@ Paid:
|
|||||||
* Hourly Forecast 4 days
|
* Hourly Forecast 4 days
|
||||||
* Daily Forecast 16 days
|
* Daily Forecast 16 days
|
||||||
* Climatic 30 days
|
* Climatic 30 days
|
||||||
|
* Solar Radiation API
|
||||||
|
|
||||||
Other:
|
Other:
|
||||||
* Request timeout settings
|
* Request timeout settings
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
* Hourly forecast
|
* Hourly forecast
|
||||||
* One Call API
|
* One Call API
|
||||||
* Daily forecast
|
* Daily forecast
|
||||||
|
* Solar Radiation API
|
||||||
* 5 day / 3-hour forecast
|
* 5 day / 3-hour forecast
|
||||||
* Air Pollution
|
* Air Pollution
|
||||||
* Geocoding API
|
* Geocoding API
|
||||||
@ -344,7 +345,7 @@ You are able to set preferable options(via chain methods) and execute appropriat
|
|||||||
|
|
||||||
| Method | Description |
|
| Method | Description |
|
||||||
|-------------------------------|--------------------------------------------------------------------------------|
|
|-------------------------------|--------------------------------------------------------------------------------|
|
||||||
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
| `getCoordinates()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||||
| `getTimezone()` | Returns location timezone object. |
|
| `getTimezone()` | Returns location timezone object. |
|
||||||
| `getTimezoneOffset()` | Returns zone offset. |
|
| `getTimezoneOffset()` | Returns zone offset. |
|
||||||
| `getCurrent()` | Returns `Current` object with current weather state if available. |
|
| `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 |
|
| Method | Description |
|
||||||
|-------------------------------|-------------------------------------------------------------------------------|
|
|-------------------------------|-------------------------------------------------------------------------------|
|
||||||
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
| `getCoordinates()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||||
| `getTimezone()` | Returns location timezone object. |
|
| `getTimezone()` | Returns location timezone object. |
|
||||||
| `getTimezoneOffset()` | Returns zone offset. |
|
| `getTimezoneOffset()` | Returns zone offset. |
|
||||||
| `getHistoricalWeather()` | Returns `HistoricalWeather` object with historical weather state. |
|
| `getHistoricalWeather()` | Returns `HistoricalWeather` object with historical weather state. |
|
||||||
@ -495,7 +496,7 @@ final AirPollutionDetails airPollutionDetails = openWeatherClient
|
|||||||
|
|
||||||
| Method | Description |
|
| Method | Description |
|
||||||
|-------------------------------|---------------------------------------------------------------------------|
|
|-------------------------------|---------------------------------------------------------------------------|
|
||||||
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
| `getCoordinates()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||||
| `getAirPollutionRecords()` | Returns list of `AirPollutionRecord` objects. |
|
| `getAirPollutionRecords()` | Returns list of `AirPollutionRecord` objects. |
|
||||||
|
|
||||||
`com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionRecord`'s useful public methods(setters are not listed):
|
`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.forecast.hourly.FourDaysHourlyForecastRequester;
|
||||||
import com.github.prominence.openweathermap.api.request.geocoding.GeocodingRequester;
|
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.onecall.OneCallWeatherRequester;
|
||||||
|
import com.github.prominence.openweathermap.api.request.radiation.SolarRadiationRequester;
|
||||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequester;
|
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequester;
|
||||||
|
|
||||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.*;
|
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.*;
|
||||||
@ -106,6 +107,11 @@ public class OpenWeatherMapClient {
|
|||||||
return new ClimaticForecastRequester(new RequestSettings(apiKey, timeoutSettings));
|
return new ClimaticForecastRequester(new RequestSettings(apiKey, timeoutSettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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>.
|
* 5 Day / 3 Hour Forecast <a href="https://openweathermap.org/forecast5">API</a>.
|
||||||
* @return requester for retrieving 5 day/3-hour weather forecast information.
|
* @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");
|
final JsonNode coordNode = rootNode.get("coord");
|
||||||
if (coordNode != null) {
|
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");
|
final JsonNode populationNode = rootNode.get("population");
|
||||||
|
|||||||
@ -41,7 +41,7 @@ public class DailyForecastLocationDeserializer extends JsonDeserializer<Location
|
|||||||
|
|
||||||
final JsonNode coordNode = rootNode.get("coord");
|
final JsonNode coordNode = rootNode.get("coord");
|
||||||
if (coordNode != null) {
|
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");
|
final JsonNode populationNode = rootNode.get("population");
|
||||||
|
|||||||
@ -74,7 +74,7 @@ public class HourlyForecastLocationDeserializer extends JsonDeserializer<Locatio
|
|||||||
|
|
||||||
final JsonNode coordNode = rootNode.get("coord");
|
final JsonNode coordNode = rootNode.get("coord");
|
||||||
if (coordNode != null) {
|
if (coordNode != null) {
|
||||||
location.setCoordinate(objectMapper.readValue(objectMapper.treeAsTokens(coordNode), Coordinates.class));
|
location.setCoordinates(objectMapper.readValue(objectMapper.treeAsTokens(coordNode), Coordinates.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
return location;
|
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");
|
final JsonNode coordNode = rootNode.get("coord");
|
||||||
if (coordNode != null) {
|
if (coordNode != null) {
|
||||||
location.setCoordinate(objectMapper.readValue(objectMapper.treeAsTokens(coordNode), Coordinates.class));
|
location.setCoordinates(objectMapper.readValue(objectMapper.treeAsTokens(coordNode), Coordinates.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
return location;
|
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>.
|
* More information <a href="https://openweathermap.org/price">at official website</a>.
|
||||||
*/
|
*/
|
||||||
public enum SubscriptionPlan {
|
public enum SubscriptionPlan {
|
||||||
/**
|
|
||||||
* Free subscription plan.
|
|
||||||
*/
|
|
||||||
FREE,
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An alias that represents any of paid plans: startup, developer, professional or enterprise.
|
* An alias that represents any of paid plans: startup, developer, professional or enterprise.
|
||||||
*/
|
*/
|
||||||
@ -57,6 +52,12 @@ public enum SubscriptionPlan {
|
|||||||
*/
|
*/
|
||||||
ENTERPRISE,
|
ENTERPRISE,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Special subscription plan. You should contact a manager to get an access.
|
||||||
|
*/
|
||||||
|
SPECIAL,
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All existing subscription plans.
|
* All existing subscription plans.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -61,7 +61,7 @@ public class AirPollutionResponseMapper {
|
|||||||
|
|
||||||
private AirPollutionDetails mapToAirPollution(JsonNode rootNode) {
|
private AirPollutionDetails mapToAirPollution(JsonNode rootNode) {
|
||||||
final AirPollutionDetails airPollutionDetails = new AirPollutionDetails();
|
final AirPollutionDetails airPollutionDetails = new AirPollutionDetails();
|
||||||
airPollutionDetails.setCoordinate(parseCoordinate(rootNode.get("coord")));
|
airPollutionDetails.setCoordinates(parseCoordinate(rootNode.get("coord")));
|
||||||
|
|
||||||
final List<AirPollutionRecord> sampleList = new ArrayList<>();
|
final List<AirPollutionRecord> sampleList = new ArrayList<>();
|
||||||
final JsonNode sampleListNode = rootNode.get("list");
|
final JsonNode sampleListNode = rootNode.get("list");
|
||||||
|
|||||||
@ -207,7 +207,7 @@ public class FiveDayThreeHourStepForecastResponseMapper {
|
|||||||
|
|
||||||
final JsonNode coordNode = rootNode.get("coord");
|
final JsonNode coordNode = rootNode.get("coord");
|
||||||
if (coordNode != null) {
|
if (coordNode != null) {
|
||||||
location.setCoordinate(parseCoordinate(coordNode));
|
location.setCoordinates(parseCoordinate(coordNode));
|
||||||
}
|
}
|
||||||
|
|
||||||
final JsonNode populationNode = rootNode.get("population");
|
final JsonNode populationNode = rootNode.get("population");
|
||||||
|
|||||||
@ -111,7 +111,7 @@ public class OneCallWeatherResponseMapper extends AbstractMapper {
|
|||||||
|
|
||||||
private CurrentWeatherData mapToCurrent(JsonNode rootNode) throws IOException {
|
private CurrentWeatherData mapToCurrent(JsonNode rootNode) throws IOException {
|
||||||
final CurrentWeatherData currentData = new CurrentWeatherData();
|
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.setTimezone(parseZoneId(rootNode.get("timezone")));
|
||||||
currentData.setTimezoneOffset(parseZoneOffset(rootNode.get("timezone_offset")));
|
currentData.setTimezoneOffset(parseZoneOffset(rootNode.get("timezone_offset")));
|
||||||
|
|
||||||
@ -261,7 +261,7 @@ public class OneCallWeatherResponseMapper extends AbstractMapper {
|
|||||||
|
|
||||||
private HistoricalWeatherData mapToHistorical(JsonNode rootNode) throws IOException {
|
private HistoricalWeatherData mapToHistorical(JsonNode rootNode) throws IOException {
|
||||||
final HistoricalWeatherData historicalData = new HistoricalWeatherData();
|
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.setTimezone(parseZoneId(rootNode.get("timezone")));
|
||||||
historicalData.setTimezoneOffset(parseZoneOffset(rootNode.get("timezone_offset")));
|
historicalData.setTimezoneOffset(parseZoneOffset(rootNode.get("timezone_offset")));
|
||||||
historicalData.setHistoricalWeather(parseHistoricalWeather(rootNode.get("current")));
|
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
|
* @return the coordinate
|
||||||
*/
|
*/
|
||||||
public Coordinates getCoordinate() {
|
public Coordinates getCoordinates() {
|
||||||
return coordinates;
|
return coordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ public class AirPollutionDetails {
|
|||||||
*
|
*
|
||||||
* @param coordinates the coordinate
|
* @param coordinates the coordinate
|
||||||
*/
|
*/
|
||||||
public void setCoordinate(Coordinates coordinates) {
|
public void setCoordinates(Coordinates coordinates) {
|
||||||
this.coordinates = coordinates;
|
this.coordinates = coordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -127,7 +127,7 @@ public class Location {
|
|||||||
* Returns location coordinates.
|
* Returns location coordinates.
|
||||||
* @return location coordinates.
|
* @return location coordinates.
|
||||||
*/
|
*/
|
||||||
public Coordinates getCoordinate() {
|
public Coordinates getCoordinates() {
|
||||||
return coordinates;
|
return coordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ public class Location {
|
|||||||
* Sets location coordinates.
|
* Sets location coordinates.
|
||||||
* @param coordinates location coordinates
|
* @param coordinates location coordinates
|
||||||
*/
|
*/
|
||||||
public void setCoordinate(Coordinates coordinates) {
|
public void setCoordinates(Coordinates coordinates) {
|
||||||
this.coordinates = coordinates;
|
this.coordinates = coordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -127,7 +127,7 @@ public class Location {
|
|||||||
* Returns location coordinates.
|
* Returns location coordinates.
|
||||||
* @return location coordinates.
|
* @return location coordinates.
|
||||||
*/
|
*/
|
||||||
public Coordinates getCoordinate() {
|
public Coordinates getCoordinates() {
|
||||||
return coordinates;
|
return coordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ public class Location {
|
|||||||
* Sets location coordinates.
|
* Sets location coordinates.
|
||||||
* @param coordinates location coordinates
|
* @param coordinates location coordinates
|
||||||
*/
|
*/
|
||||||
public void setCoordinate(Coordinates coordinates) {
|
public void setCoordinates(Coordinates coordinates) {
|
||||||
this.coordinates = coordinates;
|
this.coordinates = coordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -162,7 +162,7 @@ public class Location {
|
|||||||
* Returns location coordinates.
|
* Returns location coordinates.
|
||||||
* @return location coordinates.
|
* @return location coordinates.
|
||||||
*/
|
*/
|
||||||
public Coordinates getCoordinate() {
|
public Coordinates getCoordinates() {
|
||||||
return coordinates;
|
return coordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ public class Location {
|
|||||||
* Sets location coordinates.
|
* Sets location coordinates.
|
||||||
* @param coordinates location coordinates
|
* @param coordinates location coordinates
|
||||||
*/
|
*/
|
||||||
public void setCoordinate(Coordinates coordinates) {
|
public void setCoordinates(Coordinates coordinates) {
|
||||||
this.coordinates = coordinates;
|
this.coordinates = coordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -160,7 +160,7 @@ public class Location {
|
|||||||
* Returns location coordinates.
|
* Returns location coordinates.
|
||||||
* @return location coordinates.
|
* @return location coordinates.
|
||||||
*/
|
*/
|
||||||
public Coordinates getCoordinate() {
|
public Coordinates getCoordinates() {
|
||||||
return coordinates;
|
return coordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ public class Location {
|
|||||||
* Sets location coordinates.
|
* Sets location coordinates.
|
||||||
* @param coordinates location coordinates
|
* @param coordinates location coordinates
|
||||||
*/
|
*/
|
||||||
public void setCoordinate(Coordinates coordinates) {
|
public void setCoordinates(Coordinates coordinates) {
|
||||||
this.coordinates = coordinates;
|
this.coordinates = coordinates;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -49,7 +49,7 @@ public class CurrentWeatherData {
|
|||||||
*
|
*
|
||||||
* @return the coordinate
|
* @return the coordinate
|
||||||
*/
|
*/
|
||||||
public Coordinates getCoordinate() {
|
public Coordinates getCoordinates() {
|
||||||
return coordinates;
|
return coordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ public class CurrentWeatherData {
|
|||||||
*
|
*
|
||||||
* @param coordinates the coordinate
|
* @param coordinates the coordinate
|
||||||
*/
|
*/
|
||||||
public void setCoordinate(Coordinates coordinates) {
|
public void setCoordinates(Coordinates coordinates) {
|
||||||
this.coordinates = coordinates;
|
this.coordinates = coordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -45,7 +45,7 @@ public class HistoricalWeatherData {
|
|||||||
*
|
*
|
||||||
* @return the coordinate
|
* @return the coordinate
|
||||||
*/
|
*/
|
||||||
public Coordinates getCoordinate() {
|
public Coordinates getCoordinates() {
|
||||||
return coordinates;
|
return coordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ public class HistoricalWeatherData {
|
|||||||
*
|
*
|
||||||
* @param coordinates the coordinate
|
* @param coordinates the coordinate
|
||||||
*/
|
*/
|
||||||
public void setCoordinate(Coordinates coordinates) {
|
public void setCoordinates(Coordinates coordinates) {
|
||||||
this.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.
|
* @return location coordinates.
|
||||||
*/
|
*/
|
||||||
public Coordinates getCoordinate() {
|
public Coordinates getCoordinates() {
|
||||||
return coordinates;
|
return coordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ public class Location {
|
|||||||
*
|
*
|
||||||
* @param coordinates location coordinates
|
* @param coordinates location coordinates
|
||||||
*/
|
*/
|
||||||
public void setCoordinate(Coordinates coordinates) {
|
public void setCoordinates(Coordinates coordinates) {
|
||||||
this.coordinates = coordinates;
|
this.coordinates = coordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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();
|
final Location location = forecast.getLocation();
|
||||||
assertNotNull(location);
|
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(2643743, location.getId());
|
||||||
assertEquals("London", location.getName());
|
assertEquals("London", location.getName());
|
||||||
assertEquals("GB", location.getCountryCode());
|
assertEquals("GB", location.getCountryCode());
|
||||||
|
|||||||
@ -1096,7 +1096,7 @@ public class CurrentWeatherResponseMapperTest {
|
|||||||
|
|
||||||
Weather weather = mapper.mapToWeather(jsonString);
|
Weather weather = mapper.mapToWeather(jsonString);
|
||||||
|
|
||||||
assertNotNull(weather.getLocation().getCoordinate());
|
assertNotNull(weather.getLocation().getCoordinates());
|
||||||
assertNotNull(weather.getLocation().getCountryCode());
|
assertNotNull(weather.getLocation().getCountryCode());
|
||||||
|
|
||||||
// without coordinates and country code
|
// without coordinates and country code
|
||||||
@ -1144,7 +1144,7 @@ public class CurrentWeatherResponseMapperTest {
|
|||||||
}
|
}
|
||||||
""";
|
""";
|
||||||
weather = mapper.mapToWeather(jsonString);
|
weather = mapper.mapToWeather(jsonString);
|
||||||
assertNull(weather.getLocation().getCoordinate());
|
assertNull(weather.getLocation().getCoordinates());
|
||||||
assertNull(weather.getLocation().getCountryCode());
|
assertNull(weather.getLocation().getCountryCode());
|
||||||
|
|
||||||
// coordinates without latitude
|
// coordinates without latitude
|
||||||
@ -1196,7 +1196,7 @@ public class CurrentWeatherResponseMapperTest {
|
|||||||
}
|
}
|
||||||
""";
|
""";
|
||||||
weather = mapper.mapToWeather(jsonString);
|
weather = mapper.mapToWeather(jsonString);
|
||||||
assertNull(weather.getLocation().getCoordinate());
|
assertNull(weather.getLocation().getCoordinates());
|
||||||
assertNotNull(weather.getLocation().getCountryCode());
|
assertNotNull(weather.getLocation().getCountryCode());
|
||||||
|
|
||||||
// coordinates without longitude
|
// coordinates without longitude
|
||||||
@ -1248,7 +1248,7 @@ public class CurrentWeatherResponseMapperTest {
|
|||||||
}
|
}
|
||||||
""";
|
""";
|
||||||
weather = mapper.mapToWeather(jsonString);
|
weather = mapper.mapToWeather(jsonString);
|
||||||
assertNull(weather.getLocation().getCoordinate());
|
assertNull(weather.getLocation().getCoordinates());
|
||||||
assertNotNull(weather.getLocation().getCountryCode());
|
assertNotNull(weather.getLocation().getCountryCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,7 +79,7 @@ class DailyForecastResponseMapperTest {
|
|||||||
|
|
||||||
final Location location = forecast.getLocation();
|
final Location location = forecast.getLocation();
|
||||||
assertNotNull(location);
|
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(2643743, location.getId());
|
||||||
assertEquals("London", location.getName());
|
assertEquals("London", location.getName());
|
||||||
assertEquals("GB", location.getCountryCode());
|
assertEquals("GB", location.getCountryCode());
|
||||||
|
|||||||
@ -109,7 +109,7 @@ class HourlyForecastResponseMapperTest {
|
|||||||
final Location location = hourlyForecast.getLocation();
|
final Location location = hourlyForecast.getLocation();
|
||||||
assertEquals(2643743, location.getId());
|
assertEquals(2643743, location.getId());
|
||||||
assertEquals("London", location.getName());
|
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("GB", location.getCountryCode());
|
||||||
assertEquals(ZoneOffset.ofTotalSeconds(0), location.getZoneOffset());
|
assertEquals(ZoneOffset.ofTotalSeconds(0), location.getZoneOffset());
|
||||||
assertEquals(LocalDateTime.ofInstant(Instant.ofEpochSecond(1568958164), TimeZone.getDefault().toZoneId()), location.getSunriseTime());
|
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 {
|
public class AirPollutionDetailsUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void getCoordinate() {
|
public void getCoordinates() {
|
||||||
final AirPollutionDetails airPollutionDetails = new AirPollutionDetails();
|
final AirPollutionDetails airPollutionDetails = new AirPollutionDetails();
|
||||||
final Coordinates coordinates = Coordinates.of(22.3, 44.2);
|
final Coordinates coordinates = Coordinates.of(22.3, 44.2);
|
||||||
airPollutionDetails.setCoordinate(coordinates);
|
airPollutionDetails.setCoordinates(coordinates);
|
||||||
|
|
||||||
assertEquals(coordinates, airPollutionDetails.getCoordinate());
|
assertEquals(coordinates, airPollutionDetails.getCoordinates());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -66,11 +66,11 @@ public class AirPollutionDetailsUnitTest {
|
|||||||
|
|
||||||
assertEquals(first, second);
|
assertEquals(first, second);
|
||||||
|
|
||||||
first.setCoordinate(coordinates);
|
first.setCoordinates(coordinates);
|
||||||
|
|
||||||
assertNotEquals(first, second);
|
assertNotEquals(first, second);
|
||||||
|
|
||||||
second.setCoordinate(coordinates);
|
second.setCoordinates(coordinates);
|
||||||
|
|
||||||
assertEquals(first, second);
|
assertEquals(first, second);
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ public class AirPollutionDetailsUnitTest {
|
|||||||
|
|
||||||
assertEquals(first.hashCode(), second.hashCode());
|
assertEquals(first.hashCode(), second.hashCode());
|
||||||
|
|
||||||
first.setCoordinate(coordinates);
|
first.setCoordinates(coordinates);
|
||||||
|
|
||||||
assertNotEquals(first.hashCode(), second.hashCode());
|
assertNotEquals(first.hashCode(), second.hashCode());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -96,9 +96,9 @@ public class LocationUnitTest {
|
|||||||
public void whenSetCoordinate_thenValueIsSet() {
|
public void whenSetCoordinate_thenValueIsSet() {
|
||||||
final Location location = Location.withValues(33, "test");
|
final Location location = Location.withValues(33, "test");
|
||||||
final Coordinates coordinates = Coordinates.of(33.2, 64.2);
|
final Coordinates coordinates = Coordinates.of(33.2, 64.2);
|
||||||
location.setCoordinate(coordinates);
|
location.setCoordinates(coordinates);
|
||||||
|
|
||||||
assertEquals(coordinates, location.getCoordinate());
|
assertEquals(coordinates, location.getCoordinates());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -115,7 +115,7 @@ public class LocationUnitTest {
|
|||||||
|
|
||||||
assertNotEquals("", location.toString());
|
assertNotEquals("", location.toString());
|
||||||
|
|
||||||
location.setCoordinate(Coordinates.of(33.2, 56.3));
|
location.setCoordinates(Coordinates.of(33.2, 56.3));
|
||||||
|
|
||||||
assertNotEquals("", location.toString());
|
assertNotEquals("", location.toString());
|
||||||
|
|
||||||
@ -203,11 +203,11 @@ public class LocationUnitTest {
|
|||||||
|
|
||||||
final Coordinates coordinates = Coordinates.of(33.5, -22.4);
|
final Coordinates coordinates = Coordinates.of(33.5, -22.4);
|
||||||
|
|
||||||
one.setCoordinate(coordinates);
|
one.setCoordinates(coordinates);
|
||||||
|
|
||||||
assertNotEquals(one, two);
|
assertNotEquals(one, two);
|
||||||
|
|
||||||
two.setCoordinate(coordinates);
|
two.setCoordinates(coordinates);
|
||||||
|
|
||||||
assertEquals(one, two);
|
assertEquals(one, two);
|
||||||
|
|
||||||
|
|||||||
@ -35,12 +35,12 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
|
|
||||||
public class CurrentWeatherDataUnitTest {
|
public class CurrentWeatherDataUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void getCoordinate() {
|
public void getCoordinates() {
|
||||||
final CurrentWeatherData currentWeatherData = new CurrentWeatherData();
|
final CurrentWeatherData currentWeatherData = new CurrentWeatherData();
|
||||||
final Coordinates coordinates = Coordinates.of(11.2, 43.2);
|
final Coordinates coordinates = Coordinates.of(11.2, 43.2);
|
||||||
currentWeatherData.setCoordinate(coordinates);
|
currentWeatherData.setCoordinates(coordinates);
|
||||||
|
|
||||||
assertEquals(coordinates, currentWeatherData.getCoordinate());
|
assertEquals(coordinates, currentWeatherData.getCoordinates());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -126,11 +126,11 @@ public class CurrentWeatherDataUnitTest {
|
|||||||
|
|
||||||
assertEquals(first, second);
|
assertEquals(first, second);
|
||||||
|
|
||||||
first.setCoordinate(coordinates);
|
first.setCoordinates(coordinates);
|
||||||
|
|
||||||
assertNotEquals(first, second);
|
assertNotEquals(first, second);
|
||||||
|
|
||||||
second.setCoordinate(coordinates);
|
second.setCoordinates(coordinates);
|
||||||
|
|
||||||
assertEquals(first, second);
|
assertEquals(first, second);
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ public class CurrentWeatherDataUnitTest {
|
|||||||
|
|
||||||
assertEquals(first.hashCode(), second.hashCode());
|
assertEquals(first.hashCode(), second.hashCode());
|
||||||
|
|
||||||
first.setCoordinate(Coordinates.of(11, 42));
|
first.setCoordinates(Coordinates.of(11, 42));
|
||||||
|
|
||||||
assertNotEquals(first.hashCode(), second.hashCode());
|
assertNotEquals(first.hashCode(), second.hashCode());
|
||||||
}
|
}
|
||||||
@ -206,7 +206,7 @@ public class CurrentWeatherDataUnitTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getToString() {
|
public void getToString() {
|
||||||
final CurrentWeatherData currentWeatherData = new CurrentWeatherData();
|
final CurrentWeatherData currentWeatherData = new CurrentWeatherData();
|
||||||
currentWeatherData.setCoordinate(Coordinates.of(32, 22));
|
currentWeatherData.setCoordinates(Coordinates.of(32, 22));
|
||||||
|
|
||||||
assertNotNull(currentWeatherData.toString());
|
assertNotNull(currentWeatherData.toString());
|
||||||
assertNotEquals("", currentWeatherData.toString());
|
assertNotEquals("", currentWeatherData.toString());
|
||||||
|
|||||||
@ -34,12 +34,12 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
|
|
||||||
public class HistoricalWeatherDataUnitTest {
|
public class HistoricalWeatherDataUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void getCoordinate() {
|
public void getCoordinates() {
|
||||||
final HistoricalWeatherData historicalWeatherData = new HistoricalWeatherData();
|
final HistoricalWeatherData historicalWeatherData = new HistoricalWeatherData();
|
||||||
final Coordinates coordinates = Coordinates.of(11.2, 43.2);
|
final Coordinates coordinates = Coordinates.of(11.2, 43.2);
|
||||||
historicalWeatherData.setCoordinate(coordinates);
|
historicalWeatherData.setCoordinates(coordinates);
|
||||||
|
|
||||||
assertEquals(coordinates, historicalWeatherData.getCoordinate());
|
assertEquals(coordinates, historicalWeatherData.getCoordinates());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -95,11 +95,11 @@ public class HistoricalWeatherDataUnitTest {
|
|||||||
|
|
||||||
assertEquals(first, second);
|
assertEquals(first, second);
|
||||||
|
|
||||||
first.setCoordinate(coordinates);
|
first.setCoordinates(coordinates);
|
||||||
|
|
||||||
assertNotEquals(first, second);
|
assertNotEquals(first, second);
|
||||||
|
|
||||||
second.setCoordinate(coordinates);
|
second.setCoordinates(coordinates);
|
||||||
|
|
||||||
assertEquals(first, second);
|
assertEquals(first, second);
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ public class HistoricalWeatherDataUnitTest {
|
|||||||
|
|
||||||
assertEquals(first.hashCode(), second.hashCode());
|
assertEquals(first.hashCode(), second.hashCode());
|
||||||
|
|
||||||
first.setCoordinate(Coordinates.of(11, 42));
|
first.setCoordinates(Coordinates.of(11, 42));
|
||||||
|
|
||||||
assertNotEquals(first.hashCode(), second.hashCode());
|
assertNotEquals(first.hashCode(), second.hashCode());
|
||||||
}
|
}
|
||||||
@ -151,7 +151,7 @@ public class HistoricalWeatherDataUnitTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getToString() {
|
public void getToString() {
|
||||||
final HistoricalWeatherData historicalWeatherData = new HistoricalWeatherData();
|
final HistoricalWeatherData historicalWeatherData = new HistoricalWeatherData();
|
||||||
historicalWeatherData.setCoordinate(Coordinates.of(32, 22));
|
historicalWeatherData.setCoordinates(Coordinates.of(32, 22));
|
||||||
|
|
||||||
assertNotNull(historicalWeatherData.toString());
|
assertNotNull(historicalWeatherData.toString());
|
||||||
assertNotEquals("", historicalWeatherData.toString());
|
assertNotEquals("", historicalWeatherData.toString());
|
||||||
|
|||||||
@ -96,9 +96,9 @@ public class LocationUnitTest {
|
|||||||
public void whenSetCoordinate_thenValueIsSet() {
|
public void whenSetCoordinate_thenValueIsSet() {
|
||||||
final Location location = Location.withValues(33, "test");
|
final Location location = Location.withValues(33, "test");
|
||||||
final Coordinates coordinates = Coordinates.of(33.2, 64.2);
|
final Coordinates coordinates = Coordinates.of(33.2, 64.2);
|
||||||
location.setCoordinate(coordinates);
|
location.setCoordinates(coordinates);
|
||||||
|
|
||||||
assertEquals(coordinates, location.getCoordinate());
|
assertEquals(coordinates, location.getCoordinates());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -107,7 +107,7 @@ public class LocationUnitTest {
|
|||||||
|
|
||||||
assertNotEquals("", location.toString());
|
assertNotEquals("", location.toString());
|
||||||
|
|
||||||
location.setCoordinate(Coordinates.of(33.2, 56.3));
|
location.setCoordinates(Coordinates.of(33.2, 56.3));
|
||||||
|
|
||||||
assertNotEquals("", location.toString());
|
assertNotEquals("", location.toString());
|
||||||
|
|
||||||
@ -191,11 +191,11 @@ public class LocationUnitTest {
|
|||||||
|
|
||||||
final Coordinates coordinates = Coordinates.of(33.5, -22.4);
|
final Coordinates coordinates = Coordinates.of(33.5, -22.4);
|
||||||
|
|
||||||
one.setCoordinate(coordinates);
|
one.setCoordinates(coordinates);
|
||||||
|
|
||||||
assertNotEquals(one, two);
|
assertNotEquals(one, two);
|
||||||
|
|
||||||
two.setCoordinate(coordinates);
|
two.setCoordinates(coordinates);
|
||||||
|
|
||||||
assertEquals(one, two);
|
assertEquals(one, two);
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user