Expand my Community achievements bar.

SOLVED

Programatically deleting an Asset and its related data in AEM

Avatar

Level 4

Hi Everyone,

 

I have a requirement to delete an Asset from AEM through servlet.

I'm using below method to delete Asset.

 

Resource assetRes = resourceResolver.getResource(assetPath);

Node assetNode =  assetRes.adaptTo(Node.class)

assetNode = assetNode.remove();

resourceResolver.commit();

 

My question is does assetNode.remove() will remove the asset and its related data like all child nodes, version, history from CRX?

 

Also came accross removeRecursive(Node n, int saveEveryHowManyNodes) what does this method do.?

 

Thanks,

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hello @girishb83316758 

 

assetNode.remove() will remove the asset and its child nodes.

 

Regarding versions: 

They would not be deleted by assetNode.remove() API

  1. The versions would be deleted by version purge maintenance, as per the configurations on your system.
  2. You can also trigger version purge for a specific content path via http://localhost:4505/etc/versioning/purge.html
  3. For purging versions programmatically, one can use https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/day/cq/wcm/api/Ve...
    • It has API like purgeVersions(Node node, boolean dryRun, int maxVersions, int maxAge)
      Returns a list of purge infos of the versions that are purged using the specified conditions.
    • Version Manager can be retreived via 
        versionManager = node.getSession().getWorkspace().getVersionManager();
      

 

 

 

 

 


Aanchal Sikka

View solution in original post

5 Replies

Avatar

Community Advisor

Hi,

When we call node.remove() on a node in AEM, it will remove the specified node and its properties, but it does not automatically remove all child nodes, versions, or history related to that node. The removal of child nodes and related data is not done automatically because it may have significant implications on your content structure and history.

 

Regarding removeRecursive

Removes Node n and its children recursively, saving every N nodes as specified (to avoid growing the transient space too much)
Returns:
number of nodes deleted
Throws:
RepositoryException

Avatar

Level 4

@Ravi_Pampana  I want to delete the Asset from AEM programmatically. All the child nodes, history, versions from CRX. Basically the goal to save space and improve performance is the goal.In this case how should we do it?

 

Can you please if share if you have any references for this.

Avatar

Correct answer by
Community Advisor

Hello @girishb83316758 

 

assetNode.remove() will remove the asset and its child nodes.

 

Regarding versions: 

They would not be deleted by assetNode.remove() API

  1. The versions would be deleted by version purge maintenance, as per the configurations on your system.
  2. You can also trigger version purge for a specific content path via http://localhost:4505/etc/versioning/purge.html
  3. For purging versions programmatically, one can use https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/day/cq/wcm/api/Ve...
    • It has API like purgeVersions(Node node, boolean dryRun, int maxVersions, int maxAge)
      Returns a list of purge infos of the versions that are purged using the specified conditions.
    • Version Manager can be retreived via 
        versionManager = node.getSession().getWorkspace().getVersionManager();
      

 

 

 

 

 


Aanchal Sikka

Avatar

Administrator

@girishb83316758 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni