How To Send Multiple Documents through JBPM API

91 views
Skip to first unread message

h3llo...@gmail.com

unread,
Oct 29, 2021, 2:02:08 PM10/29/21
to jBPM Usage
Hi All,

I wanted to know if we can attach multiple document while starting a JBPM Process.

I am using JBPM 7.59.0.Final Running on Wildfly container.

I created a process with "org.jbpm.document.service.impl.DocumentCollectionImpl" Implementation and wanted to know how the payload looks like for sending multiple documents while starting a process through the kie-server api.

The Script which i currently use is.

import requests
import json


payload = json.dumps({
  "doc": {
    "org.jbpm.document.service.impl.DocumentCollectionImpl": {
      "identifier": "factura 1.pdf",
      "name": "factura 1.pdf",
      "link": "",
      "size": "",
      "lastModified": "",
      "content": "BASE64 content"
    }
  } 
})
headers = {
  'Accept': 'application/json',
  'Authorization': 'Basic a2llc2VydmVyOmtpZXNlcnZlcjEh',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Rafael Soares

unread,
Nov 1, 2021, 12:30:26 PM11/1/21
to h3llo...@gmail.com, jBPM Usage
I've used the "DocumentCollectionImpl" in the past and my payload looks like this:
suppose you have a process variable called "documents" of type "org.jbpm.document.service.impl.DocumentCollectionImpl"

"documents": {
"org.jbpm.document.service.impl.DocumentCollectionImpl": {
"documents": [
{
"identifier": "Quartely Earnings Report.txt",
"name": "Quartely Earnings Report.txt",
"content": "dGVzdCBkYXRhIDEK",
"lastModified": 1600865448290,
"size": 1000,
"attributes": {
"type": "Earnings Report"
}
},
{
"identifier": "Press Release 1.txt",
"name": "Press.txt",
"content": "dGVzdCBkYXRhIDEK",
"lastModified": 1600865448290,
"size": 1000,
"attributes": {
"type": "Press Release"
}
},
{
"identifier": "Credit Report1.txt",
"name": "Credit Report.txt",
"content": "dGVzdCBkYXRhIDEK",
"lastModified": 1600865448290,
"size": 1000,
"attributes": {
"type": "Credit Report"
}
},
{
"identifier": "Rating Document 1.txt",
"name": "Rating Document.txt",
"content": "dGVzdCBkYXRhIDEK",
"lastModified": 1600865448290,
"size": 1000,
"attributes": {
"type": "Rating x Document"
}
}
]
}

I hope this helps.
________________________
________________________
Rafael Torres Coelho Soares


--
You received this message because you are subscribed to the Google Groups "jBPM Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jbpm-usage+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jbpm-usage/da81e383-1922-43e2-ac5c-6fd1fe9de28cn%40googlegroups.com.

h3llo...@gmail.com

unread,
Nov 2, 2021, 5:18:54 AM11/2/21
to jBPM Usage
Hi Rafael, Thanks much, That did the trick.

Can u also let me know how can i retrieve these Document ID  in a process instance? Printing kcontext just gives me the Document Collection object.

Rafael Soares

unread,
Nov 2, 2021, 10:20:02 AM11/2/21
to h3llo...@gmail.com, jBPM Usage
So, "org.jbpm.document.service.impl.DocumentCollectionImpl" is a collection of "org.jbpm.document.Document"

You can iterate over DocumentCollectionImpl like this:

DocumentCollectionImpl docs = (DocumentCollectionImpl)kcontext.getVariable("documents");
System.out.println("\t received " + docs.getDocuments().size() + " doc(s)");

List<String> _docTypes = new ArrayList<>();
for(org.jbpm.document.Document doc: docs.getDocuments()){
System.out.println("Received Doc: " + doc.toString());
_docTypes.add(doc.getAttributes().get("type"));
}
System.out.println("\t docTypes: " + _docTypes);
kcontext.setVariable("docTypes", _docTypes);

________________________
Rafael Torres Coelho Soares

Reply all
Reply to author
Forward
0 new messages