Search in sources :

Example 1 with Schema

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

the class SchemaManagerEnableDisableLoadTest method testLoadAllEnabled.

// -------------------------------------------------------------------------
// Test the loadAllEnabled() method
// -------------------------------------------------------------------------
/**
 * Test the loadEnabled() method
 */
@Test
public void testLoadAllEnabled() throws Exception {
    assertTrue(schemaManager.getEnabled().isEmpty());
    assertTrue(schemaManager.loadAllEnabled());
    for (String schemaName : allSchemas) {
        assertTrue(schemaManager.isSchemaLoaded(schemaName));
    }
    // The enabled schemas
    Collection<Schema> enabled = schemaManager.getEnabled();
    assertEquals(enabled.size(), enabledSchemas.size());
    for (Schema schema : enabled) {
        assertTrue(enabledSchemas.contains(Strings.toLowerCaseAscii(schema.getSchemaName())));
    }
    // The disabled schemas
    List<Schema> disabled = schemaManager.getDisabled();
    assertEquals(0, disabled.size());
    assertTrue(schemaManager.getErrors().isEmpty());
    assertEquals(430, schemaManager.getAttributeTypeRegistry().size());
    assertEquals(49, schemaManager.getComparatorRegistry().size());
    assertEquals(55, schemaManager.getMatchingRuleRegistry().size());
    assertEquals(48, schemaManager.getNormalizerRegistry().size());
    assertEquals(123, schemaManager.getObjectClassRegistry().size());
    assertEquals(68, schemaManager.getSyntaxCheckerRegistry().size());
    assertEquals(80, schemaManager.getLdapSyntaxRegistry().size());
    assertEquals(688, schemaManager.getGlobalOidRegistry().size());
    assertEquals(12, schemaManager.getRegistries().getLoadedSchemas().size());
    assertNull(schemaManager.getRegistries().getLoadedSchema("nis"));
}
Also used : Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) Test(org.junit.Test)

Example 2 with Schema

use of org.apache.directory.api.ldap.model.schema.registries.Schema 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 3 with Schema

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

the class SchemaEntityFactory method getSchema.

/**
 * Get the schema from its name. Return the Other reference if there
 * is no schema name. Throws a NPE if the schema is not loaded.
 */
private Schema getSchema(String schemaName, Registries registries) {
    if (Strings.isEmpty(schemaName)) {
        schemaName = MetaSchemaConstants.SCHEMA_OTHER;
    }
    Schema schema = registries.getLoadedSchema(schemaName);
    if (schema == null) {
        String msg = I18n.err(I18n.ERR_16015_NON_EXISTENT_SCHEMA, schemaName);
        LOG.error(msg);
    }
    return schema;
}
Also used : DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema)

Example 4 with Schema

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

the class SchemaEntityFactory method getSyntaxChecker.

/**
 * {@inheritDoc}
 */
@Override
public SyntaxChecker getSyntaxChecker(SchemaManager schemaManager, SyntaxCheckerDescription syntaxCheckerDescription, Registries targetRegistries, String schemaName) throws LdapException {
    checkDescription(syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER);
    // The Comparator OID
    String oid = getOid(syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER);
    // Get the schema
    Schema schema = getSchema(schemaName, targetRegistries);
    if (schema == null) {
        // The schema is not loaded. We can't create the requested SyntaxChecker
        String msg = I18n.err(I18n.ERR_16019_CANNOT_ADD_SC, syntaxCheckerDescription.getName(), schemaName);
        LOG.warn(msg);
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
    }
    // The FQCN
    String fqcn = getFqcn(syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER);
    // get the byteCode
    Attribute byteCode = getByteCode(syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER);
    // Class load the SyntaxChecker
    SyntaxChecker syntaxChecker = classLoadSyntaxChecker(schemaManager, oid, fqcn, byteCode);
    // Update the common fields
    setSchemaObjectProperties(syntaxChecker, syntaxCheckerDescription, schema);
    return syntaxChecker;
}
Also used : SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema)

Example 5 with Schema

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

the class SchemaEntityFactory method getAttributeType.

/**
 * {@inheritDoc}
 * @throws LdapInvalidAttributeValueException If the AttributeType does not exist
 * @throws LdapUnwillingToPerformException If the schema is not loaded
 */
@Override
public AttributeType getAttributeType(SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName) throws LdapInvalidAttributeValueException, LdapUnwillingToPerformException {
    checkEntry(entry, SchemaConstants.ATTRIBUTE_TYPE);
    // The AttributeType OID
    String oid = getOid(entry, SchemaConstants.ATTRIBUTE_TYPE, schemaManager.isStrict());
    // Get the schema
    if (!schemaManager.isSchemaLoaded(schemaName)) {
        // The schema is not loaded, this is an error
        String msg = I18n.err(I18n.ERR_16032_CANNOT_ADD_AT, entry.getDn().getName(), schemaName);
        LOG.warn(msg);
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
    }
    Schema schema = getSchema(schemaName, targetRegistries);
    if (schema == null) {
        // The schema is disabled. We still have to update the backend
        String msg = I18n.err(I18n.ERR_16033_CANNOT_ADD_AT_IN_REGISTRY, entry.getDn().getName(), schemaName);
        LOG.info(msg);
        schema = schemaManager.getLoadedSchema(schemaName);
    }
    // Create the new AttributeType
    MutableAttributeType attributeType = new MutableAttributeType(oid);
    if (schemaManager.isRelaxed()) {
        attributeType.setRelaxed(true);
    }
    // Syntax
    Attribute mSyntax = entry.get(MetaSchemaConstants.M_SYNTAX_AT);
    if ((mSyntax != null) && (mSyntax.get() != null)) {
        attributeType.setSyntaxOid(mSyntax.getString());
    }
    // Syntax Length
    Attribute mSyntaxLength = entry.get(MetaSchemaConstants.M_LENGTH_AT);
    if (mSyntaxLength != null) {
        attributeType.setSyntaxLength(Integer.parseInt(mSyntaxLength.getString()));
    }
    // Equality
    Attribute mEquality = entry.get(MetaSchemaConstants.M_EQUALITY_AT);
    if (mEquality != null) {
        attributeType.setEqualityOid(mEquality.getString());
    }
    // Ordering
    Attribute mOrdering = entry.get(MetaSchemaConstants.M_ORDERING_AT);
    if (mOrdering != null) {
        attributeType.setOrderingOid(mOrdering.getString());
    }
    // Substr
    Attribute mSubstr = entry.get(MetaSchemaConstants.M_SUBSTR_AT);
    if (mSubstr != null) {
        attributeType.setSubstringOid(mSubstr.getString());
    }
    Attribute mSupAttributeType = entry.get(MetaSchemaConstants.M_SUP_ATTRIBUTE_TYPE_AT);
    // Sup
    if (mSupAttributeType != null) {
        attributeType.setSuperiorOid(mSupAttributeType.getString());
    }
    // isCollective
    Attribute mCollective = entry.get(MetaSchemaConstants.M_COLLECTIVE_AT);
    if (mCollective != null) {
        String val = mCollective.getString();
        attributeType.setCollective("TRUE".equalsIgnoreCase(val));
    }
    // isSingleValued
    Attribute mSingleValued = entry.get(MetaSchemaConstants.M_SINGLE_VALUE_AT);
    if (mSingleValued != null) {
        String val = mSingleValued.getString();
        attributeType.setSingleValued("TRUE".equalsIgnoreCase(val));
    }
    // isReadOnly
    Attribute mNoUserModification = entry.get(MetaSchemaConstants.M_NO_USER_MODIFICATION_AT);
    if (mNoUserModification != null) {
        String val = mNoUserModification.getString();
        attributeType.setUserModifiable(!"TRUE".equalsIgnoreCase(val));
    }
    // Usage
    Attribute mUsage = entry.get(MetaSchemaConstants.M_USAGE_AT);
    if (mUsage != null) {
        attributeType.setUsage(UsageEnum.getUsage(mUsage.getString()));
    }
    // Common properties
    setSchemaObjectProperties(attributeType, entry, schema);
    return attributeType;
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType)

Aggregations

Schema (org.apache.directory.api.ldap.model.schema.registries.Schema)74 ArrayList (java.util.ArrayList)34 Entry (org.apache.directory.api.ldap.model.entry.Entry)34 DefaultSchema (org.apache.directory.api.ldap.model.schema.registries.DefaultSchema)28 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)26 LdifReader (org.apache.directory.api.ldap.model.ldif.LdifReader)25 File (java.io.File)13 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)13 SchemaObjectWrapper (org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)13 URL (java.net.URL)12 LdapUnwillingToPerformException (org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException)12 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)11 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)9 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)9 Registries (org.apache.directory.api.ldap.model.schema.registries.Registries)9 AttributesFactory (org.apache.directory.api.ldap.model.schema.AttributesFactory)8 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)7 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)7 Test (org.junit.Test)7 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)6