Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.
SOLVED

Retrieving Resource Version Timeline via API in Adobe Experience Manager as a Cloud Service

Avatar

Level 3

Hi everyone,

I am working on a project that requires managing the versions of a resource in Adobe Experience Manager (AEM). I need to retrieve the version timeline of a resource via API. Specifically, I want to distinguish between the following states programmatically:

A) Published B) NOT published C) Published but with pending modifications

Has anyone had experience or can share examples of how to obtain this information using the AEM APIs? Any suggestions or references to useful documentation would be greatly appreciated.

Thank you in advance for your help!

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi,

 

while technically correct, I would definitely use the ootb API for this:

 

Resource getResource = resourceResolver.getResource("/your resource path");
ReplicationStatus status = getResource.adaptTo(ReplicationStatus);
// and from there use the ReplicationStatus API

because it provides a nice abstraction across a few different aspects, which were added 2-3 years ago (for example preview).


see https://javadoc.io/doc/com.adobe.aem/aem-sdk-api/latest/com/day/cq/replication/ReplicationStatus.htm...

 

View solution in original post

5 Replies

Avatar

Level 3

Just a BIT: "via API" means: via Java. 

 

Regards.

Avatar

Level 3

Hi @davidef34326447 ,

You can get the resource which you wanted to check and get last replicated date and last modified date properties.

 

Resource getResource = resourceResolver.getResource("/your resource path");
ValueMap property = resource.adaptTo(ValueMap.class);
Date lastModified = property.get("JcrConstants.JCR_LASTMODIFIED", Calendar.class);
Date lastReplicated = property.get("NameConstants.PN_PAGE_LAST_REPLICATED", Calendar.class);

By getting last modified and last replicated and you will get to know if resource is published(if you get value for lastReplicated) or not published(No value for lastReplicated) and if last modified date is greater than the published date then it comes to 3rd case(Published with pending modifications).

Hope this helps.
 

Avatar

Level 3

Thank you for your response and the provided code snippet. I appreciate the suggestion to compare the last replicated date and the last modified date to determine the state of the resource.

However, I have encountered instances where the publication date is a few milliseconds earlier than the modification date, even when there are no actual modifications to the content. Analyzing over 40k content fragments, I noticed that this behavior affected a small portion of the content fragments.

Therefore, I am looking for a more reliable way to retrieve this information.

Does anyone know if there is an SDK (Java package) within the AEM framework that provides this information without the need to compare and derive the state from such low-level data? Any pointers or examples would be greatly appreciated.

Thank you again for your help!

Avatar

Employee Advisor

Technically these timestamps should be correct, and this is the first case I read where it is reported as problematic in some cases.

 

The jcr:lastModified property can be updated in a number of cases (maybe even in the case, where nothing was effectivly changed, but the UI did a request to the backend; and there a string was updated with the previous/identical value). Can you check in the audit log if a change was recorded for these CFs?

 

(Note: the jcr:lastModified property is not special in any case; you can update it freely, and any content change does not have to update either.)

Avatar

Correct answer by
Employee Advisor

Hi,

 

while technically correct, I would definitely use the ootb API for this:

 

Resource getResource = resourceResolver.getResource("/your resource path");
ReplicationStatus status = getResource.adaptTo(ReplicationStatus);
// and from there use the ReplicationStatus API

because it provides a nice abstraction across a few different aspects, which were added 2-3 years ago (for example preview).


see https://javadoc.io/doc/com.adobe.aem/aem-sdk-api/latest/com/day/cq/replication/ReplicationStatus.htm...