From 7412d2bad9b8184aa319eea7bcfaff1e0d0e879c Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Fri, 14 Mar 2014 16:51:27 +0000
Subject: [PATCH] Checkpoint commit for OPENDJ-1308 Migrate schema support

---
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/api/VirtualAttributeProvider.java                               |   17 ++------
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/types/AttributeBuilder.java                                     |   25 +++---------
 opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/schema/ApproximateMatchingRuleTest.java |   21 ++++------
 3 files changed, 20 insertions(+), 43 deletions(-)

diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/api/VirtualAttributeProvider.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/api/VirtualAttributeProvider.java
index f0caed3..4eb518e 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/api/VirtualAttributeProvider.java
+++ b/opendj-sdk/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;
   }
 
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/types/AttributeBuilder.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/types/AttributeBuilder.java
index 43b98a2..9df765d 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/types/AttributeBuilder.java
+++ b/opendj-sdk/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".
diff --git a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/schema/ApproximatematchingRule.java b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/schema/ApproximateMatchingRuleTest.java
similarity index 92%
rename from opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/schema/ApproximatematchingRule.java
rename to opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/schema/ApproximateMatchingRuleTest.java
index 5186814..4ba3020 100644
--- a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/schema/ApproximatematchingRule.java
+++ b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/schema/ApproximateMatchingRuleTest.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));
   }
 }

--
Gitblit v1.10.0