directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r887982 - in /directory/shared/branches/shared-schema: ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/ ldap-schema-loader/src/test/java/org/apache/directory/server/schema/ ldap/src/main/java/org/apache/directory/shared/...
Date Mon, 07 Dec 2009 16:24:40 GMT
Author: elecharny
Date: Mon Dec  7 16:24:37 2009
New Revision: 887982

URL: http://svn.apache.org/viewvc?rev=887982&view=rev
Log:
o Added a chck for references in the del() method
o Fixed the tests for the del() method

Modified:
    directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
    directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerDelTest.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java?rev=887982&r1=887981&r2=887982&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
Mon Dec  7 16:24:37 2009
@@ -23,6 +23,7 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import javax.naming.NamingException;
 
@@ -42,6 +43,7 @@
 import org.apache.directory.shared.ldap.schema.ObjectClass;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.apache.directory.shared.ldap.schema.SchemaObject;
+import org.apache.directory.shared.ldap.schema.SchemaObjectWrapper;
 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
 import org.apache.directory.shared.ldap.schema.normalizers.OidNormalizer;
 import org.apache.directory.shared.ldap.schema.registries.AttributeTypeRegistry;
@@ -1318,6 +1320,21 @@
 
             // Build the new AttributeType from the given entry
             SchemaObject toDelete = registries.getGlobalOidRegistry().getSchemaObject( schemaObject.getOid()
);
+
+            // First check that this SchemaObject does not have any referencing SchemaObjects
+            Set<SchemaObjectWrapper> referencing = registries.getReferencing( toDelete
);
+
+            if ( ( referencing != null ) && !referencing.isEmpty() )
+            {
+                String msg = "Cannot remove  " + schemaObject.getOid()
+                    + " for the registries, it would become inconsistent. The following SchemaOjects
are "
+                    + "referencing this SchemaObject : " + StringTools.setToString( referencing
);
+
+                Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.OTHER
);
+                errors.add( error );
+                return false;
+            }
+
             String schemaName = getSchemaName( toDelete );
 
             // At this point, the deleted AttributeType may be referenced, it will be checked

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerDelTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerDelTest.java?rev=887982&r1=887981&r2=887982&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerDelTest.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerDelTest.java
Mon Dec  7 16:24:37 2009
@@ -87,13 +87,11 @@
     }
 
 
-    private SchemaManager loadCore() throws Exception
+    private SchemaManager loadSchema( String schemaName ) throws Exception
     {
         LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
         SchemaManager schemaManager = new DefaultSchemaManager( loader );
 
-        String schemaName = "core";
-
         schemaManager.loadWithDeps( schemaName );
 
         return schemaManager;
@@ -135,7 +133,7 @@
     @Test
     public void testDelNonExistentAttributeType() throws Exception
     {
-        SchemaManager schemaManager = loadCore();
+        SchemaManager schemaManager = loadSchema( "Core" );
         int atrSize = schemaManager.getAttributeTypeRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
 
@@ -162,7 +160,7 @@
     public void testDelExistingAttributeTypeNoReference() throws Exception
     {
         // First inject such an AT
-        SchemaManager schemaManager = loadCore();
+        SchemaManager schemaManager = loadSchema( "Core" );
         int atrSize = schemaManager.getAttributeTypeRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
 
@@ -184,7 +182,7 @@
     @Test
     public void testDelExistingAttributeTypeReferencedByOC() throws Exception
     {
-        SchemaManager schemaManager = loadCore();
+        SchemaManager schemaManager = loadSchema( "Core" );
 
         int atrSize = schemaManager.getAttributeTypeRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
@@ -208,7 +206,7 @@
     @Test
     public void testDelAttributeTypeFromDisabledSchema() throws Exception
     {
-        SchemaManager schemaManager = loadCore();
+        SchemaManager schemaManager = loadSchema( "Core" );
 
         int atrSize = schemaManager.getAttributeTypeRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
@@ -232,7 +230,7 @@
     @Test
     public void testDelExistingAttributeTypeReferencedByDescendant() throws Exception
     {
-        SchemaManager schemaManager = loadCore();
+        SchemaManager schemaManager = loadSchema( "Apache" );
 
         int atrSize = schemaManager.getAttributeTypeRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
@@ -242,7 +240,7 @@
         AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( "modifiersName"
);
 
         // It should fail
-        assertFalse( schemaManager.add( attributeType ) );
+        assertFalse( schemaManager.delete( attributeType ) );
 
         assertTrue( isATPresent( schemaManager, "modifiersName" ) );
         assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java?rev=887982&r1=887981&r2=887982&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
Mon Dec  7 16:24:37 2009
@@ -2605,6 +2605,21 @@
 
 
     /**
+     * Check that we can remove a given SchemaObject without breaking some of its references.
+     * We will return the list of refereing objects.
+     *
+     * @param schemaObject The SchemaObject to remove
+     * @return The list of SchemaObjects referencing the SchemaObjetc we want to remove
+     */
+    public Set<SchemaObjectWrapper> getReferencing( SchemaObject schemaObject )
+    {
+        SchemaObjectWrapper schemaObjectWrapper = new SchemaObjectWrapper( schemaObject );
+
+        return usedBy.get( schemaObjectWrapper );
+    }
+
+
+    /**
      * Change the Registries behavior regarding disabled SchemaObject element.
      *
      * @param acceptDisabled If <code>false</code>, then the Registries won't
accept



Mime
View raw message