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

rombert pushed a commit to annotated tag org.apache.sling.pipes-0.0.10
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-pipes.git

commit dcaabb727d9d3f20e19b040b555dfb938f7bd24d
Author: Robert Munteanu <[email protected]>
AuthorDate: Thu Feb 18 10:52:59 2016 +0000

    SLING-5523 - filter pipe should be able to filter out resources that *have* 
a configured child
    
    Submitted-By: Nicolas Peltier
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/sling-pipes@1731044
 13f79535-47bb-0310-9956-ffa450edef68
---
 .../java/org/apache/sling/pipes/FilterPipe.java    |  8 ++++++-
 .../org/apache/sling/pipes/FilterPipeTest.java     | 25 ++++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/pipes/FilterPipe.java 
b/src/main/java/org/apache/sling/pipes/FilterPipe.java
index da44198..918723b 100644
--- a/src/main/java/org/apache/sling/pipes/FilterPipe.java
+++ b/src/main/java/org/apache/sling/pipes/FilterPipe.java
@@ -34,6 +34,7 @@ public class FilterPipe extends BasePipe {
     private static Logger logger = LoggerFactory.getLogger(FilterPipe.class);
     public static final String RESOURCE_TYPE = "slingPipes/filter";
     public static final String PREFIX_FILTER = "slingPipesFilter_";
+    public static final String PN_NOT = PREFIX_FILTER + "not";
     public static final String PN_NOCHILDREN = PREFIX_FILTER + "noChildren";
     public static final String PN_TEST = PREFIX_FILTER + "test";
 
@@ -91,7 +92,12 @@ public class FilterPipe extends BasePipe {
     public Iterator<Resource> getOutput() {
         Resource resource = getInput();
         if (resource != null){
-            if (filterPasses(resource, getConfiguration())){
+            boolean not = properties.get(PN_NOT, false);
+            //the not does a exclusive or with the filter:
+            // - true filter with "true" not is false,
+            // - false filter with false not is false,
+            // - all the other combinations should pass
+            if (filterPasses(resource, getConfiguration()) ^ not){
                 logger.debug("filter passes for {}", resource.getPath());
                 return super.getOutput();
             } else {
diff --git a/src/test/java/org/apache/sling/pipes/FilterPipeTest.java 
b/src/test/java/org/apache/sling/pipes/FilterPipeTest.java
index f3bce0d..da4cb00 100644
--- a/src/test/java/org/apache/sling/pipes/FilterPipeTest.java
+++ b/src/test/java/org/apache/sling/pipes/FilterPipeTest.java
@@ -17,6 +17,8 @@
 package org.apache.sling.pipes;
 
 import org.apache.commons.lang3.StringUtils;
+import org.apache.sling.api.resource.ModifiableValueMap;
+import org.apache.sling.api.resource.PersistenceException;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ValueMap;
 import org.junit.Test;
@@ -86,4 +88,27 @@ public class FilterPipeTest extends AbstractPipeTest {
         assertFalse("output has no resource...", resourceIterator.hasNext());
     }
 
+    @Test
+    public void testTestPassesWithNot() throws PersistenceException {
+        Resource resource = context.resourceResolver().getResource(PATH_PIPE + 
"/" + NN_TEST_FAILS);
+        //we modify the pipe with the value NOT
+        resource.adaptTo(ModifiableValueMap.class).put(FilterPipe.PN_NOT, 
true);
+        context.resourceResolver().commit();
+
+        Pipe pipe = plumber.getPipe(resource);
+        Iterator<Resource> resourceIterator = pipe.getOutput();
+        assertTrue("output has one resource...", resourceIterator.hasNext());
+    }
+
+    @Test
+    public void testTestFailsWithNot() throws PersistenceException {
+        Resource resource = context.resourceResolver().getResource(PATH_PIPE + 
"/" + NN_TEST);
+        //we modify the pipe with the value NOT
+        resource.adaptTo(ModifiableValueMap.class).put(FilterPipe.PN_NOT, 
true);
+        context.resourceResolver().commit();
+        Pipe pipe = plumber.getPipe(resource);
+        Iterator<Resource> resourceIterator = pipe.getOutput();
+        assertFalse("output has no resource...", resourceIterator.hasNext());
+    }
+
 }
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to