use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.
the class AttributeTypeHelper method buildOrdering.
/**
* Build the ORDERING MR reference for an AttributeType
*/
private static void buildOrdering(MutableAttributeType attributeType, List<Throwable> errors, Registries registries) {
String orderingOid = attributeType.getOrderingOid();
if (orderingOid != null) {
MatchingRule currentOrdering = null;
try {
currentOrdering = registries.getMatchingRuleRegistry().lookup(orderingOid);
} catch (LdapException ne) {
// Not allowed.
String msg = I18n.err(I18n.ERR_13758_CANNOT_FIND_ORDERING_MR_OBJECT, orderingOid, attributeType.getName());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_ORDERING_MATCHING_RULE, msg, ne);
ldapSchemaException.setSourceObject(attributeType);
ldapSchemaException.setRelatedId(orderingOid);
errors.add(ldapSchemaException);
LOG.info(msg);
return;
}
if (currentOrdering != null) {
attributeType.setOrdering(currentOrdering);
} else {
// Not allowed.
String msg = I18n.err(I18n.ERR_13759_CANNOT_FIND_ORDERING_MR_INSTANCE, orderingOid, attributeType.getName());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_ORDERING_MATCHING_RULE, msg);
ldapSchemaException.setSourceObject(attributeType);
ldapSchemaException.setRelatedId(orderingOid);
errors.add(ldapSchemaException);
LOG.info(msg);
}
} else {
AttributeType superior = attributeType.getSuperior();
// If the AT has a superior, take its Ordering MR if any
if ((superior != null) && (superior.getOrdering() != null)) {
attributeType.setOrdering(superior.getOrdering());
}
}
}
use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.
the class DefaultSchemaObjectRegistry method register.
/**
* {@inheritDoc}
*/
@Override
public void register(T schemaObject) throws LdapException {
String oid = schemaObject.getOid();
if (byName.containsKey(oid)) {
String msg = I18n.err(I18n.ERR_13736_ELEMENT_FOR_OID_ALREADY_REGISTERED, schemaObjectType.name(), oid);
LOG.warn(msg);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OID_ALREADY_REGISTERED, msg);
ldapSchemaException.setSourceObject(schemaObject);
throw ldapSchemaException;
}
byName.put(oid, schemaObject);
/*
* add the aliases/names to the name map along with their toLowerCase
* versions of the name: this is used to make sure name lookups work
*/
for (String name : schemaObject.getNames()) {
String lowerName = Strings.trim(Strings.toLowerCaseAscii(name));
if (byName.containsKey(lowerName)) {
String msg = I18n.err(I18n.ERR_13737_ELEMENT_WITH_NAME_ALREADY_REGISTERED, schemaObjectType.name(), name);
LOG.warn(msg);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.NAME_ALREADY_REGISTERED, msg);
ldapSchemaException.setSourceObject(schemaObject);
throw ldapSchemaException;
} else {
byName.put(lowerName, schemaObject);
}
}
// And register the oid -> schemaObject relation
oidRegistry.register(schemaObject);
if (LOG.isDebugEnabled()) {
LOG.debug("registered " + schemaObject.getName() + " for OID {}", oid);
}
}
use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.
the class InitSearchRequestAttributeDescList method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
// Here, we have to inject the decoded filter into the SearchRequest
SearchRequestDecorator searchRequestDecorator = container.getMessage();
SearchRequest searchRequest = searchRequestDecorator.getDecorated();
try {
searchRequest.setFilter(searchRequestDecorator.getFilterNode());
} catch (LdapSchemaException lse) {
throw new DecoderException(lse.getMessage(), lse);
}
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
LOG.debug("Initialize AttributeDesc list");
}
}
use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddObjectClassSuperiorsAbstractWithStructuralInSup.
/**
* Addition of an ABSTRACT OC with some STRUCTURAL superior
*/
@Test
public void testAddObjectClassSuperiorsAbstractWithStructuralInSup() throws Exception {
SchemaManager schemaManager = loadSystem();
int ocrSize = schemaManager.getObjectClassRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
MutableObjectClass objectClass = new MutableObjectClass("1.1.1");
objectClass.setNames("Test");
objectClass.setType(ObjectClassTypeEnum.ABSTRACT);
objectClass.addSuperiorOids("referral");
assertFalse(schemaManager.add(objectClass));
assertTrue(schemaManager.getErrors().get(0) instanceof LdapSchemaException);
assertFalse(isOCPresent(schemaManager, "1.1.1"));
assertEquals(ocrSize, schemaManager.getObjectClassRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddAttributeTypeSupBadSup.
/**
* Try to inject an AttributeType with a bad superior
*/
@Test
public void testAddAttributeTypeSupBadSup() throws Exception {
SchemaManager schemaManager = loadSystem();
int atrSize = schemaManager.getAttributeTypeRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
MutableAttributeType attributeType = new MutableAttributeType("1.1.0");
attributeType.setEqualityOid(null);
attributeType.setOrderingOid(null);
attributeType.setSubstringOid(null);
attributeType.setSuperiorOid("0.0");
attributeType.setUsage(UsageEnum.DISTRIBUTED_OPERATION);
// It should fail
assertFalse(schemaManager.add(attributeType));
List<Throwable> errors = schemaManager.getErrors();
assertEquals(1, errors.size());
Throwable error = errors.get(0);
assertTrue(error instanceof LdapSchemaException);
assertFalse(isATPresent(schemaManager, "1.1.0"));
assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Aggregations