Update the JCR content properties | Community
Skip to main content
Nandujee
Level 3
September 4, 2017
Solved

Update the JCR content properties

  • September 4, 2017
  • 4 replies
  • 3248 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by VeenaVikraman

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

4 replies

VeenaVikraman
Community Advisor
VeenaVikramanCommunity AdvisorAccepted solution
Community Advisor
September 5, 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

VeenaVikraman
Community Advisor
Community Advisor
September 5, 2017

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

Himanshu_Singhal
Community Advisor
Community Advisor
September 5, 2017

Hi Nanda,

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

Regards,

Himanshu

smacdonald2008
Level 10
September 5, 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.