From 91cb0dd082a0132b48c255a4e5d7e504f23ee4d0 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 15 Jul 2013 15:24:47 +0000
Subject: [PATCH] Extracted several time the method findAndSetMatchingDN(). We should look at moving this code to a single reusable place.

---
 opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendAddOperation.java      |   46 ++++---
 opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyOperation.java   |   48 ++++---
 opendj-sdk/opends/src/server/org/opends/server/extensions/PasswordModifyExtendedOperation.java                 |   68 +++++------
 opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyDNOperation.java |   48 ++++---
 opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendCompareOperation.java  |   49 ++++---
 opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendDeleteOperation.java   |   46 ++++---
 6 files changed, 156 insertions(+), 149 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/extensions/PasswordModifyExtendedOperation.java b/opendj-sdk/opends/src/server/org/opends/server/extensions/PasswordModifyExtendedOperation.java
index 2b2d54c..3dc3214 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/extensions/PasswordModifyExtendedOperation.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/extensions/PasswordModifyExtendedOperation.java
@@ -115,22 +115,18 @@
    */
   private static final DebugTracer TRACER = getTracer();
 
-
-
-  // The current configuration state.
+  /** The current configuration state. */
   private PasswordModifyExtendedOperationHandlerCfg currentConfig;
 
-  // The DN of the identity mapper.
+  /** The DN of the identity mapper. */
   private DN identityMapperDN;
 
-  // The reference to the identity mapper.
+  /** The reference to the identity mapper. */
   private IdentityMapper<?> identityMapper;
 
-  // The default set of supported control OIDs for this extended
+  /** The default set of supported control OIDs for this extended */
   private Set<String> supportedControlOIDs = new HashSet<String>(0);
 
-
-
   /**
    * Create an instance of this password modify extended operation.  All
    * initialization should be performed in the
@@ -139,12 +135,8 @@
   public PasswordModifyExtendedOperation()
   {
     super();
-
   }
 
-
-
-
   /**
    * Initializes this extended operation handler based on the information in the
    * provided configuration.  It should also register itself with the
@@ -920,7 +912,7 @@
       {
         // Remove all existing encoded values that match the old password.
         Set<AttributeValue> existingValues = pwPolicyState.getPasswordValues();
-        LinkedHashSet<AttributeValue> deleteValues =
+        Set<AttributeValue> deleteValues =
              new LinkedHashSet<AttributeValue>(existingValues.size());
         if (pwPolicyState.getAuthenticationPolicy().isAuthPasswordSyntax())
         {
@@ -1245,35 +1237,12 @@
       if (userEntry == null)
       {
         operation.setResultCode(ResultCode.NO_SUCH_OBJECT);
-
         operation.appendErrorMessage(
                 ERR_EXTOP_PASSMOD_NO_USER_ENTRY_BY_AUTHZID.get(
                         String.valueOf(entryDN)));
 
         // See if one of the entry's ancestors exists.
-        DN parentDN = entryDN.getParentDNInSuffix();
-        while (parentDN != null)
-        {
-          try
-          {
-            if (DirectoryServer.entryExists(parentDN))
-            {
-              operation.setMatchedDN(parentDN);
-              break;
-            }
-          }
-          catch (Exception e)
-          {
-            if (debugEnabled())
-            {
-              TRACER.debugCaught(DebugLogLevel.ERROR, e);
-            }
-            break;
-          }
-
-          parentDN = parentDN.getParentDNInSuffix();
-        }
-
+        findAndSetMatchingDN(operation, entryDN);
         return null;
       }
 
@@ -1295,7 +1264,30 @@
     }
   }
 
+  private void findAndSetMatchingDN(Operation operation, DN entryDN)
+  {
+    try
+    {
+      DN matchedDN = entryDN.getParentDNInSuffix();
+      while (matchedDN != null)
+      {
+        if (DirectoryServer.entryExists(matchedDN))
+        {
+          operation.setMatchedDN(matchedDN);
+          return;
+        }
 
+        matchedDN = matchedDN.getParentDNInSuffix();
+      }
+    }
+    catch (Exception e)
+    {
+      if (debugEnabled())
+      {
+        TRACER.debugCaught(DebugLogLevel.ERROR, e);
+      }
+    }
+  }
 
   /**
    * {@inheritDoc}
@@ -1386,7 +1378,7 @@
   {
     ResultCode        resultCode          = ResultCode.SUCCESS;
     boolean           adminActionRequired = false;
-    ArrayList<Message> messages            = new ArrayList<Message>();
+    List<Message>     messages            = new ArrayList<Message>();
 
 
     // Make sure that the specified identity mapper is OK.
diff --git a/opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendAddOperation.java b/opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendAddOperation.java
index 2d988ab..52a6be2 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendAddOperation.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendAddOperation.java
@@ -347,28 +347,7 @@
 
         if (parentEntry == null)
         {
-          DN matchedDN = parentDN.getParentDNInSuffix();
-          while (matchedDN != null)
-          {
-            try
-            {
-              if (DirectoryServer.entryExists(matchedDN))
-              {
-                setMatchedDN(matchedDN);
-                break;
-              }
-            }
-            catch (Exception e)
-            {
-              if (debugEnabled())
-              {
-                TRACER.debugCaught(DebugLogLevel.ERROR, e);
-              }
-              break;
-            }
-
-            matchedDN = matchedDN.getParentDNInSuffix();
-          }
+          findAndSetMatchingDN(parentDN);
 
           // The parent doesn't exist, so this add can't be successful.
           setResultCode(ResultCode.NO_SUCH_OBJECT);
@@ -614,7 +593,30 @@
     }
   }
 
+  private void findAndSetMatchingDN(DN entryDN)
+  {
+    try
+    {
+      DN matchedDN = entryDN.getParentDNInSuffix();
+      while (matchedDN != null)
+      {
+        if (DirectoryServer.entryExists(matchedDN))
+        {
+          setMatchedDN(matchedDN);
+          return;
+        }
 
+        matchedDN = matchedDN.getParentDNInSuffix();
+      }
+    }
+    catch (Exception e)
+    {
+      if (debugEnabled())
+      {
+        TRACER.debugCaught(DebugLogLevel.ERROR, e);
+      }
+    }
+  }
 
   private boolean checkHasReadOnlyAttributes(
       Map<AttributeType, List<Attribute>> attributes)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendCompareOperation.java b/opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendCompareOperation.java
index 48a1fbf..bd4a3ca 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendCompareOperation.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendCompareOperation.java
@@ -205,29 +205,7 @@
               .valueOf(entryDN)));
 
           // See if one of the entry's ancestors exists.
-          DN parentDN = entryDN.getParentDNInSuffix();
-          while (parentDN != null)
-          {
-            try
-            {
-              if (DirectoryServer.entryExists(parentDN))
-              {
-                setMatchedDN(parentDN);
-                break;
-              }
-            }
-            catch (Exception e)
-            {
-              if (debugEnabled())
-              {
-                TRACER.debugCaught(DebugLogLevel.ERROR, e);
-              }
-              break;
-            }
-
-            parentDN = parentDN.getParentDNInSuffix();
-          }
-
+          findAndSetMatchingDN(entryDN);
           return;
         }
       }
@@ -359,6 +337,31 @@
     }
   }
 
+  private void findAndSetMatchingDN(DN entryDN)
+  {
+    try
+    {
+      DN matchedDN = entryDN.getParentDNInSuffix();
+      while (matchedDN != null)
+      {
+        if (DirectoryServer.entryExists(matchedDN))
+        {
+          setMatchedDN(matchedDN);
+          return;
+        }
+
+        matchedDN = matchedDN.getParentDNInSuffix();
+      }
+    }
+    catch (Exception e)
+    {
+      if (debugEnabled())
+      {
+        TRACER.debugCaught(DebugLogLevel.ERROR, e);
+      }
+    }
+  }
+
   /**
    * Performs any processing required for the controls included in the request.
    *
diff --git a/opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendDeleteOperation.java b/opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendDeleteOperation.java
index 8057d19..47e67f3 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendDeleteOperation.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendDeleteOperation.java
@@ -245,28 +245,7 @@
         appendErrorMessage(ERR_DELETE_NO_SUCH_ENTRY
             .get(String.valueOf(entryDN)));
 
-        try
-        {
-          DN parentDN = entryDN.getParentDNInSuffix();
-          while (parentDN != null)
-          {
-            if (DirectoryServer.entryExists(parentDN))
-            {
-              setMatchedDN(parentDN);
-              break;
-            }
-
-            parentDN = parentDN.getParentDNInSuffix();
-          }
-        }
-        catch (Exception e)
-        {
-          if (debugEnabled())
-          {
-            TRACER.debugCaught(DebugLogLevel.ERROR, e);
-          }
-        }
-
+        findAndSetMatchingDN(entryDN);
         return;
       }
 
@@ -437,7 +416,30 @@
     }
   }
 
+  private void findAndSetMatchingDN(DN entryDN)
+  {
+    try
+    {
+      DN matchedDN = entryDN.getParentDNInSuffix();
+      while (matchedDN != null)
+      {
+        if (DirectoryServer.entryExists(matchedDN))
+        {
+          setMatchedDN(matchedDN);
+          return;
+        }
 
+        matchedDN = matchedDN.getParentDNInSuffix();
+      }
+    }
+    catch (Exception e)
+    {
+      if (debugEnabled())
+      {
+        TRACER.debugCaught(DebugLogLevel.ERROR, e);
+      }
+    }
+  }
 
   /**
    * Performs any request control processing needed for this operation.
diff --git a/opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyDNOperation.java b/opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyDNOperation.java
index f829e42..36f96fa 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyDNOperation.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyDNOperation.java
@@ -383,28 +383,7 @@
       if (getOriginalEntry() == null)
       {
         // See if one of the entry's ancestors exists.
-        parentDN = entryDN.getParentDNInSuffix();
-        while (parentDN != null)
-        {
-          try
-          {
-            if (DirectoryServer.entryExists(parentDN))
-            {
-              setMatchedDN(parentDN);
-              break;
-            }
-          }
-          catch (Exception e)
-          {
-            if (debugEnabled())
-            {
-              TRACER.debugCaught(DebugLogLevel.ERROR, e);
-            }
-            break;
-          }
-
-          parentDN = parentDN.getParentDNInSuffix();
-        }
+        findAndSetMatchingDN(entryDN);
 
         setResultCode(ResultCode.NO_SUCH_OBJECT);
         appendErrorMessage(ERR_MODDN_NO_CURRENT_ENTRY.get(String
@@ -594,6 +573,31 @@
     }
   }
 
+  private void findAndSetMatchingDN(DN entryDN)
+  {
+    try
+    {
+      DN matchedDN = entryDN.getParentDNInSuffix();
+      while (matchedDN != null)
+      {
+        if (DirectoryServer.entryExists(matchedDN))
+        {
+          setMatchedDN(matchedDN);
+          return;
+        }
+
+        matchedDN = matchedDN.getParentDNInSuffix();
+      }
+    }
+    catch (Exception e)
+    {
+      if (debugEnabled())
+      {
+        TRACER.debugCaught(DebugLogLevel.ERROR, e);
+      }
+    }
+  }
+
   /**
    * Processes the set of controls included in the request.
    *
diff --git a/opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyOperation.java b/opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyOperation.java
index e4aa570..a1f310b 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyOperation.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyOperation.java
@@ -430,28 +430,7 @@
             .get(String.valueOf(entryDN)));
 
         // See if one of the entry's ancestors exists.
-        try
-        {
-          DN parentDN = entryDN.getParentDNInSuffix();
-          while (parentDN != null)
-          {
-            if (DirectoryServer.entryExists(parentDN))
-            {
-              setMatchedDN(parentDN);
-              break;
-            }
-
-            parentDN = parentDN.getParentDNInSuffix();
-          }
-        }
-        catch (Exception e)
-        {
-          if (debugEnabled())
-          {
-            TRACER.debugCaught(DebugLogLevel.ERROR, e);
-          }
-        }
-
+        findAndSetMatchingDN(entryDN);
         return;
       }
 
@@ -650,6 +629,31 @@
     }
   }
 
+  private void findAndSetMatchingDN(DN entryDN)
+  {
+    try
+    {
+      DN matchedDN = entryDN.getParentDNInSuffix();
+      while (matchedDN != null)
+      {
+        if (DirectoryServer.entryExists(matchedDN))
+        {
+          setMatchedDN(matchedDN);
+          return;
+        }
+
+        matchedDN = matchedDN.getParentDNInSuffix();
+      }
+    }
+    catch (Exception e)
+    {
+      if (debugEnabled())
+      {
+        TRACER.debugCaught(DebugLogLevel.ERROR, e);
+      }
+    }
+  }
+
   /**
    * Processes any controls contained in the modify request.
    *

--
Gitblit v1.10.0