In this article, I will show you how to create a custom connector to upload files and create folders from Bonita into Google Drive.
We want this connector to be able to upload one, or multiple, documents to a Google Drive, and we would also like to have the option to create a new folder to upload the documents into.
Let's note here that this document upload could be done via a series of REST connectors - but we're suggested to do it via a custom connector instead. The big advantage of doing a custom connector is that it's easier to reuse it wherever you want it to.
Configure a custom connector with project composition feature in Bonita Studio using the wizard in the desired task of the process.
One of the benefits of creating a custom connector is that a process developer can simply use the project composition in Bonita Studio, to integrate the connector and configure it easily using the wizard in the desired task of the process.
The input for the connector configuration will be
-
the DriveID in which to upload the files/create the folder
-
the documents to upload
-
the name of the folder if we want to create one
-
the credentials required to authenticate.
As output, we will have the name(s) of the file(s) uploaded, plus the link to access them.
Use the Bonita Connector Maven Archetype
Here you can follow the Bonita Documentation that explains the necessary steps:
-
Generate the project using the archetype
-
Leave the connector implementation as it is, since it already has all the required information
-
Define the connector as indicated in the documentation, with the following data:
<ul> <li aria-level="2" dir="ltr"> <p dir="ltr" role="presentation"><strong>Inputs </strong>(as required):</p> <ul> <li aria-level="3" dir="ltr"> <p dir="ltr" role="presentation"><strong>Name</strong>: driveID, <strong>type</strong>: String, <strong>mandatory </strong>= true</p> </li> <li aria-level="3" dir="ltr"> <p dir="ltr" role="presentation"><strong>Name</strong>: folderName, <strong>type</strong>: String, <strong>mandatory </strong>= false</p> </li> <li aria-level="3" dir="ltr"> <p dir="ltr" role="presentation"><strong>Name</strong>: attachments, <strong>type</strong>: List, <strong>mandatory </strong>= true</p> </li> <li aria-level="3" dir="ltr"> <p dir="ltr" role="presentation"><strong>Name</strong>: credentialsJSON, <strong>type</strong>: String, <strong>mandatory </strong>= true</p> </li> <li aria-level="3" dir="ltr"> <p dir="ltr" role="presentation"><strong>Name</strong>: createFolder, <strong>type</strong>: String, <strong>mandatory </strong>= true</p> </li> </ul> </li> <li aria-level="2" dir="ltr"> <p dir="ltr" role="presentation"><strong>Wizard pages</strong>:</p> <ul> <li aria-level="3" dir="ltr"> <p dir="ltr" role="presentation">Authentication: to specify the driveID and credentials</p> </li> <li aria-level="3" dir="ltr"> <p dir="ltr" role="presentation">Upload Configuration: option to create folder, name of the folder and the files to upload</p> </li> </ul> </li> <li aria-level="2" dir="ltr"> <p dir="ltr" role="presentation"><strong>Output</strong>:</p> <ul> <li aria-level="3" dir="ltr"> <p dir="ltr" role="presentation"><strong>Name</strong>: createdFileList, <strong>type</strong>: List</p> </li> <li aria-level="3" dir="ltr"> <p dir="ltr" role="presentation"><strong>Name</strong>: createdFolderID, <strong>type</strong>: String</p> </li> </ul> </li> </ul> </li>
Develop the business logic
Now, add the business logic of the connector in the project.
Create a library to include the main functions (connect to drive, create folder, upload files, read folder and delete folder) using the Google Drive v3 API. This library, gDriveUtils, will be in the same project as the connector.
Next step is to retrieve and validate all input parameters. You can use the proposed scripts to validate that the mandatory inputs are the correct type and are not empty.
Another important step will be to add a function to retrieve the case documents in Bonita. For this, use the Bonita Engine API.
And then add the complete business logic using our inputs, validations and functions.
Add Unit Tests
Add unit tests here. For this, you can use the Mockito framework to create the dummy elements that are needed (Bonita Process API, Documents to upload, etc.)
We also suggest adding a cleanup section to delete all files and folders created for the test.
Publish in a public repository
Use Github Actions to publish this extension in a private Maven repository, so it will be accessible to be uploaded in Bonita Studio.
Of course other automatization means can be used as well (Jenkins, Bamboo, etc), or this extension can be published and distributed manually.
Source code of the developed custom connector
The source code of the connector we developed for this demo can be found in the Bonita Community Projects section here.