use of org.apache.directory.api.ldap.model.schema.MutableAttributeType in project directory-ldap-api by apache.
the class AttributeTypeRegistryTest method testUnregister.
@Test
public void testUnregister() throws LdapException {
MutableAttributeType at0 = new MutableAttributeType("1.1");
at0.addName("t", "test", "Test", "T");
atRegistry.register(at0);
atRegistry.unregister("1.1");
assertFalse(atRegistry.contains("1.1"));
assertFalse(atRegistry.contains("t"));
assertFalse(atRegistry.contains("T"));
assertFalse(atRegistry.contains("tEsT"));
try {
atRegistry.getOidByName("T");
fail();
} catch (LdapException ne) {
assertTrue(true);
}
}
use of org.apache.directory.api.ldap.model.schema.MutableAttributeType in project directory-ldap-api by apache.
the class AttributeTypeHelper method buildSubstring.
/**
* Build the SUBSTR MR reference for an AttributeType
*/
private static void buildSubstring(MutableAttributeType attributeType, List<Throwable> errors, Registries registries) {
String substringOid = attributeType.getSubstringOid();
// The Substring MR. It can be null
if (substringOid != null) {
MatchingRule currentSubstring = null;
try {
currentSubstring = registries.getMatchingRuleRegistry().lookup(substringOid);
} catch (LdapException ne) {
// Not allowed.
String msg = I18n.err(I18n.ERR_13760_CANNOT_FIND_SUBSTR_MR_OBJECT, substringOid, attributeType.getName());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_SUBSTRING_MATCHING_RULE, msg, ne);
ldapSchemaException.setSourceObject(attributeType);
ldapSchemaException.setRelatedId(substringOid);
errors.add(ldapSchemaException);
LOG.info(msg);
return;
}
if (currentSubstring != null) {
attributeType.setSubstring(currentSubstring);
} else {
// Not allowed.
String msg = I18n.err(I18n.ERR_13761_CANNOT_FIND_SUBSTR_MR_INSTANCE, substringOid, attributeType.getName());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_SUBSTRING_MATCHING_RULE, msg);
ldapSchemaException.setSourceObject(attributeType);
ldapSchemaException.setRelatedId(substringOid);
errors.add(ldapSchemaException);
LOG.info(msg);
return;
}
} else {
AttributeType superior = attributeType.getSuperior();
// If the AT has a superior, take its Substring MR if any
if ((superior != null) && (superior.getSubstring() != null)) {
attributeType.setSubstring(superior.getSubstring());
}
}
}
use of org.apache.directory.api.ldap.model.schema.MutableAttributeType in project directory-ldap-api by apache.
the class AttributeTypeHelper method checkCollective.
/**
* Check the constraints for the Collective field.
*/
private static void checkCollective(MutableAttributeType attributeType, List<Throwable> errors) {
AttributeType superior = attributeType.getSuperior();
if ((superior != null) && superior.isCollective()) {
// An AttributeType will be collective if its superior is collective
attributeType.setCollective(true);
}
if (attributeType.isCollective() && (attributeType.getUsage() != UsageEnum.USER_APPLICATIONS)) {
// An AttributeType which is collective must be a USER attributeType
String msg = I18n.err(I18n.ERR_13764_AT_COLLECTIVE_SHOULD_BE_USER_APP, attributeType.getName());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_COLLECTIVE_MUST_HAVE_USER_APPLICATIONS_USAGE, msg);
ldapSchemaException.setSourceObject(attributeType);
errors.add(ldapSchemaException);
LOG.info(msg);
}
if (attributeType.isCollective() && attributeType.isSingleValued()) {
// A collective attribute must be multi-valued
String msg = I18n.err(I18n.ERR_13777_COLLECTIVE_NOT_MULTI_VALUED, attributeType.getName());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_COLLECTIVE_CANNOT_BE_SINGLE_VALUED, msg);
ldapSchemaException.setSourceObject(attributeType);
errors.add(ldapSchemaException);
LOG.info(msg);
}
}
use of org.apache.directory.api.ldap.model.schema.MutableAttributeType 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.schema.MutableAttributeType in project directory-ldap-api by apache.
the class OpenLdapSchemaParserTest method testComplexAttributeTypeParse.
@Test
public void testComplexAttributeTypeParse() throws Exception {
String attributeTypeData = "# adding a comment \n" + "attributetype ( 2.5.4.2 NAME ( 'knowledgeInformation' 'asdf' ) \n" + " DESC 'RFC2256: knowledge information'\n" + " EQUALITY caseIgnoreMatch\n" + " SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )";
parser.parse(attributeTypeData);
List<MutableAttributeType> attributeTypeList = parser.getAttributeTypes();
Map<String, AttributeType> attributeTypes = mapAttributeTypes(attributeTypeList);
AttributeType type = attributeTypes.get("2.5.4.2");
assertNotNull(type);
assertEquals("2.5.4.2", type.getOid());
assertEquals("knowledgeInformation", type.getName());
assertEquals("RFC2256: knowledge information", type.getDescription());
assertEquals("1.3.6.1.4.1.1466.115.121.1.15", type.getSyntaxOid());
assertEquals(32768, type.getSyntaxLength());
}
Aggregations