From 3337135b06dad7e2f48569ebee38ca96e732fca7 Mon Sep 17 00:00:00 2001
From: jdemendi <jdemendi@localhost>
Date: Wed, 12 Mar 2008 13:26:46 +0000
Subject: [PATCH] Fix bug #2991. Each workflow element must implement a returnEntry method. The returnEntry method performs a processing on  the search entry before the entry is sent to the client application. In the particular case of JE local backend, no  processing is required, so the retunEntry is doing nothing but call the returnEntry on its super class.

---
 opends/src/server/org/opends/server/workflowelement/WorkflowElement.java |  120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 116 insertions(+), 4 deletions(-)

diff --git a/opends/src/server/org/opends/server/workflowelement/WorkflowElement.java b/opends/src/server/org/opends/server/workflowelement/WorkflowElement.java
index 636da05..b5b4bf8 100644
--- a/opends/src/server/org/opends/server/workflowelement/WorkflowElement.java
+++ b/opends/src/server/org/opends/server/workflowelement/WorkflowElement.java
@@ -35,7 +35,12 @@
 import org.opends.messages.Message;
 import org.opends.server.admin.std.server.WorkflowElementCfg;
 import org.opends.server.config.ConfigException;
+import org.opends.server.core.SearchOperationBasis;
+import org.opends.server.types.Control;
+import org.opends.server.types.DN;
+import org.opends.server.types.Entry;
 import org.opends.server.types.Operation;
+import org.opends.server.types.SearchResultReference;
 
 
 /**
@@ -71,6 +76,18 @@
   private static Object registeredWorkflowElementsLock = new Object();
 
 
+  // The original operation basis which has invoked the workflow.
+  // This original operation basis is only useful for the search
+  // operation, for the returned entry and returned reference to be
+  // processed before they are sent back to the client application.
+  private Operation originalOperationBasis = null;
+
+
+  // The parent of the workflow element (null if the workflow element is
+  // the root of the processing tree).
+  private WorkflowElement<?> parent = null;
+
+
   /**
    * Creates a new instance of the workflow element.
    */
@@ -80,7 +97,6 @@
   }
 
 
-
   /**
    * Initializes the instance of the workflow element.
    *
@@ -93,6 +109,27 @@
   }
 
 
+  /**
+   * Set the original operation basis which has invoked the workflow.
+   *
+   * @param operation  the operation basis which has invoked the workflow
+   */
+  protected void setOriginalOperationBasis(Operation operation)
+  {
+    this.originalOperationBasis = operation;
+  }
+
+
+  /**
+   * Set the parent of the current workflow element.
+   *
+   * @param parent  the parent of the workflow element
+   */
+  protected void setParent(WorkflowElement<?> parent)
+  {
+    this.parent = parent;
+  }
+
 
   /**
    * Indicates whether the provided configuration is acceptable for
@@ -137,7 +174,6 @@
   public abstract void execute(Operation operation);
 
 
-
   /**
    * Indicates whether the workflow element encapsulates a private
    * local backend.
@@ -151,7 +187,6 @@
   }
 
 
-
   /**
    * Specifies whether the workflow element encapsulates a private local
    * backend.
@@ -165,7 +200,6 @@
   }
 
 
-
   /**
    * Provides the workflow element identifier.
    *
@@ -248,5 +282,83 @@
     }
   }
 
+
+  /**
+   * Used as a callback for workflow elements to indicate that the provided
+   * entry matches the search criteria and that additional processing should
+   * be performed to potentially send it back to the client.
+   *
+   * @param  entry     The entry that matches the search criteria and should be
+   *                   sent to the client.
+   * @param  controls  The set of controls to include with the entry (may be
+   *                   <CODE>null</CODE> if none are needed).
+   *
+   * @return  <CODE>true</CODE> if the caller should continue processing the
+   *          search request and sending additional entries and references, or
+   *          <CODE>false</CODE> if not for some reason (e.g., the size limit
+   *          has been reached or the search has been abandoned).
+   */
+  public boolean returnEntry(
+      Entry entry,
+      List<Control> controls)
+  {
+    boolean result;
+
+    // If the workflow element has a parent then send the entry
+    // to the parent, otherwise send the entry to the operation
+    // basis. The operation basis will be in charge of sending
+    // the entry to the client application.
+    if (parent == null)
+    {
+      SearchOperationBasis searchOperationBasis =
+        (SearchOperationBasis) originalOperationBasis;
+      result = searchOperationBasis.returnEntry(entry, controls);
+    }
+    else
+    {
+      result = parent.returnEntry(entry, controls);
+    }
+
+    return result;
+  }
+
+
+  /**
+   * Used as a callback for workflow elements to indicate that the provided
+   * search reference was encountered during processing and that additional
+   * processing should be performed to potentially send it back to the client.
+   *
+   * @param  reference  The search reference to send to the client.
+   * @param  dn         The DN related to the specified search reference.
+   *
+   * @return  <CODE>true</CODE> if the caller should continue processing the
+   *          search request and sending additional entries and references , or
+   *          <CODE>false</CODE> if not for some reason (e.g., the size limit
+   *          has been reached or the search has been abandoned).
+   */
+  public boolean returnReference(
+      DN dn,
+      SearchResultReference reference)
+  {
+    boolean result;
+
+    // If the workflow element has a parent then send the reference
+    // to the parent, otherwise send the reference to the operation
+    // basis. The operation basis will be in charge of sending
+    // the reference to the client application.
+    if (parent == null)
+    {
+      SearchOperationBasis searchOperationBasis =
+        (SearchOperationBasis) originalOperationBasis;
+      result = searchOperationBasis.returnReference(dn, reference);
+    }
+    else
+    {
+      result = parent.returnReference(dn, reference);
+    }
+
+    return result;
+  }
+
 }
 

--
Gitblit v1.10.0