Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

To display the version number of the asset in the card views.

Avatar

Level 2

Hi All,

 

I have a requirement where I have to display the latest version number of the asset in the card view below the thumbnail. We are already displaying the metadata properties of asset by overriding the PropertyList.jsp under apps /apps/dam/gui/coral/components/admin/contentrenderer/card/asset/propertyList.jsp. 

How do I fetch the version number here?

Any pointers would be helpful.

 

Thanks

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @nithya90 
Please try

AssetVersionManager versionManager = resolver.adaptTo(AssetVersionManager.class);
versionManager.listVersions(assetPath)

https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/adobe/granite/ass...  



Arun Patidar

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @nithya90 
Please try

AssetVersionManager versionManager = resolver.adaptTo(AssetVersionManager.class);
versionManager.listVersions(assetPath)

https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/adobe/granite/ass...  



Arun Patidar

Avatar

Level 6

Hi @nithya90 

 

As @arunpatidar suggested you can use the AssetVersionManager to fetch the version number and that's a ideal way as well below is a code snippet which might help you:

 

    Resource assetResource = resourceResolver.getResource(assetPath);
    Asset asset = assetResource.adaptTo(Asset.class);
    String versionNumber = "N/A";

    if (asset != null) {
        AssetVersionManager versionManager = resourceResolver.adaptTo(AssetVersionManager.class);
        if (versionManager != null) {
            Iterator<Version> versions = versionManager.listVersions(asset.getPath());
            if (versions.hasNext()) {
                Version latestVersion = versions.next();
                versionNumber = latestVersion.getVersionLabel();
            }
        }
    }

Ensure you have all the necessary imports for Asset, AssetVersionManager, Resource, ResourceResolver, and Version. integrate this changes in your propertyList.jsp accordingly.

Hope this helps!