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

Fabio Pistolesi
07.26.2015 d9ef4462a53d5ae301f2e86c4299503b155f1118
OPENDJ-2295 Provide a method to get back human readable strings from normalized index keys

Add a best effort conversion method from keys to a human readable printable string, using hexadecimal dump by default
and string for basic string type matching rules.
23 files modified
144 ■■■■■ changed files
opendj-core/src/main/java/com/forgerock/opendj/util/StaticUtils.java 14 ●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/ByteString.java 2 ●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractMatchingRuleImpl.java 10 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractSubstringMatchingRuleImpl.java 10 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactEqualityMatchingRuleImpl.java 5 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactIA5EqualityMatchingRuleImpl.java 5 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreEqualityMatchingRuleImpl.java 5 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreIA5EqualityMatchingRuleImpl.java 5 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DirectoryStringFirstComponentEqualityMatchingRuleImpl.java 5 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DistinguishedNameEqualityMatchingRuleImpl.java 5 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DoubleMetaphoneApproximateMatchingRuleImpl.java 5 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/NumericStringEqualityMatchingRuleImpl.java 5 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectIdentifierEqualityMatchingRuleImpl.java 5 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/OctetStringSubstringMatchingRuleImpl.java 5 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/TelephoneNumberEqualityMatchingRuleImpl.java 5 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/TimeBasedMatchingRulesImpl.java 9 ●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UUIDEqualityMatchingRuleImpl.java 5 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UserPasswordExactEqualityMatchingRuleImpl.java 5 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/spi/Indexer.java 11 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/EqualityIndexer.java 5 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/AttributeIndex.java 6 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/HistoricalCsnOrderingMatchingRuleImpl.java 6 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/schema/AbstractPasswordEqualityMatchingRuleImpl.java 6 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/com/forgerock/opendj/util/StaticUtils.java
@@ -731,13 +731,23 @@
     *         representation.
     */
    public static char byteToASCII(final byte b) {
        if (b >= 32 && b <= 126) {
        if (isPrintable(b)) {
            return (char) b;
        }
        return ' ';
    }
    /**
     * Returns whether the byte is a printable ASCII character.
     *
     * @param b
     *          The byte for which to determine whether it is printable ASCII
     * @return true if the byte is a printable ASCII character
     */
    public static boolean isPrintable(final byte b) {
        return 32 <= b && b <= 126;
    }
    /** Prevent instantiation. */
    private StaticUtils() {
        // No implementation required.
opendj-core/src/main/java/org/forgerock/opendj/ldap/ByteString.java
@@ -793,7 +793,7 @@
    /**
     * Returns a string representation of the contents of this byte sequence
     * using hexadecimal characters and a percent prefix (#) before each char.
     * using hexadecimal characters and a percent prefix (%) before each char.
     *
     * @return A string representation of the contents of this byte sequence
     *         using percent + hexadecimal characters.
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractMatchingRuleImpl.java
@@ -38,6 +38,7 @@
import org.forgerock.opendj.ldap.spi.Indexer;
import static org.forgerock.opendj.ldap.Assertion.*;
import static com.forgerock.opendj.util.StaticUtils.*;
/**
 * This class implements a default equality or approximate matching rule that
@@ -84,11 +85,20 @@
        }
        @Override
        public String keyToHumanReadableString(ByteSequence key) {
            return AbstractMatchingRuleImpl.this.keyToHumanReadableString(key);
        }
        @Override
        public String getIndexID() {
            return indexID;
        }
    }
    String keyToHumanReadableString(ByteSequence key) {
        return key.toByteString().toHexString();
    }
    @Override
    public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue)
            throws DecodeException {
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractSubstringMatchingRuleImpl.java
@@ -251,6 +251,11 @@
            }
        }
        @Override
        public String keyToHumanReadableString(ByteSequence key) {
            return AbstractSubstringMatchingRuleImpl.this.keyToHumanReadableString(key);
        }
        /** {@inheritDoc} */
        @Override
        public String getIndexID() {
@@ -270,6 +275,11 @@
        this.equalityIndexId = equalityIndexId;
    }
    @Override
    String keyToHumanReadableString(ByteSequence key) {
        return key.toString();
    }
    /** {@inheritDoc} */
    @Override
    public final Assertion getAssertion(final Schema schema, final ByteSequence assertionValue)
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactEqualityMatchingRuleImpl.java
@@ -46,4 +46,9 @@
    public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) {
        return SchemaUtils.normalizeStringAttributeValue(value, TRIM, NO_CASE_FOLD);
    }
    @Override
    public String keyToHumanReadableString(ByteSequence key) {
        return key.toString();
    }
}
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseExactIA5EqualityMatchingRuleImpl.java
@@ -48,4 +48,9 @@
            throws DecodeException {
        return SchemaUtils.normalizeIA5StringAttributeValue(value, TRIM, NO_CASE_FOLD);
    }
    @Override
    public String keyToHumanReadableString(ByteSequence key) {
        return key.toString();
    }
}
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreEqualityMatchingRuleImpl.java
@@ -46,4 +46,9 @@
    public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) {
        return SchemaUtils.normalizeStringAttributeValue(value, TRIM, CASE_FOLD);
    }
    @Override
    public String keyToHumanReadableString(ByteSequence key) {
        return key.toString();
    }
}
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CaseIgnoreIA5EqualityMatchingRuleImpl.java
@@ -48,4 +48,9 @@
            throws DecodeException {
        return SchemaUtils.normalizeIA5StringAttributeValue(value, TRIM, CASE_FOLD);
    }
    @Override
    public String keyToHumanReadableString(ByteSequence key) {
        return key.toString();
    }
}
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DirectoryStringFirstComponentEqualityMatchingRuleImpl.java
@@ -91,4 +91,9 @@
        // Grab the substring between the start pos and the current pos
        return ByteString.valueOf(string);
    }
    @Override
    public String keyToHumanReadableString(ByteSequence key) {
        return key.toString();
    }
}
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DistinguishedNameEqualityMatchingRuleImpl.java
@@ -54,4 +54,9 @@
            throw DecodeException.error(e.getMessageObject());
        }
    }
    @Override
    public String keyToHumanReadableString(ByteSequence key) {
        return key.toString();
    }
}
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/DoubleMetaphoneApproximateMatchingRuleImpl.java
@@ -944,4 +944,9 @@
            return false;
        }
    }
    @Override
    public String keyToHumanReadableString(ByteSequence key) {
        return key.toString();
    }
}
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/NumericStringEqualityMatchingRuleImpl.java
@@ -45,4 +45,9 @@
    public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) {
        return SchemaUtils.normalizeNumericStringAttributeValue(value);
    }
    @Override
    public String keyToHumanReadableString(ByteSequence key) {
        return key.toString();
    }
}
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectIdentifierEqualityMatchingRuleImpl.java
@@ -78,4 +78,9 @@
        final String oid = readOID(reader, schema.getOption(ALLOW_MALFORMED_NAMES_AND_OPTIONS));
        return ByteString.valueOf(resolveNames(schema, oid));
    }
    @Override
    String keyToHumanReadableString(ByteSequence key) {
        return key.toByteString().toString();
    }
}
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/OctetStringSubstringMatchingRuleImpl.java
@@ -45,4 +45,9 @@
    public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) {
        return value.toByteString();
    }
    @Override
    String keyToHumanReadableString(ByteSequence key) {
        return key.toByteString().toHexString();
    }
}
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/TelephoneNumberEqualityMatchingRuleImpl.java
@@ -61,4 +61,9 @@
        return ByteString.valueOf(buffer);
    }
    @Override
    public String keyToHumanReadableString(ByteSequence key) {
        return key.toString();
    }
}
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/TimeBasedMatchingRulesImpl.java
@@ -533,9 +533,9 @@
         * Decomposes an attribute value into a set of partial date and time
         * index keys.
         *
         * @param attValue
         * @param attributeValue
         *            The normalized attribute value
         * @param set
         * @param keys
         *            A set into which the keys will be inserted.
         */
        private void timeKeys(ByteSequence attributeValue, Collection<ByteString> keys) {
@@ -584,6 +584,11 @@
            matchingRule.timeKeys(value, keys);
        }
        @Override
        public String keyToHumanReadableString(ByteSequence key) {
            return key.toByteString().toHexString();
        }
        /** {@inheritDoc} */
        @Override
        public String getIndexID() {
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UUIDEqualityMatchingRuleImpl.java
@@ -124,4 +124,9 @@
        return ByteString.valueOf(builder);
    }
    @Override
    public String keyToHumanReadableString(ByteSequence key) {
        return key.toString();
    }
}
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UserPasswordExactEqualityMatchingRuleImpl.java
@@ -69,4 +69,9 @@
            return value.toByteString();
        }
    }
    @Override
    public String keyToHumanReadableString(ByteSequence key) {
        return key.toString();
    }
}
opendj-core/src/main/java/org/forgerock/opendj/ldap/spi/Indexer.java
@@ -64,4 +64,15 @@
     */
    void createKeys(Schema schema, ByteSequence value, Collection<ByteString> keys) throws DecodeException;
    /**
     * Returns a human readable representation of the key.
     * Does a best effort conversion from an index key to a string that can be printed, as
     * used by the diagnostic tools, which are the only users of the method.
     * It is not necessary for the resulting string to exactly match the value it was
     * generated from.
     *
     * @param key the byte string for the index key.
     * @return a human readable representation of the key
     */
    String keyToHumanReadableString(ByteSequence key);
}
opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/EqualityIndexer.java
@@ -72,4 +72,9 @@
    keys.add(equalityRule.normalizeAttributeValue(value));
  }
  @Override
  public String keyToHumanReadableString(ByteSequence key)
  {
    return key.toString();
  }
}
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/AttributeIndex.java
@@ -203,6 +203,12 @@
    }
    @Override
    public String keyToHumanReadableString(ByteSequence key)
    {
      return "PRESENCE";
    }
    @Override
    public String getIndexID()
    {
      return IndexType.PRESENCE.toString();
opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/HistoricalCsnOrderingMatchingRuleImpl.java
@@ -69,6 +69,12 @@
    {
      return ORDERING_ID;
    }
    @Override
    public String keyToHumanReadableString(ByteSequence key)
    {
      return key.toString();
    }
  }
  /** {@inheritDoc} */
opendj-server-legacy/src/main/java/org/opends/server/schema/AbstractPasswordEqualityMatchingRuleImpl.java
@@ -61,6 +61,12 @@
    }
    @Override
    public String keyToHumanReadableString(ByteSequence key)
    {
      return key.toString();
    }
    @Override
    public String getIndexID()
    {
      return EQUALITY_ID;