Home > Models
Constraints, Triggers and Functions
Facets allow you to define constraints on your Master Data in your schemas. EBX.Platform supports XML Schema facets and provides extended and programmatic facets for advanced data controls.
- XML Schema Supported facets
- Extended Facets
- Programmatic Facets
- Triggers and Functions
- User Input Control
XML Schema Supported facets
|
X |
X |
X |
X |
X |
(1) |
(2) |
(2) |
(2) |
(2) | |||
|
X |
(1) |
|||||||||||
|
X |
X |
(1) |
X |
X |
X |
X |
X |
X | ||||
|
X |
X |
(1) |
X |
X |
X |
X | ||||||
|
X |
X |
(1) |
X |
X |
X |
X | ||||||
|
X |
X |
(1) |
X |
X |
X |
X | ||||||
|
X |
X |
X |
X |
X |
(1) |
|||||||
|
X |
X |
X |
X |
X |
(1) |
(2) |
(2) |
(2) |
(2) | |||
|
X |
X |
(1) |
X |
X |
X |
X |
X |
X | ||||
|
resource (3) |
Notes:
-
(1) The whiteSpace facet can be defined, but is not interpreted by EBX.Platform
-
(2) In XML Schema, boundary facets are not allowed on the type String. Nevertheless, EBX.Platform allows those facets as extensions.
-
(3) The resource type supports only one facet (required): FacetOResource (see EBX.Platform Extended Facets).
Example:
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="4.5"/>
<xs:maxExclusive value="17.5"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Uniqueness constraint
It is possible to define a uniqueness constraint, by using the standard XML Schema element xs:unique . This constraint indicates that a value has to be unique inside a table.
In the example below, a uniqueness constraint is defined on the publisher table, for the target field name (this means that two occurrences of the publisher table cannot have the same name):
<xs:element name="publisher">
...
<xs:complexType>
<xs:sequence>
...
<xs:element name="name" type="xs:string"/>
...
</xs:sequence>
</xs:complexType>
<xs:unique name="uniqueName">
<xs:selector xpath="."/>
<xs:field xpath="name"/>
</xs:unique>
</xs:element>
A uniqueness constraint has to be defined inside a table and has the following properties:
|
Property |
Description |
Mandatory |
|
|
Identifies the constraint in the schema. |
Yes |
|
|
Indicates the table where the uniqueness applies, using a restricted XPath expression ('..' is forbidden). It can also indicate an element inside the table (without changing the meaning of the constraint). |
Yes |
|
|
Indicates the field in the context whose values must be unique, using a restricted XPath expression. |
Yes |
Limitations:
-
The target of the
xs:fieldelement has to be in a table. -
Uniqueness constraint cannot apply if the field is inside an aggregated list.
-
The definition of multiple
xs:fieldelements is not supported.
Extended Facets
EBX.Platform provides additional constraints that are not specified in XML Schema, but that are useful for Master Data Management.
In order to guarantee conformance to XML Schema, those Extended Facets are defined under the element
annotation/appinfo/otherFacets .
Foreign keys
A reference to a table is defined using the extended facet tableRef . The element must be of type xs:string.
|
Element |
Description |
Required |
|
|
XPath expression that specifies the target table. |
Yes. |
|
|
Reference of the instance that contains the target table. |
Only if element 'branch' is defined. Otherwise, default is current instance. |
|
|
Reference of the branch that contains the instance container. |
No, default is current home. |
|
|
Custom display for presenting the selected foreign key in the current record and the sorted list of possible keys. Two variants can be specified:
|
No. |
|
|
Specifies an additional constraint that filters the occurrences of the target table. Two types of filters are available:
|
No. |
The example below specifies a reference (foreign key) to an occurrence of catalog element.
<xs:appinfo>
<osd:otherFacets>
<osd:tableRef>
<tablePath>../catalog</tablePath>
<label xml:lang="en-US">Product: ${./ProductID}</label>
<filter>
<predicate>type = ${../refType} </predicate>
</filter>
</osd:tableRef>
</osd:otherFacets>
</xs:appinfo>
</xs:annotation>
Note: Multiple variants can be specified to the label of the tableRef. The priority of the tags is the following:
-
display tag with a programmatic label.
-
display tag with a localized expression.
-
display tag with a default expression.
At runtime, the extended facet
tableRef is interpreted as an enumeration whose values are formatted foreign keys. Labels may be added to key value by using
labelPaths element: each label is specified by the absolute path in the content of an occurrence.
See also:
Dynamic constraints
Those facets retain the XML Schema semantics, but the value attribute is replaced by a path attribute that allows to get the value from another Master Data in the adaptation:
-
length
-
minLength
-
maxLength
-
maxInclusive
-
maxExclusive
-
minInclusive
-
minExclusive
By means of these facets, the data model may be modified dynamically, in the adaptations.
Example:
<xs:annotation>
<xs:appinfo>
<osd:otherFacets>
<osd:minInclusive path="/domain/Loan/Pricing/AmountMini/amount"/>
</osd:otherFacets>
</xs:appinfo>
</xs:annotation>
...
</xs:element>
In this example, the boundary of the facet minInclusive is not statically defined. The value of the boundary comes from the node /domain/Loan/Pricing/AmountMini/amount
FacetOResource Constraint
This facet must be defined for each resource type. It has the following attributes:
-
moduleName: indicates with an alias which EBX.Platform module contains the resource. If it is the module itself that contains the resource, the alias must be preceded by "wbp". Otherwise, the alias must be one of the values defined in the element <dependencies> of the file‘module.xml’; -
resourceType: represents the resource type that is one of the following values: "ext-images", "ext-jscripts", "ext-stylesheets", "ext-html"; -
relativePath: represents the local directory where the resource is located, just under theresourceTypedirectory. In the example below, it is the directory www/common/images/ . Hence, for this example, the resource is located at www/common/images/promotion/ where the www/ directory is at the same level as the WEB-INF/ directory.Furthermore, if a resource is defined in a localized directory ( www/en/ for instance), it will be considered only if another resource of the same name is defined in the directory www/common/ .
This facet has the same behavior as an enumeration facet: the values are collected by recursively listing all the files in ‘local path’ from the specified directory ‘resource type’ in the specified ‘module’ .
Example:
<xs:annotation>
<xs:appinfo>
<osd:otherFacets>
<osd:FacetOResource
osd:moduleName="wbp"
osd:resourceType="ext-images"
osd:relativePath="promotion/" />
</osd:otherFacets>
</xs:appinfo>
</xs:annotation >
</ xs:element>
An overview of directories structures in an EBX.Platform module (J2EE Web application) is detailed in the section Modules - Structure .
excludeValue constraint
This facet verifies that an instance is different from a specified value.
Example:
<xs:annotation>
<xs:appinfo>
<osd:otherFacets>
<osd:excludeValue value="">
<osd:defaultErrorMessage>
Please select address role(s).
</osd:defaultErrorMessage>
</osd:excludeValue>
</osd:otherFacets>
</xs:appinfo>
</xs:annotation>
<xs:simpleType type="xs:string"/>
</xs:element >
In this example, the empty string is excluded from the possible values.
excludeSegment constraint
This facet verifies that an instance is not included in a segment of values. Boundaries are excluded.
Example:
<xs:annotation>
<xs:appinfo>
<osd:otherFacets>
<osd:excludeSegment minValue="20000" maxValue="20999">
<osd:defaultErrorMessage>
Postal code not valid.
</osd:defaultErrorMessage>
</osd:excludeSegment>
</osd:otherFacets>
</xs:appinfo>
</xs:annotation>
<xs:simpleType type="xs:string"/>
</xs:element>
In this example, values between 20000 and 20999 are excluded.
Enumeration facet filled by another node
By default, an enumeration facet is described statically in XML Schema.
The content of an enumeration facet can be filled dynamically by another node of the adaptation model.
Filling by a list
With the following information, we indicate that the content of an enumeration facet comes from the node CountryList .
<xs:appinfo>
<osd:otherFacets>
<osd:enumeration osd:path="../CountryList"/>
</osd:otherFacets>
</xs:appinfo>
</xs:annotation>
The node CountryList :
-
Must be of the same type as the node that has the enumeration facet
-
Must be an aggregated list (
maxOccurs> 1).
Example:
<xs:complexType>
<xs:sequence>
<xs:element name="CountryList" maxOccurs="unbounded">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="DE" osd:label="Allemagne"/>
<xs:enumeration value="AT" osd:label="Autriche"/>
<xs:enumeration value="BE" osd:label="Belgique"/>
<xs:enumeration value="JP" osd:label="Japon"/>
<xs:enumeration value="KR" osd:label="Corée"/>
<xs:enumeration value="CN" osd:label="Chine"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="CountryChoice" type="xs:string">
<xs:annotation>
<xs:appinfo>
<osd:otherFacets>
<osd:enumeration osd:path="../CountryList"/>
</osd:otherFacets>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType >
</xs:element >
Programmatic Facets
A programmatic constraint can be added on any XML element declaration that refers to a simple type.
In order to guarantee the conformance to XML Schema, those constraints are specified under the element
annotation/appinfo/otherFacets .
Programmatic constraints
A programmatic constraint is defined by a Java class that implements the interface
Constraint.
Additional parameters can be defined. Consequently, the implemented Java class must conform to the JavaBean protocol. In the example below, the Java class must define the methods: getParam1(), setParam1(String), ..., getParamX(), setParamX(String), etc.
Example:
<xs:annotation>
<xs:appinfo>
<osd:otherFacets>
<osd:constraint class="com.foo.CheckAmount">
<param1>...</param1>
<param...n>...</param...n>
</osd:constraint>
</osd:otherFacets>
</xs:appinfo>
</xs:annotation>
...
</xs:element>
See also:
Programmatic enumeration constraints
An enumeration constraint adds to a basic programmatic constraint the definition of an ordered list of values. Such a constraint is defined by a Java class that implements the interface
ConstraintEnumeration . This facet allows to select a value from a list.
Example:
<xs:annotation>
<xs:appinfo>
<osd:otherFacets>
<osd:constraintEnumeration class="com.foo.CheckAmountInEnumeration">
<param1>...</param1>
<param...n>...</param...n>
</osd:constraintEnumeration>
</osd:otherFacets>
</xs:appinfo>
</xs:annotation>
...
</xs:element>
Programmatic nomenclature constraints
A nomenclature constraint adds to a basic programmatic constraint the definition of an ordered list of value-labels (see Nomenclature). Such a constraint is defined by a Java class that implements the interface
ConstraintNomenclature . This facet allows to select a value from a list.
Note that an enumeration constraint is more appropriate when display must be localized or when there are many values in the enumeration.
Example:
<xs:annotation>
<xs:appinfo>
<osd:otherFacets>
<osd:constraintNomenclature class="com.foo.CheckAmountInNomenclature">
<param1>...</param1>
<param...n>...</param...n>
</osd:constraintNomenclature>
</osd:otherFacets>
</xs:appinfo>
</xs:annotation>
...
</xs:element >
Constraint on null value
Sometimes, a value is mandatory only if some conditions are verified (for example if another field has some specific value). In this case, the standard XML Schema attribute
minOccurs will not help because it is static.
For checking if a value is mandatory or not, according to its context:
-
a programmatic constraint must be defined by a Java class (see above);
-
this class must also implement the interface
ConstraintOnNull; -
XML Schema cardinality attributes must specify that the element is optional (
minOccurs="0"andmaxOccurs="1").
Note: By default, constraint on null value is not checked on user input. In order to enable this check, the 'checkNullInput' property must be set and if the element is terminal, the adaptation instance must also be activated.
Example:
<xs:annotation>
<xs:appinfo>
<osd:otherFacets>
<osd:constraint class="com.foo.CheckIfNull">
<param1>...</param1>
<param...n>...</param...n>
</osd:constraint>
</osd:otherFacets>
</xs:appinfo>
</xs:annotation>
...
</xs:element >
Constraints on table
A constraint on table is defined by a Java class that implements the interface
ConstraintOnTable .
A constraint on table can only be defined on a table node.
Additional parameters can be defined. Consequently, the implemented Java class must conform to the JavaBean protocol. In the example below, the Java class must define the methods: getParam1(), setParam1(String), ..., getParamX(), setParamX(String), etc.
Example:
<xs:annotation>
<xs:appinfo>
<osd:table>
<primaryKeys>/key</primaryKeys>
</osd:table>
<osd:otherFacets>
<osd:constraint class="com.foo.checkTable">
<param1>...</param1>
<param...n>...</param...n>
</osd:constraint>
</osd:otherFacets>
</xs:appinfo>
</xs:annotation>
</xs:element>
Important: Regarding the validation process, constraints on tables are only checked when calling a validation report of an adaptation instance/table. This means, for performance purposes, these constraints are not checked when updates (such as occurrence insertion, deletion or modification) on tables occur. However the internal incremental validation framework will optimize the validation cost of these constraints if dependencies are defined. For more information, see performance section.
See also:
Triggers and Functions
Computed values
By default, Master Data are read and persisted in the XML repository. Nevertheless, they may be the result of a specific computation and/or access an external database (a RDBMS, a central system...).
EBX.Platform even allows to take into account other Master Data in the current adaptation context.
This is made possible by defining functions .
A function is specified in the XML Schema document by using the
osd:function element (see example below).
-
The value of class attribute must be the qualified name of a Java class which implements the Java interface
ValueFunction. -
Additional parameters may be specified at schema level, in this case the JavaBeans convention is applied.
Example:
<xs:annotation>
<xs:appinfo>
<osd:function class="com.foo.ComputeValue">
<param1>...</param1>
<param...n>...</param...n>
</osd:function>
</xs:appinfo>
</xs:annotation>
...
</xs:element>
Triggers
Adaptation instances or table occurrences can be associated with methods that are automatically executed when some operations are performed: creation, update, delete, etc.
In the XML Schema document, these triggers must be declared under the
annotation/appinfo element using the
osd:trigger tag.
For adaptation instances triggers, we have to define, inside the
osd:trigger tag, a Java class that extends the abstract class
InstanceTrigger .
Note that in the case of adaptation instance triggers, it is advised to define
annotation/appinfo/osd:trigger tags just under the root element of the considered XML schema.
Example:
<xs:annotation>
<xs:appinfo>
<osd:trigger class="com.foo.MyInstanceTrigger">
<param1>...</param1>
<param...n>...</param...n>
</osd:trigger>
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
...
</xs:sequence>
</xs:complexType>
</xs:element>
For the definition of tables occurrences triggers, we have to define, inside the
osd:trigger tag, a Java class that extends the abstract class
TableTrigger .
In the case of table occurrences triggers, it is advised to define the
annotation/appinfo/osd:trigger tags just under the element describing the considered table or table type.
Examples:
On a table element:
<xs:annotation>
<xs:appinfo>
<osd:table>
<primaryKeys>/key</primaryKeys>
</osd:table>
<osd:trigger class="com.foo.MyTableTrigger"/>
</xs:appinfo>
</xs:annotation>
</xs:element>
or on a table type element:
<xs:annotation>
<xs:appinfo>
<osd:trigger class="com.foo.MyTableTrigger">
<param1>...</param1>
<param...n>...</param...n>
</osd:trigger>
</xs:appinfo>
</xs:annotation>
<xs:sequence>
...
</xs:sequence>
</xs:complexType>
Note that additional parameters can be defined. Consequently, the Java class implemented must conform to the JavaBean protocol. In the example above, the Java class must define the methods: getParam1(), setParam1(String), ..., getParamX(), setParamX(String), etc.
Auto incremented values
It is possible to define auto-incremented values. Auto-incremented values are only allowed inside a table, and they must be of type
xs:int or
xs:integer .
An auto-increment is specified in the XML Schema document by using the
osd:autoIncrement element under the
annotation/appinfo element tag.
Example:
<xs:annotation>
<xs:appinfo>
<osd:autoIncrement />
</xs:appinfo>
</xs:annotation>
</xs:element>
There are two optional elements
start and
step .
Example:
<xs:annotation>
<xs:appinfo>
<osd:autoIncrement>
<start>100</start>
<step>5</step>
</osd:autoIncrement>
</xs:appinfo>
</xs:annotation>
</xs:element>
The
start attribute specifies the first value for this auto-increment. If this attribute is not specified, then the value
1 is set by default.
The
step attribute specifies the step for the next value to be generated by the auto-increment. If this attribute is not specified, then the value
1 is set by default.
A field specifying an
osd:autoIncrement has the following behaviour:
-
The computation and allocation of the field value are performed whenever a new record is inserted and the field value is still undefined.
-
No allocation is performed if a programmatic insertion already specifies a non
nullvalue. For example, if an archive import or an XML import specifies the value, then it is preserved. Note also that, consequently, the allocation is not performed for a record insertion in occulting or overwriting modes. -
A newly allocated value is, whenever possible, unique in the scope of the repository. More precisely, the uniqueness of the allocation spans over all the instances of the schema, and it also spans over all the branches. The latter case allows to merge a branch to its parent with a reasonable guarantee that there will not be a conflict if the
osd:autoIncrementis part of the records' primary key. This principle has a very specific limitation: when a massive update transaction specifying values is performed concurrently to a transaction allocating a value on the same field, it is possible that the latter transaction will allocate a value that will be set in the first transaction (there is no locking between several branches).
Internally, the auto-increment value is stored in 'Auto Increments' table of
ebx-repository adaptation. This field is automatically updated, so that it defines the greatest value ever set on the associated
osd:autoIncrement field, in any instance and any branch in the repository. This value is computed, taking into account the max value found in the table being updated.
In some particular case, for example when multiple environments have to be managed (development, test, production), each having different auto-increment ranges, it may be required to avoid this "max value" check. This particular behavior can be achieved, thanks to the
disableMaxTableCheck property:
-
locally, by setting a parameter element in auto increment declaration:
<disableMaxTableCheck>true</disableMaxTableCheck>, -
for the whole schema, by setting
<osd:disableMaxTableCheck="true">inxs:appinfoof schema declaration, -
or globally, by setting property
ebx.autoIncrement.disableMaxTableCheck=truein main configuration file (ebx.properties).
Note that it is generally not recommended to enable this property, as this could generate conflicts in the auto-increment values.
User Input Control
Check null input
According to EBX.Manager default validation policy, in order to allow a temporary incomplete input, the control whether an element is defined when it is mandatory is not performed on user input, but on adaptation validation only. If the 'mandatory feature' must be checked immediately on user input, the element must additionally specify:
osd:checkNullInput="true" .
Note: A value is mandatory if the schema specifies that the element is mandatory, either statically (
minOccurs="1") or dynamically (by means of a Constraint on null). For terminal elements mandatory values are checked only for an activated adaptation instance. For not terminal elements the adaptation instance does not need to be activated.
Example:
...
</xs:element >
See also:
EBX.Platform whitespaces management for Data Types
According to XML Schema ( cf. http://www.w3.org/TR/xmlschema-2/#rf-whiteSpace ), whitespaces handling must follow one of preserve, replace or collapse procedures:
-
preserve. No normalization is done, the value is not changed
-
replace. All occurrences of #x9 (tab), #xA (line feed) and #xD (carriage return) are replaced with #x20 (space)
-
collapse. After the processing implied by replace, contiguous sequences of #x20's are collapsed to a single #x20, and leading and trailing #x20's are removed
EBX.Platform general management
EBX.Platform complies with XML Schema recommendation:
-
For nodes of type
xs:string(whether primary key element or not), whitespaces are always preserved and an empty string is never converted tonull. -
For other nodes (non
xs:stringtype), whitespaces are always collapsed and an empty string is converted tonull.
Exceptions: For nodes of type
osd:html or
osd:password , whitespaces are always preserved and an empty string is converted to
null . For nodes of type
xs:string defining property
osd:checkNullInput="true" an empty string is interpreted as
null at user input in
EBX.Manager.
Specific case for handling whitespaces on a primary key of type string
For primary key columns of type
xs:string , a default EBX.Platform constraint is defined. This constraint forbids empty strings and non collapsed whitespaces values at validation level.
However, if the primary key node specifies its own
xs:pattern facet, this last one overrides the default EBX.Platform constraint. For example, the specific pattern
.* would accept any strings (note that we do not recommend this).
The default constraint allows to handle some ambiguities. For example, it would be difficult for a user to distinguish between the following strings: "12 34" and "12 34". For usual values, it does not create conflicts but for primary keys, it could create errors.
Note: EBX.Platform provides a complete Tables specification , that allows to organize and manage your Master Data as in relational databases.
Home > Models