How to get the asset count for upload and download in AEM by using QueryBuilder ? | Community
Skip to main content
Level 2
Feb 13, 2023 10:33 AM UTC
Solved

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

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.

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
krishna_sai
krishna_saiAccepted solution
New Participant
Feb 13, 2023 10:58 AM UTC

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?lang=en


Thanks,
Krishna

3 replies

Nitin_laad
New Participant
Feb 13, 2023 5:30 PM UTC

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; }

 

Translate
rampai
Level 1
Feb 13, 2023 11:07 AM UTC

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

Translate
krishna_sai
krishna_saiAccepted solution
New Participant
Feb 13, 2023 10:58 AM UTC

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?lang=en


Thanks,
Krishna

Translate