Introduction to builders
In this tutorial you learn how to configure automated tasks inside workflows by using scripts and builders. Builders perform multiple steps to create and configure objects via the build()
method and return the fully constructed object. You will create a new asset, add attributes to the asset and modify the asset status.
Prerequisites
- Access to the Workflow Designer for designing the workflow.
- Access to a Collibra environment as a user with the Sysadmin global role or a global role that has at least the Workflow Administration global permission for configuring the workflow.
- Optionally, access to the Collibra Console for troubleshooting.
Accessing the Collibra API documentation
- In your Collibra Platform environment, click
in the upper-right corner.
- Select API documentation.
- On the API documentation page, select the Java Core API.
Working with the Collibra Java API builders
All the supported asset related operations are listed under the AssetApi interface in the Collibra Java API documentation.
In the context of workflow script tasks, the <Resource>Api interfaces (such as AssetApi, CommunityTypeApi, FileApi, and so on) are already instantiated and accessible via <resource>Api variables (such as assetApi, communityTypeApi, fileApi, and so on).
The API makes use of universally unique identifiers (UUIDs) to find resources in Collibra Platform. There are several ways of retrieving the UUID of a resource as mentioned in the Finding resource IDs section of the Collibra Documentation. The easiest way to retrieve the UUID is from the URL of a resource:
https://<your_collibra_url>/<resource type>/00000000-0000-0000-0001-000100000001
In Collibra Java API v2, the UUID is provided as a string via the string2Uuid()
helper method.
Before referring to any class, you must first have a reference to their packages. You resolve class references via the import
statement.
Because each script task is independent, include import
statements for all the packages you are using in a script for each script task. Avoid using generic imports to reduce execution time.
Create a new asset
To create a new asset, use the addAsset()
method which requires an AddAssetRequest
parameter. The AddAssetRequest class has a builder()
method available.
- Class: AssetApi
- Main method: AddAsset()
- Parameter and builder method: AddAssetRequest.builder()
- Main method: AddAsset()
Builder parameters | Mandatory | Type | Description |
---|---|---|---|
name() | Yes | String | Sets the name of the asset. |
typeId() | Yes | UUID | Sets the asset type. Use the string2Uuid() helper method. |
domainId() | Yes | UUID | Places the asset inside the domain. Use the string2Uuid() helper method. |
build() | Yes | Builds the object. | |
displayName() | No | String | Sets the display name of the asset. By default the display name is the same as the name. |
id() | No | UUID | Sets the id of the asset. Use the string2Uuid() helper method. |
status() | No | UUID | Sets the status of the asset. Use the string2Uuid() helper method. |
import com.collibra.dgc.core.api.dto.instance.asset.AddAssetRequest
assetApi.addAsset(AddAssetRequest.builder()
.name("DGC")
.typeId(string2Uuid("00000000-0000-0000-0000-000000011003"))
.domainId(string2Uuid("00000000-0000-0000-0000-000000006013"))
.build()
);
The command works for the out-of-the-box New Business Terms domain and Acronym asset type.
Add attributes to an asset
To add attributes to an asset, use the setAssetAttributes()
method which requires a SetAssetAttributesRequest
parameter. The SetAssetAttributesRequest class has a builder()
method available.
- Class: AssetApi
- Main method: setAssetAttributes()
- Parameter and builder method: SetAssetAttributesRequest.builder()
- Main method: setAssetAttributes()
Builder parameters | Mandatory | Type | Description |
---|---|---|---|
assetId() | Yes | UUID | Identifies the asset. Use the string2Uuid() helper method. |
typeId() | Yes | UUID | Sets the attribute type. Use the string2Uuid() helper method. |
values() | Yes | list | Sets the value or values of the attribute. |
build() | Yes | Builds the object. |
import com.collibra.dgc.core.api.dto.instance.asset.SetAssetAttributesRequest
assetApi.setAssetAttributes(SetAssetAttributesRequest.builder()
.assetId(
string2Uuid("1b2f8eb4-4f13-4cd2-a238-9a7d9666a93a")
)
.typeId(
string2Uuid("00000000-0000-0000-0000-000000000202")
)
.values(["Data Governance Center"])
.build()
);
The command sets the definition of the asset to Data Governance Center. The command does not work unless you replace the asset UUID with a valid one.
Modify an asset
To modify an asset, use the changeAsset()
method which requires a changeAssetRequest
parameter. The changeAssetRequest class has a builder()
method available.
- Class: AssetApi
- Main method: changeAsset()
- Parameter and builder method: ChangeAssetRequest.builder()
- Main method: changeAsset()
Builder parameters | Mandatory | Type | Description |
---|---|---|---|
id() | Yes | UUID | Identifies the asset. Use the string2Uuid() helper method. |
displayName() | Select at least one | String | Changes the display name of the asset. |
domainId() | Select at least one | UUID | Moves the asset to the domain. Use the string2Uuid() helper method. |
name() | Select at least one | String | Changes the name of the asset. |
statusId() | Select at least one | UUID | Changes the status of the asset. Use the string2Uuid() helper method. |
typeId() | Select at least one | UUID | Changes the asset type. Use the string2Uuid() helper method. |
build() | Yes | Builds the object. |
import com.collibra.dgc.core.api.dto.instance.asset.ChangeAssetRequest
assetApi.changeAsset(ChangeAssetRequest.builder()
.id(
string2Uuid("1b2f8eb4-4f13-4cd2-a238-9a7d9666a93a")
)
.statusId(
string2Uuid("00000000-0000-0000-0000-000000005009")
)
.build()
);
The command changes the status of the asset to Approved. The command does not work unless you replace the asset UUID with a valid one.
Multiple operations
This example creates a new acronym GDPR in the out-of-the-box New Business Terms domain, adds a description and changes the status to Approved.
import com.collibra.dgc.core.api.dto.instance.asset.AddAssetRequest
import com.collibra.dgc.core.api.dto.instance.asset.ChangeAssetRequest
import com.collibra.dgc.core.api.dto.instance.asset.SetAssetAttributesRequest
import com.collibra.dgc.core.api.model.instance.Asset
Asset GDPR = assetApi.addAsset(AddAssetRequest.builder()
.name("GDPR")
.typeId(
string2Uuid("00000000-0000-0000-0000-000000011003")
)
.domainId(
string2Uuid("00000000-0000-0000-0000-000000006013")
)
.build()
);
assetApi.setAssetAttributes(SetAssetAttributesRequest.builder()
.assetId(GDPR.getId())
.values(["General Data Protection Regulation"])
.typeId(
string2Uuid("00000000-0000-0000-0000-000000000202")
)
.build()
);
assetApi.changeAsset(ChangeAssetRequest.builder()
.id(GDPR.getId())
.statusId(
string2Uuid("00000000-0000-0000-0000-000000005009")
)
.build()
);
Additional resources
- Read the Getting started with workflows Workflow Designer documentation section.
- Read the Using workflows Collibra Documentation section.
- Consult the Java API documentation: https://<your_collibra_url>/javadocs/javav2/index.html.