Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Thu Jun 16 10:05:44 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Thu Jun 16 13:24:00 2011 +0000 @@ -1,7 +1,10 @@ package de.intevation.flys.artifacts; +import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -13,6 +16,8 @@ import de.intevation.artifacts.CallContext; import de.intevation.artifactdatabase.ProtocolUtils; +import de.intevation.artifactdatabase.state.DefaultOutput; +import de.intevation.artifactdatabase.state.Facet; import de.intevation.artifactdatabase.state.Output; import de.intevation.artifactdatabase.state.State; import de.intevation.artifactdatabase.state.StateEngine; @@ -180,7 +185,7 @@ for (String stateId: stateIds) { logger.debug("Append output modes for state: " + stateId); - State state = engine.getState(stateId); + DefaultState state = (DefaultState) engine.getState(stateId); List<Output> list = state.getOutputs(); if (list == null || list.size() == 0) { @@ -188,7 +193,17 @@ continue; } - ProtocolUtils.appendOutputModes(creator, outs, list); + List<Facet> fs = facets.get(stateId); + if (fs == null || fs.size() == 0) { + logger.debug("No facets found."); + continue; + } + + logger.debug("Found " + fs.size() + " facets."); + + List<Output> generated = generateOutputs(list, fs); + + ProtocolUtils.appendOutputModes(creator, outs, generated); } try { @@ -199,7 +214,19 @@ logger.debug( "Append output modes for state: " + cur.getID()); - ProtocolUtils.appendOutputModes(creator, outs, list); + List<Facet> fs = facets.get(cur.getID()); + if (fs != null && fs.size() > 0) { + List<Output> generated = generateOutputs(list, fs); + + logger.debug("Found " + fs.size() + " facets."); + + ProtocolUtils.appendOutputModes( + creator, outs, generated); + } + else { + logger.debug("No facets found for the current state."); + } + } } } @@ -209,6 +236,36 @@ } + protected List<Output> generateOutputs(List<Output> list, List<Facet> fs) { + List<Output> generated = new ArrayList<Output>(); + + for (Output out: list) { + Output o = new DefaultOutput( + out.getName(), + out.getDescription(), + out.getMimeType()); + + Set<String> outtype = new HashSet<String>(); + + for (Facet f: out.getFacets()) { + outtype.add(f.getName()); + } + + for (Facet f: fs) { + String type = f.getName(); + + if(outtype.contains(type)) { + o.addFacet(f); + } + } + + generated.add(o); + } + + return generated; + } + + /** * This method appends the static data - that has already been inserted by * the user - to the static node of the DESCRIBE document.