Sling Pipes is a new
tool which can extract, transform and load the underlying content using set of configuration.
Here you can load a resource tree based on a pipe, a pipe can have an input a
reader/writer or container pipes.
A pipe is nothing but a
jcr node which has some distinctive characteristics.
·
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
There are three types of
pipe container pipe which acts as a container for other two types of pipe
reader and writer.
Please refer the
following links for more sling pipes ,link1 and link2 for more details
, let’s think of use case where you want to update certain nodes with
allowedProperty= true which satisfies a certain query , this can be achieved by
writing some custom code and the alternative is use writer sling pipe the steps
are described as below.
Step1. Create a node of type
sling:folder with the resourceType as slingPipes/container
for eg "/etc/samplepipes/xpath1Write"
and name it as xpath1Write
Step2
.Create a node named conf of type sling:OrderedFolder under the node created in step1
Step 3. Create a node
named xpath with the resouceType as slingPipes/xpath
Step4. Add property
named expr of type String and value
"/jcr:root/content/geometrixx/en//element(*, nt:unstructured)[fn:name() =
'image']
“which is an xpath query
to get all nodes which has image .
Step 5: Create a writer
sling pipe, create a orderFolder node named write of resourceType
"slingPipes/write"
Step 6:Create a node
nt:unstructured node named as conf having the property to update here in our
case it is "allowedProperty" of type boolean and value true
Once you follow
the above steps the node structure should look like as below.
Once you have done the
changes time to execute the sling pipes as this is write operation so we
must use POST request , we can use curl command to update all the nodes , on
running the below command
curl -u admin:admin -X
POST http://localhost:4502/etc/samplepipes/xpath1Write.json
We get all nodes
modified with required property which has been set as a part of sling write
pipes.
Comments
Post a Comment