Skip to content
Snippets Groups Projects
Commit e870e44d authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Added forecast provider for FMI

parent a69e4806
No related branches found
No related tags found
No related merge requests found
/*
* Copyright (c) 2020 NIBIO <http://www.nibio.no/>.
*
* This file is part of VIPSLogic.
* VIPSLogic is free software: you can redistribute it and/or modify
* it under the terms of the NIBIO Open Source License as published by
* NIBIO, either version 1 of the License, or (at your option) any
* later version.
*
* VIPSLogic is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* NIBIO Open Source License for more details.
*
* You should have received a copy of the NIBIO Open Source License
* along with VIPSLogic. If not, see <http://www.nibio.no/licenses/>.
*
*/
package no.nibio.vips.util.weather;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.net.URL;
import java.text.MessageFormat;
import java.util.List;
import no.nibio.vips.entity.WeatherObservation;
import no.nibio.vips.logic.entity.PointOfInterest;
/**
* Provides forecasts from
* @copyright 2020 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class FMIWeatherForecastprovider implements WeatherForecastProvider {
private final static String FMI_VIPS_WEATHER_PROXY_URL = "http://localhost:8080/VIPSWeatherProxy/rest/forecasts/fmi?longitude={0}&latitude={1}&altitude={2}";
@Override
public List<WeatherObservation> getWeatherForecasts(PointOfInterest location) throws ParseWeatherDataException {
if(location.getGisGeom() != null)
{
return this.getWeatherForecasts(location.getGisGeom().getCoordinate().x, location.getGisGeom().getCoordinate().y, location.getGisGeom().getCoordinate().z);
}
else
{
return this.getWeatherForecasts(location.getLongitude(), location.getLatitude(), location.getAltitude());
}
}
public List<WeatherObservation> getWeatherForecasts(Double longitude, Double latitude, Double altitude) throws ParseWeatherDataException
{
try
{
URL FMIVIPSWeatherProxyURL = new URL(MessageFormat.format(
FMIWeatherForecastprovider.FMI_VIPS_WEATHER_PROXY_URL,
longitude, latitude, 0
));
//String unserializedResponse = new Scanner(FMIVIPSWeatherProxyURL.openStream(),"UTF-8")
// .useDelimiter("\\A").next();
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.readValue(FMIVIPSWeatherProxyURL.openStream(),new TypeReference<List<WeatherObservation>>(){});
}
catch(IOException ex)
{
throw new ParseWeatherDataException(ex.getMessage());
}
}
}
......@@ -25,6 +25,7 @@ package no.nibio.vips.util.weather;
*/
public class WeatherStationProviderFactory {
public final static int YR = 1;
public final static int FMI = 2;
public static WeatherForecastProvider getWeatherForecastProvider(Integer weatherForecastProviderId)
{
......@@ -32,6 +33,8 @@ public class WeatherStationProviderFactory {
{
case WeatherStationProviderFactory.YR:
return new YrWeatherForecastProvider();
case WeatherStationProviderFactory.FMI:
return new FMIWeatherForecastprovider();
default:
return null;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment