changeset 1785:661dfad9910a

Use compatibility matrix when creating collections output. flys-artifacts/trunk@3107 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 28 Oct 2011 10:04:22 +0000
parents 0fe3c4849baa
children 115803f2ba1c
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java
diffstat 3 files changed, 74 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Oct 28 09:59:47 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Oct 28 10:04:22 2011 +0000
@@ -1,3 +1,14 @@
+2011-10-28	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	Use artifacts configuration (e.g. winfo.xml) to define which facets
+	can be used in which output. Hide no-matches.
+
+	* src/main/java/de/intevation/flys/collections/AttributeWriter.java,
+	  src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java:
+	  Added use of "compatibility matrix". Only include facets in in
+	  collections description document that are marked compatible in the
+	  masterartifacts configuration (e.g. winfo.xml).
+
 2011-10-28	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java	Fri Oct 28 09:59:47 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java	Fri Oct 28 10:04:22 2011 +0000
@@ -37,6 +37,19 @@
 
     protected Map<String, Output> newAttr;
 
+    /** List of already seen facets. */
+    protected List<Facet>         oldFacets;
+
+    /** List of "new" facets. */
+    protected List<Facet>         newFacets;
+
+    /**
+     * "Compatibility matrix", mapws list of facet names to output names.
+     * Any facet that is not found in the list for a specific output will
+     * not be added to the resulting document.
+     */
+    protected Map<String, List<String>> compatibilities;
+
     private static Logger logger = Logger.getLogger(AttributeWriter.class);
 
 
@@ -51,11 +64,17 @@
     public AttributeWriter(
         ArtifactDatabase    db,
         Map<String, Output> oldAttr,
-        Map<String, Output> newAttr)
+        List<Facet>         oldFacets,
+        Map<String, Output> newAttr,
+        List<Facet>         newFacets,
+        Map<String, List<String>> matrix)
     {
-        this.db      = db;
-        this.oldAttr = oldAttr;
-        this.newAttr = newAttr;
+        this.db        = db;
+        this.oldAttr   = oldAttr;
+        this.newAttr   = newAttr;
+        this.oldFacets = oldFacets;
+        this.newFacets = newFacets;
+        this.compatibilities = matrix;
     }
 
 
@@ -85,11 +104,10 @@
         doc.appendChild(attribute);
 
         for (String outName: newAttr.keySet()) {
-
             Output a = newAttr.get(outName);
             Output b = oldAttr.get(outName);
 
-            writeOutput(doc, outs, cr, a, b);
+            writeOutput(doc, outs, cr, a.getName(), newFacets, oldFacets);
         }
 
         return doc;
@@ -99,31 +117,27 @@
     /**
      * @param doc  Document to add output nodes to
      * @param outs Node in Document to add output nodes to
-     * @param a    the new output
-     * @param b    the old output
+     * @param cr   ElementCreator in use to modify doc/outs
+     * @param outputName the "new" outputs name
+     * @param newOutFacets Facets of the new outputs
+     * @param oldOutFacets Facets of the old outputs (can be null)
      */
     protected void writeOutput(
         Document       doc,
         Node           outs,
         ElementCreator cr,
-        Output         a, /* new output */
-        Output         b) /* old output */
+        String         outputName,
+        List<Facet>    newOutFacets,
+        List<Facet>    oldOutFacets)
     {
         Element output = cr.create("output");
-        cr.addAttr(output, "name", a.getName());
+        cr.addAttr(output, "name", outputName);
 
         outs.appendChild(output);
 
-        List<Facet> facetsA = a.getFacets();
-        List<Facet> facetsB = null;
-
-        if (b != null) {
-            facetsB = b.getFacets();
-        }
-
-
+        List<String> compatibleFacets = this.compatibilities.get(outputName);
         try {
-            writeFacets(doc, cr, output, facetsA, facetsB);
+            writeFacets(doc, cr, output, newOutFacets, oldOutFacets, compatibleFacets);
         }
         catch (ArtifactDatabaseException ade) {
             logger.error(ade, ade);
@@ -133,16 +147,19 @@
 
     /**
      * @param doc    Document to add facet nodes to
+     * @param cr     ElementCreator to use with output/doc
      * @param output Node in Document to add facet nodes to
-     * @param a      the new facets
-     * @param b      the old facets
+     * @param newFacets the new facets
+     * @param oldFacets the old facets
+     * @param compatibleFacets List of facets to accept
      */
     protected void writeFacets(
         Document       doc,
         ElementCreator cr,
         Element        output,
         List<Facet>    newFacets,
-        List<Facet>    oldFacets)
+        List<Facet>    oldFacets,
+        List<String>   compatibleFacets)
     throws ArtifactDatabaseException
     {
         int num = newFacets.size();
@@ -151,10 +168,17 @@
         // new) as they are.
         List<ManagedFacet> currentFacets      = new ArrayList<ManagedFacet>();
         List<ManagedFacet> genuinelyNewFacets = new ArrayList<ManagedFacet>();
+
         for (int i = 0; i < num; i++) {
             ManagedFacet facet = (ManagedFacet) newFacets.get(i);
+            if (!compatibleFacets.contains(facet.getName())) {
+                //logger.debug("Have incompatible facet, skip: " + facet.getName());
+                continue;
+            }
+            //else logger.debug("Have compatible facet: " + facet.getName());
 
             ManagedFacet picked = pickFacet(facet, oldFacets);
+
             if (facet.equals(picked)) {
                 genuinelyNewFacets.add(picked);
             }
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Fri Oct 28 09:59:47 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Fri Oct 28 10:04:22 2011 +0000
@@ -30,6 +30,7 @@
 import de.intevation.artifactdatabase.Backend;
 import de.intevation.artifactdatabase.Backend.PersistentArtifact;
 import de.intevation.artifactdatabase.DefaultArtifactCollection;
+import de.intevation.artifactdatabase.state.StateEngine;
 
 import de.intevation.flys.artifacts.context.FLYSContext;
 import de.intevation.flys.artifacts.FLYSArtifact;
@@ -350,14 +351,20 @@
     {
         Document doc = XMLUtils.newDocument();
 
+        FLYSContext flysContext = FLYSUtils.getFlysContext(context);
+        StateEngine engine = (StateEngine) flysContext.get(
+        FLYSContext.STATE_ENGINE_KEY);
+
+        FLYSArtifact masterArtifact = getMasterArtifact(context);
+    
         XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
             doc,
             ArtifactNamespaceContext.NAMESPACE_URI,
             ArtifactNamespaceContext.NAMESPACE_PREFIX);
-
+    
         AttributeParser aParser = new AttributeParser();
         OutputParser    oParser = new OutputParser(db, context);
-
+    
         if (uuids != null) {
             for (String uuid: uuids) {
                 try {
@@ -368,13 +375,17 @@
                 }
             }
         }
-
+    
         aParser.parse(oldAttr);
-
+    
         return new AttributeWriter(
             db,
             aParser.getOuts(),
-            oParser.getOuts()).write();
+            aParser.getFacets(),
+            oParser.getOuts(),
+            oParser.getFacets(),
+            engine.getCompatibleFacets(masterArtifact.getStateHistoryIds())
+            ).write();
     }
 
 

http://dive4elements.wald.intevation.org