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());
}
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);
}
}
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);
}
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);
}
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;
}
Aggregations