Validate relationship when modifying link in the backend implementation

Hi there,

We’re implementing a custom Backend to modify the links of relationships by extending the AbstractLinkOperation.
I wonder how we can validate the upper limit and link constraint of every link that has been modified. Currently, it’s possible to add the duplicated links:

I found RelationshipLinkOperationValidator but it’s in internal stuff and used for RPC only.
Is there any public API support to validate the links?

A12 versions

a12BaseVersion=27.1.0
a12UaaVersion=7.5.1
a12KernelVersion=28.5.1
a12FormEngineVersion=36.7.2
a12DataServicesVersion=36.3.7

Best regards,
Nhat.

Hi @nhat-round-cloud

Can I check a few details of your use-case with you?

In your picture, we see two unique “Licence Plates”, Abc-567 and Abc-123. Do these entries represent:

  1. Two Documents with two links to Abc-123 and three links to Abc-567? This would mean that “Duplicable” has been selected in the Relationship Model
    or
  2. Five different Documents each with a Single Link which do not have unique values for “Licence Plate”?

If it is the first case, would it be sufficient to remove the “Duplicable” flag from the Relationship Model?

Hi @malcolm-silver-ice ,
Licence Plates is the field of Vehicle entity and we have a binding to assign the Vehicle for the Contract.


As you can see in the image above, I have only 2 Vehicles in my application but I can create 5 relationships between Contract and Vehicle…
Document graph response:
scratch_17.json (6.2 KB)

My model unchecked the duplicatable:

My implementation:

@Component
public class RelationshipLinkService extends AbstractLinkOperation {

	public RelationshipLinkSpec createLink(LinkDescriptor linkDescriptor,
	                                       RelationshipModel relationshipModel,
	                                       DocumentReference linkDocRef) {
		return super.createLink(linkDescriptor, relationshipModel, linkDocRef);
	}

	public RelationshipModel loadRelationshipModel(String relationshipModelName) {
		return super.loadRelationshipModel(relationshipModelName);
	}

	public void deleteLinkDocument(RelationshipLinkSpec relationshipLinkSpec) {
		String relationshipModelName = relationshipLinkSpec.getLinkDescriptor().getRelationshipModel();
		RelationshipModel relationshipModel = this.loadRelationshipModel(relationshipModelName);
		RelationshipLink linkToDelete = relationshipLinkLoader.loadLink(this.parseLinkId(relationshipLinkSpec.getId()));
		relationshipLinkPersister.deleteLink(linkToDelete, relationshipModel);
//		super.deleteLinkDocument(linkToDelete.getLinkDocumentDocRef());
	}
}

I’m using the implementation of A12 w/o customizing.

Regards,
Nhat.

Hello @nhat-round-cloud,

Firstly, could you please check if the custom can be done via Relationship Events.

If that is not the case, as far as I checked in the code, the “upper limit” validation seems to happen in JsonRpcOperationDispatcher > RelationshipLinkOperationValidator

Could you please check if those logic are in place?

Cheers,
Loi

Hi @lvluu,
Yes, that’s my concern. I would avoid using the internal stuff as much as possible.
If I copy the logic from dataservices then it costs time when upgrading.
I’m wondering why the relationship stuff didn’t have any public Java API. And besides that, the validator only supports for RPC Operations instead of Services

Hi @nhat-round-cloud, the relationship validation will be executed after all operations in rpc request are complete, all you need to make this validation also applies on your custom operation is publishing RelationshipLinkAfterCreateEvent after link is created.

Hi @loc-fleet-crest ,
Unfortunately, we’re using the Camunda process, and a task handler will be executed to Modify the links for some entities. That’s why the RPC operation is not called…

Best regards!

Hello @nhat-round-cloud,

for your information regarding the relationship public API, DS does provide it via new RelationshipLinkService; however, it’s only since the 2024.06 release.

Hi @loi-risen-dale
Thanks for your info!
We will consider it in the next version…

Kind regards!

Hi @nhat-round-cloud,

Two remarks from my side:

  • The fact that you’re using Camunda/Workflows should not prevent you from calling the RPC operations. In fact, all out of the box delegates call RPC operations.
  • In 2024.06-ext (Oct), A12WF will provide out of the box delegates for modifying links.

Hi @peter-smooth-cursor ,

Thanks for your info!

  1. Does that mean we need to build RPC requests in the backend to call the RPC Dispatcher?
  2. Unfortunately, we’re using a standalone Camunda application w/o A12WF…

Regards.

Hi @nhat-round-cloud,

Have a look at the Data Services clients documentation. It’s indeed a little hard to find but what we use is the RequestBuilderFactory and RpcOperationsClient from dataservices-client dependency.

We have a little code snippet in our own docs regarding how we use it, see here.

Hope it helps!