Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/states/ScenarioSelect.java @ 9277:2323d005f9a5
compile error fix
author | gernotbelger |
---|---|
date | Fri, 20 Jul 2018 10:39:02 +0200 |
parents | 0beb34d55630 |
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:
5312
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 |
9277 | 11 import java.io.File; |
12 | |
13 import org.apache.log4j.Logger; | |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5312
diff
changeset
|
14 import org.dive4elements.artifacts.Artifact; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5312
diff
changeset
|
15 import org.dive4elements.artifacts.CallContext; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5312
diff
changeset
|
16 import org.dive4elements.artifacts.CallMeta; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5312
diff
changeset
|
17 import org.dive4elements.artifacts.common.utils.FileTools; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5312
diff
changeset
|
18 import org.dive4elements.artifacts.common.utils.XMLUtils; |
5867
59ff03ff48f1
River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5865
diff
changeset
|
19 import org.dive4elements.river.artifacts.D4EArtifact; |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5312
diff
changeset
|
20 import org.dive4elements.river.artifacts.resources.Resources; |
5865
73da40528cf2
River artifacts: Renamed FLYSUtils to RiverUtils.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
21 import org.dive4elements.river.utils.RiverUtils; |
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
|
22 import org.w3c.dom.Element; |
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 |
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
|
24 /** |
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
|
25 * @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
|
26 */ |
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 public class ScenarioSelect extends DefaultState { |
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 |
9277 | 29 /** The log that is used in this class. */ |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
30 private static Logger log = Logger.getLogger(ScenarioSelect.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 |
9277 | 32 public static final String FIELD_MODE = "scenario"; |
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
|
33 |
9277 | 34 public static final String SCENARIO_CURRENT = "scenario.current"; |
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
|
35 public static final String SCENARIO_POTENTIEL = "scenario.potentiel"; |
9277 | 36 public static final String SCENARIO_SCENRAIO = "scenario.scenario"; |
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
|
37 |
9277 | 38 public static final String[] SCENARIOS = { SCENARIO_CURRENT, SCENARIO_POTENTIEL, SCENARIO_SCENRAIO }; |
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
|
39 |
1064
13784581ab0c
Moved the input of user defined barriers for the floodmap to an earlier state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1050
diff
changeset
|
40 @Override |
13784581ab0c
Moved the input of user defined barriers for the floodmap to an earlier state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1050
diff
changeset
|
41 protected String getUIProvider() { |
5312
2c1045a1e3fe
Added new states and transitions to UESK calculation and adjusted states and UI.
Raimund Renkert <rrenkert@intevation.de>
parents:
4656
diff
changeset
|
42 return ""; |
1064
13784581ab0c
Moved the input of user defined barriers for the floodmap to an earlier state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1050
diff
changeset
|
43 } |
13784581ab0c
Moved the input of user defined barriers for the floodmap to an earlier state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1050
diff
changeset
|
44 |
1159
fb5a7ff9feb8
Suppress the GeoJSON string for the FloodMap creation to be included in the static DESCRIBE part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1064
diff
changeset
|
45 @Override |
9277 | 46 protected Element[] createItems(final XMLUtils.ElementCreator cr, final Artifact artifact, final String name, final CallContext context) { |
47 final CallMeta meta = context.getMeta(); | |
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
|
48 |
1064
13784581ab0c
Moved the input of user defined barriers for the floodmap to an earlier state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1050
diff
changeset
|
49 if (name.equals(FIELD_MODE)) { |
9277 | 50 final Element[] scenarios = new Element[SCENARIOS.length]; |
1064
13784581ab0c
Moved the input of user defined barriers for the floodmap to an earlier state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1050
diff
changeset
|
51 |
13784581ab0c
Moved the input of user defined barriers for the floodmap to an earlier state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1050
diff
changeset
|
52 int i = 0; |
13784581ab0c
Moved the input of user defined barriers for the floodmap to an earlier state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1050
diff
changeset
|
53 |
9277 | 54 for (final String scenario : SCENARIOS) { |
55 scenarios[i++] = createItem(cr, new String[] { Resources.getMsg(meta, scenario, scenario), scenario }); | |
1064
13784581ab0c
Moved the input of user defined barriers for the floodmap to an earlier state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1050
diff
changeset
|
56 } |
13784581ab0c
Moved the input of user defined barriers for the floodmap to an earlier state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1050
diff
changeset
|
57 |
13784581ab0c
Moved the input of user defined barriers for the floodmap to an earlier state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1050
diff
changeset
|
58 return scenarios; |
9277 | 59 } else { |
60 final D4EArtifact flys = (D4EArtifact) artifact; | |
61 final String data = flys.getDataAsString(name); | |
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
|
62 |
9277 | 63 return new Element[] { createItem(cr, new String[] { Resources.getMsg(meta, name, name), data }) }; |
1064
13784581ab0c
Moved the input of user defined barriers for the floodmap to an earlier state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1050
diff
changeset
|
64 } |
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
|
65 } |
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 |
9277 | 67 // ist mit super identisch |
68 // @Override | |
69 // protected Element createItem(XMLUtils.ElementCreator cr, Object obj) { | |
70 // Element item = ProtocolUtils.createArtNode(cr, "item", null, null); | |
71 // Element label = ProtocolUtils.createArtNode(cr, "label", null, null); | |
72 // Element value = ProtocolUtils.createArtNode(cr, "value", null, null); | |
73 // | |
74 // String[] arr = (String[]) obj; | |
75 // | |
76 // label.setTextContent(arr[0]); | |
77 // value.setTextContent(arr[1]); | |
78 // | |
79 // item.appendChild(label); | |
80 // item.appendChild(value); | |
81 // | |
82 // return item; | |
83 // } | |
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
|
84 |
4656
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4049
diff
changeset
|
85 @Override |
9277 | 86 public void endOfLife(final Artifact artifact, final Object callContext) { |
2639
a78dafdd8590
Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1180
diff
changeset
|
87 super.endOfLife(artifact, callContext); |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
88 log.info("ScenarioSelect.endOfLife: " + artifact.identifier()); |
2639
a78dafdd8590
Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1180
diff
changeset
|
89 |
9277 | 90 final D4EArtifact flys = (D4EArtifact) artifact; |
2639
a78dafdd8590
Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1180
diff
changeset
|
91 removeDirectory(flys); |
a78dafdd8590
Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1180
diff
changeset
|
92 } |
a78dafdd8590
Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1180
diff
changeset
|
93 |
a78dafdd8590
Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1180
diff
changeset
|
94 /** |
a78dafdd8590
Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1180
diff
changeset
|
95 * Removes the directory and all its content where the required data and the |
a78dafdd8590
Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1180
diff
changeset
|
96 * results of WSPLGEN are stored. Should be called in endOfLife(). |
a78dafdd8590
Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1180
diff
changeset
|
97 */ |
4656
442fbb290fa8
Introduce river mapfile generation (WARNING: Changes in config xml files required!).
Christian Lins <christian.lins@intevation.de>
parents:
4049
diff
changeset
|
98 // FIXME: I've seen this code somewhere else... |
9277 | 99 protected void removeDirectory(final D4EArtifact artifact) { |
100 final String shapePath = RiverUtils.getXPathString(RiverUtils.XPATH_FLOODMAP_SHAPEFILE_DIR); | |
2639
a78dafdd8590
Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1180
diff
changeset
|
101 |
9277 | 102 final File artifactDir = new File(shapePath, artifact.identifier()); |
2639
a78dafdd8590
Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1180
diff
changeset
|
103 |
a78dafdd8590
Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1180
diff
changeset
|
104 if (artifactDir.exists()) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
105 log.debug("Delete directory: " + artifactDir.getAbsolutePath()); |
9277 | 106 final boolean success = FileTools.deleteRecursive(artifactDir); |
4049
8e66293c5369
Removed dead code
Sascha L. Teichmann <teichmann@intevation.de>
parents:
2646
diff
changeset
|
107 if (!success) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
108 log.warn("could not remove dir '" + artifactDir + "'"); |
4049
8e66293c5369
Removed dead code
Sascha L. Teichmann <teichmann@intevation.de>
parents:
2646
diff
changeset
|
109 } |
9277 | 110 } else { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
111 log.debug("There is no directory to remove."); |
2639
a78dafdd8590
Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1180
diff
changeset
|
112 } |
a78dafdd8590
Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1180
diff
changeset
|
113 } |
a78dafdd8590
Issue 657.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1180
diff
changeset
|
114 |
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
|
115 } |
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
|
116 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |