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

Jean-Noël Rouvignac
08.17.2016 68abf38e0b76422555852f16d5931f429dc74561
OPENDJ-1342 Migrate AVA, RDN, and DN classes: replaced calls to DN.rdn(int) and DN(RDN[])

Replaced calls to DN.rdn(int) and DN(RDN[]) constructor by:
- DN.rename(DN, DN)
- DN.parent(int)
- DN.localName(i)
- DN.rootDN().child(RDN)
1 files added
13 files modified
358 ■■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/NodeRefresher.java 50 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/SimplifiedViewEntryPanel.java 2 ●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TableViewEntryPanel.java 20 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/authorization/dseecompat/AciList.java 28 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/DN2URI.java 2 ●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/DnKeyFormat.java 9 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java 33 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/extensions/SubjectAttributeToUserAttributeCertificateMapper.java 1 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/makeldif/DNTag.java 41 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/makeldif/DNTagUtils.java 46 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/makeldif/UnderscoreDNTag.java 43 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/makeldif/UnderscoreParentDNTag.java 13 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/SearchFilter.java 1 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/types/TestDN.java 69 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/browser/NodeRefresher.java
@@ -33,16 +33,16 @@
import javax.swing.SwingUtilities;
import javax.swing.tree.TreeNode;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.RDN;
import org.forgerock.opendj.ldap.SearchScope;
import org.opends.admin.ads.util.ConnectionUtils;
import org.opends.guitools.controlpanel.ui.nodes.BasicNode;
import org.opends.messages.AdminToolMessages;
import org.opends.server.schema.SchemaConstants;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.LDAPURL;
import org.opends.server.types.OpenDsException;
import org.forgerock.opendj.ldap.RDN;
/**
 * The class that is in charge of doing the LDAP searches required to update a
@@ -796,30 +796,8 @@
              // if it is the case, do not add the parent.  If is not the case,
              // search for the parent and add it.
              RDN[] rdns = new RDN[parentComponents + 1];
              int diff = dn.size() - rdns.length;
              for (int i=0; i < rdns.length; i++)
              {
                rdns[i] = dn.rdn(i + diff);
              }
              final DN parentToAddDN = new DN(rdns);
              boolean mustAddParent = true;
              for (SearchResult addedEntry : childEntries)
              {
                try
                {
                  DN addedDN = DN.valueOf(addedEntry.getName());
                  if (addedDN.equals(parentToAddDN))
                  {
                    mustAddParent = false;
                    break;
                  }
                }
                catch (Throwable t)
                {
                  throw new RuntimeException("Error decoding dn: "+
                      addedEntry.getName()+" . "+t, t);
                }
              }
              final DN parentToAddDN = dn.parent(dn.size() - rdns.length);
              boolean mustAddParent = mustAddParent(parentToAddDN);
              if (mustAddParent)
              {
                final boolean resultValue[] = {true};
@@ -903,6 +881,26 @@
    }
  }
  private boolean mustAddParent(final DN parentToAddDN)
  {
    for (SearchResult addedEntry : childEntries)
    {
      try
      {
        DN addedDN = DN.valueOf(addedEntry.getName());
        if (addedDN.equals(parentToAddDN))
        {
          return false;
        }
      }
      catch (Throwable t)
      {
        throw new RuntimeException("Error decoding dn: " + addedEntry.getName() + " . " + t, t);
      }
    }
    return true;
  }
  /**
   * Returns the entry for the given dn.
   * The code assumes that the request controls are set in the connection.
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/SimplifiedViewEntryPanel.java
@@ -1519,7 +1519,7 @@
          DN newDN;
          if (parent == null)
          {
            newDN = new DN(new RDN[]{newRDN});
            newDN = DN.rootDN().child(newRDN);
          }
          else
          {
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TableViewEntryPanel.java
@@ -44,6 +44,12 @@
import javax.swing.SwingUtilities;
import javax.swing.tree.TreePath;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.AVA;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.RDN;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.opends.guitools.controlpanel.datamodel.BinaryValue;
import org.opends.guitools.controlpanel.datamodel.CustomSearchResult;
import org.opends.guitools.controlpanel.datamodel.ObjectClassValue;
@@ -52,13 +58,11 @@
import org.opends.guitools.controlpanel.ui.renderer.AttributeCellEditor;
import org.opends.guitools.controlpanel.ui.renderer.LDAPEntryTableCellRenderer;
import org.opends.guitools.controlpanel.util.Utilities;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.AVA;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.RDN;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.opends.server.types.*;
import org.opends.server.types.Entry;
import org.opends.server.types.LDIFImportConfig;
import org.opends.server.types.ObjectClass;
import org.opends.server.types.OpenDsException;
import org.opends.server.types.Schema;
import org.opends.server.util.LDIFReader;
import org.opends.server.util.ServerConstants;
@@ -339,7 +343,7 @@
          DN newDN;
          if (parent == null)
          {
            newDN = new DN(new RDN[]{newRDN});
            newDN = DN.rootDN().child(newRDN);
          }
          else
          {
opendj-server-legacy/src/main/java/org/opends/server/authorization/dseecompat/AciList.java
@@ -19,18 +19,23 @@
import static org.opends.messages.AccessControlMessages.*;
import static org.opends.server.authorization.dseecompat.AciHandler.*;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.SortedSet;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.api.Backend;
import org.opends.server.api.DITCacheMap;
import org.opends.server.types.Attribute;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.Entry;
import org.forgerock.opendj.ldap.RDN;
/**
 * The AciList class performs caching of the ACI attribute values
@@ -401,9 +406,6 @@
   */
  public void renameAci(DN oldDN, DN newDN ) {
    int oldRDNCount=oldDN.size();
    int newRDNCount=newDN.size();
    lock.writeLock().lock();
    try
    {
@@ -412,17 +414,9 @@
              aciList.entrySet().iterator();
      while (iterator.hasNext()) {
        Map.Entry<DN,List<Aci>> hashEntry = iterator.next();
        if(hashEntry.getKey().isSubordinateOrEqualTo(oldDN)) {
          int keyRDNCount=hashEntry.getKey().size();
          int keepRDNCount=keyRDNCount - oldRDNCount;
          RDN[] newRDNs = new RDN[keepRDNCount + newRDNCount];
          for (int i=0; i < keepRDNCount; i++) {
            newRDNs[i] = hashEntry.getKey().rdn(i);
          }
          for (int i=keepRDNCount, j=0; j < newRDNCount; i++,j++) {
            newRDNs[i] = newDN.rdn(j);
          }
          DN relocateDN=new DN(newRDNs);
        DN keyDn = hashEntry.getKey();
        if (keyDn.isSubordinateOrEqualTo(oldDN)) {
          DN relocateDN = keyDn.rename(oldDN, newDN);
          List<Aci> acis = new LinkedList<>();
          for(Aci aci : hashEntry.getValue()) {
            try {
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/DN2URI.java
@@ -490,7 +490,7 @@
          DN urlBaseDN = targetDN;
          if (!referralDN.equals(ldapurl.getBaseDN()))
          {
            urlBaseDN = EntryContainer.modDN(targetDN, referralDN.size(), ldapurl.getBaseDN());
            urlBaseDN = targetDN.rename(referralDN, ldapurl.getBaseDN());
          }
          ldapurl.setBaseDN(urlBaseDN);
          if (searchScope == null)
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/DnKeyFormat.java
@@ -73,14 +73,7 @@
   */
  static ByteString dnToDNKey(DN dn, int prefixRDNs)
  {
    final ByteStringBuilder builder = new ByteStringBuilder(128);
    final int startSize = dn.size() - prefixRDNs - 1;
    for (int i = startSize; i >= 0; i--)
    {
        builder.appendByte(NORMALIZED_RDN_SEPARATOR);
        dn.rdn(i).toNormalizedByteString(builder);
    }
    return builder.toByteString();
    return dn.localName(dn.size() - prefixRDNs).toNormalizedByteString();
  }
  /**
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java
@@ -48,6 +48,7 @@
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
import org.forgerock.opendj.ldap.schema.AttributeType;
@@ -90,13 +91,11 @@
import org.opends.server.types.Attributes;
import org.opends.server.types.CanceledOperationException;
import org.opends.server.types.Control;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
import org.opends.server.types.Modification;
import org.opends.server.types.Operation;
import org.opends.server.types.Privilege;
import org.forgerock.opendj.ldap.RDN;
import org.opends.server.types.SearchFilter;
import org.opends.server.types.SortOrder;
import org.opends.server.types.VirtualAttributeRule;
@@ -2059,7 +2058,7 @@
          }
          else
          {
            final DN newDN = modDN(oldEntry.getName(), oldTargetDN.size(), newTargetDN);
            final DN newDN = oldEntry.getName().rename(oldTargetDN, newTargetDN);
            newEntry = oldEntry.duplicate(false);
            newEntry.setDN(newDN);
            modifications = invokeSubordinateModifyDNPlugins(oldEntry, newEntry);
@@ -2146,34 +2145,6 @@
  }
  /**
   * Make a new DN for a subordinate entry of a renamed or moved entry.
   *
   * @param oldDN The current DN of the subordinate entry.
   * @param oldSuffixLen The current DN length of the renamed or moved entry.
   * @param newSuffixDN The new DN of the renamed or moved entry.
   * @return The new DN of the subordinate entry.
   */
  static DN modDN(DN oldDN, int oldSuffixLen, DN newSuffixDN)
  {
    int oldDNNumComponents    = oldDN.size();
    int oldDNKeepComponents   = oldDNNumComponents - oldSuffixLen;
    int newSuffixDNComponents = newSuffixDN.size();
    RDN[] newDNComponents = new RDN[oldDNKeepComponents+newSuffixDNComponents];
    for (int i=0; i < oldDNKeepComponents; i++)
    {
      newDNComponents[i] = oldDN.rdn(i);
    }
    for (int i=oldDNKeepComponents, j=0; j < newSuffixDNComponents; i++,j++)
    {
      newDNComponents[i] = newSuffixDN.rdn(j);
    }
    return new DN(newDNComponents);
  }
  /**
   * Insert a new entry into the attribute indexes.
   *
   * @param buffer The index buffer used to buffer up the index changes.
opendj-server-legacy/src/main/java/org/opends/server/extensions/SubjectAttributeToUserAttributeCertificateMapper.java
@@ -40,6 +40,7 @@
import org.forgerock.opendj.config.server.ConfigException;
import org.forgerock.opendj.ldap.AVA;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.RDN;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
import org.forgerock.opendj.ldap.schema.AttributeType;
opendj-server-legacy/src/main/java/org/opends/server/tools/makeldif/DNTag.java
@@ -16,14 +16,15 @@
 */
package org.opends.server.tools.makeldif;
import static org.opends.messages.ToolMessages.*;
import static org.opends.server.tools.makeldif.DNTagUtils.*;
import java.util.List;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.InitializationException;
import static org.opends.messages.ToolMessages.*;
/**
 * This class defines a tag that is used to include the DN of the current entry
 * in the attribute value.
@@ -98,43 +99,13 @@
  }
  @Override
  public TagResult generateValue(TemplateEntry templateEntry,
                                 TemplateValue templateValue)
  public TagResult generateValue(TemplateEntry templateEntry, TemplateValue templateValue)
  {
    DN dn = templateEntry.getDN();
    if (dn == null || dn.isRootDN())
    if (dn != null && !dn.isRootDN())
    {
      return TagResult.SUCCESS_RESULT;
      templateValue.getValue().append(generateDNKeepingRDNs(dn, numComponents));
    }
    if (numComponents == 0)
    {
      templateValue.getValue().append(dn);
    }
    else if (numComponents > 0)
    {
      int count = Math.min(numComponents, dn.size());
      templateValue.getValue().append(dn.rdn(0));
      for (int i = 1; i < count; i++)
      {
        templateValue.append(",");
        templateValue.getValue().append(dn.rdn(i));
      }
    }
    else
    {
      int sz = dn.size();
      int count = Math.min(Math.abs(numComponents), sz);
      templateValue.getValue().append(dn.rdn(sz - count));
      for (int i = 1; i < count; i++)
      {
        templateValue.append(",");
        templateValue.getValue().append(dn.rdn(sz - count + i));
      }
    }
    return TagResult.SUCCESS_RESULT;
  }
}
opendj-server-legacy/src/main/java/org/opends/server/tools/makeldif/DNTagUtils.java
New file
@@ -0,0 +1,46 @@
/*
 * The contents of this file are subject to the terms of the Common Development and
 * Distribution License (the License). You may not use this file except in compliance with the
 * License.
 *
 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
 * specific language governing permission and limitations under the License.
 *
 * When distributing Covered Software, include this CDDL Header Notice in each file and include
 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2016 ForgeRock AS.
 */
package org.opends.server.tools.makeldif;
import org.forgerock.opendj.ldap.DN;
/** Utility class for *DNTag classes. */
final class DNTagUtils
{
  private DNTagUtils()
  {
    // private for utility classes
  }
  static DN generateDNKeepingRDNs(DN dn, int nbRdnsToInclude)
  {
    if (nbRdnsToInclude == 0)
    {
      return dn;
    }
    else if (nbRdnsToInclude > 0)
    {
      int count = Math.min(nbRdnsToInclude, dn.size());
      return dn.localName(count);
    }
    else
    {
      int sz = dn.size();
      int count = Math.min(Math.abs(nbRdnsToInclude), sz);
      return dn.parent(sz - count).localName(count);
    }
  }
}
opendj-server-legacy/src/main/java/org/opends/server/tools/makeldif/UnderscoreDNTag.java
@@ -16,14 +16,16 @@
 */
package org.opends.server.tools.makeldif;
import static org.opends.messages.ToolMessages.*;
import static org.opends.server.tools.makeldif.DNTagUtils.*;
import java.util.List;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.util.Utils;
import org.opends.server.types.InitializationException;
import static org.opends.messages.ToolMessages.*;
/**
 * This class defines a tag that is used to include the DN of the current entry
 * in the attribute value, with underscores in place of the commas.
@@ -102,43 +104,10 @@
                                 TemplateValue templateValue)
  {
    DN dn = templateEntry.getDN();
    if (dn == null || dn.isRootDN())
    if (dn != null && !dn.isRootDN())
    {
      return TagResult.SUCCESS_RESULT;
      Utils.joinAsString(templateValue.getValue(), "_", generateDNKeepingRDNs(dn, numComponents));
    }
    if (numComponents == 0)
    {
      templateValue.getValue().append(dn.rdn(0));
      for (int i=1; i < dn.size(); i++)
      {
        templateValue.append("_");
        templateValue.getValue().append(dn.rdn(i));
      }
    }
    else if (numComponents > 0)
    {
      int count = Math.min(numComponents, dn.size());
      templateValue.getValue().append(dn.rdn(0));
      for (int i = 1; i < count; i++)
      {
        templateValue.append("_");
        templateValue.getValue().append(dn.rdn(i));
      }
    }
    else
    {
      int sz = dn.size();
      int count = Math.min(Math.abs(numComponents), sz);
      templateValue.getValue().append(dn.rdn(sz - count));
      for (int i = 1; i < count; i++) {
        templateValue.append("_");
        templateValue.getValue().append(dn.rdn(sz - count + i));
      }
    }
    return TagResult.SUCCESS_RESULT;
  }
}
opendj-server-legacy/src/main/java/org/opends/server/tools/makeldif/UnderscoreParentDNTag.java
@@ -20,6 +20,7 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.util.Utils;
import org.opends.server.types.InitializationException;
import static org.opends.messages.ToolMessages.*;
@@ -68,18 +69,10 @@
                                 TemplateValue templateValue)
  {
    DN parentDN = templateEntry.getParentDN();
    if (parentDN == null || parentDN.isRootDN())
    if (parentDN != null && !parentDN.isRootDN())
    {
      return TagResult.SUCCESS_RESULT;
      Utils.joinAsString(templateValue.getValue(), "_", parentDN);
    }
    templateValue.getValue().append(parentDN.rdn(0));
    for (int i=1; i < parentDN.size(); i++)
    {
      templateValue.append("_");
      templateValue.getValue().append(parentDN.rdn(i));
    }
    return TagResult.SUCCESS_RESULT;
  }
}
opendj-server-legacy/src/main/java/org/opends/server/types/SearchFilter.java
@@ -38,7 +38,6 @@
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.forgerock.opendj.ldap.ConditionResult;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.RDN;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.schema.AttributeType;
opendj-server-legacy/src/test/java/org/opends/server/types/TestDN.java
@@ -166,68 +166,6 @@
    DirectoryServer.getSchema().registerAttributeType(dummy, true);
  }
  /**
   * Tests the create method.
   *
   * @throws Exception
   *           If the test failed unexpectedly.
   */
  @Test
  public void testCreateNullDN1() throws Exception {
    DN dn = new DN(new RDN[0]);
    assertEquals(dn, DN.rootDN());
  }
  /**
   * Tests the create method.
   *
   * @throws Exception
   *           If the test failed unexpectedly.
   */
  @Test
  public void testCreateNullDN2() throws Exception {
    DN dn = new DN();
    assertEquals(dn, DN.rootDN());
  }
  /**
   * Tests the create method.
   *
   * @throws Exception
   *           If the test failed unexpectedly.
   */
  @Test
  public void testCreateNullDN3() throws Exception {
    DN dn = new DN((RDN[]) null);
    assertEquals(dn, DN.rootDN());
  }
  /**
   * Tests the create method.
   *
   * @throws Exception
   *           If the test failed unexpectedly.
   */
  @Test
  public void testCreateNullDN4() throws Exception {
    DN dn = new DN((ArrayList<RDN>) null);
    assertEquals(dn, DN.rootDN());
  }
  /**
   * Tests the create method.
   *
@@ -236,8 +174,7 @@
   */
  @Test
  public void testCreateWithSingleRDN1() throws Exception {
    DN dn = new DN(new RDN[] { RDN.valueOf("dc=com") });
    DN dn = DN.rootDN().child(RDN.valueOf("dc=com"));
    assertEquals(dn, DN.valueOf("dc=com"));
  }
@@ -251,9 +188,7 @@
   */
  @Test
  public void testCreateWithMultipleRDNs1() throws Exception {
    DN dn = new DN(new RDN[] { RDN.valueOf("dc=foo"),
        RDN.valueOf("dc=opends"), RDN.valueOf("dc=org") });
    DN dn = DN.rootDN().child(RDN.valueOf("dc=org")).child(RDN.valueOf("dc=opends")).child(RDN.valueOf("dc=foo"));
    assertEquals(dn, DN.valueOf("dc=foo,dc=opends,dc=org"));
  }