# HG changeset patch # User Ingo Weinzierl # Date 1306485986 0 # Node ID 9c565eb46f060cd4a1e2bbf55821495142b2fb68 # Parent f0c1250d1e7be2eeca3ff8e4253e43695626d803 Fixed the process of creating and storing the attribute of a collection. flys-artifacts/trunk@2015 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r f0c1250d1e7b -r 9c565eb46f06 flys-artifacts/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/flys/artifacts/math/LinearRemap.java: diff -r f0c1250d1e7b -r 9c565eb46f06 flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.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, diff -r f0c1250d1e7b -r 9c565eb46f06 flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java --- 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 iter = newAttr.keySet().iterator(); @@ -116,6 +119,7 @@ String name = a.getName(); if (list == null) { + logger.debug("No old facets found."); return false; } diff -r f0c1250d1e7b -r 9c565eb46f06 flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java --- 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 themes; + protected Map themes; public ThemeList(Document output) { - themes = new Vector(); + themes = new HashMap(); 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() {