comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelInfoState.java @ 3814:8083f6384023

merged flys-artifacts/pre2.6-2012-01-04
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:56 +0200
parents 00f14b837e65
children b9f7ec9bda18
comparison
equal deleted inserted replaced
1491:2a00f4849738 3814:8083f6384023
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.CrossSectionFacet;
21 import de.intevation.flys.artifacts.model.CrossSectionWaterLineFacet;
22 import de.intevation.flys.artifacts.model.CalculationResult;
23
24
25 public class WaterlevelInfoState
26 extends DefaultState
27 implements FacetTypes
28 {
29 /** The logger that is used in this state. */
30 private static Logger logger = Logger.getLogger(WaterlevelInfoState.class);
31
32
33 @Override
34 protected String getUIProvider() {
35 return "noinput";
36 }
37
38
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 // Also register the CrossSectionFacets (added to respective out).
109 int idx = 0;
110 for (String name: winfo.getCrossSectionNames()) {
111 facets.add(new CrossSectionFacet(idx++, name));
112 }
113
114 // TODO Adjust to WaterlevelState - implementation.
115 facets.add(new CrossSectionWaterLineFacet(0, "Q=" + winfo.getDataAsString("wq_single")));
116
117 // Assume to be in wq_single mode.
118 return res;
119 }
120
121
122 /**
123 * @param context Ignored.
124 */
125 @Override
126 public Object computeFeed(
127 FLYSArtifact artifact,
128 String hash,
129 CallContext context,
130 List<Facet> facets,
131 Object old
132 ) {
133 return compute((WINFOArtifact) artifact, hash, facets, old);
134 }
135
136
137 /**
138 * @param context Ignored.
139 */
140 @Override
141 public Object computeAdvance(
142 FLYSArtifact artifact,
143 String hash,
144 CallContext context,
145 List<Facet> facets,
146 Object old
147 ) {
148 return compute((WINFOArtifact) artifact, hash, facets, old);
149 }
150 }
151 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org