[Dive4elements-commits] [PATCH] Add WQFixing sanity check

Wald Commits scm-commit at wald.intevation.org
Wed May 22 18:32:53 CEST 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1369240371 -7200
# Node ID 1a169e10c0f3e1f33990a91dd294512ac97d1a70
# Parent  e9a76ffa0f9ae1159e19acd625d241b712cefc1f
Add WQFixing sanity check.

    Just ensure that values are > 0

diff -r e9a76ffa0f9a -r 1a169e10c0f3 artifacts/src/main/java/org/dive4elements/river/artifacts/states/WQFixing.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/WQFixing.java	Wed May 22 18:10:48 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/WQFixing.java	Wed May 22 18:32:51 2013 +0200
@@ -8,6 +8,8 @@
 package org.dive4elements.river.artifacts.states;
 
 import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.model.RangeWithValues;
 
 import org.apache.log4j.Logger;
 
@@ -20,13 +22,28 @@
     /** The logger used in this state.*/
     private static Logger logger = Logger.getLogger(WQFixing.class);
 
+    /** Simple sanity check if values are positive numbers **/
     @Override
     public boolean validate(Artifact artifact)
     throws IllegalArgumentException
     {
         logger.debug("WQFixing.validate");
-        // A check for positive values is already done by the client
-        // all positive values are valid
+
+        RangeWithValues[] rwvs = extractInput(getData((D4EArtifact) artifact, "wq_values"));
+
+        if (rwvs == null) {
+            throw new IllegalArgumentException("error_missing_wq_data");
+        }
+
+        for (RangeWithValues rwv: rwvs) {
+            double[] values = rwv.getValues();
+            for (double val: values) {
+                if (val <= 0) {
+                    throw new IllegalArgumentException("error_validate_positive");
+                }
+            }
+        }
+
         return true;
     }
 


More information about the Dive4elements-commits mailing list