Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Copy node from one crx to another using sling [ Rest]

Avatar

Level 1

Hi ,

   We have a requirement to copy node(s) which matches a given criteria from  source CRX to target.  For this  we used JCR api exportSystemView and importXML and its working fine . We are now  trying to achieve the same thing using sling .  

Here is what we tried 

Get the json contents of the node  [  http://<sourcehost>:<port>/crx/library/17/01/170101.0.json   ]   > worked 

Use the source json in the request body and post it to target crx    [ http://<targethost>:<port>/crx/library/17/01/170101]  where path 17/01/ is not there nor is the node 170101  >  Failed 

Anyone can give me some hints on how to achieve this ?  kindly help me. 

1 Accepted Solution

Avatar

Correct answer by
Level 10

Another option you have - one that I prefer - is to create a custom sling servlet that uses the JCR API. Then you have the power to modify the JCR as to meet your business requirements. You can perform CRUD operations on JCR nodes. You can pass custom parameters as part of the GET request and then have the servlet perform what you need. 

View solution in original post

0 Replies

Avatar

Administrator

Hi

A reference article, which could help you (it is not using Sling Rest, but faster and efficient way) :-

Link:- http://www.wemblog.com/2011/09/how-to-use-vlt-tool-to-copy-data-from.html

Different options:

1) Use package manager 
Pros: Very simple to create and do not require command like knowledge
Cons: Not suitable for Big packages. Slow some time
2) Use VLT (We are explaining how to use this in this article)
 Pros: Faster than package manager. Do not consume package space like package manager.
Cons: Slow I/O
3) Use Tool based on VLT like Recap http://adamcin.net/net.adamcin.recap/
Pros: VLT rcp UI easy to see status and administer. Do not require command like knowledge.
Cons: Slow I/O because it uses VLT under the hood.
4) Use Tool based on other transfer protocol like Grabit  https://github.com/TWCable/grabbit
Pros: Faster than VLT
Cons: Not Adobe supported. Need more dependency to set up.

 

and

Reference Article :- https://helpx.adobe.com/experience-manager/using/using-sling-apis.html

//Using Sling APIs to retrieve content from the Adobe Experience Manager Repository

 

I hope this will indirectly help you.

Thanks and Regards

Kautuk Sahni

Avatar

Level 10

See the SLing Chart here. There is a list of HTTP commands that you can use:

https://docs.adobe.com/docs/en/cq/5-6-1/developing/the_basics.html

Look under Sling Request Processing. 

Hope this helps

Avatar

Level 1

Thank you so much for replying .  I did go through the sling cheat sheet but couldn't succeed.  

 

If i try to pass in the request parameters in the url ,it works , for ex

To create the path   rest url [GET] :   http://<targethost>:<port>/crx/library/17/01??jcr:primaryType=nt:folder

To crate a node with custom node type under 17/01 with attributes 1 and 2   [POST]:     http://<targethost>:<port>/crx/library17/01/170108?jcr:primaryType=library:customNodeType&attribute1=value1&attribute2=value2

 

But if try to pass in the details in the request body it doesnt work 😞 

[POST] http://<targethost>:<port>/crx/library/17/01/170108

Request Body :  {"jcr:primaryType":"library:customNodeType", "attribute1":"value1","attribute2":"value2" }

Is the correct syntax/ usage 

Avatar

Level 1

Hi Kunal,

      I am getting following exception .   title :   Error while processing /library/17/01/170108                    Message : javax.jcr.nodetype.ConstraintViolationException: No child node definition for 170108 found in node /library/17/01

although i am sending the node [170108]   details in the request body  {"attribute1":"value1","attribute2":"value2","jcr:primaryType":"library:customNodeType"}    with content type as >  application/json;charset=UTF-8

 

We have created a sprint boot project and configured some spring batch jobs -   one of the jobs task is to copy a node from source [production] crx to target [ local] crx  . so incorporating VLT RCP in that is difficult.   

Is it possible to copy node using just the rest url with details in the request body 

Avatar

Correct answer by
Level 10

Another option you have - one that I prefer - is to create a custom sling servlet that uses the JCR API. Then you have the power to modify the JCR as to meet your business requirements. You can perform CRUD operations on JCR nodes. You can pass custom parameters as part of the GET request and then have the servlet perform what you need.