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.
Solved! Go to Solution.
Views
Replies
Total Likes
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
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
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
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;
}