03 December 2018
A Payload definition defines what data to be extracted from ENOVIA how this data is structured and how it can be validated. The extracted data is called "payload" and used when transferring data to another system.
The payload definition itself is an XML file containing the rules for this. This configuration file is stored inside a directory called "payload" below the "cfg" directory.
The generated payload consist of at least one fraction (or section) where each is generated by different configuration settings.
You may for example have one fraction whose data is generated by applying a table (defining the select statements) on a set of business object and/or connections, another fraction generated by executing some MQL statement and a third (or more) fraction generated by using custom Java code.
Below is a image illustrating this.
Fraction 1 in the image above uses a data-set to define what objects to be included in the fraction. The table defines what meta data to be extracted from ENOVIA.
The result in the final Payload is a section wrapped inside the "Documents" element.
There exists many possibilities to impact the generated XML. You may for example provide additional so called "XML Specification" into the Payload definition that changes the raw XML extract from ENOVIA. Finally, you may transform the generated payload with a configured stylesheet (XSLT template). |
The root element of the payload definition is "Payload".
The allowed attributes on the <Payload>
element are shown in the table below.
Attribute | Required | Default | Description |
---|---|---|---|
omitRootElement |
No |
False |
Can be used to omit generating the root element. Note that this is only possible if the Payload definition contains one fraction. Otherwise, the generated XML payload data would be invalid. |
rootElement |
No |
payload |
Can be used to configure the root element name |
contentType |
No |
text/xml |
Can be used to change the output content type |
encoding |
No |
According to configured encoding, typically utf-8 |
The available child elements are listed in the table below.
Element | Description |
---|---|
|
Defines a Java class that produces some content.
The class must implement the interface The name of the class is provided within the attribute |
|
Defines a dataset together with a table to define what meta-data from the business objects and/or connections to be part of the payload. The data set is provided within the child element called See Table Content for more information. |
|
Can be used to execute arbitrary MQL code. The code to be executed is defined between the start/end tag. By default, TIF assumes that the output from your MQL command is XML data. If that is not the case, you can use some additional configuration options.
|
|
Can be used to include input payload that is provided to the job. See this chapter for more information. |
|
Used for allowing a template to produce some content as a part of the payload.
|
|
Defines the default XML specification (rules) how the extracted data should be formatted. Note that each See chapter below |
|
Defines the XSLT stylesheet to be used to transform the generated payload data with. The value of the transformer element is a reference to a file of type “xslt” or “stylesheet”. See <<Transformer,chapter> below for details |
|
Defines an XML schema file to be used for validation of the final payload data. The value of the validator element is a reference to a file of type “xsd”. See chapter below for details. |
The payload fractions JavaContent, TableContent, MQLContent and Template, all
supports the attributes if
, unless
and filter
.
The filter
attribute may be used to point our a Java class of type com.technia.tif.enovia.payload.InclusionEvaluator
that will be used to decide if the fraction should be part of the payload or not.
Specifying the filter attribute causes the if/unless attributes to have no effect. |
The if
and/or unless
attribute can be used to specify a parameter, or a comma separate list of parameters
that either should be present (if) or not-present (unless) in order for the fraction
to be included in the final payload.
A table driven payload fraction uses a table (or system table) together with a data-set.
Element | Description | Example | Required |
---|---|---|---|
|
Points out the table (XML defined, or System table) that defines the columns (with selectables) that defines what meta data to be extracted from ENOVIA. |
You can point out a table in different ways, see below for some different examples.
|
No, but recommended. If not defined a default table is used that will include all basic information, all attributes and all file information from the objects. This might result in bad performance or too much data being extracted. |
|
Points out the data-set containing the definition how to find/query/filter out objects being part of this payload fraction. |
Note that the first and last example are equivalent. The dataset also supports the attribute
The default value for cacheResult is FALSE. If the value is false, the result will be removed from the cache. Example: The same data set is declared in 3 different fractions. You only set the cacheResult to TRUE on the first one. This will cause the data set to be evaluated on the first and on the third fraction. |
No, but recommended. If not defined, the objects, which this payload fraction is operating upon, will use the business object(s) as given as input to the payload generator. |
|
Defines XML specification (rules) how the extracted data should be formatted. |
See this page |
No. If not defined, the default XML format is used. |
|
May be used to point out a custom XML serializer.
The class you point out must implement the interface
|
or
|
No. If not defined, the default XML serializer is used. |
|
May be used to point out a XSLT stylesheet used for transformation of the generated XML |
or
|
No. |
|
May be used to point out a template (Freemarker) to be used for generating the data. See the chapter Template below |
or
|
No. |
The following table lists additional attributes that may be used on the <TableContent>
element:
Attribute | Description | Example | Required |
---|---|---|---|
outerElement |
May be used to define the element that will group the table-content fraction. |
|
No |
paginationSize |
Defines a pagination size that results in that data is retreived in chunks from the database. May be useful for larger datasets in order to reduce footprint, however, the performance will be slightly degraded since more DB calls will be made. Default is -1, e.g. disabled |
|
No |
sortingDisabled |
May be used to disable the default sorting according to the table column definitions. May be used to increase performance for larger data-sets. Default is false, e.g sorting is enabled according to Table Column definition(s) |
|
No |
Input content fraction includes input payload that is provided to the job.
Typically this fraction can be applied when the job is initiated via <NewJob>
event handler by other job that provides some input.
The following table lists additional sub elements that may be used on the <InputContent>
element:
Element | Description | Example | Required |
---|---|---|---|
<Transformer> |
May be used to point out a XSLT stylesheet used for transformation of the input. |
or
|
No |
The traditional way of producing data in a payload is to generate the XML with or without using a so called
<XMLSpec>
to configure the generated XML.
In addition, one usually need to implement a XSLT stylesheet to transform the XML data into the final format.
An alternative approach is to use a template for this.
TIF bundles the Apache Freemarker library, which is a template engine that is capable of generating output based upon data in an object model or model.
The model is data that is passed in to the template, e.g. the extracted data for a <TableContent>
fraction
and other parameters passed into the TIF job, which the payload is generated for.
Example configuration of a Payload using a single Table Content fraction with a template:
<Payload>
<TableContent>
<Table>tvc:table/Test.xml</Table> (1)
<Template>tvc:template/Test.ftl</Template> (2)
<Transformer>tvc:xslt/Test.xsl</Transformer> (3)
</TableContent>
</Payload>
1 | Specify what table to be used |
2 | Specifies the template to be used |
3 | OPTIONAL: If your template produces XML data, you can still use a transformer to convert the data into another format. |
An example Freemarker template is shown below:
<#ftl output_format="XML">
<objects>
<#list data.rows as row>
<row>
<#list row.cells as cell>
<cell name="${cell.column.name}">
<#list cell.values as cellValue>
<value>${cellValue.value}</value>
</#list>
</cell>
</#list>
</row>
</#list>
</objects>
For complete details regarding template authoring, please visit http://freemarker.org/docs/ref.html
The data model passed into the template engine are:
A boolean indicating if the template will be called multiple times due to pagination
The number of pages
The current page
The parameters passed to the Job. The data-type for this object is Map<String, String[]>
ENOVIA RPE parameters from when the Job was initiated. The data type for this object is Map<String, String>
The extracted data. Contains the following methods
isEmpty() - boolean
size() - integer
getRows() - List<com.technia.tvc.core.gui.table.Row>
A Row contains Cell(s) and a Cell contains CellValues(s).
Links to relevant API:
The elements <XMLSpec> and <XMLSerializer> has no meaning when a template is being defined.
|
The MQL content fraction may be used to include output from a MQL command into the generated XML. Your MQL command may for example execute some other program declared in the database, or use some of the built-in MQL commands for queries against the ENOVIA™ database.
The <MQLContent>
element is defined as illustrated below:
<MQLContent
xmlOutput="true | false"
splitBy="\n"
outerElement="name_of_outer_element"
itemElement="name_of_element_wrapping_each_item_splitted_on">
put the MQL code here
</MQLContent>
The attributes available on the <MQLContent>
element are described in the table below:
Attribute | Default | Description |
---|---|---|
xmlOutput |
true |
Defines if the MQL command returns XML formatted code. |
splitBy |
N/A |
If the output should be splitted upon some character, you may specify that here. You may use "\n", "\r" and "\t" to specify new-line, carriage-return or tab. |
outerElement |
Defines the element, which the output from this fraction should be wrapped inside. |
|
itemElement |
item |
If you use the splitBy feature, each item in the split-array will be encapsulated with the specified element. |
txType |
Defines the type of transaction used when executing the MQL command. Possible values are:
|
|
executeAsSuperUser |
false |
If true, the MQL command will be executed with admin privileges (super user). |
Using a custom Java class for extraction of a payload fraction might be useful in some cases.
In the payload configuration, you just declare it like this:
<Payload>
<JavaContent>com.acme.integrations.payload.ECODetails</JavaContent>
</Payload>
or
<Payload>
<JavaContent className="com.acme.integrations.payload.ECODetails"/>
</Payload>
And the class you point out should look like this:
package com.acme.integrations.payload;
import com.technia.tif.enovia.payload.PayloadFraction;
import com.technia.tif.enovia.payload.PayloadFractionContext;
import com.technia.tif.core.ExtractionException;
public class ECODetails implements PayladFraction {
public void createData(PayloadFractionContext ctx) throws ExtractionException {
Writer w = ctx.getWriter();
// ... implement logic here ...
}
}
You only need to implement one method called "createData".
Either using the attribute "xslt" on the <Transformer>
element or using the body text,
you may point out a XSLT stylesheet that you use to transform the source XML data with.
TIF includes Saxon-HE 9.7 that "provides a basic XSLT 2.0 processor as defined in section 21 of the XSLT 2.0 Recommendation". |
Example:
<Payload>
...
<Transformer xslt="tvc:xslt:namespace/MyStylesheet.xslt"/>
OR
<Transformer>tvc:xslt:namespace/MyStylesheet.xslt</Transformer>
</Payload>
The stylesheets should be put inside a directory called "xslt" below the "cfg" directory.
You may omit the "tvc:xslt" prefix. For example just specifying xslt="MyStylesheet.xslt"
refers to "tvc:xslt/MyStylesheet.xslt"
.
Information passed as Parameters or RPEs to the job can be used during the transformation. The prefix for parameter is job.parameter and job.rpe for RPEs.
Example where the transactionId is sent as a parameter to the job and written to the XML:
<xsl:stylesheet ...>
<xsl:param name="job.param.transactionId" />
<xsl:template name="Part">
<part>
<transactionId>
<xsl:value-of select="$job.param.transactionId" />
</transactionId>
</part>
...
</xsl:template>
</xsl:stylesheet>
XML payload can be transformed to JSON by specifying attribute type
with value json.
An example:
<Payload>
...
<Transformer type="json">
<!-- Optional properties -->
<Property ... />
</Tranformer>
</Payload>
The transformer is based on XSLTJSON XSLT stylesheet version 1.0.93. Refer the documentation for supported properties that can be used to control the stylesheet.
You may also implement a custom Java class that transforms the payload. The class is defined with attribute className
. Optionally, one or more properties can be supplied with <Property>
child element.
An example configuration:
<Payload>
...
<Transformer className="com.acme.MyCustomTransformer">
<Property name="First Property" value="Value 1" />
<Property name="Second Property" value="Value 2" />
</Transformer>
</Payload>
The class must implement the interface com.technia.tif.core.transform.Transformer
.
The definition is as follows:
package com.technia.tif.core.transform;
public interface Transformer {
void transform(TransformContext ctx) throws TransformerException;
}
Example: Excel Transformer
See the source code: POIExcelTransformer.java.
The class transforms flat, unformatted XML payload to an Excel XLSX format.
Example payload configuration for executing the transformer class:
<Payload>
<TableContent>
<!-- NOTE: Table columns must have <Label> configured -->
<Table>tvc:table/MyTable.xml</Table>
</TableContent>
<Transformer className="com.acme.tif.transform.POIExcelTransformer" />
</Payload>
The example is based on Apache POI version 3.17. |
After the data has been extracted and optionally transformed by your transformer (XSLT stylesheet) you may want to validate the XML data against a schema in order to ensure the validity of the payload.
You may specify a Validator within the payload configuration as shown below:
<Payload>
...
<Validator schema="tvc:xsd/MySchema.xsd"/>
OR
<Validator>tvc:xsd/MySchema.xsd</Validator>
</Payload>
The XML Schema files should be put inside a directory called "xsd" below the "cfg" directory.
You may omit the "tvc:xsd" prefix. For example just specifying schema="MySchema.xsd"
refers to "tvc:xsd/MySchema.xsd"
.
You may also implement a custom Java class that validates the payload. The class is defined with attribute className
. Optionally, one or more properties can be supplied with <Property>
child element.
An example configuration:
<Payload>
...
<Validator className="com.acme.MyCustomValidator">
<Property name="First Property" value="Value 1" />
<Property name="Second Property" value="Value 2" />
</Validator>
</Payload>
The class must implement the interface com.technia.tif.core.validation.Validator
.
The definitions are as follows:
package com.technia.tif.core.xml;
import com.technia.tif.core.ValidationException;
public interface Validator {
void validate(ValidationContext ctx) throws ValidationException;
}
Example: JSON Validator
See the source code: JustifyJSONValidator.java.
The class validates JSON payload against a JSON schema file that is defined in property "schema".
Example payload configuration for executing the validator class:
<Payload>
<TableContent>
...
</TableContent>
<!-- Transforms XML payload to JSON -->
<Transformer type="json" />
<Validator className="com.acme.tif.validation.JustifyJSONValidator">
<!-- Point out JSON schema file -->
<Property name="schema" value="tvc:json/MySchema.json"/>
</Validator>
</Payload>
The example is based on Justify JSON validator version 0.10.0. |
It is possible to explicitly configure content type and encoding of payload configuration. This might be useful for example when using a custom Java class for extraction of a payload fraction.
The following table lists optional attributes that may be used on the <Payload>
element:
Attribute | Description | Example |
---|---|---|
contentType |
May be used to define the content type of the payload. |
|
encoding |
May be used to define the encoding of the payload. |
|
When applying XSLT transformer using <Transformer>
element, content type and encoding can be overridden in XSLT with <xsl:output>
element. See the following table:
Attribute | Description | Example |
---|---|---|
media-type |
May be used to define the content type of the transformed payload. |
|
encoding |
May be used to define the encoding of the transformed payload. |
|