AEM Scheduler to remove the asset

Avatar

Avatar

Prince_Shivhare

Avatar

Prince_Shivhare

Prince_Shivhare

08-02-2018

Hi Community,

I want to create a scheduler by which I can remove a asset of specific extension from DAM in specific time duration.

I am trying to do it. but getting failure.

ResourceResolver writeResourceResolver;

ResourceResolverFactory rrFactory;

public void run() {

/*  creating a user to remove the asset and did the configuration in user mapping with all access to user.*/   

Map<String, Object> param = new HashMap<String, Object>();

param.put(ResourceResolverFactory.SUBSERVICE, "getResourceResolver");

ResourceResolver resourceResolver = rrFactory.getServiceResourceResolver(param);

Session session = resourceResolver.adaptTo(Session.class);

session.refresh(true);

LOG.debug("User id " + session.getUserID());

if (session != null) {

if (session.itemExists(filename)) {

Node fileNameNode = session.getNode(filename);

fileNameNode.remove();

session.save();

session.logout();

LOG.debug("file Deleted");

}

} else {

LOG.error("session is null");

}

}

Replies

Avatar

Avatar

Hemant_arora

Avatar

Hemant_arora

Hemant_arora

08-02-2018

try using the below example. Make sure you have created a system user for the scheduler service. https://helpx.adobe.com/experience-manager/using/aem-first-components1.html

Avatar

Avatar

Prince_Shivhare

Avatar

Prince_Shivhare

Prince_Shivhare

08-02-2018

Hi, I am able to achieve this. but now I have issue to find the file with certain extension only. and delete them from specific folder.

Avatar

Avatar

Hemant_arora

Avatar

Hemant_arora

Hemant_arora

08-02-2018

do a query and find for files with specific extension and delete https://helpx.adobe.com/experience-manager/using/using-query-builder-servlet.html

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

08-02-2018

Also - create a workflow to perform CRUD operations on Assets to meet your business requirements. You can create custom workflow steps to search for assets, etc,

Your solution should be

A (Scheduler Service) -> B (Invokes a workflow that performs operations on Assets).

Avatar

Avatar

kautuk_sahni

Community Manager

Total Posts

5.7K

Likes

1.0K

Correct Reply

1.1K

Avatar

kautuk_sahni

Community Manager

Total Posts

5.7K

Likes

1.0K

Correct Reply

1.1K
kautuk_sahni
Community Manager

08-02-2018

Have checked the Assets API.. there you can get name and last modified value by calling getName() getLastModified() com.day.cq.dam.api.Asset