Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/CalculationSelect.java @ 9638:6c1ebf2220f5
# 19b (check for usages of WaterlevelExporter.getWforGaugeAndQ) -> cleanup: removing calc.extreme.curve
author | dnt_bjoernsen <d.tironi@bjoernsen.de> |
---|---|
date | Thu, 31 Oct 2019 17:37:53 +0100 |
parents | e4606eae8ea5 |
children |
comparison
equal
deleted
inserted
replaced
9635:a03c54129819 | 9638:6c1ebf2220f5 |
---|---|
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.artifacts.states; | 9 package org.dive4elements.river.artifacts.states; |
10 | 10 |
11 import org.apache.log4j.Logger; | 11 import org.apache.log4j.Logger; |
12 | 12 import org.dive4elements.artifactdatabase.data.StateData; |
13 import org.w3c.dom.Element; | |
14 | |
15 import org.dive4elements.artifacts.Artifact; | 13 import org.dive4elements.artifacts.Artifact; |
16 import org.dive4elements.artifacts.CallContext; | 14 import org.dive4elements.artifacts.CallContext; |
17 import org.dive4elements.artifacts.CallMeta; | 15 import org.dive4elements.artifacts.CallMeta; |
18 | |
19 import org.dive4elements.artifacts.common.utils.XMLUtils; | 16 import org.dive4elements.artifacts.common.utils.XMLUtils; |
20 | |
21 import org.dive4elements.artifactdatabase.data.StateData; | |
22 | |
23 import org.dive4elements.river.artifacts.D4EArtifact; | 17 import org.dive4elements.river.artifacts.D4EArtifact; |
24 import org.dive4elements.river.artifacts.resources.Resources; | 18 import org.dive4elements.river.artifacts.resources.Resources; |
19 import org.w3c.dom.Element; | |
25 | 20 |
26 /** | 21 /** |
27 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 22 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
28 */ | 23 */ |
29 public class CalculationSelect extends DefaultState { | 24 public class CalculationSelect extends DefaultState { |
33 | 28 |
34 /** Name of data item. */ | 29 /** Name of data item. */ |
35 public static final String FIELD_MODE = "calculation_mode"; | 30 public static final String FIELD_MODE = "calculation_mode"; |
36 | 31 |
37 /** Constant value for the reference line calculation. */ | 32 /** Constant value for the reference line calculation. */ |
38 public static final String CALCULATION_SURFACE_CURVE = | 33 public static final String CALCULATION_SURFACE_CURVE = "calc.surface.curve"; |
39 "calc.surface.curve"; | |
40 | 34 |
41 /** Constant value for the differences calculation. */ | 35 /** Constant value for the differences calculation. */ |
42 public static final String CALCULATION_DURATION_CURVE = | 36 public static final String CALCULATION_DURATION_CURVE = "calc.duration.curve"; |
43 "calc.duration.curve"; | |
44 | 37 |
45 /** Constant value for the flood map calculation. */ | 38 /** Constant value for the flood map calculation. */ |
46 public static final String CALCULATION_FLOOD_MAP = | 39 public static final String CALCULATION_FLOOD_MAP = "calc.flood.map"; |
47 "calc.flood.map"; | |
48 | 40 |
49 /** Constant value for the profile calculation. */ | 41 /** Constant value for the profile calculation. */ |
50 public static final String CALCULATION_DISCHARGE_LONGITUDINAL_CURVE = | 42 public static final String CALCULATION_DISCHARGE_LONGITUDINAL_CURVE = "calc.discharge.longitudinal.section"; |
51 "calc.discharge.longitudinal.section"; | |
52 | 43 |
53 /** Constant value for the state discharge curve calculation. */ | 44 /** Constant value for the state discharge curve calculation. */ |
54 public static final String CALCULATION_DISCHARGE_CURVE = | 45 public static final String CALCULATION_DISCHARGE_CURVE = "calc.discharge.curve"; |
55 "calc.discharge.curve"; | |
56 | 46 |
57 /** Constant value for the state w differences calculation. */ | 47 /** Constant value for the state w differences calculation. */ |
58 public static final String CALCULATION_W_DIFFERENCES = | 48 public static final String CALCULATION_W_DIFFERENCES = "calc.w.differences"; |
59 "calc.w.differences"; | |
60 | 49 |
61 /** Constant value for the state reference curve calculation. */ | 50 /** Constant value for the state reference curve calculation. */ |
62 public static final String CALCULATION_REFERENCE_CURVE = | 51 public static final String CALCULATION_REFERENCE_CURVE = "calc.reference.curve"; |
63 "calc.reference.curve"; | |
64 | 52 |
65 /** Constant value for the historical discharge curve calculation. */ | 53 /** Constant value for the historical discharge curve calculation. */ |
66 public static final String CALCULATION_HISTORICAL_DISCHARGE_CURVE = | 54 public static final String CALCULATION_HISTORICAL_DISCHARGE_CURVE = "calc.historical.discharge.curve"; |
67 "calc.historical.discharge.curve"; | |
68 | |
69 /** Constant value for the extreme W curve calculation. */ | |
70 public static final String CALCULATION_EXTREME = | |
71 "calc.extreme.curve"; | |
72 | 55 |
73 /** An array that holds all available calculation modes. */ | 56 /** An array that holds all available calculation modes. */ |
74 public static final String[] CALCULATIONS = { | 57 public static final String[] CALCULATIONS = { CALCULATION_SURFACE_CURVE, CALCULATION_FLOOD_MAP, CALCULATION_DISCHARGE_CURVE, |
75 CALCULATION_SURFACE_CURVE, | 58 CALCULATION_HISTORICAL_DISCHARGE_CURVE, CALCULATION_DURATION_CURVE, CALCULATION_DISCHARGE_LONGITUDINAL_CURVE, CALCULATION_W_DIFFERENCES, |
76 CALCULATION_FLOOD_MAP, | 59 CALCULATION_REFERENCE_CURVE }; |
77 CALCULATION_DISCHARGE_CURVE, | |
78 CALCULATION_HISTORICAL_DISCHARGE_CURVE, | |
79 CALCULATION_DURATION_CURVE, | |
80 CALCULATION_DISCHARGE_LONGITUDINAL_CURVE, | |
81 CALCULATION_W_DIFFERENCES, | |
82 CALCULATION_REFERENCE_CURVE //, | |
83 // CALCULATION_EXTREME | |
84 }; | |
85 | |
86 | 60 |
87 /** Error message that is thrown if no mode has been chosen. */ | 61 /** Error message that is thrown if no mode has been chosen. */ |
88 public static final String ERROR_NO_CALCULATION_MODE = | 62 public static final String ERROR_NO_CALCULATION_MODE = "error_feed_no_calculation_mode"; |
89 "error_feed_no_calculation_mode"; | |
90 | 63 |
91 /** Error message that is thrown if an invalid calculation mode has been | 64 /** |
92 * chosen. */ | 65 * Error message that is thrown if an invalid calculation mode has been |
93 public static final String ERROR_INVALID_CALCULATION_MODE = | 66 * chosen. |
94 "error_feed_invalid_calculation_mode"; | 67 */ |
95 | 68 public static final String ERROR_INVALID_CALCULATION_MODE = "error_feed_invalid_calculation_mode"; |
96 | 69 |
97 public CalculationSelect() { | 70 public CalculationSelect() { |
98 } | 71 } |
99 | 72 |
100 | |
101 /** Create choices (i18ned). */ | 73 /** Create choices (i18ned). */ |
102 @Override | 74 @Override |
103 protected Element[] createItems( | 75 protected Element[] createItems(final XMLUtils.ElementCreator cr, final Artifact artifact, final String name, final CallContext context) { |
104 XMLUtils.ElementCreator cr, | 76 final CallMeta meta = context.getMeta(); |
105 Artifact artifact, | 77 final Element[] calcs = new Element[CALCULATIONS.length]; |
106 String name, | |
107 CallContext context) | |
108 { | |
109 CallMeta meta = context.getMeta(); | |
110 Element[] calcs = new Element[CALCULATIONS.length]; | |
111 | 78 |
112 for (int i = 0; i < CALCULATIONS.length; ++i) { | 79 for (int i = 0; i < CALCULATIONS.length; ++i) { |
113 String calc = CALCULATIONS[i]; | 80 final String calc = CALCULATIONS[i]; |
114 calcs[i] = createItem( | 81 calcs[i] = createItem(cr, new String[] { Resources.getMsg(meta, calc, calc), calc }); |
115 cr, new String[] { | |
116 Resources.getMsg(meta, calc, calc), | |
117 calc | |
118 }); | |
119 } | 82 } |
120 | 83 |
121 return calcs; | 84 return calcs; |
122 } | 85 } |
123 | 86 |
124 | |
125 /** Validate the chosen calculation. */ | 87 /** Validate the chosen calculation. */ |
126 @Override | 88 @Override |
127 public boolean validate(Artifact artifact) | 89 public boolean validate(final Artifact artifact) throws IllegalArgumentException { |
128 throws IllegalArgumentException | |
129 { | |
130 log.debug("CalculationSelect.validate"); | 90 log.debug("CalculationSelect.validate"); |
131 D4EArtifact flys = (D4EArtifact) artifact; | 91 final D4EArtifact flys = (D4EArtifact) artifact; |
132 | 92 |
133 StateData data = getData(flys, FIELD_MODE); | 93 final StateData data = getData(flys, FIELD_MODE); |
134 String calc = (data != null) ? (String) data.getValue() : null; | 94 String calc = (data != null) ? (String) data.getValue() : null; |
135 | 95 |
136 if (calc == null) { | 96 if (calc == null) { |
137 throw new IllegalArgumentException(ERROR_NO_CALCULATION_MODE); | 97 throw new IllegalArgumentException(ERROR_NO_CALCULATION_MODE); |
138 } | 98 } |
139 | 99 |
140 calc = calc.trim().toLowerCase(); | 100 calc = calc.trim().toLowerCase(); |
141 | 101 |
142 for (String mode: CALCULATIONS) { | 102 for (final String mode : CALCULATIONS) { |
143 if (mode.equals(calc)) { | 103 if (mode.equals(calc)) { |
144 return true; | 104 return true; |
145 } | 105 } |
146 } | 106 } |
147 | 107 |