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

Jean-Noel Rouvignac
19.09.2014 1bac1f37201cd12e5c70c6fa0139074bc42dcab1
StaticUtils.java:
Extracted methods addAttributeValue() and getObjectClassName().
1 files modified
113 ■■■■■ changed files
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/StaticUtils.java 113 ●●●●● patch | view | raw | blame | history
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/StaticUtils.java
@@ -3610,42 +3610,8 @@
    RDN rdn = dn.rdn();
    int numAVAs = rdn.getNumValues();
    // If there is only one RDN attribute, then see which objectclass we should
    // use.
    ObjectClass structuralClass;
    if (numAVAs == 1)
    {
      AttributeType attrType = rdn.getAttributeType(0);
      if (attrType.hasName(ATTR_C))
      {
        structuralClass = DirectoryServer.getObjectClass(OC_COUNTRY, true);
      }
      else if (attrType.hasName(ATTR_DC))
      {
        structuralClass = DirectoryServer.getObjectClass(OC_DOMAIN, true);
      }
      else if (attrType.hasName(ATTR_O))
      {
        structuralClass = DirectoryServer.getObjectClass(OC_ORGANIZATION, true);
      }
      else if (attrType.hasName(ATTR_OU))
      {
        structuralClass =
             DirectoryServer.getObjectClass(OC_ORGANIZATIONAL_UNIT_LC, true);
      }
      else
      {
        structuralClass =
             DirectoryServer.getObjectClass(OC_UNTYPED_OBJECT_LC, true);
      }
    }
    else
    {
      structuralClass =
           DirectoryServer.getObjectClass(OC_UNTYPED_OBJECT_LC, true);
    }
    // If there is only one RDN attribute, then see which objectclass we should use.
    ObjectClass structuralClass = DirectoryServer.getObjectClass(getObjectClassName(rdn, numAVAs));
    // Get the top and untypedObject classes to include in the entry.
    LinkedHashMap<ObjectClass,String> objectClasses =
@@ -3689,39 +3655,11 @@
      // Create the attribute and add it to the appropriate map.
      if (attrType.isOperational())
      {
        List<Attribute> attrList = operationalAttributes.get(attrType);
        if ((attrList == null) || attrList.isEmpty())
        {
          AttributeBuilder builder = new AttributeBuilder(attrType, attrName);
          builder.add(attrValue);
          attrList = new ArrayList<Attribute>(1);
          attrList.add(builder.toAttribute());
          operationalAttributes.put(attrType, attrList);
        }
        else
        {
          AttributeBuilder builder = new AttributeBuilder(attrList.get(0));
          builder.add(attrValue);
          attrList.set(0, builder.toAttribute());
        }
        addAttributeValue(operationalAttributes, attrType, attrName, attrValue);
      }
      else
      {
        List<Attribute> attrList = userAttributes.get(attrType);
        if ((attrList == null) || attrList.isEmpty())
        {
          AttributeBuilder builder = new AttributeBuilder(attrType, attrName);
          builder.add(attrValue);
          attrList = new ArrayList<Attribute>(1);
          attrList.add(builder.toAttribute());
          userAttributes.put(attrType, attrList);
        }
        else
        {
          AttributeBuilder builder = new AttributeBuilder(attrList.get(0));
          builder.add(attrValue);
          attrList.set(0, builder.toAttribute());
        }
        addAttributeValue(userAttributes, attrType, attrName, attrValue);
      }
    }
@@ -3730,7 +3668,50 @@
    return new Entry(dn, objectClasses, userAttributes, operationalAttributes);
  }
  private static String getObjectClassName(RDN rdn, int numAVAs)
  {
    if (numAVAs == 1)
    {
      final AttributeType attrType = rdn.getAttributeType(0);
      if (attrType.hasName(ATTR_C))
      {
        return OC_COUNTRY;
      }
      else if (attrType.hasName(ATTR_DC))
      {
        return OC_DOMAIN;
      }
      else if (attrType.hasName(ATTR_O))
      {
        return OC_ORGANIZATION;
      }
      else if (attrType.hasName(ATTR_OU))
      {
        return OC_ORGANIZATIONAL_UNIT_LC;
      }
    }
    return OC_UNTYPED_OBJECT_LC;
  }
  private static void addAttributeValue(LinkedHashMap<AttributeType, List<Attribute>> attrs,
      AttributeType attrType, String attrName, ByteString attrValue)
  {
    List<Attribute> attrList = attrs.get(attrType);
    if ((attrList == null) || attrList.isEmpty())
    {
      AttributeBuilder builder = new AttributeBuilder(attrType, attrName);
      builder.add(attrValue);
      attrList = new ArrayList<Attribute>(1);
      attrList.add(builder.toAttribute());
      attrs.put(attrType, attrList);
    }
    else
    {
      AttributeBuilder builder = new AttributeBuilder(attrList.get(0));
      builder.add(attrValue);
      attrList.set(0, builder.toAttribute());
    }
  }
  /**
   * Retrieves a user-friendly string that indicates the length of time (in