AnsweredAssumed Answered

[RESOLVED] Use of package in sub process

Question asked by stondini on Apr 13, 2014
Latest reply on Apr 15, 2014 by stondini
Hello,

I'm developing a process that uses a package (bpm_package) and then calls a sub process (callActivity element) passing the same package reference like this :

      <callActivity id="incomingClientDocument" name="Client Task" calledElement="IncomingClientDocument">
         <extensionElements>
            <activiti:in source="initiator" target="initiator"></activiti:in>
            <activiti:in source="bpm_package" target="bpm_package"></activiti:in>
            <activiti:in source="bpm_workflowDescription" target="bpm_workflowDescription"></activiti:in>
            <activiti:in source="bpm_workflowDueDate" target="bpm_workflowDueDate"></activiti:in>
         </extensionElements>
      </callActivity>


This works perfectly.

Then in a Java Service, I need to browse some documents and detect if they are in an active process to get the task(s).
Do to that, I use the following code :

    …
    for (NodeRef nodeRef : nodeRefs) {
      List<WorkflowInstance> workflows = this.getWorkflowService().getWorkflowsForContent(nodeRef, true);
      if (!workflows.isEmpty()) {
        List<WorkflowPath> wfPaths = this.getWorkflowService().getWorkflowPaths(workflows.get(0).getId());
        for (WorkflowPath wfPath : wfPaths) {
          List<WorkflowTask> tasks = this.getWorkflowService().getTasksForWorkflowPath(wfPath.getId());
          if (!tasks.isEmpty()) {
            // The document is used in a process
          }
        }
      }
<code>

This code gives a single workflow instance with some paths but no task.
The "workflows" list contains only the main process (which one started the workflow).
The sub process instance is missing.

I found in class "org.alfresco.repo.workflow.WorkflowPackageImpl" the method :
<code>
    public List<String> getWorkflowIdsForContent(NodeRef packageItem)
    {
        ParameterCheck.mandatory("packageItem", packageItem);
        List<String> workflowIds = new ArrayList<String>();
        if (nodeService.exists(packageItem))
        {
            List<ChildAssociationRef> parentAssocs = nodeService.getParentAssocs(packageItem);
            for (ChildAssociationRef parentAssoc : parentAssocs)
            {
                NodeRef parentRef = parentAssoc.getParentRef();
                if (nodeService.hasAspect(parentRef, WorkflowModel.ASPECT_WORKFLOW_PACKAGE)
                            && !nodeService.hasAspect(parentRef, ContentModel.ASPECT_ARCHIVED))
                {
                    String workflowInstance = (String) nodeService.getProperty(parentRef,
                                WorkflowModel.PROP_WORKFLOW_INSTANCE_ID);
                    if (workflowInstance != null && workflowInstance.length() > 0)
                    {
                        workflowIds.add(workflowInstance);
                    }
                }
            }
        }
        return workflowIds;
    }


It gets the ONLY ONE workflow instance of the package but I have two instances that use the same package.

Do you have some tips or did I do something wrong ?

Thank you.

Outcomes