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

Nicolas Capponi
14.51.2014 699c601799a26cb2a3e24171e4af4e90c2f93481
Checkpoint commit for OPENDJ-1308 Migrate schema support

Replace use of ApproximateMatchingRule#approximatelyMatch()
method by use of Assertion#matches() in order to get rid of
references to ApproximateMatchingRule class
1 files renamed
2 files modified
63 ■■■■■ changed files
opendj3-server-dev/src/server/org/opends/server/api/VirtualAttributeProvider.java 17 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/types/AttributeBuilder.java 25 ●●●● patch | view | raw | blame | history
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/schema/ApproximateMatchingRuleTest.java 21 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/api/VirtualAttributeProvider.java
@@ -34,6 +34,7 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.config.server.ConfigException;
import org.forgerock.opendj.ldap.Assertion;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ConditionResult;
@@ -539,23 +540,20 @@
                              VirtualAttributeRule rule,
                              AttributeValue value)
  {
    ApproximateMatchingRule matchingRule =
         rule.getAttributeType().getApproximateMatchingRule();
    ApproximateMatchingRule matchingRule = rule.getAttributeType().getApproximateMatchingRule();
    if (matchingRule == null)
    {
      return ConditionResult.UNDEFINED;
    }
    ByteString normalizedValue;
    Assertion assertion = null;
    try
    {
      normalizedValue = matchingRule.normalizeAttributeValue(value.getValue());
      assertion = matchingRule.getAssertion(value.getValue());
    }
    catch (Exception e)
    {
      logger.traceException(e);
      // We couldn't normalize the provided value => return "undefined".
      return ConditionResult.UNDEFINED;
    }
@@ -565,21 +563,16 @@
      try
      {
        ByteString nv = matchingRule.normalizeAttributeValue(v.getValue());
        if (matchingRule.approximatelyMatch(nv, normalizedValue))
        {
          return ConditionResult.TRUE;
        }
        result = assertion.matches(nv);
      }
      catch (Exception e)
      {
        logger.traceException(e);
        // We couldn't normalize one of the attribute values.
        // We will return "undefined" if we can't find a definite match
        result = ConditionResult.UNDEFINED;
      }
    }
    return result;
  }
opendj3-server-dev/src/server/org/opends/server/types/AttributeBuilder.java
@@ -39,11 +39,12 @@
import java.util.TreeSet;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.Assertion;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ConditionResult;
import org.forgerock.util.Reject;
import org.opends.server.api.ApproximateMatchingRule;
import org.opends.server.api.MatchingRule;
import org.opends.server.api.OrderingMatchingRule;
import org.opends.server.api.SubstringMatchingRule;
import org.opends.server.core.DirectoryServer;
@@ -149,33 +150,26 @@
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public final ConditionResult approximatelyEqualTo(
        AttributeValue value)
    public final ConditionResult approximatelyEqualTo(AttributeValue value)
    {
      ApproximateMatchingRule matchingRule = attributeType
          .getApproximateMatchingRule();
      MatchingRule matchingRule = attributeType.getApproximateMatchingRule();
      if (matchingRule == null)
      {
        return ConditionResult.UNDEFINED;
      }
      ByteString normalizedValue;
      Assertion assertion = null;
      try
      {
        normalizedValue =
          matchingRule.normalizeAttributeValue(value.getValue());
        assertion = matchingRule.getAssertion(value.getValue());
      }
      catch (Exception e)
      {
        logger.traceException(e);
        // We couldn't normalize the provided value. We should return
        // "undefined".
        return ConditionResult.UNDEFINED;
      }
@@ -184,16 +178,11 @@
      {
        try
        {
          ByteString nv = matchingRule.normalizeAttributeValue(v.getValue());
          if (matchingRule.approximatelyMatch(nv, normalizedValue))
          {
            return ConditionResult.TRUE;
          }
          result = assertion.matches(matchingRule.normalizeAttributeValue(v.getValue()));
        }
        catch (Exception e)
        {
          logger.traceException(e);
          // We couldn't normalize one of the attribute values. If we
          // can't find a definite match, then we should return
          // "undefined".
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/schema/ApproximateMatchingRuleTest.java
File was renamed from opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/schema/ApproximatematchingRule.java
@@ -28,12 +28,14 @@
import static org.testng.Assert.*;
import org.opends.server.api.ApproximateMatchingRule;
import org.opends.server.api.MatchingRule;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ConditionResult;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class ApproximatematchingRule extends SchemaTestCase
@SuppressWarnings("javadoc")
public class ApproximateMatchingRuleTest extends SchemaTestCase
{
  /**
   * Build the data for the approximateMatchingRules test.
@@ -141,22 +143,15 @@
    assertNotNull(rule);
    // Make sure that the specified class can be instantiated as a task.
    ApproximateMatchingRule ruleInstance =
      (ApproximateMatchingRule) rule.newInstance();
    MatchingRule ruleInstance = (MatchingRule) rule.newInstance();
    // we should call initializeMatchingRule but they all seem empty at the
    // moment.
    // ruleInstance.initializeMatchingRule(configEntry);
    // normalize the 2 provided values
    ByteString normalizedValue1 =
      ruleInstance.normalizeAttributeValue(ByteString.valueOf(value1));
    ByteString normalizedValue2 =
      ruleInstance.normalizeAttributeValue(ByteString.valueOf(value2));
    ByteString normalizedValue1 = ruleInstance.normalizeAttributeValue(ByteString.valueOf(value1));
    ConditionResult liveResult = ruleInstance.getAssertion(ByteString.valueOf(value2)).matches(normalizedValue1);
    // check that the approximatelyMatch return the expected result.
    Boolean liveResult = ruleInstance.approximatelyMatch(normalizedValue1,
        normalizedValue2);
    assertEquals(result, liveResult);
    assertEquals(liveResult, ConditionResult.valueOf(result));
  }
}