cancel
Showing results for 
Search instead for 
Did you mean: 

[RESOLVED] Use of package in sub process

stondini
Champ in-the-making
Champ in-the-making
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.
1 REPLY 1

stondini
Champ in-the-making
Champ in-the-making
I found the problem.
When the package was created by an action, I used the property <em>ContentModel.ASSOC_CONTAINS</em> instead of <em>WorkflowModel.ASSOC_PACKAGE_CONTAINS</em>


    NodeRef packageNodeRef = this.getWorkflowService().createPackage(null);
    this.getNodeService().addChild(packageNodeRef, actionedUponNodeRef, WorkflowModel.ASSOC_PACKAGE_CONTAINS,
        QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, "packageItems"));