contentMimeType becomes null when Document is updated
I've created a document under Data and I am able to add and delete the files (I followed the example in http://community.bonitasoft.com/project/file-upload-and-download-process...)
When the following script is run in Operations to update an attached Document, the contentMimeType gets updated from application/pdf to null.
As a result of this change, I can't send an email with the Documents attached as I get the error org.bonitasoft.engine.connector.ConnectorException: javax.mail.internet.ParseException: Expected MIME type, got null"
How can I get the contentMimeType not to change its value?
Script below:
import java.util.logging.Logger;
import org.bonitasoft.engine.bpm.contract.FileInputValue
import org.bonitasoft.engine.bpm.document.Document
import org.bonitasoft.engine.bpm.document.DocumentValue
if(myMultipleDocumentsDeleteContract.isEmpty() == false) {
for(Map<String, Object> documentToDelete : myMultipleDocumentsDeleteContract) {
if(documentToDelete.get("selected")) {
apiAccessor.processAPI.removeDocument(documentToDelete.get("id") as long);
}
}
}
int index = 0
int numberOfResult = 1
List documents
List filesInputValue = new ArrayList()
while((documents = apiAccessor.processAPI.getDocumentList(processInstanceId, "myMultipleDocuments", index, numberOfResult)).size()) {
for(Document currentDocument : documents) {
FileInputValue fileInputValue = new FileInputValue(currentDocument.contentFileName, apiAccessor.processAPI.getDocumentContent(currentDocument.contentStorageId))
filesInputValue.add(fileInputValue)
}
index += numberOfResult
}
filesInputValue.addAll(myMultipleDocumentsContract);
return filesInputValue
Thanks,
Raphael.
Hi Sean,
Thanks for the answer. It solved the problem.I used currentDocument.contentMimeType in the constructor. The code below
This is solved but I don't know how to mark it as resolved (I'm a newbie)
Just realized what you are doing...
You are "copying" a file to another to another file...
What you've not realized though is that it doesn't copy the mime type with the file, you have to do it yourself, or use the correct call...
from the documentation (http://documentation.bonitasoft.com/javadoc/api/7.3/org/bonitasoft/engin...):
FileInputValue (2 values expected)
public FileInputValue(String fileName,
byte[] content)
FileInputValue (3 values expected)
public FileInputValue(String fileName,
String contentType,
byte[] content)
If you use the second type of call referencing the original document then it will work:
apiAccessor.processAPI.getContentType(currentDocument.contentStorageId),
apiAccessor.processAPI.getDocumentContent(currentDocument.contentStorageId))
or something like it :)
regards
Seán
PS: As this reply answers your question, please mark as resolved.
Thanks Sean for the tip, the script (using
as advised) which I believe is changing the value of contentMimeType to null for Documents uploaded to a case (I got the code from the example in http://community.bonitasoft.com/project/file-upload-and-download-process)
I'm using BonitaBPMCommunity-7.3.3
Code below:
import org.bonitasoft.engine.bpm.contract.FileInputValue
import org.bonitasoft.engine.bpm.document.Document
import org.bonitasoft.engine.bpm.document.DocumentValue
if (supportingDocDeleteContract.isEmpty() == false){
for (Map<String, Object> documentToDelete : supportingDocDeleteContract){
if (documentToDelete.get("selected")){
apiAccessor.processAPI.removeDocument(documentToDelete.get("id")as long)
}
}
}
int index = 0
int numberOfResult = 1
List<Document> documents
List<FileInputValue> filesInputValue = new ArrayList<FileInputValue>()
while((documents = apiAccessor.processAPI.getDocumentList(processInstanceId, "supportingDocuments", index, numberOfResult)).size()) {
for(Document currentDocument : documents) {
FileInputValue fileInputValue = new FileInputValue(currentDocument.contentFileName, apiAccessor.processAPI.getDocumentContent(currentDocument.contentStorageId))
filesInputValue.add(fileInputValue)
}
index += numberOfResult
}
filesInputValue.addAll(supportingDocContract);
return filesInputValue
Comments
A Tip on displaying CODE/LOGS correctly in Posts:
Do not use the Supplied Buttons above, for some reason they refuse to work correctly, and despite bringing it to Bonitasofts attention, it's low priority.
To Show Code/Logs correctly use
< code >
your code/log
< /code >
removing the spaces to allow the showing of code/logs correctly as here:
You should still be able to edit your post to ensure the correct formatting of the code to help us understand it easier.
Thanks and regards
Seán