From 9a8d97c273430b8eb0ab9afc4209f555321da4e8 Mon Sep 17 00:00:00 2001
From: jarnou <jarnou@localhost>
Date: Mon, 09 Jul 2007 16:13:16 +0000
Subject: [PATCH] Bug: 1428 Synopsis: import-ldif could allow to write skipped entries to a specified file

---
 opends/src/server/org/opends/server/tasks/ImportTask.java |   46 +++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/opends/src/server/org/opends/server/tasks/ImportTask.java b/opends/src/server/org/opends/server/tasks/ImportTask.java
index c1a0891..217677b 100644
--- a/opends/src/server/org/opends/server/tasks/ImportTask.java
+++ b/opends/src/server/org/opends/server/tasks/ImportTask.java
@@ -77,11 +77,12 @@
   boolean append                  = false;
   boolean isCompressed            = false;
   boolean isEncrypted             = false;
-  boolean overwriteRejects        = false;
+  boolean overwrite               = false;
   boolean replaceExisting         = false;
   boolean skipSchemaValidation    = false;
   String  backendID               = null;
   String  rejectFile              = null;
+  String  skipFile                = null;
   ArrayList<String>  excludeAttributeStrings = null;
   ArrayList<String>  excludeBranchStrings    = null;
   ArrayList<String>  excludeFilterStrings    = null;
@@ -126,7 +127,8 @@
     AttributeType typeIncludeFilter;
     AttributeType typeExcludeFilter;
     AttributeType typeRejectFile;
-    AttributeType typeOverwriteRejects;
+    AttributeType typeSkipFile;
+    AttributeType typeOverwrite;
     AttributeType typeSkipSchemaValidation;
     AttributeType typeIsCompressed;
     AttributeType typeIsEncrypted;
@@ -153,8 +155,10 @@
          getAttributeType(ATTR_IMPORT_EXCLUDE_FILTER, true);
     typeRejectFile =
          getAttributeType(ATTR_IMPORT_REJECT_FILE, true);
-    typeOverwriteRejects =
-         getAttributeType(ATTR_IMPORT_OVERWRITE_REJECTS, true);
+    typeSkipFile =
+      getAttributeType(ATTR_IMPORT_SKIP_FILE, true);
+    typeOverwrite =
+         getAttributeType(ATTR_IMPORT_OVERWRITE, true);
     typeSkipSchemaValidation =
          getAttributeType(ATTR_IMPORT_SKIP_SCHEMA_VALIDATION, true);
     typeIsCompressed =
@@ -197,8 +201,11 @@
     attrList = taskEntry.getAttribute(typeRejectFile);
     rejectFile = TaskUtils.getSingleValueString(attrList);
 
-    attrList = taskEntry.getAttribute(typeOverwriteRejects);
-    overwriteRejects = TaskUtils.getBoolean(attrList, false);
+    attrList = taskEntry.getAttribute(typeSkipFile);
+    skipFile = TaskUtils.getSingleValueString(attrList);
+
+    attrList = taskEntry.getAttribute(typeOverwrite);
+    overwrite = TaskUtils.getBoolean(attrList, false);
 
     attrList = taskEntry.getAttribute(typeSkipSchemaValidation);
     skipSchemaValidation = TaskUtils.getBoolean(attrList, false);
@@ -444,7 +451,7 @@
       try
       {
         ExistingFileBehavior existingBehavior;
-        if (overwriteRejects)
+        if (overwrite)
         {
           existingBehavior = ExistingFileBehavior.OVERWRITE;
         }
@@ -465,6 +472,31 @@
       }
     }
 
+    if (skipFile != null)
+    {
+      try
+      {
+        ExistingFileBehavior existingBehavior;
+        if (overwrite)
+        {
+          existingBehavior = ExistingFileBehavior.OVERWRITE;
+        }
+        else
+        {
+          existingBehavior = ExistingFileBehavior.APPEND;
+        }
+
+        importConfig.writeRejectedEntries(skipFile, existingBehavior);
+      }
+      catch (Exception e)
+      {
+        int    msgID   = MSGID_LDIFIMPORT_CANNOT_OPEN_SKIP_FILE;
+        String message = getMessage(msgID, skipFile, getExceptionMessage(e));
+        logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR,
+                 message, msgID);
+        return TaskState.STOPPED_BY_ERROR;
+      }
+    }
 
     // Get the set of base DNs for the backend as an array.
     DN[] baseDNs = new DN[defaultIncludeBranches.size()];

--
Gitblit v1.10.0