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

Jean-Noël Rouvignac
30.14.2016 110ff48cb0c18fb2bd636c49d16f9e64a7deae28
Code cleanups
3 files modified
88 ■■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java 42 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java 30 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/workflowelement/localbackend/LocalBackendModifyOperation.java 16 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java
@@ -1050,10 +1050,11 @@
   */
  public void incrementAttribute(Attribute attribute) throws DirectoryException
  {
    Attribute a = getExactAttribute(attribute.getAttributeDescription());
    AttributeDescription attrDesc = attribute.getAttributeDescription();
    Attribute a = getExactAttribute(attrDesc);
    if (a == null)
    {
      LocalizableMessage message = ERR_ENTRY_INCREMENT_NO_SUCH_ATTRIBUTE.get(attribute.getAttributeDescription());
      LocalizableMessage message = ERR_ENTRY_INCREMENT_NO_SUCH_ATTRIBUTE.get(attrDesc);
      throw new DirectoryException(ResultCode.NO_SUCH_ATTRIBUTE, message);
    }
@@ -1061,25 +1062,24 @@
    Iterator<ByteString> i = attribute.iterator();
    if (!i.hasNext())
    {
      LocalizableMessage message = ERR_ENTRY_INCREMENT_INVALID_VALUE_COUNT.get(attribute.getAttributeDescription());
      LocalizableMessage message = ERR_ENTRY_INCREMENT_INVALID_VALUE_COUNT.get(attrDesc);
      throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message);
    }
    String incrementValue = i.next().toString();
    long increment = parseLong(incrementValue, attribute);
    long increment = parseLong(incrementValue, attrDesc);
    if (i.hasNext())
    {
      LocalizableMessage message = ERR_ENTRY_INCREMENT_INVALID_VALUE_COUNT.get(attribute.getAttributeDescription());
      LocalizableMessage message = ERR_ENTRY_INCREMENT_INVALID_VALUE_COUNT.get(attrDesc);
      throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message);
    }
    // Increment each attribute value by the specified amount.
    AttributeBuilder builder = new AttributeBuilder(a.getAttributeDescription());
    for (ByteString v : a)
    {
      long currentValue = parseLong(v.toString(), attribute);
      long currentValue = parseLong(v.toString(), attrDesc);
      long newValue = currentValue + increment;
      builder.add(String.valueOf(newValue));
    }
@@ -1087,7 +1087,7 @@
    replaceAttribute(builder.toAttribute());
  }
  private long parseLong(String value, Attribute attribute) throws DirectoryException
  private long parseLong(String value, AttributeDescription attrDesc) throws DirectoryException
  {
    try
    {
@@ -1095,12 +1095,11 @@
    }
    catch (NumberFormatException e)
    {
      LocalizableMessage message = ERR_ENTRY_INCREMENT_CANNOT_PARSE_AS_INT.get(attribute.getAttributeDescription());
      LocalizableMessage message = ERR_ENTRY_INCREMENT_CANNOT_PARSE_AS_INT.get(attrDesc);
      throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, message);
    }
  }
  /**
   * Removes all instances of the specified attribute type from this
   * entry, including any instances with options. If the provided
@@ -1329,9 +1328,7 @@
  public void applyModification(Modification mod, boolean relaxConstraints)
         throws DirectoryException
  {
    Attribute     a = mod.getAttribute();
    AttributeType t = a.getAttributeDescription().getAttributeType();
    AttributeType t = mod.getAttribute().getAttributeDescription().getAttributeType();
    if (t.isObjectClass())
    {
      applyModificationToObjectclass(mod, relaxConstraints);
@@ -1355,6 +1352,7 @@
      ocs.put(oc, ocName);
    }
    AttributeDescription attrDesc = a.getAttributeDescription();
    switch (mod.getModificationType().asEnum())
    {
    case ADD:
@@ -1364,7 +1362,7 @@
        {
          if (!relaxConstraints)
          {
            LocalizableMessage message = ERR_ENTRY_DUPLICATE_VALUES.get(a.getAttributeDescription());
            LocalizableMessage message = ERR_ENTRY_DUPLICATE_VALUES.get(attrDesc);
            throw new DirectoryException(ATTRIBUTE_OR_VALUE_EXISTS, message);
          }
        }
@@ -1381,7 +1379,7 @@
      {
        if (objectClasses.remove(oc) == null && !relaxConstraints)
        {
          LocalizableMessage message = ERR_ENTRY_NO_SUCH_VALUE.get(a.getAttributeDescription());
          LocalizableMessage message = ERR_ENTRY_NO_SUCH_VALUE.get(attrDesc);
          throw new DirectoryException(NO_SUCH_ATTRIBUTE, message);
        }
      }
@@ -3526,11 +3524,12 @@
        }
        // Decode the attribute.
        Attribute a = config.getCompressedSchema().decodeAttribute(entryBuffer);
        List<Attribute> attrList = attributes.get(a.getAttributeDescription().getAttributeType());
        AttributeType attrType = a.getAttributeDescription().getAttributeType();
        List<Attribute> attrList = attributes.get(attrType);
        if (attrList == null)
        {
          attrList = new ArrayList<>(1);
          attributes.put(a.getAttributeDescription().getAttributeType(), attrList);
          attributes.put(attrType, attrList);
        }
        attrList.add(a);
      }
@@ -4523,8 +4522,7 @@
      {
        continue;
      }
      else
      {
        // If a non-default attribute name was provided or if the
        // attribute has options then we will need to rebuild the
        // attribute so that it contains the user-requested names and options.
@@ -4547,19 +4545,16 @@
          {
            newAttrDesc = AttributeDescription.create(attrName, subAttrDesc.getAttributeType());
          }
          AttributeBuilder builder = new AttributeBuilder(newAttrDesc);
          builder.setOptions(attrDesc.getOptions());
          // Now add in remaining options from original attribute
          // (this will not overwrite options already present).
          builder.setOptions(subAttrDesc.getOptions());
          if (!omitValues)
          {
            builder.addAll(attribute);
          }
          attribute = builder.toAttribute();
        }
        else if (omitValues)
@@ -4613,4 +4608,3 @@
      }
    }
  }
}
opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java
@@ -770,25 +770,20 @@
  {
    // Parse the attribute type description.
    int colonPos = parseColonPosition(lines, line);
    String attrDescr = line.substring(0, colonPos);
    final AttributeDescription attrDesc = parseAttrDescription(attrDescr);
    String attrDescStr = line.substring(0, colonPos);
    final AttributeDescription attrDesc = parseAttrDescription(attrDescStr);
    final AttributeType attrType = attrDesc.getAttributeType();
    final String attrName = attrType.getNameOrOID();
    // Now parse the attribute value.
    ByteString value = parseSingleValue(lines, line, entryDN, colonPos, attrName);
    ByteString value = parseSingleValue(lines, line, entryDN, colonPos, attrDescStr);
    // See if this is an objectclass or an attribute.  Then get the
    // corresponding definition and add the value to the appropriate hash.
    if (attrName.equalsIgnoreCase("objectclass"))
    if (attrType.isObjectClass())
    {
      if (! importConfig.includeObjectClasses())
      {
        if (logger.isTraceEnabled())
        {
          logger.trace("Skipping objectclass %s for entry %s due to " +
              "the import configuration.", value, entryDN);
        }
        logger.trace("Skipping objectclass %s for entry %s due to the import configuration.", value, entryDN);
        return;
      }
@@ -814,11 +809,7 @@
    {
      if (! importConfig.includeAttribute(attrType))
      {
        if (logger.isTraceEnabled())
        {
          logger.trace("Skipping attribute %s for entry %s due to the " +
              "import configuration.", attrName, entryDN);
        }
        logger.trace("Skipping attribute %s for entry %s due to the import configuration.", attrDescStr, entryDN);
        return;
      }
@@ -827,8 +818,7 @@
          && !attrType.getSyntax().isBEREncodingRequired()
 && attrDesc.hasOption("binary"))
      {
        LocalizableMessage message = ERR_LDIF_INVALID_ATTR_OPTION.get(
          entryDN, lastEntryLineNumber, attrName);
        LocalizableMessage message = ERR_LDIF_INVALID_ATTR_OPTION.get(entryDN, lastEntryLineNumber, attrDescStr);
        logToRejectWriter(lines, message);
        throw new LDIFException(message, lastEntryLineNumber,true);
      }
@@ -839,7 +829,7 @@
        if (! attrType.getSyntax().valueIsAcceptable(value, invalidReason))
        {
          LocalizableMessage message = WARN_LDIF_VALUE_VIOLATES_SYNTAX.get(
              entryDN, lastEntryLineNumber, value, attrName, invalidReason);
              entryDN, lastEntryLineNumber, value, attrDescStr, invalidReason);
          if (DirectoryServer.getSyntaxEnforcementPolicy() == AcceptRejectWarn.WARN)
          {
            logger.error(message);
@@ -881,14 +871,14 @@
          if (!a.add(attributeValue) && checkSchema)
          {
              LocalizableMessage message = WARN_LDIF_DUPLICATE_ATTR.get(
                  entryDN, lastEntryLineNumber, attrName, value);
                  entryDN, lastEntryLineNumber, attrDescStr, value);
              logToRejectWriter(lines, message);
            throw new LDIFException(message, lastEntryLineNumber, true);
          }
          if (attrType.isSingleValue() && a.size() > 1 && checkSchema)
          {
            LocalizableMessage message = ERR_LDIF_MULTIPLE_VALUES_FOR_SINGLE_VALUED_ATTR
                    .get(entryDN, lastEntryLineNumber, attrName);
                    .get(entryDN, lastEntryLineNumber, attrDescStr);
            logToRejectWriter(lines, message);
            throw new LDIFException(message, lastEntryLineNumber, true);
          }
opendj-server-legacy/src/main/java/org/opends/server/workflowelement/localbackend/LocalBackendModifyOperation.java
@@ -1015,7 +1015,8 @@
      numPasswords = 0;
    }
    AttributeBuilder builder = new AttributeBuilder(pwAttr.getAttributeDescription());
    AttributeDescription pwdAttrDesc = pwAttr.getAttributeDescription();
    AttributeBuilder builder = new AttributeBuilder(pwdAttrDesc);
    for (ByteString v : pwAttr)
    {
      if (pwPolicyState.passwordIsPreEncoded(v))
@@ -1029,7 +1030,7 @@
        // We still need to check if the pre-encoded password matches
        // an existing value, to decrease the number of passwords.
        List<Attribute> attrList = currentEntry.getAttribute(pwAttr.getAttributeDescription().getAttributeType());
        List<Attribute> attrList = currentEntry.getAttribute(pwdAttrDesc.getAttributeType());
        if (attrList.isEmpty())
        {
          throw new DirectoryException(ResultCode.NO_SUCH_ATTRIBUTE, ERR_MODIFY_NO_EXISTING_VALUES.get());
@@ -1042,7 +1043,7 @@
      }
      else
      {
        List<Attribute> attrList = currentEntry.getAttribute(pwAttr.getAttributeDescription().getAttributeType());
        List<Attribute> attrList = currentEntry.getAttribute(pwdAttrDesc.getAttributeType());
        if (attrList.isEmpty())
        {
          throw new DirectoryException(ResultCode.NO_SUCH_ATTRIBUTE, ERR_MODIFY_NO_EXISTING_VALUES.get());
@@ -1341,7 +1342,9 @@
    // If the attribute to be replaced is the object class attribute
    // then make sure that all the object classes are known and not obsoleted.
    if (attr.getAttributeDescription().getAttributeType().isObjectClass())
    AttributeDescription attrDesc = attr.getAttributeDescription();
    AttributeType t = attrDesc.getAttributeType();
    if (t.isObjectClass())
    {
      validateObjectClasses(attr);
    }
@@ -1350,14 +1353,13 @@
    modifiedEntry.replaceAttribute(attr);
    // Make sure that the RDN attribute value(s) has not been removed.
    AttributeType t = attr.getAttributeDescription().getAttributeType();
    RDN rdn = modifiedEntry.getName().rdn();
    if (rdn != null
        && rdn.hasAttributeType(t)
        && !modifiedEntry.hasValue(attr.getAttributeDescription(), rdn.getAttributeValue(t)))
        && !modifiedEntry.hasValue(attrDesc, rdn.getAttributeValue(t)))
    {
      throw newDirectoryException(modifiedEntry, ResultCode.NOT_ALLOWED_ON_RDN,
          ERR_MODIFY_DELETE_RDN_ATTR.get(entryDN, attr.getAttributeDescription()));
          ERR_MODIFY_DELETE_RDN_ATTR.get(entryDN, attrDesc));
    }
  }