use of org.apache.directory.api.ldap.model.schema.Normalizer 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.Normalizer in project directory-ldap-api by apache.
the class SchemaManagerDelTest method testDeleteExistingNormalizer.
// =========================================================================
// MatchingRuleUse deletion tests
// -------------------------------------------------------------------------
// TODO
// =========================================================================
// NameForm deletion tests
// -------------------------------------------------------------------------
// TODO
// =========================================================================
// Normalizer deletion tests
// -------------------------------------------------------------------------
@Test
public void testDeleteExistingNormalizer() throws Exception {
SchemaManager schemaManager = loadSchema("system");
int nrSize = schemaManager.getNormalizerRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
Normalizer nr = new BooleanNormalizer();
nr.setOid("0.1.1");
assertTrue(schemaManager.add(nr));
assertEquals(nrSize + 1, schemaManager.getNormalizerRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
// FIXME this lookup is failing ! but it shouldn't be
nr = schemaManager.lookupNormalizerRegistry("0.1.1");
assertNotNull(nr);
assertTrue(schemaManager.delete(nr));
try {
schemaManager.lookupNormalizerRegistry("0.1.1");
fail();
} catch (Exception e) {
// expected
}
assertEquals(nrSize, schemaManager.getNormalizerRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.schema.Normalizer in project directory-ldap-api by apache.
the class SchemaEntityFactory method getNormalizer.
/**
* {@inheritDoc}
*/
@Override
public Normalizer getNormalizer(SchemaManager schemaManager, NormalizerDescription normalizerDescription, Registries targetRegistries, String schemaName) throws LdapException {
checkDescription(normalizerDescription, SchemaConstants.NORMALIZER);
// The Comparator OID
String oid = getOid(normalizerDescription, SchemaConstants.NORMALIZER);
// Get the schema
Schema schema = getSchema(schemaName, targetRegistries);
if (schema == null) {
// The schema is not loaded. We can't create the requested Normalizer
String msg = I18n.err(I18n.ERR_16024_CANNOT_ADD_NORMALIZER, normalizerDescription.getName(), schemaName);
LOG.warn(msg);
throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
}
// The FQCN
String fqcn = getFqcn(normalizerDescription, SchemaConstants.NORMALIZER);
// get the byteCode
Attribute byteCode = getByteCode(normalizerDescription, SchemaConstants.NORMALIZER);
// Class load the normalizer
Normalizer normalizer = classLoadNormalizer(schemaManager, oid, fqcn, byteCode);
// Update the common fields
setSchemaObjectProperties(normalizer, normalizerDescription, schema);
return normalizer;
}
use of org.apache.directory.api.ldap.model.schema.Normalizer in project directory-ldap-api by apache.
the class SchemaEntityFactory method getNormalizer.
/**
* {@inheritDoc}
*/
@Override
public Normalizer getNormalizer(SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName) throws LdapException {
checkEntry(entry, SchemaConstants.NORMALIZER);
// The Normalizer OID
String oid = getOid(entry, SchemaConstants.NORMALIZER, schemaManager.isStrict());
// Get the schema
if (!schemaManager.isSchemaLoaded(schemaName)) {
// The schema is not loaded. We can't create the requested Normalizer
String msg = I18n.err(I18n.ERR_16024_CANNOT_ADD_NORMALIZER, entry.getDn().getName(), schemaName);
LOG.warn(msg);
throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
}
Schema schema = getSchema(schemaName, targetRegistries);
if (schema == null) {
// The schema is disabled. We still have to update the backend
String msg = I18n.err(I18n.ERR_16025_CANNOT_ADD_NORMALIZER_IN_REGISTRY, entry.getDn().getName(), schemaName);
LOG.info(msg);
schema = schemaManager.getLoadedSchema(schemaName);
}
// The FQCN
String className = getFqcn(entry, SchemaConstants.NORMALIZER);
// The ByteCode
Attribute byteCode = entry.get(MetaSchemaConstants.M_BYTECODE_AT);
try {
// Class load the Normalizer
Normalizer normalizer = classLoadNormalizer(schemaManager, oid, className, byteCode);
// Update the common fields
setSchemaObjectProperties(normalizer, entry, schema);
// return the resulting Normalizer
return normalizer;
} catch (Exception e) {
throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, e.getMessage(), e);
}
}
use of org.apache.directory.api.ldap.model.schema.Normalizer in project directory-ldap-api by apache.
the class TestEntryUtils method getCaseIgnoringAttributeNoNumbersType.
/* no protection*/
static AttributeType getCaseIgnoringAttributeNoNumbersType() {
MutableAttributeType attributeType = new MutableAttributeType("1.1.3.1");
LdapSyntax syntax = new LdapSyntax("1.1.1.1", "", true);
syntax.setSyntaxChecker(new SyntaxChecker("1.1.2.1") {
/**
* The mandatory serialVersionUID field
*/
public static final long serialVersionUID = 1L;
public boolean isValidSyntax(Object value) {
if (!(value instanceof String)) {
return false;
}
String strval = (String) value;
for (char c : strval.toCharArray()) {
if (Character.isDigit(c)) {
return false;
}
}
return true;
}
});
MutableMatchingRule matchingRule = new MutableMatchingRule("1.1.2.1");
matchingRule.setSyntax(syntax);
matchingRule.setLdapComparator(new LdapComparator<String>(matchingRule.getOid()) {
/**
* The mandatory serialVersionUID field
*/
public static final long serialVersionUID = 1L;
public int compare(String o1, String o2) {
return (o1 == null ? (o2 == null ? 0 : -1) : (o2 == null ? 1 : o1.compareTo(o2)));
}
});
Normalizer normalizer = new Normalizer("1.1.1") {
/**
* The mandatory serialVersionUID field
*/
public static final long serialVersionUID = 1L;
public String normalize(String value) throws LdapException {
return normalize(value, AssertionType.ATTRIBUTE_VALUE);
}
public String normalize(String value, PrepareString.AssertionType assertionType) throws LdapException {
return Strings.toLowerCaseAscii(value);
}
};
matchingRule.setNormalizer(normalizer);
attributeType.setEquality(matchingRule);
attributeType.setSyntax(syntax);
return attributeType;
}
Aggregations