From 5984af9f0c6c5f852bc3292d981e0854f44ae802 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Wed, 29 Jun 2016 12:25:42 +0000
Subject: [PATCH] OPENDJ-3173 Upgrade task for new HTTP configuration model

---
 opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java |   42 +++++++++++++++++++++++++++++++++++++++---
 1 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java
index 0a5a90c..c00053b 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java
@@ -23,7 +23,7 @@
 
 import static org.forgerock.util.Utils.joinAsString;
 import static org.opends.messages.ToolMessages.*;
-import static org.opends.server.tools.upgrade.FileManager.copy;
+import static org.opends.server.tools.upgrade.FileManager.copyRecursively;
 import static org.opends.server.tools.upgrade.UpgradeUtils.*;
 import static org.opends.server.types.Schema.*;
 import static org.opends.server.util.StaticUtils.*;
@@ -115,6 +115,42 @@
   }
 
   /**
+   * Returns a new upgrade task which adds a config entry to the underlying
+   * config file. No summary message will be output.
+   *
+   * @param ldif
+   *          The LDIF record which will be applied to matching entries.
+   * @return A new upgrade task which applies an LDIF record to all
+   *         configuration entries matching the provided filter.
+   */
+  public static UpgradeTask addConfigEntry(final String... ldif)
+  {
+    return new AbstractUpgradeTask()
+    {
+      @Override
+      public void perform(final UpgradeContext context) throws ClientException
+      {
+        try
+        {
+          final int changeCount = updateConfigFile(configFile, null, ChangeOperationType.ADD, ldif);
+          displayChangeCount(configFile, changeCount);
+        }
+        catch (final Exception e)
+        {
+          countErrors++;
+          throw new ClientException(ReturnCode.ERROR_UNEXPECTED, LocalizableMessage.raw(e.getMessage()));
+        }
+      }
+
+      @Override
+      public String toString()
+      {
+        return "Add entry " + ldif[0];
+      }
+    };
+  }
+
+  /**
    * This task copies the file placed in parameter within the config / schema
    * folder. If the file already exists, it's overwritten.
    *
@@ -147,7 +183,7 @@
             throw new IOException(ERR_UPGRADE_CORRUPTED_TEMPLATE
                 .get(schemaFileTemplate.getPath()).toString());
           }
-          copy(schemaFileTemplate, configSchemaDirectory, true);
+          copyRecursively(schemaFileTemplate, configSchemaDirectory, true);
           context.notifyProgress(pnc.setProgress(100));
         }
         catch (final IOException e)
@@ -192,7 +228,7 @@
         {
           context.notifyProgress(pnc.setProgress(20));
 
-          copy(configFile, configDirectory, true);
+          copyRecursively(configFile, configDirectory, true);
           context.notifyProgress(pnc.setProgress(100));
         }
         catch (final IOException e)

--
Gitblit v1.10.0