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 .
Solved! Go to Solution.
Views
Replies
Total Likes
@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:
You can refresh the session to get the latest updates before getting/adapting to ValueMap. Please refer below links for more details.
https://jackrabbit.apache.org/oak/docs/dos_and_donts.html#Session_Management
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.
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??
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.
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.
@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:
Thanks Lukasz
I will look into it . thanks so much for ur help..