You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2007/11/25 23:15:33 UTC
svn commit: r598070 - in /directory/studio/trunk:
studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/
studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/
studio-ldapbrowser-commo...
Author: seelmann
Date: Sun Nov 25 14:15:32 2007
New Revision: 598070
URL: http://svn.apache.org/viewvc?rev=598070&view=rev
Log:
Partial fix of DIRSTUDIO-154: Using direct JNDI calls when copying entries. Added strategy selection if an entry to copy already exists.
Added:
directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/EntryExistsCopyStrategyDialogImpl.java (with props)
directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/EntryExistsCopyStrategyDialog.java (with props)
Modified:
directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/DnUtils.java
directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/PasteAction.java
directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DnBuilderWidget.java
directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesJob.java
Modified: directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/DnUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/DnUtils.java?rev=598070&r1=598069&r2=598070&view=diff
==============================================================================
--- directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/DnUtils.java (original)
+++ directory/studio/trunk/studio-connection-core/src/main/java/org/apache/directory/studio/connection/core/DnUtils.java Sun Nov 25 14:15:32 2007
@@ -137,8 +137,21 @@
sb.append( '=' );
sb.append( Rdn.escapeValue( rdnValues[i] ) );
}
- Rdn rdn = new Rdn( sb.toString() );
- return rdn;
+
+ String s = sb.toString();
+ try
+ {
+ if ( LdapDN.isValid( s ) )
+ {
+ Rdn rdn = new Rdn( sb.toString() );
+ return rdn;
+ }
+ }
+ catch ( Exception e )
+ {
+ }
+
+ throw new InvalidNameException( "RDN is invalid" );
}
}
Modified: directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/PasteAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/PasteAction.java?rev=598070&r1=598069&r2=598070&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/PasteAction.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/PasteAction.java Sun Nov 25 14:15:32 2007
@@ -21,6 +21,7 @@
package org.apache.directory.studio.ldapbrowser.common.actions;
+import org.apache.directory.studio.ldapbrowser.common.dialogs.EntryExistsCopyStrategyDialogImpl;
import org.apache.directory.studio.ldapbrowser.common.dialogs.ScopeDialog;
import org.apache.directory.studio.ldapbrowser.common.dnd.EntryTransfer;
import org.apache.directory.studio.ldapbrowser.common.dnd.ValuesTransfer;
@@ -169,7 +170,8 @@
scope = scopeDialog.getScope();
}
- new CopyEntriesJob( parent, entriesToPaste, scope ).execute();
+ new CopyEntriesJob( parent, entriesToPaste, scope, new EntryExistsCopyStrategyDialogImpl( Display.getDefault()
+ .getActiveShell() ) ).execute();
}
Added: directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/EntryExistsCopyStrategyDialogImpl.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/EntryExistsCopyStrategyDialogImpl.java?rev=598070&view=auto
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/EntryExistsCopyStrategyDialogImpl.java (added)
+++ directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/EntryExistsCopyStrategyDialogImpl.java Sun Nov 25 14:15:32 2007
@@ -0,0 +1,261 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.studio.ldapbrowser.common.dialogs;
+
+
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.Rdn;
+import org.apache.directory.studio.ldapbrowser.common.widgets.BaseWidgetUtils;
+import org.apache.directory.studio.ldapbrowser.common.widgets.DnBuilderWidget;
+import org.apache.directory.studio.ldapbrowser.common.widgets.WidgetModifyEvent;
+import org.apache.directory.studio.ldapbrowser.common.widgets.WidgetModifyListener;
+import org.apache.directory.studio.ldapbrowser.core.jobs.EntryExistsCopyStrategyDialog;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+
+/**
+ * A dialog to select the copy strategy if an entry already exists.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class EntryExistsCopyStrategyDialogImpl extends Dialog implements EntryExistsCopyStrategyDialog
+{
+
+ /** The dialog title. */
+ private String dialogTitle = "Select copy strategy";
+
+ /** The break button. */
+ private Button breakButton;
+
+ /** The ignore button. */
+ private Button ignoreButton;
+//
+// /** The overwrite button. */
+// private Button overwriteButton;
+
+ /** The rename button. */
+ private Button renameButton;
+//
+// /** The remember check box. */
+// private Button rememberCheckbox;
+
+ /** The DN builder widget. */
+ private DnBuilderWidget dnBuilderWidget;
+
+ /** The new RDN. */
+ private Rdn rdn;
+
+ /** The strategy */
+ private EntryExistsCopyStrategy strategy;
+
+ /** The remember flag */
+ private boolean isRememberStrategy;
+
+ private IBrowserConnection browserConnection;
+
+ private LdapDN dn;
+
+
+ /**
+ * Creates a new instance of ScopeDialog.
+ *
+ * @param parentShell the parent shell
+ * @param dialogTitle the dialog title
+ * @param multipleEntriesSelected the multiple entries selected
+ */
+ public EntryExistsCopyStrategyDialogImpl( Shell parentShell )
+ {
+ super( parentShell );
+ super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
+ }
+
+
+ /**
+ * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
+ */
+ protected void configureShell( Shell shell )
+ {
+ super.configureShell( shell );
+ shell.setText( dialogTitle );
+ }
+
+
+ /**
+ * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+ */
+ protected void okPressed()
+ {
+ rdn = null;
+// isRememberStrategy = rememberCheckbox.getSelection() && rememberCheckbox.isEnabled();
+
+ if ( breakButton.getSelection() )
+ {
+ strategy = EntryExistsCopyStrategy.BREAK;
+ }
+ else if ( ignoreButton.getSelection() )
+ {
+ strategy = EntryExistsCopyStrategy.IGNORE_AND_CONTINUE;
+ }
+// else if ( overwriteButton.getSelection() )
+// {
+// strategy = EntryExistsCopyStrategy.OVERWRITE_AND_CONTINUE;
+// }
+ else if ( renameButton.getSelection() )
+ {
+ strategy = EntryExistsCopyStrategy.RENAME_AND_CONTINUE;
+ rdn = dnBuilderWidget.getRdn();
+ }
+
+ super.okPressed();
+ }
+
+
+ /**
+ * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
+ */
+ protected void createButtonsForButtonBar( Composite parent )
+ {
+ createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false );
+ //createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
+ }
+
+
+ /**
+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ protected Control createDialogArea( Composite parent )
+ {
+ Composite composite = ( Composite ) super.createDialogArea( parent );
+ GridData gd = new GridData( GridData.FILL_BOTH );
+ composite.setLayoutData( gd );
+
+ String text = "The entry " + dn.getUpName() + " already exists. Please select how to proceed.";
+ BaseWidgetUtils.createLabel( composite, text, 1 );
+
+ Composite group2 = BaseWidgetUtils.createGroup( composite, "", 1 );
+ Composite group = BaseWidgetUtils.createColumnContainer( group2, 2, 1 );
+
+ SelectionListener listener = new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ validate();
+ }
+ };
+
+ breakButton = BaseWidgetUtils.createRadiobutton( group, "Stop copy process", 2 );
+ breakButton.setSelection( true );
+ breakButton.addSelectionListener( listener );
+
+ ignoreButton = BaseWidgetUtils.createRadiobutton( group, "Ignore entry and continue", 2 );
+ ignoreButton.addSelectionListener( listener );
+//
+// overwriteButton = BaseWidgetUtils.createRadiobutton( group, "Overwrite entry and continue", 2 );
+// overwriteButton.setEnabled( false );
+// overwriteButton.addSelectionListener( listener );
+
+ renameButton = BaseWidgetUtils.createRadiobutton( group, "Rename entry and continue", 2 );
+ renameButton.addSelectionListener( listener );
+
+ BaseWidgetUtils.createRadioIndent( group, 1 );
+ dnBuilderWidget = new DnBuilderWidget( true, false );
+ dnBuilderWidget.addWidgetModifyListener( new WidgetModifyListener()
+ {
+ public void widgetModified( WidgetModifyEvent event )
+ {
+ validate();
+ }
+ } );
+ dnBuilderWidget.createContents( group );
+ dnBuilderWidget.setInput( browserConnection, browserConnection.getSchema().getAttributeTypeDescriptionNames(),
+ dn.getRdn(), null );
+
+// rememberCheckbox = BaseWidgetUtils.createCheckbox( composite, "Remember decision", 2 );
+
+ validate();
+
+ applyDialogFont( composite );
+ return composite;
+ }
+
+
+ private void validate()
+ {
+ dnBuilderWidget.setEnabled( renameButton.getSelection() );
+ if ( renameButton.getSelection() )
+ {
+ getButton( IDialogConstants.OK_ID ).setEnabled( dnBuilderWidget.getRdn() != null );
+ }
+// rememberCheckbox.setEnabled( overwriteButton.getSelection() || ignoreButton.getSelection() );
+ }
+
+
+ public int open()
+ {
+ final int[] result = new int[1];
+ Display.getDefault().syncExec( new Runnable()
+ {
+ public void run()
+ {
+ result[0] = EntryExistsCopyStrategyDialogImpl.super.open();
+ }
+ } );
+ return result[0];
+ }
+
+
+ public EntryExistsCopyStrategy getStrategy()
+ {
+ return strategy;
+ }
+
+
+ public Rdn getRdn()
+ {
+ return rdn;
+ }
+
+
+ public boolean isRememberSelection()
+ {
+ return isRememberStrategy;
+ }
+
+
+ public void setExistingEntry( IBrowserConnection browserConnection, LdapDN dn )
+ {
+ this.browserConnection = browserConnection;
+ this.dn = dn;
+ }
+}
Propchange: directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/EntryExistsCopyStrategyDialogImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DnBuilderWidget.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DnBuilderWidget.java?rev=598070&r1=598069&r2=598070&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DnBuilderWidget.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DnBuilderWidget.java Sun Nov 25 14:15:32 2007
@@ -82,9 +82,15 @@
/** The selected parent DN. */
private LdapDN parentDn;
+
+ /** The entry widget label. */
+ private Label parentEntryLabel;
/** The entry widget to enter/select the parent DN. */
private EntryWidget parentEntryWidget;
+
+ /** The RDN label */
+ private Label rdnLabel;
/** The composite that contains the RdnLines. */
private Composite rdnComposite;
@@ -94,6 +100,9 @@
/** The list of RdnLines. */
private ArrayList<RdnLine> rdnLineList;
+
+ /** The preview label. */
+ private Label previewLabel;
/** The preview text. */
private Text previewText;
@@ -234,7 +243,7 @@
// draw parent
if ( showParent )
{
- BaseWidgetUtils.createLabel( composite, "Parent:", 1 );
+ parentEntryLabel = BaseWidgetUtils.createLabel( composite, "Parent:", 1 );
parentEntryWidget = new EntryWidget();
parentEntryWidget.createWidget( composite );
parentEntryWidget.addWidgetModifyListener( new WidgetModifyListener()
@@ -251,7 +260,7 @@
// draw RDN group
if ( showRDN )
{
- BaseWidgetUtils.createLabel( composite, "RDN:", 1 );
+ rdnLabel = BaseWidgetUtils.createLabel( composite, "RDN:", 1 );
rdnComposite = BaseWidgetUtils.createColumnContainer( composite, 5, 2 );
rdnLineList = new ArrayList<RdnLine>();
BaseWidgetUtils.createSpacer( composite, 3 );
@@ -260,7 +269,7 @@
// draw dn/rdn preview
if ( showRDN )
{
- BaseWidgetUtils.createLabel( composite, showParent ? "DN Preview: " : "RDN Preview: ", 1 );
+ previewLabel = BaseWidgetUtils.createLabel( composite, showParent ? "DN Preview: " : "RDN Preview: ", 1 );
previewText = BaseWidgetUtils.createReadonlyText( composite, "", 2 );
BaseWidgetUtils.createSpacer( composite, 3 );
}
@@ -295,7 +304,6 @@
*/
public void validate()
{
-
Exception rdnE = null;
if ( showRDN )
{
@@ -596,6 +604,39 @@
/** The rdn delete button. */
private Button rdnDeleteButton;
+ }
+
+
+ /**
+ * Enables or disables this widget.
+ *
+ * @param b true to enable, false to disable
+ */
+ public void setEnabled( boolean b )
+ {
+ if ( parentEntryWidget != null )
+ {
+ parentEntryLabel.setEnabled( b );
+ parentEntryWidget.setEnabled( b );
+ }
+ if ( rdnComposite != null && rdnLineList != null )
+ {
+ rdnLabel.setEnabled( b );
+ rdnComposite.setEnabled( b );
+ for ( RdnLine rdnLine : rdnLineList )
+ {
+ rdnLine.rdnTypeCombo.setEnabled( b );
+ rdnLine.rdnEqualsLabel.setEnabled( b );
+ rdnLine.rdnValueText.setEnabled( b );
+ rdnLine.rdnAddButton.setEnabled( b );
+ rdnLine.rdnDeleteButton.setEnabled( b && rdnLineList.size() > 1 );
+ }
+ }
+ if ( previewText != null )
+ {
+ previewLabel.setEnabled( b );
+ previewText.setEnabled( b );
+ }
}
}
Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesJob.java?rev=598070&r1=598069&r2=598070&view=diff
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesJob.java (original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesJob.java Sun Nov 25 14:15:32 2007
@@ -26,34 +26,39 @@
import java.util.Iterator;
import java.util.List;
-import javax.naming.InvalidNameException;
+import javax.naming.NameAlreadyBoundException;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
import org.apache.directory.shared.ldap.name.AttributeTypeAndValue;
+import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.name.Rdn;
import org.apache.directory.studio.connection.core.Connection;
import org.apache.directory.studio.connection.core.DnUtils;
import org.apache.directory.studio.connection.core.StudioProgressMonitor;
+import org.apache.directory.studio.connection.core.io.jndi.JNDIConnectionWrapper;
import org.apache.directory.studio.ldapbrowser.core.BrowserCoreMessages;
import org.apache.directory.studio.ldapbrowser.core.events.ChildrenInitializedEvent;
import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
+import org.apache.directory.studio.ldapbrowser.core.jobs.EntryExistsCopyStrategyDialog.EntryExistsCopyStrategy;
import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
-import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult;
-import org.apache.directory.studio.ldapbrowser.core.model.IValue;
-import org.apache.directory.studio.ldapbrowser.core.model.SearchParameter;
-import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.AliasDereferencingMethod;
-import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection.ReferralHandlingMethod;
import org.apache.directory.studio.ldapbrowser.core.model.ISearch.SearchScope;
-import org.apache.directory.studio.ldapbrowser.core.model.impl.Attribute;
-import org.apache.directory.studio.ldapbrowser.core.model.impl.Entry;
-import org.apache.directory.studio.ldapbrowser.core.model.impl.Search;
-import org.apache.directory.studio.ldapbrowser.core.model.impl.Value;
-import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils;
+import org.apache.directory.studio.ldapbrowser.core.utils.JNDIUtils;
/**
* Job to copy entries asynchronously.
+ *
+ * TODO: implement overwrite strategy
+ * TODO: implement remember selection
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
@@ -70,6 +75,9 @@
/** The copy scope */
private SearchScope scope;
+ /** The dialog to ask for the strategy */
+ private EntryExistsCopyStrategyDialog dialog;
+
/**
* Creates a new instance of CopyEntriesJob.
@@ -77,12 +85,15 @@
* @param parent the parent entry
* @param entriesToCopy the entries to copy
* @param scope the copy scope
+ * @param dialog the dialog
*/
- public CopyEntriesJob( final IEntry parent, final IEntry[] entriesToCopy, SearchScope scope )
+ public CopyEntriesJob( final IEntry parent, final IEntry[] entriesToCopy, SearchScope scope,
+ EntryExistsCopyStrategyDialog dialog )
{
this.parent = parent;
this.entriesToCopy = entriesToCopy;
this.scope = scope;
+ this.dialog = dialog;
setName( entriesToCopy.length == 1 ? BrowserCoreMessages.jobs__copy_entries_name_1
: BrowserCoreMessages.jobs__copy_entries_name_n );
}
@@ -126,6 +137,10 @@
if ( scope == SearchScope.OBJECT || scope == SearchScope.ONELEVEL || scope == SearchScope.SUBTREE )
{
+ StudioProgressMonitor dummyMonitor = new StudioProgressMonitor( monitor );
+ int copyScope = scope == SearchScope.SUBTREE ? SearchControls.SUBTREE_SCOPE
+ : scope == SearchScope.ONELEVEL ? SearchControls.ONELEVEL_SCOPE : SearchControls.OBJECT_SCOPE;
+
int num = 0;
for ( int i = 0; !monitor.isCanceled() && i < entriesToCopy.length; i++ )
{
@@ -134,7 +149,8 @@
if ( scope == SearchScope.OBJECT
|| !parent.getDn().getNormName().endsWith( entryToCopy.getDn().getNormName() ) )
{
- num = copyEntryRecursive( entryToCopy, parent, scope, num, monitor );
+ num = copyEntry( entryToCopy.getBrowserConnection(), entryToCopy.getDn(), parent.getDn(),
+ copyScope, num, dummyMonitor, monitor );
}
else
{
@@ -166,214 +182,157 @@
}
- /**
- * Copies the entry recursive.
- *
- * @param entryToCopy the entry to copy
- * @param parent the parent entry
- * @param scope the copy scope
- * @param num the number of copied entries
- * @param monitor the progress monitor
- *
- * @return the number of copied entries
- */
- private int copyEntryRecursive( IEntry entryToCopy, IEntry parent, SearchScope scope, int num, StudioProgressMonitor monitor )
+ private int copyEntry( IBrowserConnection browserConnection, LdapDN dnToCopy, LdapDN parentDn, int scope,
+ int numberOfCopiedEntries, StudioProgressMonitor dummyMonitor, StudioProgressMonitor monitor )
+ {
+ SearchControls searchControls = new SearchControls();
+ searchControls.setCountLimit( 1 );
+ searchControls.setReturningAttributes( new String[]
+ { ISearch.ALL_USER_ATTRIBUTES, IAttribute.REFERRAL_ATTRIBUTE } );
+ searchControls.setSearchScope( SearchControls.OBJECT_SCOPE );
+ NamingEnumeration<SearchResult> result = browserConnection.getConnection().getJNDIConnectionWrapper().search(
+ dnToCopy.getUpName(), ISearch.FILTER_TRUE, searchControls, "never", JNDIConnectionWrapper.REFERRAL_IGNORE,
+ null, monitor, null );
+
+ numberOfCopiedEntries = copyEntryRecursive( browserConnection, result, parentDn, scope, numberOfCopiedEntries,
+ dummyMonitor, monitor );
+
+ return numberOfCopiedEntries;
+ }
+
+
+ private int copyEntryRecursive( IBrowserConnection browserConnection, NamingEnumeration<SearchResult> entries,
+ LdapDN parentDn, int scope, int numberOfCopiedEntries, StudioProgressMonitor dummyMonitor,
+ StudioProgressMonitor monitor )
{
- // TODO: use paged search
try
{
- // TODO: use JNDI here!!!
- SearchParameter param = new SearchParameter();
- param.setSearchBase( entryToCopy.getDn() );
- param.setFilter( ISearch.FILTER_TRUE );
- param.setScope( SearchScope.OBJECT );
- param.setAliasesDereferencingMethod( AliasDereferencingMethod.NEVER );
- param.setReferralsHandlingMethod( ReferralHandlingMethod.IGNORE );
- param.setReturningAttributes( new String[]
- { ISearch.ALL_USER_ATTRIBUTES, IAttribute.REFERRAL_ATTRIBUTE } );
- ISearch search = new Search( entryToCopy.getBrowserConnection(), param );
-
- SearchJob.searchAndUpdateModel( entryToCopy.getBrowserConnection(), search, monitor );
-
- ISearchResult[] srs = search.getSearchResults();
- if ( !monitor.isCanceled() && srs != null && srs.length == 1 )
+ while ( !monitor.isCanceled() && entries.hasMore() )
{
- entryToCopy = srs[0].getEntry();
- IAttribute[] attributesToCopy = entryToCopy.getAttributes();
+ SearchResult sr = entries.next();
- // create new entry
- Rdn rdn = entryToCopy.getRdn();
- IEntry newEntry = new Entry( parent, rdn );
-
- // change RDN if entry already exists
- StudioProgressMonitor testMonitor = new StudioProgressMonitor( monitor );
- IEntry testEntry = ReadEntryJob.getEntry( parent.getBrowserConnection(), newEntry.getDn(), testMonitor );
- if ( testEntry != null )
- {
- Object rdnValue = rdn.getUpValue();
- String newRdnValue = BrowserCoreMessages.bind( BrowserCoreMessages.copy_n_of_s, "", rdnValue ); //$NON-NLS-1$
- Rdn newRdn = getNewRdn( rdn, newRdnValue );
- newEntry = new Entry( parent, newRdn );
- testEntry = ReadEntryJob.getEntry( parent.getBrowserConnection(), newEntry.getDn(), testMonitor );
- for ( int i = 2; testEntry != null; i++ )
- {
- newRdnValue = BrowserCoreMessages.bind( BrowserCoreMessages.copy_n_of_s, i + " ", rdnValue ); //$NON-NLS-1$
- newRdn = getNewRdn( rdn, newRdnValue );
- newEntry = new Entry( parent, newRdn );
- testEntry = ReadEntryJob.getEntry( parent.getBrowserConnection(), newEntry.getDn(), testMonitor );
- }
- }
+ // compose new DN
+ LdapDN oldLdapDn = JNDIUtils.getDn( sr );
+ String oldDn = oldLdapDn.getUpName();
+ Rdn oldRdn = oldLdapDn.getRdn();
+ LdapDN newLdapDn = DnUtils.composeDn( oldRdn, parentDn );
+ String newDn = newLdapDn.getUpName();
// copy attributes
- for ( int i = 0; i < attributesToCopy.length; i++ )
- {
- IAttribute attributeToCopy = attributesToCopy[i];
+ Attributes oldAttributes = sr.getAttributes();
+ Attributes newAttributes = oldAttributes;
- if ( SchemaUtils.isModifyable( attributeToCopy.getAttributeTypeDescription() )
- || IAttribute.REFERRAL_ATTRIBUTE.equalsIgnoreCase( attributeToCopy.getDescription() ) )
- {
- IAttribute newAttribute = new Attribute( newEntry, attributeToCopy.getDescription() );
- newEntry.addAttribute( newAttribute );
- IValue[] valuesToCopy = attributeToCopy.getValues();
- for ( int j = 0; j < valuesToCopy.length; j++ )
- {
- IValue valueToCopy = valuesToCopy[j];
- IValue newValue = new Value( newAttribute, valueToCopy.getRawValue() );
- newAttribute.addValue( newValue );
- }
- }
- }
+ // create entry
+ browserConnection.getConnection().getJNDIConnectionWrapper().createEntry( newDn, newAttributes, null,
+ dummyMonitor );
- // check if RDN attributes ar present
- Rdn newRdn = newEntry.getRdn();
- Iterator<AttributeTypeAndValue> atavIterator = newRdn.iterator();
- while(atavIterator.hasNext())
+ while ( dummyMonitor.errorsReported() )
{
- AttributeTypeAndValue atav = atavIterator.next();
- IAttribute rdnAttribute = newEntry.getAttribute( atav.getUpType() );
- if ( rdnAttribute != null )
+ if ( dummyMonitor.getException() instanceof NameAlreadyBoundException )
{
- IValue[] values = rdnAttribute.getValues();
- for ( int ii = 0; ii < values.length; ii++ )
+ // open dialog
+ dialog.setExistingEntry( browserConnection, newLdapDn );
+ dialog.open();
+ EntryExistsCopyStrategy strategy = dialog.getStrategy();
+// boolean rememberSelection = dialog.isRememberSelection();
+ if ( strategy != null )
{
- if ( atav.getUpValue().equals( values[ii].getRawValue() ) )
- {
- rdnAttribute.deleteValue( values[ii] );
- }
- if ( rdnAttribute.getValueSize() == 0 )
+ dummyMonitor.reset();
+
+ switch ( strategy )
{
- newEntry.deleteAttribute( rdnAttribute );
+ case BREAK:
+ monitor.setCanceled( true );
+ break;
+ case IGNORE_AND_CONTINUE:
+ break;
+// case OVERWRITE_AND_CONTINUE:
+// break;
+ case RENAME_AND_CONTINUE:
+ Rdn renamedRdn = dialog.getRdn();
+ for ( Iterator<AttributeTypeAndValue> it = oldRdn.iterator(); it.hasNext(); )
+ {
+ AttributeTypeAndValue atav = it.next();
+ Attribute attribute = newAttributes.get( atav.getUpType() );
+ if ( attribute != null )
+ {
+ attribute.remove( atav.getUpValue() );
+ if ( attribute.size() == 0 )
+ {
+ newAttributes.remove( atav.getUpType() );
+ }
+ }
+ }
+ for ( Iterator<AttributeTypeAndValue> it = renamedRdn.iterator(); it.hasNext(); )
+ {
+ AttributeTypeAndValue atav = it.next();
+ Attribute attribute = newAttributes.get( atav.getUpType() );
+ if ( attribute == null )
+ {
+ attribute = new BasicAttribute( atav.getUpType() );
+ newAttributes.put( attribute );
+ }
+ if ( !attribute.contains( atav.getUpValue() ) )
+ {
+ attribute.add( atav.getUpValue() );
+ }
+ }
+
+ newLdapDn = DnUtils.composeDn( renamedRdn, parentDn );
+ newDn = newLdapDn.getUpName();
+
+ browserConnection.getConnection().getJNDIConnectionWrapper().createEntry( newDn,
+ newAttributes, null, dummyMonitor );
+
+ break;
}
}
- }
- }
- atavIterator = newRdn.iterator();
- while(atavIterator.hasNext())
- {
- AttributeTypeAndValue atav = atavIterator.next();
- IAttribute rdnAttribute = newEntry.getAttribute( atav.getUpType() );
- if ( rdnAttribute == null )
- {
- rdnAttribute = new Attribute( newEntry, atav.getUpType() );
- newEntry.addAttribute( rdnAttribute );
- rdnAttribute.addValue( new Value( rdnAttribute, atav.getUpValue() ) );
+ else
+ {
+ monitor.reportError( dummyMonitor.getException() );
+ dummyMonitor.reset();
+ }
}
else
{
- boolean mustAdd = true;
- IValue[] values = rdnAttribute.getValues();
- for ( int ii = 0; ii < values.length; ii++ )
- {
- if ( atav.getUpValue().equals( values[ii].getStringValue() ) )
- {
- mustAdd = false;
- break;
- }
- }
- if ( mustAdd )
- {
- rdnAttribute.addValue( new Value( rdnAttribute, atav.getUpValue() ) );
- }
+ monitor.reportError( dummyMonitor.getException() );
+ dummyMonitor.reset();
}
}
- CreateEntryJob.createEntry( newEntry.getBrowserConnection(), newEntry, monitor );
- newEntry.setHasChildrenHint( false );
-
- num++;
- monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.model__copied_n_entries,
- new String[]
- { Integer.toString( num ) } ) );
-
- // check for children
- if ( !monitor.isCanceled() && ( scope == SearchScope.ONELEVEL || scope == SearchScope.SUBTREE ) )
+ if ( !monitor.isCanceled() && !monitor.errorsReported() )
{
- // TODO: use JNDI here!!!
- SearchParameter subParam = new SearchParameter();
- subParam.setSearchBase( entryToCopy.getDn() );
- subParam.setFilter( ISearch.FILTER_TRUE );
- subParam.setScope( SearchScope.ONELEVEL );
- subParam.setReturningAttributes( ISearch.NO_ATTRIBUTES );
- ISearch subSearch = new Search( entryToCopy.getBrowserConnection(), subParam );
- SearchJob.searchAndUpdateModel( entryToCopy.getBrowserConnection(), subSearch, monitor );
+ numberOfCopiedEntries++;
- ISearchResult[] subSrs = subSearch.getSearchResults();
- if ( !monitor.isCanceled() && subSrs != null && subSrs.length > 0 )
+ // copy recursively
+ if ( scope == SearchControls.ONELEVEL_SCOPE || scope == SearchControls.SUBTREE_SCOPE )
{
- for ( int i = 0; i < subSrs.length; i++ )
- {
- ISearchResult subSearchResult = subSrs[i];
- IEntry childEntry = subSearchResult.getEntry();
+ SearchControls searchControls = new SearchControls();
+ searchControls.setCountLimit( 0 );
+ searchControls.setReturningAttributes( new String[]
+ { ISearch.ALL_USER_ATTRIBUTES, IAttribute.REFERRAL_ATTRIBUTE } );
+ searchControls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+ NamingEnumeration<SearchResult> childEntries = browserConnection.getConnection()
+ .getJNDIConnectionWrapper().search( oldDn, ISearch.FILTER_TRUE, searchControls, "never",
+ JNDIConnectionWrapper.REFERRAL_IGNORE, null, monitor, null );
- if ( scope == SearchScope.ONELEVEL )
- {
- num = this
- .copyEntryRecursive( childEntry, newEntry,SearchScope.OBJECT, num, monitor );
- }
- else if ( scope == SearchScope.SUBTREE )
- {
- num = this.copyEntryRecursive( childEntry, newEntry, SearchScope.SUBTREE, num,
- monitor );
- }
+ if ( scope == SearchControls.ONELEVEL_SCOPE )
+ {
+ scope = SearchControls.OBJECT_SCOPE;
}
+ numberOfCopiedEntries = copyEntryRecursive( browserConnection, childEntries, newLdapDn, scope,
+ numberOfCopiedEntries, dummyMonitor, monitor );
}
}
}
}
- catch ( Exception e )
+ catch ( NamingException e )
{
monitor.reportError( e );
}
- return num;
- }
-
- /**
- * Gets the new rdn.
- *
- * @param rdn the rdn
- * @param newRdnValue the new rdn value
- *
- * @return the new rdn
- * @throws InvalidNameException
- */
- private Rdn getNewRdn( Rdn rdn, String newRdnValue ) throws InvalidNameException
- {
- String[] rdnTypes = new String[rdn.size()];
- String[] rdnValues = new String[rdn.size()];
- int i = 0;
- Iterator<AttributeTypeAndValue> atavIterator = rdn.iterator();
- while(atavIterator.hasNext())
- {
- AttributeTypeAndValue atav = atavIterator.next();
- rdnTypes[i] = atav.getUpType();
- rdnValues[i] = ( String ) atav.getUpValue();
- i++;
- }
- rdnValues[0] = newRdnValue;
- Rdn newRdn = DnUtils.composeRdn( rdnTypes, rdnValues );
- return newRdn;
+ return numberOfCopiedEntries;
}
}
Added: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/EntryExistsCopyStrategyDialog.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/EntryExistsCopyStrategyDialog.java?rev=598070&view=auto
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/EntryExistsCopyStrategyDialog.java (added)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/EntryExistsCopyStrategyDialog.java Sun Nov 25 14:15:32 2007
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.studio.ldapbrowser.core.jobs;
+
+
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.name.Rdn;
+import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
+
+
+/**
+ * A dialog to select the copy strategy if an entry already exists.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface EntryExistsCopyStrategyDialog
+{
+
+ /**
+ * Sets the existing entry.
+ *
+ * @param browserConnection the browser connection
+ * @param newLdapDn the new DN
+ */
+ void setExistingEntry( IBrowserConnection browserConnection, LdapDN newLdapDn );
+
+
+ /**
+ * Gets the copy strategy.
+ *
+ * @return the copy strategy
+ */
+ EntryExistsCopyStrategy getStrategy();
+
+
+ /**
+ * Gets the RDN if {@link EntryExistsCopyStrategy.RENAME_AND_CONTINUE} was selected.
+ * Returns null if another strategy was selected.
+ *
+ * @return the RDN
+ */
+ Rdn getRdn();
+
+
+ /**
+ * Returns true to remember the selected copy strategy.
+ *
+ * @return true, to remember the selected copy strategy
+ */
+ boolean isRememberSelection();
+
+
+ /**
+ * Opens the dialog.
+ *
+ * @return the status code
+ */
+ int open();
+
+ /**
+ * Enum for the copy strategy.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+ public enum EntryExistsCopyStrategy
+ {
+
+ /** Break strategy, don't continue copy process. */
+ BREAK,
+
+ /** Ignore the entry to copy and continue the copy process. */
+ IGNORE_AND_CONTINUE,
+
+ /** Overwrite the entry to copy and continue the copy process. */
+ OVERWRITE_AND_CONTINUE,
+
+ /** Rename the entry to copy and continue the copy process. */
+ RENAME_AND_CONTINUE;
+ }
+
+}
Propchange: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/EntryExistsCopyStrategyDialog.java
------------------------------------------------------------------------------
svn:mime-type = text/plain