While working on huge amounts of Enterprise content data, I am
sure you guys must have faced scenarios wherein there is a need to modify some
part of content with a particular property or some property/node is wrongly
edited and you are asked to find all those nodes and correct that property .
Similar sort of problems become cumbersome if the amount of data is quite
huge. General approach to solve this would be to write either some Groovy
script or write some Java code to parse the content and change the necessary
nodes. To overcome this redundant issue in content and to make a scalable
approach to deal with all these content related issues, Apache came up with
Sling Pipes.
What is a pipe
Its a tool where you can load content tree nodes , perform some
operation and either Retrieve an output or Modify the nodes. The aim here is to
provide reusable blocks called pipes which can be configured for any possible
operation on content.
getOutputBinding ^ | getInput +---+---+ getOutput | | +----> Pipe +----> | | +-------+
To begin with , you would
AEM 6.1 + . Start with the download of the github project fromhere and build it using
1
|
mvn clean install
-DskipTests
|
Once the build is
successful, upload the jar file : org.apache.sling.pipes-0.0.9-SNAPSHOT.jar in /system/console/bundles. If the bundle doesnt get resolved
download the org.apache.sling.query jar from LINK1 and LINK2 and upload in AEM.
Make sure both the bundles are in Active state .
Basic
Pipes
A Pipe is basically a jcr node which has several properties :
- sling:resourceType= slingPipes/plumber
- name= to be used as
an id and could be a key for output bindings.
- path= defines
pipe’s input . If its not present previous pipes output will be used
as input for this pipe.
- expr= expression
through which the pipe will execute
- additionalBinding= It is a
node you can add to set “global” bindings (property=value) in pipe
execution
- additionalScripts= scripts which
can be used as expressions.
- conf=optional child
node to add additional configurations.
Reader
Pipes :
Pipe Type
|
Description
|
Properties
|
Base Pipe
|
Dummy pipe, output=input
|
sling:resourceType = slingPipes/base
|
Sling Query Pipe
|
executes $(getInput()).children(expression)
|
|
JSON Pipe
|
feeds bindings with remote json
|
|
MultiPropertyPipe
|
iterates through values of input multi value property
and write them to bindings
|
|
XPath Pipe
|
gets resources from the xpath query.
|
|
Authorizable Pipe
|
retrieve authorizable resource corresponding to the id
passed in expression
|
|
Parent Pipe
|
outputs the parent resource of input resource
|
|
Filter Pipe
|
outputs the input resource if its matches its configuration
|
|
Containers:
Pipe Type
|
Description
|
Properties
|
Container Pipe
|
used to assemble a sequence of pipe.
|
|
Reference Pipe
|
executes the pipe referenced in path property.
|
|
Writers:
Pipe Type
|
Description
|
Properties
|
Write Pipe
|
Writes nodes and properties to the input of pipe
|
|
Move Pipe
|
used to move input to target path.
|
|
Remove Pipe
|
removed the input resource (node or prop) and returns
the parent.
|
|
Path Pipe
|
get or create path in an expression.
|
|
Execute
Sling Pipe
Once the configurations are ready , broadly there are 2 ways to
execute a pipe. If its just a GET call / read operation you can directly call
it from browser or use cURL command. If its a POST call / write operation, you
have to use cURL. Besides these basics you can also pass few parameters to
execute a pipe. We will see more with examples.
Sample
Configurations
There are few
configurations at the link which
explains how the node structure should be in place to make it work. Besides
that you can also check the link to explore more. I have also tried few things to test Sling Pipes.
You can also install the below attached package from the link below in AEM 6.1
to do some practice on Sling Pipes.
Sling Pipes is apparently quite new in the AEM world , so it you
might not get much context about it online. If you need to explore something
complex using Sling Pipes, start with basics and then try to build upon the
complex scenarios.
No comments :
Post a Comment