From 56f7fa2950663b0e26943b3f4460b33118fcd4f7 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Thu, 18 Oct 2007 23:02:53 +0000
Subject: [PATCH] Fix for issue 2452: Missing "rejected file" when importing data from LDIF
---
opends/src/server/org/opends/server/tools/InstallDS.java | 116 ++++++++++++++----
opends/src/quicksetup/org/opends/quicksetup/installer/NewSuffixOptions.java | 128 +++++++++++++++------
opends/src/server/org/opends/server/tools/InstallDSArgumentParser.java | 44 +++++++
opends/src/messages/messages/tools.properties | 10 +
opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java | 28 ++++
opends/src/quicksetup/org/opends/quicksetup/UserData.java | 4
6 files changed, 259 insertions(+), 71 deletions(-)
diff --git a/opends/src/messages/messages/tools.properties b/opends/src/messages/messages/tools.properties
index c06a7d3..a435f2f 100644
--- a/opends/src/messages/messages/tools.properties
+++ b/opends/src/messages/messages/tools.properties
@@ -2189,3 +2189,13 @@
SEVERE_ERR_TASKINFO_TASK_NOT_CANCELABLE_TASK_1477=Error: task %s is not in a \
cancelable state
NOTICE_BACKUPDB_CANCELLED_1478=The backup process was cancelled
+INFO_INSTALLDS_DESCRIPTION_REJECTED_FILE_1479=Write rejected entries to the \
+ specified file
+MILD_ERR_INSTALLDS_CANNOT_WRITE_REJECTED_1480=Cannot write to rejected entries \
+ file %s. Verify that you have enough write rights on the file
+INFO_INSTALLDS_PROMPT_REJECTED_FILE_1481=Write rejected entries to file:
+INFO_INSTALLDS_DESCRIPTION_SKIPPED_FILE_1482=Write skipped entries to the \
+ specified file
+MILD_ERR_INSTALLDS_CANNOT_WRITE_SKIPPED_1483=Cannot write to skipped entries \
+ file %s. Verify that you have enough write rights on the file
+INFO_INSTALLDS_PROMPT_SKIPPED_FILE_1484=Write skipped entries to file:
diff --git a/opends/src/quicksetup/org/opends/quicksetup/UserData.java b/opends/src/quicksetup/org/opends/quicksetup/UserData.java
index 4a0e72d..b56b232 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/UserData.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/UserData.java
@@ -103,8 +103,8 @@
LinkedList<String> baseDn = new LinkedList<String>();
baseDn.add("dc=example,dc=com");
- NewSuffixOptions defaultNewSuffixOptions = new NewSuffixOptions(
- NewSuffixOptions.Type.CREATE_BASE_ENTRY, baseDn);
+ NewSuffixOptions defaultNewSuffixOptions = NewSuffixOptions.createBaseEntry(
+ baseDn);
setNewSuffixOptions(defaultNewSuffixOptions);
// See what we can propose as port
diff --git a/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java b/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
index 0ab8d81..99aeebe 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
@@ -1135,6 +1135,18 @@
argList.add(ldifPath);
}
argList.add("-F");
+ String rejectedFile = getUserData().getNewSuffixOptions().getRejectedFile();
+ if (rejectedFile != null)
+ {
+ argList.add("-R");
+ argList.add(rejectedFile);
+ }
+ String skippedFile = getUserData().getNewSuffixOptions().getSkippedFile();
+ if (skippedFile != null)
+ {
+ argList.add("--skipFile");
+ argList.add(skippedFile);
+ }
final String[] args = new String[argList.size()];
argList.toArray(args);
@@ -3423,7 +3435,8 @@
LinkedList<String> ldifPaths = new LinkedList<String>();
ldifPaths.add(ldifPath);
- dataOptions = new NewSuffixOptions(type, baseDns, ldifPaths);
+ dataOptions = NewSuffixOptions.createImportFromLDIF(baseDns, ldifPaths,
+ null, null);
qs.displayFieldInvalid(FieldName.LDIF_PATH, false);
}
break;
@@ -3467,8 +3480,8 @@
// No validation errors
LinkedList<String> baseDns = new LinkedList<String>();
baseDns.add(baseDn);
- dataOptions = new NewSuffixOptions(type, baseDns,
- new Integer(nEntries));
+ dataOptions = NewSuffixOptions.createAutomaticallyGenerated(baseDns,
+ Integer.parseInt(nEntries));
}
break;
@@ -3479,7 +3492,14 @@
{
LinkedList<String> baseDns = new LinkedList<String>();
baseDns.add(baseDn);
- dataOptions = new NewSuffixOptions(type, baseDns);
+ if (type == NewSuffixOptions.Type.CREATE_BASE_ENTRY)
+ {
+ dataOptions = NewSuffixOptions.createBaseEntry(baseDns);
+ }
+ else
+ {
+ dataOptions = NewSuffixOptions.createEmpty(baseDns);
+ }
}
}
diff --git a/opends/src/quicksetup/org/opends/quicksetup/installer/NewSuffixOptions.java b/opends/src/quicksetup/org/opends/quicksetup/installer/NewSuffixOptions.java
index 714223c..f3dba71 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/installer/NewSuffixOptions.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/installer/NewSuffixOptions.java
@@ -46,10 +46,6 @@
public enum Type
{
/**
- * Do nothing.
- */
- NOTHING,
- /**
* Create base entry.
*/
CREATE_BASE_ENTRY,
@@ -67,51 +63,85 @@
IMPORT_AUTOMATICALLY_GENERATED_DATA
}
- private Type type = Type.NOTHING;
+ private Type type;
private LinkedList<String> baseDns = new LinkedList<String>();
private LinkedList<String> ldifPaths = new LinkedList<String>();
+ private String rejectedFile;
+
+ private String skippedFile;
+
private int numberEntries = 2000;
/**
- * Constructor for the NewSuffixOptions object.
+ * Private constructor.
+ * @param baseDns the base DNs of the suffix options.
*
- * If the Data Options is IMPORT_FROM_LDIF_FILE the args are the baseDn and
- * a String with the ldif location.
- *
- * If the Data Options is IMPORT_AUTOMATICALLY_GENERATED_DATA the args
- * are the baseDn and an Integer with the number of entries.
- *
- * For the rest of the types the args are just the baseDn.
- *
- * @param type the Type of NewSuffixOptions.
- * @param args the different argument objects (depending on the Type
- * specified)
*/
- public NewSuffixOptions(Type type, Object... args)
+ private NewSuffixOptions(LinkedList<String> baseDns)
{
- this.type = type;
- LinkedList<?> v = (LinkedList<?>)args[0];
- for (Object o : v)
- {
- baseDns.add((String)o);
- }
- switch (type)
- {
- case IMPORT_FROM_LDIF_FILE:
- v = (LinkedList<?>)args[1];
- for (Object o : v)
- {
- ldifPaths.add((String)o);
- }
- break;
+ this.baseDns.addAll(baseDns);
+ }
- case IMPORT_AUTOMATICALLY_GENERATED_DATA:
- numberEntries = ((Integer) args[1]).intValue();
- break;
- }
+ /**
+ * Creates a base entry suffix options.
+ * @param baseDNs the base DNs of the suffix options.
+ * @return a base entry suffix options.
+ */
+ public static NewSuffixOptions createBaseEntry(LinkedList<String> baseDNs)
+ {
+ NewSuffixOptions ops = new NewSuffixOptions(baseDNs);
+ ops.type = Type.CREATE_BASE_ENTRY;
+ return ops;
+ }
+
+ /**
+ * Creates an empty suffix options.
+ * @param baseDNs the base DNs of the suffix options.
+ * @return an empty suffix options.
+ */
+ public static NewSuffixOptions createEmpty(LinkedList<String> baseDNs)
+ {
+ NewSuffixOptions ops = new NewSuffixOptions(baseDNs);
+ ops.type = Type.LEAVE_DATABASE_EMPTY;
+ return ops;
+ }
+
+ /**
+ * Creates a base entry suffix options.
+ * @param baseDNs the base DNs of the suffix options.
+ * @param ldifPaths the LDIF files to be imported.
+ * @param rejectedFile the files where the rejected entries are stored.
+ * @param skippedFile the files where the skipped entries are stored.
+ * @return a base entry suffix options.
+ */
+ public static NewSuffixOptions createImportFromLDIF(
+ LinkedList<String> baseDNs, LinkedList<String> ldifPaths,
+ String rejectedFile, String skippedFile)
+ {
+ NewSuffixOptions ops = new NewSuffixOptions(baseDNs);
+ ops.type = Type.IMPORT_FROM_LDIF_FILE;
+ ops.ldifPaths.addAll(ldifPaths);
+ ops.rejectedFile = rejectedFile;
+ ops.skippedFile = skippedFile;
+ return ops;
+ }
+
+ /**
+ * Creates an automatically generated entries suffix options.
+ * @param baseDNs the base DNs of the suffix options.
+ * @param numberEntries the number of entries to generate.
+ * @return a base entry suffix options.
+ */
+ public static NewSuffixOptions createAutomaticallyGenerated(
+ LinkedList<String> baseDNs, int numberEntries)
+ {
+ NewSuffixOptions ops = new NewSuffixOptions(baseDNs);
+ ops.type = Type.IMPORT_AUTOMATICALLY_GENERATED_DATA;
+ ops.numberEntries = numberEntries;
+ return ops;
}
/**
@@ -136,6 +166,30 @@
}
/**
+ * Returns the path to store the rejected entries of the import.
+ * <CODE>null</CODE> if no rejected file is specified.
+ *
+ * @return the path to store the rejected entries of the import.
+ * <CODE>null</CODE> if no rejected file is specified.
+ */
+ public String getRejectedFile()
+ {
+ return rejectedFile;
+ }
+
+ /**
+ * Returns the path to store the skipped entries of the import.
+ * <CODE>null</CODE> if no skipped file is specified.
+ *
+ * @return the path to store the skipped entries of the import.
+ * <CODE>null</CODE> if no skipped file is specified.
+ */
+ public String getSkippedFile()
+ {
+ return skippedFile;
+ }
+
+ /**
* Returns the number of entries that will be automatically generated.
*
* @return the number of entries that will be automatically generated.
diff --git a/opends/src/server/org/opends/server/tools/InstallDS.java b/opends/src/server/org/opends/server/tools/InstallDS.java
index 77c31ac..121a1ad 100644
--- a/opends/src/server/org/opends/server/tools/InstallDS.java
+++ b/opends/src/server/org/opends/server/tools/InstallDS.java
@@ -617,25 +617,40 @@
errorMessages.add(ERR_INSTALLDS_NO_SUCH_LDIF_FILE.get(
Utils.getStringFromCollection(nonExistingFiles, ", ")));
}
- dataOptions = new NewSuffixOptions(
- NewSuffixOptions.Type.IMPORT_FROM_LDIF_FILE, baseDNs,
- argParser.importLDIFArg.getValues());
+ String rejectedFile = argParser.rejectedImportFileArg.getValue();
+ if (rejectedFile != null)
+ {
+ if (!Utils.canWrite(rejectedFile))
+ {
+ errorMessages.add(
+ ERR_INSTALLDS_CANNOT_WRITE_REJECTED.get(rejectedFile));
+ }
+ }
+ String skippedFile = argParser.skippedImportFileArg.getValue();
+ if (skippedFile != null)
+ {
+ if (!Utils.canWrite(skippedFile))
+ {
+ errorMessages.add(ERR_INSTALLDS_CANNOT_WRITE_SKIPPED.get(
+ skippedFile));
+ }
+ }
+ dataOptions = NewSuffixOptions.createImportFromLDIF(baseDNs,
+ argParser.importLDIFArg.getValues(),
+ rejectedFile, skippedFile);
}
else if (argParser.addBaseEntryArg.isPresent())
{
- dataOptions = new NewSuffixOptions(
- NewSuffixOptions.Type.CREATE_BASE_ENTRY, baseDNs);
+ dataOptions = NewSuffixOptions.createBaseEntry(baseDNs);
}
else if (argParser.sampleDataArg.isPresent())
{
- dataOptions = new NewSuffixOptions(
- NewSuffixOptions.Type.IMPORT_AUTOMATICALLY_GENERATED_DATA, baseDNs,
+ dataOptions = NewSuffixOptions.createAutomaticallyGenerated(baseDNs,
new Integer(argParser.sampleDataArg.getValue()));
}
else
{
- dataOptions = new NewSuffixOptions(
- NewSuffixOptions.Type.LEAVE_DATABASE_EMPTY, baseDNs);
+ dataOptions = NewSuffixOptions.createEmpty(baseDNs);
}
uData.setNewSuffixOptions(dataOptions);
@@ -1021,15 +1036,39 @@
importLDIFFiles.add(path);
}
}
- dataOptions = new NewSuffixOptions(
- NewSuffixOptions.Type.IMPORT_FROM_LDIF_FILE,
- baseDNs, importLDIFFiles);
+ String rejectedFile = argParser.rejectedImportFileArg.getValue();
+ if (rejectedFile != null)
+ {
+ while (!Utils.canWrite(rejectedFile))
+ {
+ printLineBreak();
+ printErrorMessage(ERR_INSTALLDS_CANNOT_WRITE_REJECTED.get(
+ rejectedFile));
+ printLineBreak();
+ rejectedFile =
+ promptForString(INFO_INSTALLDS_PROMPT_REJECTED_FILE.get(), null);
+ }
+ }
+ String skippedFile = argParser.skippedImportFileArg.getValue();
+ if (skippedFile != null)
+ {
+ while (!Utils.canWrite(skippedFile))
+ {
+ printLineBreak();
+ printErrorMessage(
+ ERR_INSTALLDS_CANNOT_WRITE_SKIPPED.get(skippedFile));
+ printLineBreak();
+ skippedFile =
+ promptForString(INFO_INSTALLDS_PROMPT_SKIPPED_FILE.get(), null);
+ }
+ }
+
+ dataOptions = NewSuffixOptions.createImportFromLDIF(baseDNs,
+ importLDIFFiles, rejectedFile, skippedFile);
}
else if (argParser.addBaseEntryArg.isPresent())
{
- dataOptions = new NewSuffixOptions(
- NewSuffixOptions.Type.CREATE_BASE_ENTRY,
- baseDNs);
+ dataOptions = NewSuffixOptions.createBaseEntry(baseDNs);
}
else if (argParser.sampleDataArg.isPresent())
{
@@ -1045,9 +1084,8 @@
Message message = INFO_INSTALLDS_PROMPT_NUM_ENTRIES.get();
numUsers = promptForInteger(message, 2000, 0, Integer.MAX_VALUE);
}
- dataOptions = new NewSuffixOptions(
- NewSuffixOptions.Type.IMPORT_AUTOMATICALLY_GENERATED_DATA,
- baseDNs, numUsers);
+ dataOptions = NewSuffixOptions.createAutomaticallyGenerated(baseDNs,
+ numUsers);
}
else
{
@@ -1093,28 +1131,50 @@
printErrorMessage(message);
}
}
- dataOptions = new NewSuffixOptions(
- NewSuffixOptions.Type.IMPORT_FROM_LDIF_FILE,
- baseDNs, importLDIFFiles);
+ String rejectedFile = argParser.rejectedImportFileArg.getValue();
+ if (rejectedFile != null)
+ {
+ while (!Utils.canWrite(rejectedFile))
+ {
+ printLineBreak();
+ printErrorMessage(
+ ERR_INSTALLDS_CANNOT_WRITE_REJECTED.get(rejectedFile));
+ printLineBreak();
+ rejectedFile =
+ promptForString(INFO_INSTALLDS_PROMPT_REJECTED_FILE.get(), null);
+ }
+ }
+ String skippedFile = argParser.skippedImportFileArg.getValue();
+ if (skippedFile != null)
+ {
+ while (!Utils.canWrite(skippedFile))
+ {
+ printLineBreak();
+ printErrorMessage(
+ ERR_INSTALLDS_CANNOT_WRITE_SKIPPED.get(skippedFile));
+ printLineBreak();
+ skippedFile =
+ promptForString(INFO_INSTALLDS_PROMPT_SKIPPED_FILE.get(), null);
+ }
+ }
+ dataOptions = NewSuffixOptions.createImportFromLDIF(baseDNs,
+ importLDIFFiles, rejectedFile, skippedFile);
}
else if (populateType == POPULATE_TYPE_GENERATE_SAMPLE_DATA)
{
Message message = INFO_INSTALLDS_PROMPT_NUM_ENTRIES.get();
int numUsers = promptForInteger(message, 2000, 0, Integer.MAX_VALUE);
- dataOptions = new NewSuffixOptions(
- NewSuffixOptions.Type.IMPORT_AUTOMATICALLY_GENERATED_DATA,
- baseDNs, numUsers);
+ dataOptions = NewSuffixOptions.createAutomaticallyGenerated(baseDNs,
+ numUsers);
}
else if (populateType == POPULATE_TYPE_LEAVE_EMPTY)
{
- dataOptions = new NewSuffixOptions(
- NewSuffixOptions.Type.LEAVE_DATABASE_EMPTY, baseDNs);
+ dataOptions = NewSuffixOptions.createEmpty(baseDNs);
}
else if (populateType == POPULATE_TYPE_BASE_ONLY)
{
- dataOptions = new NewSuffixOptions(
- NewSuffixOptions.Type.CREATE_BASE_ENTRY, baseDNs);
+ dataOptions = NewSuffixOptions.createBaseEntry(baseDNs);
}
else
{
diff --git a/opends/src/server/org/opends/server/tools/InstallDSArgumentParser.java b/opends/src/server/org/opends/server/tools/InstallDSArgumentParser.java
index f5a0a57..f10572c 100644
--- a/opends/src/server/org/opends/server/tools/InstallDSArgumentParser.java
+++ b/opends/src/server/org/opends/server/tools/InstallDSArgumentParser.java
@@ -81,6 +81,8 @@
StringArgument configClassArg;
StringArgument configFileArg;
StringArgument importLDIFArg;
+ StringArgument rejectedImportFileArg;
+ StringArgument skippedImportFileArg;
StringArgument directoryManagerDNArg;
StringArgument directoryManagerPwdStringArg;
StringArgument useJavaKeyStoreArg;
@@ -188,6 +190,18 @@
INFO_INSTALLDS_DESCRIPTION_IMPORTLDIF.get());
addArgument(importLDIFArg);
+ rejectedImportFileArg = new StringArgument(
+ "rejectfile", 'R', "rejectFile", false, false,
+ true, "{rejectFile}", null, null,
+ INFO_INSTALLDS_DESCRIPTION_REJECTED_FILE.get());
+ addArgument(rejectedImportFileArg);
+
+ skippedImportFileArg = new StringArgument(
+ "skipFile", null, "skipFile", false, false,
+ true, "{skipFile}", null, null,
+ INFO_INSTALLDS_DESCRIPTION_SKIPPED_FILE.get());
+ addArgument(skippedImportFileArg);
+
sampleDataArg = new IntegerArgument(
"sampledata", 'd', "sampleData", false,
false, true, "{numEntries}", 0, null,
@@ -516,6 +530,36 @@
sampleDataArg.getLongIdentifier());
errorMessages.add(message);
}
+
+ if (rejectedImportFileArg.isPresent() && addBaseEntryArg.isPresent())
+ {
+ Message message = ERR_TOOL_CONFLICTING_ARGS.get(
+ addBaseEntryArg.getLongIdentifier(),
+ rejectedImportFileArg.getLongIdentifier());
+ errorMessages.add(message);
+ }
+ else if (rejectedImportFileArg.isPresent() && sampleDataArg.isPresent())
+ {
+ Message message = ERR_TOOL_CONFLICTING_ARGS.get(
+ rejectedImportFileArg.getLongIdentifier(),
+ sampleDataArg.getLongIdentifier());
+ errorMessages.add(message);
+ }
+
+ if (skippedImportFileArg.isPresent() && addBaseEntryArg.isPresent())
+ {
+ Message message = ERR_TOOL_CONFLICTING_ARGS.get(
+ addBaseEntryArg.getLongIdentifier(),
+ skippedImportFileArg.getLongIdentifier());
+ errorMessages.add(message);
+ }
+ else if (skippedImportFileArg.isPresent() && sampleDataArg.isPresent())
+ {
+ Message message = ERR_TOOL_CONFLICTING_ARGS.get(
+ skippedImportFileArg.getLongIdentifier(),
+ sampleDataArg.getLongIdentifier());
+ errorMessages.add(message);
+ }
}
/**
--
Gitblit v1.10.0