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

Nicolas Capponi
24.48.2016 e63819ecedabbbac87514c1377c120c71fe7ffa4
OPENDJ-2965 Simplify OR and AND filters when only one element is provided in the expression
3 files modified
21 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/protocols/ldap/LDAPFilter.java 8 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/SearchFilter.java 4 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/types/SearchFilterTests.java 9 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/protocols/ldap/LDAPFilter.java
@@ -1866,7 +1866,13 @@
    }
    else
    {
      subComps = new ArrayList<>(filterComponents.size());
      int compSize = filterComponents.size();
      if (compSize == 1)
      {
        // the filter can be simplified to the single component
        return filterComponents.get(0).toSearchFilter();
      }
      subComps = new ArrayList<>(compSize);
      for (RawFilter f : filterComponents)
      {
        subComps.add(f.toSearchFilter());
opendj-server-legacy/src/main/java/org/opends/server/types/SearchFilter.java
@@ -1107,6 +1107,10 @@
      return new SearchFilter(filterType, null, notComponent, null,
                              null, null, null, null, null, false);
    }
    else if ((filterType == FilterType.AND || filterType == FilterType.OR) && filterComponents.size() == 1)
    {
      return filterComponents.get(0);
    }
    else
    {
      return new SearchFilter(filterType, filterComponents, null,
opendj-server-legacy/src/test/java/org/opends/server/types/SearchFilterTests.java
@@ -83,8 +83,9 @@
            {"(!(sn=test))", "(!(sn=test))"},
            {"(|(sn=test)(sn=test2))", "(|(sn=test)(sn=test2))"},
            {"(&(sn=test))", "(&(sn=test))"},
            {"(|(sn=test))", "(|(sn=test))"},
            {"(&(sn=test))", "(sn=test)"},
            {"(|(sn=test))", "(sn=test)"},
            {"(&(objectclass=person)(|(sn=test)))", "(&(objectClass=person)(sn=test))"},
    };
  }
@@ -861,8 +862,8 @@
  private static final Object[][] TEST_EQUALS_PARAMS = new Object[][]{
          // These have duplicates, and their String representation should even reflect that.
          {"(&(sn=Smith))", "(&(sn=Smith)(sn=Smith))", true, true},
          {"(|(sn=Smith))", "(|(sn=Smith)(sn=Smith))", true, true},
          {"(&(sn=Smith))", "(sn=Smith)", true, true},
          {"(|(sn=Smith))", "(sn=Smith)", true, true},
          // These are reordered, so they are equivalent, but their String representations will differ
          {"(&(sn=Smith)(sn<=Aus))", "(&(sn<=Aus)(sn=Smith))", true, false},