[resolved] How to empty process' attachments (documents)

1
0
-1

Hi all,

In my process, documents are attached using variables of Document type and the Upload Widget for uploading documents to forms.
At the end of the process, there is no need to keep the exchanged documents.
How could I remove them from the database?

I have tried the above groovy script:
def d = apiAccessor.getProcessAPI().removeDocument(myFile.getId());
apiAccessor.getProcessAPI().deleteContentOfArchivedDocument(d.getId());

but, I am getting the error
Unable to delete the document .... because it does not exists
I also tried to use the Rest Delete connector, but i am getting 401 Unauthorized status, even admin's credentials.

Also, could you verify that the content of the documents is kept only in the CONTENT row of the DOCUMENT table;

I am using Bonita Community 7.5.4

Thanks in advance.

3 answers

1
0
-1
This one is the BEST answer!

I have created two different groovy scripts:

  1. archiveDocuments
    import org.bonitasoft.engine.bpm.document.ArchivedDocument;
    import org.bonitasoft.engine.bpm.document.DocumentException;
    import org.bonitasoft.engine.bpm.document.DocumentNotFoundException;
    import org.bonitasoft.engine.bpm.document.DocumentValue
    import org.bonitasoft.engine.bpm.document.Document
    import org.bonitasoft.engine.exception.DeletionException;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.bonitasoft.engine.bpm.document.ArchivedDocumentsSearchDescriptor;
    import org.bonitasoft.engine.bpm.document.DocumentException;
    import org.bonitasoft.engine.bpm.document.DocumentNotFoundException;
    import org.bonitasoft.engine.search.SearchOptions;
    import org.bonitasoft.engine.search.SearchOptionsBuilder;
    import org.bonitasoft.engine.search.SearchResult;
    Logger logger = LoggerFactory.getLogger("org.bonitasoft.groovy.emptyDocumentParamenters()");
    try {
    // archive and delete mapping on the document with the specified identifier
    Document deleted = apiAccessor.getProcessAPI().removeDocument(doc.getId());
    return deleted
    } catch (DocumentNotFoundException e) {
    logger.error("The identifier does not refer to any existing archived document: " + e.getMessage());
    } catch (DeletionException e) {
    logger.error("An error occured: "+ e.getMessage());
    }

  2. emptyArchivedDocuments
    import org.bonitasoft.engine.bpm.document.ArchivedDocument;
    import org.bonitasoft.engine.bpm.document.DocumentException;
    import org.bonitasoft.engine.bpm.document.DocumentNotFoundException;
    import org.bonitasoft.engine.bpm.document.DocumentValue
    import org.bonitasoft.engine.bpm.document.Document
    import org.bonitasoft.engine.exception.DeletionException;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.bonitasoft.engine.bpm.document.ArchivedDocumentsSearchDescriptor;
    import org.bonitasoft.engine.bpm.document.DocumentException;
    import org.bonitasoft.engine.bpm.document.DocumentNotFoundException;
    import org.bonitasoft.engine.search.SearchOptions;
    import org.bonitasoft.engine.search.SearchOptionsBuilder;
    import org.bonitasoft.engine.search.SearchResult;
    Logger logger = LoggerFactory.getLogger("org.bonitasoft.groovy.emptyDocumentParamenters()");
    // remove content for every archived document
    try {
    // get all archived documents of the process
    SearchOptions searchOptions = new SearchOptionsBuilder(0, 1000)
    .filter(ArchivedDocumentsSearchDescriptor.PROCESSINSTANCE_ID, processInstanceId)
    .done();
    SearchResult<ArchivedDocument> archivedDocumentsOfProccess = apiAccessor.getProcessAPI().searchArchivedDocuments(searchOptions);
    archivedDocumentsOfProccess.getResult().each() {
    // empty the content of the archive document
    apiAccessor.getProcessAPI().deleteContentOfArchivedDocument(it.getId());
    }
    } catch (DocumentNotFoundException e) {
    logger.error("The identifier does not refer to any existing archived document: " + e.getMessage());
    } catch (DocumentException e) {
    logger.error("An error occured: "+ e.getMessage());
    }

    Please, do suggest a better solution. And please comment why running the above in one groovy script doesnot work.

1
0
-1

1
0
-1

put a script before the process end with this script

import org.bonitasoft.engine.bpm.document.DocumentValue
import org.bonitasoft.engine.bpm.document.Document

Document currentDocument = apiAccessor.processAPI.getLastDocument(processInstanceId, "doc")
long documentId = currentDocument.getId();
Document deleteFile=apiAccessor.processAPI.removeDocument(documentId);

Comments

Submitted by mtsiak_1358773 on Fri, 05/25/2018 - 15:18

Thank you for your reply.
I am testing the fucntionality in H2 database, and the
SELECT * FROM DOCUMENT;
still contains the document and the content.

I further added:
apiAccessor.processAPI.deleteContentOfArchivedDocument(documentId)
only to get the ArchivedDocumentNotFound Exception, which could be partially be true, as the ARCH_DOCUMENT_MAPPING table has no data.

Also the documentation
https://documentation.bonitasoft.com/bonita/7.6/documents

suggests the use of a CMS. As we are using Alfresco, how can i avoid the documents been written in the database;
I tested cmis connectors with success (as alfresco connectors refer to a pretty old alfresco version), but this works after the document parameter is set, that means that the document has been added to DOCUMENT table.

Submitted by dkoume_1353153 on Fri, 05/25/2018 - 15:43

You are searching for archived document but your case is still open.
Theremore you dont need to save the document to the database.Bonita stored the document as a resource in a Bonita document repository.

Submitted by mtsiak_1358773 on Tue, 05/29/2018 - 07:51

ok.. an how can i remove this document resource?

Also in the removeDocument it is documented that
* Remove the document with the specified identifier and returns it.
* this archive and delete mapping on the process, i.e. the content of the document itself will be kept in database, use
* {@link #deleteContentOfArchivedDocument} to delete the content

But as stated above, when using deleteContentOfArchivedDocument returns Unable to delete the document .... because it does not exists.

Thank tou again for your replies.

Submitted by mtsiak_1358773 on Tue, 05/29/2018 - 13:30

how do i get the correct id for the method:
apiAccessor.getProcessAPI().deleteContentOfArchivedDocument(id);

Notifications