annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelSelectState.java @ 1187:47ecf98f09eb

Cleanup imports. flys-artifacts/trunk@2783 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 19 Sep 2011 12:44:51 +0000
parents 1aba1a75beb2
children d251e5929860
rev   line source
1172
23eb122c8ec1 Prepared the winfo artifact for floodmap calculations (now selectable in the UI).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.states;
23eb122c8ec1 Prepared the winfo artifact for floodmap calculations (now selectable in the UI).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
1178
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
3 import org.apache.log4j.Logger;
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
4
1180
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
5 import org.w3c.dom.Element;
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
6
1178
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
7 import de.intevation.artifacts.Artifact;
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
8 import de.intevation.artifacts.CallContext;
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
9
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
10 import de.intevation.artifactdatabase.data.DefaultStateData;
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
11 import de.intevation.artifactdatabase.data.StateData;
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
12
1180
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
13 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
14
1178
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
15 import de.intevation.flys.artifacts.FLYSArtifact;
1180
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
16 import de.intevation.flys.artifacts.model.CalculationResult;
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
17 import de.intevation.flys.artifacts.model.WQKms;
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
18 import de.intevation.flys.artifacts.resources.Resources;
1178
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
19 import de.intevation.flys.utils.FLYSUtils;
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
20
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
21
1172
23eb122c8ec1 Prepared the winfo artifact for floodmap calculations (now selectable in the UI).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 /**
23eb122c8ec1 Prepared the winfo artifact for floodmap calculations (now selectable in the UI).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
23eb122c8ec1 Prepared the winfo artifact for floodmap calculations (now selectable in the UI).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 */
23eb122c8ec1 Prepared the winfo artifact for floodmap calculations (now selectable in the UI).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 public class WaterlevelSelectState extends DefaultState {
23eb122c8ec1 Prepared the winfo artifact for floodmap calculations (now selectable in the UI).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26
1178
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
27 private static final Logger logger =
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
28 Logger.getLogger(WaterlevelSelectState.class);
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
29
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
30 public static final String SPLIT_CHAR = ";";
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
31
1180
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
32 public static final String WINFO_WSP_STATE_ID = "state.winfo.waterlevel";
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
33
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
34 public static final String I18N_STATIC_KEY = "wsp.selected.string";
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
35
1178
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
36
1172
23eb122c8ec1 Prepared the winfo artifact for floodmap calculations (now selectable in the UI).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 @Override
23eb122c8ec1 Prepared the winfo artifact for floodmap calculations (now selectable in the UI).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 protected String getUIProvider() {
23eb122c8ec1 Prepared the winfo artifact for floodmap calculations (now selectable in the UI).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39 return "wsp_datacage_panel";
23eb122c8ec1 Prepared the winfo artifact for floodmap calculations (now selectable in the UI).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 }
1178
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
41
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
42
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
43 @Override
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
44 public StateData transform(
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
45 FLYSArtifact flys,
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
46 CallContext cc,
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
47 String name,
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
48 String val
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
49 ) {
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
50 if (!isValueValid(val)) {
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
51 logger.error("The given input string is not valid: '" + val + "'");
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
52 return null;
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
53 }
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
54
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
55 return new DefaultStateData(name, null, null, strip(val));
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
56 }
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
57
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
58
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
59 @Override
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
60 public boolean validate(Artifact artifact)
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
61 throws IllegalArgumentException
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
62 {
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
63 FLYSArtifact flys = (FLYSArtifact) artifact;
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
64
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
65 StateData data = flys.getData("wsp");
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
66
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
67 if (data == null) {
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
68 throw new IllegalArgumentException("WSP is empty");
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
69 }
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
70
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
71 return true;
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
72 }
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
73
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
74
1180
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
75 @Override
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
76 protected Element createStaticData(
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
77 ElementCreator creator,
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
78 CallContext cc,
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
79 String name,
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
80 String value,
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
81 String type
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
82 ) {
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
83 Element dataElement = creator.create("data");
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
84 creator.addAttr(dataElement, "name", name, true);
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
85 creator.addAttr(dataElement, "type", type, true);
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
86
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
87 Element itemElement = creator.create("item");
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
88 creator.addAttr(itemElement, "value", value, true);
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
89
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
90 String[] labels = getLabels(cc, value);
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
91 Object[] obj = new Object[] { labels[0] };
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
92
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
93 String attrValue = Resources.getMsg(
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
94 cc.getMeta(), I18N_STATIC_KEY, I18N_STATIC_KEY, obj);
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
95
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
96 creator.addAttr(itemElement, "label", attrValue, true);
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
97 dataElement.appendChild(itemElement);
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
98
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
99 return dataElement;
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
100 }
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
101
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
102
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
103 public static String[] getLabels(CallContext cc, String value) {
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
104 String[] parts = value.split(SPLIT_CHAR);
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
105
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
106 FLYSArtifact artifact = FLYSUtils.getArtifact(parts[0], cc);
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
107
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
108 CalculationResult rawData = (CalculationResult) artifact.compute(
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
109 cc,
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
110 null,
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
111 WINFO_WSP_STATE_ID,
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
112 ComputeType.ADVANCE,
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
113 false);
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
114
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
115 WQKms[] wqkms = (WQKms[]) rawData.getData();
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
116
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
117 int idx = -1;
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
118 try {
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
119 idx = Integer.parseInt(parts[2]);
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
120 }
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
121 catch (NumberFormatException nfe) { /* do nothing */ }
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
122
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
123 return new String[] { wqkms[idx].getName() };
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
124 }
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
125
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1178
diff changeset
126
1178
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
127 public static String strip(String value) {
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
128 int start = value.indexOf("[");
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
129 int end = value.indexOf("]");
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
130
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
131 if (start < 0 || end < 0) {
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
132 return value;
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
133 }
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
134
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
135 value = value.substring(start+1, end);
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
136
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
137 return value;
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
138 }
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
139
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
140
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
141 /**
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
142 * Validates the given String. A valid string for this state requires the
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
143 * format: "UUID;FACETNAME;FACETINDEX".
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
144 *
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
145 * @param value The string value requires validation.
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
146 *
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
147 * @return true, if the string applies the specified format, otherwise
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
148 * false.
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
149 */
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
150 public static boolean isValueValid(String value) {
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
151 logger.debug("Validate string: '" + value + "'");
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
152
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
153 value = strip(value);
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
154
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
155 logger.debug("Validate substring: '" + value + "'");
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
156
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
157 if (value == null || value.length() == 0) {
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
158 return false;
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
159 }
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
160
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
161 String[] parts = value.split(SPLIT_CHAR);
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
162
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
163 if (parts == null || parts.length < 3) {
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
164 return false;
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
165 }
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
166
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
167 if (parts[0] == null || parts[0].length() == 0) {
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
168 return false;
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
169 }
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
170
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
171 if (parts[1] == null || parts[1].length() == 0) {
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
172 return false;
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
173 }
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
174
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
175 try {
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
176 Integer.parseInt(parts[2]);
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
177 }
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
178 catch (NumberFormatException nfe) {
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
179 logger.error("Index is not a valid integer!", nfe);
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
180 }
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
181
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
182 return true;
1b432c260e97 Enabled the FloodMapState to fetch waterlevel data from external Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1172
diff changeset
183 }
1172
23eb122c8ec1 Prepared the winfo artifact for floodmap calculations (now selectable in the UI).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
184 }
23eb122c8ec1 Prepared the winfo artifact for floodmap calculations (now selectable in the UI).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
185 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org