{{announcement.body}}
{{announcement.title}}

How to Attach a Document to BPMN Process In jBPM 7

DZone 's Guide to

How to Attach a Document to BPMN Process In jBPM 7

There are multiple cases where we have to attached a document to BPMN process in the process execution. Here are the steps for doing so in jBPM 7.

· Open Source Zone ·
Free Resource

Multiple times we have to attach docuemnt to BPMN process which is part of process execution or if its required to perform HumanTask operation. Here are the steps for attaching Document to BPMN process in jBPM 7. 

  • In the kie-workbench, in project settings goto  deployment-descriptor file(kie-deployment-descriptor.xml)  and define the marshalling strategy for document
    • XML
       




      xxxxxxxxxx
      1


      1
      <marshalling-strategies>
      2
        <marshalling-strategy>
      3
        <resolver>mvel</resolver>
      4
        <identifier>new  org.jbpm.document.marshalling.DocumentCollectionImplMarshallingStrategy(new org.jbpm.document.marshalling.DocumentMarshallingStrategy())</identifier>
      5
         <parameters/>
      6
         </marshalling-strategy>
      7
      </marshalling-strategies>


  • Define process variable of type org.jbpm.document.DocumentCollection.

'DocumentCollectionImplMarshallingStrategy' and process variable of type 'org.jbpm.document.DocumentCollection'  support use of multiple documents in BPMN process, i.e at a time you can upload multiple documents while starting process/case execution or while performing task operation. For single document, we can use process variable of type 'org.jbpm.document.Document' with marshalling strategy 'org.jbpm.document.marshalling.DocumentMarshallingStrategy'.   

How to Pass a Document While Starting Process Execution

  • If you are using kie-workbench/business-central console to start process then you can create process form where you will have to browse through the system and upload the document while starting process instance.
  • If you want to use JAVA code to start it then you can use DocumentInstance API's for same, like as:
    • Java
       




      xxxxxxxxxx
      1
      14


       
      1
      DocumentInstance documentInstance = new DocumentInstance();
      2
      documentInstance.setIdentifier("myDoc");
      3
      documentInstance.setName("doc.pdf");
      4
      java.net.URL docURL = new java.net.URL("file:///path/to/uploadDoc.pdf");
      5
      documentInstance.setLink(String.valueOf(docURL));
      6
      documentInstance.setLastModified(java.util.Calendar.getInstance().getTime());
      7
      final InputStream inputStream = new java.io.FileInputStream("path/to/uploadDoc.pdf");
      8
      byte[] content = org.apache.commons.io.IOUtils.toByteArray(inputStream);
      9
      documentInstance.setContent(content);
      10
       
                    
      11
      Map<String, Object> processVars = new HashMap<String, Object>();
      12
      processVars.put("document_ProcessVariable", documentInstance);
      13
       
                    
      14
      long pid = processClient.startProcess(ContainerId, "DocuemntTest", processVars);


  •  When we send request to start process payload will look like as:
    • JSON
       




      x


       
      1
      {
      2
        "document" : {
      3
          "org.jbpm.document.service.impl.DocumentImpl":{
      4
             "identifier":"myDoc.pdf",
      5
             "name":"Doc.pdf",
      6
             "link":"",
      7
             "size": 53,
      8
             "lastModified" : 45,
      9
             "content":"......."
      10
          }
      11
        },
      12
      "docName":"uploadDoc.pdf",
      13
      "comments": "your comments"
      14
      }
      15
      `


Topics:
document, jbpm core engine api, jbpm features, jbpm workflow example

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}