Mercurial > dive4elements > river
changeset 2013:9d5f339d83a3
#380 Validate the user selected DEM in the server.
flys-artifacts/trunk@3462 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 19 Dec 2011 10:01:17 +0000 |
parents | 514d26021728 |
children | b11793a3e7c7 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DGMSelect.java |
diffstat | 3 files changed, 107 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Mon Dec 19 09:08:40 2011 +0000 +++ b/flys-artifacts/ChangeLog Mon Dec 19 10:01:17 2011 +0000 @@ -1,3 +1,14 @@ +2011-12-19 Ingo Weinzierl <ingo@intevation.de> + + flys/issue380 (W-INFO / Überschwemmungskarte, falsches DGM) + + * src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: Added a + convinience method that returns a parameter of FLYSArtifact as Integer. + + * src/main/java/de/intevation/flys/artifacts/states/DGMSelect.java: Override + validate() to determine, if the DGM selected by the user is valid for the + current calculation range and river. + 2011-12-19 Felix Wolfsteller <felix.wolfsteller@intevation.de> * src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Mon Dec 19 09:08:40 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Mon Dec 19 10:01:17 2011 +0000 @@ -550,6 +550,31 @@ /** + * This method returns the value of a StateData object stored in the data + * pool of this Artifact as Integer. + * + * @param name The name of the StateData object. + * + * @return an Integer representing the value of the data object or null if + * no object was found for <i>name</i>. + * + * @throws NumberFormatException if the value of the data object could not + * be transformed into an Integer. + */ + public Integer getDataAsInteger(String name) + throws NumberFormatException + { + String value = getDataAsString(name); + + if (value != null && value.length() > 0) { + return Integer.parseInt(value); + } + + return null; + } + + + /** * Add StateData containing a given string. * @param name Name of the data object. * @param value String to store.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DGMSelect.java Mon Dec 19 09:08:40 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DGMSelect.java Mon Dec 19 10:01:17 2011 +0000 @@ -6,12 +6,16 @@ import org.apache.log4j.Logger; +import de.intevation.artifacts.Artifact; import de.intevation.artifacts.CallContext; import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; +import de.intevation.flys.model.DGM; +import de.intevation.flys.model.River; + import de.intevation.flys.artifacts.FLYSArtifact; -import de.intevation.flys.model.DGM; +import de.intevation.flys.utils.FLYSUtils; /** @@ -21,6 +25,11 @@ private static final Logger logger = Logger.getLogger(DGMSelect.class); + public static final String ERR_EMPTY = "error_no_dgm_selected"; + public static final String ERR_INVALID_DGM = "error_invalid_dgm_selected"; + public static final String ERR_BAD_DGM_RANGE = "error_bad_dgm_range"; + public static final String ERR_BAD_DGM_RIVER = "error_bad_dgm_river"; + @Override protected String getUIProvider() { @@ -66,5 +75,66 @@ return ""; } + + + @Override + public boolean validate(Artifact artifact) + throws IllegalArgumentException + { + FLYSArtifact flys = (FLYSArtifact) artifact; + + DGM dgm = getDGM(flys); + + if (dgm == null) { + throw new IllegalArgumentException(ERR_INVALID_DGM); + } + + double l = dgm.getLower().doubleValue(); + double u = dgm.getUpper().doubleValue(); + + double[] range = FLYSUtils.getKmFromTo(flys); + + if (range[0] < l || range[0] > u || range[1] < l || range[1] > u) { + throw new IllegalArgumentException(ERR_BAD_DGM_RANGE); + } + + River selectedRiver = FLYSUtils.getRiver(flys); + River dgmRiver = dgm.getRiver(); + + if (selectedRiver != dgmRiver) { + throw new IllegalArgumentException(ERR_BAD_DGM_RIVER); + } + + return true; + } + + + /** + * Returns the DGM specified in the parameters of <i>flys</i>. + * + * @param flys The FLYSArtifact that knows the ID of a DGM. + * + * @throws IllegalArgumentException If the FLYSArtifact doesn't know the ID + * of a DGM. + * + * @return the DGM specified by FLYSArtifact's parameters. + */ + public static DGM getDGM(FLYSArtifact flys) + throws IllegalArgumentException + { + try { + Integer dgmId = flys.getDataAsInteger("dgm"); + if (dgmId == null) { + throw new IllegalArgumentException(ERR_EMPTY); + } + + logger.debug("Found selected dgm: '" + dgmId + "'"); + + return DGM.getDGM(dgmId); + } + catch (NumberFormatException nfe) { + throw new IllegalArgumentException(ERR_INVALID_DGM); + } + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :