Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FlowVelocityState.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 | cdbc457e23e2 |
children | e8a4d2fd25cc |
comparison
equal
deleted
inserted
replaced
2987:98c7a46ec5ae | 3318:dbe2f85bf160 |
---|---|
1 package de.intevation.flys.artifacts.states; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 | |
6 import org.apache.log4j.Logger; | |
7 | |
8 import de.intevation.artifactdatabase.state.Facet; | |
9 | |
10 import de.intevation.artifacts.CallContext; | |
11 | |
12 import de.intevation.flys.artifacts.FLYSArtifact; | |
13 import de.intevation.flys.artifacts.access.FlowVelocityAccess; | |
14 import de.intevation.flys.artifacts.model.CalculationResult; | |
15 import de.intevation.flys.artifacts.model.DataFacet; | |
16 import de.intevation.flys.artifacts.model.FacetTypes; | |
17 import de.intevation.flys.artifacts.model.FlowVelocityCalculation; | |
18 import de.intevation.flys.artifacts.model.FlowVelocityData; | |
19 import de.intevation.flys.artifacts.model.FlowVelocityFacet; | |
20 import de.intevation.flys.artifacts.resources.Resources; | |
21 | |
22 | |
23 public class FlowVelocityState extends DefaultState implements FacetTypes { | |
24 | |
25 private static Logger logger = Logger.getLogger(FlowVelocityState.class); | |
26 | |
27 | |
28 public static final String I18N_MAINCHANNEL_FACET = | |
29 "facet.flow_velocity.mainchannel"; | |
30 | |
31 public static final String I18N_TOTALCHANNEL_FACET = | |
32 "facet.flow_velocity.totalchannel"; | |
33 | |
34 public static final String I18N_TAU_FACET = | |
35 "facet.flow_velocity.tauchannel"; | |
36 | |
37 | |
38 @Override | |
39 public Object computeAdvance( | |
40 FLYSArtifact artifact, | |
41 String hash, | |
42 CallContext context, | |
43 List<Facet> facets, | |
44 Object old | |
45 ) { | |
46 logger.debug("FlowVelocityState.computeAdvance"); | |
47 | |
48 List<Facet> newFacets = new ArrayList<Facet>(); | |
49 | |
50 FlowVelocityAccess access = new FlowVelocityAccess(artifact); | |
51 | |
52 CalculationResult res = old instanceof CalculationResult | |
53 ? (CalculationResult) old | |
54 : new FlowVelocityCalculation().calculate(access); | |
55 | |
56 if (facets == null || res == null) { | |
57 return res; | |
58 } | |
59 | |
60 FlowVelocityData[] data = (FlowVelocityData[]) res.getData(); | |
61 | |
62 logger.debug("Calculated " + data.length + " FlowVelocityData objects"); | |
63 | |
64 String id = getID(); | |
65 int idx = 0; | |
66 | |
67 for (FlowVelocityData d: data) { | |
68 logger.error("TODO: Implement Facet creation for chart!"); | |
69 | |
70 newFacets.add(new FlowVelocityFacet( | |
71 idx, | |
72 FLOW_VELOCITY_MAINCHANNEL, | |
73 buildMainChannelName(artifact, context, d), | |
74 ComputeType.ADVANCE, | |
75 id, | |
76 hash | |
77 )); | |
78 | |
79 newFacets.add(new FlowVelocityFacet( | |
80 idx, | |
81 FLOW_VELOCITY_TOTALCHANNEL, | |
82 buildTotalChannelName(artifact, context, d), | |
83 ComputeType.ADVANCE, | |
84 id, | |
85 hash | |
86 )); | |
87 | |
88 newFacets.add(new FlowVelocityFacet( | |
89 idx, | |
90 FLOW_VELOCITY_TAU, | |
91 buildTauName(artifact, context, d), | |
92 ComputeType.ADVANCE, | |
93 id, | |
94 hash | |
95 )); | |
96 | |
97 idx++; | |
98 } | |
99 | |
100 Facet csv = new DataFacet( | |
101 CSV, "CSV data", ComputeType.ADVANCE, hash, id); | |
102 | |
103 // TODO ADD PDF FACET | |
104 | |
105 newFacets.add(csv); | |
106 | |
107 logger.debug("Created " + newFacets.size() + " new Facets."); | |
108 | |
109 facets.addAll(newFacets); | |
110 | |
111 return res; | |
112 } | |
113 | |
114 | |
115 protected String buildFacetName( | |
116 FLYSArtifact flys, | |
117 CallContext cc, | |
118 FlowVelocityData data, | |
119 String resourceId | |
120 ) { | |
121 Object[] args = new Object[] { | |
122 data.getZone() | |
123 }; | |
124 | |
125 return Resources.getMsg( | |
126 cc.getMeta(), | |
127 resourceId, | |
128 resourceId, | |
129 args); | |
130 } | |
131 | |
132 | |
133 protected String buildMainChannelName( | |
134 FLYSArtifact flys, | |
135 CallContext cc, | |
136 FlowVelocityData data | |
137 ) { | |
138 return buildFacetName(flys, cc, data, I18N_MAINCHANNEL_FACET); | |
139 } | |
140 | |
141 | |
142 protected String buildTotalChannelName( | |
143 FLYSArtifact flys, | |
144 CallContext cc, | |
145 FlowVelocityData data | |
146 ) { | |
147 return buildFacetName(flys, cc, data, I18N_TOTALCHANNEL_FACET); | |
148 } | |
149 | |
150 | |
151 protected String buildTauName( | |
152 FLYSArtifact flys, | |
153 CallContext cc, | |
154 FlowVelocityData data | |
155 ) { | |
156 return buildFacetName(flys, cc, data, I18N_TAU_FACET); | |
157 } | |
158 } | |
159 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |