MDM Routines - 6.2

Talend Data Fabric Studio User Guide

EnrichVersion
6.2
EnrichProdName
Talend Data Fabric
task
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

The table below lists some useful MDM routines including those for mangling Foreign Keys. In MDM, you usually need to mangle foreign keys to accommodate to compound keys.

To access these routines, double-click MDM in the system folder in the Integration perspective. The MDM category contains several routines including getFK and createFK:

Routine

Description

Syntax

getFK

Returns one of the FK components by position in a mangled FK.

MDM.getFK (FKs,0)

createFK

Returns the FK string by a single key (String singleKey).

MDM.createFK("0")

createFK

Returns the Fk string by a key list (String[] keys).

MDM.createFK ({"0","1"})

getRepeatingElement

Gets repeating element in xmlString according to the xpath & position.

MDM.getRepeatingElement

hasRepeatingElement

Checks repeating elements in xmlString according to xpath & text;

MDM.hasRepeatingElement

listRepeatingElement

Lists repeating elements in xmlString according to xpath & delimiter.

MDM.listRepeatingElement

addRepeatingElement

Adds repeating elements in xmlString according to xpath & text.

MDM.addRepeatingElement

createReturnMessage

Generates an <error code="X">msg</error> fragment.

MDM.createReturnMessage {example} genErrMsg("test message",0)

setLanguageVariant

Adds or updates an ISO variant to the multilingual text value.

MDM.setLanguageVariant

For example:

setLanguageVariant("EN","abc","[EN:ab][FR:ab_fr]"),

which will update the EN variant to be "abc". The output message will be [EN:abc][FR:ab_fr].

setLanguageVariant

Adds or updates an ISO variant to the multilingual text value with the default ISO and the sort option for the output message.

If the sort option is set to "true", the message will be output in alphabetical order.

MDM.setLanguageVariant

For example:

setLanguageVariant("FR","ab_fr","ab","EN", true), which will add the FR variant "ab_fr". The output message will be [EN:ab][FR:ab_fr].

getLanguageVariant

Gets an ISO value from a multilingual text value with the default ISO fallback.

If the ISO value requested is not found, the default ISO value will be returned.

MDM.getLanguageVariant

For example:

getLanguageVariant("DE","EN","[EN:ab][FR:ab_fr]"), which will return the default EN value "ab" because the DE value requested is not found.

getLanguageVariant

Gets an ISO value from a multilingual text value.

If the ISO value requested is not found, the null value will be returned.

MDM.getLanguageVariant

For example:

getLanguageVariant("FR","[EN:ab][FR:ab_fr]"), which will return the requested FR value "ab_fr".

getNodeList

Gets a nodelist from an xPath.

MDM.getNodeList

parse

Parses the XML.

MDM.parse

nodeToString

Generates an XML string from a node with or without the XML declaration.

MDM.nodeToString

For more information about the examples of the setLanguageVariant and getLanguageVariant routines, see How to handle ISO variants or get an ISO value from a multilingual text.

How to return one component of a mangled foreign key

The getFK routine allows you to return one component of a mangled foreign key using tMap, for example:

You must use the getFK MDM routine in the lookup table in the Map Editor. Using the getFK routine in the editor, you can add/remove/update the foreign key components. In the above capture, the routine helps you to return the name component in the mangled foreign key.

You must do the same in a reversed case and use the createFK routine to return the foreign key string by a single key.

How to handle ISO variants or get an ISO value from a multilingual text

The setLanguageVariant routine allows you to add, update or remove ISO variants in a multilingual text value, while the getLanguageVariant routine allows you to get the value of an ISO variant from a multilingual text value.

To better illustrate how to use the setLanguageVariant and getLanguageVariant routines, this section describes some routine examples with different parameter settings. Note that the examples are not exhaustive.

For more information about those routines, see MDM Routines.

The following table lists the examples which set different parameters for the routines and explains what the result will be.

Example

Description

setLanguageVariant("FR","Bonjour","Hello")

The setLanguageVariant routine may contain three parameters. In this case, the first parameter indicates an ISO variant, and the second parameter indicates its value. The last parameter shows the original multilingual text or the value of the default ISO variant. Note that the default ISO variant is "EN".

If the ISO variant does not appear in the original multilingual text, the ISO variant and its value will be added to the text. Otherwise, the old value of the ISO variant will be updated with the new one, without modifying the other ISO variants.

After this routine example is called, the output message will be [EN:Hello][FR:Bonjour].

setLanguageVariant("EN","Hello world!","[EN:Hello][FR:Bonjour]")

Because the ISO variant EN already appears in the original multilingual text, its old value "Hello" will be updated with the new value "Hello world!".

After this routine example is called, the output message will be [EN:Hello world!][FR:Bonjour].

setLanguageVariant("EN","","[EN:Hello][FR:Bonjour]")

If you leave second parameter empty, the ISO variant will be removed.

After this routine example is called, the output message will be [FR:Bonjour].

setLanguageVariant("FR","Bonjour","Hello","EN", true)

The setLanguageVariant routine may contain five parameters. In this case, the first parameter indicates an ISO variant, and the second parameter indicates its value. The third parameter indicates the original multilingual text or the value of the default ISO variant. The fourth parameter is the default ISO variant. The last parameter indicates whether the message will be sorted and output in alphabetical order.

If the ISO variant does not appear in the original multilingual text, the ISO variant and its value will be added to the text. Otherwise, the old value of the ISO variant will be updated with the new one, without modifying the other ISO variants.

After this routine example is called, the output message will be [EN:Hello][FR:Bonjour].

setLanguageVariant("FR", "Ceci est mon premier produit","[EN:This is my first product][FR:Bonjour]","EN", false)

Because the ISO variant "FR" already appears in the multilingual text, the old value "Bonjour" will be replaced with the new value "Ceci est mon premier produit". Besides, the sort option is set to false, so the message will not be sorted.

After this routine example is called, the output message will be [EN:This is my first product][FR:Ceci est mon premier produit].

setLanguageVariant("DE","Hallo","[EN:Hello][FR:Bonjour]","EN",true)

Because the ISO variant "DE" does not appear in the multilingual text, the variant and its value will be added. Besides, the sort option is set to true, so the message will be sorted and output in alphabetical order.

After this routine example is called, the output message will be [DE:Hallo][EN:Hello][FR:Bonjour].

getLanguageVariant("EN","[EN:Hello world!][FR:Bonjour]")

The getLanguageVariant routine may contain two parameters. In this case, the first parameter indicates the ISO variant whose value will be fetched. The second parameter shows the multilingual text.

If the specified ISO variant does not appear in the multilingual text, the null value will be returned.

The return value for this routine example is Hello world!.

getLanguageVariant("DE","[EN:Hello][FR:Bonjour]")

Because the ISO variant "DE" does not appear in the multilingual text, the return value for this routine example is null.

getLanguageVariant("DE","EN","[EN:Hello][FR:Bonjour]")

The getLanguageVariant routine may contain three parameters. In this case, the first parameter indicates the ISO variant whose value will be fetched. The second parameter indicates the default ISO variant. The last parameter shows the multilingual text.

If the specified ISO variant does not appear in the multilingual text, the value of the default ISO variant will be returned.

The return value for this routine example is Hello.