From e0c5b184252862e29ca271955bcd15eebd752830 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Thu, 05 Jul 2007 17:16:26 +0000
Subject: [PATCH] Update the import-ldif utility so that it includes a new "--countRejects" option that can be used to count the number of rejected entries.  That value will be used as the exit code, and can be used in scripts to determine if there were any failures during the import.

---
 opends/src/server/org/opends/server/tools/ImportLDIF.java |   26 ++++++++++++++++++++++----
 1 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/opends/src/server/org/opends/server/tools/ImportLDIF.java b/opends/src/server/org/opends/server/tools/ImportLDIF.java
index 5f4f24d..4d43127 100644
--- a/opends/src/server/org/opends/server/tools/ImportLDIF.java
+++ b/opends/src/server/org/opends/server/tools/ImportLDIF.java
@@ -34,6 +34,7 @@
 import java.util.List;
 import java.util.Random;
 
+import org.opends.server.admin.std.server.BackendCfg;
 import org.opends.server.api.Backend;
 import org.opends.server.api.ErrorLogPublisher;
 import org.opends.server.api.plugin.PluginType;
@@ -54,6 +55,7 @@
 import org.opends.server.types.ExistingFileBehavior;
 import org.opends.server.types.InitializationException;
 import org.opends.server.types.LDIFImportConfig;
+import org.opends.server.types.LDIFImportResult;
 import org.opends.server.types.SearchFilter;
 import org.opends.server.util.args.ArgumentException;
 import org.opends.server.util.args.ArgumentParser;
@@ -67,9 +69,7 @@
 import static org.opends.server.messages.ToolMessages.*;
 import static org.opends.server.util.ServerConstants.*;
 import static org.opends.server.util.StaticUtils.*;
-import org.opends.server.util.StaticUtils;
 import static org.opends.server.tools.ToolConstants.*;
-import org.opends.server.admin.std.server.BackendCfg;
 
 
 /**
@@ -135,6 +135,7 @@
 
     // Define the command-line arguments that may be used with this program.
     BooleanArgument append                  = null;
+    BooleanArgument countRejects            = null;
     BooleanArgument displayUsage            = null;
     BooleanArgument isCompressed            = null;
     BooleanArgument isEncrypted             = null;
@@ -290,6 +291,12 @@
       argParser.addArgument(skipSchemaValidation);
 
 
+      countRejects =
+           new BooleanArgument("countrejects", null, "countRejects",
+                               MSGID_LDIFIMPORT_DESCRIPTION_COUNT_REJECTS);
+      argParser.addArgument(countRejects);
+
+
       isCompressed =
            new BooleanArgument("iscompressed", 'c', "isCompressed",
                                MSGID_LDIFIMPORT_DESCRIPTION_IS_COMPRESSED);
@@ -510,7 +517,7 @@
         catch(Exception e)
         {
           System.err.println("Error installing the custom error logger: " +
-              StaticUtils.stackTraceToSingleLineString(e));
+                             stackTraceToSingleLineString(e));
         }
       }
 
@@ -1023,7 +1030,18 @@
     int retCode = 0;
     try
     {
-      backend.importLDIF(importConfig);
+      LDIFImportResult importResult = backend.importLDIF(importConfig);
+      if (countRejects.isPresent())
+      {
+        if (importResult.getEntriesRejected() > Integer.MAX_VALUE)
+        {
+          retCode = Integer.MAX_VALUE;
+        }
+        else
+        {
+          retCode = (int) importResult.getEntriesRejected();
+        }
+      }
     }
     catch (DirectoryException de)
     {

--
Gitblit v1.10.0