Wednesday 7 June 2017

Sling Pipes

Ever encountered a situation where code changes were introduced after the client started authoring and some pages had to be re-authored? Ever spent time writing code just to modify a few hundred pages that were already authored, or with removing a component from hundreds of authored pages? Have you struggled to modify content already in the repository? Need a script to change existing production content? Sling Pipes to the rescue.
Sling Pipes is a tool for doing extract – transform – load operations through a resource tree configuration. This tiny toolset provides the ability to do such transformations with proven and reusable blocks, called pipes, streaming resources from one to the other.
A pipe is a JCR node with:
  • sling:resourceType property – Must be a pipe type registered by the plumber
  • name property – Used in bindings as an id
  • path property – Defines pipe’s input
  • expr property – Expression through which the pipe will execute
  • additionalBinding node – Node you can add to set “global” bindings (property=value) in pipe execution
  • additionalScripts – Multivalue property to declare scripts that can be reused in expressions
  • conf child node – Contains addition configuration of the pipe

Registered Pipes:

Container Pipes
Pipe
Description
sling:resourceType
Container Pipe
assemble a sequence of pipes
slingPipes/container
ReferencePipe
execute the pipe referenced in path property
slingPipes/reference

Reader Pipes
Pipe
Description
sling:resourceType
Base Pipe
outputs what is in input
slingPipes/base
SlingQuery Pipe
executes $(getInput()).children(expression)
slingPipes/slingQuery
JsonPipe
feeds bindings with remote json
slingPipes/json
MultiPropertyPipe
iterates through values of input multi value property and write them to bindings
slingPipes/multiProperty
XPathPipe
retrieve resources resulting of an xpath query
slingPipes/xpath
AuthorizablePipe
retrieve authorizable resource corresponding to the id passed in expression
slingPipes/authorizable
ParentPipe
outputs the parent resource of input resource
slingPipes/parent
FilterPipe
outputs the input resource if its matches its configuration
slingPipes/filter

Writer Pipes
Pipe
Description
sling:resourceType
Write Pipe
writes given nodes & properties to current input
slingPipes/write
MovePipe
JCR move of current input to target path (can be a node or a property)
slingPipes/mv
RemovePipe
removes the input resource
slingPipes/rm
PathPipe
get or create path given in expression
slingPipes/path

Here is a demo video with more on how to use and execute sling pipes in AEM.

Vid
More details can be found in the official documentation at https://sling.apache.org/documentation/bundles/sling-pipes.html

No comments:

Post a Comment