Getting Started With Magic Xpi 4.5
Getting Started With Magic Xpi 4.5
5
Self-Paced Tutorial
W
elcome to Magic Software University’s Getting Started with Magic xpi 4.5
self-paced tutorial. We, at Magic Software University, hope that you will
find this tutorial informative and that it will assist you in getting started with
this exciting product.
The self-paced tutorial is constructed with the same information that has proven
successful and useful in the classroom setting. The self-paced tutorial that you are
currently reading is provided in addition to the classroom course. It contains the same
information but has more step-by-step information. The purpose of this self-paced
tutorial is so that you can refresh your memory after sitting in on the classroom
sessions. This tutorial does not replace the classroom lessons, but instead complements
the classroom studies.
During the course you will learn about Magic xpi and how it works. You will use some
of the flow components that Magic xpi provides to create flows, and you will learn
how to connect to some external resources.
Before you install Magic xpi 4.5, please ensure that your computer meets
the hardware requirements described on the next page.
We also recommend that you consult the Magic xpi Installation Guide.
Introduction 1
Course Prerequisites
Before you start with the course there is basic knowledge that you need to have:
Hardware
Windows 7 and later. The course was tested on
Windows 7.
Pentium processor 1.8GHz and upwards.
4Gb RAM or greater
At least 2Gb free space
Your screen should be set at a resolution of at least
1024x768 pixels.
MSSQL Server Access to MSSQL version 2005 and above. You will
need the supervisor password for the installation.
Web Server A personal IIS Web server must be installed on your
computer. Some exercises that you will develop use the
Web server.
License The course uses the standard license. Please obtain a
Magic xpi 4.5 IBNPSRV evaluation license from your
local Magic Software Enterprises representative.
Email Server You need access to an email server so that you can send
emails. You can use your Gmail, Yahoo or Hotmail
accounts as well. Check the internet for instructions on
how to configure those mail servers for POP3, IMAP and
SMTP.
Email Client You will need an email client to view emails that were
sent by the system. You can use an email client such as
Mozilla Thunderbird.
If you are using a web-based email such as Gmail, you
can use the internet browser to check the mail.
Introduction 2
How to Use This Tutorial
To get the most out of this tutorial , follow the classroom lesson and ask any questions
that you have. You can then review the self-paced tutorial for that lesson, and if you
have further questions you can ask the instructor before the next lesson.
The self-paced tutorial provides more step-by-step instructions. If you are learning using
this self-paced tutorial, feel free to contact your Magic Software Enterprises
representative or the Support department for further assistance.
Exercises
At the end of most lessons, there is an exercise. There are solutions provided for most
of the exercises. These are provided as a complete project. Try to do the exercise on
your own before looking at the solution.
Note that your solution may differ from the solution offered. This does not mean your
solution is incorrect, as there are many ways to solve a problem. The solution provided
with the course shows one method of solving the problem.
Course Material
The course material contains the following:
Course data – This is data that you will need during the course exercises. This
includes the database scripts and the XML schemas that you will be using. During
the course you will need to copy this directory to your Magic xpi project folder
once you start your project.
Student Guide – This is the course classroom handout.
Self-Paced Tutorial – This is the book you are reading. It contains the course, but as
a self-paced guide.
Introduction 3
Introduction 4
Le sson
1
Magic xpi Overview
Magic xpi Integration Platform is a comprehensive integration tool delivering fast and
simple integration and orchestration of business processes and applications. Magic xpi
enables the development and implementation of true enterprise application integration
(EAI), business process management (BPM), and service-oriented architecture (SOA)
infrastructure.
In this lesson, you will learn about integration projects, and get a first glance of the
Magic xpi development environment. You will be able to identify the main components
of Magic xpi Integration Platform. This lesson covers various aspects of Magic xpi
Integration Platform, including:
EAI became a top priority in many enterprises. With the internet and the creation of
the extended enterprise, Business to Business (B2B) integration became possible.
The Studio’s design features allow you to develop your integration project in an
intuitive and methodical way.
Integration Flows
The flows are the backbone of your Magic xpi project. An integration flow is a set of
steps, comprising their own logic that controls the execution order of the steps.
A step can either call a Magic xpi flow component or use one of the Magic xpi Server
services.
The integration flows are executed by the Magic xpi Server during deployment. You
can use a flow variable to define the flow’s logic.
Flow components
Utilities
Flow variables, context variables, global variables, and system variables
Environment variables
Flow logic
Error handling
Out-of-the-box: These are components supplied with Magic xpi. You need to
configure these components for the specific task at hand.
Self-developed: These are components that you can develop for use in your
integration project. Magic xpi provides a Connector Builder to create your own
component.
A Magic xpi flow component must provide a specific interface, which is used by the
Magic xpi Studio and the Magic xpi Server to incorporate the component in the
Magic xpi project.
This provides transparency between the flow components, and allows you to create
your flow components in a standard way.
Within the flow you can place conditions on the different flow components. This tells
Magic xpi which branch to follow, based on which condition evaluates to ‘True’. This
mechanism enables you to create branches, loops, and any other flow logic that is
necessary for the integration project.
Data Management
Most integration projects deal with data, so this is something that has to be handled.
With Magic xpi, data can be handled in multiple ways. It can be:
The Magic xpi Server is based on In-Memory Data Grid technology as the underlying
messaging and context infrastructure, and on Magic xpi runtime processes (workers) to
execute integration flows.The Server is started as a process in background mode and
has no user interface.
The Magic xpi Server runs on various operating systems, such as Windows and Linux.
Magic Monitor
Since the Magic xpi Server has no user interface, the Magic Monitor is provided to
monitor the Server activity.
You can track your project's execution in greater detail through the Dashboard,
Messages, Flows, Triggers, Servers, Locking, Subscription, Scheduler, Summary,
Activity Log, ODS, and BAM tabs.
The Debugger displays extra information about the current execution, such as flow
variables, user parameters, flow logic, and the activity log.
Version Control
Version Control, which is sometimes referred to as Source Management, provides the
following functionality:
Save versions – You can save versions of various aspects of the project, enabling
you to retrieve a previous version of any part of the project.
Team development – You can develop your project in a multi-developer
environment. Each developer works on a copy of the project's source files, and is
responsible for synchronizing their own copy with the Version Control system.
File protection – To edit a file, you first need to check out the file. This protects the
source files from being accidentally overwritten by another user.
Version Control functionality is available in Magic xpi for various objects, including:
Projects
Business processes
Flows – Each individual flow can be checked out
Repositories
Variables – Global and Context variables can be checked out
When creating a new project, you define whether the project will be implemented
using Version Control. You can also add an existing Magic xpi project to a Version
Control system.
Connector Builder
There are certain occasions when you will need customized code that Magic xpi does
not provide out of the box. Magic xpi provides a Connector Builder that allows you to
create a component for your specific needs and connect to the Magic xpi Studio for
use within the integration project.
Checker
Magic xpi provides a tool to check the syntax within the integration project. The
Checker tool will find things like unconfigured steps and incompatible types when
scanning for problems. With Magic xpi, you have two different options to process the
syntax checker, either on the specific flow or on the entire project. If the checker finds
errors, it will then show you where the errors were found.
Text Search
Magic xpi enables you to search for specific text within the integration project. You
can search either on a specific flow or the entire project. If the text is found, Magic xpi
will then show you where that text is located.
Integration projects.
The main components of Magic xpi Integration Platform.
Flow components, and the difference between out-of-box components and self-
developed components, for inclusion in your integration project.
The built-in debugger, where you can monitor and debug your flows.
Magic xpi tools.
If you work according to a defined methodology, you can prevent future errors and
minimize problems that you may be faced with during each stage of the project.
This lesson introduces the recommended methodology when working with Magic xpi.
The course’s lessons follow this methodology.
In this lesson, you will learn about the recommended Magic xpi development
methodology and you will be introduced to some of the terminology that you will be
learning about during this course.
Each business process can be broken down into smaller business logic cycles.
Example:
You may have a business procedure called Recruitment, which begins with a
search for a candidate and ends with the candidate starting to work.
This can then be broken down into a number of separate processes, such as
accepting candidates' resumes and inviting them for an interview.
Another process could be the new employee's first day at work, in which the
employee receives a car, a desk, a chair, a computer, and an email address.
The workflow is a logical flow of activities that are executed by people or machines.
Some of these machines include computer applications and databases.
These applications form the backbone of the flow, since they are responsible for
storing and handling information needed in order for the flow to be successful.
Each application that takes part in the workflow needs to be identified, including the
physical location of the servers and their stress load.
The Magic xpi Server can interact with these applications using various methods, such
as SQL, emails, messaging queues, and many others.
These external entities are resources that the Magic xpi project interacts with to provide
a solution for the integration project. After you have decided how Magic xpi will
interact with the external applications, you can then define the Magic xpi resources.
However, when defining the business process, you may find that some of these
resources need to activate Magic xpi externally. To handle these external requests,
Magic xpi exposes various services that an external application can invoke when
required.
Services are the application units that the project exposes externally, enabling them to
be invoked from external applications. The service definition holds the interface
information with which applications can call a Magic xpi project.
The Magic xpi Server offers services using various methods, such as:
Web services
HTTP
Messaging queues
Email triggers
And much more…
Once you understand how other applications need to interact with Magic xpi, you can
define the Magic xpi services that are needed for the project. Services are defined in a
central location for definition and management purposes. These defined services can
be used when you add triggers to a flow.
Each individual flow is broken down into steps that need to be implemented when
developing the integration project. Each step may branch off into further steps,
depending on whether a specified condition is met.
When you are in the design phase, you should give considerable thought to how each
flow will be invoked. Flows can be invoked in numerous ways:
After the project has been deployed, it will work with real data and implement the
business logic that was defined in the analysis stage of the implementation.
During this course you will learn more about the subjects that were touched on during
this lesson.
To implement this methodology, you first need to create a new project in Magic xpi
using the Magic xpi Studio. This is the first application in Magic xpi Integration
Platform that you need for your integration project.
Creating a Project
To create a new project, you need to be in the Magic xpi Studio. The Magic xpi
Studio can be executed from the Magic xpi Studio shortcut in the Windows Start menu.
Click the File menu, select New, then Project. The New Project dialog box opens.
Alternatively, click the New Project icon , or press CTRL+Shift+N.
Name – This name identifies your integration project and is used as an index in
various tables. You will learn more about this later.
Location – This defines the location where your project will be created.
Solution Name – By default, this is the same as the name that you assigned to the
project in the Name property (above).
Create directory for solution – Select this check box if you want to change the
solution name to something else.
Add to Source Control – Select this check box if you want your new project to work
with Version Control.
You will now get hands-on practice with the Magic xpi Studio:
My Documents\Magic\projects\<project name>
Please take note of the following files. Some of these files will be discussed in more
detail during this course:
Source Directory This is the location where Magic xpi creates all the
source files that are needed for the project. All the
files in this directory are in XML format, and should not
be changed.
Magic_xpi _course.mgxpiproj This is the project metadata and contains all the
project definitions.
Services.xml This file contains the settings for the application units
that the project exposes externally, so that they may
be invoked from external applications. You will learn
about services in a later lesson.
Course Data
For the purpose of this course, data has been prepared for you.
You will learn more about environment variables during the course, and you will use
them in your examples.
currentprojectdir %projects%Magic_xpi_course%sl%
currentproject %currentprojectdir%Magic_xpi_course.mgxpiproj
Property Description
Name The name of the project. This property cannot be modified in this
window.
Modified The last time the project was modified. This property cannot be
modified.
Owner The project owner (as specified in the Owner parameter of the INI
configuration file). This property cannot be modified in this window.
Project data The language encoding (the language and character set) that is used in
encoding the project file and in any destination XML file created in the Data
Mapper.
Resource This property points to the location of the file holding the resource
settings file settings. This file can be edited externally to port the project to different
environments.
Services This property points to the location of the file holding the service
settings file settings. This file can be edited externally to port the project to different
environments.
Company Description
MSU Computers Ltd. sells computer hardware products.
Purchasing – This department purchases stock from vendors and manages the stock
in the warehouse.
Sales – This department handles customer relations and the approval of the
customer orders.
Distribution – After an order is approved, this department handles the delivery of
orders to the customer.
Project Description
The course project handles a customer request in the following manner:
The Resources section defines all the external systems that Magic xpi needs to access
during project execution.
Each resource contains the configuration details needed for a successful connection to
an external application. For example, if you need to connect to a specific database,
you only need to configure the connection details once.
Resources 31
Advantages
Magic xpi provides a central location to define all the external resources referenced in
the project. This approach has many advantages.
In the code itself, you refer to the resource name. You can refer to the same resource
many times in your project, while the configuration details are stored only once.
The resource configuration details are stored separately from the integration flow logic.
This allows easier administration, deployment, and migration between environments
without changing the code.
Resources can be defined once and shared among multiple integration projects. This is
particularly common in situations where resources such as Email or databases are
defined.
? Before continuing, take a step back and think which resources you
will be using in the course project.
Resource Types
Before you discuss the resources themselves, you must know about resource types.
Resource types are a predefined category of resources that share the same type of
properties. For example, Database is a resource type. You may have multiple
databases defined in your project, using different DBMSs such as Oracle or MySQL,
but all share the same or similar configuration properties, depending on the particular
DBMS.
Resource types are predefined in Magic xpi, and the properties associated with each
type are stored in the <Magic xpi 4.5 installation>\Runtime\resource_types.xml file.
Resources 32
Adding a New Resource
To access the Resources section of the Settings dialog box, click the Project menu and
select Settings.
The Resources section is divided into two panes. In the left pane, there is a list of all
defined resources grouped by resource type. In the right pane, you can find the
configuration properties of the currently highlighted resource.
Resources
Definitions
1. Click Add.
2. The New Resource dialog box appears.
3. Select Email from the Resource Type
dropdown list. You will use this resource later
on to send notifications to the salesperson.
4. Set the resource name to Company mail server. This name is the internal name
to reference this resource throughout the project. It is recommended to use a
meaningful name.
5. When you are done, click OK.
You can change the resource name at any stage by parking on the
resource and selecting Rename from the context menu.
Resources 33
Once the resource has been added, the resource name will show in the left pane and
a list of properties will appear in the right pane. As mentioned before, the number and
type of properties are unique for each resource type.
You can now set the properties for the resource, in this case the Email resource. The
properties that may be set for an Email resource are:
Property Description
Server Type This could be either POP3 or IMAP for incoming mail. Leave
the property blank for outgoing mail. For the purpose of this
course, use IMAP.
Incoming Mail Server This is the name of the mail server, such as mail.example.com.
Incoming port The port that the mail server is listening to. For secured
connection, the default is 110.
Incoming Secure Specifies whether the communication with the incoming mail
Connection (SSL) server will be established over a secured connection.
Outgoing Mail Server The name of the SMTP server, such as smtp.example.com. This
is the only protocol supported for sending email.
Outgoing Port The port that the SMTP server is listening to. Typically 25.
Outgoing Secured Specifies whether the communication with the SMTP server will
Connection (SSL) be established over a secured connection.
From Address Enter a valid email address. This is the address that emails are
sent from. For example, [email protected].
Resources 34
When you have defined the Company Mail Server resource, your Resources section
should look similar to the image below.
After entering all the relevant information, it is highly recommended that you check the
accuracy of the information you entered by clicking Validate. This is very important, as
it verifies the validity of your newly-created connection.
When you click Validate, Magic xpi connects to the resource using all the parameters
that you have supplied. If the connection is valid, you will get a dialog box showing
that the connection was successful. However, if the connection fails, you will get an
error message that explains why it failed.
Resources 35
Exercise
Here you will practice what you learned in this lesson. You are going to create a
resource that you will need in later lessons.
Database Resource – This resource will connect to the course data in MSSQL.
The resource name is Course Database. You will refer to this during later
lessons.
Configure all details according to your MSSQL setup.
The course database is Magic_xpi_course.
Summary
In this lesson you learned about the Resources section of the Settings dialog box.
The Resources section provides you with a single location to configure the external
resources, making it easier to maintain them within the project.
You created a number of resources that you will use during the course.
Resources 36
Le sson
5
Scan for New Requests
Now that the analysis has been completed, and you know how the business processes
will flow in the project, it is time to start writing the integration flows. You will be taking
the business process model and turning the logical flows into actual flows.
The Flow Editor is the main editor that you will be using in the Magic xpi Studio. With
the Flow Editor, you create the actual business processes. These consist of the flow
components and the flow logic.
In this lesson, you will learn about the integration flows. You will also be introduced to
the components that make up the flows.
Solution Explorer – This pane displays all of the projects, repositories, business
processes and flows that have been defined.
Toolbox pane – This pane contains a list of components, grouped together under
various categories, that are available to be used in the integration flow.
Main pane – This is the Flow Editor, and holds all the logic to process the
integration project.
The Flow Editor consists of two different areas (see image below):
Trigger Area – This is an area that defines when and what flow is called. You will
learn more about this later in this course.
Flow Area – This area contains all the logic that connects the components together.
You will be doing most of your development here.
Trigger area
Components
Flow area
Renaming Flows
The Magic xpi flow naming convention is provided as a default. It is good practice to
give the flow a meaningful name.
1. Right-click on the Business Process where you want to add the flow.
2. From the context menu, select Add Flow. A new flow will be created with the
initial name Flow-2.
Property Description
Auto Repeat Determines whether the Magic xpi Server will process the flow
again when the last flow component is completed. The options
are Yes or No.
This can create a loop effect.
Auto Start This determines whether Magic xpi will invoke the flow when
the Magic xpi Server loads this project. The options are Yes or
No.
When you disable a flow, the flow is not executed when the
project is deployed. You can enable a flow during runtime
either by using the Enable Flow utility or from the Monitor.
Max Instances Enter the maximum number of flows that Magic xpi can process
simultaneously, including the first flow.
instances is unlimited.
Recovery Policy Determines the flow’s recovery policy when an error occurs.
Timeout Policy This property lets you define what will happen once the timeout
is reached. The options for the Timeout policy are: Abort,
Restart, or None.
Timeout Value This property lets you define how long the flow can run before
(Unlimited) Magic xpi will end it. If you are connecting to an external
system, this policy should be set to prevent the system waiting
indefinitely for an answer.
Introduction to Variables
During the invocation of a flow, it is often required to have a temporary storage place
for the information. This means that the information can be referred to, and used by,
the integration flow, or it can be sent to another integration flow.
Magic xpi predefines some variables that you can use, or you can create your own.
You will learn more about the different types of variables in the next lesson.
For the purpose of this exercise, you will be introduced to a few of the Magic xpi
predefined context variables. You will learn more about variables in later lessons.
The following Magic xpi-generated context variables that you will be using for this
exercise are:
When you park on a flow, you can view the available components in the Toolbox
pane, grouped under the relevant headings for their type.
To meet this requirement, you will use the Directory Scanner as the first step in the
Scan for New Requests flow.
The Directory Scanner component checks local area network (LAN) and/or FTP
directories to see whether files are located in the scanned directory or subdirectory.
The component can also automatically perform specific actions on the specified files in
the directories scanned by the component. You can also exclude a group of files or a
specific file from being watched.
You can use the component to perform various actions, such as:
Move
Delete
Rename
The component can work in two modes: Step mode or Trigger mode.
Step – Once the first file satisfying the configuration criteria is found in the
specified time period, or once the time period has elapsed, the required action is
performed.
For example, you can set a timeout for the component of one second. The Directory
Scanner will scan the directory for the relevant file until the file is found or until it
exceeds the defined timeout (one second, in this example).
Trigger – The component is activated by the Server, and keeps scanning the
directory for new files as long as the activating Server is running. You will learn
more about triggers in a later lesson.
You will be using the Directory Scanner in step mode in this example.
However, you should note that in the case of this example it would be
better to use the Directory Scanner in Trigger mode.
You will add the Directory Scanner as the first step in the Scan for New Requests flow.
To do this:
If components already exist in the Flow Editor, then you need to drop
the component on the component that will be executed before this
component. Magic xpi will automatically place the new step as the
next step in the flow.
General – Contains general information about this step, such as the name of the
step.
Advanced – This covers features such as two-phase processing, and other more
advanced properties. You will not learn about this section during this course.
Logging – This is useful for debugging purposes. You will learn more in a later
lesson.
Setting – Contains the connection information as fetched from the resource.
Property Description
Step Name The name of the component. This is the name that will appear on
the Flow Editor and in the logs. It is good practice to provide a
meaningful name.
Step ID A read-only field displaying the ID of the step or trigger in the flow.
Component Type A read-only field displaying the name of the step type.
Processing Mode This will determine how Magic xpi will execute the step. The
options are:
Linear
Parallel
Stand Alone
Wait for This will determine if Magic xpi will wait before continuing to the
Completion next step, if there are parallel steps defined.
Interface This is the interface that will be used with the component:
XML – Configured using a pre-created XML file.
Method – Configured using the Direct Access Method dialog
box.
Set the following properties for the Directory Scanner component you dragged:
If the component has not yet been configured, you will see a red wheel
symbol in the top right corner of the component.
In this lesson, you will learn how to configure the Directory Scanner component using
the Method interface, also known as the Direct Access Method.
Method List – This is a list of all the methods that will be processed during the step,
in the order that they appear. You can use the arrow keys to the right to move the
method either up or down in the list. You can also enter an expression to set a
condition as to whether the step will be executed or not.
Method Parameters – There are various parameters that are necessary to perform
the highlighted method. The parameters that are in bold are required. Each entry
in the parameter list has the following properties:
Property Description
1. In the Direct Access Method dialog box, click Add to add a method.
2. Select LAN to LAN from the combo box.
In Lesson 3, Magic xpi Project, you were introduced to environment variables and you
learned about the currentprojectdir environment variable. This variable contains the full
path of the current project. You will now learn how to use it.
As you have not yet been introduced to the Email component, it will be introduced
here. For testing purposes, put the ‘To’ email as your own so that you will get the email
when it is sent. This will be changed later in the course.
Email Component
From within Magic xpi, the Email component can send and receive emails with
attachments. The attachments can then be saved on the local machine.
For the Email component, you need to define an Email resource in the Resources
section of the Settings dialog box. This information will be used by the component. You
defined this resource in Lesson 4.
There are numerous methods that Magic xpi supplies for the Email component. In this
lesson, you will be using the Quick Send method. This method:
1. Add an Email step that will email a person that a new request has arrived. Call
the step Send Email to Sales. Use the Quick Send method.
2. Enter the following information for the email:
To: [email protected]
Subject: A new request has arrived
Body: A new request has arrived.
Attach the original request to the email (Hint – look at the properties you
defined in the Directory Scanner step.
Here you will get a very general overview of the Debugger. You will learn about the
Debugger and the Checker in a later lesson.
To run your project with the Debugger, you will need to do the following:
Magic xpi checks the project, in this case the flow, for any syntax errors. If there are
syntax errors, you will not be able to continue. There are various types of syntax errors,
such as a mandatory property that was not defined or was incorrectly defined.
After a few seconds, the Components pane will become the Context
Tree.
From the context menu, select Step. This will run each step. First the
Directory Scanner step will run, followed by the Email step. You will
have to repeat this step until Magic xpi finishes processing each step in the project.
6. Once you have finished processing all the steps, click the Debug xpi menu and
select Stop Debugging to go back to development mode.
Now you can check your email inbox to see if the mail was correctly sent. As you
already know, the Directory Scanner component updated two variables, C.UserXML
and C.UserString. To view the data in these variables you can use the Context View.
You will learn about this view in a later lesson.
You already learned about flows and components - the building blocks of the
integration project. Now you will discover how Magic xpi decides which step to run
within the flow, based on dynamic conditions.
Variables
Flow logic
The Expression Editor
Flow Orchestration 55
Variables
There are many different reasons for the information to be stored, such as:
Flow Orchestration 56
Environment Variables
Environment variables, as their name implies, are primarily used to describe the
physical operating environment of the project. This includes file locations, database
names, and any other values that may change as the operating environment changes.
As an example, for most projects the development environment is different from the
testing and the production environments, and each may have its own server, database
and other related configuration information.
For example, if you have a variable name drive with the assigned value d:\, then the
string %drive%FTP\IN will be interpreted during runtime as d:\FTP\IN.
You can use environment variables recursively, meaning that you can use one variable
name when defining another. Consider the following example:
sl \ \
drive C: C:
Flow Orchestration 57
There are two types of environment variables:
User – These variables are defined by the developer. You can add, delete, or
define the translation value of those variables. When deleting or renaming
variables, Magic xpi does not check whether the name is used in your code, and
does not change your code to reflect the change.
Internal – Magic xpi provides several predefined environment variables. You
cannot delete these variables, but you can modify their value. One of the most
commonly used predefined variables is currentprojectdir, which points to the
physical folder in which your current Magic xpi project resides.
To modify the translation value of environment variables, you can open the Settings
dialog box from the Project menu, or you can change the values directly in the
configuration files mentioned above.
Flow Orchestration 58
Project-Specific Variables
Magic xpi provides four types of variables, each one valid in different areas:
global variables, BP variables, flow variables, and context variables. These variables
all have their own dedicated repository.
Default Value Define the initial value for this variable, if no other value is
assigned to it. This can be a specific value, or an expression.
Note: If an expression is used, only global variables are allowed
with the expression text.
Global Variables
The Global Variables repository is accessed by double-clicking Global Variables under
the Solution Explorer’s Repositories folder.
Global variables are available to all flows in the same project that share the same
memory address. Changes made to global variables in one flow are reflected
immediately anywhere this variable is referenced, throughout the project.
Magic xpi prefixes these variables with the letter G and a separating period. So if you
named your variable MyGlobalVariable, for example, Magic xpi will call this variable
G.MyGlobalVariable.
Flow Orchestration 59
BP Variables
The BP Variables repository is accessed by double-clicking BP Variables under the
relevant business process in the Solution Explorer.
BP variables are similar to global variables, since they can share the definition and the
values among different flows. But, unlike global variables, BP variables are visible and
can be used only within flows of the same business process.
Magic xpi prefixes these variables with the letter B and a separating period.
Flow Variables
The Flow Variables repository is accessed by:
Double-clicking Flow Variables under the relevant flow in the Solution Explorer.
Parking on the relevant flow and pressing Ctrl+L.
Flow variables can be updated and referenced only within the flow they are defined
in.
Magic xpi prefixes these variables with the letter F and a separating period.
Flow Orchestration 60
Context Variables
The Context Variables repository is accessed by double-clicking Context Variables
under the Solution Explorer’s Repositories folder.
Like global variables, context variables are defined globally for the entire project. But,
as opposed to global variables, the value of the context variable is stored separately
for each context. This means that when referring to the same variable name, you can
have two different values if the reference is made from different flows. However a
called flow runs in the same context, so the value of the variable in this case will be the
same.
When you define a parallel step, this creates a new context. Therefore the same
variable can have different values even within the same flow. You will learn more
about parallel steps in a later lesson.
Updates made to a context variable are reflected only within the same flow that the
update was made from.
Magic xpi prefixes these variables with the letter C and a separating period.
Magic xpi provides some predefined context variables that can be divided into the
following categories:
Flow Orchestration 61
Flow Logic
Flow logic is a broad term referring to the set of conditions and rules that determines
the execution path of your project.
Conditions
Logic flow
The GoTo command
Call Flow component
Component properties (linear, wait for completion)
Flow invocation (triggers, publish and subscribe, Scheduler)
Using these tools, you can create complex logic including branches, loops, and other
flow logic that you may need. You will learn about these during this course.
Now assume that the requirement was to send a reply email to the customer to say that
his request was received by the system and would be handled shortly, what would you
do? You could add a second email step after the Send to Salesperson step. However,
this will be inefficient as these two steps are independent of one another. Why can
these steps not be executed in parallel? You can do this by creating a branch.
To create a branch:
Select the Email component and drop it on the Directory Scanner component.
You will now have two steps under the Directory Scanner step.
? You now have two steps. In which order will they be executed?
Flow Orchestration 62
Parallel vs. Linear Execution
In Magic xpi, each component could have one of three possible processing modes:
Linear
Parallel
Stand Alone
When steps are being executed in a linear mode, the Magic xpi Server executes those
steps sequentially, one after the other. The execution of the next step does not start until
the completion of the previous step.
There are situations when you will decide to execute more than one step at a time.
There are several reasons for concurrent execution such as:
Performance – If each step is executed only after the previous step has been
completed, the flow will take a long time to execute.
Independent steps – If a step is independent of a previous step, you can run these
two steps concurrently.
Long executing step – When a step takes a long time, such as a step that fetches
data from a remote database, it will hold up other steps. You can, therefore, run
other steps concurrently so that this step will not hold up execution.
In the Flow Editor, as you can see the in diagram, a linear connection is marked with a
solid line, while a parallel connection is marked with a dotted line.
You can have more than one parallel step at the same level, and all
parallel steps without a condition, or with a condition that when
evaluated to TRUE will be executed.
You may also have multiple linear components at the same level, but
only one will be executed.
Flow Orchestration 63
Wait for Completion
When there are both linear and parallel steps on the same level, there are situations
where the process needs to wait for the completion of the execution of some of the
parallel steps before continuing to the next linear steps. This may be for various
reasons, such as waiting for a returned variable from a running step.
To instruct the Magic xpi engine to wait for the completion of all other steps at the
same level, there is a special Wait for Completion flag that you can set in the flow’s
properties. This flag can be specified only on steps with linear execution mode.
When the Magic xpi Server determines the next linear step to execute, it checks if the
selected step has Wait for Completion set to Yes. If so, the Magic xpi Server will wait
for the completion of all parallel steps that will process at this level. This excludes those
steps with a condition that evaluates to FALSE. Also, parallel steps with an execution
mode set to Stand Alone are also excluded from the Wait for Completion process.
When marked with Wait for Completion, a special icon will show just above the step
on the Flow Editor (see image above).
Flow Orchestration 64
Determining the Next Step to Execute
When Magic xpi completes the execution of a step, it needs to determine which steps
will be invoked next.
The Magic xpi Server scans all the non-linear (parallel or stand alone) components in
the next level, and evaluates their conditions. The Magic xpi Server then executes all
those non-linear components where the condition evaluates to TRUE, or no condition is
defined.
Among the linear components, only one component will be executed. The Magic xpi
Server scans all the linear components in the next level that have a condition defined.
The scanning order is from left to right. If the condition of a linear component
evaluates to TRUE, Magic xpi will execute this component.
If no linear component with a condition is defined, Magic xpi will look for a linear
component without a condition. If one is found, Magic xpi will execute this component.
If Magic xpi does not find any linear component to execute, the flow is terminated.
If there is more than one component at the same level where the condition evaluates to
TRUE, the condition with the leftmost component will be selected as this is the first that
will be found.
Flow Orchestration 65
Expression Editor
The Expression Editor is where you define expressions that return a specific value to the
reference point where the Expression Editor was invoked from.
When you want to specify a condition for the execution of the step, you need to define
a Boolean expression that will evaluate to TRUE or FALSE at runtime.
To define an execution condition, right-click on the desired step, and select Condition
from the context menu.
The Expression Editor dialog box will open and provide you with the tools to define the
condition expression. Note that the dialog box’s title will show in parentheses the
expected type of the return value (in our example – Logical).
Flow Orchestration 66
Just above the editing area, there is an icon toolbar. These are tools that can help you
when constructing an expression:
Flow Orchestration 67
When typing in the Expression Editor, you can type the first few letters of a function
and press CTRL+Space. This will open a list of functions and the selected value in the
list will be the one closest to the string you have typed. Like the assistors mentioned
above, you can selected the highlighted function and paste it into the editing area at
the cursor position.
It is good practice to verify the validity of the expression before you close the
Expression Editor dialog box.
Flow Orchestration 68
Exercise
1. Add two new variables to be used in the Directory Scanner component in place
of the predefined context variables:
Name – EmailTo
Type – Alpha
Length – 100
Default Value – Salesperson’s email address (for example:
[email protected])
Add this global variable to your Email step.
3. You do not want the Email component to process if the moving of the file was
unsuccessful. Put a condition on the Email component, so that if the file name is
blank, the flow will be terminated.
4. Add the following flow variables (you will need them in the next lesson):
Summary
In this lesson, you learned about the different variable types supported by Magic xpi,
and about the flow logic that determined the actual execution path at runtime.
Flow Orchestration 69
Flow Orchestration 70
Le sson
7
Checking Customer Existence
A central part of any integration project is data transformation. In Magic xpi, one of
the main tools used for data transformation is the Data Mapper. In this lesson, you will
be introduced to the Data Mapper utility. This enables you to create associations
between records and fields in different formats from different sources by using visual
mapping. This utility is one of the most widely used utilities in the Magic xpi Studio.
Once the system receives a new request and the file is moved to the appropriate
directory, the system then needs to validate the input. The first step in this process is to
check whether the customer exists in the local database.
Magic xpi enables you to map source data to destination data. Source data can be
one of the following:
XML
Database (Select statements)
Flat file (a text file or CSV file)
JSON
Variables
ODS or UDS entries
XML
Database (Insert/Update/Delete statements)
Flat file (a text file or CSV file)
JSON
Variables
ODS or UDS entries
Call flow
Template (usually HTML or RTF)
Do the following:
1. Drop a Data Mapper utility as a child step of the Send Email to Sales step.
2. Name the step Extract Details from Request.
3. Double-click the Data Mapper utility, or right-click on it and select
Configuration from the context menu to open the Data Mapper window.
You can have multiple sources and destinations. For each of the entries you will need
to define the properties. Each set of properties will be different, depending on the
object type. For example, Variable properties will be different from Database
properties.
In the image below, you can see an XML file as a source and flow variables as a
destination. When the source and the destination are configured and connected, and
this step is executed, the Data Mapper will map elements from an XML file to variables.
For this example, the source type will be XML and the destination type will be
Variables.
Every type in the Data Mapper has a different set of properties. To set
the properties for a specific entry, right-click on it and select
Show Properties.
In the current lesson, you must define properties for the XML source
and for the Variables destination. In most cases, the properties will be
the same regardless of whether the specific type is in the Source Tree
or the Destination Tree.
Do the following:
4. From the Toolbox’s Mapper Schemas section, drag an XML source into the
Data Mapper window’s Source Tree area.
5. Right-click on the XML source and select Show Properties.
6. Enter Request in the Name property.
Property Description
XSD File This is the path to the XML schema. You have to specify the
exact path and file name for the XSD file.
XML Root Select the XML root that you want to map data from.
Note that you will only be able to park on this field when there
is more than one root element in the XSD file. Magic xpi will
default to the first root element that it finds.
XSD Sub Type The Source schema's subtype. Select one of the following
options:
File
IFC Model
XML Position Forwarding (Source only)
IFC Model This property lets you select a predefined XSD to use as XML
data. This provides an easy way of using the XML Schema
Definition (XSD) for any flow component.
XML Position This option enables the XML Source data to start mapping from
Forwarding the saved start position, by calling the flow.
(Source only)
For example, if you have an order entry, where each XML
order file includes one order header and multiple order items,
the order header is handled in the main flow. The multiple
order items are handled in a second (called) flow. If you select
XML Position Forwarding, the called flow handles single order
items instead of reprocessing the entire XML.
Source Type There are various options for the source of the data:
File – This is an external XML file, where the data is being
stored. If you select this, you can click on the button in
the File Path field to enter an expression for the file.
Variable – This is a BLOB variable that the data is stored in.
If you select this, you can click on the button in the
Variable field to get a list of valid variables.
XML Validation This validates that the XML is in a valid format according to the
schema, before you start mapping. If the XML is not in a valid
format, you will get an error.
Recursion Depth This property will determine how many times the structure of the
selected XML file repeats.
Example: If a parent node in the XML structure contains three
children, enter 3 to repeat the structure three times. For no
recursion, leave the default of 1.
Data Format This property lets you define the defaults that you want
Magic xpi to use when presented with a certain data type.
Use Streaming Parser Select this check box to use a streaming XML parser. This
(Source only) allows the Data Mapper to handle large XML documents.
Do the following:
Do the following:
10. From the Toolbox’s Mapper Schemas section, drag a Variable destination into
the Data Mapper window’s Destination Tree area.
11. Right-click on the Variable destination and select Show Properties. In the
Properties pane, enter Variables in the Name field.
You will now select some variables that you defined in the previous lesson:
12. In the Variable destination’s Properties pane, click the Variables field’s
button.
13. In the Destination Properties dialog box, select the following variables:
F.ContactName
F.CustomerEmail
F.CustomerId
A white line will appear connecting the source to the destination. A double white line
will appear connecting the request to the instance. This line denotes that for every
occurrence found in the XML, it will be copied to the F.CustomerID variable. Note that
a blue color for the connecting line simply denotes the connection currently in focus.
When working with data, you often need to use database tables. You fetch data from
tables according to a set of rules and you write data to tables.
For example, after receiving a request with a Customer ID, you need to check whether
that client is a customer in the local database and what the customer's credit rating is.
If the client is not a customer, you will need to add the client to your database.
The Data Mapper utility provides the tools needed to work with databases.
A database object may be used as either a source or a destination object in the Data
Mapper. However, as discussed earlier, the mapping of a source to a destination is a
Read/Write scenario; therefore, not all database operations are valid in both trees.
The valid options are:
Select – Source
Insert – Destination
Update – Destination
Delete – Destination
Various MSSQL tables are used in this course. For information on the various tables
and how they connect to one another, please look at the Course Data section, which
you can find right before the Solutions appendix.
1. Drag a Data Mapper utility as a child step of the Extract details from request
step. Name this step Check if the Customer Exists.
2. Double-click the Data Mapper utility, or right-click on it and select
Configuration from the context menu to open the Data Mapper window.
3. From the Toolbox’s Mapper Schemas section, drag a Database source into the
Data Mapper window’s Source Tree area.
4. Right-click on the Database source and select Show Properties. Set
CheckCustomer as the Name.
Wizard – You can create an SQL statement visually with the Database Wizard.
SQL Statement – You can create an SQL statement manually.
Dynamic SQL Statement – You can determine whether you want to write your own
INSERT/UPDATE/DELETE statements, which will be executed "as is".
Database Definition – A list of the defined resources for databases. If you have not
previously defined a resource or want to add a different one, you can click the
New option in the dropdown list, which will enable you to add a new resource.
DB Disconnect – Defines whether all open connections to the database will be
disconnected at the end of the step.
Error Handling Flow – Enables you to handle exceptions using a specific error flow
mechanism. This is only valid for Database operations that are defined as
destinations.
Wizard – This will guide you through the necessary steps to create a valid SQL
statement.
SQL – This enables you to enter your own SQL statement.
5. In the Properties pane’s Wizard field, click the button. The Database
Wizard opens.
The wizard shows a list of the tables found in the database. There are two selection
panes which enable you to select which tables will be used. You use the buttons to
select the tables. In the Selected Tables list, there is a list of tables that have been
selected. If you want to remove a table from the list, you can park on it and click
Remove. To select the Customers table:
Filter Definitions Only – This check box lets you select the owner and the tables that
will be fetched for the Select Table operation. You can select a specific owner and
view all of this owner's tables, or you can select only a subset of these tables.
Available list by owner – This enables you to filter the list according to a certain
owner or to display all of the tables. Bear in mind that there may also be system
tables in the list.
The Select Columns dialog box displays a list of the columns or fields found in the
tables that were selected. The Display Field Order field lets you define the order in
which thedatabase fields will be displayed – either as defined in the table or in
alphabetical order.
In the Select Columns dialog box, you select which table columns will be fetched from
the tables. Remember that the result will be a database SELECT statement. The columns
displayed are those that are defined in the tables you selected in the previous step.
Available Columns – A list of all the columns in the tables you selected.
Variables – The list of variables that you can use.
To select an item from the list, you need to park on it and double-click. You may select
any entry more than once.
After clicking Next, you are presented with the Summary dialog box. Here you see the
result of what you previously defined. You can make changes to the SQL statement if
necessary.
The next stage is to map the record retrieved by the Data Mapper to a variable. You
already learned how to do this earlier in this lesson.
15. From the Toolbox’s Mapper Schemas section, drag a Variable destination into
the Data Mapper window’s Destination Tree area.
16. Right-click on the Variable destination and select Show Properties. In the
Properties pane, enter CustomerName in the Name field.
17. In the Variable destination’s Properties pane, click the Variables field’s
button.
18. In the Destination Properties dialog box, select the F.CustomerName variable.
19. Expand the source and the destination.
20. Connect the CustomerName node on the source to F.CustomerName in the
destination.
1. Pull the Contact ID from the Request XML. You will need to create a flow
variable to accomplish this.
2. Now that you have the Contact ID from the Request XML, you need to check
that ID against the Contacts table to see if the contact exists.
3. If the contact does not exist, add an Email component to send an email back to
the customer stating the following 'You are not registered as an official contact
for your company. Please approach your representative. '
Summary
In this lesson, you learned about the Data Mapper utility. You learned how to:
As you develop a project, you provide instruction and configure each component. You
also provide flow logic that instructs Magic xpi what component to execute, and in
what order.
When you want your project to execute, you start a background process that reads
those instructions and executes the components according to the flow logic. This
background process is the Magic xpi Server.
Runtime Environment 87
The Executable File
When you installed the Magic xpi Suite, the installation program installed several
components. These include the Magic xpi Studio, the Magic xpi Server, the Magic
Monitor, and the GigaSpaces middleware.
When you are in development mode and save the project, Magic xpi saves the project
definition files in XML format in the <My Documents>\Magic\projects\<Project
name>\current project\Source directory.
The first step in executing a project with the Magic xpi Server is building an executable
file. When you want to deploy your project, you need to save the project as an
executable file (ibp).
To do this:
If the file was already built, you can select Rebuild Solution, or simply press
CTRL+SHIFT+B.
Runtime Environment 88
When the Magic xpi Server loads, it executes in the background and as such has no
user interface. It automatically loads a project and executes it. The project that is
executed is determined by two environment variables:
currentprojectdir – This variable holds the path to the folder where all the project
files reside, including the project file itself. If you did not change the default setting,
this folder contains the name of your projects. It is located in the projects subfolder,
which is in the Magic xpi installation folder.
currentproject – This variable holds the complete path and file name to the project
file itself. This file was created when you built the executable file.
Both of these environment variables are predefined, and are updated automatically by
the Magic xpi Studio.
When you build an executable file, the Magic xpi Studio updates the project shortcut
on your Windows Start menu. This enables you to control the execution of the project
using the Magic xpi Server.
Under the Projects folder, you will find an entry with the name of your project, and two
shortcuts in a submenu. These are:
Runtime Environment 89
Executing a Project
When a Magic xpi project starts, the Magic xpi Server loads the project metadata and
performs a series of initialization activities. The following list describes the Magic xpi
project’s initialization phase:
At this point, the Magic xpi Server executes the project according to the flow logic.
Each activity is logged in the messaging system and can be viewed using the
Magic Monitor (see later in this lesson).
The Flow Manager is the part of the Magic xpi Server that is responsible for the actual
execution of the flow. After a component is executed, the Flow Manager checks for
errors by examining the error return code, and executes the internal error handler or
invokes the error flow. If there are no errors, the Flow Manager checks the return status
code and executes the internal logic handler or the logic component, if one is defined.
Once the internal variables are set, the Flow Manager decides which component will
be executed next, based on the flow logic. You will learn more about error handling
later in this course
The Flow Manager is also responsible for calling steps in a different Server, using the
Magic xpi routing system, if the next step is set to run on a remote Server.
If transactions are defined, the Flow Manager is responsible for managing the
transaction by sending Start Transaction, Commit, and Rollback commands as
required.
Runtime Environment 90
Magic Monitor
The Magic Monitor is a tool that enables you to track the execution of your project by
giving you accurate information about your projects in a single intuitive and easy-to-
use dashboard. You can view the information for whole projects or you can select
different levels within projects, and you can use filters to display information from
specific times. The information displayed is updated regularly. The status of each
project is taken from the Space.
You open the Monitor from the Windows Start menu's Magic Monitor shortcut. By
default, this link points to the local host. You should change it to link to the host running
the Magic Monitor services:
2. Select Properties.
Runtime Environment 91
4. Change the URL to point to the host running the Monitor services. If, for
example, the host that runs the Monitor services is 10.1.3.75, you would
change the URL to: http://10.1.3.75:8068/magicmonitor/panels.jsp
Note: By default, the Magic Monitor Web Server uses port 8068. To change this port,
open the <Magic xpi installation>\Runtime\RTView\servers\apache-tomcat-6.0.18-
sl\conf\server.xml file, and then change the Connector port parameter to any non-SSL
HTTP/1.1 port.
The Magic Monitor shortcut will open a link in a browser and the following login
screen will appear.
Username – admin
Initial password – changeit
When you open the Magic Monitor, you see the Magic xpi Dashboard. This displays
top-level information about all the projects that are connected to the server, such as
license details, Space status, threads in use, and messages. To get more detailed
information about specific projects, you can click one of the links that are grouped
together under Actions.
Runtime Environment 92
This opens the Magic xpi Projects Dashboard.
Projects pane – On the left of the screen, this shows a list of available projects. You
can control your projects using the Start, Stop, and Restart buttons.
Project View – Covering the rest of the screen, this gives you detailed information
about your projects, including messages, license usage, available workers, alerts,
and trigger activity. You can adjust the time span of the displayed information.
At the top of the Magic xpi Projects Dashboard, you can click the Messages, Flows,
Triggers, Servers, Locking, Subscription, Scheduler, Activity Log, ODS, BAM, and
Summary tab buttons to navigate to specific project information.
Runtime Environment 93
Activity Log
The Magic Monitor’s Activity Log tab displays detailed information about the
Magic xpi Server log messages. There are various check boxes and dropdown lists
that enable you to filter the information that is displayed. You can add your own
messages to this log, as you will learn in the next section.
Name Description
Date & Time This column displays the date and time the message was written to
the log. The time is displayed in milliseconds.
Message Type The message that is written to the log. The message describes the
action taking place. Messages displayed include:
When the Server started and when it ended.
When the flow started and when it ended.
When the component started and when it ended.
An error message appears in red.
Message String This column displays the text attached to the log process. This text
has additional information about the execution process.
FSID This is the flow sequence ID in the execution process. If the message
is general, and not part of a flow, this number is zero.
BLOB This column holds any BLOB file that is part of the message.
Runtime Environment 94
Exercise
In previous lessons you used the Magic xpi Debugger to see Magic xpi in action. You
will now run the project using the Magic xpi Server. You can use the following
checklist:
Summary
In this lesson, you learned about the Magic xpi Server and the Magic Monitor.
Runtime Environment 95
Runtime Environment 96
Le sson
9
Testing Your Project
You learned how to develop an integration project, and you learned how to deploy it.
Before moving your project to production, you need to test your code and make sure it
works correctly.
Magic xpi provides several tools to help you test and debug your project, so that you
can deliver it error-free.
In a previous lesson, you were introduced to the Magic xpi Debugger. This enables
you to test your flow. You will learn more about the Magic xpi Debugger in this lesson.
The Checker starts automatically when you start the Debugger, or when you save an
executable file for deployment.
The Checker will disable part of the project or the whole project, if errors are found, as
follows:
When activated with the Debugger, an executable file will not be created at all.
When activated as a part of the Build Executable File process, flows with errors
will be changed to an inactive state. It is therefore possible that the entire project
will be inactive.
From the Project menu, select Checker... and then Run to run the Checker on the
whole project (this option can be activated by typing CTRL+R).
From the flow’s context menu, select Checker... to check the selected flow only.
The Checker does not check any logic within the step.
The Checker Results screen lists every item checked and indicates areas where there is
an error. The errors are displayed with an indication of their severity on the following
levels:
Type Description
Error This is the most severe level. It indicates a fatal error, which means
that the step will not work.
An example of a severe error is: Missing component configuration.
This indicates that mandatory configuration information is missing
from the component.
Warning This indicates an error that does not prevent the step from executing.
Results at deployment might not be what you expected based on your
project definitions.
The filter buttons at the top of the Checker Results screen let you define which types of
Checker messages to display.
The Debugger runs your project or attaches to a running project. It gives you the ability
to control and view execution sequences, flow variables, the calling of Magic xpi
services, and breakpoints. You can execute steps one at a time, or you can run the
execution automatically until you reach a breakpoint.
Magic xpi executes the project in Debug mode using the running Server engine.
You can view all property-type settings for steps, but only in read-only mode. To make
any necessary changes, you will need to stop the Debugger process, go back to the
Flow Editor and make the changes, and then return to the Debugger to restart the
process.
Open mode – Opens a project on a local machine. You can do this from
the Debug xpi menu by selecting Start Debugging, by pressing F5, or by
clicking the Debugger icon in the toolbar.
In a previous lesson, you selected Debug from the flow’s context menu
to debug a specific flow. However if you select to debug a specific
flow, any other flows in the project will be disabled.
Option Description
Stopped The Server is waiting for a command and will not execute until it receives one.
Running The Debugger is currently running one flow or more.
The current mode is displayed in the form header, as shown in the image below.
To execute the Debugger, you need to select Start Debugging from the
Debug xpi menu or the icon from the toolbar.
The following options are available when the Debugger’s mode is Stopped.
Windows Opens the Breakpoints and Suspends pane and the Output pane.
Start Debugging Runs the project until a breakpoint is reached, or there are no
more steps to execute.
Attach to Project Lets you start the debug session in Attach to Project mode.
Project Settings Opens the Debugger Settings dialog box. Here, you can define
the refresh rate timeout and other debugging options.
Settings Opens the Options dialog box and takes you directly to the Magic
xpi Debugger section's General settings. Here, you can configure
the Debugger's timeout settings for your project.
The following options are available when the Debugger’s mode is Running.
Windows Opens the Breakpoints and Suspends pane and the Output pane,
as well as other various panes.
Break All Stops the execution of the project as soon as the execution of all
currently running steps is completed.
Step Execute single step. Active only when the Debugger is in Stopped
mode.
Scheduler Lets you see the upcoming events schedule when you reach a
breakpoint in the flow, based on your Scheduler table.
Context View Opens the Context View for the currently selected step.
The Debugger then waits until the user selects Step or Continue.
To activate the breakpoint on a step, select the step and then select
Breakpoint from the context menu.
In the image on the right, you can see the step that is marked as a
breakpoint.
To suspend a step, select the step and then select Suspend Step from
the context menu.
When a step is defined as suspended, its icon and text will appear
dimmed.
In the image on the right, you can see the step that is suspended
since it is dimmed.
The top-most (root) step and the bottom-most steps do not have the
Suspend Branch option.
There is only one active debug context available at a specific time. The first context
that reaches a breakpoint is set as the active debug context. You can set any context
as the active debug context by right-clicking and selecting Set Active Context. When in
Step mode, the focus of the debugging process is always on the active context. You
can only step through a context if it is set as the active debug context. You will learn
about running other contexts later in this course.
The Context Tree uses various colors and indications to provide you with additional
information, as follows:
The Context Tree uses various icons to enable you to quickly identify each context type.
The icons used in the image displayed above are:
Auto Start
Linear Step
There are other icons available. You can view them in the Magic xpi Help.
This option is available only when the Debugger has stopped; for example, at a
breakpoint. It shows the values of all variables in the scope of the current context of the
current step, the highlighted step in the Context Tree.
To activate the Context View, make sure you are parked on the correct step and then
select Context View from the Debug xpi menu. Alternativey, you can right-click on the
highlighted step in the Context Tree, and then select Context View.
The Context View form has four tabs, one for each type of Magic xpi variable.
You can change the variables’ values from this dialog box. This is very useful when
debugging a project.
Using the Logging properties of the component that you want to debug.
Adding a Save Message utility.
Logging Section
The Logging section is one of the sections in a component’s Properties pane. You are
able to specify any string and/or BLOB information to be sent to the Magic Monitor’s
Activity Log tab.
You have the option to send only a string message, a BLOB variable, or both.
Logging Scope
Using the Logging Scope property, you can specify when the information is to be sent
to the Magic xpi Activity Log view.
No – Nothing will be written to the Activity Log tab. This is the default.
Step – Magic xpi will write information to the log for the entire step.
Method – Magic xpi will write information to the log for each method in the step.
This will be carried out after the method was executed.
Full – Magic xpi will write information for both the Step and the Method options.
The XML interface does not allow Method level logging.
As an example, add logging details to the Logging tab of the Send email to Sales
component. In this example:
Summary
In this lesson, you learned how to:
According to the business scenario, once the system receives a new request and the
check for the customer is successful, the system will then need to check that the
requested items exist in the database.
Use the Flow Data utility to update variables and to store the request data in an
ODS.
Call a flow that checks the stock availability for each of the request's items.
The following table describes the different parameters of the Flow Data utility:
Parameter Description
Type The type of the target variable that the action will be performed
on:
Flow
Context
Global
Business Process
ODS Global
ODS Local
Environment
Name The name of the target variable. When the action is Delete, and
the type is ODS, you can leave this field blank in order to delete
all ODS variables.
Data Type The data type of the variable. This type is filled in by the system
based on the target variable that you selected. You can select the
type only for ODS when the action is not Delete.
Encoding The encoding type for updated BLOB and Alpha variables.
Index The index of the ODS record in the ODS data array.
Update Expression The value of target variable in an Update action will be updated
with the return value of this expression.
1. In the Solution Explorer, under the Scan for New Requests flow, double-click
Flow Variables and add the following variable to the Flow Variables
repository:
In the company scenario, the request will be added to the system even if the company
is unknown. This will be in two separate threads.
You need to initialize the C.All_Items_Exist context variable and save the request
number in the F.RequestNum flow variable.
6. Add a Flow Data utility as a child step of the Check if the Customer Exists step.
7. In the Properties pane’s Step Name field, type: Get Req number from FileName
8. In the Description field, type: This service updates the RequestNum variable
and initializes the All_Items_Exist variable that will be used later on.
9. Double-click the Flow Data utility, or right-click on it and select Configuration
from the context menu to open the Flow Data Configuration dialog box.
10. Click Add to add commands.
To retrieve this number you will be using the following functions in the next step:
Trim – This removes trailing blanks from both the left and right sides of the
expression, so you will use: Trim(F.RequestFileName)
Right – This function fetches a number of characters from the right side of the
expression. The idea is to retrieve the value 003.xml, which is 7 characters from
the right, so you will use:
Right (Trim (F.RequestFileName), 7)
Mid – This function retrieves a string from within another string. You set the start
point and how many characters you want to retrieve. The previous expression left
you with 003.xml. All you need is the first three characters, 003, so you will use:
Mid (Right ( Trim (F.RequestFileName), 7), 1, 3)
Val – This function takes a string with digits and converts it to a numeric value. The
previous expression returned the string ‘003’. This needs to be converted to a
number, so you will use: Val (Mid (Right ( Trim (F.RequestFileName), 7), 1, 3), ‘5’)
Note that you will see 3 and not 003, this is the expected behavior.
11. Add the following commands to the Flow Data step:
Unlike a data warehouse, which contains static data, the contents of the ODS are
updated through the course of business operations.
ODS is designed to quickly perform relatively simple queries on small amounts of data
(such as finding the status of a customer order), rather than complex queries on large
amounts of data, typical of the data warehouse.
ODS is similar to a person’s short term memory in that it stores only very recent
information. In comparison, the data warehouse is more like long term memory in that
it stores relatively permanent information.
The ODS system manages a data table that maintains an entry for each item saved in
the ODS.
Each item saved in the ODS is identified by its flow sequence ID and UserKey. An
ODS data item can be Alpha, Numeric, Date, Time, Logical, or BLOB. The data saved
in the ODS system can be retrieved by other Magic xpi Servers.
The Magic xpi ODS system supports the store, retrieve, and save data-retrieval modes.
If, during project development, you use the local flow storage (ODS Local), the
data is saved in the ODS database for a particular thread. The saved data can be
retrieved by steps in the same thread only. The data is cleared from the ODS
database when the particular thread is completed.
If, during project development, you use the global storage (ODS Global), the data
is saved in the ODS database and can be retrieved from within any flow.
1. Double-click the Get Req number from FileName step, or right-click on it and
select Configuration from the context menu.
2. In the Flow Data Configuration dialog box, click Add.
3. Enter the following information for the command:
Selecting the Dynamic check box indicates that the name will be a
dynamic name, meaning that it will be evaluated as an expression.
In the example above, the name will be evaluated to Request_1.
In the case above, the flow was executed twice with the same request number. Each
time the flow was run, an entry was added to the ODS. Magic xpi automatically
provided an incrementing index in order to differentiate between the instances. At a
later stage, the challenge will be how to retrieve the index you are looking for.
If a BLOB has been added, you can view its contents by clicking the BLOB icon.
To solve this problem, you will create a flow that checks each item's availability in the
database. The flow will check the stock availability of one item and later, you will call
this flow for each of the request's items.
1. In the Solution Explorer, right-click on Business Process-1 and select Add Flow.
2. Right-click on the new flow and select Rename
from the context menu.
3. Change the flow name to Check Item.
First, you need to add flow variables that will be used in the flow:
F.ItemCode Alpha 30
F.RequestNum Numeric 5
The flow variables defined in this flow will become parameters for the
flow when it is called by other flows.
10. From the Toolbox’s Mapper Schemas section, drag a Database source into the
Source Tree area.
11. Right-click on the Database source and select Show Properties.
12. Enter CheckItem in the Name property.
13. Use the Database wizard or the SQL option to:
The C.All_Items_Exist variable will updated if there is enough of the item in stock.
However, if a previous iteration found that there were not enough items in stock, this
variable need not be updated. To do this:
21. In the Data Mapper, park on the C.All_Items_Exist node and select
Show Properties from the context menu.
22. Park on the Calculated value property and open the Expression Editor.
You need to use the value returned from the database SELECT statement to update the
check by the C.All_Items_Exist value.
Here is something for you to think about. What will happen if the user
You will now add a Data Mapper step with a Call Flow destination to the Check Item
flow. By using the Call Flow, the Data Mapper will invoke the Check Item flow for each
item in the order.
6. From the Toolbox’s Mapper Schemas section, drag an XML source into the
Source Tree area.
7. Right-click on the XML source and select Show Properties.
8. Enter Items_from_Request in the Name property.
9. In the XSD File field, type: course_data\schemas\request.xsd
10. Set the Source Type field to Variable.
11. Open the Variables List and select the F.RequestXML variable.
12. From the Toolbox’s Mapper Schemas section, drag a Call Flow destination into
the Data Mapper window’s Destination Tree area.
13. Right-click on the Call Flow destination and select Show Properties.
14. Enter CheckEachItem in the Name property.
15. In the Flow Name property, open the Flow List and select the Check Item flow.
In the Destination Tree area, you will see that all the flow variables defined in the
destination flow are used here as parameters of that flow.
17. Connect the item compound node in the Source Tree area to the Check Item
node in the Destination Tree area. By doing this you are ensuring that for each
item found, you will be invoking the Call Flow operation.
18. Open the Item node and connect the following nodes:
partNum to F.ItemCode
quantity to F.Quantity
19. Park on the F.RequestNum node in the Destination Tree area.
20. In the Properties pane, park on the Calculated Value property and type
F.RequestNum. Although it seems that you are updating the F.RequestNum
variable with itself, this is not the case. The F.RequestNum displayed in the
Destination Tree area is the name of the flow variable in the called flow,
Check Item.
1. The called flow Check Item checks whether there is enough stock to supply the
required amount. However, two problems arise that you need to handle:
The request header details must be inserted into the Requests table.
Remember to update the Requests.CustomerExists field.
Hint: The customer does not exist if the F.CustomerName variable is
blank.
The request lines must be inserted into the RequestItems table. Remember
to update the RequestItems.Status field. If the current request line is valid,
update this with 'TRUE'Log, but if there is a problem update this with
'FALSE'Log.
Hint: Do this in the Check Item flow.
3. Create an initialization flow (Auto Start) that deletes all the records from the
Requests database and Items table.
Summary
In this lesson, you learned how to:
In the exercise, you used the Data Mapper to insert and delete entries from the
database.
You learned about resources and the Resources section of the Settings dialog box in
Magic xpi. In a similar way, Magic xpi maintains a central repository defining the
external methods that other applications can use to interface with Magic xpi. As with
the Resources section, the Services section is also found in the Settings dialog box. The
Settings dialog box can also be opened from the Start menu in stand-alone mode.
Services 123
Services Section
The main purposes of a centralized Services section are:
Reusability – A service can be used more than once throughout the project. For
example, an external queue manager such as MSMQ can be used in several
places. Instead of defining and maintaining the definitions for each instance
separately, you can define it once.
Flexibility – The services are defined in a separate file and can be configured
outside the project. When migrating the project between different operating
environments, no changes are required to the project.
Ease of maintenance – All services are defined in one central location. You do not
need to look throughout the project to locate where services are being used.
The Services section provides a list of all services that the project provides to external
sources. It is good practice to add a brief description to make the list more meaningful.
Services 124
To add a new service:
1. Click Add.
The New Service dialog box opens.
2. The Service Type dropdown list contains
a list of all the predefined service types.
Magic xpi has a predefined a list of service types. For each service type there is a list
of configurable properties.
These definitions are per Magic xpi installation and affect all projects.
Once the service has been added, you need to configure it. The configurable settings
for each service type are different.
As an example, you will continue with the HTTP service that you have added. When
you park on the service, you will see the list of properties for that service. As has been
discussed, a service is an external resource and is often first defined in the Resources
section of the Settings dialog box. You will use this service in the next lesson, when
you define an HTTP trigger.
Services 125
For HTTP, there are two parameters:
Web Server – This is the name of the website where the Magic xpi requester
resides. The default value is %MachineName%. This is a predefined environment
variable, and its default value is the name of the local machine.
Alias – The website's alias name. The default is %Alias%, this is a predefined
environment variable. Its default value is Magicxpi4.5. You will leave the default
values unchanged.
There is no limit to the number of configurations that can be created for a single
service type.
Services 126
HTTP Endpoints
When using the HTTP service, an external HTML form calls Magic xpi and activates a
flow. This form of invoking a flow is called a trigger, and will be discussed in detail in
the next lesson.
When calling such a trigger, the calling HTML form may submit additional information
required by Magic xpi to service the request. This additional information has to be
predefined in Magic xpi. Each such predefined set of passed values, their names and
types is called an endpoint.
To activate the trigger and consequently invoke the flow, the URL must be defined in
the following way:
Where:
ComputerName is the name of the local computer where Magic xpi resides.
Magic xpi instance is the Magic xpi alias. This will be Magicxpi4.5 in the current
version.
/MgWebRequester.dll?appname=IFS is constant and must be part of the address.
ProjectName is the name of the current project.
&prgname=HTTP&arguments=-A is constant and must be part of the address.
Service Name is the name of the HTTP service in the Services section.
Endpoint name is the name you gave to the endpoint.
Argument Name=value is the name of an argument passed to the trigger with its
corresponding value.
Services 127
For example, the following is a legal address:
http://localhost/Magicxpi4.5/MgWebRequester.dll?appname=IFSMagic_xpi_course
&prgname=HTTP&arguments=-ARequestConfirmation%23check_request_status&
RequestNum=5
You can also send a request to the Server by using a form and hidden input tags for
the arguments. You can generate a sample form by selecting the
Generate Sample HTML checkbox in the Endpoint dialog box. You will use it in the
exercise at the end of this lesson.
The generated sample HTML file will be created in the following directory:
%currentprojectdir%Service\<Service Name>, where Service Name is the name of the
service, in this case, RequestConfirmation. You can define your own path.
Services 128
Exercise
1. Create an endpoint called check_request_status.
2. Create an HTML page to invoke the service by using the
Generate Sample HTML option.
3. Pass the request number in a variable called RequestNum.
Summary
In this lesson, you learned about:
Services 129
Services 130
Lesson
12
Checking Request Status
Sometimes, in an integration scenario, human intervention is required. The transaction is held
in persistent memory, such as a database, until reviewed by a person.
In this lesson, you will learn how to invoke a flow by using an external triggering mechanism
and will see an example of this from an Internet browser. You will learn how to create a
dynamic HTML file which you will return to the calling Internet browser. While doing this, you
will learn a method of implementing a scenario of human intervention.
This lesson contains various topics, including:
The Flow Editor provides a special section to define flow triggers. When you include
components in the Triggers area section of the Flow Editor, these components serve to activate
the flow when the trigger component receives the appropriate information.
Another flow trigger is provided by the Scheduler utility, which will be discussed in a later
lesson.
1. In the Solution Explorer, right-click on Business Process-1 and select Add Flow. Name
the flow: Check Request Status
If you want this flow to be above the Initialization flow, you can park
on the flow and select Move Flow Up from the context menu.
Next, you will set four flow variables that will be used in the flow, and one environment
variable that points to the templates folder location.
Under the Check Request Status flow:
The Component Configuration dialog box opens. The dialog box has two sections, the Service
Details and the Argument Details.
The arguments will be mapped to an internal Magic xpi variable by selecting the Variable
Selection box in the Mapping Variable column.
These are the parameters that are sent from the external Internet browser to Magic xpi,
and will then be used within the flow. Each mandatory argument has to be mapped to a
variable.
The Return Value is a BLOB variable that will be passed back to the Internet browser for
display. This is in the form of a valid HTML script.
The Validation Expression defines limits to the trigger. You can open the Expression Editor
to create an expression. In this way, you can create conditions for triggering the flow by
creating a validation expression.
When you click the variable selection buttons, you will not see any of the variables that you
used in the Scan for New Requests flow. This is because you defined these variables as flow
variables, and flow variables are localized to the specific flow in which they were defined.
7. Park on the Mapping Variable column and click the button. Select
F.HTTP_Request_Num from the selection list.
8. Park on the Return Value variable and select the F.Result_HTML variable.
9. Click OK to close the dialog box.
5. From the Toolbox’s Mapper Schemas section, drag a Database source into the Source
Tree area.
6. Right-click on the Database source and select Show Properties.
7. Enter Scan_Requests in the Name property.
8. In the Database Definition field, select the Course Database entry.
9. Click Wizard:
a. Note that the DB Operation property is set to Select by default. This is the only
option for sources.
b. Select the Requests table.
c. Select the CustomerID, and CustomerExists columns.
d. You need to select only the request entry that the user requested when they
passed the Request ID. So, the WHERE clause will be:
[Requests].RequestId = <?F.HTTP_Request_Num?>
10. From the Toolbox’s Mapper Schemas section, drag a Variable destination into the
Destination Tree area.
11. Right-click on the Variable destination and select Show Properties.
12. Enter Create_HTML_Header in the Name property.
13. Select the F.RequestExists, F.CustomerExists, F.CustomerId and F.RequestHeader flow
variables.
14. Expand the source and destination.
15. Map CustomerId to F.CustomerId and to F.RequestHeader.
16. Map CustomerExists to F.CustomerExists and to F.RequestHeader.
17. When the Data Mapper executes, it will fetch only those records where
[Requests].RequestId = <?F.HTTP_Request_Num?>. Therefore, set the F.RequestExists
variable’s Calculated Value field to 'TRUE'LOG.
The Calculated Value checks whether the customer exists, and then adds a hyperlink under the
Customer ID, if the customer does not exist.
The expression above seems complex, so a little explanation is necessary. To add a hyperlink
under the CustomerID value, you need to use an HTML tag called an anchor. This has a syntax
of <a href="link">text</a>. The double quotation marks, ", are important here. In the
example above, the link will be '<a
href="http://localhost/Magicxpi4.5/MgWebRequester.dll?appname=IFSmagic_xpi_course&
prgname=HTTP&arguments=-ARequestConfirmation%23add_customer&RequestNum=' & Trim
(Str( F.HTTP_Request_Num,'5')) & ' ">'.
You are using the HTTP service named RequestConfirmation. You can see the addition of the
add_customer endpoint to the hyperlink.
1. Add a Data Mapper utility as child step of Get Information from DB. Name it Get
Customer Information.
2. Double-click the step, or right-click on it and select Configuration from the context
menu.
3. From the Toolbox’s Mapper Schemas section, drag a Database source into the Source
Tree area.
4. Right-click on the Database source and select Show Properties.
5. Enter Fetch_customer in the Name property.
6. Click Wizard:
If the CustomerId does not exist, this Data Mapper step will not fetch any details.
7. From the Toolbox’s Mapper Schemas section, drag a Variable destination into the
Destination Tree area.
8. Right-click on the Variable destination and select Show Properties.
9. Enter Create_HTML_Header in the Name property.
10. Select the F.RequestHeader flow variable.
11. Expand the source and destination.
When the Data Mapper executes, it will fetch only those records where
[Customers].CustomerID=<?F.CustomerId?>.
This is an important expression. If the customer is found in the database, you will
update the HTML with the name fetched from the database. But if the customer does
not exist, you will use the information that you updated in the previous step.
<!$MG_name> – The name part of the tag is represented as a node in the destination
schema in the Data Mapper utility.
<!$MGREPEAT> – Defines the beginning of a repeated area that is represented in the
Data Mapper utility as a compound. The repeated area is duplicated and processed for
each iteration of the connected compound, thereby allowing for an unknown number of
data rows.
<!$MGENDREPEAT> – Defines the end of a repeated area and is not represented in the
Data Mapper utility.
You can also define a section of the file that will be displayed in the final output according to
a logical expression.
<!$MGIF_name> – Defines the start of an IF block. This is logical data. If the data is True,
the rest of the IF block is processed. You can have nested IF blocks. The MGIF simply
defines the start of a block, and the tag itself will not appear in the output.
<!$MGENDIF> – Defines the end of an IF block. If there is an IF block, this is mandatory.
<!$MGELSE> – Defines the start of an ELSE block and the end of an IF block, which must
precede the ELSE block. The ELSE block is processed if the name data value of the IF block
evaluates to False. This tag is optional. The tag itself is removed from the output.
4. Test your project using the HTML page that you created in a previous lesson. You can
find the HTML file in the directory: %currentprojectdir%Service\RequestConfirmation.
Summary
In this lesson, you learned about:
The integration project needs to be able to detect and identify potential errors as soon
as they occur, report those errors, and continue to work and stay stable.
The monitoring, processing, and handling of error situations are an integral part of any
project.
The values in the following variables can only be used in the condition following the
step that raised the error. They are cleared before entering the next step:
The following variables assist you in identifying the origin of the error:
C.sys.LastErrorFlowName – The name of the flow where the last error occurred.
C.sys.ErrorStepName – The name of the step that invoked the last error.
Finally, the following variables hold information about the last error. They are only
updated when a new error occurs:
C.sys.LastErrorCode – The last error code. This remains until there is a new error.
C.sys.LastErrorDescription – The last error description. This remains until there is a
new error.
C.sys.LastErrorInfo – Contains full information about the error. It is a BLOB and can
contain an SQL statement, a Java error, and others.
The simplest way of checking for an error is by checking the error code contained in
the error variables. You check the value in C.sys.ErrorCode before entering the next
step.
1. Park on the Scan for New Requests flow. Add an Email component as a child
step of the Extract Details from Request step.
2. Name the step: Send Thank You Email
3. Set the Processing Mode to Parallel.
4. Select the Method interface.
5. Double-click the step, or right-click on it and select Configuration from the
context menu.
6. Click Add. Select Quick Send and set the following:
a. To: F.CustomerEmail
b. Subject: 'We received your request.'
c. Body: 'Thank you for your request. We are currently checking into
it.'&ASCIIChr (10)&'MSU Computers'
7. Add an Email component as a child step of the Send Thank You Email step.
Name the step: Send Error Email.
8. Select the Method interface.
9. Double-click the step, or right-click on it and select Configuration from the
context menu.
10. Click Add. Select Quick Send and set the following:
a. To: [email protected]
b. Subject: 'Email to the customer was returned.'
c. Body: 'This is an automatic notification. Please do not reply.'&ASCIIChr
(10)&'An email to a customer failed.'
When you run this flow with an invalid email address, you will get an error that is
handled by this flow.
In flow level error handling, Magic xpi enables you to define automatic behavior for
certain errors. You can define an error policy for a range of error codes in the
Errors Policies repository. This repository is accessed by double-clicking Error Policies
under the relevant flow.
When an error occurs that falls in that range, the predefined error policy will be
invoked.
You can decide between Abort, Ignore, Restart Flow, Retry, and Jump.
When you use the Jump method, the flow continues from that step and does not
continue with the step that raised the error.
Component Type
Each component has an internal component ID and a component type. You can see
these values in each component’s Properties pane.
It is possible to have the same error codes in different components. A specific error
code depends on the component type.
In the last example we added a condition for this step as: C.sys.ErrorCode =102.
By conditioning this step with FALSE, you are ensuring that this step or branch is
unreachable. It is, in a sense, disabled.
6. Under the Scan for New Requests flow, double-click Error Policies.
7. in the Error Policies repository, click Add.
8. Click the zoom button in the From column. This loads the Errors Repository
dialog box, where you can select an error for a specific component.
9. From the dropdown list, select Email. Only the error types for the Email
component will now be displayed.
10. Select 102 Send Mail Error.
11. Repeat step 8 for the To property.
12. In the Error Policy column, select Jump.
13. Click the zoom button in the Step column. You see only the steps in the current
flow. Select the Send Error Email step.
This step will not be executed in the normal sequence because the condition is False.
However, with the error policy that you defined, you will be able to jump to the step
and carry out a sequence of steps.
You can test this in the same way that you did the previous example.
a. To: [email protected]
b. Subject: 'Email to the customer was returned'
c. Body: 'This is an automatic notification. Please do not reply.'&ASCIIChr
(10)&'An email to a customer failed.'
4. Set a condition for the Send Email to Administrator step, and set the condition
with the following expression: C.sys.LastErrorCode =102.
Once the error flow ends, the focus returns to the flow that raised the error. It then
continues with the following step, the one after the step where the error occurred. The
error flow returns clears the error.
The error flow example provided in this lesson displays the handling
of a single error. However, you can create a general error flow that
will handle different types of errors.
You can decide whether to end without an error (the default), return the same error to
the calling flow, or raise a different error.
1. Add a Flow Data utility as the last step of the error flow.
2. Update the C.sys.ErrorCode variable with 102. This code must be a code that
is compliant with the list of errors for the specific component. The Email
component has the following error codes: 100, 101, 102, and103.
If you need to return the same error code as the one that raised the error, you can
update C.sys.ErrorCode with the value fetched from C.sys.LastErrorCode.
3. When control is returned to the main flow, an error will be raised and handled
by the flow error mechanism.
Defining whether the error flow returns with an error or not depends
on your own project requirements.
If the file or folder does not exist, return an error to the Internet browser.
In the templates folder there is a template named Error.tpl. Return this
template to the Internet browser.
Summary
Magic xpi handles flow errors in the following sequence:
A Web service can be a commercial Web service or one that is freely distributed.
Magic xpi enables you to use Web services as a consumer and to offer Web services
as a provider. Magic xpi's Web service functionality is based on a third party
program called Systinet Server for Java (SSJ). This is also referred to as Systinet in this
lesson.
In this lesson, you will add a flow that handles the “add customer” scenario.
It can handle multiple security mechanisms, including Web Services Security (WS-S). Its
authentication support includes HTTP Basic, HTTP Digest, and Secure Socket Layer
(SSL).
The authorization model relies on JAAS, which provides maximum integration with
existing security frameworks. XML-level security is supported with XML signature, XML
encryption, and the Security Assertions Markup Language (SAML).
The Magic xpi installation process also installs a copy of this software. If the
installation and configuration of Systinet was successful, Magic xpi will manage all the
communication with this software for you.
Systinet creates the following shortcuts in the operating system’s Start menu:
You need to start the Systinet server before using it. You can start the server in one of
the following ways:
Once the server has loaded, you can start the console by doing one of the following:
Accessing the operating system's Start > All Programs > Systinet Server for Java
menu, and selecting the Systinet Enablement Server Administration Console
program entry.
Entering the following in your browser: http://localhost:6060/admin/console
Web Services Client – Provides the option to use a published Web service. This is
also referred to as consuming a Web service. You will see this in a later lesson.
Web Services Provider – Provides the option to publish Magic xpi as a Web
service, so that other applications can invoke Magic xpi and thereby trigger a
flow.
Once you set up Magic xpi as a Web service provider, it will be able to receive
requests from any external system, process its request, and provide an answer.
The Systinet Server is the management server where all Magic xpi Web services are
deployed. Since this server is external to Magic xpi, the first step is to create a
resource containing the connection details to the Systinet
server:
The resource settings for the Web Services Server resource displays information from
your Systinet installation. You can leave the default settings as is.
2. Add a new service and select Web Services. You can give it the same name as
the resource, AddCustomer.
3. In the Web Service Provider setting, select the AddCustomer resource that you
created.
4. In the Web Service Name setting, type: AddCustomerWS.
5. Click Operations to create the operations or processes that this Web service
provides. This is very similar to defining endpoints for the HTTP service.
The service name in the left pane is an internal Magic xpi name used to
identify this service in Magic xpi. The Web Service Name setting provided
in the settings pane is the name of the service that is deployed in external
systems, such as Systinet.
Each operation can have a single return value and multiple arguments.
To add an operation:
1. In the Operations dialog box, click Add to add an operation. Name the
operation Add_customer.
2. Create an argument, name it RequestID, and set the Direction to In. This must
be a Numeric variable of size 5 and an XSD Type of xsd:int. Remember that
Numeric is the internal Magic xpi data type and xsd:int is the data type that is
defined in the Web service.
3. Click OK to exit the Operations dialog box.
4. Click Management. This dialog box enables you to generate the specified
Web service inside the Systinet program.
5. Click Generate.
1. Create a new flow named Add Customer. You can move the flow up so that it
appears before the Check Item flow. This is not a necessity, but by doing so
you group all the main flows together at the top of the business process. To
move a flow upwards, select Move Flow Up from the context menu.
2. Under the Add Customer flow, double-click Flow Variables to open the Flow
Variables repository.
3. Add the following variables:
4. Drag the Web Services utility and drop it into the Triggers area of the Add
Customer flow. Name the trigger Add Customer by WS.
5. In the Setting section of the Properties pane, ensure that the AddCustomer
service was automatically selected.
6. Double-click the trigger, or right-click on it and select Configuration from the
context menu so that you can define the parameters. You will see that the
Service name, AddCustomerWS was automatically defined.
7. Select the Add_customer operation from the dropdown list.
8. You will get the list of arguments that you defined in the service. Park on the
RequestID parameter and then from the Mapping Variable column, click .
Select the F.RequestNum variable.
1. Add the Flow Data utility to the Flow area as the first step in the flow.
2. In the Name field, type Get request XML file from ODS.
3. Double-click the Flow Data utility, or right-click on it and select Configuration
from the context menu.
4. In the Flow Data Configuration dialog box, click Add and set the Action
column to Update.
5. Set the Type column to Flow.
6. In the Name column, select the F.RequestXML flow variable.
7. In the Encoding column, select the required encoding type for the variable.
8. In the Update Expression column, type:
ODSGet ( 'Request_' & Trim ( Str ( F.RequestNum , '5' ) ) , 1 , 'B' , 1 )
9. Click OK.
The next stage is to add the information to the Customers table. The source data will be
the retrieved XML file currently stored in the RequestXML variable.
1. Drag a Data Mapper step as a child step of the Get Request XML file from
ODS step. Name the step Add Customer to DB.
2. Double-click the Data Mapper step, or right-click on it and select Configuration
from the context menu.
Customer_ID Customers.CustomerID
Customer_Name Customers.CustomerName
country Customers.CustomerCountry
city Customers.CustomerCity
street Customers.CustomerAddress
zip Customers.CustomerZipCode
RequestTotal Customers.CustomerCredit
Customer_ID Contacts.CustomerID
ContactID Contacts.ContactID
ContactName Contacts.ContactName
Contact_eMail Contacts.ContactEmail
Note: You are using the same Data Mapper step to insert into two separate tables.
You can now invoke the flow from the Systinet console.
1. Start the console by entering the following URL in the Internet browser:
http://localhost:6060/admin/console
2. Enter the user name (the default is admin).
3. Enter the password (the default is changeit).
Since you deployed the Web service automatically via Magic xpi, the Web service is
listed as deployed in the Systinet server.
2. Enter a request number and click Perform call. The Magic xpi Add Customer
flow will be invoked.
1. Add an HTTP Trigger to the Add Customer flow. This will receive the request
number and invoke the flow. Return a BLOB variable in the HTTP trigger. To do
this, add a BLOB flow variable named F.RequestHTML.
2. Return an HTML file to the HTTP trigger, confirming that the customer was
successfully added to the database. Use the CustomerAdded.tpl template.
Hint: You do this by updating the F.RequestHTML BLOB that you defined in step
1.
3. The customer has now been successfully added to the Customers table and the
Contacts table, but the indication of its existence in the Requests database is
still set to false. Update the Requests table.
4. Execute the project again and use the HTML page you created in Lesson 12 to
check the status of the request. If there is a hyperlink under the CustomerID
instead of a name, click the hyperlink.
Summary
In this lesson, you added the Add Customer flow, which was triggered by a Web
service. Using the request number sent from the Web service, you fetched the request
data from the ODS and inserted information into the Customers table and the Contacts
table.
The concept is the same as having a magazine subscription. When you subscribe to
the magazine, you do not need to constantly check for the latest edition. The publisher
sends you the latest edition when the magazine is published. If you are not subscribed
to this magazine you will not be 'bothered' with information you don't want. The
benefit of using the PSS method is that your systems do not need to constantly refresh
and check for new information, and this saves system resources.
In previous lessons, you examined incoming requests and logged them in the database
and ODS. Later, you added the option for the user to manually correct faulty requests
where the customer did not exist in the database.
In this lesson you will add flows that will process valid requests. These are requests
where the customer exists and the items are available in stock.
Publishing a topic
Subscribing a flow to a topic
The Magic xpi PSS system contains the subscription information. When a published
event occurs, the PSS system sends an invocation request to all the subscribed flows,
even on different Magic xpi Servers.
The PSS system is available to all Magic xpi Servers in the same
project. This means that the other Magic xpi Servers can retrieve data
from this system.
When the Handle Request topic is published, the request number will be
passed to the Process Request flow in the C.UserCode variable.
You will create a flow variable that will hold the request number that was passed
through a context variable. You do not need to define a new flow variable since you
already have the value in the C.UserCode variable. However it is good practice to
define your own variable with a meaningful name.
During this course, every time you created a flow, you were asked to add a
? flow variable named F.RequestNum. How else could you have handled
this?
You will now take the request information and add it to the delivery database.
12. Drag a Data Mapper step as a child step of the Get request number step.
Name the step Add Delivery Header.
13. Double-click the Add Delivery Header step, or right-click on it and select
Configuration from the context menu.
14. From the Toolbox’s Mapper Schemas section, drag a Database source into the
Source Tree area.
15. Right-click on the Database source and select Show Properties.
16. Enter Get_request_header in the Name property.
17. Use the Database wizard:
18. From the Toolbox’s Mapper Schemas section, drag a Database destination into
the Destination Tree area.
19. Right-click on the Database source and select Show Properties.
20. Enter Add_To_Delivery in the Name property.
21. Use the Database wizard:
26. Drag a Data Mapper step as a child step of the Add Delivery Header step.
Name the step Add Delivery Details.
27. Double-click the Add Delivery Details step, or right-click on it and select
Configuration from the context menu.
28. From the Toolbox’s Mapper Schemas section, drag a Database source into the
Source Tree area.
29. Right-click on the Database source and select Show Properties.
30. Enter Get_Request_Details in the Name property.
31. Use the Database wizard:
32. From the Toolbox’s Mapper Schemas section, drag a Database destination into
the Destination Tree area.
33. Right-click on the Database source and select Show Properties.
34. Enter Add_To_Delivery in the Name property.
35. Use the Database wizard:
1. Drag a Flow Data utility as a child of Add Delivery Details. Name the step
Remove ODS entry.
2. Double-click the Remove ODS entry step, or right-click on it and select
Configuration from the context menu.
3. Click Add.
4. Set the Action to Delete.
5. Select the Dynamic property.
6. In the Name property, set the name to: 'Request_' & Trim ( Str ( F.RequestNum ,
'5' ) )
You have finished defining the flow. The request has been added to the delivery system
and the ODS has been cleared. Now you need to publish the topic for requests that
have no problems.
In this section you will publish the Handle Request topic when the request is found to
be valid.
By setting the condition, the Handle Request topic will only be published if the
customer exists and all items are available.
1. In the Process Request flow, remove the request from the local database tables,
both the Requests and RequestItems tables. This is part of the system cleanup.
2. In the Add Customer flow, publish the Handle Request topic if the customer’s
request is valid. Remember that the request’s items are saved in the
RequestItems table and a valid item is one where the status is TRUE.
To ship this request, all items in the request must be valid.
Summary
This lesson introduced you to the Publish and Subscribe mechanism in Magic xpi. In
this lesson, you used the PSS Publish utility to publish the Handle Request topic.
The Process Request flow is subscribed to the Handle Request topic. The flow will be
invoked when the Handle Request topic is published.
For these requests, you need to provide a follow-up mechanism that checks whether the
requests that are logged in the database are still invalid.
The follow-up mechanism will re-examine all of the requests from the database and
process those that are valid.
Scheduling a flow
Flow Enablement
The flow starts immediately by setting the AutoStart flow property to Yes.
Calling the flow from a different flow using the Call Flow destination of the Data
Mapper utility.
An external event occurs, which triggers the flow.
An internal event occurs using the Publish and Subscribe utility.
There are situations where a flow needs to be invoked at a specific time or time
interval.
The Scheduler utility enables you to create schedules for flow invocation. During
deployment, the Magic xpi Server uses the information in the Scheduler system to
invoke flows at the required time periods.
The Scheduler handles timer events, created by the integration project developers,
which determine the schedule for flow invocation.
The Scheduler has an entry for every timer event for flows on the particular server. The
entry contains the date and time for when the flow should be executed. The Magic xpi
Server constantly checks the Scheduler, and, when a scheduler entry’s time arrives, the
Magic xpi Server invokes the appropriate flow.
When you make changes to your integration project, the Scheduler system is updated
with any new timer events.
You define schedules in the Flow Editor. To define a scheduler for a flow, you need to
first define a Scheduler service in the Settings dialog box’s Service section. You then
need to drag a Scheduler utility to the Triggers area, and select the Scheduler service
that you just defined.
1. In the Settings dialog box’s Service section, add a new Scheduler service.
Name it AutomaticCheck.
2. Set the Scheduler Type field to Interval, and leave the Calculate Scheduler
Runtime at Startup check box selected.
3. Set the Minutes field to 2.
11. Drop a Data Mapper utility onto the flow. Name it Check Request Items.
12. Create a Database source named RequestItems.
13. Using the wizard:
When a flow needs to be activated, the Magic xpi Server checks whether the flow is
currently enabled.
You define when you want the flow to be activated. Select one of the following from
option:
In much the same way as you previously defined a Scheduler service, the Weekly and
Monthly options (above) are configured in the Settings dialog box’s Service section.
You then ‘import’ these settings into the flow’s properties.
First, you create a Flow Enablement service and select either Weekly or Monthly in the
Activation Type field. You then select the relevant check boxes for the days or the
months that you want to activate your flow. Then, in the Enablement Service field in the
flow’s Properties pane, you select the required Flow Enablement service’s name. Your
flow will then be enabled according to the settings that you defined in the Flow
Enablement service.
If the flow is not enabled and a request to invoke it arrives via a trigger mechanism,
such as an HTTP request or a Scheduler action, the flow will not be invoked and the
activation request will be ignored.
Summary
This lesson provided you with additional ways to control when a flow is invoked.
During the lesson, you fixed invalid requests. If it was found that there was not enough
in stock to supply the request, you modified the request. You then set a new scheduler
that would run once a day and handle any requests that were still in the system.
This lesson will introduce you to the rules used by the Data Mapper. You will also learn
some additional mapping techniques.
Single Elements
You can map the following elements in the Data Mapper window:
1. Copy the folder Mapper_Sample from the Course Files folder to the
My Documents\Magic\projects folder.
2. Open the Mapper_Sample project.
Automatic Mapping
Automatic complex element mapping ensures that no data is lost while mapping.
Whenever simple elements are mapped without a parent complex element mapping,
Magic xpi automatically connects the first parent complex element of the source and
destination elements where the Max occurrences node property is greater than 1.
You see in the image above that a parent has been connected automatically. You used
this throughout the course.
You will see in the image above that B was automatically connected to Y. This is
because C has a Max occurrences value of 1.
Complex Element
Complex data mapping is carried out by:
You will see that e crosses the previous connection and that C was automatically
mapped to Y.
To overcome this, you need to ensure that the C complex element has a Max
Occurrences of 1. This can be implemented by changing the schema or adding a
filter.
1. Park on C and access the properties. Enter a condition for the Single Instance
Filter, such as 'TRUE'LOG.
2. Connect e to x. This time, the action should be successful.
The condition you entered is an example. The actual expression to use would
depend on your own data.
Use the Flow Data utility instead of the Data Mapper to update variables.
Use the Data Mapper’s Call Flow option only when you need to process many
records. Use the Invoke Flow utility if you need to process one record only.
When you need to store data temporarily, it is more efficient to use a file saved in
a variable, such as a BLOB, than to use the ODS. The ODS is a table stored in a
database, and thus consumes more memory than a memory file. However, the
ODS is persistent and can be recovered from failure. You will learn about the
memory file in this lesson.
When you have a condition and an update expression on a compound node, the
update expression will be calculated first, regardless of the condition expression.
This means that variables contained in the update expression will always be
updated.
The Data Mapper has a specific order in which it executes the requested
operations. These should be taken into account when you are designing the step:
Execution Order
The execution order is based on the order of the destination items, starting from the
top.
If you reorder the destinations, the execution order may also change.
Database
Flat File
Variable
ODS
Call Flow
UDS
The following are executed individually:
XML
JSON
Template
Assume that when a request is sent to the delivery system, you need to update a
defined list of people that you have to update by email, such as the warehouse
manager, the sales manager, and the accounts manager. You can use a single email
step to send the same email to a list of names defined in a text file.
To map the information directly to the Email component, you will use the Email
component's XML interface.
In the Destination Tree, there is an entry called IFC_Email. This is automatically added
as a result of the XML interface.
You are going to map comma-delimited data from a flat file to an XML file. The flat file
in question has a defined structure that you need to understand to extract information.
7. From the Toolbox’s Mapper Schemas section, drag a Flat File source into the
Source Tree area. Name the source FetchMailList.
You can take a look at the file in order to understand the file structure and how it
should be set in the Flat File source’s Properties pane. In this case, it is a very simple
structure.
FirstName Alpha 30 30
LastName Alpha 30 30
The structure is predefined and cannot be changed. For example, if you wanted to
save two time fields in a record, you were unable to.
ODS is kept in a table with all the overhead of a regular database table.
The User Defined Storage, or UDS, is very similar to ODS, but it addresses the above
"limitations" by:
Assume that when the Scan DB for valid requests flow runs, you need to create a
simple audit trail of what was scanned and send the file to the system administrator.
Time stamp
Customer ID
Request ID
Request value
The UDS Repository opens. As with other repositories there are two panes, the left and
the right. In the left pane you provide a name for the UDS, and in the right pane you
define the variables.
2. Click Add on the left pane, and set the name to AuditTrail. You cannot use
spaces here.
3. On the right pane, click Add.
4. Set the Name property to TimeStamp with a type of Alpha and a size of 20.
5. Select the Index check box.
You have now defined the first column in the structure and have defined that this will
be the index. You will now define two more columns:
6. On the right pane, click Add. Set the Name property to CustomerId, a Numeric
field of size 5.
7. Click Add again. Set the Name property to RequestNum, a Numeric field of
size 5.
You have now defined a UDS structure. You have three columns, one of them being the
structure’s index.
When you define a new flow variable, you can define that this variable is of the same
type as the UDS that you previously created.
1. Under the Scan DB for valid requests flow, double-click Flow Variables.
2. Click Add to add a flow variable and name it Audit_trail.
3. Park on the Type column and open the dropdown list. You will see that the UDS
model that you defined is one of the structure’s to be selected. Select
U.AuditTrail.
Now that you have written to the UDS, you can retrieve the information. You can do
this with the Data Mapper.
15. Add a Data Mapper step as the child step of Scan requests. Name the step
Create Trail.
16. Double-click the Create Trail step, or right-click on it and select Configuration
from the context menu.
17. From the Toolbox’s Mapper Schemas section, drag a UDS source into the
Source Tree area.
18. Right-click on the UDS source and select Show Properties.
19. Enter FetchUDS in the Name property.
20. In the Variable property, select F.Audit_Trail.
21. From the Toolbox’s Mapper Schemas section, drag a Flat File destination into
the Destination Tree area.
22. Right-click on the Flat File destination and select Show Properties.
23. Enter CreateFile in the Name property.
24. Set the Destination Type to File, and set the destination file to:
EnvVal ('currentprojectdir')&'course_data\out\audit_trail.txt'
26. Expand the source and destination, and connect the nodes to one another.
In this exercise, you are going to map comma-delimited data from a flat file to an XML
file.
The flat file contains comma-delimited data. The first column determines the line type
(H = Header, L = Line).
You need to map all header type data to the Header compound in the XML, and all
line type data to the Item compound in the XML.
The image below shows you the structure of the example files. It is presented here to
give you a hint about how to map these files.
For the purpose of this example, add a new flow called Create XML Order from ASCII.
Place the XML file in the OUT directory, and name it Order.xml.
You learned more about the Magic xpi Data Mapper, including some of the issues
to take into consideration on single and complex elements.
You learned about flat file mapping.
You also learned about UDS storage and how to use it.
When working with UDS, remember:
UDS data is stored in the memory, and is therefore available to the current running
flow only.
You can copy the UDS data to a BLOB to enable you to use it at a later stage.
The UDS Repository can be used only with the Flow Data utility and the Data
Mapper utility.
Once you define UDS models in the UDS Repository, they will be added to the list
of the flow variable types (in the Flow Variable repository's Type column).
When the development environment and the deployment environments both run on the
Windows operating system, there should be very few problems with running the flows
in a project. However, remember that the deployment environment may not be a
Windows operating system.
As you are getting ready to move your project from the development environment to
the test or production environment, there are several steps you need to perform.
Deployment issues
Database issues
It is recommended to use the same database type for the Magic xpi internal and
application databases that you are going to use in deployment environments. This
means that if your development internal database was Microsoft SQL Server, then
you should use the same server type in deployment.
It is recommended that you disable or clear all debugging code from the project
before deploying. For example, disable or clear the flows, messages, and
programs used for debugging purposes.
Use environment variables when you provide names or addresses to servers,
messaging queues, and aliases.
It is good practice to use environment variables in resources and services.
Magic xpi achieves portability by translating the environment variables at runtime,
according to the values entered in the Settings dialog box’s Environment section.
It is important to remember that the Magic xpi engines run under the user that is
defined for the GSA service, and not by the logged in user. By default, the user
that is defined for the service is the Local System account as shown in the image
below. For running Magic xpi on a single machine, this is usually fine. However,
on a clustered environment, the service should run as a user who has privileges to
access network resources.
Deployment Issues
When you are ready to deploy your projects, you need to prepare the server
environment.
It is highly recommended that you rebuild your project whenever you make any
changes to it, and also prior to deployment, by selecting the Rebuild Solution option
from the Build menu.
If you saved any environment variables under the General Environment section of the
Settings dialog box, make sure that you copy the relevant variables to the Magic.ini
file of any new deployment environment.
It is good practice to test your project in the deployment environment to ensure that you
have correctly configured and deployed your project.
For more information about deploying projects in a clustered environment, see the
Magic xpi 4.x - Advanced Deployment Guide.pdf file included with the Magic xpi
installation.
Recommendations
Deployment issues
Remember that when you deploy, the only component of Magic xpi Integration
Platform that you will need is the Magic xpi Server.
If you plan to deploy your project on a non-Windows platform, you should consider
the differences in the operating systems when you develop your project. Read the
Magic xpi Help for assistance on these systems.
In the right hand pane of the Settings dialog box, you will define the properties for MSSQL:
Solutions 207
Solution Lesson 5 – Scan for New Requests
You are required to add a step that sends an email to notify the administrator that a new request has
arrived. In the course, you will be using a single valid email, [email protected].
You will use this for all the tests.
1. Park on the Toolbox pane.
2. Click and drag the Email component and drop it on the Scan Directory step.
In the Scan Directory step, you defined that the file name and path would be returned in a variable
named C.UserString. Therefore:
In the Attachment Path property, type C.UserString. You will change this in a later lesson.
Solutions 208
Solution Lesson 6 – Flow Orchestration
Adding Variables
You are required to add variables that are to be used in place of the Magic xpi predefined
variables.
1. Under the Scan for New Requests entry in the Solution Explorer, double-click Flow Variables.
The Flow Variables repository opens. Click Add to add a variable.
2. Set the Name property to RequestXML and tab to the Type property. The name will change to
F.RequestXML.
3. Open the Type dropdown list and select BLOB.
4. Add the following flow variables:
CustomerId Numeric 9
5. Under the Repositories entry in the Solution Explorer, double-click Global Variables. The
Global Variables repository opens.
6. Click Add to add a variable.
7. Set the Name property to EmailTo and tab to the Type property. The name will change to
G.EmailTo.
8. Open the Type dropdown list and select Alpha.
9. In the Length field, enter 100.
10. In the Default Value property, enter [email protected].
Solutions 209
Now you have to use these variables:
11. Double-click the Scan Directory step, or right-click on it and select Configuration from the
context menu.
12. Make sure that LAN to LAN is selected in the left pane.
13. On the right pane, park on the Return File To property. Click the Browse button . Select the
F.RequestXML variable that you defined.
14. Park on the Return Destination Filename To property. Click the Browse button . Select the
F.RequestFilename variable that you defined.
15. Double-click the Send Email to Sales step, or right-click on it and select Configuration from
the context menu.
16. Make sure that Quick Send is selected in the left pane.
17. On the right pane, park on the To property and enter G.EmailTo as the value.
Solutions 210
Solution Lesson 7 – Checking Customer Existence
Checking Customer Existence
You are required to check the existence of the contact.
The first stage is to define the contact ID variable.
1. In the Solution Explorer, under the Scan for New Requests entry, double-click on Flow
Variables.
2. In the Flow Variables repository, click Add to add a variable.
3. Set the Name property to ContactId and tab to the Type property. The name will change to
F.ContactId.
4. Open the Type dropdown list and select Numeric.
5. Set the Length to 9.
Solutions 211
To check the existence of the contact:
11. Drag a Data Mapper utility as a child step of the Check if the customer exists step. Name this
step Check the Contact.
12. Double-click the Data Mapper utility, or right-click on it and select Configuration from the
context menu to open the Data Mapper window.
13. From the Toolbox’s Mapper Schemas section, drag a Database source into the Data Mapper
window’s Source Tree area.
14. Right-click on the XML source and select Show Properties.
15. Enter CheckContact in the Name property.
The Database Definition property points to the Course Database that you defined.
16. In the Properties pane’s Wizard field, click the button. The Select Tables dialog box
opens.
17. Park on the Contacts entry in the Available Tables pane.
18. Click Add. The Contacts entry is removed from the Available Tables and added to the
Selected Tables pane.
19. Click Next. The Select Columns dialog box opens.
20. Park on the ContactName entry in the Available Columns pane.
21. Click Add. The ContactName entry is removed from the Available Columns and added to the
Selected columns pane.
22. Click Next. The Where Clause dialog box opens.
23. Park on [Contacts]CustomerID in the Available Columns pane and double-click.
[Contacts]CustomerID is added to the Where Clause Text pane.
24. Park on the Where Clause Text pane and type = after [Contacts]CustomerID.
The text should now read: [Contacts]CustomerID =
25. Park on F.CustomerId in the Variables pane and double-click. The text should now read:
[Contacts]CustomerID = <?F.CustomerId?>
26. You now need to fetch the contact part. Park on the Where Clause Text pane and type AND
after [Contacts]CustomerID = <?F.CustomerId?>.
27. Complete the WHERE clause so that the WHERE clause will be:
[Contacts]CustomerID = <?F.CustomerId?> AND [Contacts].ContactID=<?F.ContactId?>
Solutions 212
The next stage is to map the record retrieved by the Data Mapper to a variable. You already
learned how to do this earlier in this lesson.
28. From the Toolbox’s Mapper Schemas section, drag a Variable destination into the Data
Mapper window’s Destination Tree area.
29. Right-click on the Variable destination and select Show Properties.
30. Enter ContactName in the Name property.
31. In the Properties pane, click the Variable field’s button and select the F.ContactName
variable.
32. Connect the ContactName node on the source to F.ContactName in the destination.
Now you need to condition this step so that if the previous step did not succeed there is no need to
do this step.
33. Select Condition from the context menu of the step.
34. Set the following condition: Trim ( F.CustomerName )<>''.
If the contact does not exist, then you need to send them a reply email. This is something you have
already done in a previous exercise.
35. Park on the Toolbox pane.
36. Click and drag the Email component and drop it on the Check the contact step.
37. In the Email component’s Properties pane, enter Send Rejection Email in the Step Name field.
38. In the Properties pane’s Settings section, make sure that the Course email resource has been
automatically selected. It is automatically selected because it is the only email resource that
you have defined.
39. Double-click the Email component, or right-click on it and select Configuration from the
context menu.
Solutions 213
The Direct Access Method dialog box opens:
40. In the left pane, click Add.
41. Select Quick Send from the dropdown list.
Solutions 214
Solution Lesson 10 – Item Validity Check
Requested price is too low
The client wants to purchase the item at a price less than the list price. The solution is very similar to
the process where you checked whether there is enough stock. To check whether the price is less
than the list price, do the following:
1. Under the Check Item flow, double-click on Flow Variables.
2. In the Flow Variables repository, add a flow variable named F.RequestPrice which is
Numeric with a size of 9.2.
3. Double-click the Report Items Existence Data Mapper step, or right-click on it and select
Configuration from the context menu.
4. Right-click on the CheckItem source node and select Show Properties.
5. In the Properties pane, use the Database Wizard to update the SQL statement:
Click Next until you reach the columns selection dialog, and select the CatalogPrice
column of the Products table. This will add the CatalogPrice as another selected
column.
Click Next until you have finished, as you will not be making any other selections. You
will receive a message that some of the connections may be lost, but you can ignore
the messages by clicking OK.
6. In the Data Mapper window, connect CatalogPrice to the C.All_Items_Exist node.
7. Right-click on C.All_Items_Exists and select Show Properties. You may find that your previous
Calculated Value expression has been removed. This happened as a result of modifying the
SQL statement. In any case, you will need to enter a new expression:
Src.S1/Record/CatalogPrice < F.RequestPrice AND Src.S1/Record/StockQuantity
>=F.Quantity AND C.All_Items_Exist
8. Park on the Scan for new requests flow.
9. Double-click the Check Items Data Mapper step, or right-click on it and select Configuration
from the context menu.
10. Map from USPrice to F.RequestPrice.
Solutions 215
The item does not exist
The client wants to purchase an item that does not exist in the catalog. There are a number of ways
to solve this. The solution that will be explained here involves:
How does it work? When the Data Mapper finds a record, it updates the flow variable with TRUE. If
the flow variable is FALSE after exiting the Data Mapper, it indicates that the Data Mapper did not
find a matching record and therefore there was no mapping connection.
1. Under the Check Item flow, double-click on Flow Variables.
2. In the Flow Variables repository, add a flow variable named F.ItemExists and set it as a
Logical type.
You need to add a parent step to the Report Items Existence step:
3. Click and hold the keyboard Ctrl button.
4. Select the Flow Data utility from the Toolbox pane, and drag and drop it on the Report Items
Existence step.
5. A menu will pop up. Select Make As Parent.
6. In the Flow Data utility, set the Step Name property to: Update flow variable.
7. Double-click the Update flow variable step, or right-click on it and select Configuration from
the context menu.
8. In the Flow Data Configuration dialog box, add an entry for:
Action: Update
Type: Flow
Name: F.ItemExists
Update Expression: 'FALSE'LOG
Solutions 216
16. Add an entry for:
Action: Update
Type: Context
Name: C.All_Items_Exist
Update Expression: 'FALSE'LOG
17. Set a condition for this step: Not (F.ItemExists).
F.ItemExists is a logical variable that contains either TRUE or FALSE. There is no need to implicitly use
a condition such as F.ItemExists = 'FALSE'LOG.
Your Check Item flow will now look similar to the image below:
Solutions 217
Adding the Request Information to the Database
To do this you need to have a Database type as the destination in a Data Mapper step.
You can do this in the Data Mapper step that you have already defined. In this step you currently
read from the Request XML and then call the Check Item flow to check each item.
You will modify this step in the following way:
In addition to the Call Flow destination, you will be adding a Database destination. You will use
the Database destination to insert records to the Requests table.
The items will be inserted in the called flow. You are already handling each item in the called
flow so as part of the process you can add the current record to the database.
The default transaction level of the Data Mapper is for the entire step. Therefore, if there is a problem
writing to one of the tables and there is a rollback, no data will be written to the database tables.
1. Park on the Scan for New Requests flow.
2. Double-click the Check Items step, or right-click on it and select Configuration from the
context menu.
Bear in mind that because the data is being added within a transaction, you will not see them in the
database until the Check Items step is completed.
3. From the Toolbox’s Mapper Schemas section, drag a Database destination into the
Destination Tree area.
4. Right-click on the Database destination and select Show Properties.
5. Enter AddRequest in the Name property.
6. Use the Wizard and:
Park on the Requests.RequestId node of the Request table destination and select
Show Properties from the context menu. Enter a Calculated Value for F.RequestNum.
Connect Customer_ID from the source to Requests.CustomerId on the destination.
Connect Request_Total from the source to Requests.RequestTotal on the destination.
Park on Requests.CustomerExists and select Show Properties from the context menu.
Enter a Calculated Value for Trim (F.CustomerName) <>''. Remember that if the Check
Customer Exists step failed to fetch a customer name, the F.CustomerName variable
will be blank.
Solutions 218
You have finished adding the request. Now you need to add the lines. You will do this in the called
flow.
8. Park on the Check Item flow.
9. Double-click the Report Items Existence step, or right-click on it and select Configuration from
the context menu.
10. Park on the Database source and select Show Properties. Use the Wizard and add the
CatalogName column from the Products table.
11. From the Toolbox’s Mapper Schemas section, drag a Database destination into the
Destination Tree area.
12. Right-click on the Database destination and select Show Properties.
13. Enter AddRequestItems in the Name property.
14. Use the Wizard and:
Park on the
RequestItems.RequestId
node of the RequestItems
table destination and
select Show Properties
from the context menu.
Enter a Calculated Value
for F.RequestNum.
Park on the RequestItems.ProductCode node of the RequestItems table destination and
select Show Properties from the context menu. Enter a Calculated Value for
F.ItemCode.
Park on the RequestItems.Quantity node of the RequestItems table destination and select
Properties from the context menu. Enter a Calculated Value for F.Quantity.
Park on the RequestItems.RequestPrice node of the RequestItems table destination and
select Show Properties from the context menu. Enter a Calculated Value for
F.RequestPrice.
Connect CatalogName to RequestItems.ProductName.
Connect CatalogPrice to RequestItems.Status.
Connect StockQuantity to RequestItems.Status.
Park on the RequestItems.Status node and select Show Properties from the context
menu. Enter a Calculated Value with the following expression:
Src.S1/Record/CatalogPrice < F.RequestPrice AND Src.S1/Record/StockQuantity >=
F.Quantity
This is a similar expression to the expression you entered to update C.All_Items_Exist.
You can now run the flow and test your work.
Solutions 219
Initialization Flow
You have used the Data Mapper to select information from a table and you have now used the Data
Mapper to insert records into a table. You will now use the Data Mapper to delete records from a
table.
1. In the Solution Explorer, right-click on Business Process-1 and
select Add Flow.
2. Change the flow name to Initialization.
3. Select Properties from the context menu of the flow. Set the
AutoStart property to Yes.
4. Add a Data Mapper step to the Initialization flow and name it Delete Items DB.
5. Double-click the Delete Items DB step, or right-click on it and select Configuration from the
context menu.
In this step, you will not be using a source in the Data Mapper.
6. From the Toolbox’s Mapper Schemas section, drag a Database destination into the
Destination Tree area.
7. Right-click on the Database destination and select Show Properties.
8. Enter DeleteRequests in the Name property.
9. Use the Wizard and:
10. From the Toolbox’s Mapper Schemas section, drag a Database destination into the
Destination Tree area.
11. Right-click on the Database destination and select Show Properties.
12. Enter DeleteRequestItems in the Name property.
13. Use the Wizard and:
Solutions 220
Solution Lesson 11 – Services
You are going to add a service that you will be using in the next lesson. You are adding an HTTP
service that you will need in the next lesson.
1. Open the Projects menu and select Settings. The Settings dialog box opens.
In this lesson, you added the RequestConfirmation service. If you did not add it, then select Add and,
in the New Service dialog box, select HTTP and then type RequestConfirmation.
2. Park on the RequestConfirmation node and click Endpoints.
When you click OK, Magic xpi automatically creates a sample HTML page under:
My Documents\Magic\projects\< project name>\<current project>\Service\<Service name>
As an example, the path to the HTML will be:
C:\Users\<your user name>\My Documents\Magic\projects\Magic_xpi_course\
Magic_xpi_course\Service\RequestConfirmation\ check_request_status.html
If you click on the HTML in the path above, you will get an HTML similar to the image below. You
can modify the look and feel of this HTML page.
Solutions 221
Solution Lesson 12 – Checking Request Status
You need to return the F.Result_HTML file to the Internet browser. You have only updated the header
section in which you have either displayed the name of the customer or a hyperlink.
To update the F.Result_HTML file you will be using the Data Mapper with a Template destination.
1. Park on the Check Request Status flow.
2. Add a Data Mapper step as the child step of Get Customer Information. Name this step Send
Response Page.
3. Double-click the step, or right-click on it and select Configuration from the context menu.
As you have already fetched the customer details, you only need to fetch the request’s lines:
4. From the Toolbox’s Mapper Schemas section, drag a Database source into the Source Tree
area.
5. Right-click on the Database source and select Show Properties.
6. Enter Request_items in the Name property.
7. Use the Wizard and:
Solutions 222
Now you have to map to update the variable.
In the Data Mapper window, you will see that the Destination Tree contains the Merge tags that
were fetched from the template. The tags that were defined within an MGREPEAT section are listed
as a compound node in the destination.
13. Park on the Header node and select Show Properties from the context menu. Enter a
Calculated Value of F.RequestHeader. This is the header that you updated during the lesson.
14. Connect ProductCode to ItemCode.
15. Connect ProductName to ItemName.
16. Connect Status to LineStatus.
17. Park on the LineStatus node and select Show Properties from the context menu. Enter a
Calculated Value with the following expression:
IF (Src.S1/Record/Status ,'All OK', 'There is a problem!')
Solutions 223
File Management Component
When the HTTP trigger invokes a flow, it is recommended to send a response page for every
scenario of the flow logic. As you may have realized, the user may request information for a request
that has not yet been logged in the system. To answer that need, you will return a predefined HTML
file. You will now add a File Management component to the flow that loads a predefined HTML
page when a request is not found.
The predefined file is currently located under the Files directory. The first step will be to create an
environment variable that points to this location. It is important to do this as you will be referring to
this in the next lesson.
1. From the Project menu, select Settings.
2. Under General Environment, click User Environment Variables.
3. Add an entry named Files, with a value of %currentprojectdir%course_data\Files%sl%.
Solutions 224
Solution Lesson 13 – Error Handling
You are asked to handle a situation where the File Management component returns an error. In the
specific example, the Internet browser must also be updated. As this is a specific issue, a generic
flow will not be useful. Remember, of course, that you need to update the F.Returned_HTML variable
so that the requester can return it to the Internet browser.
To solve this issue, you can create an error policy in the same flow where the error occurs.
1. Park on the Check Request Status flow.
2. Add a Data Mapper step as the child step of Get Information from DB. Name this step Send
Error Page.
3. Set a condition of FALSE for this step.
4. Double-click the Send Error Page step, or right-click on it and select Configuration from the
context menu.
Solutions 225
5. From the Toolbox’s Mapper Schemas section, drag a Template destination into the
Destination Tree area.
6. Right-click on the Template destination and select Show Properties.
7. Enter ReturnErrorPage in the Name property.
8. Set the Template File property to: %templates%\Error.tpl. Remember that the tpl extension is
not a required extension. However error.tpl is the name of the file.
9. Set the Destination Type to Variable and select F.Result_HTML.
Although you are adding a single step here you can add as many steps as needed. For example,
you can add an email step that sends an email to the administrator. It is important that the
administrator is also updated.
13. Add an Email component as a child step of the Send Error Page step. Name the step Update
Admin.
14. Double-click the Update Admin step, or right-click on it and select Configuration from the
context menu.
15. Select the Method interface. Select the Quick Send method and set the following:
a. To: [email protected]
b. Subject: 'Urgent: A necessary file was not found'
Solutions 226
Remember: The email step is provided purely as an example.
16. Under the Check Request Status flow, double-click Error Policies.
17. Click Add.
18. Click the zoom button in the From column. This loads the Errors Repository dialog box, where
you can select an error for a specific component.
19. From the dropdown list, select File Management. Only the error types for the File
Management component will now be displayed.
20. Select 200, which is Folder does not exist.
21. In the To property, select 216, which is Operation failed. This is the last component error
defined by the File Management component.
22. In the Error Policy column, select Jump.
23. Click the zoom button in the Step column. You see only the steps in the current flow. Select
the Send Error Page step.
You are done. You can test this by sending a request that has not been logged. Before doing that,
rename the Files folder to something else.
The image below is similar to what will appear in your Internet browser.
Solutions 227
Solution Lesson 14 – Adding a Customer
In a previous lesson, you learned how to accept a request from the Web using the HTTP component.
This process returned an HTML page that included a link for adding a new customer if the customer
did not exist in the database.
In the current lesson, you added the Add Customer flow which was triggered by a Web service.
Using the request number sent from the Web Service, you fetched the request data from the ODS
and inserted information into the Customers table and the Contacts table.
Therefore, the necessary steps for adding a customer exist. You will add another trigger to this flow
that completes the Add Customer scenario. This is triggered from the Internet browser.
You will first add a new endpoint to the HTTP Service.
1. From the Project menu, select Settings. Open the Services node and select the
RequestConfirmation service.
2. Click Endpoints to open the Endpoint dialog box. Click Add to add a new endpoint.
3. Set the Endpoint Name to add_customer.
4. Park on the Arguments pane and click Add.
5. Enter RequestNum as the Name parameter. This must be a Numeric data type and have a
size of 5.
Solutions 228
The next stage is to return the information to the Internet browser that the customer was added.
1. Add a Data Mapper utility as a child step of the Add Customer to DB step. Name the step
Update Browser.
2. Double-click the Data Mapper, or right-click on it and select Configuration from the context
menu.
You could, of course, have added this operation to the previous step. It was separated in this
example for clarity.
Solutions 229
Update Customer Status
The last stage is to update the Requests table that the customer now exists. You will now configure
the Data Mapper utility with an update statement.
1. Add a Data Mapper utility as a child step of the Update Browser step. Name the step
Change Customer Status in DB.
You can add all the steps in this solution as a single Data Mapper
step.
2. In the Description field, type: This step updates the DB using a dynamic WHERE clause.
3. Double-click the Data Mapper, or right-click on it and select Configuration from the context
menu.
Solutions 230
You have completed the Database Wizard for an Update statement.
The final result will be:
UPDATE [Requests] SET CustomerExists=<!?CustomerExists?!> WHERE
RequestId=<!?RequestNum?!>
12. In the Data Mapper window, expand the destination.
13. Park on the CustomerExists node and enter a Calculated Value of 'TRUE'LOG.
14. Park on the dynamic variable, RequestNum, and enter the following Calculated Value:
F.RequestNum
Solutions 231
Solution Lesson 15 – Handling Approved Requests
During the lesson, you were asked if using the flow variable, F.RequestNum, every time you defined
a flow was the ideal solution. The answer is that you could define a context variable,
C.RequestNum. The value in this variable is valid as long as the context is alive, but the variable
definition exists throughout the project.
The request is still in the local databases, you need to remove it from the database so that the request
will not be handed a second time.
1. Park on the Process Request flow.
2. Add a Data Mapper step as a child step of Add Delivery Details and name it Remove from
DB.
3. Set the processing mode to Parallel.
4. Double-click the Data Mapper, or right-click on it and select Configuration from the context
menu.
In this step, you will not be using a source in the Data Mapper.
5. From the Toolbox’s Mapper Schemas section, drag a Database destination into the
Destination Tree area.
6. Right-click on the Database destination and select Show Properties.
7. Enter DeleteRequests in the Name property.
8. Use the Wizard and:
Solutions 232
In the Add Customer flow, you added a customer if it did not appear in the database. The customer
may have shippable requests. If there are shippable items, you will publish the topic so that they may
be added to the delivery database. Remember that a shippable item is one where the status is 1.
There are many ways to do this. You can use the solution from Lesson 11:
How does it work? When the Data Mapper finds a record, it updates the flow variable with TRUE. If
the flow variable is FALSE after exiting the Data Mapper, it indicates that the Data Mapper did not
find a matching record and therefore there was no mapping connection.
1. Park on the Add Customer flow.
2. Add a flow variable named F.ItemExists which has a Logical type.
3. Select the Flow Data utility from the Toolbox, and drag and drop it on the Add Customer to
DB step.
4. In the Flow Data utility, set the name property to: Update flow variable.
5. Set the processing mode to Parallel.
6. Double-click the Flow Data utility, or right-click on it and select Configuration from the context
menu.
7. Add an entry for:
Action: Update
Type: Flow
Name: F.ItemExists
Update Expression: 'FALSE'LOG
Solutions 233
Defining the Data Mapper step:
8. Add a Data Mapper step as the child step of Update flow variable. Name the step Check for
valid items.
9. Double-click the Data Mapper, or right-click on it and select Configuration from the context
menu.
Solutions 234
The last stage is to publish the topic:
21. Add the PSS Publish utility as a child step of the Check for valid items step.
22. Name the step Publish the Handle Request.
23. Double-click the PSS Publish step, or right-click on it and select Configuration from the context
menu.
24. Zoom from the PSS Name entry and enter Handle Request in the Expression Editor.
25. In the Code parameter, set the following expression: F.RequestNum.
26. Click OK to confirm.
You have now published to the same flow from two different flows.
Solutions 235
Solution Lesson 16 – Automatic Item Check
In the lesson, you fixed problematic requests. However, these requests are not passed to the delivery
system.
You will now create a flow that will scan all requests in a timely manner.
1. Insert a new flow named Scan DB for valid requests.
2. Right-click on the flow name and select Move Flow Up. Move it above the Check Reason
flow.
3. In the Settings dialog box’s Service section, add a new Scheduler service. Call it
Midnight_Scan.
4. Select Daily from the Scheduler Type pulldown menu.
5. Park on the Time(s) to Execute property and click the button.
Solutions 236
You now need to scan the system for open requests where the customer also exists. To do this you
need to:
Scan the Requests table for requests and fetch the Request number.
For each request, scan the request items table and check whether there is a valid request. If there
is a valid request, you need to publish to the handle request topic. You will perform this part of
the scenario in a separate flow.
1. Insert a new flow named Scan requests items.
2. Right-click on the flow name and select Move Flow Up. Move it to just below the
Check Reason flow.
3. Add the following flow variables:
Action: Update
Type: Flow
Name: F.ItemExists
Update Expression: 'FALSE'LOG
Solutions 237
12. From the Toolbox’s Mapper Schemas section, drag a Variable destination into the
Destination Tree area.
13. Right-click on the Variable destination and select Show Properties.
14. Enter Update_Variable in the Name property.
15. Select the F.ItemExists variable.
16. Expand the source and destination.
17. Connect the ProductCode source node to F.ItemExists. The Data Mapper needs at least one
connection.
18. Right-click on the F.ItemExists node and select Show Properties.
19. Enter a Calculated Value for 'TRUE'LOG.
Solutions 238
All that is left to do is to call this flow:
1. Park on the Scan DB for valid request flow.
2. Add a Data Mapper step as the first step and name it Scan requests.
3. Double-click the Data Mapper step, or right-click on it and select Configuration from the
context menu.
4. From the Toolbox’s Mapper Schemas section, drag a Database source into the Source Tree
area.
5. Right-click on the Database source and select Show Properties.
6. Enter ScanRequest in the Name property.
7. Use the Wizard and:
This flow is the last part of the cleanup of the invalid requests. Every night at midnight, the Scheduler
will run and clean the system.
Solutions 239
Solution Lesson 17 – More About Magic xpi
Mapping Flat File to Order
This is an exercise which has nothing to do with the course scenario. It is provided as an extra
scenario so that you may understand other techniques.
1. Insert a new flow named Create XML Order from ASCII.
2. Add a Data Mapper to the flow.
3. Name it ASCII Order to XML.
4. Double-click the Data Mapper step, or right-click on it and select Configuration from the
context menu.
5. From the Toolbox’s Mapper Schemas section, drag a Flat File source into the Source Tree
area.
6. Right-click on the Flat File source and select Show Properties.
7. Enter ASCII_Order in the Name property.
Identifier Alpha 30 30
Field1 Numeric 9 9
Field2 Numeric 9 9
Name Alpha 30 30
Solutions 240
11. From the Toolbox’s Mapper Schemas section, drag an XML destination into the Destination
Tree area.
12. Right-click on the XML destination and select Show Properties.
13. Enter XML_Order in the Name property.
14. Set the XSD File to: course_data\Files\Order.xsd
15. Set the Destination Type to File. Create the file in:
EnvVal ('currentprojectdir')&'course_data\out\order.xml'
Data Mapping
The idea behind this example is that the same field in the source file should be mapped to both
Header columns and Item columns.
In addition, the first column should be processed to separate the line type indicator and the actual
data.
By using an expression in the CustomerID and ItemID elements, you can filter the first column's
source data. Using an expression in the destination compounds helps you filter the mapped data.
In the Data Mapper window, map the following sources to destinations:
1. Connect Record to Header and Item.
2. Connect Field1 to CustomerID and ItemID.
3. Connect Field2 to OrderID and Quantity.
4. Connect Price to ItemPrice.
5. Connect Name to ItemName.
Setting an Identifier = Header expression in the Header compound ensures that only Header type
rows will be written to this compound. The line identifier is the first character in each line.
Note that when you map compounds, all of their columns/elements are available in the Expression
Editor.
In the Destination Tree:
6. Park on the Header node and select Show Properties.
7. Park on the Condition property and select a condition for:
Src.S1/Record/Identifier ='H'
Solutions 241
Solutions 242