Mercurial > dive4elements > river
changeset 7227:744df5a03337
Use diagram configuration and there processors to define compatible facets in loaded data.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Wed, 02 Oct 2013 19:24:43 +0200 |
parents | 8ab618dda850 |
children | 3f141505077b |
files | artifacts/src/main/java/org/dive4elements/river/artifacts/D4EArtifact.java artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContext.java artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java artifacts/src/main/java/org/dive4elements/river/exports/GeneratorLookup.java |
diffstat | 5 files changed, 78 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/D4EArtifact.java Wed Oct 02 18:41:12 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/D4EArtifact.java Wed Oct 02 19:24:43 2013 +0200 @@ -52,6 +52,7 @@ import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; import org.dive4elements.river.artifacts.cache.CacheFactory; import org.dive4elements.river.artifacts.context.RiverContext; +import org.dive4elements.river.artifacts.context.RiverContextFactory; import org.dive4elements.river.artifacts.model.CalculationMessage; import org.dive4elements.river.artifacts.states.DefaultState; import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; @@ -119,6 +120,13 @@ private String boundToOut; + /** + * Interface to a global facet filter. + */ + public interface FacetFilter { + boolean accept(String outName, String facetName); + } // interface FacetFilter + /** * The default constructor that creates an empty D4EArtifact. @@ -1279,7 +1287,7 @@ log.debug("State '" + stateId + "' has facets " + fs); } - List<Output> gen = generateOutputs(list, fs); + List<Output> gen = generateOutputs(list, filterFacets(fs)); if (debug) { log.debug("State '" + stateId + "' has " + gen.size() + " outs"); @@ -1288,6 +1296,29 @@ return gen; } + /** If a global facet filter and a bounded out are defined + * use them to eliminate unwished facets. + */ + protected List<Facet> filterFacets(List<Facet> facets) { + if (boundToOut == null || boundToOut.isEmpty()) { + return facets; + } + + FacetFilter facetFilter = + (FacetFilter)RiverContextFactory.getGlobalContext() + .get(RiverContext.FACETFILTER_KEY); + if (facetFilter == null) { + return facets; + } + + List<Facet> result = new ArrayList<Facet>(facets.size()); + for (Facet facet: facets) { + if (facetFilter.accept(boundToOut, facet.getName())) { + result.add(facet); + } + } + return result; + } /** * Generate a list of outputs with facets from fs if type is found in list
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContext.java Wed Oct 02 18:41:12 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContext.java Wed Oct 02 19:24:43 2013 +0200 @@ -46,6 +46,9 @@ public static final String OUTGENERATORS_KEY = "flys.export.outgenerators"; + public static final String FACETFILTER_KEY = + "flys.export.facetfilter"; + /** The key that is used to store the map of themes in the context. */ public static final String THEMES = "flys.themes.map";
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java Wed Oct 02 18:41:12 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java Wed Oct 02 19:24:43 2013 +0200 @@ -389,6 +389,7 @@ logger.info("Successfully loaded " + idx + " output generators."); context.put(RiverContext.OUTGENERATORS_KEY, generators); + context.put(RiverContext.FACETFILTER_KEY, generators); }
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java Wed Oct 02 18:41:12 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java Wed Oct 02 19:24:43 2013 +0200 @@ -26,7 +26,7 @@ import org.dive4elements.artifacts.common.utils.ElementConverter; public class DiagramAttributes -implements ElementConverter +implements ElementConverter, D4EArtifact.FacetFilter { private static Logger log = Logger.getLogger(DiagramAttributes.class); @@ -528,5 +528,16 @@ ? "" // null? : axesAttrs.get(index).getName(); } + + @Override + public boolean accept(String outName, String facetName) { + Instance instance = new Instance(); + for (Processor pr: instance.getProcessors()) { + if (pr.canHandle(facetName)) { + return true; + } + } + return false; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/artifacts/src/main/java/org/dive4elements/river/exports/GeneratorLookup.java Wed Oct 02 18:41:12 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/GeneratorLookup.java Wed Oct 02 19:24:43 2013 +0200 @@ -11,10 +11,15 @@ import java.util.HashMap; import java.util.Map; +import org.apache.log4j.Logger; import org.dive4elements.river.utils.Pair; +import org.dive4elements.river.artifacts.D4EArtifact.FacetFilter; public class GeneratorLookup +implements FacetFilter { + private static Logger log = Logger.getLogger(GeneratorLookup.class); + private Map<String, Pair<Class<OutGenerator>, Object>> generators; public GeneratorLookup() { @@ -34,5 +39,30 @@ public Pair<Class<OutGenerator>, Object> getGenerator(String outName) { return generators.get(outName); } + + @Override + public boolean accept(String outName, String facetName) { + + Pair<Class<OutGenerator>, Object> pair = generators.get(outName); + if (pair == null) { + return true; + } + + try { + Class<OutGenerator> clazz = pair.getA(); + OutGenerator generator = clazz.newInstance(); + + return generator instanceof FacetFilter + ? ((FacetFilter)generator).accept(outName, facetName) + : true; + } + catch (InstantiationException ie) { + log.error(ie, ie); + } + catch (IllegalAccessException iae) { + log.error(iae, iae); + } + return true; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :