AEM Assets Cleanup
A collection of useful services to perform asset cleanup on Adobe Experience Manager
Technology, Language & Libraries
Java, Adobe Experience Manager, OSGi, Sling
The following configuration parameters are used in the services and servlet described below:
Cron job expression
- The Cron expression that describes the interval schedule when the task will be run.
- The number of days where assets are considered "Inactive". This is used to compare the Last Modified property of the asset.
- The path of the archive folder where assets will be moved from its original directory.
- The number of days before the archived assets will be permanently deleted.
Asset Cleanup Scheduler
A scheduler task that runs at a certain period of time at an interval to find inactive assets and move these assets to an Archive folder.
The scheduler validates the current run mode since we are only doing the clean up on the Author instance.
The program iterates through all the assets that are currently in the Archive folder, and deletes all assets that are past the expiration age
The program runs a JCRSQL2 query to find all assets under a specified directory
The program iterates through the results and finds all the inactive assets
The program checks if the inactive asset has been replicated or "activated". If it is, then it deactivates it, which removes it from the Publish instance.
The inactive asset is then moved to the Archive folder
The program terminates, and runs again on the next interval.
Below are some snippets of the scheduler. View the full working code here.
Utility functions for finding inactive assets, and manipulating the assets:
Java Sling Servlet
Below is a snippet of the POST request that triggers a deletion of inactive and unreferenced assets. View the full working code here.