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

ludovicp
15.55.2010 5933e18c3cd0a65c5179752da2413e4eab3b897c
Add RDN attributes if missing in entry during the import.
2 files modified
110 ■■■■■ changed files
opends/src/server/org/opends/server/util/LDIFReader.java 104 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestImportJob.java 6 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/LDIFReader.java
@@ -411,6 +411,12 @@
      // appropriate to do so.
      if (checkSchema)
      {
        //Add the RDN attributes.
        addRDNAttributesIfNecessary(entryDN,userAttributes,
                operationalAttributes);
        //Add any superior objectclass(s) missing in the objectclass map.
        addSuperiorObjectClasses(objectClasses);
        MessageBuilder invalidReason = new MessageBuilder();
        if (! entry.conformsToSchema(null, false, true, false, invalidReason))
        {
@@ -423,9 +429,6 @@
          suffix.removePending(entryDN);
          continue;
        }
         //Add any superior objectclass(s) missing in an entries
        //objectclass map.
        addSuperiorObjectClasses(entry.getObjectClasses());
      }
      entryInfo.setEntryID(entryID);
      entryInfo.setSuffix(suffix);
@@ -2361,5 +2364,100 @@
      attrList.add(builder.toAttribute());
    }
  }
  /**
   * Adds any missing RDN attributes to the entry that is being imported.
   */
  private void addRDNAttributesIfNecessary(DN entryDN,
          HashMap<AttributeType,List<Attribute>>userAttributes,
          HashMap<AttributeType,List<Attribute>> operationalAttributes)
  {
    RDN rdn = entryDN.getRDN();
    int numAVAs = rdn.getNumValues();
    for (int i=0; i < numAVAs; i++)
    {
      AttributeType  t = rdn.getAttributeType(i);
      AttributeValue v = rdn.getAttributeValue(i);
      String         n = rdn.getAttributeName(i);
      if (t.isOperational())
      {
        List<Attribute> attrList = operationalAttributes.get(t);
        if (attrList == null)
        {
          attrList = new ArrayList<Attribute>();
          attrList.add(Attributes.create(t, n, v));
          operationalAttributes.put(t, attrList);
        }
        else
        {
          boolean found = false;
          for (int j = 0; j < attrList.size(); j++)
          {
            Attribute a = attrList.get(j);
            if (a.hasOptions())
            {
              continue;
            }
            if (!a.contains(v))
            {
              AttributeBuilder builder = new AttributeBuilder(a);
              builder.add(v);
              attrList.set(j, builder.toAttribute());
            }
            found = true;
            break;
          }
          if (!found)
          {
            attrList.add(Attributes.create(t, n, v));
          }
        }
      }
      else
      {
        List<Attribute> attrList = userAttributes.get(t);
        if (attrList == null)
        {
          attrList = new ArrayList<Attribute>();
          attrList.add(Attributes.create(t, n, v));
          userAttributes.put(t, attrList);
        }
        else
        {
          boolean found = false;
          for (int j = 0; j < attrList.size(); j++)
          {
            Attribute a = attrList.get(j);
            if (a.hasOptions())
            {
              continue;
            }
            if (!a.contains(v))
            {
              AttributeBuilder builder = new AttributeBuilder(a);
              builder.add(v);
              attrList.set(j, builder.toAttribute());
            }
            found = true;
            break;
          }
          if (!found)
          {
            attrList.add(Attributes.create(t, n, v));
          }
        }
      }
    }
  }
}
opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestImportJob.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 */
package org.opends.server.backends.jeb;
@@ -59,7 +59,7 @@
  private String top = "dn: dc=importtest,dc=com\n" +
      "objectclass: top\n" +
      "objectclass: domain\n" +
      "dc: example\n" +
      "dc: importtest\n" +
      "\n" +
      "dn: ou=People,dc=importtest,dc=com\n" +
      "objectclass: top\n" +
@@ -74,7 +74,7 @@
      "dn: dc=importtest1,dc=com\n" +
      "objectclass: top\n" +
      "objectclass: domain\n" +
      "dc: example1\n";
      "dc: importtest1\n";
  private String entries1 =
      "dn: uid=user.0,ou=People,dc=importtest,dc=com\n" +
      "objectClass: top\n" +