Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

How to know what changed using a ResourceChange object?

Avatar

Avatar
Validate 10
Level 3
jkpanera
Level 3

Likes

18 likes

Total Posts

97 posts

Correct Reply

2 solutions
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 10
View profile

Avatar
Validate 10
Level 3
jkpanera
Level 3

Likes

18 likes

Total Posts

97 posts

Correct Reply

2 solutions
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 10
View profile
jkpanera
Level 3

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

Avatar

Avatar
Validate 25
MVP
Himanshu_Singhal
MVP

Likes

65 likes

Total Posts

206 posts

Correct Reply

23 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give Back 5
Give Back 3
View profile

Avatar
Validate 25
MVP
Himanshu_Singhal
MVP

Likes

65 likes

Total Posts

206 posts

Correct Reply

23 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give Back 5
Give Back 3
View profile
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.

Avatar

Avatar
Validate 10
Level 3
jkpanera
Level 3

Likes

18 likes

Total Posts

97 posts

Correct Reply

2 solutions
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 10
View profile

Avatar
Validate 10
Level 3
jkpanera
Level 3

Likes

18 likes

Total Posts

97 posts

Correct Reply

2 solutions
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 10
View profile
jkpanera
Level 3

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.

Avatar

Avatar
Validate 25
MVP
Himanshu_Singhal
MVP

Likes

65 likes

Total Posts

206 posts

Correct Reply

23 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give Back 5
Give Back 3
View profile

Avatar
Validate 25
MVP
Himanshu_Singhal
MVP

Likes

65 likes

Total Posts

206 posts

Correct Reply

23 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give Back 5
Give Back 3
View profile
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.

Avatar

Avatar
Validate 10
Level 3
jkpanera
Level 3

Likes

18 likes

Total Posts

97 posts

Correct Reply

2 solutions
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 10
View profile

Avatar
Validate 10
Level 3
jkpanera
Level 3

Likes

18 likes

Total Posts

97 posts

Correct Reply

2 solutions
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 10
View profile
jkpanera
Level 3

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?