Highlighted

How to know what changed using a ResourceChange object?

jkpanera

23-07-2019

He guys,

I am writing a ResourceChangeListener. I'm implementing onChange(List<ResourceChange> changes). But the list of changes has very little information.

getChangedPropertyNames(), addedPropertyNames(), removedPropertyNames() are all deprecated (and return null). So how do I know what was actually changed?

Replies

Highlighted

Himanshu_Singhal

MVP

24-07-2019

@Component(

  service = ResourceChangeListener.class,

  property = {

  ResourceChangeListener.PATHS + "=" + "/apps/sample/i18n/",

  ResourceChangeListener.CHANGES + "=" + "ADDED"
   }

)

public class ChangedResourceHandler implements ResourceChangeListener {

   @Override
   public void onChange(@Nonnull List<ResourceChange> list) {

   try {

   for (final ResourceChange change : list) {

          change.getPath(); //Gives you the path where changes occurs

  }

  } catch (Exception e) {

   LOGGER.error("Exception {}", e);

  }

  }

}

Sample code for ResourceChange Listener. You can add type of event i.e. ADDED, CREATED
And, inside onChnage method, you get the list of paths which has changed.

What else do you need apart from PATH where change occurs because using that path, you can get resource and once you've resource, then can get all resource related data.

Highlighted

jkpanera

24-07-2019

Once I have the path, I can get the resource that changed, but I don't know which properties are new or changed. I can get the new properties but I don't know what values were there before.

Highlighted

Himanshu_Singhal

MVP

24-07-2019

True. You can't get the information which one is old and which one is new. To get the information of what has specifically has changed, you'll have to get the previous version of page and for that, you should've the versioning enabled so every time you make the change, it creates a new version of page.

Highlighted

jkpanera

24-07-2019

When I install the same content package twice, the onChange method is called twice even though nothing has actually changed the second time. So why does it get called?