Sometimes you may want a work space or directory to be deleted when it becomes empty. For instance, you may have a temporary directory to share files for review or collaboration. The workspace or folder will remain available until the reviews and collaborations have been completed and the documents filed or moved into their designated spaces. Once the documents are moved out of the workspace, it would be best practice to remove the folder to keep your document management system clean, organized and manageable.
One of the many ways to achieve this behavior in Alfresco, would be to add a custom Action, and attach it to a rule. Another way, may be to add a behavior policy on the directories that need to be monitored and removed. Alternatively, you may write a cron job to routinely purge unused folders. Or maybe, you may regularly remind your users to clean up after themselves. In this article however, we’ll examine how to achieve this functionality in Alfresco, via Rules, Space Templates and Actions.
The Alfresco Services used for this are:
The inherited classes and interfaces are:
When this action is included as part of a rule, with criterions set to listen for items leaving or being deleted from the target directory, it will execute to delete the target directory.
This class will then be wired into the Spring IOC bean configuration as follows:
A working example of this functionality can be found in the Alfresco workflow upload functionality module. In this referenced project, the Action and rule will be automatically added to the Alfresco Templates directory; so that folders based on this templated behavior can be easily created.