For my current AEM 6.0 project I need to create a custom workflow to create renditions. Were working on a shared platform with other AEM projects. Thats the reason why we arent allowed to adapt the original DAMUpdateAsset workflow (which renders the AEM specific renditions, thumbnails and so on).
My custom rendition workflow renders different renditions. The problem is, sometimes i recive exceptions like IllegalOakState when my workflow runs in parallel to the DAMUpdateAsset workflow.
What I need is a solution, to wait with my workflow until the DAMUpdateAsset workflow is finished.
Currently I am trying to get that done with an oak query
public static final String QUERY_STRING = "SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/etc/workflow/instances]) and CONTAINS('status', 'COMPLETED') and contains('modelId', '/etc/workflow/models/dam/update_asset/jcr:content/model') and [data/payload/path]='%s' and endTime > CAST('%s' AS DATE)";
private void waitForDamUpdateImage(Session session, String path) throws WorkflowException, InterruptedException
{
final DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.GERMAN);
final Date now = new Date();
final Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date(now.getTime() - 2 * 60 * 1000));
String queryString = String.format(QUERY_STRING, path, formatter.format(calendar.getTime()));
Iterator iterator;
do
{
//wait(100); this wait will produce IllegalMonitor... Exception
iterator = QueryUtils.query(session, queryString);
}
while (!iterator.hasNext());
}
I dont think that this is a optimal solution, i think there will be a much easier way to solve this problem.
Hopefully you got an idea of what my problem is and maybe help me solve this.
Thank you anyway ;)
You can create a workflow launcher which will automatically invoke your workflow on Event of node modified for node type cq:workflow and path /etc/workflow/instances(/.*). and condition is either status=COMPLETED or modeleid=/etc/workflow/models/dam/update_asset/jcr:content/model, you may need to experiment which condition has best performance.
As only one condition is allowed in launcher, you need to check one of the condition in your process implementation and continue or abort.