directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r689400 - in /directory/studio/trunk: ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/ ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ ldapbrowser-core/src/main/java/...
Date Wed, 27 Aug 2008 07:36:46 GMT
Author: seelmann
Date: Wed Aug 27 00:36:45 2008
New Revision: 689400

URL: http://svn.apache.org/viewvc?rev=689400&view=rev
Log:
Fix for DIRSTUDIO-244: Added 'overwrite 'option when copy/paste an entry

Modified:
    directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/EntryExistsCopyStrategyDialogImpl.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesJob.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifJob.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/ModelConverter.java

Modified: directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/EntryExistsCopyStrategyDialogImpl.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/EntryExistsCopyStrategyDialogImpl.java?rev=689400&r1=689399&r2=689400&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/EntryExistsCopyStrategyDialogImpl.java
(original)
+++ directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/EntryExistsCopyStrategyDialogImpl.java
Wed Aug 27 00:36:45 2008
@@ -61,9 +61,9 @@
 
     /** The ignore button. */
     private Button ignoreButton;
-//
-//    /** The overwrite button. */
-//    private Button overwriteButton;
+
+    /** The overwrite button. */
+    private Button overwriteButton;
 
     /** The rename button. */
     private Button renameButton;
@@ -128,10 +128,10 @@
         {
             strategy = EntryExistsCopyStrategy.IGNORE_AND_CONTINUE;
         }
-//        else if ( overwriteButton.getSelection() )
-//        {
-//            strategy = EntryExistsCopyStrategy.OVERWRITE_AND_CONTINUE;
-//        }
+        else if ( overwriteButton.getSelection() )
+        {
+            strategy = EntryExistsCopyStrategy.OVERWRITE_AND_CONTINUE;
+        }
         else if ( renameButton.getSelection() )
         {
             strategy = EntryExistsCopyStrategy.RENAME_AND_CONTINUE;
@@ -181,10 +181,9 @@
 
         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 );
+
+        overwriteButton = BaseWidgetUtils.createRadiobutton( group, "Overwrite entry and
continue", 2 );
+        overwriteButton.addSelectionListener( listener );
 
         renameButton = BaseWidgetUtils.createRadiobutton( group, "Rename entry and continue",
2 );
         renameButton.addSelectionListener( listener );
@@ -216,7 +215,6 @@
         if ( renameButton.getSelection() )
         {
             dnBuilderWidget.setEnabled( true );
-//            dnBuilderWidget.get
             getButton( IDialogConstants.OK_ID ).setEnabled( dnBuilderWidget.getRdn() != null
);
         }
         else

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesJob.java?rev=689400&r1=689399&r2=689400&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesJob.java
(original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/CopyEntriesJob.java
Wed Aug 27 00:36:45 2008
@@ -32,6 +32,8 @@
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 import javax.naming.ldap.Control;
@@ -41,8 +43,8 @@
 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.jobs.StudioProgressMonitor;
 import org.apache.directory.studio.connection.core.Connection.ReferralHandlingMethod;
+import org.apache.directory.studio.connection.core.jobs.StudioProgressMonitor;
 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;
@@ -256,13 +258,13 @@
                 SearchResult sr = entries.next();
                 LdapDN oldLdapDn = JNDIUtils.getDn( sr );
                 Rdn oldRdn = oldLdapDn.getRdn();
-                
+
                 // reuse attributes of the entry to copy
                 Attributes newAttributes = sr.getAttributes();
 
                 // compose new DN
                 Rdn newRdn = oldLdapDn.getRdn();
-                if( forceNewRdn != null )
+                if ( forceNewRdn != null )
                 {
                     newRdn = forceNewRdn;
                 }
@@ -287,7 +289,7 @@
                         dialog.setExistingEntry( targetBrowserConnection, newLdapDn );
                         dialog.open();
                         EntryExistsCopyStrategy strategy = dialog.getStrategy();
-//                        boolean rememberSelection = dialog.isRememberSelection();
+                        //                        boolean rememberSelection = dialog.isRememberSelection();
                         if ( strategy != null )
                         {
                             dummyMonitor.reset();
@@ -297,22 +299,49 @@
                                 case BREAK:
                                     monitor.setCanceled( true );
                                     break;
+
                                 case IGNORE_AND_CONTINUE:
                                     break;
-//                                case OVERWRITE_AND_CONTINUE:
-//                                    break;
+
+                                case OVERWRITE_AND_CONTINUE:
+                                    // create modification items
+                                    List<ModificationItem> mis = new ArrayList<ModificationItem>();
+                                    NamingEnumeration<? extends Attribute> all = newAttributes.getAll();
+                                    while ( all.hasMore() )
+                                    {
+                                        Attribute attribute = all.next();
+                                        ModificationItem mi = new ModificationItem( DirContext.REPLACE_ATTRIBUTE,
+                                            attribute );
+                                        mis.add( mi );
+                                    }
+
+                                    // modify entry
+                                    targetBrowserConnection.getConnection().getJNDIConnectionWrapper().modifyEntry(
+                                        newLdapDn.getUpName(), mis.toArray( new ModificationItem[mis.size()]
),
+                                        referralsHandlingMethod, null, dummyMonitor, null
);
+
+                                    // forece reloading of attributes
+                                    IEntry newEntry = targetBrowserConnection.getEntryFromCache(
newLdapDn );
+                                    if ( newEntry != null )
+                                    {
+                                        newEntry.setAttributesInitialized( false );
+                                    }
+                                    
+                                    break;
+
                                 case RENAME_AND_CONTINUE:
                                     Rdn renamedRdn = dialog.getRdn();
-                                    
+
                                     // apply renamed RDN to the attributes
                                     applyNewRdn( newAttributes, newRdn, renamedRdn );
-                                    
+
                                     // compose new DN
                                     newLdapDn = DnUtils.composeDn( renamedRdn, parentDn );
 
                                     // create entry
-                                    targetBrowserConnection.getConnection().getJNDIConnectionWrapper().createEntry(
newLdapDn.getUpName(),
-                                        newAttributes, referralsHandlingMethod, null, dummyMonitor,
null );
+                                    targetBrowserConnection.getConnection().getJNDIConnectionWrapper().createEntry(
+                                        newLdapDn.getUpName(), newAttributes, referralsHandlingMethod,
null,
+                                        dummyMonitor, null );
 
                                     break;
                             }
@@ -333,7 +362,7 @@
                 if ( !monitor.isCanceled() && !monitor.errorsReported() )
                 {
                     numberOfCopiedEntries++;
-                    
+
                     monitor.reportProgress( BrowserCoreMessages.bind( BrowserCoreMessages.model__copied_n_entries,
                         new String[]
                             { "" + numberOfCopiedEntries } ) ); //$NON-NLS-1$
@@ -371,7 +400,8 @@
         return numberOfCopiedEntries;
     }
 
-    private static void applyNewRdn(Attributes attributes, Rdn oldRdn, Rdn newRdn)
+
+    private static void applyNewRdn( Attributes attributes, Rdn oldRdn, Rdn newRdn )
     {
         // remove old RDN attributes and values
         for ( Iterator<AttributeTypeAndValue> it = oldRdn.iterator(); it.hasNext();
)
@@ -387,7 +417,7 @@
                 }
             }
         }
-        
+
         // add new RDN attributes and values
         for ( Iterator<AttributeTypeAndValue> it = newRdn.iterator(); it.hasNext();
)
         {

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifJob.java?rev=689400&r1=689399&r2=689400&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifJob.java
(original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifJob.java
Wed Aug 27 00:36:45 2008
@@ -57,15 +57,12 @@
 import org.apache.directory.studio.ldapbrowser.core.events.BulkModificationEvent;
 import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
 import org.apache.directory.studio.ldapbrowser.core.model.ConnectionException;
-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.IValue;
 import org.apache.directory.studio.ldapbrowser.core.utils.ModelConverter;
 import org.apache.directory.studio.ldapbrowser.core.utils.Utils;
 import org.apache.directory.studio.ldifparser.LdifFormatParameters;
 import org.apache.directory.studio.ldifparser.model.LdifEnumeration;
-import org.apache.directory.studio.ldifparser.model.LdifPart;
 import org.apache.directory.studio.ldifparser.model.container.LdifChangeAddRecord;
 import org.apache.directory.studio.ldifparser.model.container.LdifChangeDeleteRecord;
 import org.apache.directory.studio.ldifparser.model.container.LdifChangeModDnRecord;
@@ -462,30 +459,9 @@
                 // creation failed with Error 68, now try to update the existing entry
                 monitor.reset();
 
-                List<ModificationItem> mis = new ArrayList<ModificationItem>();
-                for ( IAttribute attribute : dummyEntry.getAttributes() )
-                {
-                    Attribute jndiAttribute = new BasicAttribute( attribute.getDescription()
);
-                    boolean isLdifPart = false;
-                    for ( IValue value : attribute.getValues() )
-                    {
-                        if ( value.getRawValue() instanceof LdifPart )
-                        {
-                            isLdifPart = true;
-                            break;
-                        }
-                        jndiAttribute.add( value.getRawValue() );
-                    }
-                    if ( !isLdifPart )
-                    {
-                        ModificationItem mi = new ModificationItem( DirContext.REPLACE_ATTRIBUTE,
jndiAttribute );
-                        mis.add( mi );
-                    }
-                }
-
-                browserConnection.getConnection().getJNDIConnectionWrapper().modifyEntry(
dn,
-                    mis.toArray( new ModificationItem[0] ), ReferralHandlingMethod.IGNORE,
getControls( record ),
-                    monitor, null );
+                ModificationItem[] mis = ModelConverter.entryToReplaceModificationItems(
dummyEntry );
+                browserConnection.getConnection().getJNDIConnectionWrapper().modifyEntry(
dn, mis,
+                    ReferralHandlingMethod.IGNORE, getControls( record ), monitor, null );
             }
         }
         else if ( record instanceof LdifChangeDeleteRecord )

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/ModelConverter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/ModelConverter.java?rev=689400&r1=689399&r2=689400&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/ModelConverter.java
(original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/ModelConverter.java
Wed Aug 27 00:36:45 2008
@@ -24,7 +24,13 @@
 /**
  * Utilities to convert between models
  */
+import java.util.ArrayList;
+import java.util.List;
+
 import javax.naming.InvalidNameException;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
 
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants;
@@ -53,7 +59,6 @@
 public class ModelConverter
 {
 
-
     /**
      * Converts the given {@link LdifContentRecord} to an {@link DummyEntry}.
      *
@@ -64,8 +69,8 @@
      *
      * @throws InvalidNameException
      */
-    public static DummyEntry ldifContentRecordToEntry( LdifContentRecord ldifContentRecord,
IBrowserConnection connection )
-        throws InvalidNameException
+    public static DummyEntry ldifContentRecordToEntry( LdifContentRecord ldifContentRecord,
+        IBrowserConnection connection ) throws InvalidNameException
     {
         return createIntern( ldifContentRecord, connection );
     }
@@ -81,8 +86,8 @@
      *
      * @throws InvalidNameException
      */
-    public static DummyEntry ldifChangeAddRecordToEntry( LdifChangeAddRecord ldifChangeAddRecord,
IBrowserConnection connection )
-        throws InvalidNameException
+    public static DummyEntry ldifChangeAddRecordToEntry( LdifChangeAddRecord ldifChangeAddRecord,
+        IBrowserConnection connection ) throws InvalidNameException
     {
         return createIntern( ldifChangeAddRecord, connection );
     }
@@ -98,7 +103,8 @@
      *
      * @throws InvalidNameException
      */
-    private static DummyEntry createIntern( LdifRecord ldifRecord, IBrowserConnection connection
) throws InvalidNameException
+    private static DummyEntry createIntern( LdifRecord ldifRecord, IBrowserConnection connection
)
+        throws InvalidNameException
     {
         LdifPart[] parts = ldifRecord.getParts();
 
@@ -283,6 +289,7 @@
         }
     }
 
+
     /**
      * Gets the string value from the given {@link IValue}. If the given
      * {@link IValue} is binary is is encoded according to the regquested
@@ -314,4 +321,40 @@
         }
         return s;
     }
+
+
+    /**
+     * Converts the entry to JNDI replace modification items. Each attribute
+     * of the entry will become a replace modification item. 
+     * 
+     * @param entry the entry to convert
+     * 
+     * @return the modification items
+     */
+    public static ModificationItem[] entryToReplaceModificationItems( IEntry entry )
+    {
+        List<ModificationItem> mis = new ArrayList<ModificationItem>();
+
+        for ( IAttribute attribute : entry.getAttributes() )
+        {
+            BasicAttribute jndiAttribute = new BasicAttribute( attribute.getDescription()
);
+            boolean isLdifPart = false;
+            for ( IValue value : attribute.getValues() )
+            {
+                if ( value.getRawValue() instanceof LdifPart )
+                {
+                    isLdifPart = true;
+                    break;
+                }
+                jndiAttribute.add( value.getRawValue() );
+            }
+            if ( !isLdifPart )
+            {
+                ModificationItem mi = new ModificationItem( DirContext.REPLACE_ATTRIBUTE,
jndiAttribute );
+                mis.add( mi );
+            }
+        }
+
+        return mis.toArray( new ModificationItem[mis.size()] );
+    }
 }



Mime
View raw message