From ba85db18a72c57f7bc777193d22cfb8d4224db11 Mon Sep 17 00:00:00 2001 From: Tor-Einar Skog <tor-einar.skog@nibio.no> Date: Mon, 15 Mar 2021 10:51:18 +0100 Subject: [PATCH] Adding error handling when missing IPM Decisions weather parameter Adding Dew point to IPMD parameters we do handle --- .../vips/ipmdecisions/DataTransformer.java | 20 ++++++++++-- .../DataTransformerException.java | 31 +++++++++++++++++++ .../ipmdecisions/IPMDecisionsWeatherUtil.java | 3 +- 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 src/main/java/no/nibio/vips/ipmdecisions/DataTransformerException.java diff --git a/src/main/java/no/nibio/vips/ipmdecisions/DataTransformer.java b/src/main/java/no/nibio/vips/ipmdecisions/DataTransformer.java index d25a362..64dae84 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 0000000..fe36dbd --- /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 ab91109..34cddb6 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) -- GitLab