Update the JCR content properties

Avatar

Avatar

Nandujee

Avatar

Nandujee

Nandujee

04-09-2017

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Veena_Vikram

MVP

Avatar

Veena_Vikram

MVP

Veena_Vikram
MVP

04-09-2017

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

Answers (3)

Answers (3)

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

05-09-2017

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

Avatar

Avatar

Himanshu_Singhal

MVP

Avatar

Himanshu_Singhal

MVP

Himanshu_Singhal
MVP

05-09-2017

Hi Nanda,

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

Regards,

Himanshu

Avatar

Avatar

Veena_Vikram

MVP

Avatar

Veena_Vikram

MVP

Veena_Vikram
MVP

04-09-2017

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