Author: npeltier Date: Fri Sep 1 14:59:54 2017 New Revision: 1806970 URL: http://svn.apache.org/viewvc?rev=1806970&view=rev Log: [sling pipes] update samples & formatting
Modified: sling/site/trunk/content/documentation/bundles/sling-pipes.mdtext Modified: sling/site/trunk/content/documentation/bundles/sling-pipes.mdtext URL: http://svn.apache.org/viewvc/sling/site/trunk/content/documentation/bundles/sling-pipes.mdtext?rev=1806970&r1=1806969&r2=1806970&view=diff ============================================================================== --- sling/site/trunk/content/documentation/bundles/sling-pipes.mdtext (original) +++ sling/site/trunk/content/documentation/bundles/sling-pipes.mdtext Fri Sep 1 14:59:54 2017 @@ -56,7 +56,7 @@ Plumber can provider a PipeBuilder with API to quickly configure and run pipes. e.g. - `plumber.newPipe(resolver).xpath('//element(*,nt:unstructured)[@sling:resourceType='to/delete']").rm().run();` + plumber.newPipe(resolver).xpath('//element(*,nt:unstructured)[@sling:resourceType='to/delete']").rm().run(); will search for resource of type `to/delete` and remove them. @@ -72,7 +72,7 @@ PipeBuilder basically will automatically note that that configuration part has shortcuts for some pipes. Typically, above sample is a shorter equivalent of -`plumber.newPipe(resolver).pipe('slingPipes/xpath').expr('//element(*,nt:unstructured)[@sling:resourceType='to/delete']").pipe('slingPipes/rm').run();` + plumber.newPipe(resolver).pipe('slingPipes/xpath').expr('//element(*,nt:unstructured)[@sling:resourceType='to/delete']").pipe('slingPipes/rm').run(); when available, shortcuts will be specified next to each pipe type documentation. @@ -98,7 +98,7 @@ which will return you the path of the re In the eventuality of a long execution (synchronous or asynchronous), you can retrieve the status of a pipe, by executing -GET /etc/pipes/mySamplePipe**.status**.json + GET /etc/pipes/mySamplePipe**.status**.json ##### Request Parameter `binding` @@ -125,7 +125,7 @@ e.g. will returns something similar to -{"size":2, "items":[{'user':'John Smith','path':'/home/users/q/q123jk1UAZS'},{'user':'John Doe','path':'/home/users/q/q153jk1UAZS'}]} + {"size":2, "items":[{'user':'John Smith','path':'/home/users/q/q123jk1UAZS'},{'user':'John Doe','path':'/home/users/q/q153jk1UAZS'}]} ##### Request Parameter `dryRun` if parameter dryRun is set to true, and the executed pipe is supposed to modify content, it will log (at best it can) the change it *would* have done, without doing anything @@ -282,7 +282,7 @@ global bindings can be set at pipe execu ##### slingQuery | write write repository user prefix Ms/Mr depending on gender - .newPipe(resolver).xpath('/jcr:root/home/users//element(*,rep:Users)') + plumber.newPipe(resolver).xpath('/jcr:root/home/users//element(*,rep:Users)') .$('nt:unstructured#profile') .write("fullName","${(profile.gender === 'female' ? 'Ms ' + profile.fullName : 'Mr ' + profile.fullName)}") .run() @@ -290,7 +290,7 @@ write repository user prefix Ms/Mr depen ##### slingQuery | multiProperty | authorizable | write move badge<->user relation ship from badge->users MV property to a user->badges MV property - .newPipe(resolver).echo('/etc/badges/jcr:content/par') + plumber.newPipe(resolver).echo('/etc/badges/jcr:content/par') .$('[sling:resourceType=myApp/components/badge]').name('badge') .pipe('slingPipes/multiProperty').path('${path.badge}/profiles').name('profile') .auth('${profile}').name('user') @@ -299,72 +299,37 @@ move badge<->user relation ship from bad .run() -### xpath | json | write -this use case is for completing repository profiles with external system's data (that has an json api) +##### echo | $ | $ | echo | json | write +this use case is for completing repository website with external system's data (that has an json api), +it does - { - "jcr:primaryType": "nt:unstructured", - "jcr:description": "this pipe retrieves json info from an external system and writes them to the user profile, uses moment.js, it - distributes modified resources using publish distribution agent", - "sling:resourceType": "slingPipes/container", - "distribution.agent": "publish", - "additionalScripts": "/etc/source/moment.js", - "conf": { - "jcr:primaryType": "sling:OrderedFolder", - "profile": { - "jcr:primaryType": "sling:OrderedFolder", - "expr": "/jcr:root/home/users//element(profile,nt:unstructured)[@uid]", - "jcr:description": "query all user profile nodes", - "sling:resourceType": "slingPipes/xpath" - }, - "json": { - "jcr:primaryType": "sling:OrderedFolder", - "expr": "${(profile.uid ? 'https://my.external.system.corp.com/profiles/' + profile.uid.substr(0,2) + '/' + profile.uid + '.json' : '')", - "jcr:description": "retrieves json information relative to the given profile, if the uid is not found, expr is empty: the pipe will do nothing", - "sling:resourceType": "slingPipes/json" - }, - "write": { - "jcr:primaryType": "sling:OrderedFolder", - "path": "path.profile", - "jcr:description": "write json information to the profile node", - "sling:resourceType": "slingPipes/write", - "conf": { - "jcr:primaryType": "sling:OrderedFolder", - "background": "${json.opt('background')}", - "about": "${json.opt('about')}", - "birthday": "${(json.opt('birthday') ? moment(json.opt('birthday'), \"MMMM DD\").toDate() : '')}", - "mobile": "${json.opt('mobile')}" - } - } - } - } - -### xpath | parent | rm - - { - "jcr:primaryType": "nt:unstructured", - "jcr:description": "this pipe removes user with bad property in their profile", - "sling:resourceType": "slingPipes/container", - "conf": { - "jcr:primaryType": "sling:OrderedFolder", - "profile": { - "jcr:primaryType": "sling:OrderedFolder", - "expr": "/jcr:root/home/users//element(profile,nt:unstructured)[@bad]", - "jcr:description": "query all user profile nodes with bad properties", - "sling:resourceType": "slingPipes/xpath" - }, - "parent": { - "jcr:primaryType": "sling:OrderedFolder", - "jcr:description": "get the parent node (user node)", - "sling:resourceType": "slingPipes/parent" - }, - "rm": { - "jcr:primaryType": "sling:OrderedFolder", - "jcr:description": "remove it", - "sling:resourceType": "slingPipes/rm", - } - } - } +- loop over "my:Page" country/language tree under `/content/mySite`, +- fetch json with contextual parameter that must be in upper case, +- and write part of the returned json in the current resource. + +This pipe is run asynchronously in case the execution takes long. + + + + plumber.newPipe(resolver) + .echo("/content/mySite") + .$('my:Page') + .$('my:Page').name("localePage") + .echo('${path.localePage}/jcr:content').name("content") + .json('https://www.external.com/api/${content.country.toUpperCase()}.json.name('api') + .write('cachedValue','${api.remoteJsonValueWeWant}') + .runAsync(null) + + +##### xpath | parent | rm + +- query all user profile nodes with bad properties, +- get the parent node (user node) +- remove it + + plumber.newPipe(resolver) + .xpath("/jcr:root/home/users//element(profile,nt:unstructured)[@bad]") + .parent().rm().run() some other samples are in https://github.com/npeltier/sling-pipes/tree/master/src/test/ @@ -373,4 +338,5 @@ For running this tool on a sling instanc - java 8 (Nashorn is used for expression) - slingQuery (3.0.0) (used in SlingQueryPipe) -- jackrabbit api (2.7.5+) (used in AuthorizablePipe) \ No newline at end of file +- jackrabbit api (2.7.5+) (used in AuthorizablePipe) +