Expand my Community achievements bar.

SOLVED

How to get the asset count for upload and download in AEM by using QueryBuilder ?

Avatar

Level 2

Hi All,

 

I have a requirement to fetch the number of assets uploaded and downloaded to AEM in a certain time period by using the query builder.

Please help me resolve this issue.

 

Thanks in advance.

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @KaibalyaJena_123 you can make use of daterange predicates to acheive this

Example: 

path=/content/dam
type=dam:Asset
daterange.property=jcr:created
daterange.lowerBound=2023-01-01
daterange.upperBound=2023-02-23

https://experienceleague.adobe.com/docs/experience-manager-65/assets/JCR_query_cheatsheet-v1.1.pdf?l...


Thanks,
Krishna

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi @KaibalyaJena_123 you can make use of daterange predicates to acheive this

Example: 

path=/content/dam
type=dam:Asset
daterange.property=jcr:created
daterange.lowerBound=2023-01-01
daterange.upperBound=2023-02-23

https://experienceleague.adobe.com/docs/experience-manager-65/assets/JCR_query_cheatsheet-v1.1.pdf?l...


Thanks,
Krishna

Avatar

Level 6

Hi @KaibalyaJena_123 ,

 

Can you check Asset Reports instead? Below link has documentation depending on which AEM version you are using.

Reports about usage and sharing of assets | Adobe Experience Manager

 

Thanks,

Ram

Avatar

Community Advisor

Hi @KaibalyaJena_123 

check this out, if you are looking for sample code for upload/download -

 

 public int getDownloadedAssetCount(ResourceResolver resourceResolver, Calendar startDate, Calendar endDate) {
        int downloadedAssetCount = 0;
        try {
            QueryBuilder queryBuilder = resourceResolver.adaptTo(QueryBuilder.class);
            Map<String, String> map = new HashMap<>();
            map.put("path", "/content/dam");
            map.put("type", "dam:Asset");
            map.put("event", DamEvent.ASSET_DOWNLOADED.name());
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
            map.put("event.date.from", dateFormat.format(startDate.getTime()));
            map.put("event.date.to", dateFormat.format(endDate.getTime()));
            Query query = queryBuilder.createQuery(PredicateGroup.create(map), resourceResolver.adaptTo(Session.class));
            SearchResult result = query.getResult();
            downloadedAssetCount = result.getHits().size();
        } catch (Exception e) {
            log.error("Error while getting downloaded asset count", e);
        }
        return downloadedAssetCount;
    }
-----------------------------------------------------------


public int getUploadedAssetCount(ResourceResolver resourceResolver, Calendar startDate, Calendar endDate) {
        int uploadedAssetCount = 0;
        try {
            QueryBuilder queryBuilder = resourceResolver.adaptTo(QueryBuilder.class);
            Map<String, String> map = new HashMap<>();
            map.put("path", "/content/dam");
            map.put("type", "dam:Asset");
            map.put("event", DamEvent.ASSET_CREATED.name());
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
            map.put("event.date.from", dateFormat.format(startDate.getTime()));
            map.put("event.date.to", dateFormat.format(endDate.getTime()));
            Query query = queryBuilder.createQuery(PredicateGroup.create(map), resourceResolver.adaptTo(Session.class));
            SearchResult result = query.getResult();
            uploadedAssetCount = result.getHits().size();
        } catch (Exception e) {
            log.error("Error while getting uploaded asset count", e);
        }
        return uploadedAssetCount;
    }