Search in sources :

Example 26 with MutableAttributeType

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);
    }
}
Also used : MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test)

Example 27 with MutableAttributeType

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());
        }
    }
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 28 with MutableAttributeType

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);
    }
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException)

Example 29 with MutableAttributeType

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());
        }
    }
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 30 with MutableAttributeType

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());
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) Test(org.junit.Test)

Aggregations

MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)55 Test (org.junit.Test)37 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)24 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)24 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)18 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)17 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)10 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)7 PrepareString (org.apache.directory.api.ldap.model.schema.PrepareString)7 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)6 SyntaxChecker (org.apache.directory.api.ldap.model.schema.SyntaxChecker)6 Normalizer (org.apache.directory.api.ldap.model.schema.Normalizer)5 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)5 DeepTrimToLowerNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer)5 OpenLdapObjectIdentifierMacro (org.apache.directory.api.ldap.model.schema.syntaxCheckers.OpenLdapObjectIdentifierMacro)5 InputStream (java.io.InputStream)4 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)4 ByteArrayComparator (org.apache.directory.api.ldap.model.schema.comparators.ByteArrayComparator)4 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)2 LdapProtocolErrorException (org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException)2