changeset 1784:0fe3c4849baa

Cosmetics and refactoring in FLYSArtifactCollection. flys-artifacts/trunk@3106 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 28 Oct 2011 09:59:47 +0000
parents 376c81aa7d55
children 661dfad9910a
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java
diffstat 2 files changed, 51 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Oct 28 09:55:59 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Oct 28 09:59:47 2011 +0000
@@ -1,3 +1,9 @@
+2011-10-28	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java
+	  (mergeAttributes, getMasterArtifact): Extraced, updated caller.
+	  Cosmetics to reduce indentation one step.
+
 2011-10-28	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Fri Oct 28 09:55:59 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Fri Oct 28 09:59:47 2011 +0000
@@ -32,12 +32,14 @@
 import de.intevation.artifactdatabase.DefaultArtifactCollection;
 
 import de.intevation.flys.artifacts.context.FLYSContext;
+import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.model.ManagedFacet;
 import de.intevation.flys.artifacts.model.ManagedDomFacet;
 import de.intevation.flys.exports.OutGenerator;
 import de.intevation.flys.themes.Theme;
 import de.intevation.flys.themes.ThemeFactory;
 
+import de.intevation.flys.utils.FLYSUtils;
 
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
@@ -105,15 +107,18 @@
 
             collection.appendChild(doc.importNode(newAttr, true));
 
-            if (aUUIDs != null) {
-                for (String uuid: aUUIDs) {
-                    try {
-                        artifacts.appendChild(
-                            buildArtifactNode(db, uuid, context, ec));
-                    }
-                    catch (ArtifactDatabaseException dbe) {
-                        log.warn(dbe, dbe);
-                    }
+            // Make it an empty array if null.
+            if (aUUIDs == null) {
+                aUUIDs = new String[] {};
+            }
+
+            for (String uuid: aUUIDs) {
+                try {
+                    artifacts.appendChild(
+                        buildArtifactNode(db, uuid, context, ec));
+                }
+                catch (ArtifactDatabaseException dbe) {
+                    log.warn(dbe, dbe);
                 }
             }
         }
@@ -131,6 +136,7 @@
     /**
      * Merge the current art:outputs nodes with the the outputs provided by the
      * artifacts in the Collection.
+     *
      * @param uuids Artifact uuids.
      */
     protected Node mergeAttributes(
@@ -219,20 +225,13 @@
         generator.init(format, out, context);
 
         // Get master artifact.
-        try{
-            ArtifactDatabase db = context.getDatabase();
-            CallMeta callMeta   = context.getMeta();
-            Document document = db.getCollectionsMasterArtifact(
-                identifier(), callMeta);
-
-            String masterUUID = XMLUtils.xpathString(
-                document, XPATH_MASTER_UUID, ArtifactNamespaceContext.INSTANCE);
-
-            log.debug("Will set master Artifact to uuid: " + masterUUID);
-            generator.setMasterArtifact(getArtifact(masterUUID, context));
+        FLYSArtifact master = getMasterArtifact(context);
+        if (master != null) {
+            log.debug("Will set master Artifact to uuid: " + master.identifier());
+            generator.setMasterArtifact(master);
         }
-        catch (ArtifactDatabaseException adb) {
-            log.error(adb, adb);
+        else {
+            log.warn("Could not set master artifact.");
         }
 
         try {
@@ -316,6 +315,30 @@
 
 
     /**
+     * @return masterartifact or null if exception/not found.
+     */
+    protected FLYSArtifact getMasterArtifact(CallContext context)
+    {
+        try {
+            ArtifactDatabase db = context.getDatabase();
+            CallMeta callMeta   = context.getMeta();
+            Document document   = db.getCollectionsMasterArtifact(
+                identifier(), callMeta);
+    
+            String masterUUID   = XMLUtils.xpathString(
+                document, XPATH_MASTER_UUID, ArtifactNamespaceContext.INSTANCE);
+            FLYSArtifact masterArtifact =
+                (FLYSArtifact) getArtifact(masterUUID, context);
+            return masterArtifact;
+        }
+        catch (ArtifactDatabaseException ade) {
+            log.error(ade, ade);
+        }
+        return null;
+    }
+
+
+    /**
      * Return merged output document.
      * @param uuids List of artifact uuids.
      */

http://dive4elements.wald.intevation.org