From 8c2fb347d05648fa8e6ee41abc86cc658b8a3f70 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 27 May 2016 12:31:05 +0000
Subject: [PATCH] OPENDJ-2797 When adding matching rule use, also set their schema file

---
 opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java   |   35 -----------------
 opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java |   10 ++--
 opendj-server-legacy/src/main/java/org/opends/server/types/DirectoryConfig.java  |   16 --------
 opendj-server-legacy/src/main/java/org/opends/server/types/Schema.java           |   34 +++++++++--------
 4 files changed, 23 insertions(+), 72 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 28fdbfb..040e678 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
@@ -2441,15 +2441,15 @@
     // Otherwise, we're replacing an existing matching rule use.
     if (existingMRU == null)
     {
-      schema.registerMatchingRuleUse(matchingRuleUse, false);
-      addNewSchemaElement(modifiedSchemaFiles, new ServerSchemaElement(matchingRuleUse));
+      String schemaFile = addNewSchemaElement(modifiedSchemaFiles, new ServerSchemaElement(matchingRuleUse));
+      schema.registerMatchingRuleUse(matchingRuleUse, schemaFile, false);
     }
     else
     {
       schema.deregisterMatchingRuleUse(existingMRU);
-      schema.registerMatchingRuleUse(matchingRuleUse, false);
-      replaceExistingSchemaElement(modifiedSchemaFiles, new ServerSchemaElement(matchingRuleUse),
-          new ServerSchemaElement(existingMRU));
+      String schemaFile = replaceExistingSchemaElement(
+          modifiedSchemaFiles, new ServerSchemaElement(matchingRuleUse), new ServerSchemaElement(existingMRU));
+      schema.registerMatchingRuleUse(matchingRuleUse, schemaFile, false);
     }
   }
 
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java b/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
index fc9ccac..1c8b1f9 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
@@ -2707,41 +2707,6 @@
   }
 
   /**
-   * Registers the provided matching rule use with the Directory Server.
-   *
-   * @param  matchingRuleUse    The matching rule use to register with the
-   *                            server.
-   * @param  overwriteExisting  Indicates whether to overwrite an existing
-   *                            mapping if there are any conflicts (i.e.,
-   *                            another matching rule use with the same matching
-   *                            rule).
-   *
-   * @throws  DirectoryException  If a conflict is encountered and the
-   *                              <CODE>overwriteExisting</CODE> flag is set to
-   *                              <CODE>false</CODE>
-   */
-  public static void registerMatchingRuleUse(MatchingRuleUse matchingRuleUse,
-                                             boolean overwriteExisting)
-         throws DirectoryException
-  {
-    directoryServer.schema.registerMatchingRuleUse(matchingRuleUse,
-                                                   overwriteExisting);
-  }
-
-  /**
-   * Deregisters the provided matching rule use with the Directory Server.
-   *
-   * @param  matchingRuleUse  The matching rule use to deregister with the
-   *                          server.
-   * @throws DirectoryException
-   *            If the resulting schema contains warning.
-   */
-  public static void deregisterMatchingRuleUse(MatchingRuleUse matchingRuleUse) throws DirectoryException
-  {
-    directoryServer.schema.deregisterMatchingRuleUse(matchingRuleUse);
-  }
-
-  /**
    * Retrieves the DIT content rule associated with the specified objectclass.
    *
    * @param  objectClass  The objectclass for which to retrieve the associated
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/DirectoryConfig.java b/opendj-server-legacy/src/main/java/org/opends/server/types/DirectoryConfig.java
index f06eabb..3e6ece7 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/DirectoryConfig.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/DirectoryConfig.java
@@ -349,22 +349,6 @@
   }
 
   /**
-   * Retrieves the matching rule use associated with the provided
-   * matching rule.
-   *
-   * @param  matchingRule  The matching rule for which to retrieve the
-   *                       matching rule use.
-   *
-   * @return  The matching rule use for the provided matching rule, or
-   *          <CODE>null</CODE> if none is defined.
-   */
-  public static MatchingRuleUse
-       getMatchingRuleUse(MatchingRule matchingRule)
-  {
-    return DirectoryServer.getMatchingRuleUse(matchingRule);
-  }
-
-  /**
    * Retrieves the DIT content rule associated with the specified
    * objectclass.
    *
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 8866d73..ed9e182 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
@@ -1211,31 +1211,33 @@
     return schemaNG.getMatchingRuleUse(matchingRule);
   }
 
-
-
   /**
-   * Registers the provided matching rule use definition with this
-   * schema.
+   * Registers the provided matching rule use definition with this schema.
    *
-   * @param  matchingRuleUse    The matching rule use definition to
-   *                            register.
-   * @param  overwriteExisting  Indicates whether to overwrite an
-   *                            existing mapping if there are any
-   *                            conflicts (i.e., another matching rule
-   *                            use with the same matching rule).
-   *
-   * @throws  DirectoryException  If a conflict is encountered and the
-   *                              <CODE>overwriteExisting</CODE> flag
-   *                              is set to <CODE>false</CODE>
+   * @param matchingRuleUse
+   *          The matching rule use definition to register.
+   * @param schemaFile
+   *          The schema file where this definition belongs, maybe {@code null}
+   * @param overwriteExisting
+   *          Indicates whether to overwrite an existing mapping if there are any conflicts (i.e.,
+   *          another matching rule use with the same matching rule).
+   * @throws DirectoryException
+   *           If a conflict is encountered and the {@code overwriteExisting} flag is set to
+   *           {@code false}
    */
-  public void registerMatchingRuleUse(MatchingRuleUse matchingRuleUse, boolean overwriteExisting)
-         throws DirectoryException
+  public void registerMatchingRuleUse(MatchingRuleUse matchingRuleUse, String schemaFile, boolean overwriteExisting)
+      throws DirectoryException
   {
     exclusiveLock.lock();
     try
     {
       SchemaBuilder builder = new SchemaBuilder(schemaNG);
       Builder mruBuilder = builder.buildMatchingRuleUse(matchingRuleUse);
+      if (schemaFile != null)
+      {
+        mruBuilder.removeExtraProperty(SCHEMA_PROPERTY_FILENAME)
+                  .extraProperties(SCHEMA_PROPERTY_FILENAME, schemaFile);
+      }
       if (overwriteExisting)
       {
         mruBuilder.addToSchemaOverwrite();

--
Gitblit v1.10.0