Preprocessing Metadata using Webhooks

An example Webhook consumer service set up using Java and Spring Boot. 

Table of Contents

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. 

Setting up the Consumer Service

To implement processing of incoming update metadata using our webhook service, we need to configure an endpoint within a controller class of our Example Webhook Service, in this instance ExampleRestController. The URL we define between the RequestMapping annotation of the controller class and the PostMapping annotation of the endpoint method will need to find its way into the system hook configuration of our yuuvis® Momentum system. We will also define a stub method for working with the incoming metadata, which we will call from within our endpoint method, the object map provided by the system hook. 

Controller Class with Endpoint for Webhook Consumption
@RestController
@RequestMapping("/api/dms/request")
public class ExampleRestController
{
    @PostMapping(value = "/update/metadata", produces = {"application/json"})
    public Map<String, Object> updateDmsObjectMetadata(@RequestBody Map<String, Object> dmsApiObjectList, 
                                                       @RequestHeader(value = "Authorization", required = true) String authorization)
    {
        doSomething(dmsApiObjectList, authorization);
        return dmsApiObjectList;
    }
    private void doSomething(Map<String, Object> dmsApiObjectList, String authorization)
    {
        // do something with the metadata
    }
}

Configuring the Webhook

To use the webhook service for the intended purpose of intercepting metadata when updating objects, we need to create a new entry in the Webhook list within our systems' systemHookConfiguration.json file (\system\systemHookConfiguration.json ). The url attribute must refer to the webhook service identifier (derived from the artifact ID in the services' maven file) and direct to one of the endpoints declared in the service.

The services responsible for the webhook execution need to be restarted after changing the systemHookConfiguration.json file. The corresponding services of each webhook are listed here. For the enrichment of metadata, the pertaining service would be the API-gateway. 

Example SystemHookConfiguration.json
{
  "systemhooks": {
    "webhooks": [
      {
        "enable": true,
        "predicate": "spel:true",
        "type": "dms.request.update.metadata",
        "url": "<protocol>://<webhook service identifier>/api/dms/request/update/metadata",
        "useDiscovery": true
      }
    ]
  }
}

Summary

In this tutorial, a Java-based method for webhook consumption is outlined. The code presented, including the project structure and additional webhook management, can be found in github. More concrete example webhook use cases are described in the articles linked below.


Read on

Accessing Binary Content during an Import

Access binary content files via webhooks during the import process. Keep reading

Validation of Properties using Catalogs

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

Webhooks

A system hook that extends a function call by an HTTP call under defined conditions. Keep reading