I need to get the list of all Content fragments and assets used in a page in my sling servlet. Which API should I use for this.
Thanks
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Thanks @shaileshb584084 and @walterch for your time. I tried with AssetReferenceSearch and now I am able to get the list of assets and content fragment paths in the page. Not sure if I get nested CF list from this. I need to work on it. I am adding my code fragment below. Thanks again for your time.
Node node = resource.adaptTo(Node.class); AssetReferenceSearch reference = new AssetReferenceSearch(node,"/content/dam/custom-project-path",resourceResolver); Map<String,Asset> referenceList = new HashMap<String,Asset>(); referenceList.putAll(reference.search());
Hi,
Just create a query in your servlet to get the list of the assets/contentFragment.
Query for testing it on http://localhost:4502/libs/cq/search/content/querydebug.html
type=dam:Asset
path=<page-path>
Finally create the same using
Session session = resourceResolver.adaptTo(Session.class); if(null!=session) { try { QueryBuilder queryBuilder = resourceResolver.adaptTo(QueryBuilder.class); Map<String, String> queryParameterMap = new HashMap<>(); queryParameterMap.put("type", DamConstants.NT_DAM_ASSET); queryParameterMap.put("path",<page-path>; Query query = queryBuilder.createQuery(PredicateGroup.create(queryParameterMap), session); SearchResult searchResult = query.getResult(); if (null != searchResult) { for (Hit hit : searchResult.getHits()) { Resource assetResource = hit.getResource(); //you can add your code for further processing as per business logic }catch(Exception e) { } }
In the query you can get the page-path from the servlet. One you get the results, add an additional check to check if the asset reference is present in the page or not & finally you will get the list of all valid assets.
Thanks
Thanks @shaileshb584084 and @walterch for your time. I tried with AssetReferenceSearch and now I am able to get the list of assets and content fragment paths in the page. Not sure if I get nested CF list from this. I need to work on it. I am adding my code fragment below. Thanks again for your time.
Node node = resource.adaptTo(Node.class); AssetReferenceSearch reference = new AssetReferenceSearch(node,"/content/dam/custom-project-path",resourceResolver); Map<String,Asset> referenceList = new HashMap<String,Asset>(); referenceList.putAll(reference.search());
What about ACS AEM Commons Report Builder?
https://adobe-consulting-services.github.io/acs-aem-commons/features/report-builder/index.html
Hi @walterch
I need the reference list when a user click on a custom button within the page. I tried to use the class ReferenceProvider but it seems like there are lot of implementations for the same. Also I am not able to Refer most of these implementation. I am just curious to understand how the reference list is getting populated in /libs/wcm/core/content/sites/publishpagewizard.html?item="custom-path" while the default publication is invoked. I am just trying to understand if there is any AEM specific class to do this functionality.
Thanks
Just take the request param i.e. the page path and use the same in the query described in the comment above. It will resolve your business requirement.
There is no direct API to find the assets & content fragment used on the page & which are still valid.
Thanks
ACS AEM Commons Report Builder - This is used just for reporting. It is not possible to do automatic processing with the result of the report.
If only reporting is to be considered, then only one should go with the " ACS AEM Commons Report Builder".
Still it doesn't solve my issue. Say, if I have a page A. The page A is included by a CF A. The CF A is referred to another CF B. My requirement is when the user clicks the page A, I should be able to fetch both CF A and CFB as references. I an not sure if ReferenceAggregator can be used for that purpose.
Views
Likes
Replies