Search in sources :

Example 1 with DefaultSchema

use of org.apache.directory.api.ldap.model.schema.registries.DefaultSchema in project directory-ldap-api by apache.

the class SchemaManagerLoadTest method loadNewSchema.

/**
 * Test that we can load a new schema
 */
@Test
public void loadNewSchema() throws Exception {
    LdifSchemaLoader loader = new LdifSchemaLoader(schemaRepository);
    SchemaManager schemaManager = new DefaultSchemaManager(loader);
    Schema dummy = new DefaultSchema(loader, "dummy");
    assertTrue(schemaManager.load(dummy));
    assertTrue(schemaManager.getErrors().isEmpty());
    assertEquals(0, schemaManager.getAttributeTypeRegistry().size());
    assertEquals(0, schemaManager.getComparatorRegistry().size());
    assertEquals(0, schemaManager.getMatchingRuleRegistry().size());
    assertEquals(0, schemaManager.getNormalizerRegistry().size());
    assertEquals(0, schemaManager.getObjectClassRegistry().size());
    assertEquals(0, schemaManager.getSyntaxCheckerRegistry().size());
    assertEquals(0, schemaManager.getLdapSyntaxRegistry().size());
    assertEquals(0, schemaManager.getGlobalOidRegistry().size());
    assertEquals(1, schemaManager.getRegistries().getLoadedSchemas().size());
    assertNotNull(schemaManager.getRegistries().getLoadedSchema("dummy"));
}
Also used : Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 2 with DefaultSchema

use of org.apache.directory.api.ldap.model.schema.registries.DefaultSchema in project directory-ldap-api by apache.

the class DefaultSchemaLoader method updateSchemas.

private void updateSchemas(SchemaObject schemaObject) {
    String schemaName = schemaObject.getSchemaName();
    Schema schema;
    if (Strings.isEmpty(schemaName) || "null".equals(schemaName)) {
        schemaName = "default";
        schema = schemaMap.get(schemaName);
    } else {
        schema = schemaMap.get(schemaName);
    }
    if (schema == null) {
        schema = new DefaultSchema(this, schemaName);
        schemaMap.put(schemaName, schema);
    }
    schema.getContent().add(new SchemaObjectWrapper(schemaObject));
}
Also used : DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)

Example 3 with DefaultSchema

use of org.apache.directory.api.ldap.model.schema.registries.DefaultSchema in project directory-ldap-api by apache.

the class SchemaManagerLoadTest method loadNewSchemaBadDependencies.

/**
 * Test that we can't load a new schema with bad dependencies
 */
@Test
public void loadNewSchemaBadDependencies() throws Exception {
    LdifSchemaLoader loader = new LdifSchemaLoader(schemaRepository);
    SchemaManager schemaManager = new DefaultSchemaManager(loader);
    Schema dummy = new DefaultSchema(loader, "dummy");
    dummy.addDependencies("bad");
    assertFalse(schemaManager.load(dummy));
    assertFalse(schemaManager.getErrors().isEmpty());
    assertEquals(0, schemaManager.getAttributeTypeRegistry().size());
    assertEquals(0, schemaManager.getComparatorRegistry().size());
    assertEquals(0, schemaManager.getMatchingRuleRegistry().size());
    assertEquals(0, schemaManager.getNormalizerRegistry().size());
    assertEquals(0, schemaManager.getObjectClassRegistry().size());
    assertEquals(0, schemaManager.getSyntaxCheckerRegistry().size());
    assertEquals(0, schemaManager.getLdapSyntaxRegistry().size());
    assertEquals(0, schemaManager.getGlobalOidRegistry().size());
    assertEquals(0, schemaManager.getRegistries().getLoadedSchemas().size());
    assertNull(schemaManager.getRegistries().getLoadedSchema("dummy"));
}
Also used : Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 4 with DefaultSchema

use of org.apache.directory.api.ldap.model.schema.registries.DefaultSchema in project directory-ldap-api by apache.

the class SchemaManagerLoadTest method testLoadSchemasWithDepsCoreInetOrgPersonAndBad.

// ---------------------------------------------------------------------------
// Test the load( Schema... ) method
// ---------------------------------------------------------------------------
/**
 * test loading the "InetOrgPerson", "core" and an empty schema. The empty schema
 * should be present in the registries, as it's a vaid schema
 */
@Test
public void testLoadSchemasWithDepsCoreInetOrgPersonAndBad() throws Exception {
    LdifSchemaLoader loader = new LdifSchemaLoader(schemaRepository);
    SchemaManager schemaManager = new DefaultSchemaManager(loader);
    Schema system = loader.getSchema("system");
    Schema core = loader.getSchema("core");
    Schema empty = new DefaultSchema(loader, "empty");
    Schema cosine = loader.getSchema("cosine");
    Schema inetOrgPerson = loader.getSchema("InetOrgPerson");
    assertTrue(schemaManager.load(system, core, empty, cosine, inetOrgPerson));
    assertTrue(schemaManager.getErrors().isEmpty());
    assertEquals(142, schemaManager.getAttributeTypeRegistry().size());
    assertEquals(36, schemaManager.getComparatorRegistry().size());
    assertEquals(42, schemaManager.getMatchingRuleRegistry().size());
    assertEquals(35, schemaManager.getNormalizerRegistry().size());
    assertEquals(50, schemaManager.getObjectClassRegistry().size());
    assertEquals(59, schemaManager.getSyntaxCheckerRegistry().size());
    assertEquals(66, schemaManager.getLdapSyntaxRegistry().size());
    assertEquals(300, schemaManager.getGlobalOidRegistry().size());
    assertEquals(5, schemaManager.getRegistries().getLoadedSchemas().size());
    assertNotNull(schemaManager.getRegistries().getLoadedSchema("system"));
    assertNotNull(schemaManager.getRegistries().getLoadedSchema("core"));
    assertNotNull(schemaManager.getRegistries().getLoadedSchema("cosine"));
    assertNotNull(schemaManager.getRegistries().getLoadedSchema("InetOrgPerson"));
    assertNotNull(schemaManager.getRegistries().getLoadedSchema("empty"));
}
Also used : Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 5 with DefaultSchema

use of org.apache.directory.api.ldap.model.schema.registries.DefaultSchema in project directory-ldap-api by apache.

the class SchemaEntityFactory method getSchema.

/**
 * {@inheritDoc}
 */
@Override
public Schema getSchema(Entry entry) throws LdapException {
    String name;
    String owner;
    String[] dependencies = EMPTY_ARRAY;
    boolean isDisabled = false;
    if (entry == null) {
        throw new IllegalArgumentException(I18n.err(I18n.ERR_16016_NULL_ENTRY));
    }
    if (entry.get(SchemaConstants.CN_AT) == null) {
        throw new IllegalArgumentException(I18n.err(I18n.ERR_16017_INVALID_CN_AT));
    }
    name = entry.get(SchemaConstants.CN_AT).getString();
    if (entry.get(SchemaConstants.CREATORS_NAME_AT) == null) {
        throw new IllegalArgumentException(I18n.err(I18n.ERR_16018_INVALID_AT, SchemaConstants.CREATORS_NAME_AT));
    }
    owner = entry.get(SchemaConstants.CREATORS_NAME_AT).getString();
    if (entry.get(MetaSchemaConstants.M_DISABLED_AT) != null) {
        String value = entry.get(MetaSchemaConstants.M_DISABLED_AT).getString();
        value = Strings.upperCase(value);
        isDisabled = "TRUE".equalsIgnoreCase(value);
    }
    if (entry.get(MetaSchemaConstants.M_DEPENDENCIES_AT) != null) {
        Set<String> depsSet = new HashSet<>();
        Attribute depsAttr = entry.get(MetaSchemaConstants.M_DEPENDENCIES_AT);
        for (Value value : depsAttr) {
            depsSet.add(value.getValue());
        }
        dependencies = depsSet.toArray(EMPTY_ARRAY);
    }
    return new DefaultSchema(null, name, owner, dependencies, isDisabled);
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Value(org.apache.directory.api.ldap.model.entry.Value) HashSet(java.util.HashSet)

Aggregations

DefaultSchema (org.apache.directory.api.ldap.model.schema.registries.DefaultSchema)7 Schema (org.apache.directory.api.ldap.model.schema.registries.Schema)5 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)4 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)4 Test (org.junit.Test)4 HashSet (java.util.HashSet)1 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)1 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)1 Value (org.apache.directory.api.ldap.model.entry.Value)1 SchemaObjectWrapper (org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)1 JarLdifSchemaLoader (org.apache.directory.api.ldap.schema.loader.JarLdifSchemaLoader)1 LdifSchemaLoader (org.apache.directory.api.ldap.schema.loader.LdifSchemaLoader)1