From 7eb8825838df7d565a17c1b07c1f0ed1c2f25647 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Fri, 02 May 2008 10:59:15 +0000
Subject: [PATCH] Fix for issue 3221 (uninstall returns 0 but fails when LDAP connection is rejected) There was a bug in the manner the option forceOnError.  Appart from that there were some issues due to the fact that most of the methods in UninstallCliHelper do not throw exceptions.  I have updated some interfaces and now the behavior is the following:

---
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/QuickSetupCli.java              |    7 +++
 opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java        |    4 +-
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/CliApplication.java             |    6 ++-
 opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java |   57 ++++++++++++++++++++--------
 4 files changed, 54 insertions(+), 20 deletions(-)

diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java
index 8c111a0..46c8b5e 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java
+++ b/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java
@@ -43,7 +43,6 @@
 
 import static org.opends.messages.AdminToolMessages.*;
 import static org.opends.messages.QuickSetupMessages.*;
-import static org.opends.messages.UtilityMessages.*;
 
 import org.opends.quicksetup.*;
 import org.opends.quicksetup.event.ProgressUpdateEvent;
@@ -118,10 +117,13 @@
    * and null if the user cancels the uninstallation.
    * @throws UserDataException if there is an error with the data
    * in the arguments.
+   * @throws ApplicationException if there is an error processing data in
+   * non-interactive mode and an error must be thrown (not in force on error
+   * mode).
    */
   public UninstallUserData createUserData(UninstallerArgumentParser args,
       String[] rawArguments)
-  throws UserDataException
+  throws UserDataException, ApplicationException
   {
     parser = args;
     UninstallUserData userData = new UninstallUserData();
@@ -485,11 +487,14 @@
    * @return <CODE>true</CODE> if the user wants to continue with uninstall and
    * <CODE>false</CODE> otherwise.
    * @throws UserDataException if there is a problem with the data
-   * provided by the user (in the particular case where we are on quiet
-   * uninstall and some data is missing or not valid).
+   * provided by the user (in the particular case where we are on
+   * non-interactive uninstall and some data is missing or not valid).
+   * @throws ApplicationException if there is an error processing data in
+   * non-interactive mode and an error must be thrown (not in force on error
+   * mode).
    */
   private boolean checkServerState(UninstallUserData userData)
-  throws UserDataException
+  throws UserDataException, ApplicationException
   {
     boolean cancelled = false;
     boolean interactive = parser.isInteractive();
@@ -548,8 +553,9 @@
         }
         else
         {
-          cancelled =
+          boolean errorWithRemote =
             !updateUserUninstallDataWithRemoteServers(userData);
+          cancelled = errorWithRemote && !parser.isForceOnError();
         }
       }
       else
@@ -611,8 +617,9 @@
           if (startWorked)
           {
             userData.setStopServer(true);
-            cancelled =
+            boolean errorWithRemote =
               !updateUserUninstallDataWithRemoteServers(userData);
+            cancelled = errorWithRemote && !parser.isForceOnError();
           }
           else
           {
@@ -1063,9 +1070,12 @@
    * <CODE>false</CODE> otherwise.
    * @throws UserDataException if were are not in interactive mode and not in
    * force on error mode and the operation must be stopped.
+   * @throws ApplicationException if there is an error processing data in
+   * non-interactive mode and an error must be thrown (not in force on error
+   * mode).
    */
   private boolean updateUserUninstallDataWithRemoteServers(
-      UninstallUserData userData) throws UserDataException
+      UninstallUserData userData) throws UserDataException, ApplicationException
   {
     boolean accepted = false;
     boolean interactive = parser.isInteractive();
@@ -1150,6 +1160,10 @@
       println();
       println(Utils.getMessage(te));
 
+    } catch (ApplicationException ae)
+    {
+      throw ae;
+
     } catch (Throwable t)
     {
       LOG.log(Level.WARNING, "Error connecting to server: "+t, t);
@@ -1219,9 +1233,12 @@
    * @param userData the user data.
    * @throws UserDataException if there is an error with the information
    * provided by the user when we are in non-interactive mode.
+   * @throws ApplicationException if there is an error processing data in
+   * non-interactive mode and an error must be thrown (not in force on error
+   * mode).
    */
   private boolean handleTopologyCache(TopologyCache cache,
-      UninstallUserData userData) throws UserDataException
+      UninstallUserData userData) throws UserDataException, ApplicationException
   {
     boolean returnValue;
     boolean stopProcessing = false;
@@ -1281,9 +1298,8 @@
           }
           else
           {
-            stopProcessing = true;
-            println();
-            println(INFO_ERROR_READING_CONFIG_LDAP_CERTIFICATE_SERVER.get(
+            exceptionMsgs.add(
+                INFO_ERROR_READING_CONFIG_LDAP_CERTIFICATE_SERVER.get(
                 e.getHostPort(), e.getCause().getMessage()));
           }
         }
@@ -1326,10 +1342,19 @@
     {
       if (exceptionMsgs.size() > 0)
       {
-        println();
-        println(Utils.getMessageFromCollection(exceptionMsgs,
-            Constants.LINE_SEPARATOR));
-        returnValue = false;
+        Message msg = Utils.getMessageFromCollection(exceptionMsgs,
+            Constants.LINE_SEPARATOR);
+        if (parser.isForceOnError())
+        {
+          println();
+          println(msg);
+          returnValue = false;
+        }
+        else
+        {
+          throw new ApplicationException(ReturnCode.APPLICATION_ERROR, msg,
+              null);
+        }
       }
       else
       {
diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java
index 99aab0a..d1064e7 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java
+++ b/opendj-sdk/opends/src/guitools/org/opends/guitools/uninstaller/Uninstaller.java
@@ -571,7 +571,7 @@
    * @param launcher
    */
   public UserData createUserData(Launcher launcher)
-          throws UserDataException {
+          throws UserDataException, ApplicationException {
     return cliHelper.createUserData(
         (UninstallerArgumentParser)launcher.getArgumentParser(),
         launcher.getArguments());
@@ -1884,7 +1884,7 @@
         LOG.log(Level.INFO, "Error updating replication references in: "+
             server.getHostPort(true), ae);
 
-        if (getUninstallUserData().isForceOnError())
+        if (!getUninstallUserData().isForceOnError())
         {
           throw ae;
         }
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/CliApplication.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/CliApplication.java
index 6f218ca..4c7f72a 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/CliApplication.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/CliApplication.java
@@ -40,10 +40,12 @@
    * status.
    * @param launcher that launched this application
    * @return UserData object populated to reflect the input args and status
-   * @throws UserDataException if something is wrong
+   * @throws UserDataException if something is wrong with the data provided
+   * by the user
+   * @throws ApplicationException if there is an application specific problem
    */
   UserData createUserData(Launcher launcher)
-          throws UserDataException;
+          throws UserDataException, ApplicationException;
 
   /**
    * Gets the user data this application will use when running.
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/QuickSetupCli.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/QuickSetupCli.java
index 9fc4fdb..047e081 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/QuickSetupCli.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/QuickSetupCli.java
@@ -144,6 +144,13 @@
         returnValue = ReturnCode.USER_DATA_ERROR;
       }
     }
+    catch (ApplicationException ae)
+    {
+      System.err.println();
+      System.err.println(ae.getLocalizedMessage());
+      System.err.println();
+      returnValue = ae.getType();
+    }
     return returnValue;
   }
 

--
Gitblit v1.10.0