{
// Getting the first original entry from the list
Entry originalEntry = originalEntries.remove( 0 );
// Creating a modification entry to hold all modifications
LdifEntry modificationEntry = new LdifEntry();
modificationEntry.setDn( originalEntry.getDn() );
// Looking for the equivalent entry in the destination partition
Entry destinationEntry = destinationPartition.lookup( new LookupOperationContext( null, originalEntry
.getDn(), attributeIds ) );
if ( destinationEntry != null )
{
// Setting the changetype to delete
modificationEntry.setChangeType( ChangeType.Modify );
// Comparing both entries
compareEntries( originalEntry, destinationEntry, modificationEntry );
}
else
{
// The original entry is no longer present in the destination partition
// Setting the changetype to delete
modificationEntry.setChangeType( ChangeType.Delete );
}
// Checking if modifications occurred on the original entry
ChangeType modificationEntryChangeType = modificationEntry.getChangeType();
if ( modificationEntryChangeType != ChangeType.None )
{
if ( modificationEntryChangeType == ChangeType.Delete
|| ( modificationEntryChangeType == ChangeType.Modify && modificationEntry
.getModifications().size() > 0 ) )
{
// Adding the modification entry to the list
modifications.add( modificationEntry );
}
}
// Creating a search operation context to get the children of the current entry
SearchOperationContext soc = new SearchOperationContext( null, originalEntry.getDn(),
SearchScope.ONELEVEL,
FilterParser.parse( originalPartition.getSchemaManager(), "(objectClass=*)" ), attributeIds ); //$NON-NLS-1$
soc.setAliasDerefMode( AliasDerefMode.DEREF_ALWAYS );
// Looking for the children of the current entry
EntryFilteringCursor cursor = originalPartition.search( soc );
while ( cursor.next() )
{
originalEntries.add( ( ( ClonedServerEntry ) cursor.get() ).getClonedEntry() );
}
}
// Reversing the list to allow deletion of leafs first (otherwise we would be deleting
// higher nodes with children first).
// Order for modified entries does not matter.
Collections.reverse( modifications );
// Looking up the destination base entry
Entry destinationBaseEntry = destinationPartition
.lookup( new LookupOperationContext( null, baseDn, attributeIds ) );
if ( destinationBaseEntry == null )
{
throw new PartitionsDiffException( "Unable to find the base entry in the destination partition." ); //$NON-NLS-1$
}
// Creating the list containing all the destination entries to be processed
// and adding it the destination base entry
List<Entry> destinationEntries = new ArrayList<Entry>();
destinationEntries.add( originalBaseEntry );
// Looping until all destination entries are being processed
while ( destinationEntries.size() > 0 )
{
// Getting the first destination entry from the list
Entry destinationEntry = destinationEntries.remove( 0 );
// Looking for the equivalent entry in the destination partition
Entry originalEntry = originalPartition.lookup( new LookupOperationContext( null, destinationEntry
.getDn(), attributeIds ) );
// We're only looking for new entries, modified or removed
// entries have already been computed
if ( originalEntry == null )
{
// Creating a modification entry to hold all modifications
LdifEntry modificationEntry = new LdifEntry();
modificationEntry.setDn( destinationEntry.getDn() );
// Setting the changetype to addition
modificationEntry.setChangeType( ChangeType.Add );
// Copying attributes
for ( Attribute attribute : destinationEntry )
{
modificationEntry.addAttribute( attribute );
}
// Adding the modification entry to the list
modifications.add( modificationEntry );
}