How to validate data records against the master storage through the REST API

EnrichVersion
6.4
EnrichProdName
Talend MDM Platform
Talend Data Fabric
task
Data Governance > Validating data
EnrichPlatform
Talend MDM Server
Talend Studio

How to validate data records against the master storage through the REST API

An MDM REST interface is available to allow you to validate data records against the master storage through the REST API.

Before saved to the master database, a data record has to go through a validation process, which involves checking the data record against the database schema, foreign key constraints, validation rules and the Before-Saving process (if any) defined in the entity that the data record pertains to.

This article applies to Talend products with MDM 6.2.0 and above.

Validate data records

Validate one or more records against the master storage without creating new data or modifying the existing data.

Request

POST /data/{containerName}/validate

Request URL

http://{serverurl}/talendmdm/services/rest/data/{containerName}/validate?container={containerType}

Query parameters

  • containerName: This is a String value which specifies the name of the data container against which you want to validate data record(s).
  • containerType: This is a String value which represents the type of the data container. It is either ‘MASTER’ (default) or ‘STAGING’.
  • returnSource: This is a Boolean value which indicates whether to include the sent records within the response. By default, it is false.
  • beforeSaving: This is a Boolean value which indicates whether to bypass the beforeSaving process associated with the record(s) during validation. By default, it is true. The data validation operation should be an immutable action, and thus you are allowed to disable the check against the beforeSaving process which in some cases may modify the data.

Request Body

An XML representation of the new data record you want to use to replace the existing one.

The id element(s) in the request body determine which record is to be updated.

Headers

  • Content-Type: application/xml
  • Authorization: Basic Authentication scheme
  • Accept: application/xml or application/json. The Accept header tells the server to return either JSON or XML content. By default, the result is returned in JSON format.

Response Body

A list of the validation results for each record (either in XML or in JSON format) containing the validity status, a message that can be empty or the reason why the data record is invalid, and optionally the sent record(s) as an echo.

For example:

<results>
    <result>
        <isValid>true</isValid>
        <message></message>
        <sourceXml>
            <ProductFamily>
                <Id>1</Id>
                <Name>Literature</Name>
                <ChangeStatus>Approved</ChangeStatus>
            </ProductFamily>
        </sourceXml>
    </result>
    <result>
        <isValid>false</isValid>
        <message>[Error] :-1:-1: cvc-enumeration-valid: Value 'Unknown' is not facet-valid with respect to enumeration '[Pending Rejected Approved]'. It must be a value from the enumeration. [Error] :-1:-1: cvc-type.3.1.3: The value 'Unknown' of element 'ChangeStatus' is not valid.
        </message>
        <sourceXml>
            <ProductFamily>
                <Id>2</Id>
                <Name>Comics</Name>
                <ChangeStatus>Unknown</ChangeStatus>
            </ProductFamily>
        </sourceXml>
    </result>
</results>

Response Code

200 - If the validation operation is executed successfully, this status code is returned whatever the result(s) of the validation.

How to validate a data record through the REST API using a Job

The following example shows how to use a Talend Job to validate a data record through the REST API and print out the response message accordingly.

The Job is composed of two components: tREST and tJavaRow:

  • tREST is used to send the HTTP request and get the response correspondingly.
  • tJavaRow is used to print out the response.

Retrieve the Job file tREST.zip from the Downloads tab in the left panel of this page.

Before you begin

  • The MDM server is up and running.
  • You have already launched Talend Studio.
  • You have already imported the MDM Demo Project.

Procedure

  1. From the Palette, drop two components tREST and tRESTon the workspace.
  2. Connect tREST to tREST using a Row > Main link.
  3. Double-click tREST to open its Basic settings tab.
  4. In the URL field, enter the URL to access the MDM REST API service.
    In this example, it is http://localhost:8180/talendmdm/services/rest/data/Product/validate.
  5. From the HTTP Method list, select POST.
  6. Click the [+] button to add two lines in the HTTP Headers area to describe the content type of the HTTP request and specify the authorization information.
    In this example, provide the following name/value pairs:
    name value

    "Content-Type"

    "application/xml"

    "Authorization"

    "Basic YWRtaW5pc3RyYXRvcjphZG1pbmlzdHJhdG9y"

  7. In the HTTP Body area, enter the data record you want to validate against the master storage in XML format.
    In this example, the <root> element is used to enclose the data record.
  8. Double-click tJavaRow to open its Basic settings tab.
  9. In the Code area, enter your customized code.
    For example:
    System.out.println("\n##### An invalid record example #####\n");
    System.out.println(restResponse_tREST_1);
  10. Save and execute the Job.
    Since no Accept header is specified, the response returns the JSON content. The response shows that the data record is not valid and gives a message about why the data record did not pass the validation.