sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From npelt...@apache.org
Subject svn commit: r1807821 - in /sling/trunk/contrib/extensions/sling-pipes/src: main/java/org/apache/sling/pipes/ main/java/org/apache/sling/pipes/internal/ test/java/org/apache/sling/pipes/ test/java/org/apache/sling/pipes/it/
Date Fri, 08 Sep 2017 20:42:06 GMT
Author: npeltier
Date: Fri Sep  8 20:42:06 2017
New Revision: 1807821

URL: http://svn.apache.org/viewvc?rev=1807821&view=rev
Log:
SLING-7110 add PipeBuilder.runWith

Modified:
    sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/PipeBuilder.java
    sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java
    sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java
    sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/it/PipeBuilderIT.java

Modified: sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/PipeBuilder.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/PipeBuilder.java?rev=1807821&r1=1807820&r2=1807821&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/PipeBuilder.java
(original)
+++ sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/PipeBuilder.java
Fri Sep  8 20:42:06 2017
@@ -196,6 +196,14 @@ public interface PipeBuilder {
     Set<String> run(Map bindings) throws Exception;
 
     /**
+     * allow execution of a pipe, with more parameter
+     * @param bindings additional bindings, should be key/value format
+     * @return set of resource path, output of the pipe execution
+     * @throws Exception in case something goes wrong with pipe execution
+     */
+    Set<String> runWith(Object... bindings) throws Exception;
+
+    /**
      * run a pipe asynchronously
      * @param bindings additional bindings for the execution (can be null)
      * @return registered job for the pipe execution

Modified: sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java?rev=1807821&r1=1807820&r2=1807821&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java
(original)
+++ sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java
Fri Sep  8 20:42:06 2017
@@ -171,6 +171,28 @@ public class PipeBuilderImpl implements
     }
 
     /**
+     * Checks arguments and throws exception if there is an issue
+     * @param params
+     * @throws IllegalArgumentException
+     */
+    protected void checkArguments(Object... params) throws IllegalArgumentException {
+        if (params.length % 2 > 0){
+            throw new IllegalArgumentException("there should be an even number of arguments");
+        }
+    }
+
+    /**
+     * write key/value pairs into a map
+     * @param map
+     * @param params
+     */
+    protected void writeToMap(Map map, Object... params){
+        for (int i = 0; i < params.length; i += 2){
+            map.put(params[i], params[i + 1]);
+        }
+    }
+
+    /**
      * Add some configurations to current's Step node defined by name (if null, will be step's
properties)
      * @param name name of the configuration node, can be null in which case it's the subpipe
itself
      * @param params key/value pair list of configuration
@@ -178,9 +200,7 @@ public class PipeBuilderImpl implements
      * @throws IllegalAccessException in case configuration is wrong
      */
     protected PipeBuilder writeToCurrentStep(String name, Object... params) throws IllegalAccessException
{
-        if (params.length % 2 > 0){
-            throw new IllegalArgumentException("there should be an even number of arguments");
-        }
+        checkArguments(params);
         Map props = name != null ? currentStep.confs.get(name) : currentStep.properties;
         if (props == null){
             props = new HashMap();
@@ -188,9 +208,7 @@ public class PipeBuilderImpl implements
                 currentStep.confs.put(name, props);
             }
         }
-        for (int i = 0; i < params.length; i += 2){
-            props.put(params[i], params[i + 1]);
-        }
+        writeToMap(props, params);
         return this;
     }
 
@@ -273,6 +291,14 @@ public class PipeBuilderImpl implements
     }
 
     @Override
+    public Set<String> runWith(Object... bindings) throws Exception {
+        checkArguments(bindings);
+        Map bindingsMap = new HashMap();
+        writeToMap(bindingsMap, bindings);
+        return run(bindingsMap);
+    }
+
+    @Override
     public Set<String> run(Map bindings) throws Exception {
         Pipe pipe = this.build();
         return plumber.execute(resolver, pipe, bindings,  new NopWriter() , true);

Modified: sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java?rev=1807821&r1=1807820&r2=1807821&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java
(original)
+++ sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java
Fri Sep  8 20:42:06 2017
@@ -88,6 +88,8 @@ public class PipeBuilderTest extends Abs
         Map bindings = new HashMap<>();
         bindings.put("testedPath", PATH_FRUITS);
         Set<String> paths = plumber.newPipe(context.resourceResolver()).echo("${testedPath}").run(bindings);
-        assertTrue("paths should contain implemented testedPath", paths.contains(PATH_FRUITS));
+        assertTrue("paths should contain implemented testedPath after run(bindings) is executed",
paths.contains(PATH_FRUITS));
+        paths = plumber.newPipe(context.resourceResolver()).echo("${testedPath}").runWith("testedPath",
PATH_FRUITS);
+        assertTrue("paths should contain implemented testedPath after runWith is executed",
paths.contains(PATH_FRUITS));
     }
 }
\ No newline at end of file

Modified: sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/it/PipeBuilderIT.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/it/PipeBuilderIT.java?rev=1807821&r1=1807820&r2=1807821&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/it/PipeBuilderIT.java
(original)
+++ sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/it/PipeBuilderIT.java
Fri Sep  8 20:42:06 2017
@@ -98,15 +98,11 @@ public class PipeBuilderIT extends Pipes
         try (ResourceResolver resolver = resolver()) {
             Pipe pipe = plumber.newPipe(resolver).mkdir(ROOT + "/test-${testedBinding}").write("jcr:title","${testedBinding}").build();
             for (int i = 0; i < 10; i ++) {
-                Map bindings = new HashMap();
-                bindings.put("testedBinding", i);
-                plumber.newPipe(resolver).pipe(ReferencePipe.RESOURCE_TYPE).expr(pipe.getResource().getPath()).run(bindings);
+                plumber.newPipe(resolver).ref(pipe.getResource().getPath()).runWith("testedBinding",
i);
             }
             Set<String> results = plumber.newPipe(resolver).echo(ROOT).traverse().run();
             LOGGER.info("Following results are found {}", results);
             assertEquals("we should have root and implemented children", 11, results.size());
         }
     }
-
-
 }



Mime
View raw message