Search in sources :

Example 6 with LoadableSchemaObject

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

the class Registries method dissociateFromSchema.

/**
 * Remove the given SchemaObject from the Map associating SchemaObjetcs to their
 * related Schema.
 *
 * @param schemaObject The schemaObject to remove
 * @throws LdapException If there is a problem
 */
public void dissociateFromSchema(SchemaObject schemaObject) throws LdapException {
    // And unregister the schemaObject within its schema
    Set<SchemaObjectWrapper> content = schemaObjects.get(Strings.toLowerCaseAscii(schemaObject.getSchemaName()));
    if (content != null) {
        SchemaObjectWrapper schemaObjectWrapper = new SchemaObjectWrapper(schemaObject);
        if (content.contains(schemaObjectWrapper)) {
            // remove the schemaObject
            content.remove(schemaObjectWrapper);
            // an instance of LoadableSchemaObject
            if (!(schemaObject instanceof LoadableSchemaObject)) {
                globalOidRegistry.unregister(schemaObject.getOid());
            }
            LOG.debug("Unregistered {}:{}", schemaObject.getObjectType(), schemaObject.getOid());
        } else {
            // Not present !!
            // What should we do ?
            LOG.debug("Unregistering of {}:{} failed, not found in Registries", schemaObject.getObjectType(), schemaObject.getOid());
        }
    }
}
Also used : LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)

Example 7 with LoadableSchemaObject

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

the class DefaultSchemaManager method copy.

private SchemaObject copy(SchemaObject schemaObject) {
    SchemaObject copy = null;
    if (!(schemaObject instanceof LoadableSchemaObject)) {
        copy = schemaObject.copy();
    } else {
        // Check the schemaObject here.
        if (((LoadableSchemaObject) schemaObject).isValid()) {
            copy = schemaObject;
        } else {
            // We have an invalid SchemaObject, no need to go any further
            Throwable error = new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err(I18n.ERR_11007, schemaObject.getOid()));
            errors.add(error);
        }
    }
    return copy;
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException)

Example 8 with LoadableSchemaObject

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

the class DefaultSchemaManager method delete.

/**
 * {@inheritDoc}
 */
@Override
public boolean delete(SchemaObject schemaObject) throws LdapException {
    // First, clear the errors
    errors.clear();
    if (registries.isRelaxed()) {
        // Apply the addition right away
        registries.delete(errors, schemaObject);
        return errors.isEmpty();
    } else {
        // The new schemaObject's OID must exist
        if (!checkOidExist(schemaObject)) {
            Throwable error = new LdapProtocolErrorException(I18n.err(I18n.ERR_16039_OID_DOES_NOT_EXIST, schemaObject.getOid()));
            errors.add(error);
            return false;
        }
        // Get the SchemaObject to delete if it's not a LoadableSchemaObject
        SchemaObject toDelete = getSchemaObject(schemaObject);
        // First check that this SchemaObject does not have any referencing SchemaObjects
        Set<SchemaObjectWrapper> referencing = registries.getReferencing(toDelete);
        if ((referencing != null) && !referencing.isEmpty()) {
            String msg = I18n.err(I18n.ERR_16040_CANNOT_REMOVE_FROM_REGISTRY, schemaObject.getOid(), Strings.setToString(referencing));
            Throwable error = new LdapProtocolErrorException(msg);
            errors.add(error);
            return false;
        }
        String schemaName = getSchemaName(toDelete);
        // At this point, the deleted AttributeType may be referenced, it will be checked
        // there, if the schema and the AttributeType are both enabled.
        Schema schema = getLoadedSchema(schemaName);
        if (schema == null) {
            // The SchemaObject must be associated with an existing schema
            String msg = I18n.err(I18n.ERR_16041_CANNOT_DELETE_SCHEMA_OBJECT, schemaObject.getOid());
            LOG.info(msg);
            Throwable error = new LdapProtocolErrorException(msg);
            errors.add(error);
            return false;
        }
        if (schema.isEnabled() && schemaObject.isEnabled()) {
            // As we may break the registries, work on a cloned registries
            Registries clonedRegistries = null;
            try {
                clonedRegistries = registries.clone();
            } catch (CloneNotSupportedException cnse) {
                throw new LdapOtherException(cnse.getMessage(), cnse);
            }
            // Delete the SchemaObject from the cloned registries
            clonedRegistries.delete(errors, toDelete);
            // Remove the cloned registries
            clonedRegistries.clear();
            // If we didn't get any error, apply the deletion to the real retistries
            if (errors.isEmpty()) {
                // Apply the deletion to the real registries
                registries.delete(errors, toDelete);
                LOG.debug(I18n.msg(I18n.MSG_16022_REMOVED_FROM_ENABLED_SCHEMA, toDelete.getName(), schemaName));
                return true;
            } else {
                // We have some error : reject the deletion and get out
                LOG.info(I18n.msg(I18n.MSG_16023_CANNOT_DELETE_SCHEMAOBJECT, schemaObject.getOid(), Strings.listToString(errors)));
                return false;
            }
        } else {
            // At least, we register the OID in the globalOidRegistry, and associates it with the
            // schema
            registries.associateWithSchema(errors, schemaObject);
            LOG.debug(I18n.msg(I18n.MSG_16024_REMOVED_FROM_DISABLED_SCHEMA, schemaObject.getName(), schemaName));
            return errors.isEmpty();
        }
    }
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) LdapProtocolErrorException(org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) Registries(org.apache.directory.api.ldap.model.schema.registries.Registries) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper) LdapOtherException(org.apache.directory.api.ldap.model.exception.LdapOtherException)

Aggregations

LoadableSchemaObject (org.apache.directory.api.ldap.model.schema.LoadableSchemaObject)8 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)5 SchemaObjectWrapper (org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)5 LdapUnwillingToPerformException (org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException)4 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)3 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)2 DitContentRule (org.apache.directory.api.ldap.model.schema.DitContentRule)2 DitStructureRule (org.apache.directory.api.ldap.model.schema.DitStructureRule)2 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)2 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)2 MatchingRuleUse (org.apache.directory.api.ldap.model.schema.MatchingRuleUse)2 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)2 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)2 NameForm (org.apache.directory.api.ldap.model.schema.NameForm)2 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 LdapOtherException (org.apache.directory.api.ldap.model.exception.LdapOtherException)1