AnsweredAssumed Answered

Access Document content in Java action : 'virtual' NodeRef ?

Question asked by fcamblor on Feb 9, 2011
Latest reply on Feb 11, 2011 by mitpatoliya
Hi all,

I'd like, in a Java action called inside a workflow, to retrieve the document content I just submitted.
I encountered some strange behaviour (to my point of view) : when executing action targetting document(s) : these document(s) seems inside sort of "virtual" NodeRef.
I'd like to know if my assumption (about "virtual" noderef) is true, or, if not, I'd like to understand the underlying behaviour about this :)

My processdefinition sample :

<process-definition xmlns="" name="wf:adhocCustom">
   <task-node name="adhoc">
      <task name="wf:adhocTask" swimlane="assignee">
         <event type="task-create">
               if (bpm_workflowDueDate != void) taskInstance.dueDate = bpm_workflowDueDate;
               if (bpm_workflowPriority != void) taskInstance.priority = bpm_workflowPriority;
   <transition name="" to="completed">
       <action class="">

Then I have following implementation :

public class MyAction extends JBPMSpringActionHandler {
    private NodeService nodeService;
    private ContentService contentService;
    private FileFolderService fileFolderService;

    protected void initialiseHandler(BeanFactory factory)
        ServiceRegistry services = (ServiceRegistry) factory.getBean(ServiceRegistry.SERVICE_REGISTRY);
        nodeService = services.getNodeService();
        contentService = services.getContentService();
        fileFolderService = services.getFileFolderService();

    public void execute(final ExecutionContext context) throws Exception
      // Retrieving current "virtual" node hosting modified documents [1]
      NodeRef virtualDirectory = ((JBPMNode) context.getContextInstance().getVariable("bpm_package")).getNodeRef();
      // Browsing every modified files, and calling target sites deployments [2]
      for(FileInfo fileInfo : fileFolderService.listFiles(virtualDirectory)){
         // Retrieving document file path & content
         Path filePath = nodeService.getPath(fileInfo.getNodeRef());
         String fileContent = contentService.getReader(fileInfo.getNodeRef(), ContentModel.PROP_CONTENT).getContentString();
         // …

In [1] I retrieve current bpm_package's NodeRef.
In my particular case, as I said earlier, this NodeRef seems to not be an "existing" Node Reference (some sort of "virtual directory).
I made this assumption because :
  • When I execute fileFolderService.getFileInfo(virtualDirectory), it returns null (directory seems not to *really* exist)
  • When iterating over virtualDirectory children ([2]), I only see modified document (other documents residing at the same level of the current modified document don't appear in the listing)

  • Are my assumptions right ?
    (that is : is the algorithm in [2] a "good" algorithm allowing to retrieve modified document(s) content(s) ?)

    Thanks in advance !