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.
Join the DZone community and get the full member experience.
Join For FreeMultiple 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.
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
114
1DocumentInstance documentInstance = new DocumentInstance();
2documentInstance.setIdentifier("myDoc");
3documentInstance.setName("doc.pdf");
4java.net.URL docURL = new java.net.URL("file:///path/to/uploadDoc.pdf");
5documentInstance.setLink(String.valueOf(docURL));
6documentInstance.setLastModified(java.util.Calendar.getInstance().getTime());
7final InputStream inputStream = new java.io.FileInputStream("path/to/uploadDoc.pdf");
8byte[] content = org.apache.commons.io.IOUtils.toByteArray(inputStream);
9documentInstance.setContent(content);
1011Map<String, Object> processVars = new HashMap<String, Object>();
12processVars.put("document_ProcessVariable", documentInstance);
1314long 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`
-
Opinions expressed by DZone contributors are their own.
Comments