Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelInfoState.java @ 3818:dc18457b1cef
merged flys-artifacts/pre2.7-2012-03-16
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:59 +0200 |
parents | 51b9899f819d |
children | 3bf86d01fa54 |
comparison
equal
deleted
inserted
replaced
2456:60ab1054069d | 3818:dc18457b1cef |
---|---|
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 public Object computeInit( | |
39 FLYSArtifact artifact, | |
40 String hash, | |
41 Object context, | |
42 CallMeta meta, | |
43 List<Facet> facets | |
44 ) { | |
45 return compute((WINFOArtifact) artifact, hash, facets, null); | |
46 } | |
47 | |
48 | |
49 protected Object compute( | |
50 WINFOArtifact winfo, | |
51 String hash, | |
52 List<Facet> facets, | |
53 Object old | |
54 ) { | |
55 logger.debug("WaterlevelInfoState.compute"); | |
56 String id = getID(); | |
57 | |
58 CalculationResult res = old instanceof CalculationResult | |
59 ? (CalculationResult)old | |
60 : winfo.getWaterlevelData(); | |
61 | |
62 if (facets == null) { | |
63 return res; | |
64 } | |
65 | |
66 WQKms [] wqkms = (WQKms [])res.getData(); | |
67 | |
68 for (int i = 0; i < wqkms.length; i++) { | |
69 String nameW = null; | |
70 String nameQ = null; | |
71 | |
72 if (winfo.isQ()) { | |
73 nameQ = wqkms[i].getName(); | |
74 nameW = "W(" + nameQ + ")"; | |
75 } | |
76 else { | |
77 nameW = wqkms[i].getName(); | |
78 nameQ = "Q(" + nameQ + ")"; | |
79 } | |
80 | |
81 logger.debug("WaterlevelInfoState Create facet: " + nameW); | |
82 logger.debug("WaterlevelInfoState Create facet: " + nameQ); | |
83 | |
84 Facet w = new WaterlevelFacet( | |
85 i, LONGITUDINAL_W, nameW, ComputeType.ADVANCE, id, hash); | |
86 Facet q = new WaterlevelFacet( | |
87 i, LONGITUDINAL_Q, nameQ, ComputeType.ADVANCE, id, hash); | |
88 | |
89 facets.add(w); | |
90 facets.add(q); | |
91 } | |
92 | |
93 if (wqkms.length > 0) { | |
94 Facet wst = new DataFacet( | |
95 WST, "WST data", ComputeType.ADVANCE, hash, id); | |
96 Facet csv = new DataFacet( | |
97 CSV, "CSV data", ComputeType.ADVANCE, hash, id); | |
98 | |
99 facets.add(wst); | |
100 facets.add(csv); | |
101 } | |
102 | |
103 if (res.getReport().hasProblems()) { | |
104 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id)); | |
105 } | |
106 | |
107 // TODO Adjust to WaterlevelState - implementation. | |
108 facets.add(new CrossSectionWaterLineFacet(0, "Q=" + winfo.getDataAsString("wq_single"))); | |
109 | |
110 // Assume to be in wq_single mode. | |
111 return res; | |
112 } | |
113 | |
114 | |
115 /** | |
116 * @param context Ignored. | |
117 */ | |
118 @Override | |
119 public Object computeFeed( | |
120 FLYSArtifact artifact, | |
121 String hash, | |
122 CallContext context, | |
123 List<Facet> facets, | |
124 Object old | |
125 ) { | |
126 return compute((WINFOArtifact) artifact, hash, facets, old); | |
127 } | |
128 | |
129 | |
130 /** | |
131 * @param context Ignored. | |
132 */ | |
133 @Override | |
134 public Object computeAdvance( | |
135 FLYSArtifact artifact, | |
136 String hash, | |
137 CallContext context, | |
138 List<Facet> facets, | |
139 Object old | |
140 ) { | |
141 return compute((WINFOArtifact) artifact, hash, facets, old); | |
142 } | |
143 } | |
144 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |