Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/GaugeDischargeState.java @ 3318:dbe2f85bf160
merged flys-artifacts/2.8
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:35 +0200 |
parents | 94d78e0dc5e9 |
children |
comparison
equal
deleted
inserted
replaced
2987:98c7a46ec5ae | 3318:dbe2f85bf160 |
---|---|
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.CallMeta; | |
8 import de.intevation.artifacts.CallContext; | |
9 | |
10 import de.intevation.artifactdatabase.state.Facet; | |
11 | |
12 import de.intevation.flys.artifacts.ChartArtifact; | |
13 import de.intevation.flys.artifacts.GaugeDischargeArtifact; | |
14 import de.intevation.flys.artifacts.FLYSArtifact; | |
15 | |
16 import de.intevation.flys.artifacts.model.GaugeDischargeFacet; | |
17 import de.intevation.flys.artifacts.model.FacetTypes; | |
18 import de.intevation.flys.artifacts.model.WQKms; | |
19 import de.intevation.flys.artifacts.model.ReportFacet; | |
20 import de.intevation.flys.artifacts.model.EmptyFacet; | |
21 import de.intevation.flys.artifacts.model.CalculationResult; | |
22 | |
23 import de.intevation.flys.artifacts.resources.Resources; | |
24 | |
25 import de.intevation.flys.model.Gauge; | |
26 | |
27 | |
28 /** | |
29 * The only state for an GaugeDischargeState (River and km known). | |
30 */ | |
31 public class GaugeDischargeState | |
32 extends DefaultState | |
33 implements FacetTypes | |
34 { | |
35 /** Developer-centric description of facet. */ | |
36 public static final String I18N_DESCRIPTION = "facet.discharge.curve"; | |
37 | |
38 /** The logger that is used in this state. */ | |
39 private static final Logger logger = | |
40 Logger.getLogger(GaugeDischargeState.class); | |
41 | |
42 | |
43 /** | |
44 * Create i18ned name for gaugedischargeFacet. | |
45 * @param artifact The artifact which has information about the gauge. | |
46 * @param meta used for i18n. | |
47 * @return localized name for gaugedischargefacet. | |
48 */ | |
49 protected String createFacetName(GaugeDischargeArtifact artifact, | |
50 CallMeta meta) { | |
51 | |
52 Gauge gauge = artifact.getGauge(); | |
53 Object[] args = new Object[] { | |
54 gauge.getName(), | |
55 gauge.getStation() | |
56 }; | |
57 | |
58 String name = Resources.getMsg( | |
59 meta, | |
60 "chart.computed.discharge.curve.gauge", | |
61 "", | |
62 args); | |
63 | |
64 return name; | |
65 } | |
66 | |
67 | |
68 /** | |
69 * Add an GaugeDischargeFacet to list of Facets. | |
70 * | |
71 * @param artifact Ignored. | |
72 * @param hash Ignored. | |
73 * @param context Ignored. | |
74 * @param meta CallMeta to be used for internationalization. | |
75 * @param facets List to add AnnotationFacet to. | |
76 * | |
77 * @return null. | |
78 */ | |
79 @Override | |
80 public Object computeInit( | |
81 FLYSArtifact artifact, | |
82 String hash, | |
83 Object context, | |
84 CallMeta meta, | |
85 List<Facet> facets | |
86 ) { | |
87 logger.debug("GaugeDischargeState.computeInit()"); | |
88 | |
89 GaugeDischargeFacet facet = new GaugeDischargeFacet( | |
90 0, | |
91 DISCHARGE_CURVE, | |
92 createFacetName((GaugeDischargeArtifact) artifact, meta)); | |
93 | |
94 facets.add(facet); | |
95 | |
96 return null; | |
97 } | |
98 | |
99 | |
100 /** | |
101 * 'Calculate' Discharge at Gauge. | |
102 */ | |
103 @Override | |
104 public Object computeAdvance( | |
105 FLYSArtifact artifact, | |
106 String hash, | |
107 CallContext context, | |
108 List<Facet> facets, | |
109 Object old | |
110 ) { | |
111 if (artifact instanceof GaugeDischargeArtifact) { | |
112 logger.debug("GaugeDischargeState.computeAdvance()"); | |
113 GaugeDischargeArtifact dischargeArtifact = (GaugeDischargeArtifact) artifact; | |
114 | |
115 CalculationResult res; | |
116 | |
117 | |
118 if (old instanceof CalculationResult) { | |
119 res = (CalculationResult) old; | |
120 } | |
121 else { | |
122 res = dischargeArtifact.getDischargeCurveData(); | |
123 } | |
124 | |
125 WQKms[] wqkms = (WQKms[]) res.getData(); | |
126 | |
127 if (wqkms != null && facets != null) { | |
128 logger.debug("GaugeDischargeState.computeAdvance(): create facets"); | |
129 | |
130 GaugeDischargeFacet facet = new GaugeDischargeFacet( | |
131 0, | |
132 DISCHARGE_CURVE, | |
133 createFacetName(dischargeArtifact, context.getMeta())); | |
134 | |
135 facets.add(facet); | |
136 | |
137 //facets.add(new DataFacet(CSV, "CSV data")); | |
138 //facets.add(new DataFacet(PDF, "PDF data")); | |
139 | |
140 if (res.getReport().hasProblems()) { | |
141 facets.add(new ReportFacet()); | |
142 } | |
143 } | |
144 else { | |
145 if (wqkms == null) | |
146 logger.debug("GaugeDischargeState.computeAdvance(): wqkms 0"); | |
147 else | |
148 logger.debug("GaugeDischargeState.computeAdvance(): facets 0"); | |
149 } | |
150 | |
151 return res; | |
152 } | |
153 else if (artifact instanceof ChartArtifact) { | |
154 ChartArtifact chart = (ChartArtifact)artifact; | |
155 facets.add(new EmptyFacet()); | |
156 return null; | |
157 } | |
158 return null; | |
159 } | |
160 } | |
161 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |