*
Metamerge logo
Search

Advanced Search
*
*
*
* HOME DOCUMENTS & RESOURCES DOWNLOADS EARLY TECH ACCESS SUPPORT FAQ KNOWN ISSUES OLD VERSIONS
*

Scripting

Metamerge Integrator provides its users with a highly-flexible engine that can be tuned both from the user interface controls of MI Admin as well as through script input from the user. While the user interface controls provide a means of controlling the data flow on a higher level, scripting provides users with the ability to control almost any aspect of the data flow at any level (including overriding standard MI processing).

MI provides support for a number of scripting languages. Description of these languages and how to use them within the context of MI can be found here . You can set the Script Language for the entire AssemblyLine in the Settings tab. If you change the language, remember that this affects the code used in the Prolog, Epilog, Hooks and Attribute Maps. It does not affect a Connector or Parser written in a script language.

When is scripting needed ?

Scripting is neccessary when you need to add custom processing to your AssemblyLine. Examples of where scripting would be helpful include: (1) the value of an attribute in your output Connector is calculated based on one or more of the input Connector's attributes; (2) you want to process only entries that match a particular set of criteria; (3) you want to override the update operation of the Connector you are using; and/or (4) you want to run some initializing procedures before your AssemblyLine starts. All of these cases mentioned (and many others not mentioned) require scripting.

Where and how is scripting integrated into the AssemblyLine ?

As we already explained, you must utilize scripting when the need for custom processing arises in the integration process. The need for custom data processing will inevitably come in some identifiable point in the flow of data (e.g., before any processing begins, before processing a particular entry, after a failure, etc.). MI provides you with a number of control points throughout the data flow where you may provide direction through scripting (e.g., the AssemblyLines "Prolog" and "Epilog" sections, Connectors "Hooks" sections, etc.). These control points are easily accessed within the MI Admin tool. Implementing custom processing is simply a matter of identifying the correct control point and adding your script in the appropriate edit window.

It is important to both correctly identify the appropriate control point where you will input your script as well as limit the scope of your script to cover just that single goal associated with the control point.

How will scripting affect execution ?

The MI Engine exposes a number of classes and instances that may be accessed, read and modified from user-created scripts in the AssemblyLine. These objects represent the state of the AssemblyLines and the whole MI environment at any moment. By modifying any of these objects, you modify the MI environment itself and thus affect the execution of the integration process.

The list of the global objects, see the reference for more information:

o main - reference can be found  here.
o system - reference can be found here
o task - reference can be found here.
o status - reference can be found here.
o work - reference can be found here .
o conn - reference can be found here .
o event - reference can be found here .
o current - reference can be found here.
o error -  reference can be found here .

A description of all classes and instances available can be found here.

By understanding the classes and interfaces exposed, you will better understand the elements of the MI engine as well as the language it speaks.

Using variables

It is very important to distinguish the holder of the data processed (the Entry object) from other generic variables and data types provided to you by your chosen scripting language. Your creativity and the capabilities of the scripting languages are your only restrictions in terms of what may be placed in the scripting windows. However, when you manipulate data in the context of data flow, you should be aware of and utilize the structure of the Entry object.

As Attribute objects serve as the primary containers for data within the context of an AssemblyLine, it is just these objects that will be accessed and modified during the integration process. Note that each attribute value is in fact an object and belongs to some class. The classes to which the Connector's attributes belong can be seen in the "Syntax" column in the "Configure Connector" dialog, "Attributes" tab. Knowing the attribute value's class, one can successfully access and interpret this value. For example, if a java.lang.String attribute contains a floating point value that you want to use as a floating point, you must first manually transform this value (by the means of the scripting language) to some numeric data type.

When creating variables or processes not directly related to the data flowing in the integration process and the global objects available, the following principle applies: You can declare and use any variables (objects) allowed by the scripting language you choose. The purpose of these variables should be to help you achieve the specific goal associated with the control point in which you script. They should serve only as temporary buffers and not attempt to affect the state of the MI environment itself.

Here you can find explanations about  handling some common data types:
o using floating point values
using date values

Control Points for Scripting

Scripting in an AssemblyLine

 o "Prolog" - Scripting here usually performs any initializing actions needed for the participants in the AssemblyLine. There is one tab for code that is executed before all Connectors have been initialized., and one tab for code that is executed after all Connectors have been initialized, but before they are run and the real execution started. The Prolog code is executed once for each run of the Assembly Line. "Prolog" is the place to declare global variables you will need through the execution of the AssemblyLine (e.g., for counters, average values, etc.)

 o "Script Component" - You may add Script Components to your AssemblyLine in addition to Connectors, by using the Script button under the Data Flow tab in the AssemblyLine. The Script Components is executed once for each entry processed by the Assembly Line, just like a Connector.

 o “Epilog” - Any finalizing actions are to be coded here. The code is executed once for each run of the AssemblyLine after all Connectors have finished their tasks. A common pattern is to release here all resources allocated in the "Prolog" section.

Scripting in a Connector

 o “Attribute Map” - Custom attribute mapping is performed here. You have to select the attribute, choose the "Advanced" Attribute Mapping Mode and input your script in the edit window. Remember that after you've done all processing necessary, you have to assign the result value achieved to "ret.value", i.e. "ret.value = resultValue; ".

“Hooks” - Hooks give you the means to (1) respond to certain events that occur and (2) override Connectors' basic functionality. A description of the Hooks mehanism can be found here. In the Hooks scope you have access to the global MI objects, so you have full control over the MI environment, the AssemblyLine, the Connector itself, entries and attributes. The "Hooks" give you a diversity of control points for customizing the process flow.

Setting Internal Parameters by Scripting

It is possible to set Internal Parameters for a Connector by scripting, like this
conn.setParam ( "filePath", "examples/scripting/sample.csv" );
Here is an example package showing how to set connector parameters through scripting

Scripting in an EventHandler

Reference about scripting in an EventHandler is included here.

Scripting in a Parser

Scripting in a Parser actually refers to implementing your own Parser by scripting. A description of this process is included here.

 

*
  Metamerge Integrator version 4.5 ©Copyright Metamerge AS 2000-2002 Last edited 2002-04-30 contact us