Hi @nandini559,
Below response is with respect to the requirement listed + validation required on the resources to be activated + possibilities with OOB Workflow set up.
For the query "attach pages to the running workflow" - This is not possible. This is because, the flow starts by triggering workflow on an Asset-> word or pdf document, which remains as Payload through out the Workflow and it is not possible to directly amend the Payload. (for our publish process step to act upon in the same workflow)
For this reason,
- We can create one separate workflow model for handling review process + scheduled activation.
- Original workflow which is triggered on a document will capture the resources to be activated and for handling the validation and hence to activate by calling workflow model created above.
To locate the resources to be activated to the workflow:
- Create dialog participant step with Touch UI dialog having pathfield as multifield resource.
For validations on resources and hence activate:
- Create a process step which will perform the below
- Get the list of resources(configured in dialog participant step) from the history. (WorkItem's MetaDataMap)
- For each of the resources (via iteration)
- Adapt the resource to a Page to check if the page is in locked state -> page.isLocked() #11
- Using WcmWorkflowService(com.day.cq.wcm.workflow.api.WcmWorkflowService), check if the resource is already in workflow -> wcmWFService.isInWorkflow(resource path) #10
- If both the validation is through(as indicated by a flag variable), trigger workflow using wfSession.startWorkflow(wfModel, wfData)
- wfModel -> Create WorkflowModel object from separate workflow model (created for review and scheduled Activation process step)
- wfData - Create WorkflowData with resource path which is through both the validation.
By this way, separate workflow instance will be created for each of the validated resources.
API for creating Workflow Package is not exposed as service OOB in which case, we can create single workflow instance pertaining to the workflow package path. (I will explore other options around this and update this thread)
In brief, below is the high level flow
- Workflow is triggered on a document (which has inputs to create pages)
- Assigned to Content Author(Dialog Participant Step) -> Performs authoring/manual activity outside WF and completes the step by providing list of resources in dialog
- Process Step -> custom process step performing above mentioned actions. (Another workflow model will be called for each of the validated resources)
Rough snippet from custom Workflow process step:
List<HistoryItem> historyItems = wfSession.getHistory(item.getWorkflow());
for (HistoryItem history : historyItems) {
MetaDataMap workItemMetaMap = history.getWorkItem().getMetaDataMap();
String[] pathFieldValues = workItemMetaMap.get("pathFieldMulti", String[].class); // pathFieldMulti holds the array of paths authored in Dialog participant step
if (null != pathFieldValues) {
for (String pathField : pathFieldValues) {
boolean wfFlag = true;
if (null != pathField) {
Resource pathResc = rescResolver.resolve(pathField);
Page pathPageObj = pathResc.adaptTo(Page.class);
if (null != pathPageObj) {
if (pathPageObj.isLocked()) {
wfFlag = false;
LOG.debug("Page is locked");
}
}
if (wcmWFService.isInWorkflow(pathField)) {
wfFlag = false;
LOG.debug("Page is in WF already");
}
if (wfFlag) {
WorkflowModel wfModel = getWorkflowModel(wfSession);
WorkflowData wfData = getWorkflowData(wfSession, pathField);
startWorkflow(wfSession, wfModel, wfData);
}
}
}
}
}
private void startWorkflow(WorkflowSession wfSession, WorkflowModel wfModel, WorkflowData wfData) {
try {
wfSession.startWorkflow(wfModel, wfData);
} catch (WorkflowException e) {
LOG.error("Unable to start workflow={}", e.getMessage());
}
}
private WorkflowData getWorkflowData(WorkflowSession wfSession, String pathFieldVal) {
WorkflowData wfData = wfSession.newWorkflowData("JCR_PATH", pathFieldVal);
return wfData;
}
private WorkflowModel getWorkflowModel(WorkflowSession wfSession) {
WorkflowModel wfModel = null;
try {
wfModel = wfSession.getModel(ACTIVATION_WF);
} catch (WorkflowException e) {
LOG.error("Unable to create WF Model={}", e.getMessage());
}
return wfModel;
}
