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 2018/11/24 16:53:24 UTC

[directory-studio] 01/02: Migrate deleteEntry to LDAP API

This is an automated email from the ASF dual-hosted git repository.

seelmann pushed a commit to branch remove-jndi-provider-and-jndi-layer
in repository https://gitbox.apache.org/repos/asf/directory-studio.git

commit 262aff79ac4218943fb8c15a2f58041cf473cba9
Author: Stefan Seelmann <ma...@stefan-seelmann.de>
AuthorDate: Sat Nov 24 14:55:06 2018 +0100

    Migrate deleteEntry to LDAP API
---
 .../apache/directory/studio/connection/core/IJndiLogger.java |  3 ++-
 .../studio/connection/core/io/ConnectionWrapper.java         |  3 ++-
 .../core/io/api/DirectoryApiConnectionWrapper.java           | 10 +++++-----
 .../connection/core/io/jndi/LdifModificationLogger.java      |  4 ++--
 .../studio/connection/core/io/jndi/LdifSearchLogger.java     |  3 ++-
 .../studio/ldapbrowser/core/jobs/DeleteEntriesRunnable.java  |  2 +-
 .../studio/ldapbrowser/core/jobs/ImportDsmlRunnable.java     |  2 +-
 .../studio/ldapbrowser/core/jobs/ImportLdifRunnable.java     |  2 +-
 .../test/integration/core/ConnectionWrapperTestBase.java     | 12 +++---------
 9 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/IJndiLogger.java b/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/IJndiLogger.java
index 75633a3..ffd6d13 100644
--- a/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/IJndiLogger.java
+++ b/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/IJndiLogger.java
@@ -27,6 +27,7 @@ import javax.naming.ldap.Control;
 
 import org.apache.directory.api.ldap.model.entry.Entry;
 import org.apache.directory.api.ldap.model.message.Referral;
+import org.apache.directory.api.ldap.model.name.Dn;
 import org.apache.directory.studio.connection.core.Connection.AliasDereferencingMethod;
 import org.apache.directory.studio.connection.core.io.jndi.ReferralsInfo;
 import org.apache.directory.studio.connection.core.io.jndi.StudioSearchResult;
@@ -61,7 +62,7 @@ public interface IJndiLogger
      * @param ex the naming exception if an error occurred, null otherwise
      * 
      */
-    void logChangetypeDelete( Connection connection, final String dn, final Control[] controls,
+    void logChangetypeDelete( Connection connection, final Dn dn, final Control[] controls,
         NamingException ex );
 
 
diff --git a/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionWrapper.java b/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionWrapper.java
index 211781c..85ba9c4 100644
--- a/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionWrapper.java
+++ b/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/ConnectionWrapper.java
@@ -27,6 +27,7 @@ import javax.naming.directory.SearchControls;
 import javax.naming.ldap.Control;
 
 import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.name.Dn;
 import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor;
 import org.apache.directory.studio.connection.core.Connection.AliasDereferencingMethod;
 import org.apache.directory.studio.connection.core.Connection.ReferralHandlingMethod;
@@ -151,6 +152,6 @@ public interface ConnectionWrapper
      * @param monitor the progress monitor
      * @param referralsInfo the referrals info
      */
-    void deleteEntry( final String dn, final Control[] controls, final StudioProgressMonitor monitor,
+    void deleteEntry( final Dn dn, final Control[] controls, final StudioProgressMonitor monitor,
         final ReferralsInfo referralsInfo );
 }
diff --git a/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java b/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java
index a7dab85..ab0a090 100644
--- a/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java
+++ b/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/api/DirectoryApiConnectionWrapper.java
@@ -1051,7 +1051,7 @@ public class DirectoryApiConnectionWrapper implements ConnectionWrapper
     /**
      * {@inheritDoc}
      */
-    public void deleteEntry( final String dn, final Control[] controls, final StudioProgressMonitor monitor,
+    public void deleteEntry( final Dn dn, final Control[] controls, final StudioProgressMonitor monitor,
         final ReferralsInfo referralsInfo )
     {
         if ( connection.isReadOnly() )
@@ -1069,16 +1069,16 @@ public class DirectoryApiConnectionWrapper implements ConnectionWrapper
                 {
                     // Preparing the delete request
                     DeleteRequest request = new DeleteRequestImpl();
-                    request.setName( new Dn( dn ) );
+                    request.setName( dn );
                     request.addAllControls( convertControls( controls ) );
 
                     // Performing the delete operation
                     DeleteResponse deleteResponse = ldapConnection.delete( request );
 
                     // Handle referral
-                    ReferralHandlingDataConsumer consumer = referralHandlingData -> 
-                        referralHandlingData.connectionWrapper.deleteEntry( referralHandlingData.referralDn, controls,
-                            monitor, referralHandlingData.newReferralsInfo );
+                    ReferralHandlingDataConsumer consumer = referralHandlingData -> referralHandlingData.connectionWrapper
+                        .deleteEntry( new Dn( referralHandlingData.referralDn ), controls, monitor,
+                            referralHandlingData.newReferralsInfo );
                     
                     if ( checkAndHandleReferral( deleteResponse, monitor, referralsInfo, consumer ) )
                     {
diff --git a/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifModificationLogger.java b/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifModificationLogger.java
index 4e5f9f9..c107d1b 100644
--- a/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifModificationLogger.java
+++ b/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifModificationLogger.java
@@ -311,7 +311,7 @@ public class LdifModificationLogger implements IJndiLogger
     /**
      * {@inheritDoc}
      */
-    public void logChangetypeDelete( Connection connection, final String dn, final Control[] controls,
+    public void logChangetypeDelete( Connection connection, final Dn dn, final Control[] controls,
         NamingException ex )
     {
         if ( !isModificationLogEnabled() )
@@ -319,7 +319,7 @@ public class LdifModificationLogger implements IJndiLogger
             return;
         }
 
-        LdifChangeDeleteRecord record = new LdifChangeDeleteRecord( LdifDnLine.create( dn ) );
+        LdifChangeDeleteRecord record = new LdifChangeDeleteRecord( LdifDnLine.create( dn.getName() ) );
         addControlLines( record, controls );
         record.setChangeType( LdifChangeTypeLine.createDelete() );
         record.finish( LdifSepLine.create() );
diff --git a/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifSearchLogger.java b/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifSearchLogger.java
index 536c237..6b338e3 100644
--- a/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifSearchLogger.java
+++ b/plugins/connection.core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/LdifSearchLogger.java
@@ -49,6 +49,7 @@ import javax.naming.ldap.Control;
 import org.apache.commons.lang.StringUtils;
 import org.apache.directory.api.ldap.model.entry.Entry;
 import org.apache.directory.api.ldap.model.message.Referral;
+import org.apache.directory.api.ldap.model.name.Dn;
 import org.apache.directory.api.ldap.model.url.LdapUrl;
 import org.apache.directory.studio.connection.core.Connection;
 import org.apache.directory.studio.connection.core.Connection.AliasDereferencingMethod;
@@ -266,7 +267,7 @@ public class LdifSearchLogger implements IJndiLogger
     /**
      * {@inheritDoc}
      */
-    public void logChangetypeDelete( Connection connection, final String dn, final Control[] controls,
+    public void logChangetypeDelete( Connection connection, final Dn dn, final Control[] controls,
         NamingException ex )
     {
         // don't log changetypes
diff --git a/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/DeleteEntriesRunnable.java b/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/DeleteEntriesRunnable.java
index 9686822..8953543 100644
--- a/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/DeleteEntriesRunnable.java
+++ b/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/DeleteEntriesRunnable.java
@@ -380,7 +380,7 @@ public class DeleteEntriesRunnable implements StudioConnectionBulkRunnableWithPr
         if ( browserConnection.getConnection() != null )
         {
             browserConnection.getConnection().getConnectionWrapper()
-                .deleteEntry( dn.getName(), controls, monitor, null );
+                .deleteEntry( dn, controls, monitor, null );
         }
     }
 }
diff --git a/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportDsmlRunnable.java b/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportDsmlRunnable.java
index fed4f52..fef37da 100644
--- a/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportDsmlRunnable.java
+++ b/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportDsmlRunnable.java
@@ -427,7 +427,7 @@ public class ImportDsmlRunnable implements StudioConnectionBulkRunnableWithProgr
     {
         // Executing the del request
         browserConnection.getConnection().getConnectionWrapper()
-            .deleteEntry( request.getName().getName(), getControls( request ), monitor, null );
+            .deleteEntry( request.getName(), getControls( request ), monitor, null );
 
         // Creating the response
         if ( batchResponseDsml != null )
diff --git a/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifRunnable.java b/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifRunnable.java
index 6ff851b..d6a565f 100644
--- a/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifRunnable.java
+++ b/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ImportLdifRunnable.java
@@ -483,7 +483,7 @@ public class ImportLdifRunnable implements StudioConnectionBulkRunnableWithProgr
         {
             LdifChangeDeleteRecord changeDeleteRecord = ( LdifChangeDeleteRecord ) record;
             browserConnection.getConnection().getConnectionWrapper()
-                .deleteEntry( dn, getControls( changeDeleteRecord ), monitor, null );
+                .deleteEntry( new Dn( dn ), getControls( changeDeleteRecord ), monitor, null );
         }
         else if ( record instanceof LdifChangeModifyRecord )
         {
diff --git a/tests/test.integration.core/src/main/java/org/apache/directory/studio/test/integration/core/ConnectionWrapperTestBase.java b/tests/test.integration.core/src/main/java/org/apache/directory/studio/test/integration/core/ConnectionWrapperTestBase.java
index 94dc925..daaeb72 100644
--- a/tests/test.integration.core/src/main/java/org/apache/directory/studio/test/integration/core/ConnectionWrapperTestBase.java
+++ b/tests/test.integration.core/src/main/java/org/apache/directory/studio/test/integration/core/ConnectionWrapperTestBase.java
@@ -29,11 +29,9 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 import java.io.ByteArrayInputStream;
 import java.net.ConnectException;
-import java.net.UnknownHostException;
 import java.nio.channels.UnresolvedAddressException;
 import java.security.cert.Certificate;
 import java.security.cert.CertificateFactory;
@@ -42,12 +40,9 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.function.Function;
 
-import javax.naming.AuthenticationException;
-import javax.naming.CommunicationException;
 import javax.naming.LinkLoopException;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
-import javax.naming.directory.Attributes;
 import javax.naming.directory.DirContext;
 import javax.naming.directory.ModificationItem;
 import javax.naming.directory.SearchControls;
@@ -73,7 +68,6 @@ import org.apache.directory.studio.connection.core.ConnectionParameter;
 import org.apache.directory.studio.connection.core.ConnectionParameter.AuthenticationMethod;
 import org.apache.directory.studio.connection.core.ConnectionParameter.EncryptionMethod;
 import org.apache.directory.studio.connection.core.IReferralHandler;
-import org.apache.directory.studio.connection.core.Utils;
 import org.apache.directory.studio.connection.core.io.ConnectionWrapper;
 import org.apache.mina.util.AvailablePortFinder;
 import org.eclipse.core.runtime.NullProgressMonitor;
@@ -615,7 +609,7 @@ public abstract class ConnectionWrapperTestBase extends AbstractLdapTestUnit
 
         // delete referral entry 
         StudioProgressMonitor monitor = getProgressMonitor();
-        getConnectionWrapper( monitor ).deleteEntry( referralDn, null, monitor, null );
+        getConnectionWrapper( monitor ).deleteEntry( new Dn( referralDn ), null, monitor, null );
 
         // should have deleted the target entry
         assertFalse( monitor.isCanceled() );
@@ -636,7 +630,7 @@ public abstract class ConnectionWrapperTestBase extends AbstractLdapTestUnit
 
         // delete referral entry 
         StudioProgressMonitor monitor = getProgressMonitor();
-        getConnectionWrapper( monitor ).deleteEntry( referralDn, null, monitor, null );
+        getConnectionWrapper( monitor ).deleteEntry( new Dn( referralDn ), null, monitor, null );
 
         // should have deleted the target entry
         assertFalse( monitor.isCanceled() );
@@ -657,7 +651,7 @@ public abstract class ConnectionWrapperTestBase extends AbstractLdapTestUnit
 
         // delete referral entry 
         StudioProgressMonitor monitor = getProgressMonitor();
-        getConnectionWrapper( monitor ).deleteEntry( referralDn, null, monitor, null );
+        getConnectionWrapper( monitor ).deleteEntry( new Dn( referralDn ), null, monitor, null );
 
         // should not have deleted the target entry
         assertFalse( monitor.isCanceled() );