[Dive4elements-commits] [PATCH] Fix WQ input validation for fixing analysis
Wald Commits
scm-commit at wald.intevation.org
Wed May 22 17:08:25 CEST 2013
# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1369235286 -7200
# Node ID 0a200ba544617c4e8030486e4f8fb22a533bb794
# Parent 5f52a80796259687e9a6dc0c37c04468db8da540
Fix WQ input validation for fixing analysis
It is basically the same as the other WQ inputs but here all
positive numbers are valid.
diff -r 5f52a8079625 -r 0a200ba54461 artifacts/doc/conf/artifacts/fixanalysis.xml
--- a/artifacts/doc/conf/artifacts/fixanalysis.xml Wed May 22 13:03:10 2013 +0200
+++ b/artifacts/doc/conf/artifacts/fixanalysis.xml Wed May 22 17:08:06 2013 +0200
@@ -246,7 +246,7 @@
<state id="state.fix.vollmer.qs" description="state.fix.vollmer.qs"
helpText="help.state.fix.vollmer.qs"
- state="org.dive4elements.river.artifacts.states.WQAdapted">
+ state="org.dive4elements.river.artifacts.states.WQFixing">
<data name="wq_isq" type="String" />
<data name="wq_values" type="WQTriple" />
</state>
diff -r 5f52a8079625 -r 0a200ba54461 artifacts/src/main/java/org/dive4elements/river/artifacts/states/WQFixing.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/WQFixing.java Wed May 22 17:08:06 2013 +0200
@@ -0,0 +1,37 @@
+/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+package org.dive4elements.river.artifacts.states;
+
+import org.dive4elements.artifacts.Artifact;
+
+import org.apache.log4j.Logger;
+
+/**
+ * State to input W/Q data for fixings
+ * @author <a href="mailto:aheinecke at intevation.de">Andre Heinecke</a>
+ */
+public class WQFixing extends WQAdapted {
+
+ /** The logger used in this state.*/
+ private static Logger logger = Logger.getLogger(WQFixing.class);
+
+ @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
+ return true;
+ }
+
+ @Override
+ protected String getUIProvider() {
+ return "wq_panel_adapted_fixing";
+ }
+}
diff -r 5f52a8079625 -r 0a200ba54461 gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java Wed May 22 13:03:10 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java Wed May 22 17:08:06 2013 +0200
@@ -620,6 +620,8 @@
String error_validate_upper_range();
+ String error_validate_positive();
+
String error_create_artifact();
String error_describe_artifact();
diff -r 5f52a8079625 -r 0a200ba54461 gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties Wed May 22 13:03:10 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties Wed May 22 17:08:06 2013 +0200
@@ -316,6 +316,7 @@
error_validate_date_range_invalid = The specified timerange is invalid.
error_validate_lower_range = The lower value $1 needs to be bigger than $2.
error_validate_upper_range = The upper value $1 needs to be smaller than $2.
+error_validate_positive = The value $1 must be positive.
error_empty_state = Required inputs are missing.
error_invalid_double_value = Wrong format for a floating point number.
error_create_artifact = Error while creating new project.
diff -r 5f52a8079625 -r 0a200ba54461 gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties Wed May 22 13:03:10 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties Wed May 22 17:08:06 2013 +0200
@@ -316,6 +316,7 @@
error_validate_date_range_invalid = Der eingegebene Zeitbereich ist ung\u00fcltig.
error_validate_lower_range = Der untere Wert $1 muss gr\u00f6\u00dfer sein als $2.
error_validate_upper_range = Der obere Wert $1 muss kleiner sein als $2.
+error_validate_positive = Der Wert $1 muss eine positive Zahl sein.
error_empty_state = Es wurden nicht alle ben\u00d6tigten Daten eingegeben.
error_invalid_double_value = Falsches Format f\u00fc eine Flie\u00dfkommazahl.
error_create_artifact = Fehler beim Erstellen eines neuen Projekts.
diff -r 5f52a8079625 -r 0a200ba54461 gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_en.properties
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_en.properties Wed May 22 13:03:10 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_en.properties Wed May 22 17:08:06 2013 +0200
@@ -314,6 +314,7 @@
error_validate_date_range_invalid = The specified timerange is invalid.
error_validate_lower_range = The lower value $1 needs to be bigger than $2.
error_validate_upper_range = The upper value $1 needs to be smaller than $2.
+error_validate_positive = The value $1 must be positive.
error_empty_state = Required inputs are missing.
error_invalid_double_value = Wrong format for a floating point number.
error_create_artifact = Error while creating new project.
diff -r 5f52a8079625 -r 0a200ba54461 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java Wed May 22 13:03:10 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java Wed May 22 17:08:06 2013 +0200
@@ -70,6 +70,9 @@
else if (uiProvider.equals("wq_panel_adapted")) {
return new WQAdaptedInputPanel();
}
+ else if (uiProvider.equals("wq_panel_adapted_fixing")) {
+ return new WQAdaptedFixingInputPanel();
+ }
else if (uiProvider.equals("q_segmented_panel")) {
return new QSegmentedInputPanel();
}
diff -r 5f52a8079625 -r 0a200ba54461 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WQAdaptedFixingInputPanel.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WQAdaptedFixingInputPanel.java Wed May 22 17:08:06 2013 +0200
@@ -0,0 +1,75 @@
+/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.client.client.ui;
+
+import com.google.gwt.i18n.client.NumberFormat;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This UIProvider creates a widget to enter W or Q data for
+ * Fixation analysis
+ *
+ * @author <a href="mailto:aheinecke at intevation.de">Andre Heinecke</a>
+ */
+public class WQAdaptedFixingInputPanel
+extends WQAdaptedInputPanel
+{
+ private static final long serialVersionUID = -3218827566805476423L;
+
+ @Override
+ protected List<String> validateRange(Map<String, double[]> ranges) {
+ List<String> errors = new ArrayList<String>();
+ NumberFormat nf = NumberFormat.getDecimalFormat();
+
+ Iterator<String> iter = wqranges.keySet().iterator();
+
+ while (iter.hasNext()) {
+ List<String> tmpErrors = new ArrayList<String>();
+
+ String key = iter.next();
+ DoubleArrayPanel dap = wqranges.get(key);
+
+ if (!dap.validateForm()) {
+ errors.add(MSG.error_invalid_double_value());
+ return errors;
+ }
+
+ int idx = 0;
+
+ double[] values = dap.getInputValues();
+
+ double[] good = new double[values.length];
+
+ for (double value: values) {
+ if (value <= 0) {
+ String tmp = MSG.error_validate_positive();
+ tmp = tmp.replace("$1", nf.format(value));
+ errors.add(tmp);
+ } else {
+ good[idx++] = value;
+ }
+ }
+
+ double[] justGood = new double[idx];
+ for (int i = 0; i < justGood.length; i++) {
+ justGood[i] = good[i];
+ }
+
+ if (!errors.isEmpty()) {
+ dap.setValues(justGood);
+ }
+ }
+ return errors;
+ }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
More information about the Dive4elements-commits
mailing list