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

Jean-Noel Rouvignac
14.15.2014 fd650a8fd632005824a2e64d78549992ee9ffda0
OPENDJ-1308 Migrate schema support

Used ConditionResult.valueOf() to simplify client code and make it more readable.
19 files modified
338 ■■■■ changed files
opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/util/ReadOnlyConfigFileHandler.java 19 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/api/ApproximateMatchingRule.java 15 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/api/EqualityMatchingRule.java 9 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/backends/BackupBackend.java 9 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/backends/MemoryBackend.java 15 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/backends/MonitorBackend.java 17 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/backends/RootDSEBackend.java 9 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/backends/jeb/BackendImpl.java 9 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/backends/jeb/Index.java 10 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/backends/task/TaskBackend.java 9 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/core/PasswordPolicyState.java 35 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/extensions/ConfigFileHandler.java 13 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/schema/AuthPasswordEqualityMatchingRule.java 13 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/schema/CollationMatchingRuleFactory.java 49 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/schema/TimeBasedMatchingRuleFactory.java 55 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/schema/UserPasswordEqualityMatchingRule.java 14 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/types/SearchFilter.java 27 ●●●● patch | view | raw | blame | history
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/schema/EqualityMatchingRuleTest.java 8 ●●●● patch | view | raw | blame | history
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/schema/TimeBasedMatchingRuleTest.java 3 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/util/ReadOnlyConfigFileHandler.java
@@ -26,14 +26,13 @@
 */
package org.opends.guitools.controlpanel.util;
import static org.opends.messages.ConfigMessages.*;
import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.ConditionResult;
import org.opends.server.admin.Configuration;
import org.opends.server.api.ConfigHandler;
import org.opends.server.config.ConfigEntry;
@@ -48,7 +47,6 @@
import org.opends.server.types.BackupConfig;
import org.opends.server.types.BackupDirectory;
import org.opends.server.types.CanceledOperationException;
import org.forgerock.opendj.ldap.ConditionResult;
import org.opends.server.types.DN;
import org.opends.server.types.DirectoryEnvironmentConfig;
import org.opends.server.types.DirectoryException;
@@ -63,6 +61,8 @@
import org.opends.server.util.LDIFReader;
import org.opends.server.util.StaticUtils;
import static org.opends.messages.ConfigMessages.*;
/**
 * A class used to read the configuration from a file.  This config file
 * handler does not allow to modify the configuration, only to read it.
@@ -384,18 +384,11 @@
  public ConditionResult hasSubordinates(DN entryDN) throws DirectoryException
  {
    ConfigEntry baseEntry = configEntries.get(entryDN);
    if(baseEntry == null)
    if (baseEntry != null)
    {
      return ConditionResult.UNDEFINED;
      return ConditionResult.valueOf(baseEntry.hasChildren());
    }
    else if(baseEntry.hasChildren())
    {
      return ConditionResult.TRUE;
    }
    else
    {
      return ConditionResult.FALSE;
    }
    return ConditionResult.UNDEFINED;
  }
  /**
opendj3-server-dev/src/server/org/opends/server/api/ApproximateMatchingRule.java
@@ -26,11 +26,8 @@
 */
package org.opends.server.api;
import org.forgerock.opendj.ldap.ConditionResult;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ConditionResult;
/**
 * This class defines the set of methods and structures that must be
@@ -86,14 +83,8 @@
  public ConditionResult valuesMatch(ByteSequence attributeValue,
                                     ByteSequence assertionValue)
  {
    if (approximatelyMatch(attributeValue, assertionValue))
    {
      return ConditionResult.TRUE;
    }
    else
    {
      return ConditionResult.FALSE;
    }
    return ConditionResult.valueOf(
        approximatelyMatch(attributeValue, assertionValue));
  }
}
opendj3-server-dev/src/server/org/opends/server/api/EqualityMatchingRule.java
@@ -82,14 +82,7 @@
  public ConditionResult valuesMatch(ByteSequence attributeValue,
                                     ByteSequence assertionValue)
  {
    if (areEqual(attributeValue, assertionValue))
    {
      return ConditionResult.TRUE;
    }
    else
    {
      return ConditionResult.FALSE;
    }
    return ConditionResult.valueOf(areEqual(attributeValue, assertionValue));
  }
opendj3-server-dev/src/server/org/opends/server/backends/BackupBackend.java
@@ -321,14 +321,7 @@
    {
      return ConditionResult.UNDEFINED;
    }
    else if(ret == 0)
    {
      return ConditionResult.FALSE;
    }
    else
    {
      return ConditionResult.TRUE;
    }
    return ConditionResult.valueOf(ret != 0);
  }
opendj3-server-dev/src/server/org/opends/server/backends/MemoryBackend.java
@@ -35,6 +35,9 @@
import java.util.Set;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.ConditionResult;
import org.forgerock.util.Reject;
import org.opends.server.admin.Configuration;
import org.opends.server.admin.std.server.MemoryBackendCfg;
import org.opends.server.api.Backend;
@@ -46,11 +49,9 @@
import org.opends.server.core.ModifyOperation;
import org.opends.server.core.ModifyDNOperation;
import org.opends.server.core.SearchOperation;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.types.AttributeType;
import org.opends.server.types.BackupConfig;
import org.opends.server.types.BackupDirectory;
import org.forgerock.opendj.ldap.ConditionResult;
import org.opends.server.types.Control;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.DN;
@@ -67,7 +68,6 @@
import org.opends.server.util.LDIFException;
import org.opends.server.util.LDIFReader;
import org.opends.server.util.LDIFWriter;
import org.forgerock.util.Reject;
import static org.opends.messages.BackendMessages.*;
import static org.opends.server.util.ServerConstants.*;
@@ -318,14 +318,7 @@
    {
      return ConditionResult.UNDEFINED;
    }
    else if(ret == 0)
    {
      return ConditionResult.FALSE;
    }
    else
    {
      return ConditionResult.TRUE;
    }
    return ConditionResult.valueOf(ret != 0);
  }
  /**
opendj3-server-dev/src/server/org/opends/server/backends/MonitorBackend.java
@@ -496,22 +496,13 @@
      throws DirectoryException
  {
    final NavigableMap<DN, MonitorProvider<?>> dit = getDIT();
    if (!dit.containsKey(entryDN))
    {
      return ConditionResult.UNDEFINED;
    }
    else
    if (dit.containsKey(entryDN))
    {
      final DN nextDN = dit.higherKey(entryDN);
      if (nextDN == null || !nextDN.isDescendantOf(entryDN))
      {
        return ConditionResult.FALSE;
      }
      else
      {
        return ConditionResult.TRUE;
      }
      return ConditionResult.valueOf(
          nextDN != null && nextDN.isDescendantOf(entryDN));
    }
    return ConditionResult.UNDEFINED;
  }
opendj3-server-dev/src/server/org/opends/server/backends/RootDSEBackend.java
@@ -394,14 +394,7 @@
    {
      return ConditionResult.UNDEFINED;
    }
    else if(ret == 0)
    {
      return ConditionResult.FALSE;
    }
    else
    {
      return ConditionResult.TRUE;
    }
    return ConditionResult.valueOf(ret != 0);
  }
opendj3-server-dev/src/server/org/opends/server/backends/jeb/BackendImpl.java
@@ -525,14 +525,7 @@
    {
      return ConditionResult.UNDEFINED;
    }
    else if(ret == 0)
    {
      return ConditionResult.FALSE;
    }
    else
    {
      return ConditionResult.TRUE;
    }
    return ConditionResult.valueOf(ret != 0);
  }
opendj3-server-dev/src/server/org/opends/server/backends/jeb/Index.java
@@ -931,19 +931,11 @@
    {
      EntryIDSet entryIDList =
           new EntryIDSet(key.getData(), data.getData());
      if (!entryIDList.isDefined())
      {
        return ConditionResult.UNDEFINED;
      }
      else if (entryIDList.contains(entryID))
      {
        return ConditionResult.TRUE;
      }
      else
      {
        return ConditionResult.FALSE;
      }
      return ConditionResult.valueOf(entryIDList.contains(entryID));
    }
    else
    {
opendj3-server-dev/src/server/org/opends/server/backends/task/TaskBackend.java
@@ -376,14 +376,7 @@
    {
      return ConditionResult.UNDEFINED;
    }
    else if(ret == 0)
    {
      return ConditionResult.FALSE;
    }
    else
    {
      return ConditionResult.TRUE;
    }
    return ConditionResult.valueOf(ret != 0);
  }
opendj3-server-dev/src/server/org/opends/server/core/PasswordPolicyState.java
@@ -1902,16 +1902,17 @@
   */
  public boolean isPasswordExpired()
  {
    if ((isPasswordExpired == null) ||
        (isPasswordExpired == ConditionResult.UNDEFINED))
    {
      getPasswordExpirationTime();
    }
    refreshIfUndefined(isPasswordExpired);
    return isPasswordExpired == ConditionResult.TRUE;
  }
  private void refreshIfUndefined(ConditionResult cond)
  {
    if (cond == null || cond == ConditionResult.UNDEFINED)
    {
      getPasswordExpirationTime();
    }
  }
  /**
   * Indicates whether the user's last password change was within the minimum
@@ -1986,12 +1987,7 @@
   */
  public boolean mayUseGraceLogin()
  {
    if ((mayUseGraceLogin == null) ||
        (mayUseGraceLogin == ConditionResult.UNDEFINED))
    {
      getPasswordExpirationTime();
    }
    refreshIfUndefined(mayUseGraceLogin);
    return mayUseGraceLogin == ConditionResult.TRUE;
  }
@@ -2007,11 +2003,7 @@
   */
  public boolean shouldWarn()
  {
    if ((shouldWarn == null) || (shouldWarn == ConditionResult.UNDEFINED))
    {
      getPasswordExpirationTime();
    }
    refreshIfUndefined(shouldWarn);
    return shouldWarn == ConditionResult.TRUE;
  }
@@ -2026,12 +2018,7 @@
   */
  public boolean isFirstWarning()
  {
    if ((isFirstWarning == null) ||
        (isFirstWarning == ConditionResult.UNDEFINED))
    {
      getPasswordExpirationTime();
    }
    refreshIfUndefined(isFirstWarning);
    return isFirstWarning == ConditionResult.TRUE;
  }
opendj3-server-dev/src/server/org/opends/server/extensions/ConfigFileHandler.java
@@ -1011,18 +1011,11 @@
         throws DirectoryException
  {
    ConfigEntry baseEntry = configEntries.get(entryDN);
    if(baseEntry == null)
    if (baseEntry != null)
    {
      return ConditionResult.UNDEFINED;
      return ConditionResult.valueOf(baseEntry.hasChildren());
    }
    else if(baseEntry.hasChildren())
    {
      return ConditionResult.TRUE;
    }
    else
    {
      return ConditionResult.FALSE;
    }
    return ConditionResult.UNDEFINED;
  }
opendj3-server-dev/src/server/org/opends/server/schema/AuthPasswordEqualityMatchingRule.java
@@ -181,18 +181,11 @@
      return ConditionResult.FALSE;
    }
    // We support the scheme, so make the determination.
    if (storageScheme.authPasswordMatches(assertionValue,
    return ConditionResult.valueOf(
        storageScheme.authPasswordMatches(assertionValue,
                                          authPWComponents[1].toString(),
                                          authPWComponents[2].toString()))
    {
      return ConditionResult.TRUE;
    }
    else
    {
      return ConditionResult.FALSE;
    }
                                          authPWComponents[2].toString()));
  }
opendj3-server-dev/src/server/org/opends/server/schema/CollationMatchingRuleFactory.java
@@ -875,14 +875,7 @@
    public ConditionResult valuesMatch(ByteSequence attributeValue,
        ByteSequence assertionValue)
    {
      if (assertionValue.equals(attributeValue))
      {
        return ConditionResult.TRUE;
      }
      else
      {
        return ConditionResult.FALSE;
      }
      return ConditionResult.valueOf(assertionValue.equals(attributeValue));
    }
@@ -1779,15 +1772,7 @@
        ByteSequence assertionValue)
    {
      int ret = attributeValue.compareTo(assertionValue);
      if (ret < 0)
      {
        return ConditionResult.TRUE;
      }
      else
      {
        return ConditionResult.FALSE;
      }
      return ConditionResult.valueOf(ret < 0);
    }
@@ -1847,15 +1832,7 @@
        ByteSequence assertionValue)
    {
      int ret = attributeValue.compareTo(assertionValue);
      if (ret <= 0)
      {
        return ConditionResult.TRUE;
      }
      else
      {
        return ConditionResult.FALSE;
      }
      return ConditionResult.valueOf(ret <= 0);
    }
@@ -1916,15 +1893,7 @@
        ByteSequence assertionValue)
    {
      int ret = attributeValue.compareTo(assertionValue);
      if (ret > 0)
      {
        return ConditionResult.TRUE;
      }
      else
      {
        return ConditionResult.FALSE;
      }
      return ConditionResult.valueOf(ret > 0);
    }
@@ -1984,15 +1953,7 @@
        ByteSequence assertionValue)
    {
      int ret = attributeValue.compareTo(assertionValue);
      if (ret >= 0)
      {
        return ConditionResult.TRUE;
      }
      else
      {
        return ConditionResult.FALSE;
      }
      return ConditionResult.valueOf(ret >= 0);
    }
opendj3-server-dev/src/server/org/opends/server/schema/TimeBasedMatchingRuleFactory.java
@@ -473,15 +473,7 @@
        ByteSequence assertionValue)
    {
      int ret = compareValues(attributeValue, assertionValue);
      if (ret > 0)
      {
        return ConditionResult.TRUE;
      }
      else
      {
        return ConditionResult.FALSE;
      }
      return ConditionResult.valueOf(ret > 0);
    }
@@ -561,15 +553,7 @@
        ByteSequence assertionValue)
    {
      int ret = compareValues(attributeValue, assertionValue);
      if (ret < 0)
      {
        return ConditionResult.TRUE;
      }
      else
      {
        return ConditionResult.FALSE;
      }
      return ConditionResult.valueOf(ret < 0);
    }
@@ -1048,37 +1032,16 @@
      int assertMonth = bb.getInt(16);
      int assertYear = bb.getInt(20);
      if(assertSecond != -1 && assertSecond !=second)
      if ((assertSecond != -1 && assertSecond != second)
          || (assertMinute != -1 && assertMinute != minute)
          || (assertHour != -1 && assertHour != hour)
          // All the non-zero values should match.
          || (assertDate != 0 && assertDate != date)
          || (assertMonth != -1 && assertMonth != month)
          || (assertYear != 0 && assertYear != year))
      {
        return ConditionResult.FALSE;
      }
      if(assertMinute !=-1 && assertMinute !=minute)
      {
        return ConditionResult.FALSE;
      }
      if(assertHour !=-1 && assertHour !=hour)
      {
        return ConditionResult.FALSE;
      }
      //All the non-zero values should match.
      if(assertDate !=0 && assertDate != date)
      {
        return ConditionResult.FALSE;
      }
      if(assertMonth !=-1 && assertMonth != month)
      {
        return ConditionResult.FALSE;
      }
      if(assertYear !=0 && assertYear != year)
      {
        return ConditionResult.FALSE;
      }
     return ConditionResult.TRUE;
    }
opendj3-server-dev/src/server/org/opends/server/schema/UserPasswordEqualityMatchingRule.java
@@ -34,10 +34,10 @@
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ConditionResult;
import org.opends.server.api.EqualityMatchingRule;
import org.opends.server.api.PasswordStorageScheme;
import org.opends.server.core.DirectoryServer;
import org.forgerock.opendj.ldap.ConditionResult;
import org.opends.server.types.DirectoryException;
import static org.opends.server.schema.SchemaConstants.*;
@@ -182,17 +182,9 @@
      return ConditionResult.FALSE;
    }
    // We support the scheme, so make the determination.
    if (storageScheme.passwordMatches(assertionValue,
        ByteString.valueOf(userPWComponents[1])))
    {
      return ConditionResult.TRUE;
    }
    else
    {
      return ConditionResult.FALSE;
    }
    return ConditionResult.valueOf(storageScheme.passwordMatches(
        assertionValue, ByteString.valueOf(userPWComponents[1])));
  }
opendj3-server-dev/src/server/org/opends/server/types/SearchFilter.java
@@ -3094,28 +3094,15 @@
    // See if the entry has an attribute with the requested type.
    // If so, then it's a match.  If not, then it's not a match.
    if (entry.hasAttribute(attributeType, attributeOptions))
    ConditionResult result = ConditionResult.valueOf(
        entry.hasAttribute(attributeType, attributeOptions));
    if (logger.isTraceEnabled())
    {
      if (logger.isTraceEnabled())
      {
        logger.trace(
            "Returning TRUE for presence component %s in " +
            "filter %s for entry %s",
            this, completeFilter, entry.getName());
      }
      return ConditionResult.TRUE;
      logger.trace(
          "Returning %s for presence component %s in filter %s for entry %s",
          result, this, completeFilter, entry.getName());
    }
    else
    {
      if (logger.isTraceEnabled())
      {
        logger.trace(
            "Returning FALSE for presence component %s in " +
            "filter %s for entry %s",
            this, completeFilter, entry.getName());
      }
      return ConditionResult.FALSE;
    }
    return result;
  }
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/schema/EqualityMatchingRuleTest.java
@@ -27,10 +27,10 @@
package org.opends.server.schema;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ConditionResult;
import org.opends.server.api.EqualityMatchingRule;
import org.opends.server.core.DirectoryServer;
import org.opends.server.types.AcceptRejectWarn;
import org.forgerock.opendj.ldap.ConditionResult;
import org.opends.server.types.DirectoryException;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -166,11 +166,7 @@
    ConditionResult liveResult =
      rule.valuesMatch(normalizedValue1, normalizedValue2);
    if (result == true)
      assertEquals(ConditionResult.TRUE, liveResult);
    else
      assertEquals(ConditionResult.FALSE, liveResult);
    assertEquals(liveResult, ConditionResult.valueOf(result));
  }
}
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/schema/TimeBasedMatchingRuleTest.java
@@ -339,8 +339,7 @@
    MatchingRule partialTimeRule = DirectoryServer.getMatchingRule(
            EXT_PARTIAL_DATE_TIME_NAME.toLowerCase());
    ByteString str = partialTimeRule.normalizeAssertionValue(ByteString.valueOf(assertionValue));
    assertTrue(partialTimeRule.valuesMatch(ByteString.valueOf(attributeValue), str) ==
            ConditionResult.TRUE);
    assertEquals(partialTimeRule.valuesMatch(ByteString.valueOf(attributeValue), str), ConditionResult.TRUE);
  }