LdapDN oldDn = oldEntry.getDn();
LdapDN parentDn = DnUtils.getParent( oldDn );
LdapDN newDn = DnUtils.composeDn( newRdn, parentDn );
// use a dummy monitor to be able to handle exceptions
StudioProgressMonitor dummyMonitor = new StudioProgressMonitor( monitor );
// try to rename entry
renameEntry( browserConnection, oldEntry, newDn, dummyMonitor );
// do a simulated rename, if renaming of a non-leaf entry is not supported.
if ( dummyMonitor.errorsReported() && !monitor.isCanceled() )
{
if ( dialog != null && dummyMonitor.getException() instanceof ContextNotEmptyException )
{
// open dialog
dialog.setEntryInfo( browserConnection, oldDn, newDn );
dialog.open();
boolean isSimulatedRename = dialog.isSimulateRename();
if ( isSimulatedRename )
{
// do simulated rename operation
dummyMonitor.reset();
CopyEntriesJob.copyEntry( oldEntry, oldEntry.getParententry(), newRdn,
SearchControls.SUBTREE_SCOPE, 0, null, dummyMonitor, monitor );
if ( !dummyMonitor.errorsReported() )
{
dummyMonitor.reset();
DeleteEntriesJob.optimisticDeleteEntryRecursive( browserConnection, oldDn, oldEntry
.isReferral(), false, 0, dummyMonitor, monitor );
}
}
else
{
// no simulated rename operation
// report the exception to the real monitor
Exception exception = dummyMonitor.getException();
monitor.reportError( exception );
}
}
else
{
// we have another exception
// report it to the real monitor
Exception exception = dummyMonitor.getException();
monitor.reportError( exception );
}
}
// update model
if ( !monitor.errorsReported() && !monitor.isCanceled() )
{
// uncache old entry
browserConnection.uncacheEntryRecursive( oldEntry );
// remove old entry and add new entry to parent
IEntry parent = oldEntry.getParententry();
boolean hasMoreChildren = parent.hasMoreChildren();
parent.deleteChild( oldEntry );
List<StudioControl> controls = new ArrayList<StudioControl>();
if ( oldEntry.isReferral() )
{
controls.add( StudioControl.MANAGEDSAIT_CONTROL );
}
// Here we try to read the renamed entry to be able to send the right event notification.
// In some cases this don't work:
// - if there was a referral and the entry was created on another (master) server and not yet sync'ed to the current server
// So we use a dummy monitor to no bother the user with an error message.
dummyMonitor.reset();
newEntry = ReadEntryRunnable.getEntry( browserConnection, newDn, controls, dummyMonitor );
dummyMonitor.done();
if ( newEntry != null )
{
parent.addChild( newEntry );
}
parent.setHasMoreChildren( hasMoreChildren );