changeset 638:9c565eb46f06

Fixed the process of creating and storing the attribute of a collection. flys-artifacts/trunk@2015 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 27 May 2011 08:46:26 +0000
parents f0c1250d1e7b
children deb5e9840813
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.java flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java
diffstat 4 files changed, 59 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu May 26 16:54:16 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri May 27 08:46:26 2011 +0000
@@ -1,3 +1,18 @@
+2011-05-27  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/collections/AttributeParser.java:
+	  Repaired broken XPath expressions to find the output modes in an
+	  attribute document of a collection.
+
+	* src/main/java/de/intevation/flys/collections/AttributeWriter.java: This
+	  writer will now create a document that has a root node art:attribute.
+	  Before these changes, the document's root node was art:outputs which is
+	  part of the attribute document but not the right root node.
+
+	* src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java:
+	  Adapted some XPath expressions and corrected the the process to create
+	  attribute documents.
+
 2011-05-26	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/math/LinearRemap.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.java	Thu May 26 16:54:16 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.java	Fri May 27 08:46:26 2011 +0000
@@ -25,7 +25,7 @@
 
     /** Constant XPath that points to the outputmodes of an artifact.*/
     public static final String XPATH_ARTIFACT_OUTPUTMODES =
-        "/art:output";
+        "/art:attribute/art:outputs/art:output";
 
 
     private static Logger logger = Logger.getLogger(AttributeParser.class);
@@ -103,16 +103,32 @@
             Node theme = themes.item(i);
 
             String name = XMLUtils.xpathString(
-                theme, "@facet", ArtifactNamespaceContext.INSTANCE);
+                theme, "@art:facet", ArtifactNamespaceContext.INSTANCE);
+
+            if (name == null || name.length() == 0) {
+                continue;
+            }
 
             String uuid = XMLUtils.xpathString(
-                theme, "@artifact", ArtifactNamespaceContext.INSTANCE);
+                theme, "@art:artifact", ArtifactNamespaceContext.INSTANCE);
+
+            if (uuid == null || uuid.length() == 0) {
+                continue;
+            }
 
             String pos = XMLUtils.xpathString(
-                theme, "@pos", ArtifactNamespaceContext.INSTANCE);
+                theme, "@art:pos", ArtifactNamespaceContext.INSTANCE);
+
+            if (pos == null || pos.length() == 0) {
+                continue;
+            }
 
             String active = XMLUtils.xpathString(
-                theme, "@active", ArtifactNamespaceContext.INSTANCE);
+                theme, "@art:active", ArtifactNamespaceContext.INSTANCE);
+
+            if (active == null || active.length() == 0) {
+                continue;
+            }
 
             ManagedFacet item = new ManagedFacet(
                 name, "", uuid,
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java	Thu May 26 16:54:16 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java	Fri May 27 08:46:26 2011 +0000
@@ -46,8 +46,11 @@
             ArtifactNamespaceContext.NAMESPACE_URI,
             ArtifactNamespaceContext.NAMESPACE_PREFIX);
 
-        Element outs = cr.create("outputs");
-        doc.appendChild(outs);
+        Element attribute = cr.create("attribute");
+        Element outs       = cr.create("outputs");
+
+        attribute.appendChild(outs);
+        doc.appendChild(attribute);
 
         Iterator<String> iter = newAttr.keySet().iterator();
 
@@ -116,6 +119,7 @@
         String name = a.getName();
 
         if (list == null) {
+            logger.debug("No old facets found.");
             return false;
         }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Thu May 26 16:54:16 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Fri May 27 08:46:26 2011 +0000
@@ -4,6 +4,7 @@
 import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Vector;
@@ -78,14 +79,12 @@
 
         Element collection = ec.create("artifact-collection");
         Element artifacts  = ec.create("artifacts");
-        Element attributes = ec.create("attribute");
 
         ec.addAttr(collection, "name", getName(), true);
         ec.addAttr(collection, "uuid", identifier(), true);
         ec.addAttr(collection, "creation", creation,  true);
 
         collection.appendChild(artifacts);
-        collection.appendChild(attributes);
         doc.appendChild(collection);
 
         ArtifactDatabase db = context.getDatabase();
@@ -94,15 +93,20 @@
             String[] artifactUUIDs = getArtifactUUIDs(context);
 
             Document oldAttrs = getAttribute();
-            Document attrs    = buildAttributes(
+
+            Document attrs = buildAttributes(
                 db, context,
                 oldAttrs,
                 artifactUUIDs);
 
-            db.setCollectionAttribute(identifier(), context.getMeta(), attrs);
+            log.debug("============== FINAL ATTRIBUTES AFTER MERGE =======");
+            de.intevation.flys.artifacts.XMLDebug.out(attrs);
+            log.debug("============== THIS WAS THE FINAL ATTRIBUTE =======");
 
-            Node child = attrs.getFirstChild();
-            attributes.appendChild(doc.importNode(child, true));
+            collection.appendChild(doc.importNode(attrs.getFirstChild(), true));
+
+            // save the merged document into database
+            db.setCollectionAttribute(identifier(), context.getMeta(), attrs);
 
             for (String uuid: artifactUUIDs) {
                 try {
@@ -278,7 +282,7 @@
 
         Node out = (Node) XMLUtils.xpath(
             attr,
-            "art:outputs/art:output[@name='" + output + "']",
+            "art:attribute/art:outputs/art:output[@name='" + output + "']",
             XPathConstants.NODE,
             ArtifactNamespaceContext.INSTANCE);
 
@@ -676,10 +680,10 @@
      */
     private class ThemeList {
         private Logger logger = Logger.getLogger(ThemeList.class);
-        protected Vector<ManagedFacet> themes;
+        protected Map<Integer, ManagedFacet> themes;
 
         public ThemeList(Document output) {
-            themes = new Vector<ManagedFacet>();
+            themes = new HashMap<Integer, ManagedFacet>();
             parse(output);
         }
 
@@ -735,7 +739,9 @@
                 int pos = Integer.parseInt(position);
                 int act = Integer.parseInt(active);
 
-                themes.add(pos-1, new ManagedFacet(name, null, uuid, pos, act));
+                themes.put(
+                    new Integer(pos-1),
+                    new ManagedFacet(name, null, uuid, pos, act));
             }
             catch (NumberFormatException nfe) {
                 logger.warn(nfe, nfe);
@@ -743,7 +749,7 @@
         }
 
         public ManagedFacet get(int idx) {
-            return themes.get(idx);
+            return themes.get(new Integer(idx));
         }
 
         public int size() {

http://dive4elements.wald.intevation.org