Mercurial > dive4elements > river
changeset 6062:1a169e10c0f3 3.0.5
Add WQFixing sanity check.
Just ensure that values are > 0
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Wed, 22 May 2013 18:32:51 +0200 |
parents | e9a76ffa0f9a |
children | e5cc63c911e8 |
files | artifacts/src/main/java/org/dive4elements/river/artifacts/states/WQFixing.java |
diffstat | 1 files changed, 19 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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; }