Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java @ 322:448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
flys-artifacts/trunk@1716 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 18 Apr 2011 12:36:08 +0000 |
parents | a8e7c351bdf1 |
children | ed3325a0232a |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java Mon Apr 18 09:34:18 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java Mon Apr 18 12:36:08 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; @@ -23,7 +25,7 @@ /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ -public class WQSelect extends DefaultState { +public class WQSelect extends RangeState { /** The logger used in this class.*/ private static Logger logger = Logger.getLogger(WQSelect.class); @@ -35,6 +37,18 @@ /** The default step width for Qs.*/ public static final String DEFAULT_STEP_W = "30"; + /** The name of the 'mode' field. */ + public static final String WQ_MODE = "wq_mode"; + + /** The name of the 'from' field. */ + public static final String WQ_FROM = "wq_from"; + + /** The name of the 'to' field. */ + public static final String WQ_TO = "wq_to"; + + /** The name of the 'step' field. */ + public static final String WQ_STEP = "wq_step"; + /** * The default constructor that initializes an empty State object. */ @@ -172,5 +186,95 @@ return new double[] { minQ, maxQ }; } + + + @Override + public boolean validate(Artifact artifact, CallContext context) + throws IllegalArgumentException + { + logger.debug("WQSelect.validate"); + + Map<String, StateData> data = getData(); + + String mode = (String) data.get(WQ_MODE).getValue(); + logger.debug("WQ Mode: " + mode); + + String fromStr = (String) data.get(WQ_FROM).getValue(); + String toStr = (String) data.get(WQ_TO).getValue(); + String stepStr = (String) data.get(WQ_STEP).getValue(); + + double from = Double.parseDouble(fromStr); + double to = Double.parseDouble(toStr); + double step = Double.parseDouble(stepStr); + + try { + if (mode != null && mode.trim().toLowerCase().equals("w")) { + return validateW(artifact, context, from, to, step); + } + else if (mode != null && mode.trim().toLowerCase().equals("q")) { + return validateQ(artifact, context, from, to, step); + } + else { + throw new IllegalArgumentException("error_feed_invalid_wq_mode"); + } + } + catch (NumberFormatException nfe) { + throw new IllegalArgumentException("error_feed_number_format"); + } + } + + + /** + * Validates the inserted W values. + * + * @param artifact The owner artifact. + * @param context The CallContext + * @param from The lower value of the W range. + * @param to The upper value of the W range. + * @param step The step width. + * + * @return true, if everything was fine, otherwise an exception is thrown. + */ + protected boolean validateW( + Artifact artifact, + CallContext context, + double from, + double to, + double step) + throws IllegalArgumentException + { + logger.debug("WQSelect.validateW"); + + double[] minmaxW = determineMinMaxW(artifact); + + return validateRange(minmaxW[0], minmaxW[1], from, to, step); + } + + + /** + * Validates the inserted Q values. + * + * @param artifact The owner artifact. + * @param context The CallContext + * @param from The lower value of the Q range. + * @param to The upper value of the Q range. + * @param step The step width. + * + * @return true, if everything was fine, otherwise an exception is thrown. + */ + protected boolean validateQ( + Artifact artifact, + CallContext context, + double from, + double to, + double step) + throws IllegalArgumentException + { + logger.debug("WQSelect.validateQ"); + + double[] minmaxQ = determineMinMaxQ(artifact); + + return validateRange(minmaxQ[0], minmaxQ[1], from, to, step); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :