Hi,
What is the best approach to provide an assets search API to a 3rd party system? They need to query AEM DAM and show assets in their system.
Search Parameters : Asset Title, Asset Description, Asset Content (in case of documents), Search by Custom Metadata Field (future scope)
Thanks
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @beast42 ,
When it comes to exposing AEM asset data you can consider below 2 options:
1. Assets HTTP API [0]
Out-Of-The-Box Assets HTTP API implemented as REST API allows for create-read-update-delete (CRUD) operations on digital assets, including on metadata, on renditions, and on comments, together with structured content using Experience Manager Content Fragments.
However, it depends on the requirement whether it meets exact expectations or not based on this, team has to extend/enhance existing feature. For more details please refer [0]
2. Sling Servlet - Component/Service
A Servlet is a class used to extend the capabilities of servers that host applications accessed by means of a request-response programming model. For such applications, Servlet technology defines HTTP-specific servlet classes.
By means, through servlet you can implement Sling Servlet to expose data to third party application.
Resource resource; ValueMap mainProperties; ValueMap assetMetadataProperties; Resource metadataResource; ValueMap jcrProperties; Resource jcrdataResource; ValueMap allProperties; for (Hit hit : result.getHits()) { //LOGGER.info("\n********Hit path="+hit.getPath()+", title="+hit.getTitle()); resource = hit.getResource(); if(null!=resource){ mainProperties = resource.getValueMap(); // Add JCR Properties jcrdataResource = resource.getChild("jcr:content"); jcrProperties = ResourceUtil.getValueMap(jcrdataResource); // Add Metadata properties metadataResource = resource.getChild("jcr:content/metadata"); assetMetadataProperties = ResourceUtil.getValueMap(metadataResource); // Adding all together allProperties = new ValueMapDecorator(new HashMap()); allProperties.putAll(hit.getProperties()); allProperties.putAll(mainProperties); // Includes jcr:created createdDate etc. allProperties.put("jcr:path",hit.getPath()); //Add Path allProperties.putAll(jcrProperties); allProperties.putAll(assetMetadataProperties); //LOGGER.debug("All Asset Properties="+new Gson().toJson(allProperties)); } }Retrieving metadata properties eg.
Resource resource = resourceResolver.getResource("/a/path/to/a/file/in/the/dam");Once you manage to fetch everything as expected, you can then embed it into JSON and expose it to third party.
Asset asset = resource.adaptTo(Asset.class);
String fileName = asset.getMetadataValue("dc:title");
String formatValue=asset.getMetadataValue("dc:format");
Hope that helps!
Regards,
Santosh
Hello beast42,
One of the ways to share assets can be through asset share commons.
You can find the article https://opensource.adobe.com/asset-share-commons/
if you integrate asset-share-commons it has in-build search functionality. you can customise based on your requirement.
I trust this helps you.
Thanks,
Hi @Lavanya_Pejjayi ,
Thanks for your reply.
Assets share commons is more of a GUI based solution. We need an API which can be consumed from a 3rd party system.
Does asset share commons exposes an API as well? I could not find anything in documentation.
Hi @beast42 ,
When it comes to exposing AEM asset data you can consider below 2 options:
1. Assets HTTP API [0]
Out-Of-The-Box Assets HTTP API implemented as REST API allows for create-read-update-delete (CRUD) operations on digital assets, including on metadata, on renditions, and on comments, together with structured content using Experience Manager Content Fragments.
However, it depends on the requirement whether it meets exact expectations or not based on this, team has to extend/enhance existing feature. For more details please refer [0]
2. Sling Servlet - Component/Service
A Servlet is a class used to extend the capabilities of servers that host applications accessed by means of a request-response programming model. For such applications, Servlet technology defines HTTP-specific servlet classes.
By means, through servlet you can implement Sling Servlet to expose data to third party application.
Resource resource; ValueMap mainProperties; ValueMap assetMetadataProperties; Resource metadataResource; ValueMap jcrProperties; Resource jcrdataResource; ValueMap allProperties; for (Hit hit : result.getHits()) { //LOGGER.info("\n********Hit path="+hit.getPath()+", title="+hit.getTitle()); resource = hit.getResource(); if(null!=resource){ mainProperties = resource.getValueMap(); // Add JCR Properties jcrdataResource = resource.getChild("jcr:content"); jcrProperties = ResourceUtil.getValueMap(jcrdataResource); // Add Metadata properties metadataResource = resource.getChild("jcr:content/metadata"); assetMetadataProperties = ResourceUtil.getValueMap(metadataResource); // Adding all together allProperties = new ValueMapDecorator(new HashMap()); allProperties.putAll(hit.getProperties()); allProperties.putAll(mainProperties); // Includes jcr:created createdDate etc. allProperties.put("jcr:path",hit.getPath()); //Add Path allProperties.putAll(jcrProperties); allProperties.putAll(assetMetadataProperties); //LOGGER.debug("All Asset Properties="+new Gson().toJson(allProperties)); } }Retrieving metadata properties eg.
Resource resource = resourceResolver.getResource("/a/path/to/a/file/in/the/dam");Once you manage to fetch everything as expected, you can then embed it into JSON and expose it to third party.
Asset asset = resource.adaptTo(Asset.class);
String fileName = asset.getMetadataValue("dc:title");
String formatValue=asset.getMetadataValue("dc:format");
Hope that helps!
Regards,
Santosh
Views
Likes
Replies
Views
Likes
Replies