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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Get Activation Status of assets post modification.

Avatar

Level 2

Hi All,

 

I am writing a utility wherein the page/asset would be replicated if it's modified and pending activation. The last replication date should be less than or earlier than the modification date.

 

How can we do it from backend/java code? I tried "ReplicationStatus", but it does not fit the use case.

 

Thx.

6 Replies

Avatar

Community Advisor

Hi @Vinodthakur 

 

You can write a Sling event listener which listens to the events at the asset's node specified and then replicates the modified asset/page

https://github.com/sunilkumar1117/AEM-Sample/blob/master/acs-aem-samples-master/bundle/src/main/java...

 

Hope this helps!

 

Thanks,

Kiran Vedantam.

Avatar

Level 2

Hi @Kiran_Vedantam , @SantoshSai ,

 

Thanks for the suggestion, the problem is that we are looking to implement this on a huge set of records like 10000 records at a time. Do you see anything more optimal solution here?

 

Thanks.

Avatar

Community Advisor

Are you trying bulk asset properties update @Vinodthakur? You can try writing a custom workflow step that replicates the assets on the update of the properties.

 

Thanks,

Kiran Vedantam.

Avatar

Level 2

Hi Kiran,

Thanks. I proceeded with the code suggested by @SantoshSai . The requirement is to find all the references (static) of a page/XP fragment that are outdated and use them to purge Akamai cache.  

 

Thanks.

Avatar

Community Advisor

Hi @Vinodthakur 

I would achieve this using Workflow Launcher which provides one component to monitor all changes in the content repository and launch workflow.

Reference: https://www.argildx.com/technology/triggering-a-workflow-using-event-listeners-in-aem/ 

For your further requirement - sharing some code snippet

public String getReplicationStatus() {
 Session session = resource.getResourceResolver().adaptTo(Session.class);
  log.debug("Getting replication status for {}", path);
 ReplicationStatus status = replicator.getReplicationStatus(session, path);
 Status rStatus = Status.NOT_ACTIVATED;
 if (status != null) {
  if (status.isDeactivated()) {
   rStatus = Status.DEACTIVATED;
  } else if (status.isPending()) {
   rStatus = Status.IN_PROGRESS;
  } else if (status.isActivated()) {
   Calendar lastModified = getLastModified(resource.getResourceResolver(), path);
   if (lastModified != null && status.getLastPublished() != null
     && lastModified.after(status.getLastPublished())) {
    rStatus = Status.MODIFIED;
   } else {
    rStatus = Status.ACTIVATED;
   }
  }
 }
 
 log.debug("Retrieved replication status {}", rStatus);
 return rStatus.toString();
}


Hope that help you!

Regards,
Santosh

Avatar

Employee Advisor

What do you mean with "replicated if it's modified and pending activation"? I understand "pending activation" that the replication API as already been invoked on it and it's just sitting in the queue waiting to get replicated.

 

private Calendar getLastReplicationDate (Resource res) {
  ReplicationStatus status = res.adaptTo(ReplicationStatus.class);
  if (status != null && status.isActivated()) {
    return status.getLastPublished();
  } else {
    return null;
  }
}

private boolean mustBeActivated(Page page) {
  return !page.getLastModified().before(getLastReplicationDate(page.getContentResource()));
}