Mercurial > dive4elements > river
changeset 323:b33ba2cd4a3e
The calculation method is validated in the feed() operation.
flys-artifacts/trunk@1717 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 18 Apr 2011 13:00:57 +0000 |
parents | 448d0dc64357 |
children | cd9e397cc2a8 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/CalculationSelect.java |
diffstat | 2 files changed, 45 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Mon Apr 18 12:36:08 2011 +0000 +++ b/flys-artifacts/ChangeLog Mon Apr 18 13:00:57 2011 +0000 @@ -1,3 +1,9 @@ +2011-04-18 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/states/CalculationSelect.java: + The inserted calculation method is validated now (overrides validate() + of DefaultState). + 2011-04-18 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/CalculationSelect.java Mon Apr 18 12:36:08 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/CalculationSelect.java Mon Apr 18 13:00:57 2011 +0000 @@ -1,5 +1,7 @@ package de.intevation.flys.artifacts.states; +import java.util.Map; + import org.apache.log4j.Logger; import org.w3c.dom.Element; @@ -11,6 +13,7 @@ import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.artifactdatabase.ProtocolUtils; +import de.intevation.artifactdatabase.data.StateData; import de.intevation.flys.artifacts.resources.Resources; @@ -52,6 +55,16 @@ CALCULATION_DISCHARGE_LONGITUDINAL_CURVE }; + /** Error message that is thrown if no mode has been chosen.*/ + public static final String ERROR_NO_CALCULATION_MODE = + "error_feed_no_calculation_mode"; + + /** Error message that is thrown if an invalid calculation mode has been + * chosen.*/ + public static final String ERROR_INVALID_CALCULATION_MODE = + "error_feed_invalid_calculation_mode"; + + protected Element[] createItems( XMLUtils.ElementCreator cr, Artifact artifact, @@ -90,5 +103,31 @@ return item; } + + + @Override + public boolean validate(Artifact artifact, CallContext context) + throws IllegalArgumentException + { + logger.debug("CalculationSelect.validate"); + + Map<String, StateData> data = getData(); + + String calc = (String) data.get("calculation_mode").getValue(); + + if (calc == null) { + throw new IllegalArgumentException(ERROR_NO_CALCULATION_MODE); + } + + calc = calc.trim().toLowerCase(); + + for (String mode: CALCULATIONS) { + if (mode.equals(calc)) { + return true; + } + } + + throw new IllegalArgumentException(ERROR_INVALID_CALCULATION_MODE); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :