use of org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException in project directory-ldap-api by apache.
the class Registries method dissociateFromSchema.
/**
* Store the given SchemaObject in the Map associating SchemaObjetcs to their
* related Schema.
*
* @param errors The list that collect errors
* @param schemaObject The schemaObject to register
* @throws LdapException If there is a problem
*/
public void dissociateFromSchema(List<Throwable> errors, SchemaObject schemaObject) throws LdapException {
LOG.debug("Unregistering {}:{}", schemaObject.getObjectType(), schemaObject.getOid());
// Check that the SchemaObject is already registered
if (!(schemaObject instanceof LoadableSchemaObject) && !globalOidRegistry.contains(schemaObject.getOid())) {
String msg = I18n.err(I18n.ERR_13751_UNREGISTERING_FAILED_NOT_PRESENT, schemaObject.getObjectType(), schemaObject.getOid());
LOG.error(msg);
Throwable error = new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
errors.add(error);
return;
}
// Get a normalized form of schema name
String schemaName = getSchemaName(schemaObject);
String oid = schemaObject.getOid();
// And unregister the schemaObject from its schema
Set<SchemaObjectWrapper> content = schemaObjects.get(schemaName);
SchemaObjectWrapper schemaObjectWrapper = new SchemaObjectWrapper(schemaObject);
if (!content.contains(schemaObjectWrapper)) {
// Not present !
// What should we do ?
LOG.info("Unregistering of {}:{} failed, is not present in the Registries", schemaObject.getObjectType(), schemaObject.getOid());
} else {
// Remove the association
content.remove(schemaObjectWrapper);
// an instance of LoadableSchemaObject
if (!(schemaObject instanceof LoadableSchemaObject)) {
try {
globalOidRegistry.unregister(oid);
} catch (LdapException ne) {
errors.add(ne);
return;
}
}
LOG.debug("Unregistered {} for OID {}", schemaObject.getName(), schemaObject.getOid());
}
}
use of org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException in project directory-ldap-api by apache.
the class SchemaManagerLoadTest method testLoadWrongSchema.
/**
* Test loading a wrong schema
*/
@Test
public void testLoadWrongSchema() throws Exception {
LdifSchemaLoader loader = new LdifSchemaLoader(schemaRepository);
SchemaManager schemaManager = new DefaultSchemaManager(loader);
assertTrue(schemaManager.load("system"));
try {
schemaManager.loadWithDeps("bad");
fail();
} catch (LdapUnwillingToPerformException lonse) {
// expected
}
assertTrue(schemaManager.getErrors().isEmpty());
assertEquals(38, schemaManager.getAttributeTypeRegistry().size());
assertEquals(35, schemaManager.getComparatorRegistry().size());
assertEquals(35, schemaManager.getMatchingRuleRegistry().size());
assertEquals(35, schemaManager.getNormalizerRegistry().size());
assertEquals(9, schemaManager.getObjectClassRegistry().size());
assertEquals(59, schemaManager.getSyntaxCheckerRegistry().size());
assertEquals(59, schemaManager.getLdapSyntaxRegistry().size());
assertEquals(141, schemaManager.getGlobalOidRegistry().size());
assertEquals(1, schemaManager.getRegistries().getLoadedSchemas().size());
assertNotNull(schemaManager.getRegistries().getLoadedSchema("system"));
assertNull(schemaManager.getRegistries().getLoadedSchema("bad"));
}
use of org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException in project directory-ldap-api by apache.
the class DefaultSchemaManager method toArray.
/**
* Transform a String[] array of schema to a Schema[]
*/
private Schema[] toArray(String... schemas) throws LdapException {
Schema[] schemaArray = new Schema[schemas.length];
int n = 0;
for (String schemaName : schemas) {
Schema schema = schemaMap.get(schemaName);
if (schema != null) {
schemaArray[n++] = schema;
} else {
throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err(I18n.ERR_11001, schemaName));
}
}
return schemaArray;
}
use of org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException 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;
}
use of org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException in project directory-ldap-api by apache.
the class SchemaEntityFactory method getMatchingRule.
/**
* {@inheritDoc}
* @throws LdapInvalidAttributeValueException If the MatchingRule does not exist
* @throws LdapUnwillingToPerformException If the schema is not loaded
*/
@Override
public MatchingRule getMatchingRule(SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName) throws LdapUnwillingToPerformException, LdapInvalidAttributeValueException {
checkEntry(entry, SchemaConstants.MATCHING_RULE);
// The MatchingRule OID
String oid = getOid(entry, SchemaConstants.MATCHING_RULE, schemaManager.isStrict());
// Get the schema
if (!schemaManager.isSchemaLoaded(schemaName)) {
// The schema is not loaded. We can't create the requested MatchingRule
String msg = I18n.err(I18n.ERR_16028_CANNOT_ADD_MR, 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_16029_CANNOT_ADD_MR_IN_REGISTRY, entry.getDn().getName(), schemaName);
LOG.info(msg);
schema = schemaManager.getLoadedSchema(schemaName);
}
MutableMatchingRule matchingRule = new MutableMatchingRule(oid);
// The syntax field
Attribute mSyntax = entry.get(MetaSchemaConstants.M_SYNTAX_AT);
if (mSyntax != null) {
matchingRule.setSyntaxOid(mSyntax.getString());
}
// The normalizer and comparator fields will be updated when we will
// apply the registry
// Common properties
setSchemaObjectProperties(matchingRule, entry, schema);
return matchingRule;
}
Aggregations