AEM how to know if a given asset is processed or not programatically? | Community
Skip to main content
Level 4
November 30, 2022
Solved

AEM how to know if a given asset is processed or not programatically?

  • November 30, 2022
  • 3 replies
  • 2302 views

When I upload an image on AEM it takes few seconds before it gets processed. However if its not fully processed and I try to publish it it fails. Is there a way to programatically know if a given image is processed or not? (Using Assets. / Replicate or some other API)?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by lukasz-m

Hi @spidey1405,

Assuming you are using OOTB DAM Update Asset workflow then you can utilize information that is generated by DAM Update Asset Workflow Completed step. This step is also responsible to set dam:assetState property value to processed. As part of this step DAM_UPDATE_ASSET_WORKFLOW_COMPLETED event is send when DAM Update Asset workflow is completed. Having this knowledge, you can simply create event handler that will be listening on above topic. Here is very basic example:

package com.mysite.core.handler;

import com.day.cq.dam.api.DamEvent;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(
        immediate = true,
        service = EventHandler.class,
        property = EventConstants.EVENT_TOPIC + "=" + DamEvent.EVENT_TOPIC)
public class DAMEventHandler implements EventHandler {

    private static final Logger LOG = LoggerFactory.getLogger(DAMEventHandler.class);

    @Override
    public void handleEvent(Event event) {
        DamEvent damEvent = DamEvent.fromEvent(event);
        if (DamEvent.Type.DAM_UPDATE_ASSET_WORKFLOW_COMPLETED.equals(damEvent.getType())) {
            LOG.info("Processed asset path: " + damEvent.getAssetPath());

            // place for your code
        }
    }
}

and one more, but more complex:

Above solution will prevent you to check dam:assetState property periodically (for given asset) and generate unnecessary load on AEM instance.

3 replies

lukasz-m
Community Advisor
lukasz-mCommunity AdvisorAccepted solution
Community Advisor
November 30, 2022

Hi @spidey1405,

Assuming you are using OOTB DAM Update Asset workflow then you can utilize information that is generated by DAM Update Asset Workflow Completed step. This step is also responsible to set dam:assetState property value to processed. As part of this step DAM_UPDATE_ASSET_WORKFLOW_COMPLETED event is send when DAM Update Asset workflow is completed. Having this knowledge, you can simply create event handler that will be listening on above topic. Here is very basic example:

package com.mysite.core.handler;

import com.day.cq.dam.api.DamEvent;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(
        immediate = true,
        service = EventHandler.class,
        property = EventConstants.EVENT_TOPIC + "=" + DamEvent.EVENT_TOPIC)
public class DAMEventHandler implements EventHandler {

    private static final Logger LOG = LoggerFactory.getLogger(DAMEventHandler.class);

    @Override
    public void handleEvent(Event event) {
        DamEvent damEvent = DamEvent.fromEvent(event);
        if (DamEvent.Type.DAM_UPDATE_ASSET_WORKFLOW_COMPLETED.equals(damEvent.getType())) {
            LOG.info("Processed asset path: " + damEvent.getAssetPath());

            // place for your code
        }
    }
}

and one more, but more complex:

Above solution will prevent you to check dam:assetState property periodically (for given asset) and generate unnecessary load on AEM instance.

krati_garg
Adobe Employee
Adobe Employee
November 30, 2022

@spidey1405 

Whenever DAM Update Asset Workflow finishes with Asset processing, dam:assetState property is set as processed. Please see the screen shot below. 

You can check this property before replicating the Asset programmatically.

 

 

Level 4
November 30, 2022

Hey @krati_garg  so does that mean when the processing is going on it would not show processed? What would be the value at that time?

TarunKumar
Community Advisor
Community Advisor
November 30, 2022

Hi @spidey1405 ,

You can check for the property "dam:assetState" of asset inside jcr:content. For Processed asset it should appear as "processed" for unprocessed it should appear as "unProcessed".

Level 4
November 30, 2022

Hey Tarun what about processing? Basically when it is in processing does it show processed or unprocessed?

TarunKumar
Community Advisor
Community Advisor
November 30, 2022

Hi @spidey1405 ,
It appears as "processing" as far as I remember, however I will have to double check it by reproducing the scenario.