From ee0fbff002e17a56aca09cb8dc7da0f4fe20ad6e Mon Sep 17 00:00:00 2001
From: boli <boli@localhost>
Date: Tue, 31 Jul 2007 21:38:45 +0000
Subject: [PATCH]
---
opends/src/server/org/opends/server/tasks/ImportTask.java | 214 +++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 159 insertions(+), 55 deletions(-)
diff --git a/opends/src/server/org/opends/server/tasks/ImportTask.java b/opends/src/server/org/opends/server/tasks/ImportTask.java
index a0b2901..e2615ce 100644
--- a/opends/src/server/org/opends/server/tasks/ImportTask.java
+++ b/opends/src/server/org/opends/server/tasks/ImportTask.java
@@ -224,19 +224,8 @@
clearBackend = TaskUtils.getBoolean(attrList, false);
// Make sure that either the "includeBranchStrings" argument or the
- // "backendID" argument was provided, but not both.
- if(!includeBranchStrings.isEmpty())
- {
- if(backendID != null)
- {
- int msgID = MSGID_LDIFIMPORT_CONFLICTING_OPTIONS;
- String message = getMessage(msgID, typeIncludeBranch.getNameOrOID(),
- typeBackendID.getNameOrOID());
- throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
- msgID);
- }
- }
- else if(backendID == null)
+ // "backendID" argument was provided.
+ if(includeBranchStrings.isEmpty() && backendID == null)
{
int msgID = MSGID_LDIFIMPORT_MISSING_BACKEND_ARGUMENT;
String message = getMessage(msgID, typeIncludeBranch.getNameOrOID(),
@@ -245,15 +234,109 @@
msgID);
}
+ Backend backend = null;
+ ArrayList<DN> defaultIncludeBranches;
+ ArrayList<DN> excludeBranches =
+ new ArrayList<DN>(excludeBranchStrings.size());
+ ArrayList<DN> includeBranches =
+ new ArrayList<DN>(includeBranchStrings.size());
+
+ for (String s : includeBranchStrings)
+ {
+ DN includeBranch;
+ try
+ {
+ includeBranch = DN.decode(s);
+ }
+ catch (DirectoryException de)
+ {
+ int msgID = MSGID_LDIFIMPORT_CANNOT_DECODE_INCLUDE_BASE;
+ String message = getMessage(msgID, s, de.getErrorMessage());
+ throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
+ msgID);
+ }
+ catch (Exception e)
+ {
+ int msgID = MSGID_LDIFIMPORT_CANNOT_DECODE_INCLUDE_BASE;
+ String message = getMessage(msgID, s, getExceptionMessage(e));
+ throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
+ msgID);
+ }
+
+ if(! includeBranches.contains(includeBranch))
+ {
+ includeBranches.add(includeBranch);
+ }
+ }
+ for (String s : excludeBranchStrings)
+ {
+ DN excludeBranch;
+ try
+ {
+ excludeBranch = DN.decode(s);
+ }
+ catch (DirectoryException de)
+ {
+ int msgID = MSGID_LDIFIMPORT_CANNOT_DECODE_EXCLUDE_BASE;
+ String message = getMessage(msgID, s, de.getErrorMessage());
+ throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
+ msgID);
+ }
+ catch (Exception e)
+ {
+ int msgID = MSGID_LDIFIMPORT_CANNOT_DECODE_EXCLUDE_BASE;
+ String message = getMessage(msgID, s, getExceptionMessage(e));
+ throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
+ msgID);
+ }
+
+ if (! excludeBranches.contains(excludeBranch))
+ {
+ excludeBranches.add(excludeBranch);
+ }
+ }
+
+ for (String filterString : excludeFilterStrings)
+ {
+ try
+ {
+ SearchFilter.createFilterFromString(filterString);
+ }
+ catch (DirectoryException de)
+ {
+ int msgID = MSGID_LDIFIMPORT_CANNOT_PARSE_EXCLUDE_FILTER;
+ String message = getMessage(msgID, filterString,
+ de.getErrorMessage());
+ throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
+ msgID);
+ }
+ }
+
+ for (String filterString : includeFilterStrings)
+ {
+ try
+ {
+ SearchFilter.createFilterFromString(filterString);
+ }
+ catch (DirectoryException de)
+ {
+ int msgID = MSGID_LDIFIMPORT_CANNOT_PARSE_INCLUDE_FILTER;
+ String message = getMessage(msgID, filterString,
+ de.getErrorMessage());
+ throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
+ msgID);
+ }
+ }
+
if(backendID != null)
{
- Backend backend = DirectoryServer.getBackend(backendID);
+ backend = DirectoryServer.getBackend(backendID);
if (backend == null)
{
int msgID = MSGID_LDIFIMPORT_NO_BACKENDS_FOR_ID;
String message = getMessage(msgID, backendID);
throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
- msgID);
+ msgID);
}
else if (! backend.supportsLDIFImport())
{
@@ -262,11 +345,12 @@
throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
msgID);
}
- // Make sure that if the "backendID" argument was provided and the
- // "append" option was not provided, the "clearBackend" argument was also
- // provided if there are more then one baseDNs for the backend being
- // imported.
- else if(!append && backend.getBaseDNs().length > 1 && !clearBackend)
+ // Make sure that if the "backendID" argument was provided, no include
+ // base was included, and the "append" ption was not provided, the
+ // "clearBackend" argument was also provided if there are more then one
+ // baseDNs for the backend being imported.
+ else if(!append && includeBranchStrings.isEmpty() &&
+ backend.getBaseDNs().length > 1 && !clearBackend)
{
StringBuilder builder = new StringBuilder();
for(DN dn : backend.getBaseDNs())
@@ -284,31 +368,8 @@
else
{
// Find the backend that includes all the branches.
- Backend backend = null;
- for (String s : includeBranchStrings)
+ for(DN includeBranch : includeBranches)
{
- DN includeBranch;
- try
- {
- includeBranch = DN.decode(s);
- }
- catch (DirectoryException de)
- {
- int msgID = MSGID_LDIFIMPORT_CANNOT_DECODE_INCLUDE_BASE;
- String message = getMessage(msgID, s, de.getErrorMessage());
- logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR,
- message, msgID);
- throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
- msgID);
- }
- catch (Exception e)
- {
- int msgID = MSGID_LDIFIMPORT_CANNOT_DECODE_INCLUDE_BASE;
- String message = getMessage(msgID, s, getExceptionMessage(e));
- throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
- msgID);
- }
-
Backend locatedBackend = DirectoryServer.getBackend(includeBranch);
if(locatedBackend != null)
{
@@ -320,13 +381,35 @@
{
// The include branches span across multiple backends.
int msgID = MSGID_LDIFIMPORT_INVALID_INCLUDE_BASE;
- String message = getMessage(msgID, s, backend.getBackendID());
+ String message = getMessage(msgID,
+ includeBranch.toNormalizedString(),
+ backend.getBackendID());
throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,
message, msgID);
}
}
}
}
+
+ // Make sure the selected backend will handle all the include branches
+ defaultIncludeBranches = new ArrayList<DN>(backend.getBaseDNs().length);
+ for (DN dn : backend.getBaseDNs())
+ {
+ defaultIncludeBranches.add(dn);
+ }
+
+ for(DN includeBranch : includeBranches)
+ {
+ if (! Backend.handlesEntry(includeBranch, defaultIncludeBranches,
+ excludeBranches))
+ {
+ int msgID = MSGID_LDIFIMPORT_INVALID_INCLUDE_BASE;
+ String message = getMessage(msgID, includeBranch.toNormalizedString(),
+ backend.getBackendID());
+ throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
+ msgID);
+ }
+ }
}
@@ -408,11 +491,11 @@
// Get the backend into which the LDIF should be imported.
Backend backend = null;
ArrayList<DN> defaultIncludeBranches;
- ArrayList<DN> excludeBranches = new ArrayList<DN>();
- ArrayList<DN> includeBranches = new ArrayList<DN>();
+ ArrayList<DN> excludeBranches =
+ new ArrayList<DN>(excludeBranchStrings.size());
+ ArrayList<DN> includeBranches =
+ new ArrayList<DN>(includeBranchStrings.size());
-
- includeBranches = new ArrayList<DN>(includeBranchStrings.size());
for (String s : includeBranchStrings)
{
DN includeBranch;
@@ -437,7 +520,10 @@
return TaskState.STOPPED_BY_ERROR;
}
- includeBranches.add(includeBranch);
+ if(! includeBranches.contains(includeBranch))
+ {
+ includeBranches.add(includeBranch);
+ }
}
if(backendID != null)
@@ -460,11 +546,12 @@
message, msgID);
return TaskState.STOPPED_BY_ERROR;
}
- // Make sure that if the "backendID" argument was provided and the
- // "append" option was not provided, the "clearBackend" argument was also
- // provided if there are more then one baseDNs for the backend being
- // imported.
- else if(!append && backend.getBaseDNs().length > 1 && !clearBackend)
+ // Make sure that if the "backendID" argument was provided, no include
+ // base was included, and the "append" ption was not provided, the
+ // "clearBackend" argument was also provided if there are more then one
+ // baseDNs for the backend being imported.
+ else if(!append && includeBranches.isEmpty() &&
+ backend.getBaseDNs().length > 1 && !clearBackend)
{
StringBuilder builder = new StringBuilder();
builder.append(backend.getBaseDNs()[0].toNormalizedString());
@@ -574,6 +661,23 @@
{
includeBranches = defaultIncludeBranches;
}
+ else
+ {
+ // Make sure the selected backend will handle all the include branches
+ for(DN includeBranch : includeBranches)
+ {
+ if (! Backend.handlesEntry(includeBranch, defaultIncludeBranches,
+ excludeBranches))
+ {
+ int msgID = MSGID_LDIFIMPORT_INVALID_INCLUDE_BASE;
+ String message = getMessage(msgID, includeBranch.toNormalizedString(),
+ backend.getBackendID());
+ logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR,
+ message, msgID);
+ return TaskState.STOPPED_BY_ERROR;
+ }
+ }
+ }
// Create the LDIF import configuration to use when reading the LDIF.
ArrayList<String> fileList = new ArrayList<String>(ldifFiles);
--
Gitblit v1.10.0