From 6df6635f1250c399a2f39d87d0534301ce4c22d7 Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Fri, 31 Aug 2007 15:43:58 +0000
Subject: [PATCH] Exposes the reversion functionality of the upgrader (issue 2169).  Originally it was intended to be exposed as a new script but in order to avoid the negativity of having a command devoted to undoing the upgrade and to avoid more scripts in the top-level directory, I've exposed the functionality as 2 new options in the existing upgrade script.  I will update the Wiki with documentation for these new options soon.

---
 opends/src/quicksetup/org/opends/quicksetup/util/InProcessServerController.java |   33 +++++++++++++++++++++++++++++----
 1 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/opends/src/quicksetup/org/opends/quicksetup/util/InProcessServerController.java b/opends/src/quicksetup/org/opends/quicksetup/util/InProcessServerController.java
index 23dcff7..565f1e1 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/util/InProcessServerController.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/util/InProcessServerController.java
@@ -60,10 +60,12 @@
 import org.opends.server.protocols.internal.InternalClientConnection;
 import org.opends.server.protocols.internal.InternalSearchOperation;
 import org.opends.server.protocols.ldap.LDAPAttribute;
+import org.opends.server.protocols.asn1.ASN1OctetString;
 import org.opends.server.core.ModifyOperation;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.core.AddOperation;
 import org.opends.server.core.DeleteOperation;
+import org.opends.server.core.CompareOperation;
 import org.opends.server.config.ConfigException;
 
 import java.util.logging.Logger;
@@ -416,7 +418,7 @@
           // report the error to the user
           MessageBuilder error = op.getErrorMessage();
           throw new ApplicationException(
-              ApplicationReturnCode.ReturnCode.IMPORT_ERROR,
+              ReturnCode.IMPORT_ERROR,
                   INFO_ERROR_APPLY_LDIF_MODIFY.get(dnByteString.toString(),
                           error != null ? error.toString() : ""),
                   null);
@@ -435,6 +437,29 @@
         rc = addOp.getResultCode();
         if (rc.equals(ResultCode.SUCCESS)) {
           LOG.log(Level.INFO, "processed server add " + addOp.getEntryDN());
+        } else if (rc.equals(ResultCode.ENTRY_ALREADY_EXISTS)) {
+          // Compare the attributes with the existing entry to see if we
+          // can ignore this add.
+          boolean ignore = true;
+          for (RawAttribute attr : rawAttrs) {
+            ArrayList<ASN1OctetString> values = attr.getValues();
+            for (ASN1OctetString value : values) {
+              CompareOperation compOp =
+                cc.processCompare(dnByteString, attr.getAttributeType(), value);
+              if (ResultCode.ASSERTION_FAILED.equals(compOp.getResultCode())) {
+                ignore = false;
+                break;
+              }
+            }
+          }
+          if (!ignore) {
+            MessageBuilder error = addOp.getErrorMessage();
+            throw new ApplicationException(
+                ReturnCode.IMPORT_ERROR,
+                    INFO_ERROR_APPLY_LDIF_ADD.get(dnByteString.toString(),
+                            error != null ? error.toString() : ""),
+                    null);
+          }
         } else {
           boolean ignore = false;
 
@@ -471,7 +496,7 @@
           if (!ignore) {
             MessageBuilder error = addOp.getErrorMessage();
             throw new ApplicationException(
-                    ApplicationReturnCode.ReturnCode.IMPORT_ERROR,
+                    ReturnCode.IMPORT_ERROR,
                     INFO_ERROR_APPLY_LDIF_ADD.get(dnByteString.toString(),
                             error != null ? error.toString() : ""),
                     null);
@@ -489,7 +514,7 @@
           // report the error to the user
           MessageBuilder error = delOp.getErrorMessage();
           throw new ApplicationException(
-              ApplicationReturnCode.ReturnCode.IMPORT_ERROR,
+              ReturnCode.IMPORT_ERROR,
                   INFO_ERROR_APPLY_LDIF_DELETE.get(dnByteString.toString(),
                           error != null ? error.toString() : ""),
                   null);
@@ -497,7 +522,7 @@
         break;
       default:
         LOG.log(Level.SEVERE, "Unexpected record type " + cre.getClass());
-        throw new ApplicationException(ApplicationReturnCode.ReturnCode.BUG,
+        throw new ApplicationException(ReturnCode.BUG,
                 INFO_BUG_MSG.get(),
                 null);
     }

--
Gitblit v1.10.0