Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

Programmatically create workflow packages

Avatar

Level 2

Hi All,

For one of my requirements I have had to create a custom console from where authors can select pages and initiate a workflow. Since authors can select multiple pages, I need to be able to pass multiple payload to the workflow. I know this could be done via Workflow packages but the documentation around it seems rather limited. I need to create Workflow package on the fly. I'm aware of a ResourceCollection and ResourceCollectionManager service that could be used but somehow it doesn't work. I'm using the following code:- 

ResourceCollection resourceCollection = resourceCollectionManager.createCollection(session.getNode(workflowPkgPage.getPath())); logger.debug("resourceCollection node created = {}", resourceCollection.getPath());

and I get the following logged in my logs (INFO):-

"com.adobe.granite.workflow.core.collection.ResourceCollectionManagerImpl Resource collection at /etc/workflow/packages/mypackage2 is not a package."

Followed by a NPE in the second line of code above. "/etc/workflow/packages/mypackage2" does indeed exist in CRX. This is a node I am creating first and passing to the above code.

To add to confusion, there are two set of workflow APIs in CQ with following namespace:

  • com.adobe.granite.workflow.*
  • com.day.cq.workflow.*

I am using the first package, as I believe it to be the "latest and greatest" (Possibly because I thought that Adobe will gradually move to granite packaging namespace). Although most classes and methods do seem identical between the two namespaces.

Which one among the two should be used ?

To summarize there are two questions:

  1. Which package to use for Workflow implementation?
  2. How to create workflow packages programmatically?

 

Thanks

Ashish

1 Accepted Solution

Avatar

Correct answer by
Level 10

1)   Use granite one

2)    AFAIK there is no direct api. You might need to do form submission for each resource.

For your use case is each payload will be using same workflow or different one ?

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

1)   Use granite one

2)    AFAIK there is no direct api. You might need to do form submission for each resource.

For your use case is each payload will be using same workflow or different one ?

Avatar

Level 2

Thanks Sham,

I am using the Granite workflow API. I think the official documentation needs to be updated. Every workflow documentation I came across used the "com.day.cq.." API.

In the end I created the required Workflow Package Page via Node API.

For my usecase I need to launch a workflow with multiple payloads. With the above approach my issue is now resolved.

 

Thanks
Ashish