Altova FlowForce Server 2024 

Create a Directory Polling Job

Home Prev Top Next

This example shows you how to monitor a directory for changes with the help of a file system trigger created in FlowForce Server (see also File System Triggers). Whenever a new XML file is added to the directory, FlowForce Server executes a mapping job that takes the XML file as input parameter. The output of the mapping job is then moved to an archive directory.

 

Prerequisites

Required licenses: MapForce Enterprise or Professional edition, MapForce Server or MapForce Server Advanced Edition, and FlowForce Server

The FlowForce Web Server and FlowForce Server services must be listening at the configured network address and port

You have a FlowForce Server user account with permissions to one of the containers (by default, the /public container is accessible to any authenticated user).

The mapping job created in this example copies files from one directory to another. Therefore, on the operating system where FlowForce Server runs, ensure that both directories exist and that you have rights to create files in both directories. This example uses the C:\FlowForceExamples\DirPolling and C:\FlowForceExamples\Archive directories.

 

Demo files used

ShortApplicationInfo.mfd — the MapForce mapping from which the FlowForce Server job will be created

ApplicationsPage.xml — the XML instance file to be supplied as input to the mapping.

 

Both files are available at the following path on the machine where MapForce is installed: <Documents>\Altova\MapForce2024\MapForceExamples\.

 

What the mapping does

The MapForce mapping used in this example (ShortApplicationInfo.mfd) is illustrated below. From a FlowForce Server perspective, the important thing is that the mapping takes an XML file as input, and produces another XML file as output.

 

Essentially, this mapping converts an XML file (ApplicationsPage.xml) to a different schema and saves it as ShortInfo.xml. The mapping is relatively easy to understand by looking at the topmost connection: for each Item found in the source, it creates an Info item in the target. The other connections are used to copy values from the respective child items. Of particular interest is the dotted connection; in MapForce, this connection is called "Source-driven (Mixed Content)" and it is used because SubSection contains mixed content.

ff_map_ShortApplicationInfo

ShortApplicationInfo.mfd

Notice the names of the source and target XML schemas are SectionedPage and ShortInfo, respectively. As you will see further below, the FlowForce job will have an input and output parameter with the same name, after the mapping is deployed to FlowForce Server.

 

Deploying the mapping to FlowForce Server

The mapping ShortApplicationInfo.mfd does not need any special preparation before it is deployed to FlowForce Server. Since both the source and target components are XML files, they will be included automatically in the package deployed to FlowForce Server.

 

To deploy the mapping to FlowForce, open it in MapForce and run the menu command File | Deploy to FlowForce Server.

fs_ex_dir_polling_02

If FlowForce Server runs on a different host and port, change the connection details above accordingly, see Defining the Network Settings. Also note that the path of the mapping is /public/Examples/ShortApplicationInfo.mapping; this is consistent with previous examples.

 

Creating the directory polling job

After the mapping is deployed to FlowForce Server, the browser opens and loads the job creation page. As illustrated below, the first execution step is created automatically and it calls the mapping function deployed previously. Notice that the input parameter has the same name as the source MapForce component (SectionedPage), while the output parameter has the same name as the target component (ShortInfo).

fs_ex_dir_polling_03

Configure the job as follows:

 

1.In the Working-directory box, enter the path to the working directory. This example uses C:\FlowForceExamples\DirPolling as working directory.

A working directory is a parameter required by execution steps if the job needs a location to unpack any input files or save output files. FlowForce Server also uses the working directory to resolve any relative paths that occur during step execution. When asked to provide a working directory, you should supply a valid path on the operating system where FlowForce Server runs. If you do not supply a working directory when creating the step, FlowForce Server uses a temporary directory.

2.Under "Triggers", click new Filesystem trigger. Notice that FlowForce Server automatically adds a new triggerfile parameter under "Input Parameters". You will need to refer to this parameter in a subsequent step.

TriggerfileParameter

3.Set the following trigger values:

 

Check: Modified Date

File or directory: C:\FlowForceExamples\DirPolling\*.xml

Polling interval: 60 seconds

fs_ex_dir_polling_05

4.Under Execution Steps, supply the triggerfile parameter as input value to the SectionedPage parameter. To do this, click the ff-setTo button next to the SectionedPage parameter, and then select triggerfile. As a result, the value of the SectionedPage parameter changes to {triggerfile}. The curly braces denote a FlowForce expression and should not be removed.

fs_ex_dir_polling_06

With the configuration done so far, the trigger will fire whenever ApplicationsPage.xml is copied into the working directory. However, since the trigger uses a wildcard (*.xml), it would be fired also when any other XML file changes inside the directory, including the mapping output itself (ShortInfo.xml). This is not the intended behavior and could cause errors; therefore, let's add a second step that will move the generated output file to a new directory. Alternatively, you could rename the trigger to C:\FlowForceExamples\DirPolling\ApplicationsPage.xml (in this case, a second step is no longer necessary).

 

To add the step which moves the output to a new directory, do the following:

 

1.Add a new execution step, immediately after the previous one.

2.Configure the step as follows (note that the source and destination fields are case-sensitive):

 

Execute function

Browse for the /system/filesystem/move function.

Source

ShortInfo.xml

 

We used a relative path because the Working Directory parameter is set, see below.

Destination

This must be an existing file or directory path on the operating system where FlowForce Server runs. Set it to:

 

C:\FlowForceExamples\Archive

Overwrite target

Select this check box. This instructs FlowForce Server to overwrite any file with the same name found at the destination path.

Abort on error

Leave this parameter as is.

 

Optional parameter. This parameter determines the outcome of a job in which an error has occurred. If the Abort on error parameter is true, job execution will be terminated. If the Abort on error parameter is false, FlowForce Server will ignore errors and continue job execution. The default value is true.

Working directory

FlowForce will look for all relative file paths in this directory. Set it to:

 

C:\FlowForceExamples\DirPolling

fs_ex_dir_polling_07

Finally, add your operating system credentials with which the job will be executed:

 

1.Under "Credentials", select an existing credential record or specify a local credential. For more information, see Credentials.

2.Click Save.

 

Running the job

You can now test the job by copying the file ApplicationsPage.xml to the working directory. When you do this, FlowForce Server executes the mapping job and copies the resulting output file to the archive directory.

 

To see whether the job executed successfully, refer to the job log.

© 2017-2023 Altova GmbH