changeset 348:f2277458823e

Enabled 'post-describe' hooks for Artifacts. artifacts/trunk@3176 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 07 Nov 2011 16:40:01 +0000
parents 16ab243507e0
children b3eb029e07dd
files ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java
diffstat 3 files changed, 39 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Oct 28 10:08:35 2011 +0000
+++ b/ChangeLog	Mon Nov 07 16:40:01 2011 +0000
@@ -1,3 +1,9 @@
+2011-11-07  Ingo Weinzierl <ingo@intevation.de>
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java,
+	  artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java:
+	  Enabled "post-describe" hooks for the Artifact's describe operation.
+
 2011-10-28	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	Let StateEngine compute a compatibiliy matrix based on given State
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Fri Oct 28 10:08:35 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java	Mon Nov 07 16:40:01 2011 +0000
@@ -444,6 +444,12 @@
      */
     protected List<Hook> postAdvanceHooks;
 
+    /**
+     * Hooks that are executed after an artifact's describe() operation was
+     * called.
+     */
+    protected List<Hook> postDescribeHooks;
+
     protected List<LifetimeListener> lifetimeListeners;
 
     /**
@@ -511,6 +517,10 @@
         this.postAdvanceHooks = postAdvanceHooks;
     }
 
+    public void setPostDescribeHook(List<Hook> postDescribeHooks) {
+        this.postDescribeHooks = postDescribeHooks;
+    }
+
     /**
      * Used to extract the artifact collection factory from bootstrap.
      *
@@ -558,6 +568,7 @@
     protected void setupHooks(FactoryBootstrap bootstrap) {
         setPostFeedHook(bootstrap.getPostFeedHooks());
         setPostAdvanceHook(bootstrap.getPostAdvanceHooks());
+        setPostDescribeHook(bootstrap.getPostDescribeHooks());
     }
 
     protected void setupBackendListeners(FactoryBootstrap bootstrap) {
@@ -847,7 +858,16 @@
             artifact);
 
         try {
-            return artifact.getArtifact().describe(data, cc);
+            Artifact art = artifact.getArtifact();
+            Document res = art.describe(data, cc);
+
+            if (postDescribeHooks != null) {
+                for (Hook hook: postDescribeHooks) {
+                    hook.execute(art, cc, res);
+                }
+            }
+
+            return res;
         }
         finally {
             cc.postCall();
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java	Fri Oct 28 10:08:35 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java	Mon Nov 07 16:40:01 2011 +0000
@@ -170,6 +170,8 @@
 
     protected List<Hook> postAdvanceHooks;
 
+    protected List<Hook> postDescribeHooks;
+
     protected List<LifetimeListener> lifetimeListeners;
 
     protected List<BackendListener> backendListeners;
@@ -542,8 +544,9 @@
     protected void loadHooks() {
         logger.info("loading hooks");
 
-        postFeedHooks    = new ArrayList<Hook>();
-        postAdvanceHooks = new ArrayList<Hook>();
+        postFeedHooks     = new ArrayList<Hook>();
+        postAdvanceHooks  = new ArrayList<Hook>();
+        postDescribeHooks = new ArrayList<Hook>();
 
         NodeList nodes = Config.getNodeSetXPath(HOOKS);
 
@@ -567,6 +570,9 @@
                 else if (a.equals("post-advance")) {
                     postAdvanceHooks.add(hook);
                 }
+                else if (a.equals("post-describe")) {
+                    postDescribeHooks.add(hook);
+                }
             }
         }
     }
@@ -703,6 +709,10 @@
         return postAdvanceHooks;
     }
 
+    public List<Hook> getPostDescribeHooks() {
+        return postDescribeHooks;
+    }
+
     public HTTPServer getHTTPServer() {
         return httpServer;
     }

http://dive4elements.wald.intevation.org