Developing a custom connector for Google Drive integration

alejandro.rondon_1386485's picture
alejandro.rondon_1386485

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:

    • Inputs (as required):

      • Name: driveID, type: String, mandatory = true

      • Name: folderName, type: String, mandatory = false

      • Name: attachments, type: List, mandatory = true

      • Name: credentialsJSON, type: String, mandatory = true

      • Name: createFolder, type: String, mandatory = true

    • Wizard pages:

      • Authentication: to specify the driveID and credentials

      • Upload Configuration: option to create folder, name of the folder and the files to upload

    • Output:

      • Name: createdFileList, type: List

      • Name: createdFolderID, type: String

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.

Notifications