You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by je...@apache.org on 2018/06/08 17:41:53 UTC

[sling-whiteboard] branch master updated: updated readme and tests

This is an automated email from the ASF dual-hosted git repository.

jeb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new e5cc446  updated readme and tests
e5cc446 is described below

commit e5cc446abb304aa9f0d33d05abe2986fce9e1f5f
Author: Jason E Bailey <je...@apache.org>
AuthorDate: Fri Jun 8 13:41:47 2018 -0400

    updated readme and tests
---
 resource-filter/README.md                                      | 10 +++++++++-
 .../apache/sling/resource/filter/ResourceFilterArgTest.java    |  7 +++----
 .../apache/sling/resource/predicates/PropertyPredicates.java   |  5 +++--
 3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/resource-filter/README.md b/resource-filter/README.md
index 5d7f8d5..8c09685 100644
--- a/resource-filter/README.md
+++ b/resource-filter/README.md
@@ -59,7 +59,7 @@ Values for comparison are obtained through multiple methods
 All types are converted to either a String or a Number. For direct equivalence the comparison is done as a String. For relational comparisons the object will be adapted to a number.
 
 ### Dates/Instants
-Dates are a special, there are multiple ways to enter a date.
+Dates are special, there are multiple ways to enter a date.
 
 In line, as part of the query, a date can be identified as a string that conforms to a standard ISO-8601 date time.
 
@@ -99,6 +99,14 @@ OOTB Functions are:
 | date  | 0 - 2     | Instant | First argument is string representation of the date, second argument is a standard Java DateFormat representation of the value. No argument returns the current time. |
 | path  | none		| String  | path of the tested resource        |
 
+### Arguments
+The ResourceFilter can have key value pairs added so that the values may be used as part of the script resolution. Arguments are accessed by using the dollar sign '$'
+
+```java
+new ResourceFilter("[jcr:content/sling:resourceType] != $type").addArgument("type","apps/components/page/folder");
+```
+
+
 ## Optimizing Traversals
 Similar to indexing in a query there are strategies that you can do within a tree traversal so that traversals can be done in an efficient manner across a large number of resources. The following strategies will assist in traversal optimization.
 
diff --git a/resource-filter/src/test/java/org/apache/sling/resource/filter/ResourceFilterArgTest.java b/resource-filter/src/test/java/org/apache/sling/resource/filter/ResourceFilterArgTest.java
index c1189bd..585a37a 100644
--- a/resource-filter/src/test/java/org/apache/sling/resource/filter/ResourceFilterArgTest.java
+++ b/resource-filter/src/test/java/org/apache/sling/resource/filter/ResourceFilterArgTest.java
@@ -40,15 +40,14 @@ public class ResourceFilterArgTest {
 
     @Test
     public void testMatchingNameInArg() throws Exception {
-        ResourceFilter filter = new ResourceFilter(
-                "[jcr:content/created] > $date and [jcr:content/jcr:title] == $lang")
+        ResourceFilter filter = new ResourceFilter("[jcr:content/jcr:title] == $lang")
                         .addArgument("date", "2013-08-08T16:32:59").addArgument("lang", "Mongolian");
         List<Resource> found = handle(START_PATH, filter);
         assertEquals(1, found.size());
     }
     
     @Test
-    public void testMatchingNameInList() throws Exception {
+    public void testMatchingNameAndMultipleArgs() throws Exception {
         ResourceFilter filter = new ResourceFilter(
                 "[jcr:content/created] > $date and [jcr:content/jcr:title] == $lang")
                         .addArgument("date", "2013-08-08T16:32:59").addArgument("lang", "Mongolian");
@@ -57,7 +56,7 @@ public class ResourceFilterArgTest {
     }
     
     @Test
-    public void testNameFunctionAgainstRegex2() throws ParseException, Exception {
+    public void testNameFunctionAgainstRegex() throws ParseException, Exception {
         ResourceFilter query = new ResourceFilter("name() like $regex").addArgument("regex", "testpage[1-2]");
         List<Resource> found = handle(START_PATH, query);
         assertEquals(2, found.size());
diff --git a/resource-predicates/src/main/java/org/apache/sling/resource/predicates/PropertyPredicates.java b/resource-predicates/src/main/java/org/apache/sling/resource/predicates/PropertyPredicates.java
index 62c3dcf..abfb2ee 100644
--- a/resource-predicates/src/main/java/org/apache/sling/resource/predicates/PropertyPredicates.java
+++ b/resource-predicates/src/main/java/org/apache/sling/resource/predicates/PropertyPredicates.java
@@ -14,6 +14,7 @@
 package org.apache.sling.resource.predicates;
 
 import java.lang.reflect.Array;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.Objects;
 import java.util.function.Predicate;
@@ -68,10 +69,10 @@ public class PropertyPredicates {
      *            latest acceptable time
      * @return predicate which will perform the matching
      */
-    public Predicate<Resource> isBefore(Date when) {
+    public Predicate<Resource> isBefore(Calendar when) {
         Objects.requireNonNull(when, "value may not be null");
         return value -> {
-            Date then = value.getValueMap().get(key, Date.class);
+            Calendar then = value.getValueMap().get(key, Calendar.class);
             if (then != null) {
                 return then.before(when);
             }

-- 
To stop receiving notification emails like this one, please contact
jeb@apache.org.