March 28, 2020
Estimated Post Reading Time ~

Sling Pipes

It's 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.

Install Sling Pipes in AEM
To begin with, you would AEM 6.1 +. Start with the download of the GitHub project from here and build it using
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 doesn't get resolved to download the org.apache.sling.query jar from LINK1 and LINK2 and upload it in AEM.
Make sure both the bundles are in the Active state.
Basic Pipes
A Pipe is basically a JCR node that has several properties :
sling:resourceType= slingPipes/plumber
name= to be used as an id and could be a key for output bindings.
path= defines the pipe’s input. If it's not present previous pipe's 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 that can be used as expressions.
conf=optional child node to add additional configurations.
Reader Pipes:
Pipe TypeDescriptionProperties
 Base PipeDummy pipe, output=inputsling:resourceType = slingPipes/base
Sling Query Pipeexecutes $(getInput()).children(expression)
  •  sling:resourceType = slingPipes/slingQuery
  • expr = mandatory property, contains slingQuery expression through which getInput()’s children will be computed to getOutput()
 JSON Pipefeeds bindings with remote json
  • sling:resourceType = slingPipes/json
  • expr mandatory property
 MultiPropertyPipe iterates through values of input multi value property and write them to bindings
  • sling:resourceType=slingPipes/multiProperty
  • path = path of a mv property
 XPath Pipe gets resources from the xpath query.
  • sling:resourceType= slingPipes/xpath
  • expr = xpath query expression
 Authorizable Pipe retrieve authorizable resource corresponding to the id passed in expression
  • sling:resourceType = slingPipes/authorizable
  • expr = authorizable id
  • autoCreateGroup (boolean)
  • addMembers (stringified json array)
  • addToGroup (expression)
  • bindMembers (boolean)
 Parent Pipe outputs the parent resource of input resource
  • sling:resourceType= slingPipes/parent
Filter Pipeoutputs the input resource if its matches its configuration
  • sling:resourceType = slingPipes/filter
  • conf node
  • slingPipesFilter_not=’true’ inverts the expected result of the filter
Containers:
Pipe TypeDescriptionProperties
Container Pipeused to assemble a sequence of pipes.
  • sling:resourceType = slingPipes/container
  • conf node
Reference Pipeexecutes the pipe referenced in path property.
  • sling:resourceType = slingPipes/reference
  • path
Writers:
Pipe TypeDescriptionProperties
Write PipeWrites nodes and properties to the input of pipe
  • sling:resourceType = slingPipes/write
  • conf node
Move Pipe used to move the input to the target path.
  •  sling:resourceType=slingPipes/mv
  • expr=target path
Remove Pipe removed the input resource (node or prop) and returns the parent.
  •  sling:resourceType=slingPipes/rm
  • conf node
Path Pipe get or create a path in an expression.
  •  sling:resourceType = slingPipes/path
  • nodeType = node type of the intermediate nodes to create
  • autosave = to save at each creation.
Execute Sling Pipe
Once the configurations are ready, broadly there are 2 ways to execute a pipe. If it's just a GET call / read operation you can directly call it from a browser or use the cURL command. If it's a POST call / write operation, you have to use cURL. Besides these basics, you can also pass a few parameters to execute a pipe. We will see more examples.

Sling Pipes is apparently quite new in the AEM world, so you might not get many contexts about it online. If you need to explore something complex using Sling Pipes, start with the basics, and then try to build upon the complex scenarios. You may also comment below on a few scenarios where content modification is needed and I can help you explore the usage of Sling Pipes in that use case. Going forward, I am sure this would be a boon for us. Happy Exploring. !!

Read More Information about Sling Pipe below
https://adapt.to/2016/en/schedule/introduction-to-sling-pipes.html


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.