You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by np...@apache.org on 2018/05/30 15:06:05 UTC
[sling-org-apache-sling-pipes] branch master updated: SLING-7694
add input relative path support
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 58c1f2a SLING-7694 add input relative path support
58c1f2a is described below
commit 58c1f2a46635d0d79e9e1b9e20b15493a59dc500
Author: Nicolas Peltier <pe...@gmail.com>
AuthorDate: Wed May 30 17:05:50 2018 +0200
SLING-7694 add input relative path support
---
src/main/java/org/apache/sling/pipes/BasePipe.java | 13 ++++++++++++-
src/main/java/org/apache/sling/pipes/internal/PathPipe.java | 7 +++----
src/test/java/org/apache/sling/pipes/AbstractPipeTest.java | 4 +++-
src/test/java/org/apache/sling/pipes/BasePipeTest.java | 12 ++++++++++++
4 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/apache/sling/pipes/BasePipe.java b/src/main/java/org/apache/sling/pipes/BasePipe.java
index 24637cc..c648cb6 100644
--- a/src/main/java/org/apache/sling/pipes/BasePipe.java
+++ b/src/main/java/org/apache/sling/pipes/BasePipe.java
@@ -35,7 +35,7 @@ import java.util.List;
public class BasePipe implements Pipe {
private final Logger logger = LoggerFactory.getLogger(BasePipe.class);
-
+ public static final String SLASH = "/";
public static final String RT_PREFIX = "slingPipes/";
public static final String RESOURCE_TYPE = RT_PREFIX + "base";
public static final String DRYRUN_KEY = "dryRun";
@@ -160,6 +160,9 @@ public class BasePipe implements Pipe {
Resource configuredInput = null;
String path = getPath();
if (StringUtils.isNotBlank(path)){
+ if (!isRootPath(path) && getPreviousResource() != null){
+ path = getPreviousResource().getPath() + SLASH + path;
+ }
configuredInput = resolver.getResource(path);
if (configuredInput == null) {
logger.warn("configured path {} is not found, expect some troubles...", path);
@@ -169,6 +172,14 @@ public class BasePipe implements Pipe {
}
/**
+ * @param path path to be checked
+ * @return true if path is root (aka not relative)
+ */
+ protected boolean isRootPath(String path){
+ return path.startsWith(SLASH);
+ }
+
+ /**
* Retrieves previous pipe if contained by a parent, or referrer's
* @return pipe before this one or the referrer's can be null in case there is no parent
*/
diff --git a/src/main/java/org/apache/sling/pipes/internal/PathPipe.java b/src/main/java/org/apache/sling/pipes/internal/PathPipe.java
index 1f06ab3..014e4de 100644
--- a/src/main/java/org/apache/sling/pipes/internal/PathPipe.java
+++ b/src/main/java/org/apache/sling/pipes/internal/PathPipe.java
@@ -50,7 +50,6 @@ public class PathPipe extends BasePipe {
public static final String PN_NODETYPE = "nodeType";
public static final String PN_INTERMEDIATE = "intermediateType";
public static final String PN_AUTOSAVE = "autosave";
- public static final String SLASH = "/";
String resourceType;
String nodeType;
@@ -77,16 +76,16 @@ public class PathPipe extends BasePipe {
@Override
protected Iterator<Resource> computeOutput() throws Exception {
Iterator<Resource> output = Collections.emptyIterator();
- String expression = getExpr();
+ String expr = getExpr();
try {
- String path = expression.startsWith(SLASH) ? expression : getInput().getPath() + SLASH + expression;
+ String path = isRootPath(expr) ? expr : getInput().getPath() + SLASH + expr;
logger.info("creating path {}", path);
if (!isDryRun()) {
Resource resource = jcr ? getOrCreateNode(path) : ResourceUtil.getOrCreateResource(resolver, path, resourceType, intermediateType, autosave);
output = Collections.singleton(resource).iterator();
}
} catch (PersistenceException e){
- logger.error ("Not able to create path {}", expression, e);
+ logger.error ("Not able to create path {}", expr, e);
}
return output;
}
diff --git a/src/test/java/org/apache/sling/pipes/AbstractPipeTest.java b/src/test/java/org/apache/sling/pipes/AbstractPipeTest.java
index 84bb202..c73e109 100644
--- a/src/test/java/org/apache/sling/pipes/AbstractPipeTest.java
+++ b/src/test/java/org/apache/sling/pipes/AbstractPipeTest.java
@@ -41,7 +41,9 @@ import org.junit.Rule;
public class AbstractPipeTest {
protected static final String PATH_PIPE = "/etc/pipe";
- protected static final String PATH_FRUITS = "/content/fruits";
+ protected static final String ROOT = "/content";
+ protected static final String NN_FRUITS = "fruits";
+ protected static final String PATH_FRUITS = ROOT + BasePipe.SLASH + NN_FRUITS;
protected static final String BANANA_SUFFIX = "/banana";
protected static final String PATH_BANANA = PATH_FRUITS + BANANA_SUFFIX;
protected static final String APPLE_SUFFIX = "/apple";
diff --git a/src/test/java/org/apache/sling/pipes/BasePipeTest.java b/src/test/java/org/apache/sling/pipes/BasePipeTest.java
index 847e481..b22938a 100644
--- a/src/test/java/org/apache/sling/pipes/BasePipeTest.java
+++ b/src/test/java/org/apache/sling/pipes/BasePipeTest.java
@@ -17,6 +17,7 @@
package org.apache.sling.pipes;
import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.api.resource.Resource;
import org.junit.Test;
import javax.json.Json;
@@ -26,6 +27,7 @@ import java.io.StringReader;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class BasePipeTest extends AbstractPipeTest {
@@ -53,4 +55,14 @@ public class BasePipeTest extends AbstractPipeTest {
JsonArray array = response.getJsonArray(OutputWriter.KEY_ERRORS);
assertEquals("there should be one error", 1, array.size());
}
+
+ @Test
+ public void testRelativeInput() throws Exception {
+ Resource resource = plumber.newPipe(context.resourceResolver())
+ .echo(ROOT)
+ .echo(NN_FRUITS)
+ .build().getOutput().next();
+ assertNotNull("there should be an output", resource);
+ assertEquals("it should be fruits root", PATH_FRUITS, resource.getPath());
+ }
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
npeltier@apache.org.