comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelInfoState.java @ 3468:f37e7e8907cb

merged flys-artifacts/2.8.1
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:39 +0200
parents 3bf86d01fa54
children
comparison
equal deleted inserted replaced
3387:5ffad8bde8ad 3468:f37e7e8907cb
1 package de.intevation.flys.artifacts.states;
2
3 import java.util.List;
4
5 import org.apache.log4j.Logger;
6
7 import de.intevation.artifacts.CallContext;
8 import de.intevation.artifacts.CallMeta;
9
10 import de.intevation.artifactdatabase.state.Facet;
11
12 import de.intevation.flys.artifacts.FLYSArtifact;
13 import de.intevation.flys.artifacts.WINFOArtifact;
14 import de.intevation.flys.artifacts.model.FacetTypes;
15 import de.intevation.flys.artifacts.model.ReportFacet;
16 import de.intevation.flys.artifacts.model.WaterlevelFacet;
17 import de.intevation.flys.artifacts.model.WQKms;
18
19 import de.intevation.flys.artifacts.model.DataFacet;
20 import de.intevation.flys.artifacts.model.CrossSectionWaterLineFacet;
21 import de.intevation.flys.artifacts.model.CalculationResult;
22
23
24 public class WaterlevelInfoState
25 extends DefaultState
26 implements FacetTypes
27 {
28 /** The logger that is used in this state. */
29 private static Logger logger = Logger.getLogger(WaterlevelInfoState.class);
30
31
32 @Override
33 protected String getUIProvider() {
34 return "noinput";
35 }
36
37
38 @Override
39 public Object computeInit(
40 FLYSArtifact artifact,
41 String hash,
42 Object context,
43 CallMeta meta,
44 List<Facet> facets
45 ) {
46 return compute((WINFOArtifact) artifact, hash, facets, null);
47 }
48
49
50 protected Object compute(
51 WINFOArtifact winfo,
52 String hash,
53 List<Facet> facets,
54 Object old
55 ) {
56 logger.debug("WaterlevelInfoState.compute");
57 String id = getID();
58
59 CalculationResult res = old instanceof CalculationResult
60 ? (CalculationResult)old
61 : winfo.getWaterlevelData();
62
63 if (facets == null) {
64 return res;
65 }
66
67 WQKms [] wqkms = (WQKms [])res.getData();
68
69 for (int i = 0; i < wqkms.length; i++) {
70 String nameW = null;
71 String nameQ = null;
72
73 if (winfo.isQ()) {
74 nameQ = wqkms[i].getName();
75 nameW = "W(" + nameQ + ")";
76 }
77 else {
78 nameW = wqkms[i].getName();
79 nameQ = "Q(" + nameQ + ")";
80 }
81
82 logger.debug("WaterlevelInfoState Create facet: " + nameW);
83 logger.debug("WaterlevelInfoState Create facet: " + nameQ);
84
85 Facet w = new WaterlevelFacet(
86 i, LONGITUDINAL_W, nameW, ComputeType.ADVANCE, id, hash);
87 Facet q = new WaterlevelFacet(
88 i, LONGITUDINAL_Q, nameQ, ComputeType.ADVANCE, id, hash);
89
90 facets.add(w);
91 facets.add(q);
92 }
93
94 if (wqkms.length > 0) {
95 Facet wst = new DataFacet(
96 WST, "WST data", ComputeType.ADVANCE, hash, id);
97 Facet csv = new DataFacet(
98 CSV, "CSV data", ComputeType.ADVANCE, hash, id);
99
100 facets.add(wst);
101 facets.add(csv);
102 }
103
104 if (res.getReport().hasProblems()) {
105 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id));
106 }
107
108 // TODO Adjust to WaterlevelState - implementation.
109 facets.add(new CrossSectionWaterLineFacet(0, "Q=" + winfo.getDataAsString("wq_single")));
110
111 // Assume to be in wq_single mode.
112 return res;
113 }
114
115
116 /**
117 * @param context Ignored.
118 */
119 @Override
120 public Object computeFeed(
121 FLYSArtifact artifact,
122 String hash,
123 CallContext context,
124 List<Facet> facets,
125 Object old
126 ) {
127 return compute((WINFOArtifact) artifact, hash, facets, old);
128 }
129
130
131 /**
132 * @param context Ignored.
133 */
134 @Override
135 public Object computeAdvance(
136 FLYSArtifact artifact,
137 String hash,
138 CallContext context,
139 List<Facet> facets,
140 Object old
141 ) {
142 return compute((WINFOArtifact) artifact, hash, facets, old);
143 }
144 }
145 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org