mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
15.24.2013 fff28547081591b9b506c43b2df646dea3a32405
Extracted several time the method findAndSetMatchingDN(). We should look at moving this code to a single reusable place.

LocalBackend*Operation.java:
Extracted method findAndSetMatchingDN() from the process*() methods. Tidied up the code to make it the same across all classes.

PasswordModifyExtendedOperation.java:
Extracted method findAndSetMatchingDN() from getEntryByDN().
6 files modified
305 ■■■■ changed files
opends/src/server/org/opends/server/extensions/PasswordModifyExtendedOperation.java 68 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendAddOperation.java 46 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendCompareOperation.java 49 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendDeleteOperation.java 46 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyDNOperation.java 48 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/workflowelement/localbackend/LocalBackendModifyOperation.java 48 ●●●● patch | view | raw | blame | history
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.
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)
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.
   *
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.
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.
   *
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.
   *