Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Trying to archive assets based on prism:expiration date using scheduler, but its not working ,please guide me where I went wrong?


Level 2

package com.AcHotels.core.servlets;



import java.time.OffsetDateTime;

import java.util.HashMap;

import java.util.Map;

import javax.jcr.Node;

import javax.jcr.NodeIterator;

import javax.jcr.Property;

import javax.jcr.PropertyIterator;

import javax.jcr.Session;

import javax.jcr.Value;

import javax.servlet.Servlet;

import org.apache.sling.api.SlingHttpServletRequest;

import org.apache.sling.api.SlingHttpServletResponse;

import org.apache.sling.api.resource.ResourceResolver;

import org.apache.sling.api.servlets.HttpConstants;

import org.apache.sling.api.servlets.SlingSafeMethodsServlet;

import org.osgi.framework.Constants;

import org.osgi.service.component.annotations.Component;

import org.osgi.service.component.annotations.Reference;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import java.util.*;

import com.AcHotels.core.services.search.AssetsSearch;

import com.adobe.granite.asset.api.AssetManager;

import com.day.cq.search.PredicateGroup;

import com.day.cq.search.Query;

import com.day.cq.search.QueryBuilder;

import com.day.cq.search.result.Hit;

import com.day.cq.search.result.SearchResult;


@component(service = Servlet.class, property = { Constants.SERVICE_DESCRIPTION + "= Asset Expired Servlet",

"sling.servlet.methods=" + HttpConstants.METHOD_GET, "sling.servlet.paths=" + "/bin/servlet/expired" })

public class AssetMigrationServlet extends SlingSafeMethodsServlet {


private static final long serialVersionUID = 7524136240611031422L;

private static final Logger LOGGER = LoggerFactory.getLogger(AssetMigrationServlet.class);



private QueryBuilder builder;


AssetsSearch assetSearch;


private static final String CONTENT_PATH = "/content/dam/AC-Hotels-Marriott/home-page/images/";



protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) {

LOGGER.info("Asset Expired Servlet Called successfully!! ");


try {

ResourceResolver resourceResolver = request.getResourceResolver();

AssetManager assetManager = resourceResolver.adaptTo(AssetManager.class);


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

if (session.nodeExists(CONTENT_PATH)) {


Node parentNode = session.getNode(CONTENT_PATH);


if (parentNode.hasNodes()) {

NodeIterator childNode = parentNode.getNodes();


while (childNode.hasNext()) {

Node assetNode = childNode.nextNode();

String assetName = assetNode.getName();


String assetPath = CONTENT_PATH + assetName;

String movePath = "/content/dam/AC-Hotels-Marriott/archive/expired/" + assetName;


if (assetName.equalsIgnoreCase("jcr:content")) {

LOGGER.info("JCR:CONTENT Node found, hence skipped movement...");

} else {

//assetManager.moveAsset(assetPath, movePath);

final PredicateGroup pGroup= assetSearch.createExpireAssetsQuery(OffsetDateTime.now(), "/content/dam/AC-Hotels-Marriott/home-page/images/", true);

final List<Hit> expiredAssets=assetSearch.searchAssets(pGroup, resourceResolver);

final int hitscount=expiredAssets.size();

for(final Hit expiredAsset :expiredAssets) {

final Node node=expiredAsset.getNode();

assetManager.moveAsset(assetPath, movePath);

LOGGER.info("Asset Node"+node);



response.getWriter().println("***********************************Asset With Name: "

+ assetPath + " is Moved to: " + movePath);








} catch (Exception e) {







4 Replies


Employee Advisor

@jyo2902 The code snippet added over here is a servlet and not a scheduler. Would you be able to add Scheduler Code?

Also, please add if you have AEM On Prem set up or AEMaaCs


Level 2

 I am trying this in local aem as cloud instance.

   I created a servlet to perform that asset search and movement and yet to write scheduler code but getting this error for performing asset movement in 


core pom and main pom given this latest version in dependency but still getting this error


Please let me know how to write scheduler for this .




Level 2


Its aem sdk only its pointing to ,no uber jar given but that issue still persists