diff --git a/src/main/java/no/nibio/vips/ipmdecisions/DataTransformer.java b/src/main/java/no/nibio/vips/ipmdecisions/DataTransformer.java index d25a362b2a05eb6b56bf72d2a032ad1f585547a1..64dae847ae8c8c4908d2b8fd2e455740cb8cdb66 100644 --- a/src/main/java/no/nibio/vips/ipmdecisions/DataTransformer.java +++ b/src/main/java/no/nibio/vips/ipmdecisions/DataTransformer.java @@ -29,6 +29,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import net.ipmdecisions.model.entity.LocationResult; import net.ipmdecisions.model.entity.ModelOutput; import net.ipmdecisions.weather.entity.LocationWeatherData; @@ -45,10 +46,25 @@ import no.nibio.vips.observation.ObservationImpl; */ public class DataTransformer { - public List<WeatherObservation> getVIPSWeatherData(WeatherData IPMWeatherData) + public List<WeatherObservation> getVIPSWeatherData(WeatherData IPMWeatherData) throws DataTransformerException { - List<WeatherObservation> retVal = new ArrayList<>(); IPMDecisionsWeatherUtil ipmUtil = new IPMDecisionsWeatherUtil(); + // Input check: Are we able to transform all the parameters? + List<Integer> missingParamCodes = new ArrayList<>(); + for(Integer paramCode: IPMWeatherData.getWeatherParameters()) + { + if(ipmUtil.getVIPSParameterId(paramCode) == null) + { + missingParamCodes.add(paramCode); + } + } + if(missingParamCodes.size() > 0) + { + String paramStr = missingParamCodes.stream().map(p->String.valueOf(p)).collect(Collectors.joining(",")); + throw new DataTransformerException("Could not find matching internal parameter codes for: " + paramStr); + } + + List<WeatherObservation> retVal = new ArrayList<>(); Integer logIntervalId = IPMWeatherData.getInterval().equals(3600) ? WeatherObservation.LOG_INTERVAL_ID_1H : WeatherObservation.LOG_INTERVAL_ID_1D; LocationWeatherData oneLocation = IPMWeatherData.getLocationWeatherData().get(0); diff --git a/src/main/java/no/nibio/vips/ipmdecisions/DataTransformerException.java b/src/main/java/no/nibio/vips/ipmdecisions/DataTransformerException.java new file mode 100644 index 0000000000000000000000000000000000000000..fe36dbdfc8652775339b8b985fa0687b172960a6 --- /dev/null +++ b/src/main/java/no/nibio/vips/ipmdecisions/DataTransformerException.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2021 NIBIO <http://www.nibio.no/>. + * + * This file is part of VIPSCommon. + * VIPSCommon 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. + * + * VIPSCommon 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 VIPSCommon. If not, see <http://www.nibio.no/licenses/>. + * + */ + +package no.nibio.vips.ipmdecisions; + +/** + * @copyright 2021 <a href="http://www.nibio.no/">NIBIO</a> + * @author Tor-Einar Skog <tor-einar.skog@nibio.no> + */ +class DataTransformerException extends Exception { + public DataTransformerException(String msg) + { + super(msg); + } +} diff --git a/src/main/java/no/nibio/vips/ipmdecisions/IPMDecisionsWeatherUtil.java b/src/main/java/no/nibio/vips/ipmdecisions/IPMDecisionsWeatherUtil.java index ab91109bd9c2bf2e12b0167830420145bc025f17..34cddb6551cc527a065fbdbec102c6a691dae32f 100644 --- a/src/main/java/no/nibio/vips/ipmdecisions/IPMDecisionsWeatherUtil.java +++ b/src/main/java/no/nibio/vips/ipmdecisions/IPMDecisionsWeatherUtil.java @@ -44,7 +44,8 @@ public class IPMDecisionsWeatherUtil { 4002, WeatherElements.WIND_SPEED_2M, // FM2/FF2 4003, WeatherElements.WIND_SPEED_2M, // FM2/FF2 5001, WeatherElements.GLOBAL_RADIATION, // Q0 - 3101, WeatherElements.LEAF_WETNESS_DURATION // BT + 3101, WeatherElements.LEAF_WETNESS_DURATION, // BT + 1901, WeatherElements.DEW_POINT_TEMPERATURE // DT ); public Integer getIPMParameterId(String VIPSParameterId)