Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to replicate the specific property.

Avatar

Level 4

hi All,

We have the requirement where we have updated the 1 property of existing node on author now we have replicate this particular property of node (not whole node )to publish. Can someone please  suggest how can we achieve that using the java code.

Thanks in advance.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi Sahil,

I am not sure how to replicate single property without affecting others. but you can try below if feasible

1. Can't you use same utility on Publishers to update property?

2. If not, you can generate JSON which contains pages and property values which is being updated by utility and publish JSON on publisher

3. On Publisher write an even if JSON file change, it will trigger another utility which reads this file and update property on directly on publishers.

This will avoid multiple deployments and you can manage impacted pages on author and controlled by JSON on publisher.

Thanks

Arun



Arun Patidar

View solution in original post

10 Replies

Avatar

Community Advisor

Hi,

You can write JCR Events and invoke replication or workflow based on property change in Author to publish page/node on publisher.

More info

JCR 2.0: 12 Observation (Content Repository for Java Technology API v2.0)

ObservationManager (Content Repository for Java Technology API 1.0)

e.g. Adding event Listener on changing property jcreventpage Page

session = repository.loginService("readService",null);

  observationManager = session.getWorkspace().getObservationManager();

  observationManager.addEventListener(this, Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED, "/content/AEM63App/fr/jcreventpage", true, null,

  new String[]{"cq:PageContent","nt:unstructured"} , true);

and on event listener you can write condition to identify property

if (changedProperty.getName().equalsIgnoreCase("jcr:title")

Thanks

Arun



Arun Patidar

Avatar

Level 4

Hi Arun,

Thanks for responding actually we are changing the property using the java code for eg:- sling:resourceType on jcr:content and on this same node we have other properties as well so while we are replicating it through code it is replicating the whole node not the specific property. Can you please suggest how we can we achieve this so that we can replicate only the specific property instead of whole node.

Thanks

Sahil Garg

Avatar

Community Advisor

Hi,

In this case you can use Replication Content filter before calling replication to filter properties.

com.day.cq.replication.ReplicationContentFilter

Example you can find AEM - Custom Replication Content Filter

Thanks

Arun



Arun Patidar

Avatar

Level 4

Hi Arun,

I have tried that post but in this case there is 1 issue i have allowed the single property in filter but while replicating this to publisher it is only replicating the single property but other properties are faded out. For eg:-

Author

jcr:content :-

                    sling:resourceType:- abc

                      title :- title1

                       headnav:-head

While i will replicate this node to publisher it will only publish the sling:resourceType and there is no other fields at all but as per the scenerios there should be other fields as well with the existing value.

Please suggest if we can do something to achieve this.

Avatar

Community Advisor

Hi,

What is your requirement? Do you want to update single property of specific pages only once and after that it is ok to deploy pages like normal deployment? If you are not changing other properties so will be ok to deploy those properties also along with specific property. Can you please explain the exact requirement?

Thanks

Arun



Arun Patidar

Avatar

Level 4

Hi Arun,

So we are creating the utility by using which we can update the single property on node so same we have to publish from author to publisher but while replicating through java code we need to make sure that if there are any other draft changes on this node we will not publish them so to ignore other changes we are looking for that if we can only publish that specific property instead of full node.

Thanks

Sahil Garg.

Avatar

Correct answer by
Community Advisor

Hi Sahil,

I am not sure how to replicate single property without affecting others. but you can try below if feasible

1. Can't you use same utility on Publishers to update property?

2. If not, you can generate JSON which contains pages and property values which is being updated by utility and publish JSON on publisher

3. On Publisher write an even if JSON file change, it will trigger another utility which reads this file and update property on directly on publishers.

This will avoid multiple deployments and you can manage impacted pages on author and controlled by JSON on publisher.

Thanks

Arun



Arun Patidar

Avatar

Level 10

You cannot replicate a prop on a node. You replicate pages or assets. If you want to change a prop on a node on Pub instance, then write a custom tool that invokes a Servlet - the Servlet uses the JCR API and it updates the given prop.

Avatar

Level 4

Thank Arun, for reply as we don't have any way to do it from author we are writing 1 more utility to make the changes at publisher directly.