changeset 1993:85132c9edd64

Make reuse of the old CollectionAttribute during the describe() operation of FLYSArtifactCollection - remove the old facets only. flys-artifacts/trunk@3430 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 16 Dec 2011 09:19:11 +0000
parents e1c9f28e2675
children 3e703d134bbe
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java flys-artifacts/src/main/java/de/intevation/flys/collections/CollectionAttribute.java flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java
diffstat 4 files changed, 61 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Dec 16 07:28:17 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Dec 16 09:19:11 2011 +0000
@@ -1,3 +1,17 @@
+2011-12-16  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/collections/CollectionAttribute.java:
+	  Added a method to set a new Settings object for a specific Output and a
+	  method to clear the list of Facets of a specific Output.
+
+	* src/main/java/de/intevation/flys/collections/AttributeWriter.java: The
+	  AttributeWriter no longer creates new CollectionAttributes - it only
+	  modifies the old CollectionAttribute. At first, it clears the Facets of
+	  all Outputs. Finally, the merged Facets are added to the Outputs.
+
+	* src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java:
+	  Added the CollectionAttribute to the AttributeWriters constructor.
+
 2011-12-16  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/DoubleAttribute.java: New. An
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java	Fri Dec 16 07:28:17 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java	Fri Dec 16 09:19:11 2011 +0000
@@ -61,6 +61,7 @@
      */
     public AttributeWriter(
         ArtifactDatabase    db,
+        CollectionAttribute attribute,
         Map<String, Output> oldAttr,
         List<Facet>         oldFacets,
         Map<String, Output> newAttr,
@@ -68,6 +69,7 @@
         Map<String, List<String>> matrix)
     {
         this.db        = db;
+        this.attribute = attribute;
         this.oldAttr   = oldAttr;
         this.newAttr   = newAttr;
         this.oldFacets = oldFacets;
@@ -88,12 +90,9 @@
      * @return document with merged outputs as described.
      */
     protected CollectionAttribute write() {
-        attribute = new CollectionAttribute();
-
         for (String outName: newAttr.keySet()) {
             Output a = newAttr.get(outName);
-
-            attribute.addOutput(a.getName(), a);
+            attribute.clearFacets(outName);
 
             writeOutput(a.getName(), newFacets, oldFacets);
         }
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/CollectionAttribute.java	Fri Dec 16 07:28:17 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/CollectionAttribute.java	Fri Dec 16 09:19:11 2011 +0000
@@ -58,6 +58,28 @@
     }
 
 
+    public void setSettings(String outputKey, Settings settings) {
+        if (settings == null) {
+            logger.warn("Tried to set empty Settings for '" + outputKey + "'");
+            return;
+        }
+
+        if (outputMap == null) {
+            logger.warn("Tried to add facet but no Outputs are existing yet.");
+            return;
+        }
+
+        Output output = outputMap.get(outputKey);
+
+        if (output == null) {
+            logger.warn("Tried to add facet for unknown Output: " + outputKey);
+            return;
+        }
+
+        output.setSettings(settings);
+    }
+
+
     public void addFacet(String outputKey, Facet facet) {
         if (facet == null) {
             logger.warn("Tried to add empty facet.");
@@ -87,6 +109,27 @@
     }
 
 
+    public void clearFacets(String outputKey) {
+        if (outputKey == null || outputKey.length() == 0) {
+            logger.warn("Tried to clear Facets, but no Output key specified!");
+            return;
+        }
+
+        if (outputMap == null) {
+            logger.warn("Tried to clear Facets, but no Outputs existing!");
+            return;
+        }
+
+        Output output = outputMap.get(outputKey);
+        if (output == null) {
+            logger.warn("Tried to clear Facets for unknown Out: " + outputKey);
+            return;
+        }
+
+        output.setFacets(new ArrayList<Facet>());
+    }
+
+
     public Document toXML() {
         Document doc = XMLUtils.newDocument();
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Fri Dec 16 07:28:17 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Fri Dec 16 09:19:11 2011 +0000
@@ -507,6 +507,7 @@
 
         return new AttributeWriter(
             db,
+            aParser.getCollectionAttribute(),
             aParser.getOuts(),
             aParser.getFacets(),
             oParser.getOuts(),

http://dive4elements.wald.intevation.org