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

How do we find out if an asset is already in a workflow

Avatar

Level 4

How do we find out if an asset is already in a workflow ? It could be another workflow model or another instance of the same model.

My problem statement is that I have pick up assets from a specific dam folder for parsing and then moving to different folders on business logic.... It is fine till this point, But I have to wait / hold off till the Asset update w/f or any other workflow which is triggered on 'THIS' asset has completed.

/Kanwal

1 Accepted Solution

Avatar

Correct answer by
Employee

Hi Kanwal -

There is an OSGI Service you can use called "PayloadMap".  [0]  It will permit you to quickly find out all the running worklfows for a particular payload path.

Hope this helps,

Will

[0] http://docs.adobe.com/docs/de/aem/6-0/develop/ref/javadoc/com/adobe/granite/workflow/PayloadMap.html

View solution in original post

0 Replies

Avatar

Correct answer by
Employee

Hi Kanwal -

There is an OSGI Service you can use called "PayloadMap".  [0]  It will permit you to quickly find out all the running worklfows for a particular payload path.

Hope this helps,

Will

[0] http://docs.adobe.com/docs/de/aem/6-0/develop/ref/javadoc/com/adobe/granite/workflow/PayloadMap.html

Avatar

Level 4

Hey Will,

This seems to the exact api that will do the job for me. -:)

But I notice that the injection for the sevice fails. I tried like this...

@Reference private PayloadMap payloadMap;

My WorkflowProce which implements the WorkflowProcess stops geting deployed.. When I comment these above statements, method execute(...) is reached.

I tried to check through the depfinder, the dependency exits in my aem instance, as follows

com.adobe.granite.workflow.api (162) <dependency> <groupId>com.adobe.granite</groupId> <artifactId>com.adobe.granite.workflow.api</artifactId> <version>1.0.6</version> <scope>provided</scope> </dependency>

 

How can I get the PaylaodMap service into my workflow.

/Regards
Kanwal

Avatar

Level 7

Hello,
We can approach to this problem using QueryBuilder.
1. You can get path of the asset to be moved by using Asset API as follows
<%@ page import="com.day.cq.dam.api.Asset%>
Asset asset = resourceResolver.adaptTo(Asset.class);
String assetPath = asset.getPath();

2. Now you can get the running workflow(if the instance exists) with the same path as follows, but if there is no such workflow instance then the hits will be 0
Provide the "assetPath" for "1_property.value", keep rest as the same.
type=cq:Workflow
path=/etc/workflow/instances
1_property=data/payload/path
1_property.value=/content/dam/geometrixx/portraits/scott_reynolds.jpg
2_property=status
2_property.value=RUNNING

For hit == 1, It will return something like the following
{
"id": "/etc/workflow/instances/2015-07-16/model_21749528994226",
"state": "RUNNING",
"initiator": "admin",
"startTime": "Thu Jul 16 19:24:50 IST 2015",
"model": "/etc/workflow/models/request_for_deactivation/jcr:content/model",
"payloadType": "JCR_PATH",
"payload": "/content/dam/geometrixx/portraits/scott_reynolds.jpg",
"workItems": [{
"id": "/etc/workflow/instances/2015-07-16/model_21749528994226/workItems/node1_etc_workflow_instances_2015-07-16_model_21749528994226",
"node": "node1"
}
]
}

3. If the hit is 1 that means it is associated with a workflow which is in running state, even then if you want to move the asset, one way is to terminate the workflow(or delete the workflow instance) before writing the code to move it, here you can use something as following
workflowModelPath is the path of workflow instance i.e value of "id" from the above quey result
<%@ page import="javax.jcr.Item%>
Item workflowModel = resourceResolver.getResource(workflowModelPath).adaptTo(Item.class);
workflowModel.remove();
resourceResolver.commit();

* In this case you may need to authenticate it by providing username and password
Feel free to reach for any further query
 

Avatar

Level 4

Hey Will,

Got it yes.....

Now accessing as follows

PayloadMap payloadMap = resourceResolver.adaptTo(PayloadMap.class);

Cheers !

/Regards
Kanwal

Avatar

Level 4

I have one pointer for anyone who is looking for assets that are in workflows triggered as part of workflow launcher tab in AEM.

e.g if you are interested in assets (pdf,images, etc) which will be part of a workflow, you will need to check the 'original' rendition.

PayloadMap payloadMap = resourceResolver.adaptTo(PayloadMap.class);payloadMap.isInWorkflow(resource.getPath() + "/jcr:content/renditions/original", true/false))

This will make sure that the workflows triggered on different payloads from 'launchers' will be loo be in your radar.

Avatar

Level 1

Hi Will,

PayloadMap is coming as null upon accessing as follows, in a class that implements WorkFLowProcess

PayloadMap payloadMap = resourceResolver.adaptTo(PayloadMap.class);

Please share the class where you have tried PayloadMap successfully