directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r407103 - /directory/branches/elecharny/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java
Date Tue, 16 May 2006 23:14:47 GMT
Author: elecharny
Date: Tue May 16 16:14:18 2006
New Revision: 407103

URL: http://svn.apache.org/viewcvs?rev=407103&view=rev
Log:
Added the changetype: delete command
fixed the unbind request

Modified:
    directory/branches/elecharny/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java

Modified: directory/branches/elecharny/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java
URL: http://svn.apache.org/viewcvs/directory/branches/elecharny/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java?rev=407103&r1=407102&r2=407103&view=diff
==============================================================================
--- directory/branches/elecharny/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java
(original)
+++ directory/branches/elecharny/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/ImportCommand.java
Tue May 16 16:14:18 2006
@@ -54,6 +54,7 @@
 import org.apache.directory.shared.ldap.codec.bind.BindResponse;
 import org.apache.directory.shared.ldap.codec.bind.LdapAuthentication;
 import org.apache.directory.shared.ldap.codec.bind.SimpleAuthentication;
+import org.apache.directory.shared.ldap.codec.del.DelRequest;
 import org.apache.directory.shared.ldap.codec.extended.ExtendedResponse;
 import org.apache.directory.shared.ldap.codec.unbind.UnBindRequest;
 import org.apache.directory.shared.ldap.codec.util.LdapResultEnum;
@@ -193,11 +194,11 @@
     }
 
     /**
-     * Prepare the LDIF entry and send it to the encoder, then wait for a
+     * Send the entry to the encoder, then wait for a
      * reponse from the LDAP server on the results of the operation.
      * 
-     * @param a_buf
-     *            The string buffer that contain the LDIF entry
+     * @param entry
+     *            The entry to add
      * @param msgId
      *            message id number
      */
@@ -261,6 +262,101 @@
         }
     }
 
+    /**
+     * Send the entry to the encoder, then wait for a
+     * reponse from the LDAP server on the results of the operation.
+     * 
+     * @param entry
+     *            The entry to add
+     * @param msgId
+     *            message id number
+     */
+    private void deleteEntry( Entry entry, int messageId ) throws IOException, DecoderException,
InvalidNameException,
+            NamingException, EncoderException
+    {
+        DelRequest delRequest = new DelRequest();
+
+        String dn = entry.getDn();
+
+        if ( isDebugEnabled() )
+        {
+            System.out.println( "Deleting entry " + dn );
+        }
+        
+        delRequest.setEntry(  new LdapDN( dn ) );
+        
+        LdapMessage message = new LdapMessage();
+
+        message.setProtocolOP( delRequest );
+        message.setMessageId( messageId );
+        ByteBuffer bb = message.encode( null );
+        bb.flip();
+
+        sendMessage( bb );
+
+        bb.clear();
+
+        LdapMessage response = readResponse( bb );
+
+        LdapResult result = response.getDelResponse().getLdapResult();
+
+        if ( result.getResultCode() == LdapResultEnum.SUCCESS )
+        {
+            if ( isDebugEnabled() )
+            {
+                System.out.println( "Delete of Entry " + entry.getDn() + " was successful"
);
+            }
+        }
+        else
+        {
+            System.err.println( "Delete of entry " + entry.getDn() + " failed for the following
reasons provided by the server:\n"
+                    + result.getErrorMessage() );
+        }
+    }
+
+    /**
+     * Send the change operation to the encoder, then wait for a
+     * reponse from the LDAP server on the results of the operation.
+     * 
+     * @param entry
+     *            The entry to add
+     * @param msgId
+     *            message id number
+     */
+    private void changeEntry( Entry entry, int messageId ) throws IOException, DecoderException,
InvalidNameException,
+            NamingException, EncoderException
+    {
+        switch ( entry.getChangeType() )
+        {
+            case Entry.ADD :
+                // No difference with the injection of new entries
+                addEntry( entry, messageId );
+                break;
+                
+            case Entry.DELETE :
+                deleteEntry( entry, messageId );
+                break;
+                
+            case Entry.MODIFY :
+                //changeModifyEntry( entry, messageId );
+                break;
+                
+            case Entry.MODDN :
+                //changeModDNEntry( entry, messageId );
+                break;
+                
+            case Entry.MODRDN :
+                //changeModRDNEntry( entry, messageId );
+                break;
+                
+        }
+    }
+
+    /**
+     * Bind to the ldap server
+     * 
+     * @param messageId The message Id
+     */
     private void bind( int messageId ) throws InvalidNameException, EncoderException, DecoderException,
IOException
     {
         BindRequest bindRequest = new BindRequest();
@@ -326,28 +422,8 @@
         ByteBuffer bb = message.encode( null );
         bb.flip();
 
-        connect();
         sendMessage( bb );
-
-        bb.clear();
-
-        LdapMessage response = readResponse( bb );
-
-        LdapResult result = response.getAddResponse().getLdapResult();
-
-        if ( result.getResultCode() == LdapResultEnum.SUCCESS )
-        {
-            if ( isDebugEnabled() )
-            {
-                System.out.println( "Unbinding of user " + user + " was successful" );
-            }
-        }
-        else
-        {
-            System.err.println( "Uninding of user " + user + " failed for the following reasons
provided by the server:\n"
-                    + result.getErrorMessage() );
-            System.exit( 1 );
-        }
+        System.out.println( "Unbinding of user " + user + " was successful" );
     }
 
     /**
@@ -385,7 +461,7 @@
 
         if ( ldifReader.containsEntries() )
         {
-            // Parse the file and inject every entri or every modification
+            // Parse the file and inject every entry
             Iterator entries = ldifReader.iterator();
             long t0 = System.currentTimeMillis();
             int nbAdd = 0;
@@ -415,15 +491,33 @@
         }
         else
         {
-            // Parse the file and inject every entri or every modification
-            Iterator changes = ldifReader.iterator();
+            // Parse the file and inject every modification
+            Iterator entries = ldifReader.iterator();
+            long t0 = System.currentTimeMillis();
+            int nbAdd = 0;
 
-            while ( changes.hasNext() )
+            while ( entries.hasNext() )
             {
-                ModificationItem modification = (ModificationItem) changes.next();
+                Entry entry = (Entry) entries.next();
+
+                changeEntry( entry, messageId++ );
+                nbAdd++;
+
+                if ( nbAdd % 10 == 0 )
+                {
+                    System.out.print( '.' );
+                }
 
-                // addchange( modification, messageId++ );
+                if ( nbAdd % 500 == 0 )
+                {
+                    System.out.println( nbAdd );
+                }
             }
+
+            long t1 = System.currentTimeMillis();
+
+            System.out.println( "Done!" );
+            System.out.println( nbAdd + " users changed in " + ( ( t1 - t0 ) / 1000 ) + "
seconds" );
         }
 
         // Logout to the server



Mime
View raw message