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 2017/10/20 20:37:14 UTC
[sling-org-apache-sling-pipes] 03/04: SLING-7172 introduce siblings
pipe
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
commit 07befc6da634874f926659f70c5967f82c7facbe
Author: npeltier <np...@adobe.com>
AuthorDate: Fri Oct 20 22:31:59 2017 +0200
SLING-7172 introduce siblings pipe
---
.../java/org/apache/sling/pipes/PipeBuilder.java | 16 ++++++----
.../sling/pipes/internal/PipeBuilderImpl.java | 18 +++++++----
.../apache/sling/pipes/internal/PlumberImpl.java | 2 ++
.../pipes/internal/slingQuery/SiblingsPipe.java | 37 ++++++++++++++++++++++
.../org/apache/sling/pipes/AbstractPipeTest.java | 1 +
.../org/apache/sling/pipes/PipeBuilderTest.java | 2 +-
.../internal/slingQuery/SiblingsPipeTest.java | 36 +++++++++++++++++++++
.../SLING-INF/jcr_root/content/fruits.json | 4 +++
8 files changed, 103 insertions(+), 13 deletions(-)
diff --git a/src/main/java/org/apache/sling/pipes/PipeBuilder.java b/src/main/java/org/apache/sling/pipes/PipeBuilder.java
index 3fe25c2..8033a3a 100644
--- a/src/main/java/org/apache/sling/pipes/PipeBuilder.java
+++ b/src/main/java/org/apache/sling/pipes/PipeBuilder.java
@@ -81,6 +81,13 @@ public interface PipeBuilder {
PipeBuilder children(String expr);
/**
+ * attach a sling query siblings pipe to the current context
+ * @param expr sling query expression
+ * @return updated instance of PipeBuilder
+ */
+ PipeBuilder siblings(String expr);
+
+ /**
* attach a rm pipe to the current context
* @return updated instance of PipeBuilder
*/
@@ -130,26 +137,23 @@ public interface PipeBuilder {
* attach a parents pipe to the current context
* @param expr expression
* @return updated instance of PipeBuilder
- * @throws IllegalAccessException in case it's called with wrong # of arguments
*/
- PipeBuilder parents(String expr) throws IllegalAccessException;
+ PipeBuilder parents(String expr);
/**
* attach a reference pipe to the current context
* @param expr reference
* @return updated instance of PipeBuilder
- * @throws IllegalAccessException in case it's called with wrong # of arguments
*/
- PipeBuilder ref(String expr)throws IllegalAccessException;
+ PipeBuilder ref(String expr);
/**
* attach a not pipe to the current context
* @param expr reference
* @return updated instance of PipeBuilder
- * @throws IllegalAccessException in case it's called with wrong # of arguments
*/
- PipeBuilder not(String expr)throws IllegalAccessException;
+ PipeBuilder not(String expr);
/**
* parameterized current pipe in the context
diff --git a/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java b/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java
index 85e78e5..87a4227 100644
--- a/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java
+++ b/src/main/java/org/apache/sling/pipes/internal/PipeBuilderImpl.java
@@ -26,6 +26,7 @@ import org.apache.sling.pipes.*;
import org.apache.sling.pipes.internal.slingQuery.ChildrenPipe;
import org.apache.sling.pipes.internal.slingQuery.ParentPipe;
import org.apache.sling.pipes.internal.slingQuery.ParentsPipe;
+import org.apache.sling.pipes.internal.slingQuery.SiblingsPipe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -165,18 +166,23 @@ public class PipeBuilderImpl implements PipeBuilder {
}
@Override
- public PipeBuilder parents(String expr) throws IllegalAccessException {
- return pipe(ParentsPipe.RESOURCE_TYPE).expr(expr);
+ public PipeBuilder parents(String expr) {
+ return pipeWithExpr(ParentsPipe.RESOURCE_TYPE, expr);
}
@Override
- public PipeBuilder ref(String expr) throws IllegalAccessException {
- return pipe(ReferencePipe.RESOURCE_TYPE).expr(expr);
+ public PipeBuilder siblings(String expr) {
+ return pipeWithExpr(SiblingsPipe.RESOURCE_TYPE, expr);
}
@Override
- public PipeBuilder not(String expr) throws IllegalAccessException {
- return pipe(NotPipe.RESOURCE_TYPE).expr(expr);
+ public PipeBuilder ref(String expr) {
+ return pipeWithExpr(ReferencePipe.RESOURCE_TYPE, expr);
+ }
+
+ @Override
+ public PipeBuilder not(String expr) {
+ return pipeWithExpr(NotPipe.RESOURCE_TYPE, expr);
}
@Override
diff --git a/src/main/java/org/apache/sling/pipes/internal/PlumberImpl.java b/src/main/java/org/apache/sling/pipes/internal/PlumberImpl.java
index 31d4840..a1e43be 100644
--- a/src/main/java/org/apache/sling/pipes/internal/PlumberImpl.java
+++ b/src/main/java/org/apache/sling/pipes/internal/PlumberImpl.java
@@ -56,6 +56,7 @@ import org.apache.sling.pipes.*;
import org.apache.sling.pipes.internal.slingQuery.ChildrenPipe;
import org.apache.sling.pipes.internal.slingQuery.ParentPipe;
import org.apache.sling.pipes.internal.slingQuery.ParentsPipe;
+import org.apache.sling.pipes.internal.slingQuery.SiblingsPipe;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
@@ -124,6 +125,7 @@ public class PlumberImpl implements Plumber, JobConsumer {
registerPipe(TraversePipe.RESOURCE_TYPE, TraversePipe.class);
registerPipe(CsvPipe.RESOURCE_TYPE, CsvPipe.class);
registerPipe(ParentPipe.RESOURCE_TYPE, ParentPipe.class);
+ registerPipe(SiblingsPipe.RESOURCE_TYPE, SiblingsPipe.class);
}
@Reference(policy= ReferencePolicy.DYNAMIC, cardinality= ReferenceCardinality.OPTIONAL)
diff --git a/src/main/java/org/apache/sling/pipes/internal/slingQuery/SiblingsPipe.java b/src/main/java/org/apache/sling/pipes/internal/slingQuery/SiblingsPipe.java
new file mode 100644
index 0000000..8e6ca14
--- /dev/null
+++ b/src/main/java/org/apache/sling/pipes/internal/slingQuery/SiblingsPipe.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.pipes.internal.slingQuery;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.pipes.Plumber;
+import org.apache.sling.query.SlingQuery;
+
+import static org.apache.sling.query.SlingQuery.$;
+
+public class SiblingsPipe extends AbstractExpressionSlingQueryPipe {
+
+ public static final String RESOURCE_TYPE = RT_PREFIX + "siblings";
+
+ public SiblingsPipe(Plumber plumber, Resource resource) throws Exception {
+ super(plumber, resource);
+ }
+
+ @Override
+ protected SlingQuery getQuery(Resource resource, String expression) {
+ return $(resource).siblings(expression);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/pipes/AbstractPipeTest.java b/src/test/java/org/apache/sling/pipes/AbstractPipeTest.java
index 0b8d99a..801a3cd 100644
--- a/src/test/java/org/apache/sling/pipes/AbstractPipeTest.java
+++ b/src/test/java/org/apache/sling/pipes/AbstractPipeTest.java
@@ -45,6 +45,7 @@ public class AbstractPipeTest {
protected static final String PATH_BANANA = PATH_FRUITS + "/banana";
protected static final String PATH_APPLE = PATH_FRUITS + "/apple";
protected static final String PATH_PEA = PATH_APPLE + "/isnota/pea";
+ protected static final String PATH_CARROT = PATH_APPLE + "/isnota/carrot";
protected static final String SAME_COLOR = PATH_PEA + "/buttheyhavesamecolor";
protected static final String NN_SIMPLE = "simple";
protected static final String NN_COMPLEX = "complex";
diff --git a/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java b/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java
index c3f52b8..8d55e7c 100644
--- a/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java
+++ b/src/test/java/org/apache/sling/pipes/PipeBuilderTest.java
@@ -72,7 +72,7 @@ public class PipeBuilderTest extends AbstractPipeTest {
.children("nt:unstructured#isnota")
.children("nt:unstructured").name("thing")
.write("jcr:path", "${path.thing}").run();
- assertEquals("There should be only one resource", 2, paths.size());
+ assertEquals("There should be 3 resources", 3, paths.size());
String pea = "/content/fruits/apple/isnota/pea";
String carrot = "/content/fruits/apple/isnota/carrot";
assertTrue("the paths should contain " + pea, paths.contains(pea));
diff --git a/src/test/java/org/apache/sling/pipes/internal/slingQuery/SiblingsPipeTest.java b/src/test/java/org/apache/sling/pipes/internal/slingQuery/SiblingsPipeTest.java
new file mode 100644
index 0000000..afb7985
--- /dev/null
+++ b/src/test/java/org/apache/sling/pipes/internal/slingQuery/SiblingsPipeTest.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.pipes.internal.slingQuery;
+
+import org.apache.sling.pipes.AbstractPipeTest;
+import org.junit.Test;
+
+import java.util.Set;
+
+import static org.junit.Assert.*;
+
+public class SiblingsPipeTest extends AbstractPipeTest{
+
+ @Test
+ public void testSiblings() throws Exception {
+ Set<String> outputs = plumber.newPipe(context.resourceResolver())
+ .echo(PATH_CARROT)
+ .siblings("[color=green]").run();
+ assertEquals("there should be 1 outputs", 1, outputs.size());
+ assertTrue("there should be pea", outputs.contains(PATH_PEA));
+ }
+}
\ No newline at end of file
diff --git a/src/test/resources/SLING-INF/jcr_root/content/fruits.json b/src/test/resources/SLING-INF/jcr_root/content/fruits.json
index 0817134..c9b2c71 100644
--- a/src/test/resources/SLING-INF/jcr_root/content/fruits.json
+++ b/src/test/resources/SLING-INF/jcr_root/content/fruits.json
@@ -16,6 +16,10 @@
"jcr:primaryType":"nt:unstructured"
}
},
+ "plum":{
+ "jcr:primaryType":"nt:unstructured",
+ "jcr:title":"Plum"
+ },
"carrot":{
"jcr:primaryType":"nt:unstructured",
"andtheircolorisdifferent":{
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.