Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/SedimentDensityArtifact.java @ 7199:baf04164fcc6
issue1435: Stubs for SedimentDensityFacet and -Artifact.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Mon, 30 Sep 2013 09:38:09 +0200 |
parents | |
children | 99c5e4148859 |
comparison
equal
deleted
inserted
replaced
7198:f707ee04ac80 | 7199:baf04164fcc6 |
---|---|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.artifacts; | |
10 | |
11 import java.util.ArrayList; | |
12 import java.util.List; | |
13 | |
14 import org.apache.log4j.Logger; | |
15 import org.w3c.dom.Document; | |
16 | |
17 import org.dive4elements.artifactdatabase.state.DefaultOutput; | |
18 import org.dive4elements.artifactdatabase.state.Facet; | |
19 import org.dive4elements.artifactdatabase.state.FacetActivity; | |
20 import org.dive4elements.artifactdatabase.state.State; | |
21 import org.dive4elements.artifacts.Artifact; | |
22 import org.dive4elements.artifacts.ArtifactFactory; | |
23 import org.dive4elements.artifacts.CallMeta; | |
24 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
25 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; | |
26 import org.dive4elements.river.artifacts.model.Calculation; | |
27 import org.dive4elements.river.artifacts.model.CalculationResult; | |
28 import org.dive4elements.river.artifacts.model.minfo.SedimentDensity; | |
29 import org.dive4elements.river.artifacts.model.minfo.SedimentDensityFacet; | |
30 import org.dive4elements.river.artifacts.model.minfo.SedimentDensityFactory; | |
31 import org.dive4elements.river.artifacts.states.StaticState; | |
32 | |
33 import org.dive4elements.river.artifacts.model.FacetTypes; | |
34 | |
35 import org.dive4elements.river.utils.Formatter; | |
36 | |
37 | |
38 /** Artifact to access sediment density measurements. */ | |
39 public class SedimentDensityArtifact | |
40 extends StaticD4EArtifact | |
41 implements FacetTypes | |
42 { | |
43 /** The logger for this class. */ | |
44 private static Logger logger = | |
45 Logger.getLogger(SedimentDensityArtifact.class); | |
46 | |
47 /** Artifact key name. */ | |
48 private static final String NAME = "sedimentdensity"; | |
49 | |
50 /** Spawn only inactive facets. */ | |
51 static { | |
52 // TODO: Move to configuration. | |
53 FacetActivity.Registry.getInstance() | |
54 .register(NAME, FacetActivity.INACTIVE); | |
55 } | |
56 | |
57 /** Need to give the state an id. */ | |
58 public static final String STATIC_STATE_NAME = | |
59 "state.sedimentdensity.static"; | |
60 | |
61 /** One and only state to be in. */ | |
62 protected transient State state = null; | |
63 | |
64 protected String DATA_ID = "ID"; | |
65 protected String DATA_YEAR = "YEAR"; | |
66 | |
67 /** | |
68 * Trivial Constructor. | |
69 */ | |
70 public SedimentDensityArtifact() { | |
71 logger.debug("SedimentDensityArtifact.SedimentDensityArtifact"); | |
72 } | |
73 | |
74 | |
75 /** Get artifact key name. */ | |
76 @Override | |
77 public String getName() { | |
78 return NAME; | |
79 } | |
80 | |
81 | |
82 private Object getSedimentDensity() { | |
83 logger.debug("SedimentDensityArtifact.getSedimentDensity"); | |
84 Integer id = getDataAsInteger(DATA_ID); | |
85 Integer year = getDataAsInteger(DATA_YEAR); | |
86 | |
87 // TODO use cache if possible | |
88 return SedimentDensityFactory.getSedimentDensityUncached(id, year); | |
89 } | |
90 | |
91 | |
92 private State newDensityState() { | |
93 return new StaticState(STATIC_STATE_NAME) { | |
94 public Object staticCompute(List<Facet> facets) { | |
95 return getSedimentDensity(); | |
96 } | |
97 }; | |
98 } | |
99 | |
100 | |
101 /** Create a new state with bogus output. */ | |
102 protected State spawnState() { | |
103 state = newDensityState(); | |
104 List<Facet> fs = getFacets(STATIC_STATE_NAME); | |
105 DefaultOutput output = new DefaultOutput( | |
106 "general", | |
107 "general", | |
108 "image/png", | |
109 fs, | |
110 "chart"); | |
111 | |
112 state.getOutputs().add(output); | |
113 | |
114 return state; | |
115 } | |
116 | |
117 | |
118 /** | |
119 * Gets called from factory, to set things up. | |
120 */ | |
121 @Override | |
122 public void setup( | |
123 String identifier, | |
124 ArtifactFactory factory, | |
125 Object context, | |
126 CallMeta callMeta, | |
127 Document data) | |
128 { | |
129 logger.debug("SedimentDensityArtifact.setup"); | |
130 | |
131 // Store id, yield yields. | |
132 state = newDensityState(); | |
133 if (logger.isDebugEnabled()) { | |
134 logger.debug(XMLUtils.toString(data)); | |
135 } | |
136 | |
137 List<Facet> fs = new ArrayList<Facet>(); | |
138 | |
139 String code = getDatacageIDValue(data); | |
140 | |
141 if (code != null) { | |
142 //String name = SedimentDensityFactory.getSedimentDensityDescription(Integer.valueOf(code)); | |
143 //id: and year? | |
144 | |
145 String name = "facet"; | |
146 | |
147 Facet facet = new SedimentDensityFacet( | |
148 0, | |
149 SEDIMENT_LOAD_COARSE, | |
150 name, | |
151 //???? | |
152 ComputeType.ADVANCE, state.getID(), "hash" | |
153 ); | |
154 fs.add(facet); | |
155 addFacets(state.getID(), fs); | |
156 addStringData(DATA_ID, code); | |
157 addStringData(DATA_YEAR, code); | |
158 } | |
159 | |
160 spawnState(); | |
161 super.setup(identifier, factory, context, callMeta, data); | |
162 } | |
163 | |
164 | |
165 /** | |
166 * Get a list containing the one and only State. | |
167 * @param context ignored. | |
168 * @return list with one and only state. | |
169 */ | |
170 @Override | |
171 protected List<State> getStates(Object context) { | |
172 ArrayList<State> states = new ArrayList<State>(); | |
173 states.add(getState()); | |
174 return states; | |
175 } | |
176 | |
177 | |
178 /** | |
179 * Get the "current" state (there is but one). | |
180 * @param cc ignored. | |
181 * @return the "current" (only possible) state. | |
182 */ | |
183 @Override | |
184 public State getCurrentState(Object cc) { | |
185 return getState(); | |
186 } | |
187 | |
188 | |
189 /** | |
190 * Get the only possible state. | |
191 * @return the state. | |
192 */ | |
193 protected State getState() { | |
194 return getState(null, null); | |
195 } | |
196 | |
197 | |
198 /** | |
199 * Get the state. | |
200 * @param context ignored. | |
201 * @param stateID ignored. | |
202 * @return the state. | |
203 */ | |
204 @Override | |
205 protected State getState(Object context, String stateID) { | |
206 return (state != null) | |
207 ? state | |
208 : spawnState(); | |
209 } | |
210 | |
211 | |
212 /** | |
213 * Called via setup. Overridden to avoid cloning all data. | |
214 * | |
215 * @param artifact The master-artifact. | |
216 */ | |
217 @Override | |
218 protected void initialize( | |
219 Artifact artifact, | |
220 Object context, | |
221 CallMeta meta) | |
222 { | |
223 logger.debug("SedimentDensityArtifact.initialize"); | |
224 } | |
225 } | |
226 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |