Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Excerpt
An example Webhook consumer service set up using Java and Spring Boot for the validation of object properties using catalogs.


Section
bordertrue


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
languagejava
titleController 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;
    }
}

Creating the Validation Service for Incoming Metadata

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
languagejava
titleHookException
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
titleWebhook 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
iconfalse

Read on

Section


Column
width25%

CATALOG Service

Insert excerpt
CATALOG Service
CATALOG Service
nopaneltrue
 Keep reading


Column
width25%

systemHookConfiguration.json

Insert excerpt
systemHookConfiguration.json
systemHookConfiguration.json
nopaneltrue
 Keep reading


Column
width25%

Webhooks

Insert excerpt
Webhooks
Webhooks
nopaneltrue
 Keep reading



...