...
Excerpt |
---|
An example Webhook consumer service set up using Java and Spring Boot for the validation of object properties using catalogs. |
Section |
---|
|
Column |
---|
Table of Contents Table of Contents |
---|
exclude | (Table of Contents|Read on|systemHookConfiguration.json|Webhooks|CATALOG Service) |
---|
|
|
|
Introduction
For some properties of your DMS objects managed by yuuvis® Momentum, you might want to allow only certain string values that are defined in a catalog. One possible way to implement such a custom validation is the usage of a webhook dms.request.objects.upsert.database-before that is calling the CATALOG Service. In this tutorial, you will be guided through the set up of such an example webhook consumer service. It verifies that the value of a certain string property is contained in a specified catalog. Thus, this webhook service will provide an extra validation layer for object import and/or update.
Requirements
In this tutorial, we'll create a Spring Boot Service using Java, meaning the requirements for the project are derived from Spring Boot. Thus, a JDK version 1.8 or later and Maven 3.2 or later are required.
...
The object property which should be validated, must be defined in the global schema that is available in all tenants.
Setting up the Webhook Service
To implement the processing of incoming metadata using our example webhook service, we need to configure a controller class with the corresponding validation endpoint. In the example code block below, we define the class ValidationWebhookRestController
with the method validateObjectProperty
. The URL defined in the RequestMapping
annotation of the controller class and the PostMapping
annotation of the endpoint method will be referenced in the system hook configuration of our yuuvis® Momentum system as shown later in this article. We will also define the method propertyValidationService.validateObject
for working with the incoming metadata, which is called within our endpoint method.
Code Block |
---|
language | java |
---|
title | Controller Class with Endpoint for Webhook Consumption |
---|
|
@RestController
@RequestMapping("/api/dms/request")
public class ValidationWebhookRestController
{
@Autowired
private PropertyValidationService propertyValidationService;
@PostMapping(value = "/upsert", produces = {"application/json"})
public Map<String, Object> validateObjectProperty (@RequestBody Map<String, Object> dmsApiObjectList,
@RequestHeader(value = "Authorization", required = true) String authorization) throws HookException {
this.propertyValidationService.validateObject(dmsApiObjectList, authorization);
return dmsApiObjectList;
}
} |
This is the heart of our example webhook consumer service. Create the class propertyValidationService
and annotate it as @Service
. This indicates that it holds the business logic and will communicate with the REPOSITORY service.
...
Code Block |
---|
language | java |
---|
title | HookException |
---|
|
public class HookException extends Exception
{
private static final long serialVersionUID = 1L;
public HookException(String message)
{
super(message);
}
public HookException(String string, Throwable exception)
{
super(string,exception);
}
} |
Webhook System Configuration
In the systemHookConfiguration.json
file, add the following configuration (SpEL) and save it to the configuration server. In this configuration, we specify the type of our validation webhook dms.request.objects.database-before
and its URL http://validationWebhook/api/dms/request/upsert
. We also specify the predicate for triggering of the webhook. In this example, we want our webhook to be activated if an object is imported or updated that has the property "Name" assigned.
Code Block |
---|
title | Webhook Configuration |
---|
|
{
"enable": true,
"predicate": "spel:properties['Name']!=null && (properties['Name']['value'])!=null",
"type": "dms.request.objects.upsert.database-before",
"url": "http://validationWebhook/api/dms/request/upsert",
"useDiscovery": true
} |
Summary
In this tutorial we went through the steps of creating and configuring a webhook service for validating object properties using a catalog. Find the complete code project described in this tutorial in this GitHub Repository.
Info |
---|
|
Read on
Section |
---|
Column |
---|
| Insert excerpt |
---|
| CATALOG Service |
---|
| CATALOG Service |
---|
nopanel | true |
---|
| Keep reading
|
Column |
---|
| Insert excerpt |
---|
| systemHookConfiguration.json |
---|
| systemHookConfiguration.json |
---|
nopanel | true |
---|
| Keep reading
|
Column |
---|
| Insert excerpt |
---|
| Webhooks |
---|
| Webhooks |
---|
nopanel | true |
---|
| Keep reading
|
|
|
...