comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 693:af393c5eb2c8 facets-slt

Write computed facets into artifacts describe document. flys-artifacts/branches/facets-slt@2133 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 16 Jun 2011 13:24:00 +0000
parents f8ac04b2dbd0
children 708b270dfd30
comparison
equal deleted inserted replaced
692:22e4bffbe240 693:af393c5eb2c8
1 package de.intevation.flys.artifacts; 1 package de.intevation.flys.artifacts;
2 2
3 import java.util.ArrayList;
4 import java.util.HashSet;
3 import java.util.List; 5 import java.util.List;
4 import java.util.Map; 6 import java.util.Map;
7 import java.util.Set;
5 8
6 import org.w3c.dom.Document; 9 import org.w3c.dom.Document;
7 import org.w3c.dom.Element; 10 import org.w3c.dom.Element;
8 import org.w3c.dom.Node; 11 import org.w3c.dom.Node;
9 12
11 14
12 import de.intevation.artifacts.ArtifactNamespaceContext; 15 import de.intevation.artifacts.ArtifactNamespaceContext;
13 import de.intevation.artifacts.CallContext; 16 import de.intevation.artifacts.CallContext;
14 17
15 import de.intevation.artifactdatabase.ProtocolUtils; 18 import de.intevation.artifactdatabase.ProtocolUtils;
19 import de.intevation.artifactdatabase.state.DefaultOutput;
20 import de.intevation.artifactdatabase.state.Facet;
16 import de.intevation.artifactdatabase.state.Output; 21 import de.intevation.artifactdatabase.state.Output;
17 import de.intevation.artifactdatabase.state.State; 22 import de.intevation.artifactdatabase.state.State;
18 import de.intevation.artifactdatabase.state.StateEngine; 23 import de.intevation.artifactdatabase.state.StateEngine;
19 import de.intevation.artifactdatabase.transition.TransitionEngine; 24 import de.intevation.artifactdatabase.transition.TransitionEngine;
20 25
178 StateEngine engine = (StateEngine) flysContext.get( 183 StateEngine engine = (StateEngine) flysContext.get(
179 FLYSContext.STATE_ENGINE_KEY); 184 FLYSContext.STATE_ENGINE_KEY);
180 185
181 for (String stateId: stateIds) { 186 for (String stateId: stateIds) {
182 logger.debug("Append output modes for state: " + stateId); 187 logger.debug("Append output modes for state: " + stateId);
183 State state = engine.getState(stateId); 188 DefaultState state = (DefaultState) engine.getState(stateId);
184 189
185 List<Output> list = state.getOutputs(); 190 List<Output> list = state.getOutputs();
186 if (list == null || list.size() == 0) { 191 if (list == null || list.size() == 0) {
187 logger.debug("-> No output modes for this state."); 192 logger.debug("-> No output modes for this state.");
188 continue; 193 continue;
189 } 194 }
190 195
191 ProtocolUtils.appendOutputModes(creator, outs, list); 196 List<Facet> fs = facets.get(stateId);
197 if (fs == null || fs.size() == 0) {
198 logger.debug("No facets found.");
199 continue;
200 }
201
202 logger.debug("Found " + fs.size() + " facets.");
203
204 List<Output> generated = generateOutputs(list, fs);
205
206 ProtocolUtils.appendOutputModes(creator, outs, generated);
192 } 207 }
193 208
194 try { 209 try {
195 DefaultState cur = (DefaultState) getCurrentState(context); 210 DefaultState cur = (DefaultState) getCurrentState(context);
196 if (cur.validate(this, context)) { 211 if (cur.validate(this, context)) {
197 List<Output> list = cur.getOutputs(); 212 List<Output> list = cur.getOutputs();
198 if (list != null && list.size() > 0) { 213 if (list != null && list.size() > 0) {
199 logger.debug( 214 logger.debug(
200 "Append output modes for state: " + cur.getID()); 215 "Append output modes for state: " + cur.getID());
201 216
202 ProtocolUtils.appendOutputModes(creator, outs, list); 217 List<Facet> fs = facets.get(cur.getID());
218 if (fs != null && fs.size() > 0) {
219 List<Output> generated = generateOutputs(list, fs);
220
221 logger.debug("Found " + fs.size() + " facets.");
222
223 ProtocolUtils.appendOutputModes(
224 creator, outs, generated);
225 }
226 else {
227 logger.debug("No facets found for the current state.");
228 }
229
203 } 230 }
204 } 231 }
205 } 232 }
206 catch (IllegalArgumentException iae) { 233 catch (IllegalArgumentException iae) {
207 // state is not valid, so we do not append its outputs. 234 // state is not valid, so we do not append its outputs.
208 } 235 }
236 }
237
238
239 protected List<Output> generateOutputs(List<Output> list, List<Facet> fs) {
240 List<Output> generated = new ArrayList<Output>();
241
242 for (Output out: list) {
243 Output o = new DefaultOutput(
244 out.getName(),
245 out.getDescription(),
246 out.getMimeType());
247
248 Set<String> outtype = new HashSet<String>();
249
250 for (Facet f: out.getFacets()) {
251 outtype.add(f.getName());
252 }
253
254 for (Facet f: fs) {
255 String type = f.getName();
256
257 if(outtype.contains(type)) {
258 o.addFacet(f);
259 }
260 }
261
262 generated.add(o);
263 }
264
265 return generated;
209 } 266 }
210 267
211 268
212 /** 269 /**
213 * This method appends the static data - that has already been inserted by 270 * This method appends the static data - that has already been inserted by

http://dive4elements.wald.intevation.org