Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

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

Avatar

Level 5

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)?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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.

View solution in original post

6 Replies

Avatar

Correct answer by
Community Advisor

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.

Avatar

Employee

@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.

 

krati_garg_0-1669791016145.png

 

Avatar

Level 5

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?

Avatar

Level 4

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".

Avatar

Level 5

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

Avatar

Level 4

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