Search in sources :

Example 11 with Schema

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

the class SchemaMarker method loadSchemaObjects.

private List<Entry> loadSchemaObjects(String schemaObjectType, Schema... schemas) throws LdapException, IOException {
    Map<String, List<Entry>> m = scObjEntryMap.get(schemaObjectType);
    List<Entry> atList = new ArrayList<>();
    for (Schema s : schemas) {
        List<Entry> preLoaded = m.get(s.getSchemaName());
        if (preLoaded != null) {
            atList.addAll(preLoaded);
        }
    }
    return atList;
}
Also used : Entry(org.apache.directory.api.ldap.model.entry.Entry) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 12 with Schema

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

the class DefaultSchemaManager method enable.

/**
 * {@inheritDoc}
 */
@Override
public boolean enable(Schema... schemas) throws LdapException {
    boolean enabled = false;
    // Reset the errors if not null
    if (errors != null) {
        errors.clear();
    }
    // Work on a cloned and relaxed registries
    Registries clonedRegistries = cloneRegistries();
    clonedRegistries.setRelaxed();
    Set<Schema> disabledSchemas = new HashSet<>();
    for (Schema schema : schemas) {
        if (schema.getDependencies() != null) {
            for (String dependency : schema.getDependencies()) {
                Schema dependencySchema = schemaMap.get(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();
    // Destroy the clonedRegistry
    clonedRegistries.clear();
    if (errors.isEmpty()) {
        // Ok no errors. Check the registries now
        errors = clonedRegistries.checkRefInteg();
        if (errors.isEmpty()) {
            // We are golden : let's apply the schemas in the real registries
            for (Schema schema : schemas) {
                schema.enable();
                load(registries, schema);
            }
            // Build the cross references
            errors = registries.buildReferences();
            registries.setStrict();
            enabled = true;
        }
    }
    // clear the cloned registries
    clonedRegistries.clear();
    return enabled;
}
Also used : Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) Registries(org.apache.directory.api.ldap.model.schema.registries.Registries) HashSet(java.util.HashSet)

Example 13 with Schema

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

the class DefaultSchemaManager method loadDepsFirst.

/**
 * Recursive method which loads schema's with their dependent schemas first
 * and tracks what schemas it has seen so the recursion does not go out of
 * control with dependency cycle detection.
 *
 * @param registries The Registries in which the schemas will be loaded
 * @param schema the current schema we are attempting to load
 * @throws Exception if there is a cycle detected and/or another
 * failure results while loading, producing and or registering schema objects
 */
private void loadDepsFirst(Registries registries, Schema schema) throws LdapException {
    if (schema == null) {
        LOG.info(I18n.msg(I18n.MSG_16013_SCHEMA_IS_NULL));
        return;
    }
    if (schema.isDisabled() && !registries.isDisabledAccepted()) {
        LOG.info(I18n.msg(I18n.MSG_16017_UNACCEPTED_DISABLED_SCHEMA));
        return;
    }
    String schemaName = schema.getSchemaName();
    if (registries.isSchemaLoaded(schemaName)) {
        LOG.info(I18n.msg(I18n.MSG_16018_SCHEMA_ALREADY_LOADED, schema.getSchemaName()));
        return;
    }
    String[] deps = schema.getDependencies();
    // if no deps then load this guy and return
    if ((deps == null) || (deps.length == 0)) {
        load(registries, schema);
        return;
    }
    /*
         * We got deps and need to load them before this schema.  We go through
         * all deps loading them with their deps first if they have not been
         * loaded.
         */
    for (String depName : deps) {
        if (registries.isSchemaLoaded(depName)) {
            // The schema is already loaded. Loop on the next schema
            continue;
        } else {
            // Call recursively this method
            Schema schemaDep = schemaMap.get(depName);
            loadDepsFirst(registries, schemaDep);
        }
    }
    // Now load the current schema
    load(registries, schema);
}
Also used : Schema(org.apache.directory.api.ldap.model.schema.registries.Schema)

Example 14 with Schema

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

the class DefaultSchemaManager method verify.

/**
 * {@inheritDoc}
 */
@Override
public boolean verify(Schema... schemas) throws LdapException {
    // Work on a cloned registries
    Registries clonedRegistries = cloneRegistries();
    // Loop on all the schemas
    for (Schema schema : schemas) {
        try {
            // Inject the schema
            boolean loaded = load(clonedRegistries, schema);
            if (!loaded) {
                // We got an error : exit
                clonedRegistries.clear();
                return false;
            }
            // Now, check the registries
            List<Throwable> errorList = clonedRegistries.checkRefInteg();
            if (!errorList.isEmpty()) {
                // We got an error : exit
                clonedRegistries.clear();
                return false;
            }
        } catch (Exception e) {
            // We got an error : exit
            clonedRegistries.clear();
            return false;
        }
    }
    // We can now delete the cloned registries before exiting
    clonedRegistries.clear();
    return true;
}
Also used : Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) Registries(org.apache.directory.api.ldap.model.schema.registries.Registries) LdapProtocolErrorException(org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) IOException(java.io.IOException) LdapOtherException(org.apache.directory.api.ldap.model.exception.LdapOtherException) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 15 with Schema

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

the class DefaultSchemaManager method loadWithDepsRelaxed.

/**
 * {@inheritDoc}
 */
@Override
public boolean loadWithDepsRelaxed(Schema... schemas) throws LdapException {
    registries.setRelaxed();
    // Load the schemas
    for (Schema schema : schemas) {
        loadDepsFirstRelaxed(schema);
    }
    // Build the cross references
    errors = registries.buildReferences();
    // Check the registries now
    errors = registries.checkRefInteg();
    return true;
}
Also used : Schema(org.apache.directory.api.ldap.model.schema.registries.Schema)

Aggregations

Schema (org.apache.directory.api.ldap.model.schema.registries.Schema)73 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)27 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