Skip to main content

Sling Pipes

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

Popular posts from this blog

Handle bar & AEM server side integration

In AEM 6.0 version, as part of social communities’ project AEM implemented a handlebar script files in place of JSP scripts.  As part of this project AEM SCF community implemented a handle bar engine which in turn uses handlebars.java(jknack) library to compile and execute handlebar templates. Example: Let’s say I have a component called helloworld and the path of component  is  /apps/mysite/components/content/helloworld. Below three steps we need to do to implement header component. 1.       Register a HBS component To register HBS component we need to implement SocialComponentFactory interface and then we need to override methods. In “getSupportedResourceType” method we need to return component path to register it to handlebar engine.  Once we register a component json response will automatically available to handlebar script file. Example: The key aspect is to overri...

How to remove hardcoding .html from pathfield in AEM/CQ

In our project we have a pathfield in quite a lot of dialog for various custom components which refers/links to pages. After getting the value of this pathfield in the sightly template we were  adding the html extension manually on it. e.g.                 <a class="navbar-brand" href="${properties.homepagePath @ context='unsafe'}">${properties.headerAuthTitle}</a> We can avoid hardcoding the path by adding property in dialog link  linkPattern The  pathfield  xtype has a config option called  linkpattern . This allows you to configure the widget to automatically add an extension  in case the browsefield is used  to select the link. If a user types the text , the extension is not added. Use this option to add '.html' and all internal links will have .html appended (assuming the content authors always use the pathfield's browse option to select the link [which they should be doing ] ). This wa...

Mediator Design Pattern

Mediator design pattern is  a pattern used to communicate between  related  object using mediator , the communication happens  in such way that either party is not aware of the underlying communication mechanism. So as a classic example  is our BSE and NSE stock exchange , the exchange facilitates with different stock offerings and they don't hold any stocks with them , it is broker which offers to sale or buy to NSE or BSE and which facilitates the buying or selling of the share . So here BSE and NSE are the mediator which provides hooks for different brokers zerodha, sharekhan... to register and perform the trade , one broker offers to sale certain shares to and other broker buys the same , and this task is performed by the mediator silently without bothering each other. Please follow the UML diagram for the same. Here we have Colleague object which is nothing but the abstract broker and then we have different implementation of broker's like sharekhan...