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

Programmatically How Do I check if an asset uploaded has been processed and dam:assetState is set to processed.

Avatar

Level 2

Hi Team , 

 

I have to check if the asset uploaded in dAM is processed or not then perform some logic.

So I am looking for  /asset/path/image.pdf/jcr:content in where the valuemap gives dam:assetState : Processed (property - value)

 

This check I tried in code but it keeps giving me dam:assetState : UnProcessed thou I see in CRX Asset has been processed. 

 

Updated ValueMap I am not getting..

 

Can you please suggest some ways .

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@madhukumari, here's very simple implementation (a starting point)

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 here you can find more complex example/implementation:

View solution in original post

4 Replies

Avatar

Community Advisor

Hi @madhu-sapy,

Keeping in mind that dam:assetState property is set to Processed by DAM Update Asset Workflow Completed step, and that this will also sent an event DAM_UPDATE_ASSET_WORKFLOW_COMPLETED. You can create event handler that will be listening on above topic.

In that case you do not need to worried about refreshing session or resource resolver, because DAM Update Asset Workflow Completed step is sending above event after asset processing is completed (including set dam:assetState to Processed), so you will get proper value in your ValueMap.

Avatar

Level 2

Hi Lukasz,

 

Two question here  : 

Will there be any issue if we go with resolver.refresh.. is this not proper solution .. ?

or its just a tactical solution...

 

for Event handler ; I am already processing some sort on inputs via ResourceChangeListener on a specific Dam folder, using event handler in the same class.. would work?? 

 

 

Avatar

Community Advisor

I think resolver.refresh could be considered as a short term tactical solution. However in my opinion it does not guarantee that your solution will be always working, because the end result will rely on a fact when the refresh will happen. In theory your code can run the resolver.refresh before changes has been applied in the repository, so you will not get expected information on ValueMap anyway.

In my opinion in this specific scenario, this is not a proper solution at least from technical point of view, and I would recommend to relay on event.

In terms of EventHandler implementation, I would rather go with separate class to keep it clean and do not mix multiple responsibilities inside one class. Nevertheless technically you can create EventHandler that will support multiple topics.

Avatar

Level 2

Thanks Lukasz for the brief.

 

I will look into this eventhandler , I do have theoretical knowledge on it .. Could you please help me with some examples.. 

 

I dont have to check these on all the assets in repo ...just on 1 single folder.. 

 

Thanks so much for ur response.

 

 

Avatar

Correct answer by
Community Advisor

@madhukumari, here's very simple implementation (a starting point)

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 here you can find more complex example/implementation: