changeset 147:76cc1a66a05f

Implemented a FLYSArtifactCollection that will be used in this application now. flys-artifacts/trunk@1565 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 24 Mar 2011 18:47:07 +0000
parents e8dfe6ba2000
children 2649ada6b053
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/conf.xml flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java
diffstat 3 files changed, 126 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Mar 24 17:29:08 2011 +0000
+++ b/flys-artifacts/ChangeLog	Thu Mar 24 18:47:07 2011 +0000
@@ -1,3 +1,12 @@
+2011-03-24  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java:
+	  New. This ArtifactCollection overrides the DefaultArtifactCollection to
+	  implement FLYS specific describe() and out() operations.
+
+	* doc/conf/conf.xml: Use the FLYSArtifactCollection instead of the
+	  DefaultArtifactCollection for this application.
+
 2011-03-24	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java:
--- a/flys-artifacts/doc/conf/conf.xml	Thu Mar 24 17:29:08 2011 +0000
+++ b/flys-artifacts/doc/conf/conf.xml	Thu Mar 24 18:47:07 2011 +0000
@@ -7,7 +7,7 @@
             name="DefaultArtifactCollectionFactory"
             description="The default artifact collection factory"
             ttl="60000"
-            artifact-collection="de.intevation.artifactdatabase.DefaultArtifactCollection">de.intevation.artifactdatabase.DefaultArtifactCollectionFactory</collection-factory>
+            artifact-collection="de.intevation.flys.collections.FLYSArtifactCollection">de.intevation.artifactdatabase.DefaultArtifactCollectionFactory</collection-factory>
 
         <artifact-factories>
             <!-- All Artifactfactories which are available in this Database.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Thu Mar 24 18:47:07 2011 +0000
@@ -0,0 +1,116 @@
+package de.intevation.flys.collections;
+
+import java.util.Date;
+
+import javax.xml.xpath.XPathConstants;
+
+import org.apache.log4j.Logger;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.ArtifactNamespaceContext;
+import de.intevation.artifacts.CallContext;
+import de.intevation.artifacts.CollectionItem;
+
+import de.intevation.artifacts.common.utils.XMLUtils;
+
+import de.intevation.artifactdatabase.DefaultArtifactCollection;
+import de.intevation.artifactdatabase.Backend;
+import de.intevation.artifactdatabase.Backend.PersistentArtifact;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class FLYSArtifactCollection extends DefaultArtifactCollection {
+
+    /** The logger used in this class.*/
+    private static Logger log = Logger.getLogger(FLYSArtifactCollection.class);
+
+
+    /** Constant XPath that points to the outputmodes of an artifact.*/
+    public static final String XPATH_ARTIFACT_OUTPUTMODES =
+        "/art:result/art:outputmodes";
+
+
+    @Override
+    public Document describe(CallContext context) {
+        log.debug("FLYSArtifactCollection.describe: " + identifier);
+
+        Document doc = XMLUtils.newDocument();
+
+        XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
+            doc,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+        Date creationTime = getCreationTime();
+        String creation   = creationTime != null
+            ? Long.toString(creationTime.getTime())
+            : "";
+
+        Element collection = ec.create("artifact-collection");
+        Element artifacts  = ec.create("artifacts");
+
+        ec.addAttr(collection, "name", getName(), true);
+        ec.addAttr(collection, "uuid", identifier(), true);
+        ec.addAttr(collection, "creation", creation,  true);
+
+        collection.appendChild(artifacts);
+        doc.appendChild(collection);
+
+        Document attribute = getAttribute();
+        if (attribute != null) {
+            Node child = attribute.getFirstChild();
+            collection.appendChild(doc.importNode(child, true));
+        }
+
+        Backend backend        = Backend.getInstance();
+        CollectionItem[] items = backend.listCollectionArtifacts(identifier());
+
+        for (CollectionItem item: items) {
+            artifacts.appendChild(
+                buildArtifactNode(item, backend, context, ec));
+        }
+
+        return doc;
+    }
+
+
+    protected Element buildArtifactNode(
+        CollectionItem          item,
+        Backend                 backend,
+        CallContext             context,
+        XMLUtils.ElementCreator ec)
+    {
+        String uuid = item.getArtifactIdentifier();
+
+        log.debug("Append artifact '"+ uuid +"' to collection description");
+
+        Element ci   = ec.create("artifact");
+        ec.addAttr(ci, "uuid", uuid);
+
+        PersistentArtifact pArtifact = backend.getArtifact(uuid);
+        Artifact artifact            = pArtifact.getArtifact();
+
+        // XXX I am not sure if it works well every time with an empty document
+        // in the describe operation of an artifact.
+        Document description = artifact.describe(null, context);
+        Node outputModes     = (Node) XMLUtils.xpath(
+            description,
+            XPATH_ARTIFACT_OUTPUTMODES,
+            XPathConstants.NODE,
+            ArtifactNamespaceContext.INSTANCE);
+
+        if (outputModes != null) {
+            Document doc = ci.getOwnerDocument();
+            ci.appendChild(doc.importNode(outputModes, true));
+        }
+
+        return ci;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org