Home > Tutorial

Define Advanced Constraints

We just went through the definition of every elements corresponding to each table in the database. Our modelling task is not ended at this point, as we need to enrich the model with extended functionalities that XML Schema does not natively support.

Extended facets

XML Schema gives the opportunity to specify constraints (a.k.a. facets) on the schema elements. This gives the opportunity to implement business logic across the schema elements and ensure the coherence and integrity of the relationship between elements.
All extended facets are declared under a mdm:otherFacets element.

Integrity contraints

Learn MoreWe just learned how to implement the primary keys for all table type elements in our schema. A reference to a table (foreign key) is defined using the extended facet mdm:tableRef. This element is defined under the element xs:annotation/xs:appinfo/mdm:otherFacets.

As a child of the facet, we may specify:

  • container: reference of the instance that contains the table. Default is current instance.
  • tablePath: XPath expression that specifies the table (required)
  • labelPaths: XPath expressions that specify the composition of the label (default is the primary key)
  • displayKey: "true" or "false", specifies whether key is displayed as label prefix. Default is “true”.

Example: Ensure that element pub_id in table Titles refers to element pub_id in table Publishers.

<xs:element name="pub_id">
    <xs:annotation>
        <
xs:appinfo>
            <
mdm:otherFacets>
                <
mdm:tableRef>
                    <
tablePath>/root/Publishers</tablePath>
                    <
labelPath>/name</labelPath>
                    <
displayKey>true</displayKey>
                </mdm:tableRef
>
            </mdm:otherFacets
>
        </xs:appinfo
>
    </xs:annotation
>
    <xs:simpleType>
        <xs:restriction base="xs:string">
            <xs:maxLength value="4"/>
        </xs:restriction>
    </xs:simpleType>
</xs:element>

Dynamic contraints

We can easily specify that the value of element lo_range in table Royalties must be higher than 1:

<xs:element name="lo_rangeminOccurs="0">
    <xs:simpleType>
        <xs:restriction base="xs:int">
            <
xs:minInclusive value="1"/>
        </xs:restriction
>
    </xs:simpleType>
</xs:element>

However, this kind of constraint is static in the declaration, preventing to express constraints between elements.

Learn More webMethods MDM provides additional constraints that are not specified in XML Schema, i.e.dynamic constraints. A dynamic constraint is declared on an element, referencing another one, which is semantically linked with it. The two elements are then dynamically compared at runtime, and each time the constraint is breached, an error message is triggered.

Like any other extended facets, the constraint is declared within an xs:annotation/xs:appinfo/mdm:otherFacet element.
The mdm:otherFacet keeps the same semantic as the xs:restriction element used for static constraints:

  • the constraint type is not in the xs namespace anymore, but in the mdm namespace,
  • all constraints types have their equivalent (minInclusive, minExclusive, maxInclusive, maxExclusive, minLength, maxLength, length), depending on the element type.

Example: Ensure that lo_range value is always lower to hi_range value in the Royalties table.

We implement a dynamic constraint on the lo_range element, referencing the hi_range element.

<xs:element name="lo_rangetype="xs:intminOccurs="0">
    <xs:annotation>
        <
xs:appinfo>
            <
mdm:otherFacets>
                <
mdm:maxInclusive path="../hi_range"/>
            </mdm:otherFacets
>
        </xs:appinfo
>
    </xs:annotation
>
</xs:element>

As displayed in the following webMethods Master Data Manager screenshot, when the user Submit the values populated in the page, as the lo_range value is higher than the hi_range element, a default error message is raised (“the value is too big”).

The error message is customizable in the schema under the mdm:otherFacets element, using the mdm:defaultErrorMessage element.

<xs:element name="lo_rangetype="xs:intminOccurs="0">
    <xs:annotation>
        <xs:appinfo>
            <mdm:otherFacets>
                <mdm:maxInclusive path="../hi_range">
                    <mdm:defaultErrorMessage xml:lang="en-US">
low range value must be lower than higher range value
                    </mdm:defaultErrorMessage>
                    <
mdm:defaultErrorMessage xml:lang="fr-FR">
la valeur de la borne inférieure doit être inférieure à la valeur de la borne supérieure
                    </mdm:defaultErrorMessage
>
                </mdm:maxInclusive>
            </mdm:otherFacets>
        </xs:appinfo>
    </xs:annotation>
</xs:element>

The message can be localized and customized for the user need.

excludeValue Constraint

Learn MorewebMethods MDM also provides extended facets aimed to prevent a specific value for an element.

The mdm:excludeValue element is dedicated for that purpose. It accepts value as an attribute, which specifies the reject value for the element.

Example: Ensure that lo_range value is different than value “1” in the Royalties table.

<xs:element name="lo_rangetype="xs:intminOccurs="0">
    <xs:annotation>
        <xs:appinfo>
            <mdm:otherFacets>
                <mdm:excludeValue value="1">
                    <mdm:defaultErrorMessage xml:lang="en-US">
low range value must be different than value 1</mdm:defaultErrorMessage>
                    <mdm:defaultErrorMessage xml:lang="fr-FR">
la valeur de la borne inférieure doit être différente de 1</mdm:defaultErrorMessage>
                </mdm:excludeValue>
            </mdm:otherFacets>
        </xs:appinfo>
    </xs:annotation>
</xs:element>

excludeSegment Constraint

Learn MoreFollowing the same principle as the excludeValue constraint, the excludeSegment element prevents that the element value is out of the specified range.

Please note that the boundaries of the range are excluded.

Example: Ensure that lo_range value is out of range (100,200) in the Royalties table.

<xs:element name="lo_rangetype="xs:intminOccurs="0">
    <xs:annotation>
        <xs:appinfo>
            <mdm:otherFacets>
                <mdm:excludeSegment minValue="100maxValue="200">
                    <mdm:defaultErrorMessage xml:lang="en-US">
low range value must be out of range [100,200]</mdm:defaultErrorMessage>
                    <mdm:defaultErrorMessage xml:lang="fr-FR">
la valeur de la borne inférieure doit être hors de la plage [100,200]</mdm:defaultErrorMessage>
                </mdm:excludeSegment>
            </mdm:otherFacets>
        </xs:appinfo>
    </xs:annotation>
</xs:element>

Resource constraint

Learn MoreIt may be sometimes useful to declare an external resource in the model. For instance, an image or HTML resource can enhance the look and feel of an instance screen in webMethods Master Data Manager.

In our sample database context, we could add a field called front_picture in table titles that refers to an image, i.e. the front page of the book.

This can be easy done using the mdm:FacetOResource.

<xs:element name="front_picturetype="mdm:resourceminOccurs="0">
    <xs:annotation>
        <xs:appinfo>
            <mdm:otherFacets>
                <
mdm:FacetOResource 
                    mdm:moduleName="wbp
                    mdm:resourceType="ext-images
                    mdm:relativePath="frontpages/"/>

            </mdm:otherFacets
>
        </xs:appinfo>                    
    </xs:annotation>
</xs:element>

Please note about the mdm:FacetOResource attributes:

  • moduleName: indicates with an alias which webMethods MDM module contains the resource. If it is the module itself that contains the resource, the alias must be preceded by "wbp" (stands for Web Business Process). Otherwise, the alias must be one of the values defined in the element <dependencies> in file ‘module.xml’
  • resourceType: resource type is one of the following values: “ext-images”, “ext-jscripts”, “ext-stylesheets”, “ext-html”
  • relativePath: A local directory where to find the resource, just under the "resourceType" directory (here www/common/images). Hence, for this example, the resource is located at www/common/images/frontpages/ where the www/ directory is at the same level than the WEB-INF/ directory.

 

Next: Develop Programmatic Constraints >

 

Home > Tutorial