directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 10469 - in incubator/directory/rms/trunk/je/src: java/org/apache/rms/je/profile test/org/apache/rms/je/profile
Date Sat, 01 May 2004 02:23:42 GMT
Author: akarasulu
Date: Fri Apr 30 19:23:41 2004
New Revision: 10469

Modified:
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/JeProfileRoleLinkDAO.java
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/ProfileRoleLinkDAOMonitor.java
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/ProfileRoleLinkDAOMonitorAdapter.java
   incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/profile/JeProfileRoleLinkDAOTest.java
Log:
Commit changes ...

 o completed role link dao delete() operation
 o completed and passed unit tests for delete() op
 o added new interface methods for delete() monitoring
 o implemented new monitor methods for no-op adapter



Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/JeProfileRoleLinkDAO.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/JeProfileRoleLinkDAO.java
(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/JeProfileRoleLinkDAO.java
Fri Apr 30 19:23:41 2004
@@ -18,6 +18,7 @@
 
 
 import org.apache.rms.je.JeUtils ;
+import org.apache.rms.je.JeRmsException;
 import org.apache.rms.RmsException ;
 import org.apache.rms.je.sequence.Sequence ;
 
@@ -201,7 +202,49 @@
     public void delete( String appName, String userName, String roleName )
             throws RmsException
     {
-        throw new NotImplementedException( "STUB" ) ;
+        DatabaseEntry pk ;
+        OperationStatus status ;
+
+        if ( ! has( appName, userName, roleName ) )
+        {
+            monitor.roleLinkDoesNotExist( this, "delete", appName, userName,
+                    roleName ) ;
+            throw new RmsException(
+                    "Cannot delete role link which is not present. User "
+                    + userName + " is NOT in role " + roleName
+                    + " for application " + appName ) ;
+        }
+
+        pk = getPkEntry( appName, userName, roleName ) ;
+
+        try
+        {
+            status = db.delete( null, pk ) ;
+        }
+        catch ( DatabaseException e )
+        {
+            monitor.failedOnDelete( this, appName, userName, roleName, e ) ;
+            throw new RmsException( e ) ;
+        }
+
+        if ( status == OperationStatus.SUCCESS )
+        {
+            monitor.roleLinkDeleted( this, appName, userName, roleName ) ;
+        }
+        else if ( status == OperationStatus.NOTFOUND )
+        {
+            throw new RmsException(
+                    "Cannot delete role link which is not present. User "
+                    + userName + " is NOT in role " + roleName
+                    + " for application " + appName ) ;
+        }
+        else
+        {
+            monitor.failedOnCreate( this, status, appName, userName,
+                    roleName ) ;
+            throw new RmsException(
+                    "role link db.delete() failed with status of " + status ) ;
+        }
     }
 
 
@@ -280,7 +323,7 @@
             } ;
 
             cursor = db.join( secCursors, null ) ;
-            status = cursor.getNext( key, value, LockMode.DEFAULT ) ;
+            status = cursor.getNext( key, LockMode.DEFAULT ) ;
         }
         catch ( DatabaseException e )
         {
@@ -360,7 +403,7 @@
             } ;
 
             cursor = db.join( secCursors, null ) ;
-            status = cursor.getNext( key, value, LockMode.DEFAULT ) ;
+            status = cursor.getNext( key, LockMode.DEFAULT ) ;
         }
         catch ( DatabaseException e )
         {
@@ -432,6 +475,110 @@
     // -----------------------------------------------------------------------
     // Utility Methods
     // -----------------------------------------------------------------------
+
+
+    /**
+     * Quick check to see if a user's application profile is associated with a
+     * specific role.
+     *
+     * @param appName  the name of the profile's application
+     * @param userName the name of the profile's user
+     * @param roleName the name of the profile's role
+     * @return the primary key (rowId) entry of the link record
+     * @throws org.apache.rms.RmsException if there is a failure to access the
+     * underlying database, or the entry does not exist
+     */
+    public DatabaseEntry getPkEntry( String appName, String userName,
+                                     String roleName ) throws RmsException
+    {
+        OperationStatus status = null ;
+        DatabaseEntry key = new DatabaseEntry() ;
+        DatabaseEntry value = new DatabaseEntry() ;
+        DatabaseEntry appNameKey = new DatabaseEntry() ;
+        DatabaseEntry userNameKey = new DatabaseEntry() ;
+        DatabaseEntry roleNameKey = new DatabaseEntry() ;
+
+        try
+        {
+            appNameKey.setData( appName.getBytes( "UTF-8" ) ) ;
+            userNameKey.setData( userName.getBytes( "UTF-8" ) ) ;
+            roleNameKey.setData( roleName.getBytes( "UTF-8" ) ) ;
+        }
+        catch ( UnsupportedEncodingException e )
+        {
+            monitor.failedOnHas( this, appName, userName, roleName, e ) ;
+            throw new RmsException( e ) ;
+        }
+
+        JoinCursor cursor = null ;
+        SecondaryCursor appNameCursor = null ;
+        SecondaryCursor userNameCursor = null ;
+        SecondaryCursor roleNameCursor = null ;
+
+        try
+        {
+            // -o- setup the application name cursor -o-
+            appNameCursor = byAppName.openSecondaryCursor( null, null ) ;
+            status = appNameCursor
+                    .getSearchKey( appNameKey, value, LockMode.DEFAULT ) ;
+            if ( status != OperationStatus.SUCCESS )
+            {
+                throw new JeRmsException( status, "application " + appName
+                    + " lookup in secondary failed with status " + status )  ;
+            }
+
+            // -o- setup the user name cursor -o-
+            userNameCursor = byUserName.openSecondaryCursor( null, null ) ;
+            status = userNameCursor.getSearchKey( userNameKey, value,
+                    LockMode.DEFAULT ) ;
+            if ( status != OperationStatus.SUCCESS )
+            {
+                throw new JeRmsException( status, "user " + userName
+                    + " lookup in secondary failed with status " + status )  ;
+            }
+
+            // -o- setup the role name cursor -o-
+            roleNameCursor = byRoleName.openSecondaryCursor( null, null ) ;
+            status = roleNameCursor.getSearchKey( roleNameKey, value,
+                    LockMode.DEFAULT ) ;
+            if ( status != OperationStatus.SUCCESS )
+            {
+                throw new JeRmsException( status, "role " + roleName
+                    + " lookup in secondary failed with status " + status )  ;
+            }
+
+            // -o- prepare the cursor array and the join cursor -o-
+            SecondaryCursor [] secCursors = {
+                appNameCursor,
+                userNameCursor,
+                roleNameCursor
+            } ;
+
+            cursor = db.join( secCursors, null ) ;
+            status = cursor.getNext( key, LockMode.DEFAULT ) ;
+        }
+        catch ( DatabaseException e )
+        {
+            monitor.failedOnHas( this, appName, userName, roleName, e ) ;
+            throw new RmsException( e ) ;
+        }
+        finally
+        {
+            closeNoError( cursor ) ;
+            closeNoError( appNameCursor ) ;
+            closeNoError( userNameCursor ) ;
+            closeNoError( roleNameCursor ) ;
+        }
+
+        if ( status != OperationStatus.SUCCESS )
+        {
+            throw new JeRmsException( status, "link of role " + roleName
+                + " in application " + appName + " for user " + userName
+                + " not found due to join status of " + status )  ;
+        }
+
+        return key ;
+    }
 
 
     /**

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/ProfileRoleLinkDAOMonitor.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/ProfileRoleLinkDAOMonitor.java
(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/ProfileRoleLinkDAOMonitor.java
Fri Apr 30 19:23:41 2004
@@ -159,4 +159,41 @@
      */
     void successOnHas( ProfileRoleLinkDAO dao, String appName,
                        String roleName, boolean haveIt ) ;
+
+    /**
+     * Monitors DAO operation failures that result when a link is expected but
+     * does not exist.
+     *
+     * @param dao the data access object performing the lookup
+     * @param op the operation performed by the dao
+     * @param appName the name of the application
+     * @param userName the name of the user
+     * @param roleName the name of the role
+     */
+    void roleLinkDoesNotExist( ProfileRoleLinkDAO dao, String op,
+                               String appName, String userName,
+                               String roleName ) ;
+
+    /**
+     * Monitor callback for failures while attempting to delete a link
+     *
+     * @param dao the data access object that failed on delete
+     * @param appName the name of the application
+     * @param userName the name of the user
+     * @param roleName the name of the role
+     * @param fault the faulting throwable that caused the failure
+     */
+    void failedOnDelete( ProfileRoleLinkDAO dao, String appName,
+                         String userName, String roleName, Throwable fault ) ;
+
+    /**
+     * Monitor callback for successful link delete events.
+     *
+     * @param dao the data access object that deleted a link
+     * @param appName the name of the application
+     * @param userName the name of the user
+     * @param roleName the name of the role
+     */
+    void roleLinkDeleted( ProfileRoleLinkDAO dao, String appName,
+                          String userName, String roleName ) ;
 }

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/ProfileRoleLinkDAOMonitorAdapter.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/ProfileRoleLinkDAOMonitorAdapter.java
(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/ProfileRoleLinkDAOMonitorAdapter.java
Fri Apr 30 19:23:41 2004
@@ -116,4 +116,28 @@
                               String roleName, boolean haveIt )
     {
     }
+
+
+    public void roleLinkDoesNotExist( ProfileRoleLinkDAO dao, String op,
+                                      String appName, String userName,
+                                      String roleName )
+    {
+    }
+
+
+    public void failedOnDelete( ProfileRoleLinkDAO dao, String appName,
+                                String userName, String roleName,
+                                Throwable fault )
+    {
+        if ( fault != null )
+        {
+            fault.printStackTrace() ;
+        }
+    }
+
+
+    public void roleLinkDeleted( ProfileRoleLinkDAO dao, String appName,
+                                 String userName, String roleName )
+    {
+    }
 }

Modified: incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/profile/JeProfileRoleLinkDAOTest.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/profile/JeProfileRoleLinkDAOTest.java
(original)
+++ incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/profile/JeProfileRoleLinkDAOTest.java
Fri Apr 30 19:23:41 2004
@@ -110,4 +110,44 @@
         assertTrue( dao.has( "app2", "roleB" ) ) ;
         assertFalse( dao.has( "app2", "roleA" ) ) ;
     }
+
+
+    public void testCreateHasAndDelete() throws Exception
+    {
+        assertFalse( dao.has( "app1", "user1", "roleA" ) ) ;
+        assertFalse( dao.has( "app1", "user2", "roleA" ) ) ;
+        assertFalse( dao.has( "app1", "roleA" ) ) ;
+
+        assertFalse( dao.has( "app2", "user1", "roleB" ) ) ;
+        assertFalse( dao.has( "app2", "user2", "roleB" ) ) ;
+        assertFalse( dao.has( "app2", "roleA" ) ) ;
+
+        dao.create( "app1", "user1", "roleA" ) ;
+        dao.create( "app1", "user2", "roleA" ) ;
+        dao.create( "app2", "user1", "roleB" ) ;
+        dao.create( "app2", "user2", "roleB" ) ;
+
+        assertTrue( dao.has( "app1", "user1", "roleA" ) ) ;
+        assertTrue( dao.has( "app1", "user2", "roleA" ) ) ;
+        assertTrue( dao.has( "app1", "roleA" ) ) ;
+        assertFalse( dao.has( "app1", "roleB" ) ) ;
+
+        assertTrue( dao.has( "app2", "user1", "roleB" ) ) ;
+        assertTrue( dao.has( "app2", "user2", "roleB" ) ) ;
+        assertTrue( dao.has( "app2", "roleB" ) ) ;
+        assertFalse( dao.has( "app2", "roleA" ) ) ;
+
+        dao.delete( "app1", "user1", "roleA" ) ;
+        dao.delete( "app1", "user2", "roleA" ) ;
+        dao.delete( "app2", "user1", "roleB" ) ;
+        dao.delete( "app2", "user2", "roleB" ) ;
+
+        assertFalse( dao.has( "app1", "user1", "roleA" ) ) ;
+        assertFalse( dao.has( "app1", "user2", "roleA" ) ) ;
+        assertFalse( dao.has( "app1", "roleA" ) ) ;
+
+        assertFalse( dao.has( "app2", "user1", "roleB" ) ) ;
+        assertFalse( dao.has( "app2", "user2", "roleB" ) ) ;
+        assertFalse( dao.has( "app2", "roleA" ) ) ;
+    }
 }

Mime
View raw message