Search in sources :

Example 6 with MatchingRule

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

the class SchemaManagerDelTest method testDeleteExistingNormalizerUsedByRemovedMatchingRule.

/**
 * Check that a Normalizer which has been used by a deleted MatchingRule
 * can be removed
 */
@Test
public void testDeleteExistingNormalizerUsedByRemovedMatchingRule() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int nrSize = schemaManager.getNormalizerRegistry().size();
    int mrrSize = schemaManager.getMatchingRuleRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    String OID = "2.5.13.33";
    // Check that the MR and N are present
    assertTrue(isMatchingRulePresent(schemaManager, OID));
    assertTrue(isNormalizerPresent(schemaManager, OID));
    // Now try to remove the N
    Normalizer normalizer = schemaManager.lookupNormalizerRegistry(OID);
    // shouldn't be deleted cause there is a MR associated with it
    assertFalse(schemaManager.delete(normalizer));
    List<Throwable> errors = schemaManager.getErrors();
    assertFalse(errors.isEmpty());
    assertTrue(errors.get(0) instanceof LdapProtocolErrorException);
    // Now delete the using MR : it should be OK
    MatchingRule mr = new MatchingRule(OID);
    assertTrue(schemaManager.delete(mr));
    assertEquals(mrrSize - 1, schemaManager.getMatchingRuleRegistry().size());
    assertEquals(goidSize - 1, schemaManager.getGlobalOidRegistry().size());
    assertFalse(isMatchingRulePresent(schemaManager, OID));
    // and try to delete the normalizer again
    assertTrue(schemaManager.delete(normalizer));
    assertFalse(isNormalizerPresent(schemaManager, OID));
    assertEquals(nrSize - 1, schemaManager.getNormalizerRegistry().size());
    assertEquals(goidSize - 1, schemaManager.getGlobalOidRegistry().size());
}
Also used : LdapProtocolErrorException(org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException) BooleanNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.BooleanNormalizer) 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) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) Test(org.junit.Test)

Example 7 with MatchingRule

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

the class DefaultSchemaManager method addMatchingRules.

/**
 * Add all the Schema's DitContentRules
 */
// Not yet implemented, but may be used
// @SuppressWarnings("PMD.UnusedFormalParameter")
// private void addDitContentRules( Schema schema, Registries registries ) throws LdapException, IOException
// {
// if ( !schema.getSchemaLoader().loadDitContentRules( schema ).isEmpty() )
// {
// throw new NotImplementedException( I18n.err( I18n.ERR_11003 ) );
// }
// }
/**
 * Add all the Schema's DitStructureRules
 */
// Not yet implemented, but may be used
// @SuppressWarnings("PMD.UnusedFormalParameter")
// private void addDitStructureRules( Schema schema, Registries registries ) throws LdapException, IOException
// {
// if ( !schema.getSchemaLoader().loadDitStructureRules( schema ).isEmpty() )
// {
// throw new NotImplementedException( I18n.err( I18n.ERR_11004 ) );
// }
// }
/**
 * Add all the Schema's MatchingRules
 */
private void addMatchingRules(Schema schema, Registries registries) throws LdapException, IOException {
    if (schema.getSchemaLoader() == null) {
        return;
    }
    for (Entry entry : schema.getSchemaLoader().loadMatchingRules(schema)) {
        MatchingRule matchingRule = factory.getMatchingRule(this, entry, registries, schema.getSchemaName());
        addSchemaObject(registries, matchingRule, schema);
    }
}
Also used : Entry(org.apache.directory.api.ldap.model.entry.Entry) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule)

Example 8 with MatchingRule

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

the class MatchingRuleTest method testNumericStringMatch.

@Test
public void testNumericStringMatch() throws Exception {
    MatchingRule mr1 = schemaManager.lookupMatchingRuleRegistry("numericStringMatch");
    assertEquals(NumericNormalizer.class.getName(), mr1.getNormalizer().getClass().getName());
    assertEquals("1234567890", mr1.getNormalizer().normalize(" 1 234 567 890 "));
    assertEquals(NumericStringComparator.class.getName(), mr1.getLdapComparator().getClass().getName());
    assertEquals(0, mr1.getLdapComparator().compare(" 1 234 567 890 ", "1234567890"));
    MatchingRule mr2 = schemaManager.lookupMatchingRuleRegistry("numericStringSubstringsMatch");
    assertEquals(NumericNormalizer.class.getName(), mr2.getNormalizer().getClass().getName());
    assertEquals("1234567890", mr2.getNormalizer().normalize(" 1 234 567 890 "));
    assertEquals(NumericStringComparator.class.getName(), mr2.getLdapComparator().getClass().getName());
    assertEquals(0, mr2.getLdapComparator().compare(" 1 234 567 890 ", "1234567890"));
    MatchingRule mr3 = schemaManager.lookupMatchingRuleRegistry("numericStringOrderingMatch");
    assertEquals(NumericNormalizer.class.getName(), mr3.getNormalizer().getClass().getName());
    assertEquals("1234567890", mr3.getNormalizer().normalize(" 1 234 567 890 "));
    assertEquals(NumericStringComparator.class.getName(), mr3.getLdapComparator().getClass().getName());
    assertEquals(0, mr3.getLdapComparator().compare(" 1 234 567 890 ", "1234567890"));
    assertTrue(mr3.getLdapComparator().compare(" 1 2 3  ", " 2 3 4") < 0);
    assertTrue(mr3.getLdapComparator().compare(" 1 2 3 4 ", " 2 3 4") < 0);
}
Also used : NumericNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer) NumericStringComparator(org.apache.directory.api.ldap.model.schema.comparators.NumericStringComparator) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) Test(org.junit.Test)

Example 9 with MatchingRule

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

the class MatchingRuleTest method testGeneralizedTimeStringMatch.

@Test
public void testGeneralizedTimeStringMatch() throws Exception {
    MatchingRule mr1 = schemaManager.lookupMatchingRuleRegistry("generalizedTimeMatch");
    assertEquals(GeneralizedTimeNormalizer.class.getName(), mr1.getNormalizer().getClass().getName());
    String normalized = mr1.getNormalizer().normalize("2010031415Z");
    assertTrue("20100314150000.000Z".equals(normalized) || "20100314153000.000Z".equals(normalized) || "20100314154500.000Z".equals(normalized));
    assertEquals("20100314133102.003Z", mr1.getNormalizer().normalize("20100314150102.003+0130"));
    assertEquals(GeneralizedTimeComparator.class.getName(), mr1.getLdapComparator().getClass().getName());
    // Deal with +HH:30 and +HH:45 TZ
    int compare1 = mr1.getLdapComparator().compare("2010031415Z", "20100314150000.000+0000");
    int compare2 = mr1.getLdapComparator().compare("2010031415Z", "20100314153000.000+0000");
    int compare3 = mr1.getLdapComparator().compare("2010031415Z", "20100314154500.000+0000");
    assertTrue((compare1 == 0) || (compare2 == 0) || (compare3 == 0));
    MatchingRule mr2 = schemaManager.lookupMatchingRuleRegistry("generalizedTimeOrderingMatch");
    assertEquals(GeneralizedTimeNormalizer.class.getName(), mr2.getNormalizer().getClass().getName());
    normalized = mr2.getNormalizer().normalize("2010031415Z");
    assertTrue("20100314150000.000Z".equals(normalized) || "20100314153000.000Z".equals(normalized) || "20100314154500.000Z".equals(normalized));
    assertEquals("20100314133102.003Z", mr2.getNormalizer().normalize("20100314150102.003+0130"));
    assertEquals(GeneralizedTimeComparator.class.getName(), mr2.getLdapComparator().getClass().getName());
    // Deal with +HH:30 and +HH:45 TZ
    compare1 = mr2.getLdapComparator().compare("2010031415Z", "20100314150000.000+0000");
    compare2 = mr2.getLdapComparator().compare("2010031415Z", "20100314153000.000+0000");
    compare3 = mr2.getLdapComparator().compare("2010031415Z", "20100314154500.000+0000");
    assertTrue((compare1 == 0) || (compare2 == 0) || (compare3 == 0));
    assertTrue(mr2.getLdapComparator().compare("2010031415Z", "2010031414Z") > 0);
    assertTrue(mr2.getLdapComparator().compare("2010031415Z", "2010031416Z") < 0);
}
Also used : GeneralizedTimeComparator(org.apache.directory.api.ldap.model.schema.comparators.GeneralizedTimeComparator) GeneralizedTimeNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.GeneralizedTimeNormalizer) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) Test(org.junit.Test)

Example 10 with MatchingRule

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

the class DefaultSchemaLoader method loadMatchingRules.

/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadMatchingRules(Schema... schemas) throws LdapException, IOException {
    List<Entry> matchingRuleEntries = new ArrayList<>();
    if (schemas == null) {
        return matchingRuleEntries;
    }
    AttributesFactory factory = new AttributesFactory();
    for (Schema schema : schemas) {
        Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
        for (SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers) {
            SchemaObject schemaObject = schemaObjectWrapper.get();
            if (schemaObject instanceof MatchingRule) {
                MatchingRule matchingRule = (MatchingRule) schemaObject;
                Entry matchingRuleEntry = factory.convert(matchingRule, schema, null);
                matchingRuleEntries.add(matchingRuleEntry);
            }
        }
    }
    return matchingRuleEntries;
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) AttributesFactory(org.apache.directory.api.ldap.model.schema.AttributesFactory) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) ArrayList(java.util.ArrayList) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule)

Aggregations

MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)36 Test (org.junit.Test)21 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)11 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)11 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)9 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)7 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)7 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)6 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)5 Normalizer (org.apache.directory.api.ldap.model.schema.Normalizer)5 ParseException (java.text.ParseException)4 LdapProtocolErrorException (org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException)4 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)4 NoOpNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer)4 LdapComparator (org.apache.directory.api.ldap.model.schema.LdapComparator)3 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)3 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)3 Entry (org.apache.directory.api.ldap.model.entry.Entry)2 Value (org.apache.directory.api.ldap.model.entry.Value)2 DitContentRule (org.apache.directory.api.ldap.model.schema.DitContentRule)2