directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1045161 - in /directory/shared/trunk/ldap-schema/src: main/java/org/apache/directory/shared/ldap/schema/manager/impl/ test/java/org/apache/directory/shared/ldap/schema/loader/ldif/
Date Mon, 13 Dec 2010 15:05:42 GMT
Author: elecharny
Date: Mon Dec 13 15:05:42 2010
New Revision: 1045161

URL: http://svn.apache.org/viewvc?rev=1045161&view=rev
Log:
Fix for DIRSHARED-65 : it's now possible to enable a schema which depends on disabled schema.
ALl the parents will be enabled.

Modified:
    directory/shared/trunk/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/manager/impl/DefaultSchemaManager.java
    directory/shared/trunk/ldap-schema/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/SchemaManagerEnableDisableLoadTest.java

Modified: directory/shared/trunk/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/manager/impl/DefaultSchemaManager.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/manager/impl/DefaultSchemaManager.java?rev=1045161&r1=1045160&r2=1045161&view=diff
==============================================================================
--- directory/shared/trunk/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/manager/impl/DefaultSchemaManager.java
(original)
+++ directory/shared/trunk/ldap-schema/src/main/java/org/apache/directory/shared/ldap/schema/manager/impl/DefaultSchemaManager.java
Mon Dec 13 15:05:42 2010
@@ -402,12 +402,36 @@ public class DefaultSchemaManager implem
         Registries clonedRegistries = cloneRegistries();
         clonedRegistries.setRelaxed();
 
+        Set<Schema> disabledSchemas = new HashSet<Schema>();
+
         for ( Schema schema : schemas )
         {
+            if ( schema.getDependencies() != null )
+            {
+                for ( String dependency : schema.getDependencies() )
+                {
+                    Schema dependencySchema = schemaLoader.getSchema( dependency );
+
+                    if ( dependencySchema.isDisabled() )
+                    {
+                        disabledSchemas.add( dependencySchema );
+                    }
+                }
+            }
+
             schema.enable();
             load( clonedRegistries, schema );
         }
 
+        // Revert back the disabled schema to disabled
+        for ( Schema disabledSchema : disabledSchemas )
+        {
+            if ( disabledSchema.isEnabled() )
+            {
+                disabledSchema.disable();
+            }
+        }
+
         // Build the cross references
         errors = clonedRegistries.buildReferences();
 
@@ -668,7 +692,9 @@ public class DefaultSchemaManager implem
             {
                 for ( String dependency : schema.getDependencies() )
                 {
-                    if ( schemaLoader.getSchema( dependency ) == null )
+                    Schema dependencySchema = schemaLoader.getSchema( dependency );
+
+                    if ( dependencySchema == null )
                     {
                         // The dependency has not been loaded.
                         String msg = I18n.err( I18n.ERR_11002, schema.getSchemaName() );
@@ -677,6 +703,19 @@ public class DefaultSchemaManager implem
                         errors.add( error );
                         return false;
                     }
+
+                    // If the dependency is disabled, then enable it
+                    if ( dependencySchema.isDisabled() )
+                    {
+                        dependencySchema.enable();
+
+                        if ( load( registries, dependencySchema ) == false )
+                        {
+                            dependencySchema.disable();
+
+                            return false;
+                        }
+                    }
                 }
             }
 

Modified: directory/shared/trunk/ldap-schema/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/SchemaManagerEnableDisableLoadTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-schema/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/SchemaManagerEnableDisableLoadTest.java?rev=1045161&r1=1045160&r2=1045161&view=diff
==============================================================================
--- directory/shared/trunk/ldap-schema/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/SchemaManagerEnableDisableLoadTest.java
(original)
+++ directory/shared/trunk/ldap-schema/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/SchemaManagerEnableDisableLoadTest.java
Mon Dec 13 15:05:42 2010
@@ -21,6 +21,7 @@ package org.apache.directory.shared.ldap
 
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -267,4 +268,39 @@ public class SchemaManagerEnableDisableL
     {
 
     }
+
+
+    /**
+     * Enable a disabled schema, which depends on a disabled schema itself.
+     * Samba is disabled, and depends on nis which is also disabled. Enabling samba
+     * should enabled nis.
+     */
+    @Test
+    public void testEnableDisabledDependingOnDisabled() throws Exception
+    {
+        schemaManager.loadAllEnabled();
+
+        assertFalse( schemaManager.isEnabled( "samba" ) );
+        assertFalse( schemaManager.isEnabled( "nis" ) );
+
+        assertTrue( schemaManager.enable( "samba" ) );
+        assertTrue( schemaManager.isEnabled( "samba" ) );
+        assertTrue( schemaManager.isEnabled( "nis" ) );
+
+        assertNotNull( schemaManager.lookupAttributeTypeRegistry( "gecos" ) );
+
+        assertTrue( schemaManager.getErrors().isEmpty() );
+        assertEquals( 488, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 49, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 49, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 49, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 146, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 68, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 73, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 757, schemaManager.getGlobalOidRegistry().size() );
+
+        assertEquals( 14, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "samba" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "nis" ) );
+    }
 }



Mime
View raw message