ImportLDIFReader.java revision 6f1a7f89a2bc9812c61f71d282ead3299556f876
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
* Copyright 2015 ForgeRock AS
*/
/** This class specializes the LDIFReader for imports. */
final class ImportLDIFReader extends LDIFReader
{
/**
* A class holding the entry, its entryID as assigned by the LDIF reader and its suffix as
* determined by the LDIF reader.
*/
static final class EntryInformation
{
private final EntryContainer entryContainer;
{
this.entryContainer = entryContainer;
}
{
return entry;
}
{
return entryID;
}
{
return entryContainer;
}
}
private final RootContainer rootContainer;
/**
* Creates a new LDIF reader that will read information from the specified file.
*
* @param importConfig
* The import configuration for this LDIF reader. It must not be <CODE>null</CODE>.
* @param rootContainer
* The root container needed to get the next entry ID.
* @throws IOException
* If a problem occurs while opening the LDIF file for reading.
*/
public ImportLDIFReader(LDIFImportConfig importConfig, RootContainer rootContainer) throws IOException
{
super(importConfig);
this.rootContainer = rootContainer;
}
/**
* Reads the next entry from the LDIF source.
*
* @return The next entry information read from the LDIF source, or <CODE>null</CODE> if the end of the LDIF
* data is reached of if the import has been cancelled.
* @param suffixesMap
* A map of entry containers instances.
* @throws IOException
* If an I/O problem occurs while reading from the file.
* @throws LDIFException
* If the information read cannot be parsed as an LDIF entry.
*/
public final EntryInformation readEntry(Map<DN, EntryContainer> suffixesMap) throws IOException, LDIFException
{
while (true)
{
final EntryContainer entryContainer;
synchronized (this)
{
// Read the set of lines that make up the next entry.
lines = readEntryLines();
{
return null;
}
lastEntryHeaderLines = new LinkedList<>();
// Read the DN of the entry and see if it is one that should be included
// in the import.
try
{
}
catch (LDIFException e)
{
logger.traceException(e);
continue;
}
{
// This should only happen if the LDIF starts with the "version:" line
// and has a blank line immediately after that. In that case, simply
// read and return the next entry.
continue;
}
if (entryContainer == null)
{
+ "should be included based on a suffix match check.", entryDN);
continue;
}
if (!addPending(entryDN))
{
continue;
}
}
// Create the entry and see if it is one that should be included in the import
{
continue;
}
}
}
{
// Read the set of attributes from the entry.
try
{
{
readAttribute(lines, line, entryDN, objectClasses, userAttrBuilders, operationalAttrBuilders, checkSchema);
}
}
catch (LDIFException e)
{
if (logger.isTraceEnabled())
{
}
return null;
}
return entry;
}
{
if (importConfig.invokeImportPlugins())
{
PluginResult.ImportLDIF pluginResult = pluginConfigManager.invokeLDIFImportPlugins(importConfig, entry);
if (!pluginResult.continueProcessing())
{
if (rejectMessage != null)
{
}
else
{
}
logToRejectWriter(lines, m);
return false;
}
}
return true;
}
{
// Add any superior objectclass(s) missing in the objectclass map.
{
LocalizableMessage message = ERR_LDIF_SCHEMA_VIOLATION.get(entryDN, lastEntryLineNumber, invalidReason);
return false;
}
return true;
}
/**
* Return the suffix instance in the specified map that matches the specified DN.
*
* @param dn
* The DN to search for.
* @param map
* The map to search.
* @return The entry container instance that matches the DN, or null if no match is found.
*/
{
{
if (entryContainer != null)
{
return entryContainer;
}
}
return null;
}
/**
* Make sure the specified parent DN is not in the pending map.
*
* @param parentDN The DN of the parent.
*/
{
if (l != null)
{
l.await();
}
}
/**
* Add specified DN to the pending map.
*
* @param dn The DN to add to the map.
* @return true if the DN was added, false if the DN is already present.
*/
{
}
/**
* Remove the specified DN from the pending map, it may not exist if the
* entries are being migrated so just return.
*
* @param dn The DN to remove from the map.
*/
{
if(l != null)
{
l.countDown();
}
}
}