directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r807008 - in /directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl: EntryInjector.java SyncreplRunnerUI.java
Date Sun, 23 Aug 2009 19:40:26 GMT
Author: kayyagari
Date: Sun Aug 23 19:40:26 2009
New Revision: 807008

URL: http://svn.apache.org/viewvc?rev=807008&view=rev
Log:
added delete functionality to the test UI

Modified:
    directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/EntryInjector.java
    directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplRunnerUI.java

Modified: directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/EntryInjector.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/EntryInjector.java?rev=807008&r1=807007&r2=807008&view=diff
==============================================================================
--- directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/EntryInjector.java
(original)
+++ directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/EntryInjector.java
Sun Aug 23 19:40:26 2009
@@ -25,10 +25,17 @@
 import java.util.concurrent.Semaphore;
 
 import javax.swing.JButton;
+import javax.swing.JLabel;
 import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.border.TitledBorder;
 
 import org.apache.directory.shared.ldap.client.api.LdapConnection;
+import org.apache.directory.shared.ldap.client.api.messages.SearchResponse;
+import org.apache.directory.shared.ldap.client.api.messages.SearchResultEntry;
+import org.apache.directory.shared.ldap.cursor.Cursor;
 import org.apache.directory.shared.ldap.entry.client.DefaultClientEntry;
+import org.apache.directory.shared.ldap.filter.SearchScope;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -37,8 +44,6 @@
 /**
  * 
  * A utility class to inject entries into the syncrepl provider server.
- *
- * TODO add a feature to purge entries
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
@@ -48,11 +53,15 @@
     private JButton btnAdd;
     private JButton btnPause;
     private JButton btnKeepAdding;
-
+    private JButton btnDelete;
+    private JButton btnRandDelete;
+    private JTextField txtDn;
     private RunnerThread runner = new RunnerThread();
 
     private LdapConnection connection;
 
+    private SyncreplConfiguration config;
+    
     private static final Logger LOG = LoggerFactory.getLogger( EntryInjector.class );
 
 
@@ -88,6 +97,37 @@
     }
 
 
+    public void deleteEntry( String dn )
+    {
+        try
+        {
+            if( dn != null && dn.trim().length() > 0 )
+            {
+                connection.delete( dn );
+            }
+            else if( dn == null )
+            {
+                Cursor<SearchResponse> cursor = connection.search( config.getBaseDn(),
config.getFilter(), SearchScope.getSearchScope( config.getSearchScope() ), config.getAttributes().split(
"," ) );
+                cursor.beforeFirst();
+                if( cursor.next() && cursor.next() ) // to skip the baseDN
+                {
+                    SearchResponse res = cursor.get();
+                    if( res instanceof SearchResultEntry )
+                    {
+                        connection.delete( ( ( SearchResultEntry ) res ).getEntry().getDn()
 );
+                    }
+                }
+                
+                cursor.close();
+            }
+        }
+        catch( Exception e )
+        {
+            e.printStackTrace();
+        }
+    }
+    
+    
     public void close()
     {
         try
@@ -116,6 +156,25 @@
         btnKeepAdding = new JButton( "Keep Adding" );
         btnKeepAdding.addActionListener( this );
         add( btnKeepAdding );
+
+        JPanel innerPanel = new JPanel();
+        innerPanel.setBorder( new TitledBorder( "Delete Entry" ) );
+        
+        innerPanel.add( new JLabel( "DN:" ) );
+        
+        txtDn = new JTextField( 20 );
+        txtDn.addActionListener( this );
+        innerPanel.add( txtDn );
+
+        btnDelete = new JButton( "Delete" );
+        btnDelete.addActionListener( this );
+        innerPanel.add( btnDelete );
+        
+        btnRandDelete = new JButton( "Delete Random" );
+        btnRandDelete.addActionListener( this );
+        innerPanel.add( btnRandDelete );
+         
+        add( innerPanel );
     }
 
 
@@ -146,6 +205,14 @@
             btnPause.setEnabled( true );
             btnKeepAdding.setEnabled( false );
         }
+        else if ( src == btnRandDelete )
+        {
+            deleteEntry( null );
+        }
+        else if ( src == btnDelete )
+        {
+            deleteEntry( txtDn.getText() );
+        }
     }
 
     class RunnerThread extends Thread
@@ -213,9 +280,18 @@
     }
 
 
+    public void setConfig( SyncreplConfiguration config )
+    {
+        this.config = config;
+    }
+
+
     public void enable( boolean enable )
     {
         btnAdd.setEnabled( enable );
         btnKeepAdding.setEnabled( enable );
+        btnDelete.setEnabled( enable );
+        btnRandDelete.setEnabled( enable );
+        txtDn.setEnabled( enable );
     }
 }
\ No newline at end of file

Modified: directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplRunnerUI.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplRunnerUI.java?rev=807008&r1=807007&r2=807008&view=diff
==============================================================================
--- directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplRunnerUI.java
(original)
+++ directory/apacheds/trunk/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplRunnerUI.java
Sun Aug 23 19:40:26 2009
@@ -244,7 +244,8 @@
         entryInjector = new EntryInjector( provServerHost, provServerPort, provServerBindDn,
provServerPwd );
         entryInjector.enable( false );
         entryInjector.setBorder( new TitledBorder( "Entry Injector" ) );
-
+        entryInjector.setConfig( config );
+        
         JFrame frame = new JFrame();
         frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
         frame.setTitle( "Syncrepl consumer UI" );



Mime
View raw message