From 06dc34882e70da6158464bfb18dd30ef86e1bc1d Mon Sep 17 00:00:00 2001
From: Violette Roche-Montane <violette.roche-montane@forgerock.com>
Date: Mon, 03 Jun 2013 07:42:27 +0000
Subject: [PATCH] CR-1777-OPENDJ - Upgrade code cleanup - The upgrade context is now set in the CLI. - The upgrade context contains now the callback handler which simplify all the function (removed all calls to callbackhandler, functions just need the context at this point). - The context contains the CLI user selected options which simplify the code, removed the CheckCLIUserOption, the task have just to check the context for those parameters. - Removed the useless VerificationCallback.java - Added a TaskType in UpgradeTask.java. - Added function verifyTaskType in UpgradeTasks.java which verify user selected options are correct. - Modified tools.properties message numbers

---
 opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java |   87 +++++++------------------------------------
 1 files changed, 15 insertions(+), 72 deletions(-)

diff --git a/opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java b/opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java
index eb78921..a2fec11 100644
--- a/opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java
+++ b/opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java
@@ -40,7 +40,6 @@
 FormattedNotificationCallback.TITLE_CALLBACK;
 import static org.opends.server.tools.upgrade.Upgrade.EXIT_CODE_ERROR;
 import static org.opends.server.tools.upgrade.Upgrade.EXIT_CODE_SUCCESS;
-import static org.opends.server.tools.upgrade.VerificationCallback.*;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -359,12 +358,22 @@
     // Main process
     try
     {
+
+      // Upgrade's context.
+      UpgradeContext context =
+          new UpgradeContext(BuildVersion.instanceVersion(), BuildVersion
+              .binaryVersion(), this);
+
+      context.setIgnoreErrorsMode(isIgnoreErrors());
+      context.setAcceptLicenseMode(isAcceptLicense());
+      context.setInteractiveMode(isInteractive());
+      context.setForceUpgradeMode(isForceUpgrade());
+
       // Creates the log file.
       UpgradeLog.initLogFileHandler();
 
       // Starts upgrade.
-      Upgrade.upgrade(BuildVersion.instanceVersion(), BuildVersion
-          .binaryVersion(), this);
+      Upgrade.upgrade(context);
     }
     catch (ClientException ex)
     {
@@ -437,72 +446,6 @@
           throw new IOException("Unsupported message type: ");
         }
       }
-      else if (c instanceof VerificationCallback)
-      {
-        final VerificationCallback cc = (VerificationCallback) c;
-        // Checks user's options.
-        if (cc.getRequiredOptions() != null)
-        {
-          for (final int opt : cc.getRequiredOptions())
-          {
-            if (opt == NEED_USER_INTERACTION)
-            {
-              if (!isInteractive())
-              {
-                cc.setSelectedIndex(cc.getDefaultOption());
-                return;
-              }
-            }
-
-            if (opt == MANDATORY_USER_INTERACTION)
-            {
-              if (!isInteractive() && !isForceUpgrade())
-              {
-                println(Style.ERROR, ERR_UPGRADE_USER_INTERACTION_REQUIRED
-                    .get(OPTION_LONG_NO_PROMPT, OPTION_LONG_FORCE_UPGRADE), 0);
-                cc.setSelectedIndex(ConfirmationCallback.NO);
-                return;
-              }
-              else if (!isInteractive() && isForceUpgrade())
-              {
-                cc.setSelectedIndex(ConfirmationCallback.YES);
-              }
-            }
-
-            if (opt == TAKE_LONG_TIME_TO_COMPLETE
-                || opt == CANNOT_BE_REVERTED)
-            {
-              if (!isInteractive() && !isForceUpgrade())
-              {
-                println(Style.ERROR, ERR_UPGRADE_USER_INTERACTION_REQUIRED
-                    .get(OPTION_LONG_NO_PROMPT, OPTION_LONG_FORCE_UPGRADE), 0);
-                cc.setSelectedIndex(ConfirmationCallback.NO);
-                return;
-              }
-            }
-
-            // Does the user specify the ignore errors mode ?
-            if (opt == IGNORE_ERRORS_MODE) {
-              if (!isIgnoreErrors())
-              {
-                cc.setSelectedIndex(ConfirmationCallback.NO);
-                return;
-              }
-              cc.setSelectedIndex(ConfirmationCallback.YES);
-            }
-
-            if (opt == ACCEPT_LICENSE_MODE) {
-              if (!isAcceptLicense())
-              {
-                cc.setSelectedIndex(ConfirmationCallback.NO);
-                return;
-              }
-              cc.setSelectedIndex(ConfirmationCallback.YES);
-            }
-          }
-          return;
-        }
-      }
       else if (c instanceof ConfirmationCallback)
       {
         final ConfirmationCallback cc = (ConfirmationCallback) c;
@@ -597,14 +540,14 @@
             LOG.log(INFO, value);
           }
         }
-        else
+        else // Non interactive mode :
         {
-          // Non interactive mode
+          // Force mode.
           if (isForceUpgrade())
           {
             cc.setSelectedIndex(ConfirmationCallback.YES);
           }
-          else
+          else // Default non interactive mode.
           {
             cc.setSelectedIndex(cc.getDefaultOption());
           }

--
Gitblit v1.10.0