# HG changeset patch # User Felix Wolfsteller # Date 1319796262 0 # Node ID 661dfad9910a4abdf63f889f4ebcadd79f41a771 # Parent 0fe3c4849baa3da531f9ee97f1414a79e0798e0b Use compatibility matrix when creating collections output. flys-artifacts/trunk@3107 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 0fe3c4849baa -r 661dfad9910a flys-artifacts/ChangeLog --- 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 + + 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 * src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java diff -r 0fe3c4849baa -r 661dfad9910a flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.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 newAttr; + /** List of already seen facets. */ + protected List oldFacets; + + /** List of "new" facets. */ + protected List 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> compatibilities; + private static Logger logger = Logger.getLogger(AttributeWriter.class); @@ -51,11 +64,17 @@ public AttributeWriter( ArtifactDatabase db, Map oldAttr, - Map newAttr) + List oldFacets, + Map newAttr, + List newFacets, + Map> 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 newOutFacets, + List oldOutFacets) { Element output = cr.create("output"); - cr.addAttr(output, "name", a.getName()); + cr.addAttr(output, "name", outputName); outs.appendChild(output); - List facetsA = a.getFacets(); - List facetsB = null; - - if (b != null) { - facetsB = b.getFacets(); - } - - + List 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 newFacets, - List oldFacets) + List oldFacets, + List compatibleFacets) throws ArtifactDatabaseException { int num = newFacets.size(); @@ -151,10 +168,17 @@ // new) as they are. List currentFacets = new ArrayList(); List genuinelyNewFacets = new ArrayList(); + 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); } diff -r 0fe3c4849baa -r 661dfad9910a flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java --- 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(); }