diff flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java @ 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 046bd86ae41d
children deb5e9840813
line wrap: on
line diff
--- 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