Search in sources :

Example 1 with NoOpNormalizer

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

the class SchemaManagerAddTest method testAddNewNormalizer.

// =========================================================================
// MatchingRuleUse addition tests
// -------------------------------------------------------------------------
// TODO
// =========================================================================
// NameForm addition tests
// -------------------------------------------------------------------------
// TODO
// =========================================================================
// Normalizer addition tests
// -------------------------------------------------------------------------
@Test
public void testAddNewNormalizer() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int nrSize = schemaManager.getNormalizerRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    String oid = "0.0.0";
    Normalizer normalizer = new NoOpNormalizer(oid);
    assertTrue(schemaManager.add(normalizer));
    List<Throwable> errors = schemaManager.getErrors();
    assertEquals(0, errors.size());
    assertEquals(nrSize + 1, schemaManager.getNormalizerRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
    Normalizer added = schemaManager.lookupNormalizerRegistry(oid);
    assertNotNull(added);
    assertEquals(normalizer.getClass().getName(), added.getFqcn());
}
Also used : NoOpNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer) NoOpNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 2 with NoOpNormalizer

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

the class SchemaManagerAddTest method testAddAlreadyExistingNormalizer.

@Test
public void testAddAlreadyExistingNormalizer() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int nrSize = schemaManager.getNormalizerRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    String oid = "0.0.0";
    Normalizer normalizer = new NoOpNormalizer(oid);
    assertTrue(schemaManager.add(normalizer));
    Normalizer added = schemaManager.lookupNormalizerRegistry(oid);
    assertNotNull(added);
    assertEquals(normalizer.getClass().getName(), added.getFqcn());
    List<Throwable> errors = schemaManager.getErrors();
    assertEquals(0, errors.size());
    assertEquals(nrSize + 1, schemaManager.getNormalizerRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
    Normalizer normalizer2 = new NoOpNormalizer(oid);
    assertFalse(schemaManager.add(normalizer2));
    errors = schemaManager.getErrors();
    assertEquals(1, errors.size());
    assertEquals(nrSize + 1, schemaManager.getNormalizerRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
    added = schemaManager.lookupNormalizerRegistry(oid);
    assertNotNull(added);
    assertEquals(normalizer.getClass().getName(), added.getFqcn());
}
Also used : NoOpNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer) NoOpNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 3 with NoOpNormalizer

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

the class SchemaManagerAddTest method testAddNormalizerWithWrongFQCN.

/**
 * Test that we can't add two Normalizers with the same class code.
 */
@Test
public void testAddNormalizerWithWrongFQCN() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int nrSize = schemaManager.getNormalizerRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    String oid = "0.0.0";
    Normalizer normalizer = new NoOpNormalizer(oid);
    // using java.sql.ResultSet cause it is very unlikely to get loaded
    // in ADS, as the FQCN is not the one expected
    normalizer.setFqcn("java.sql.ResultSet");
    assertFalse(schemaManager.add(normalizer));
    List<Throwable> errors = schemaManager.getErrors();
    errors = schemaManager.getErrors();
    assertEquals(1, errors.size());
    assertEquals(nrSize, schemaManager.getNormalizerRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
    try {
        schemaManager.lookupNormalizerRegistry(oid);
        fail();
    } catch (Exception e) {
        // Expected
        assertTrue(true);
    }
}
Also used : NoOpNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer) NoOpNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) IOException(java.io.IOException) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test)

Example 4 with NoOpNormalizer

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

the class MatchingRuleHelper method addToRegistries.

/**
 * Inject the MatchingRule into the Registries, updating the references to
 * other SchemaObject
 *
 * @param matchingRule The MatchingRule to add to the Registries
 * @param errors The errors we got while adding the MatchingRule to the registries
 * @param registries The Registries
 * @throws LdapException If the addition failed
 */
@SuppressWarnings("rawtypes")
public static void addToRegistries(MutableMatchingRule matchingRule, List<Throwable> errors, Registries registries) throws LdapException {
    if (registries != null) {
        try {
            matchingRule.unlock();
            LdapComparator<?> ldapComparator = null;
            Normalizer normalizer = null;
            LdapSyntax ldapSyntax = null;
            try {
                // Gets the associated Comparator
                ldapComparator = registries.getComparatorRegistry().lookup(matchingRule.getOid());
            } catch (LdapException ne) {
                // Default to a catch all comparator
                ldapComparator = new ComparableComparator(matchingRule.getOid());
            }
            try {
                // Gets the associated Normalizer
                normalizer = registries.getNormalizerRegistry().lookup(matchingRule.getOid());
            } catch (LdapException ne) {
                // Default to the NoOp normalizer
                normalizer = new NoOpNormalizer(matchingRule.getOid());
            }
            try {
                // Get the associated LdapSyntax
                ldapSyntax = registries.getLdapSyntaxRegistry().lookup(matchingRule.getSyntaxOid());
            } catch (LdapException ne) {
                // The Syntax is a mandatory element, it must exist.
                String msg = I18n.err(I18n.ERR_13765_MR_MUST_REFER_EXISTING_SYNTAX);
                LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.MR_NONEXISTENT_SYNTAX, msg, ne);
                ldapSchemaException.setSourceObject(matchingRule);
                ldapSchemaException.setRelatedId(matchingRule.getSyntaxOid());
                errors.add(ldapSchemaException);
                LOG.info(msg);
            }
            /**
             * Add the MR references (using and usedBy) :
             * MR -> C
             * MR -> N
             * MR -> S
             */
            if (ldapComparator != null) {
                registries.addReference(matchingRule, ldapComparator);
                matchingRule.setLdapComparator(ldapComparator);
            }
            if (normalizer != null) {
                registries.addReference(matchingRule, normalizer);
                matchingRule.setNormalizer(normalizer);
            }
            if (ldapSyntax != null) {
                registries.addReference(matchingRule, ldapSyntax);
                matchingRule.setSyntax(ldapSyntax);
            }
        } finally {
            matchingRule.lock();
        }
    }
}
Also used : NoOpNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer) NoOpNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) ComparableComparator(org.apache.directory.api.ldap.model.schema.comparators.ComparableComparator) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 5 with NoOpNormalizer

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

the class DefaultAttributeTypeRegistry method addMappingFor.

/**
 * {@inheritDoc}
 */
@Override
public void addMappingFor(AttributeType attributeType) throws LdapException {
    MatchingRule equality = attributeType.getEquality();
    OidNormalizer oidNormalizer;
    String oid = attributeType.getOid();
    if (equality == null) {
        LOG.debug("Attribute {} does not have an EQUALITY MatchingRule : using NoopNormalizer", attributeType.getName());
        oidNormalizer = new OidNormalizer(oid, new NoOpNormalizer(attributeType.getOid()));
    } else {
        oidNormalizer = new OidNormalizer(oid, equality.getNormalizer());
    }
    oidNormalizerMap.put(oid, oidNormalizer);
    // Also inject the attributeType's short names in the map
    for (String name : attributeType.getNames()) {
        oidNormalizerMap.put(Strings.toLowerCaseAscii(name), oidNormalizer);
    }
}
Also used : NoOpNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer) OidNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.OidNormalizer) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule)

Aggregations

NoOpNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer)8 Normalizer (org.apache.directory.api.ldap.model.schema.Normalizer)5 Test (org.junit.Test)4 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)3 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)3 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)2 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)2 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)2 SyntaxChecker (org.apache.directory.api.ldap.model.schema.SyntaxChecker)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)1 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)1 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)1 ByteArrayComparator (org.apache.directory.api.ldap.model.schema.comparators.ByteArrayComparator)1 ComparableComparator (org.apache.directory.api.ldap.model.schema.comparators.ComparableComparator)1 OidNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.OidNormalizer)1 OctetStringSyntaxChecker (org.apache.directory.api.ldap.model.schema.syntaxCheckers.OctetStringSyntaxChecker)1