Mercurial > dive4elements > river
changeset 2060:3ffb7195173f
Validate user defined Qs based on the start kilometer ('Q free').
flys-artifacts/trunk@3553 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 28 Dec 2011 12:39:35 +0000 (2011-12-28) |
parents | 522826b41ffa |
children | 87f9153bb7ca |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java |
diffstat | 2 files changed, 93 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Wed Dec 28 08:28:13 2011 +0000 +++ b/flys-artifacts/ChangeLog Wed Dec 28 12:39:35 2011 +0000 @@ -1,3 +1,10 @@ +2011-12-28 Ingo Weinzierl <ingo@intevation.de> + + flys/issue104 (W-INFO: Wasserspiegellagenberechnung / Strecke) + + * src/main/java/de/intevation/flys/artifacts/states/WQSelect.java: + Validate user defined free Q values. + 2011-12-28 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/artifacts/states/WQSelect.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java Wed Dec 28 08:28:13 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java Wed Dec 28 12:39:35 2011 +0000 @@ -222,7 +222,7 @@ { // TODO Insert correct min/max values! double[] minmaxW = determineMinMaxW(artifact); - double[] minmaxQ = determineMinMaxQ(artifact); + double[] minmaxQ = determineMinMaxQAtGauge(artifact); if (name.equals("wq_from")) { Element minW = createItem( @@ -356,8 +356,8 @@ * * @return the min and max Q values for the current gauge. */ - protected double[] determineMinMaxQ(Artifact artifact) { - logger.debug("WQSelect.determineMinMaxQ"); + protected double[] determineMinMaxQAtGauge(Artifact artifact) { + logger.debug("WQSelect.determineMinMaxQAtGauge"); WINFOArtifact flysArtifact = (WINFOArtifact) artifact; @@ -376,6 +376,37 @@ } + /** + * Determines the min and max Q value for the current kilometer range. If no + * min and max values could be determined, this method will return + * + * @param artifact The FLYSArtifact. + * + * @return the min and max Q values for the current kilometer range. + */ + protected double[] determineMinMaxQ(Artifact artifact) { + logger.debug("WQSelect.determineMinMaxQ"); + + FLYSArtifact flys = (FLYSArtifact) artifact; + double[] kms = FLYSUtils.getKmRange(flys); + + if (kms == null || kms.length == 0) { + return new double[] { Double.MIN_VALUE, Double.MAX_VALUE }; + } + + River river = FLYSUtils.getRiver(flys); + Wst wst = WstFactory.getWst(river); + + logger.debug("User defined KMs: " + kms[0] + " - " + kms[kms.length-1]); + + double[] minmaxQ = wst.determineMinMaxQ(kms[0], kms[0]); + + return minmaxQ != null + ? minmaxQ + : new double[] { Double.MIN_VALUE, Double.MAX_VALUE }; + } + + @Override public boolean validate(Artifact artifact) throws IllegalArgumentException @@ -446,16 +477,18 @@ all.sort(); - StateData dMode = getData(flys, WQ_MODE); - String mode = dMode != null ? (String) data.getValue() : null; + FLYSUtils.WQ_MODE mode = FLYSUtils.getWQMode(flys); logger.debug("WQ Mode: " + mode); double[] minmax = null; - if (mode != null && mode.trim().toLowerCase().equals("w")) { + if (mode == FLYSUtils.WQ_MODE.WGAUGE) { minmax = determineMinMaxW(artifact); } + else if (mode == FLYSUtils.WQ_MODE.QGAUGE) { + minmax = determineMinMaxQAtGauge(artifact); + } else { minmax = determineMinMaxQ(artifact); } @@ -474,13 +507,11 @@ throws IllegalArgumentException { logger.debug("WQSelect.validateRange"); - WINFOArtifact flys = (WINFOArtifact) artifact; - StateData data = flys.getData(WQ_MODE); - String mode = data != null ? (String) data.getValue() : null; - logger.debug("WQ Mode: " + mode); + WINFOArtifact flys = (WINFOArtifact) artifact; + FLYSUtils.WQ_MODE mode = FLYSUtils.getWQMode(flys); - if (mode == null || mode.length() == 0) { + if (mode == null) { throw new IllegalArgumentException("error_feed_invalid_wq_mode"); } @@ -501,11 +532,14 @@ double to = Double.parseDouble(toStr); double step = Double.parseDouble(stepStr); - if (mode != null && mode.trim().toLowerCase().equals("w")) { - return validateW(artifact, from, to, step); + if (mode == FLYSUtils.WQ_MODE.WGAUGE) { + return validateGaugeW(artifact, from, to, step); } - else if (mode != null && mode.trim().toLowerCase().equals("q")) { - return validateQ(artifact, from, to, step); + else if (mode == FLYSUtils.WQ_MODE.QGAUGE) { + return validateGaugeQ(artifact, from, to, step); + } + else if (mode == FLYSUtils.WQ_MODE.QFREE) { + return validateFreeQ(artifact, from, to, step); } else { throw new IllegalArgumentException( @@ -528,14 +562,14 @@ * * @return true, if everything was fine, otherwise an exception is thrown. */ - protected boolean validateW( + protected boolean validateGaugeW( Artifact artifact, double from, double to, double step) throws IllegalArgumentException { - logger.debug("WQSelect.validateW"); + logger.debug("WQSelect.validateGaugeW"); double[] minmaxW = determineMinMaxW(artifact); @@ -544,7 +578,8 @@ /** - * Validates the inserted Q values. + * Validates the inserted Q values based on the Q range for the current + * gauge. * * @param artifact The owner artifact. * @param from The lower value of the Q range. @@ -553,14 +588,40 @@ * * @return true, if everything was fine, otherwise an exception is thrown. */ - protected boolean validateQ( - Artifact artifact, - double from, - double to, - double step) - throws IllegalArgumentException + protected boolean validateGaugeQ( + Artifact artifact, + double from, + double to, + double step) + throws IllegalArgumentException { - logger.debug("WQSelect.validateQ"); + logger.debug("WQSelect.validateGaugeQ"); + + double[] minmaxQ = determineMinMaxQAtGauge(artifact); + + return validateBounds(minmaxQ[0], minmaxQ[1], from, to, step); + } + + + /** + * Validates the inserted Q values based on the Q range for the current + * kilometer range. + * + * @param artifact The owner artifact. + * @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 validateFreeQ( + Artifact artifact, + double from, + double to, + double step) + throws IllegalArgumentException + { + logger.debug("WQSelect.validateFreeQ"); double[] minmaxQ = determineMinMaxQ(artifact);