Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/states/WaterlevelGroundDifferences.java @ 9277:2323d005f9a5
compile error fix
author | gernotbelger |
---|---|
date | Fri, 20 Jul 2018 10:39:02 +0200 |
parents | e4606eae8ea5 |
children |
rev | line source |
---|---|
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5867
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5867
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4865
diff
changeset
|
9 package org.dive4elements.river.artifacts.states; |
927
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import org.apache.log4j.Logger; |
9277 | 12 import org.dive4elements.artifactdatabase.data.StateData; |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4865
diff
changeset
|
13 import org.dive4elements.artifacts.Artifact; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4865
diff
changeset
|
14 import org.dive4elements.artifacts.CallContext; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4865
diff
changeset
|
15 import org.dive4elements.artifacts.common.utils.XMLUtils; |
9277 | 16 import org.dive4elements.river.artifacts.D4EArtifact; |
17 import org.w3c.dom.Element; | |
927
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 /** |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 */ |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 public class WaterlevelGroundDifferences extends RangeState { |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 |
9277 | 24 public static final String LOWER_FIELD = "diff_from"; |
25 public static final String UPPER_FIELD = "diff_to"; | |
26 public static final String DIFF_FIELD = "diff_diff"; | |
927
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 public static final double DEFAULT_STEP = 0d; |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 |
9277 | 30 private static Logger log = Logger.getLogger(WaterlevelGroundDifferences.class); |
927
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 protected String getLowerField() { |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 return LOWER_FIELD; |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 } |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 protected String getUpperField() { |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 return UPPER_FIELD; |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 } |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 protected String getStepField() { |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 return DIFF_FIELD; |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 } |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 @Override |
9277 | 45 protected double[] getMinMax(final Artifact artifact) { |
927
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 return new double[] { -Double.MAX_VALUE, Double.MAX_VALUE }; |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 } |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 @Override |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 protected String getUIProvider() { |
928
e7664917dbdf
Changed the desired UI provider for the WaterlevelGroundDifferences state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
927
diff
changeset
|
51 return "waterlevel_ground_panel"; |
927
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 } |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 protected double getDefaultStep() { |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 return DEFAULT_STEP; |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 } |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 @Override |
9277 | 59 protected Element[] createItems(final XMLUtils.ElementCreator cr, final Artifact artifact, final String name, final CallContext context) { |
60 final double[] minmax = getMinMax(artifact); | |
927
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 double minVal = Double.MIN_VALUE; |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 double maxVal = Double.MAX_VALUE; |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 if (minmax != null) { |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 minVal = minmax[0]; |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 maxVal = minmax[1]; |
9277 | 68 } else { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7736
diff
changeset
|
69 log.warn("Could not read min/max distance values!"); |
927
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 } |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 if (name.equals(LOWER_FIELD)) { |
9277 | 73 final Element min = createItem(cr, new String[] { "min", new Double(minVal).toString() }); |
927
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 return new Element[] { min }; |
9277 | 76 } else if (name.equals(UPPER_FIELD)) { |
77 final Element max = createItem(cr, new String[] { "max", new Double(maxVal).toString() }); | |
927
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 return new Element[] { max }; |
9277 | 80 } else { |
81 final Element step = createItem(cr, new String[] { "step", String.valueOf(getDefaultStep()) }); | |
927
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 return new Element[] { step }; |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
83 } |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 } |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 |
9277 | 86 // ist mit super identisch! |
87 // protected Element createItem(XMLUtils.ElementCreator cr, Object obj) { | |
88 // Element item = ProtocolUtils.createArtNode(cr, "item", null, null); | |
89 // Element label = ProtocolUtils.createArtNode(cr, "label", null, null); | |
90 // Element value = ProtocolUtils.createArtNode(cr, "value", null, null); | |
91 // | |
92 // String[] arr = (String[]) obj; | |
93 // | |
94 // label.setTextContent(arr[0]); | |
95 // value.setTextContent(arr[1]); | |
96 // | |
97 // item.appendChild(label); | |
98 // item.appendChild(value); | |
99 // | |
100 // return item; | |
101 // } | |
4865
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
928
diff
changeset
|
102 |
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
928
diff
changeset
|
103 @Override |
9277 | 104 public boolean validate(final Artifact artifact) throws IllegalArgumentException { |
105 final D4EArtifact flys = (D4EArtifact) artifact; | |
4865
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
928
diff
changeset
|
106 |
9277 | 107 final StateData dFrom = getData(flys, getLowerField()); |
108 final StateData dTo = getData(flys, getUpperField()); | |
109 final StateData dStep = getData(flys, getStepField()); | |
4865
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
928
diff
changeset
|
110 |
9277 | 111 final String fromStr = dFrom != null ? (String) dFrom.getValue() : null; |
112 final String toStr = dTo != null ? (String) dTo.getValue() : null; | |
113 final String stepStr = dStep != null ? (String) dStep.getValue() : null; | |
4865
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
928
diff
changeset
|
114 |
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
928
diff
changeset
|
115 if (fromStr == null || toStr == null || stepStr == null) { |
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
928
diff
changeset
|
116 throw new IllegalArgumentException("error_empty_state"); |
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
928
diff
changeset
|
117 } |
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
928
diff
changeset
|
118 |
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
928
diff
changeset
|
119 try { |
9277 | 120 final double from = Double.parseDouble(fromStr); |
121 final double to = Double.parseDouble(toStr); | |
122 final double step = Double.parseDouble(stepStr); | |
4865
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
928
diff
changeset
|
123 |
9277 | 124 final double[] minmax = getMinMax(flys); |
4865
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
928
diff
changeset
|
125 |
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
928
diff
changeset
|
126 return validateBounds(minmax[0], minmax[1], from, to, step); |
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
928
diff
changeset
|
127 } |
9277 | 128 catch (final NumberFormatException nfe) { |
4865
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
928
diff
changeset
|
129 throw new IllegalArgumentException("error_invalid_double_value"); |
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
928
diff
changeset
|
130 } |
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
928
diff
changeset
|
131 } |
7736
714fda61b006
Server side validation for flys/issue1549.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
132 |
714fda61b006
Server side validation for flys/issue1549.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
133 @Override |
9277 | 134 protected boolean validateBounds(final double fromValid, final double toValid, final double from, final double to) throws IllegalArgumentException { |
7736
714fda61b006
Server side validation for flys/issue1549.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
135 if (to < 0d) { |
9277 | 136 log.error("Invalid 'to' " + to + " is lesser than zero."); |
7736
714fda61b006
Server side validation for flys/issue1549.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
137 throw new IllegalArgumentException("error_feed_from_out_of_range"); |
714fda61b006
Server side validation for flys/issue1549.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
138 } |
714fda61b006
Server side validation for flys/issue1549.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
139 return super.validateBounds(fromValid, toValid, from, to); |
714fda61b006
Server side validation for flys/issue1549.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
140 } |
927
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
141 } |
53a2be494765
Enhanced the transition model to continue the parameterization in the waterlevel state to compute flood maps.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
142 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |