sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From npelt...@apache.org
Subject [sling-org-apache-sling-pipes] branch master updated: SLING-7614 allow expressions in node names
Date Sat, 05 May 2018 22:41:52 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new ff07dd1  SLING-7614 allow expressions in node names
ff07dd1 is described below

commit ff07dd19321450d752cb2dea895879959a29ca01
Author: Nicolas Peltier <peltier.nicolas@gmail.com>
AuthorDate: Sun May 6 00:41:43 2018 +0200

    SLING-7614 allow expressions in node names
---
 .../java/org/apache/sling/pipes/internal/WritePipe.java    | 14 ++++++++++++--
 .../org/apache/sling/pipes/internal/WritePipeTest.java     |  8 ++++++++
 src/test/resources/write.json                              | 11 +++++++++++
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/sling/pipes/internal/WritePipe.java b/src/main/java/org/apache/sling/pipes/internal/WritePipe.java
index 4cbc948..33da895 100644
--- a/src/main/java/org/apache/sling/pipes/internal/WritePipe.java
+++ b/src/main/java/org/apache/sling/pipes/internal/WritePipe.java
@@ -102,7 +102,15 @@ public class WritePipe extends BasePipe {
         return value;
     }
 
-
+    /**
+     * convert the configured string value (can be an expression) in a value that can be
written in a resource.
+     * also handles patch for multivalue properties like <code>+[value]</code>
in which case <code>value</code>
+     * is added to the MV property
+     * @param resource resource to which value will be written
+     * @param key property to which value will be written
+     * @param expression configured value to write
+     * @return actual value to write to the resource
+     */
     protected Object computeValue(Resource resource, String key, Object expression) {
         if (expression instanceof String) {
             return computeValue(resource, key, (String)expression);
@@ -177,12 +185,14 @@ public class WritePipe extends BasePipe {
         NodeIterator childrenConf = conf.getNodes();
         if (childrenConf.hasNext()){
             Node targetNode = target.adaptTo(Node.class);
+            logger.info("dubbing {} at {}", conf.getPath(), target.getPath());
             while (childrenConf.hasNext()){
                 Node childConf = childrenConf.nextNode();
                 String name = childConf.getName();
-                logger.info("dubbing {} at {}", conf.getPath(), target.getPath());
+                name = bindings.instantiateExpression(name);
                 if (!isDryRun()){
                     Node childTarget = targetNode.hasNode(name) ? targetNode.getNode(name)
: targetNode.addNode(name, childConf.getPrimaryNodeType().getName());
+                    logger.debug("writing tree {}", childTarget.getPath());
                     writeTree(childConf, resolver.getResource(childTarget.getPath()));
                 }
             }
diff --git a/src/test/java/org/apache/sling/pipes/internal/WritePipeTest.java b/src/test/java/org/apache/sling/pipes/internal/WritePipeTest.java
index bc206fb..78f4156 100644
--- a/src/test/java/org/apache/sling/pipes/internal/WritePipeTest.java
+++ b/src/test/java/org/apache/sling/pipes/internal/WritePipeTest.java
@@ -152,4 +152,12 @@ public class WritePipeTest extends AbstractPipeTest {
         assertTrue("first should be apple", children.get(0).endsWith(APPLE_SUFFIX));
         assertTrue("second should be banana", children.get(1).endsWith(BANANA_SUFFIX));
     }
+
+    @Test
+    public void testExpressionNode() throws PersistenceException {
+        Iterator<Resource> it = getOutput(PATH_PIPE + "/expressionNode");
+        it.next();
+        context.resourceResolver().commit();
+        assertNotNull("there should be a node created", context.resourceResolver().getResource(PATH_APPLE
+ "/testExpression"));
+    }
 }
diff --git a/src/test/resources/write.json b/src/test/resources/write.json
index 6be4f2c..0cd2dc4 100644
--- a/src/test/resources/write.json
+++ b/src/test/resources/write.json
@@ -90,5 +90,16 @@
         }
       }
     }
+  },
+  "expressionNode":{
+    "jcr:primaryType":"nt:unstructured",
+    "sling:resourceType":"slingPipes/write",
+    "path":"/content/fruits/apple",
+    "conf": {
+      "jcr:primaryType":"nt:unstructured",
+      "${'t' + ((2 > 1) ? 'estExpression':'')}": {
+        "jcr:primaryType":"nt:unstructured"
+      }
+    }
   }
 }
\ No newline at end of file

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

Mime
View raw message