MDM Routines - 6.5

Talend Open Studio for MDM User Guide

EnrichVersion
6.5
EnrichProdName
Talend Open Studio for MDM
task
Data Governance
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, in the Repository of the Integration perspective, expand Code > Routines > system and then double-click MDM. The MDM routines are listed under the MDM category.

Routine

Description

Syntax

getFK

Returns one of the foreign key components by position in a mangled foreign key.

Note that the position is specified by an integer starting from 0.

MDM.getFK

For example:

getFK("[fk1][fk2][fk3]",1),

which will return the second foreign key component in the composite foreign key. The output message will be "fk2".

createFK

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

MDM.createFK

For example:

createFK("0"),

which will return a foreign key created with the id provided. The output message will be "[0]".

createFK

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

MDM.createFK

For example:

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

which will return a foreign key with the ids provided. The output message will be "[0][1]".

getRepeatingElement

Gets repeating element in an xml string according to the xpath and position.

Note that the position is specified by an integer starting from 0.

MDM.getRepeatingElement

For example:

getRepeatingElement("<Product><Features><Feature>color</Feature><Feature>size</Feature></Features></Product>","/Product/Features/Feature",1),

which will extract the second multi-occurrence element described by the xpath node from the xml string provided. The output message will be "size".

hasRepeatingElement

Checks repeating elements in an xml string according to the xpath and the text.

MDM.hasRepeatingElement

For example:

hasRepeatingElement("<Product><Features><Feature>color</Feature><Feature>size</Feature></Features></Product>","/Product/Features/Feature","size"),

which will return the result about whether the specified multi-occurrence element described by the xpath node and the text "size" exist in the xml string provided. The output message will be "true".

listRepeatingElement

Lists repeating elements in an xml string according to the xpath and the delimiter.

Note that the delimiter is wrapped by single quotes.

MDM.listRepeatingElement

For example:

listRepeatingElement("<Product><Features><Feature>color</Feature><Feature>size</Feature></Features></Product>", "/Product/Features/Feature",',') ,

which will list all the multi-occurrence elements described by the xpath node from the xml string provided with the specified delimiter. The output message will be "color, size".

addRepeatingElement

Adds repeating elements in an xml string according to the xpath and the text.

MDM.addRepeatingElement

For example:

addRepeatingElement("<Product><Features><Feature>color</Feature><Feature>size</Feature></Features></Product>", "/Product/Features/Feature","model"),

which will add a new multi-occurence element described by the combination of the xpath node and the text to the xml string provided. The output message will be

<Product>
    <Features>
        <Feature>color</Feature>
        <Feature>size</Feature>
        <Feature>model</Feature>
    </Features>
</Product>

.

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".

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.