mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Nicolas Capponi
22.06.2014 d14f9e08b56dda53fc2073b9caf031cbbd52fd4e
OPENDJ-1590 Add default matching rule for each collation matching rules

2 files modified
30 ■■■■ changed files
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchemaImpl.java 26 ●●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/CollationEqualityMatchingRuleTest.java 4 ●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchemaImpl.java
@@ -918,7 +918,11 @@
            final Locale locale = localesCache.get(names.get(0));
            addCollationMatchingRule(builder, oid, names, 1, "lt", collationLessThanMatchingRule(locale));
            addCollationMatchingRule(builder, oid, names, 2, "lte", collationLessThanOrEqualMatchingRule(locale));
            addCollationMatchingRule(builder, oid, names, 3, "eq", collationEqualityMatchingRule(locale));
            MatchingRuleImpl collationEqualityMatchingRule = collationEqualityMatchingRule(locale);
            addCollationMatchingRule(builder, oid, names, 3, "eq", collationEqualityMatchingRule);
            // the default oid is registered with equality matching rule
            final int ignored = 0;
            addCollationMatchingRule(builder, oid, names, ignored, "", collationEqualityMatchingRule);
            addCollationMatchingRule(builder, oid, names, 4, "gte", collationGreaterThanOrEqualToMatchingRule(locale));
            addCollationMatchingRule(builder, oid, names, 5, "gt", collationGreaterThanMatchingRule(locale));
            addCollationMatchingRule(builder, oid, names, 6, "sub", collationSubstringMatchingRule(locale));
@@ -929,7 +933,8 @@
    private static void addCollationMatchingRule(final SchemaBuilder builder, final String baseOid,
            final List<String> names, final int numericSuffix, final String symbolicSuffix,
            final MatchingRuleImpl matchingRuleImplementation) {
        builder.buildMatchingRule(baseOid + "." + numericSuffix)
        final String oid = symbolicSuffix.isEmpty() ? baseOid : baseOid + "." + numericSuffix;
        builder.buildMatchingRule(oid)
            .names(collationMatchingRuleNames(names, numericSuffix, symbolicSuffix))
            .syntaxOID(SYNTAX_DIRECTORY_STRING_OID)
            .extraProperties(OPENDS_ORIGIN)
@@ -943,17 +948,24 @@
     * @param localeNames
     *            List of locale names that correspond to the matching rule (e.g., "en", "en-US")
     * @param numSuffix
     *            numeric suffix corresponding to type of matching rule (e.g, 5 for greater than matching rule)
     *            numeric suffix corresponding to type of matching rule (e.g, 5 for greater than matching rule). It is
     *            ignored if equal to zero (0).
     * @param symbolicSuffix
     *            symbolic suffix corresponding to type of matching rule (e.g, "gt" for greater than matching rule)
     *            symbolic suffix corresponding to type of matching rule (e.g, "gt" for greater than matching rule). It
     *            may be empty ("") to indicate the default rule.
     * @return the names list (e.g, "en.5", "en.gt", "en-US.5", "en-US.gt")
     */
    private static String[] collationMatchingRuleNames(final List<String> localeNames, final int numSuffix,
            final String symbolicSuffix) {
        final String symbolicSuffix) {
        final List<String> names = new ArrayList<String>();
        for (String localeName : localeNames) {
            names.add(localeName + "." + numSuffix);
            names.add(localeName + "." + symbolicSuffix);
            if (symbolicSuffix.isEmpty()) {
                // the default rule
                names.add(localeName);
            } else {
                names.add(localeName + "." + numSuffix);
                names.add(localeName + "." + symbolicSuffix);
            }
        }
        return names.toArray(new String[names.size()]);
    }
opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/CollationEqualityMatchingRuleTest.java
@@ -100,6 +100,10 @@
        // 'ar' does not share oid with another locale
        MatchingRule rule3 = Schema.getCoreSchema().getMatchingRule("ar.3");
        assertThat(rule3.getNames()).containsOnly("ar.eq", "ar.3");
        // equality matching rule is also the default matching rule
        MatchingRule rule4 = Schema.getCoreSchema().getMatchingRule("ar");
        assertThat(rule4.getNames()).containsOnly("ar");
    }
    @Test