The "groovy-lib" folder
The groovy-lib folder is a specific directory in your Collibra environment customization files that allows you to deploy and share Groovy scripts across multiple workflow processes.
By placing Groovy scripts in this folder, you can create custom libraries and helper classes that are accessible to any workflow script task. This promotes code reusability, simplifies maintenance, and helps to enforce consistent behavior in your workflows:
- Reusability
- Write a function once and call it from any workflow. This saves time and reduces the chance of errors.
- Maintainability
- Update a script in one place, and the changes are automatically reflected in all workflows that use it.
- Consistency
- Ensure that common tasks, such as sending notifications or integrating with an external system, are performed in the same way everywhere.
- Simplicity
- Keep your workflow definitions cleaner and more focused on the business process by moving complex code logic into external libraries.
When to use the "groovy-lib" folder
You should use the groovy-lib folder when you have Groovy code that you want to reuse across different workflows or when you want to separate complex logic from your business process definitions. Some examples include:
- Utility classes with helper methods for string manipulation, date calculations, or API interactions.
- Standardized methods for logging or error handling.
- Connectors for integrating with external systems.
For code that is specific to a single workflow and not intended for reuse, you can continue to write it directly in the workflow script tasks. The core value of the groovy-lib folder is to store scripts that are common to a large number of tasks.
Uploading scripts to the "groovy-lib" folder
To get started with the groovy-lib folder, use the console export file mechanism to add a customization package to Collibra. The workflow engine automatically makes any GROOVY files from the groovy-lib available in your workflow scripts.
- Create a console export file with customizations.
- Open Collibra Console with a user profile that has at least the ADMIN role.
Collibra Console opens with the Infrastructure page.
- In the main menu, click Console Export Files.
The Console Export Files page appears.
- Above the table, to the right, click Create Console Export File.
- In the Create Console Export File dialog box, enter the required information:
- Environment
- The Collibra environment for which to create an export file.
- Customizations
- This ensures that if there is a groovy-lib folder it gets downloaded and allows you to upload a new or modified one.
The configuration is always included in export files for consistency and reliability.
- Click Create Export File.
- Open Collibra Console with a user profile that has at least the ADMIN role.
- Once Collibra finishes processing the file, download it.
- Extract the contents of the archive.
- Add your Groovy scripts to dgc → groovy-lib.
If this folder structure does not exist, create it.
- Go to the containing directory of the extracted files, select all of them, and add then to a ZIP archive.
Do not archive the containing directory. Select only the individual files and directories to have the same structure as the original ZIP file.
- Upload ZIP archive to your Collibra environment:
- Open Collibra Console with a user profile that has at least the ADMIN role.
Collibra Console opens with the Infrastructure page.
- In the main menu, click Console Export Files.
The Console Export Files page appears.
- Above the table, to the right, click Upload Console Export File.
- In the Upload Console Export File dialog box, enter the required information:
- Not password protected
- The option to choose for new console export files.
- Retain for
- The retention period for the export file, after which the file is automatically removed.
- Select the ZIP archive you created.
The upload starts automatically.
- Open Collibra Console with a user profile that has at least the ADMIN role.
- Once the upload finishes, apply the console export file:
- In the row of the export file you have uploaded, click
Apply Restore. - In the Applying console export file dialog box, enter the required information:
- Environment
- The Collibra environment where you want to apply the export file.
- Export
- The export file you have uploaded.
- Customizations
- This ensures that the groovy-lib folder and your reusable scripts get applied.
- Click Apply console export file.
The console export file is applied to the selected environment. The time to apply an export file depends on the amount of data it contains. During this time, your environment is unavailable. The process is complete when all services in your environment have the running status again.
- In the row of the export file you have uploaded, click
Using the "groovy-lib" folder
If you use the groovy-lib mechanism to create reusable functions across workflows, consider that by default, the entire content of the groovy-lib folder is included in each script task before compilation. Since compilation time increases with the number of lines of code, including unused reusable functions can negatively affect performance.
To mitigate this issue, enable the Don’t attach Groovy libs by default option in Collibra Console. For scripts that require reusable functions, explicitly add a // #importFile statement at the beginning of the script to load the relevant files:
// #importFile resourcePrinter.groovy
// #importFile processDetailsPrinter.groovy
Rules for using #importFile:
- The
#importFilestatement must be the first line in the script, even before the imports section. Any whitespace character at the beginning of the script is ignored. - Whitespace characters are allowed before and after
//. - There cannot be any whitespace character between
#andimportFile. - Whitespace characters are allowed between
#importFileand the Groovy file name. - If a referenced Groovy file is not found in the groovy-lib folder, it is silently ignored.