Remove/ change target/source of asset relation
Hi,
I’m a newer to Collibra workflow designer.
I tried to build a workflow in order to change target of existed relation
Refer to suggest approach in https://datacitizens.collibra.com/forum/t/change-relationship-in-workflow/3618/5, I tried to delete a wrong relation and add a new relation with list of assets (which are collected from start form )
The workflow has not worked correctly.
Although the new relation was added, the existed relation wasn’t deleted.
At first, I tried to reverse the relation in order to remove the source, but it still doesn’t work.
My script as below:
//1. Delete existed relation
relationApi.removeRelation(UUID.fromString(relatedsystemsTypeUuid))
//2. Add new relation
addRelationsWithOneSourceAndMultipleTargetsToAsset(item.getId(),relatedsystemsTypeUuid,relatedsystems)
def addRelationsWithOneSourceAndMultipleTargetsToAsset(sourceUuid,relationTypeUuid,targetUuidList) {
if (targetUuidList == null){return;}
def addRelationsRequests = []
loggerApi.info("Source: " + sourceUuid.toString())
loggerApi.info("Type: " + relationTypeUuid.toString())
loggerApi.info("Target: " + targetUuidList.toString())
loggerApi.info(“Target Class” + targetUuidList.getClass().toString())
targetUuidList.each{ t -> loggerApi.info(“T Class” + t.getClass().toString())
addRelationsRequests.add(AddRelationRequest.builder()
.sourceId(sourceUuid)
.targetId(t)
.typeId(string2Uuid(relationTypeUuid))
.build())
}
relationApi.addRelations(addRelationsRequests)
}
Note:
relatedsystems : list of related Assets collected from start form
relatedsystemsTypeUuid - Relation type Id which is identified in start form
huongtran_thu
OP2 years ago · EditedHi Stefan,
Refer to https://techcombank-dev.collibra.com/docs/javav2/com/collibra/dgc/core/api/dto/instance/relation/FindRelationsRequest.html, there are methods to search for target Uuid, Source Uuid and relation type Uuid.
I can not find any method to get relation Uuid
Could you suggest a specific scrip task for this case ?
Thanks
huongtran_thu
OP2 years ago · EditedHi Stefan,
Refer to https://techcombank-dev.collibra.com/docs/javav2/com/collibra/dgc/core/api/dto/instance/relation/FindRelationsRequest.html, there are methods to search for target Uuid, Source Uuid and relation type Uuid.
I can not find any method to get relation Uuid
Could you suggest a specific scrip task for this case ?
Thanks
stefan_busch
·2 years ago · EditedHi,
you will need this from the RelationApi:
As input you will give it the FindRelationRequest from the link you posted and as return value you will get a CursorPagedResponse object which stores relation objects.
On the CursorPagedResponse object you can just call getResults() to get the stored relations as a list (technically you will only get the first 1000 entries of the FindRelationRequest but that is no issue in this case).
For each relation in the relation list you get from getResults(), you can call .getId() to get the UUID of the relation.
Bringing it all together would look like this:
FindRelationsRequest findRelationsRequest = FindRelationsRequest.builder().sourceId(sourceUuid).targetId(targetUuid).relationTypeId(relationTypeUuid).build();
request = relationApi.findRelations(findRelationsRequest);
for(relation in request.getResults()) {
relationId = relation.getId(); //<-- this is the UUID of the relation between the asssets sourceUuid and targetUuid with the type relationTypeUuid
}
of course for this to work the relation has to exist otherwise the request.getResults() will return an empty list.
stefan_busch
·2 years ago · EditedHi,
the reason why this is probably not working is that you try to call the removeRelation Method with relatedsystemsTypeUuid because this is only the UUID of the type of the relation and not the UUID of the relation between the two assets. If you add a relation like here
you actually get a return object of type Relation. On this return object you can call the method getId() to get the UUID of the newly created relation. With this id as input you could call
to remove it.
huongtran_thu
OP2 years ago · EditedHi Stefan,
Thanks for your reply. I understand your approach but I don’t know how to get relation UUID of current asset.
In my case, relatedsystemsTypeUuid is created in separate workflow.
It is Resource ID in a relation “Code set is contained in System”
Refer to https://productresources.collibra.com/docs/collibra/latest/Content/Assets/Characteristics/Relations/RelationTypes/ta_find-resource-id-relation-type.htm
stefan_busch
·2 years ago · EditedHi Huong,
in this case you would first need to find the relation via a FindRelationRequest and the relationAPI.
There you can specify the asset id and the relation type id.