Expand my Community achievements bar.

SOLVED

AEM Assets - Provide Search API to 3rd party

Avatar

Level 3

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

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @beast42 ,

When it comes to exposing AEM asset data you can consider below 2 options:

  1. Assets HTTP API [0]
  2. Sling Servlet - Component/Service

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. 

  • Implement Servlet/Service which will be responsible for fetching AEM Asset data through QueryBuilder API refer below code snippet for retrieving all properties of an asset
    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"); 
    Asset asset = resource.adaptTo(Asset.class);
    String fileName = asset.getMetadataValue("dc:title");
    String formatValue=asset.getMetadataValue("dc:format");
    Once you manage to fetch everything as expected, you can then embed it into JSON and expose it to third party.
    In this case you will have more control over the other option - One can manipulate the stuff as per need.

[0]: https://experienceleague.adobe.com/docs/experience-manager-65/assets/extending/mac-api-assets.html?l...

Hope that helps!

Regards,

Santosh

View solution in original post

3 Replies

Avatar

Employee

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.

Screen Shot 2022-07-06 at 10.42.32 am.png

 

I trust this helps you. 

 

Thanks,

 

Avatar

Level 3

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. 

Avatar

Correct answer by
Community Advisor

Hi @beast42 ,

When it comes to exposing AEM asset data you can consider below 2 options:

  1. Assets HTTP API [0]
  2. Sling Servlet - Component/Service

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. 

  • Implement Servlet/Service which will be responsible for fetching AEM Asset data through QueryBuilder API refer below code snippet for retrieving all properties of an asset
    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"); 
    Asset asset = resource.adaptTo(Asset.class);
    String fileName = asset.getMetadataValue("dc:title");
    String formatValue=asset.getMetadataValue("dc:format");
    Once you manage to fetch everything as expected, you can then embed it into JSON and expose it to third party.
    In this case you will have more control over the other option - One can manipulate the stuff as per need.

[0]: https://experienceleague.adobe.com/docs/experience-manager-65/assets/extending/mac-api-assets.html?l...

Hope that helps!

Regards,

Santosh