From fc87c2ea7fffe1be9cbe6902a823068c84ca9393 Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Fri, 10 Oct 2014 14:34:56 +0000
Subject: [PATCH] OPENDJ-1592 CR-4782 Migrate time-based matching rules

---
 opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/RelativeTimeLessThanMatchingRuleTest.java    |   12 ---
 opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchemaImpl.java                          |   16 +++++
 opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/RelativeTimeGreaterThanMatchingRuleTest.java |   12 ---
 opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaConstants.java                         |   57 +++++++++++++++++++
 opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/PartialDateAndTimeMatchingRuleTestCase.java  |   12 ---
 opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/TimeBasedMatchingRulesImpl.java              |    8 +-
 opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchema.java                              |   50 ++++++++++++++++
 7 files changed, 129 insertions(+), 38 deletions(-)

diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchema.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchema.java
index d32c5db..1eed3f4 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchema.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchema.java
@@ -145,6 +145,8 @@
         = CoreSchemaImpl.getInstance().getMatchingRule("2.5.13.13");
     private static final MatchingRule CASE_EXACT_IA5_MATCHING_RULE
         = CoreSchemaImpl.getInstance().getMatchingRule("1.3.6.1.4.1.1466.109.114.1");
+    private static final MatchingRule CASE_EXACT_IA5_SUBSTRING_MATCHING_RULE
+        = CoreSchemaImpl.getInstance().getMatchingRule("1.3.6.1.4.1.26027.1.4.902");
     private static final MatchingRule CASE_EXACT_MATCHING_RULE
         = CoreSchemaImpl.getInstance().getMatchingRule("2.5.13.5");
     private static final MatchingRule CASE_EXACT_ORDERING_MATCHING_RULE
@@ -199,10 +201,16 @@
         = CoreSchemaImpl.getInstance().getMatchingRule("2.5.13.18");
     private static final MatchingRule OCTET_STRING_SUBSTRINGS_MATCHING_RULE
         = CoreSchemaImpl.getInstance().getMatchingRule("2.5.13.19");
+    private static final MatchingRule PARTIAL_DATE_AND_TIME_MATCHING_RULE
+        = CoreSchemaImpl.getInstance().getMatchingRule("1.3.6.1.4.1.26027.1.4.7");
     private static final MatchingRule PRESENTATION_ADDRESS_MATCHING_RULE
         = CoreSchemaImpl.getInstance().getMatchingRule("2.5.13.22");
     private static final MatchingRule PROTOCOL_INFORMATION_MATCHING_RULE
         = CoreSchemaImpl.getInstance().getMatchingRule("2.5.13.24");
+    private static final MatchingRule RELATIVE_TIME_GREATER_THAN_ORDERING_MATCHING_RULE
+        = CoreSchemaImpl.getInstance().getMatchingRule("1.3.6.1.4.1.26027.1.4.5");
+    private static final MatchingRule RELATIVE_TIME_LESS_THAN_ORDERING_MATCHING_RULE
+        = CoreSchemaImpl.getInstance().getMatchingRule("1.3.6.1.4.1.26027.1.4.6");
     private static final MatchingRule TELEPHONE_NUMBER_MATCHING_RULE
         = CoreSchemaImpl.getInstance().getMatchingRule("2.5.13.20");
     private static final MatchingRule TELEPHONE_NUMBER_SUBSTRINGS_MATCHING_RULE
@@ -936,7 +944,17 @@
     }
 
     /**
-     * Returns a reference to the {@code caseExactSubstringsMatch} Matching Rule which has the OID {@code 2.5.13.7}.
+     * Returns a reference to the {@code caseExactIA5SubstringsMatch} Matching Rule which has the OID {@code 2.5.13.7}.
+     *
+     * @return A reference to the {@code caseExactIA5SubstringsMatch} Matching Rule.
+     */
+    public static MatchingRule getCaseExactIA5SubstringsMatchingRule() {
+        return CASE_EXACT_IA5_SUBSTRING_MATCHING_RULE;
+    }
+
+    /**
+     * Returns a reference to the {@code caseExactSubstringsMatch} Matching Rule which has the
+     * OID {@code 1.3.6.1.4.1.26027.1.4.902}.
      *
      * @return A reference to the {@code caseExactSubstringsMatch} Matching Rule.
      */
@@ -1168,6 +1186,16 @@
     }
 
     /**
+     * Returns a reference to the {@code partialDateAndTime} Matching Rule
+     * which has the OID {@code 1.3.6.1.4.1.26027.1.4.7}.
+     *
+     * @return A reference to the {@code partialDateAndTime} Matching Rule.
+     */
+    public static MatchingRule getPartialDateAndTimeMatchingRule() {
+        return PARTIAL_DATE_AND_TIME_MATCHING_RULE;
+    }
+
+    /**
      * Returns a reference to the {@code presentationAddressMatch} Matching Rule which has the OID {@code 2.5.13.22}.
      *
      * @return A reference to the {@code presentationAddressMatch} Matching Rule.
@@ -1186,6 +1214,26 @@
     }
 
     /**
+     * Returns a reference to the {@code relativeTimeGreaterThan} Matching Rule
+     * which has the OID {@code 1.3.6.1.4.1.26027.1.4.5}.
+     *
+     * @return A reference to the {@code relativeTimeGreaterThan} Matching Rule.
+     */
+    public static MatchingRule getRelativeTimeGreaterThanMatchingRule() {
+        return RELATIVE_TIME_GREATER_THAN_ORDERING_MATCHING_RULE;
+    }
+
+    /**
+     * Returns a reference to the {@code relativeTimeLessThan} Matching Rule
+     * which has the OID {@code 1.3.6.1.4.1.26027.1.4.6}.
+     *
+     * @return A reference to the {@code relativeTimeLessThan} Matching Rule.
+     */
+    public static MatchingRule getRelativeTimeLessThanMatchingRule() {
+        return RELATIVE_TIME_LESS_THAN_ORDERING_MATCHING_RULE;
+    }
+
+    /**
      * Returns a reference to the {@code telephoneNumberMatch} Matching Rule which has the OID {@code 2.5.13.20}.
      *
      * @return A reference to the {@code telephoneNumberMatch} Matching Rule.
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchemaImpl.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchemaImpl.java
index 71768fa..87b4a60 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchemaImpl.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CoreSchemaImpl.java
@@ -28,6 +28,7 @@
 package org.forgerock.opendj.ldap.schema;
 
 import static org.forgerock.opendj.ldap.schema.SchemaConstants.*;
+import static org.forgerock.opendj.ldap.schema.TimeBasedMatchingRulesImpl.*;
 
 import java.util.Arrays;
 import java.util.Collections;
@@ -684,6 +685,21 @@
                 .description(AMR_DOUBLE_METAPHONE_DESCRIPTION).syntaxOID(SYNTAX_DIRECTORY_STRING_OID)
                 .extraProperties(OPENDJ_ORIGIN).implementation(new DoubleMetaphoneApproximateMatchingRuleImpl())
                 .addToSchema();
+        builder.buildMatchingRule(OMR_RELATIVE_TIME_GREATER_THAN_OID)
+                .names(OMR_RELATIVE_TIME_GREATER_THAN_NAME, OMR_RELATIVE_TIME_GREATER_THAN_ALT_NAME)
+                .description(OMR_RELATIVE_TIME_GREATER_THAN_DESCRIPTION).syntaxOID(SYNTAX_GENERALIZED_TIME_OID)
+                .extraProperties(OPENDJ_ORIGIN).implementation(relativeTimeGTOMatchingRule())
+                .addToSchema();
+        builder.buildMatchingRule(OMR_RELATIVE_TIME_LESS_THAN_OID)
+                .names(OMR_RELATIVE_TIME_LESS_THAN_NAME, OMR_RELATIVE_TIME_LESS_THAN_ALT_NAME)
+                .description(OMR_RELATIVE_TIME_LESS_THAN_DESCRIPTION).syntaxOID(SYNTAX_GENERALIZED_TIME_OID)
+                .extraProperties(OPENDJ_ORIGIN).implementation(relativeTimeLTOMatchingRule())
+                .addToSchema();
+        builder.buildMatchingRule(MR_PARTIAL_DATE_AND_TIME_OID)
+                .names(Collections.singletonList(MR_PARTIAL_DATE_AND_TIME_NAME))
+                .description(MR_PARTIAL_DATE_AND_TIME_DESCRIPTION).syntaxOID(SYNTAX_GENERALIZED_TIME_OID)
+                .extraProperties(OPENDJ_ORIGIN).implementation(partialDateAndTimeMatchingRule())
+                .addToSchema();
     }
 
     private static void defaultAttributeTypes(final SchemaBuilder builder) {
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaConstants.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaConstants.java
index db275cb..879d778 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaConstants.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/SchemaConstants.java
@@ -425,6 +425,21 @@
     public static final String EMR_WORD_OID = "2.5.13.32";
 
     /**
+     * The Description for the partialDateAndTimeMatchingRule ordering matching rule.
+     */
+    public static final String MR_PARTIAL_DATE_AND_TIME_DESCRIPTION = "partial date and time matching";
+
+    /**
+     * The Name for the partialDateAndTimeMatchingRule ordering matching rule.
+     */
+    public static final String MR_PARTIAL_DATE_AND_TIME_NAME = "partialDateAndTimeMatchingRule";
+
+    /**
+     * The OID for the partialDateAndTimeMatchingRule ordering matching rule.
+     */
+    public static final String MR_PARTIAL_DATE_AND_TIME_OID = OID_OPENDS_SERVER_MATCHING_RULE_BASE  + ".7";
+
+    /**
      * The name for the caseExactOrderingMatch ordering matching rule.
      */
     public static final String OMR_CASE_EXACT_NAME = "caseExactOrderingMatch";
@@ -485,6 +500,48 @@
     public static final String OMR_OCTET_STRING_OID = "2.5.13.18";
 
     /**
+     * The Description for the relativeTimeGreaterThan ordering matching rule.
+     */
+    public static final String OMR_RELATIVE_TIME_GREATER_THAN_DESCRIPTION =
+        "greater-than relative time for time-based searches";
+
+    /**
+     * The Name for the relativeTimeGreaterThan ordering matching rule.
+     */
+    public static final String OMR_RELATIVE_TIME_GREATER_THAN_NAME = "relativeTimeGTOrderingMatch";
+
+    /**
+     * The alternative name for the relativeTimeGreaterThan ordering matching rule.
+     */
+    public static final String OMR_RELATIVE_TIME_GREATER_THAN_ALT_NAME = "relativeTimeOrderingMatch.gt";
+
+    /**
+     * The OID for the relativeTimeGreaterThan ordering matching rule.
+     */
+    public static final String OMR_RELATIVE_TIME_GREATER_THAN_OID = OID_OPENDS_SERVER_MATCHING_RULE_BASE  + ".5";
+
+    /**
+     * The Description for the relativeTimeLessThan ordering matching rule.
+     */
+    public static final String OMR_RELATIVE_TIME_LESS_THAN_DESCRIPTION =
+        "less-than relative time for time-based searches";
+
+    /**
+     * The Name for the relativeTimeLessThan ordering matching rule.
+     */
+    public static final String OMR_RELATIVE_TIME_LESS_THAN_NAME = "relativeTimeLTOrderingMatch";
+
+    /**
+     * The alternative name for the relativeTimeLessThan ordering matching rule.
+     */
+    public static final String OMR_RELATIVE_TIME_LESS_THAN_ALT_NAME = "relativeTimeOrderingMatch.lt";
+
+    /**
+     * The OID for the relativeTimeLessThan ordering matching rule.
+     */
+    public static final String OMR_RELATIVE_TIME_LESS_THAN_OID = OID_OPENDS_SERVER_MATCHING_RULE_BASE  + ".6";
+
+    /**
      * The name for the uuidOrderingMatch ordering matching rule.
      */
     public static final String OMR_UUID_NAME = "uuidOrderingMatch";
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/TimeBasedMatchingRulesImpl.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/TimeBasedMatchingRulesImpl.java
index dac394e..c34e311 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/TimeBasedMatchingRulesImpl.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/TimeBasedMatchingRulesImpl.java
@@ -57,7 +57,7 @@
 /**
  * Implementations of time-based matching rules.
  */
-public final class TimeBasedMatchingRulesImpl {
+final class TimeBasedMatchingRulesImpl {
 
     private static final String RELATIVE_TIME_INDEX_ID = "rt";
     private static final String PARTIAL_DATE_TIME_INDEX_ID = "pdt";
@@ -82,7 +82,7 @@
      *
      * @return the matching rule implementation
      */
-    public static MatchingRuleImpl relativeTimeGTOMatchingRule() {
+    static MatchingRuleImpl relativeTimeGTOMatchingRule() {
         return new RelativeTimeGreaterThanOrderingMatchingRuleImpl();
     }
 
@@ -91,7 +91,7 @@
      *
      * @return the matching rule implementation
      */
-    public static MatchingRuleImpl relativeTimeLTOMatchingRule() {
+    static MatchingRuleImpl relativeTimeLTOMatchingRule() {
         return new RelativeTimeLessThanOrderingMatchingRuleImpl();
     }
 
@@ -100,7 +100,7 @@
      *
      * @return the matching rule implementation
      */
-    public static MatchingRuleImpl partialDateAndTimeMatchingRule() {
+    static MatchingRuleImpl partialDateAndTimeMatchingRule() {
         return new PartialDateAndTimeMatchingRuleImpl();
     }
 
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/PartialDateAndTimeMatchingRuleTestCase.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/PartialDateAndTimeMatchingRuleTestCase.java
index 181fcf9..d2e62df 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/PartialDateAndTimeMatchingRuleTestCase.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/PartialDateAndTimeMatchingRuleTestCase.java
@@ -179,17 +179,7 @@
     /** {@inheritDoc} */
     @Override
     protected MatchingRule getRule() {
-        // Note that oid and names are not used by the test (ie, they could be any value, test should pass anyway)
-        // Only the implementation class and the provided locale are really tested here.
-        String oid = "1.3.6.1.4.1.26027.1.4.7";
-        Schema schema = new SchemaBuilder(Schema.getCoreSchema()).
-            buildMatchingRule(oid).
-                syntaxOID(SchemaConstants.SYNTAX_GENERALIZED_TIME_OID).
-                names("partialDateAndTimeMatchingRule").
-                implementation(TimeBasedMatchingRulesImpl.partialDateAndTimeMatchingRule()).
-                addToSchema().
-            toSchema();
-        return schema.getMatchingRule(oid);
+        return CoreSchema.getPartialDateAndTimeMatchingRule();
     }
 
     @Test
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/RelativeTimeGreaterThanMatchingRuleTest.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/RelativeTimeGreaterThanMatchingRuleTest.java
index b6e5b29..1c513b3 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/RelativeTimeGreaterThanMatchingRuleTest.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/RelativeTimeGreaterThanMatchingRuleTest.java
@@ -113,17 +113,7 @@
     /** {@inheritDoc} */
     @Override
     protected MatchingRule getRule() {
-        // Note that oid and names are not used by the test (ie, they could be any value, test should pass anyway)
-        // Only the implementation class and the provided locale are really tested here.
-        String oid = "1.3.6.1.4.1.26027.1.4.5";
-        Schema schema = new SchemaBuilder(Schema.getCoreSchema()).
-            buildMatchingRule(oid).
-                syntaxOID(SchemaConstants.SYNTAX_GENERALIZED_TIME_OID).
-                names("relativeTimeGTOrderingMatch.gt").
-                implementation(TimeBasedMatchingRulesImpl.relativeTimeGTOMatchingRule()).
-                addToSchema().
-            toSchema();
-        return schema.getMatchingRule(oid);
+        return CoreSchema.getRelativeTimeGreaterThanMatchingRule();
     }
 
     @Test
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/RelativeTimeLessThanMatchingRuleTest.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/RelativeTimeLessThanMatchingRuleTest.java
index 1e3f6b1..177887a 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/RelativeTimeLessThanMatchingRuleTest.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/RelativeTimeLessThanMatchingRuleTest.java
@@ -114,17 +114,7 @@
     /** {@inheritDoc} */
     @Override
     protected MatchingRule getRule() {
-        // Note that oid and names are not used by the test (ie, they could be any value, test should pass anyway)
-        // Only the implementation class and the provided locale are really tested here.
-        String oid = "1.3.6.1.4.1.26027.1.4.6";
-        Schema schema = new SchemaBuilder(Schema.getCoreSchema()).
-            buildMatchingRule(oid).
-                syntaxOID(SchemaConstants.SYNTAX_GENERALIZED_TIME_OID).
-                names("relativeTimeLTOrderingMatch.lt").
-                implementation(TimeBasedMatchingRulesImpl.relativeTimeLTOMatchingRule()).
-                addToSchema().
-            toSchema();
-        return schema.getMatchingRule(oid);
+        return CoreSchema.getRelativeTimeLessThanMatchingRule();
     }
 
     @Test

--
Gitblit v1.10.0