Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/states/WaterlevelState.java @ 5831:bd047b71ab37
Repaired internal references
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:06:39 +0200 |
parents | flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java@1b4aaa7dbd07 |
children |
comparison
equal
deleted
inserted
replaced
5830:160f53ee0870 | 5831:bd047b71ab37 |
---|---|
1 package org.dive4elements.river.artifacts.states; | |
2 | |
3 import java.util.List; | |
4 | |
5 import org.apache.log4j.Logger; | |
6 | |
7 import org.dive4elements.artifactdatabase.state.Facet; | |
8 import org.dive4elements.artifacts.CallContext; | |
9 import org.dive4elements.river.artifacts.ChartArtifact; | |
10 import org.dive4elements.river.artifacts.FLYSArtifact; | |
11 import org.dive4elements.river.artifacts.WINFOArtifact; | |
12 import org.dive4elements.river.artifacts.model.CalculationResult; | |
13 import org.dive4elements.river.artifacts.model.CrossSectionWaterLineFacet; | |
14 import org.dive4elements.river.artifacts.model.DataFacet; | |
15 import org.dive4elements.river.artifacts.model.EmptyFacet; | |
16 import org.dive4elements.river.artifacts.model.FacetTypes; | |
17 import org.dive4elements.river.artifacts.model.ReportFacet; | |
18 import org.dive4elements.river.artifacts.model.WQKms; | |
19 import org.dive4elements.river.artifacts.model.WaterlevelFacet; | |
20 import org.dive4elements.river.utils.FLYSUtils; | |
21 | |
22 /** State in which a waterlevel has been calculated. */ | |
23 public class WaterlevelState | |
24 extends DefaultState | |
25 implements FacetTypes | |
26 { | |
27 /** The logger that is used in this state. */ | |
28 private static Logger logger = Logger.getLogger(WaterlevelState.class); | |
29 | |
30 | |
31 /** | |
32 * From this state can only be continued trivially. | |
33 */ | |
34 @Override | |
35 protected String getUIProvider() { | |
36 return "continue"; | |
37 } | |
38 | |
39 | |
40 /** | |
41 * Compute result or returned object from cache, create facets. | |
42 * @param old Object that was cached. | |
43 */ | |
44 protected Object compute( | |
45 WINFOArtifact winfo, | |
46 CallContext cc, | |
47 String hash, | |
48 List<Facet> facets, | |
49 Object old | |
50 ) { | |
51 String id = getID(); | |
52 | |
53 CalculationResult res = old instanceof CalculationResult | |
54 ? (CalculationResult) old | |
55 : winfo.getWaterlevelData(); | |
56 | |
57 if (facets == null) { | |
58 return res; | |
59 } | |
60 | |
61 boolean debug = logger.isDebugEnabled(); | |
62 | |
63 WQKms [] wqkms = (WQKms []) res.getData(); | |
64 | |
65 for (int i = 0; i < wqkms.length; i++) { | |
66 String name = wqkms[i].getName(); | |
67 | |
68 String nameW = FLYSUtils.createWspWTitle(winfo, cc, name); | |
69 String nameQ = FLYSUtils.createWspQTitle(winfo, cc, name); | |
70 | |
71 // Hotfix for theme names. Themes with the same name cause problems | |
72 // aggregating chart legend items. | |
73 if (i > 0 && name.equals(wqkms[i - 1].getName())) { | |
74 nameW += "; Q=" + wqkms[i].get(0, new double[3])[1]; | |
75 nameQ += " = " + wqkms[i].get(0, new double[3])[1]; | |
76 } | |
77 | |
78 if (debug) { | |
79 logger.debug("Create facet: " + nameW); | |
80 logger.debug("Create facet: " + nameQ); | |
81 } | |
82 | |
83 Facet w = new WaterlevelFacet( | |
84 i, LONGITUDINAL_W, nameW, ComputeType.ADVANCE, id, hash); | |
85 Facet q = new WaterlevelFacet( | |
86 i, LONGITUDINAL_Q, nameQ, ComputeType.ADVANCE, id, hash); | |
87 | |
88 facets.add(new CrossSectionWaterLineFacet(i, nameW)); | |
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 Facet pdf = new DataFacet( | |
100 PDF, "PDF data", ComputeType.ADVANCE, hash, id); | |
101 | |
102 facets.add(wst); | |
103 facets.add(csv); | |
104 facets.add(pdf); | |
105 } | |
106 | |
107 if (res.getReport().hasProblems()) { | |
108 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id)); | |
109 } | |
110 | |
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 if (artifact instanceof ChartArtifact) { | |
127 facets.add(new EmptyFacet()); | |
128 return null; | |
129 } | |
130 return compute((WINFOArtifact) artifact, context, hash, facets, old); | |
131 } | |
132 | |
133 | |
134 /** | |
135 * @param context Ignored. | |
136 */ | |
137 @Override | |
138 public Object computeAdvance( | |
139 FLYSArtifact artifact, | |
140 String hash, | |
141 CallContext context, | |
142 List<Facet> facets, | |
143 Object old | |
144 ) { | |
145 if (artifact instanceof ChartArtifact) { | |
146 facets.add(new EmptyFacet()); | |
147 return null; | |
148 } | |
149 return compute((WINFOArtifact) artifact, context, hash, facets, old); | |
150 } | |
151 } | |
152 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |