From b5f211cba2660529048afc4ebd37b1903c3ea4ac Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Mon, 30 May 2016 10:43:12 +0000
Subject: [PATCH] OPENDJ-2987 Use OID instead of full ObjectClass to detect multiple updates of the same objectclass in a modification

---
 opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java |   16 ++++++----------
 opendj-server-legacy/src/main/java/org/opends/server/types/Schema.java           |   25 ++++++++++++++++---------
 opendj-server-legacy/src/messages/org/opends/messages/schema.properties          |   10 +++++++++-
 3 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
index 71d7996..baa74a6 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
@@ -1587,22 +1587,18 @@
 
       for (ByteString v : a)
       {
-        ObjectClass oc;
+        String oid;
         try
         {
-          oc = schema.parseObjectClass(v.toString());
+          oid = schema.parseOID(v.toString(), ResultCode.INVALID_ATTRIBUTE_SYNTAX, ERR_PARSING_OBJECTCLASS_OID);
         }
         catch (DirectoryException de)
         {
           logger.traceException(de);
-
-          LocalizableMessage message = ERR_SCHEMA_MODIFY_CANNOT_DECODE_OBJECTCLASS.get(
-              v, de.getMessageObject());
-          throw new DirectoryException(
-                         ResultCode.INVALID_ATTRIBUTE_SYNTAX, message, de);
+          throw de;
         }
 
-        if (objectClass.getOID().equals(oc.getOID()))
+        if (objectClass.getOID().equals(oid))
         {
           // We found a match where the objectClass is added back later, so we
           // don't need to do anything else here.
@@ -2492,7 +2488,7 @@
   {
     // Check if there is an existing syntax with this oid.
     String oid =
-        Schema.parseOID(definition, ResultCode.INVALID_ATTRIBUTE_SYNTAX, ERR_ATTR_SYNTAX_LDAPSYNTAX_EMPTY_VALUE);
+        Schema.parseOID(definition, ResultCode.INVALID_ATTRIBUTE_SYNTAX, ERR_PARSING_LDAP_SYNTAX_OID);
 
     // We allow only unimplemented syntaxes to be substituted.
     if (schema.hasSyntax(oid))
@@ -2547,7 +2543,7 @@
      * hence never deleted.
      */
     String oid =
-        Schema.parseOID(definition, ResultCode.INVALID_ATTRIBUTE_SYNTAX, ERR_ATTR_SYNTAX_LDAPSYNTAX_EMPTY_VALUE);
+        Schema.parseOID(definition, ResultCode.INVALID_ATTRIBUTE_SYNTAX, ERR_PARSING_LDAP_SYNTAX_OID);
 
     LDAPSyntaxDescription removeLSD = schema.getLdapSyntaxDescription(oid);
     if (removeLSD == null)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/Schema.java b/opendj-server-legacy/src/main/java/org/opends/server/types/Schema.java
index c04aeea..c3995fb 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/Schema.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/Schema.java
@@ -16,8 +16,6 @@
  */
 package org.opends.server.types;
 
-import static org.opends.messages.SchemaMessages.ERR_ATTR_SYNTAX_MRUSE_EMPTY_VALUE;
-
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.File;
@@ -42,7 +40,7 @@
 import java.util.concurrent.locks.ReentrantLock;
 
 import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.i18n.LocalizableMessageDescriptor.Arg0;
+import org.forgerock.i18n.LocalizableMessageDescriptor.Arg1;
 import org.forgerock.i18n.LocalizedIllegalArgumentException;
 import org.forgerock.i18n.slf4j.LocalizedLogger;
 import org.forgerock.opendj.ldap.AttributeDescription;
@@ -507,19 +505,28 @@
     }
   }
 
-  private String parseObjectClassOID(String definition) throws DirectoryException
+  /**
+   * Retrieves the OID of the provided object class definition.
+   *
+   * @param definition
+   *            Definition of an object class.
+   * @return the OID of the object class
+   * @throws DirectoryException
+   *            If the definition couldn't be parsed.
+   */
+  public String parseObjectClassOID(String definition) throws DirectoryException
   {
-    return parseOID(definition, ResultCode.INVALID_ATTRIBUTE_SYNTAX, ERR_ATTR_SYNTAX_OBJECTCLASS_EMPTY_VALUE);
+    return parseOID(definition, ResultCode.INVALID_ATTRIBUTE_SYNTAX, ERR_PARSING_OBJECTCLASS_OID);
   }
 
   private String parseAttributeTypeOID(String definition) throws DirectoryException
   {
-    return parseOID(definition, ResultCode.INVALID_ATTRIBUTE_SYNTAX, ERR_ATTR_SYNTAX_ATTRTYPE_EMPTY_VALUE);
+    return parseOID(definition, ResultCode.INVALID_ATTRIBUTE_SYNTAX, ERR_PARSING_ATTRIBUTE_TYPE_OID);
   }
 
   private String parseMatchingRuleUseOID(String definition) throws DirectoryException
   {
-    return parseOID(definition, ResultCode.INVALID_ATTRIBUTE_SYNTAX, ERR_ATTR_SYNTAX_MRUSE_EMPTY_VALUE);
+    return parseOID(definition, ResultCode.INVALID_ATTRIBUTE_SYNTAX, ERR_PARSING_MATCHING_RULE_USE_OID);
   }
 
   /**
@@ -536,7 +543,7 @@
    * @throws DirectoryException
    *           If a problem occurs while parsing the definition
    */
-  public static String parseOID(String definition, ResultCode parsingErrorResultCode, Arg0 parsingErrorMsg)
+  public static String parseOID(String definition, ResultCode parsingErrorResultCode, Arg1<Object> parsingErrorMsg)
       throws DirectoryException
   {
     try
@@ -565,7 +572,7 @@
     }
     catch (IndexOutOfBoundsException e)
     {
-      throw new DirectoryException(parsingErrorResultCode, parsingErrorMsg.get(), e);
+      throw new DirectoryException(parsingErrorResultCode, parsingErrorMsg.get(definition), e);
     }
   }
 
diff --git a/opendj-server-legacy/src/messages/org/opends/messages/schema.properties b/opendj-server-legacy/src/messages/org/opends/messages/schema.properties
index b6a1466..fac37e2 100644
--- a/opendj-server-legacy/src/messages/org/opends/messages/schema.properties
+++ b/opendj-server-legacy/src/messages/org/opends/messages/schema.properties
@@ -501,4 +501,12 @@
 ERR_MATCHING_RULE_USE_CANNOT_REGISTER_342=Matching rule use could not be \
  registered from definition: %s
 ERR_OBJECT_CLASS_CANNOT_REGISTER_343=Object class could not be \
- registered from definition: %s
\ No newline at end of file
+ registered from definition: %s
+ERR_PARSING_OBJECTCLASS_OID_344=Unable to parse the OID from the provided definition \
+ of objectclass: '%s'
+ERR_PARSING_ATTRIBUTE_TYPE_OID_345=Unable to parse the OID from the provided definition \
+ of attribute type: '%s'
+ERR_PARSING_LDAP_SYNTAX_OID_346=Unable to parse the OID from the provided definition \
+ of ldap syntax: '%s'
+ERR_PARSING_MATCHING_RULE_USE_OID_347=Unable to parse the OID from the provided definition \
+ of matching rule use: '%s' 

--
Gitblit v1.10.0