directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ersi...@apache.org
Subject svn commit: r440038 - in /directory/sandbox/ersiner/sptriggerdemo/src/main: java/sptriggerdemo/ java/sptriggerdemo/common/ resources/
Date Mon, 04 Sep 2006 11:59:55 GMT
Author: ersiner
Date: Mon Sep  4 04:59:55 2006
New Revision: 440038

URL: http://svn.apache.org/viewvc?view=rev&rev=440038
Log:
Removed the mess.
Added a real world SP example.

Added:
    directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/SPMainDemo.java
    directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/common/
    directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/common/BulkOperations.java
    directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/common/Greeter.java
    directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/common/MailingListManager.java
Removed:
    directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/DemoTool.java
    directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/Greeter.java
    directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/MailingListManager.java
Modified:
    directory/sandbox/ersiner/sptriggerdemo/src/main/resources/sptriggerdemo.ldif

Added: directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/SPMainDemo.java
URL: http://svn.apache.org/viewvc/directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/SPMainDemo.java?view=auto&rev=440038
==============================================================================
--- directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/SPMainDemo.java (added)
+++ directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/SPMainDemo.java Mon
Sep  4 04:59:55 2006
@@ -0,0 +1,69 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed 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 sptriggerdemo;
+
+
+import java.util.Hashtable;
+
+import javax.naming.NamingException;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.sp.JavaStoredProcedureUtils;
+import org.apache.directory.shared.ldap.sp.LdapContextParameter;
+import org.apache.directory.shared.ldap.trigger.TriggerUtils;
+
+import sptriggerdemo.common.BulkOperations;
+
+
+/**
+ * Demo utility for Stored Procedures and Triggers.
+ * 
+ * @author <a href="mailto:ersiner@apache.org">Ersin Er</a>
+ */
+public class SPMainDemo
+{
+    private static String host = "localhost";
+    private static int port = 1025;
+
+
+    private static LdapContext connectToServer() throws NamingException
+    {
+        Hashtable env = new Hashtable();
+        env.put( "java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory" );
+        env.put( "java.naming.provider.url", "ldap://" + host + ":" + port + "/ou=system"
);
+        env.put( "java.naming.security.principal", "uid=admin,ou=system" );
+        env.put( "java.naming.security.credentials", "secret" );
+        env.put( "java.naming.security.authentication", "simple" );
+        return new InitialLdapContext( env, null );
+    }
+
+
+    public static void main( String[] args ) throws NamingException
+    {
+        LdapContext ctx = connectToServer();
+
+        LdapContext spCtx = ( LdapContext ) ctx.lookup( "ou=Stored Procedures" );
+
+        JavaStoredProcedureUtils.loadStoredProcedureClass( spCtx, BulkOperations.class.getName(),
SPMainDemo.class );
+
+        JavaStoredProcedureUtils.callStoredProcedure( ctx, BulkOperations.class.getName()
+ ".delSubtree",
+            new Object[] { new LdapContextParameter( "ou=system" ), new LdapDN( "ou=Mailing
Lists") } );
+    }
+}

Added: directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/common/BulkOperations.java
URL: http://svn.apache.org/viewvc/directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/common/BulkOperations.java?view=auto&rev=440038
==============================================================================
--- directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/common/BulkOperations.java
(added)
+++ directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/common/BulkOperations.java
Mon Sep  4 04:59:55 2006
@@ -0,0 +1,41 @@
+package sptriggerdemo.common;
+
+import javax.naming.Name;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.directory.shared.ldap.name.LdapDN;
+
+/**
+ * A group of bulk operation methods which are prefered to
+ * run as Stored Procedures.
+ * 
+ * @author <a href="mailto:ersiner@apache.org">Ersin Er</a>
+ */
+public class BulkOperations
+{
+    /**
+     * Recursively deletes a subtree including the apex given.
+     * 
+     * @param ctx an LDAP session context to perform operations on
+     * @param rdn ctx relative name of the entry which is root of
+     *        the subtree to be deleted 
+     * @throws NamingException
+     */
+    public static void delSubtree( LdapContext ctx, Name rdn ) throws NamingException
+    {
+        NamingEnumeration results = ctx.search( rdn, "(objectClass=*)", new SearchControls()
);
+        while ( results.hasMore() )
+        {
+            SearchResult result = ( SearchResult ) results.next();
+            Name childRdn = new LdapDN( result.getName() );
+            childRdn.remove( 0 );
+            delSubtree( ctx, childRdn );
+        }
+        ctx.destroySubcontext( rdn );
+        System.out.println( "Deleted: " + rdn );
+    }
+}

Added: directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/common/Greeter.java
URL: http://svn.apache.org/viewvc/directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/common/Greeter.java?view=auto&rev=440038
==============================================================================
--- directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/common/Greeter.java
(added)
+++ directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/common/Greeter.java
Mon Sep  4 04:59:55 2006
@@ -0,0 +1,27 @@
+package sptriggerdemo.common;
+
+import javax.naming.NamingException;
+
+/**
+ * LDAP Stored Procedure Unit that does not really make much sense.
+ * Just has a "Hello World" type procedure.
+ * 
+ * @author <a href="mailto:ersiner@apache.org">Ersin Er</a>
+ */
+public class Greeter
+{
+    public static String sayHello( String who, Integer times ) throws NamingException
+    {
+        StringBuffer buffer = new StringBuffer();
+        
+        for ( int i = 0; i < times.intValue(); i++ )
+        {
+            buffer.append( "Hello " );
+        }
+        
+        buffer.append( who );
+        buffer.append( '!' );
+        
+        return buffer.toString();
+    }
+}

Added: directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/common/MailingListManager.java
URL: http://svn.apache.org/viewvc/directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/common/MailingListManager.java?view=auto&rev=440038
==============================================================================
--- directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/common/MailingListManager.java
(added)
+++ directory/sandbox/ersiner/sptriggerdemo/src/main/java/sptriggerdemo/common/MailingListManager.java
Mon Sep  4 04:59:55 2006
@@ -0,0 +1,88 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed 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 sptriggerdemo.common;
+
+
+import javax.naming.Name;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import javax.naming.ldap.LdapContext;
+
+
+/**
+ * LDAP Stored Procedure Unit for handling mailing lists
+ * modeled as static groups.
+ * 
+ * @author <a href="mailto:ersiner@apache.org">Ersin Er</a>
+ */
+public class MailingListManager
+{
+    /** the name of the context holding mailing lists */
+    private static String mlCtxName = "ou=Mailing Lists,ou=system";
+
+
+    public static void subscribeAddedPersonToEverybodyList( LdapContext ctx, Name addedEntryName
)
+        throws NamingException
+    {
+        System.out.println( "User \"" + addedEntryName + "\" has been added." );
+
+        String everyBodyMlCtxName = "cn=Everybody," + mlCtxName;
+
+        Attributes newMember = new BasicAttributes( "member", addedEntryName.toString(),
true );
+        ctx.modifyAttributes( everyBodyMlCtxName, DirContext.ADD_ATTRIBUTE, newMember );
+
+        System.out.println( "User \"" + addedEntryName + "\" has been subscribed to Everybody
mail list." );
+    }
+
+
+    public static void unsubscribeDeletedPersonFromAllLists( LdapContext ctx, Name deletedEntryName
)
+        throws NamingException
+    {
+        System.out.println( "User \"" + deletedEntryName + "\" has been deleted." );
+
+        String filterExpr = "(member={0})";
+        Object[] filterArgs = new Object[]
+            { deletedEntryName.toString() };
+        SearchControls ctrl = new SearchControls();
+        ctrl.setSearchScope( SearchControls.ONELEVEL_SCOPE );
+        NamingEnumeration results = ctx.search( mlCtxName, filterExpr, filterArgs, ctrl );
+        while ( results.hasMoreElements() )
+        {
+            SearchResult result = ( SearchResult ) results.nextElement();
+            String name = result.getName();
+            Attributes member = new BasicAttributes( "member", deletedEntryName.toString(),
true );
+            try
+            {
+                ctx.modifyAttributes( name, DirContext.REMOVE_ATTRIBUTE, member );
+            }
+            catch ( NamingException e )
+            {
+                e.printStackTrace();
+                throw e;
+            }
+        }
+
+        System.out.println( "User \"" + deletedEntryName
+            + "\" has been unsubscribed from all mail lists which it was subscribed to."
);
+    }
+}

Modified: directory/sandbox/ersiner/sptriggerdemo/src/main/resources/sptriggerdemo.ldif
URL: http://svn.apache.org/viewvc/directory/sandbox/ersiner/sptriggerdemo/src/main/resources/sptriggerdemo.ldif?view=diff&rev=440038&r1=440037&r2=440038
==============================================================================
--- directory/sandbox/ersiner/sptriggerdemo/src/main/resources/sptriggerdemo.ldif (original)
+++ directory/sandbox/ersiner/sptriggerdemo/src/main/resources/sptriggerdemo.ldif Mon Sep
 4 04:59:55 2006
@@ -18,14 +18,14 @@
 objectclass: organizationalUnit
 objectclass: top
 
-dn: cn=Everybody, ou=Mailing Lists, ou=system
+dn: cn=Board, ou=Mailing Lists, ou=system
 objectclass: extensibleObject
 objectclass: groupOfNames
 objectclass: top
 cn: Everybody
 member: uid=admin, ou=system
 
-dn: cn=Quality Project, ou=Mailing Lists, ou=system
+dn: cn=Project Vista, ou=Mailing Lists, ou=system
 objectclass: extensibleObject
 objectclass: groupOfNames
 objectclass: top
@@ -34,6 +34,11 @@
 
 dn: ou=Stored Procedures, ou=system
 ou: Stored Procedures
+objectclass: organizationalUnit
+objectclass: top
+
+dn: ou=Backup, ou=system
+ou: Backup
 objectclass: organizationalUnit
 objectclass: top
 



Mime
View raw message