Get Activation Status of assets post modification. | Community
Skip to main content
Vinodthakur
Level 2
May 31, 2022

Get Activation Status of assets post modification.

  • May 31, 2022
  • 3 replies
  • 1960 views

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.

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

3 replies

Kiran_Vedantam
Community Advisor
Community Advisor
May 31, 2022

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/com/adobe/acs/samples/events/impl/SampleJcrEventListener.java

 

Hope this helps!

 

Thanks,

Kiran Vedantam.

Vinodthakur
Level 2
May 31, 2022

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.

Kiran_Vedantam
Community Advisor
Community Advisor
May 31, 2022

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.

SantoshSai
Community Advisor
Community Advisor
May 31, 2022

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

Santosh Sai
joerghoh
Adobe Employee
Adobe Employee
June 3, 2022

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()));
}