Expand my Community achievements bar.

SOLVED

Update the JCR content properties

Avatar

Level 4

Hello All,

Currently, I am working on the migration script where the script will get all 'par' and component of the JCR:Content and search for particular value in all property and update the value on the property.

Sample page structure :

XXX- page

    - jcr:content

       - par1

           |- image property - XXXXX

        -title

        - par2

           |- text property - YYYYY

           |-title

           |- title_0

           |-text-0

YYYY- page

   - jcr:content

      - par1

          |- image property - XXXXX

       -title

       - par2

          |- text property - YYYYY

          |-title

          |- title_0

          |-text-0

Example:

image . - > property - XXXXX

text-0 . - > property - YYYYY

after the script excution

image . - > property - ZZZZZZ

text-0 . - > property - QQQQQ

Code snippet:

  node node = (Node) NodeItr.nextNode();

  NodeIterator NodeItrs = node.getNodes();

  while (NodeItrs.hasNext()) {

  Node node1 = (Node) NodeItrs.nextNode();

----search and update proprery logic----

  if (node1.hasNodes()) {

  NodeIterator NodeItr2 = node1.getNodes();

  while (NodeItr2.hasNext()) {

  Node node2 = (Node) NodeItr2.nextNode();

     ----search and update proprery logic----

}

.....

...

....

while (NodeItr10.hasNext()) {

  Node node10 = (Node) NodeItr10.nextNode();

----search and update proprery logic----

}

}

So I have to read each and every node and find the property. Property will be updated with new value.

My Question :

1. Is there any optimal way to search for the JCR content property?

2. Say if the parent node contains 10 children, I have to read 10 children contents and search the particular property(code snippet). suggest me the optimal way to search for the jcr:content

Thanks

Nanda

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi Nanda

       Why are you not using Query Builder ? Check if these helps

https://hashimkhan.in/2015/12/02/query-builder/

Full Text Search in AEM using Query Builder | TO THE NEW Blog

Thanks

Veena

View solution in original post

4 Replies

Avatar

Correct answer by
Community Advisor

Hi Nanda

       Why are you not using Query Builder ? Check if these helps

https://hashimkhan.in/2015/12/02/query-builder/

Full Text Search in AEM using Query Builder | TO THE NEW Blog

Thanks

Veena

Avatar

Community Advisor

I think this is more specific to AEM than AEM forms ?

Avatar

Community Advisor

Hi Nanda,

You can use JCR SQL2 queries to perform the search operation.

Regards,

Himanshu

Avatar

Level 10

You are on the correct path - using JCR SQL/2 or QUeryBuilder (which is built on JCR API) is the way to proceed here.