Welcome Guest! Log in


It is a common task to get a batch of files and treat them in a process, one by one. Here is a nice way to handle this iteration, using the FileWait action.

What we want to do

We have a directory which contains the following files:

stambia@devsrv01:~/support/data/TC00xx/TC0002/inputfiles$ ls -l
total 528
-rw-r--r-- 1 stambia stambia 125142 9 oct. 09:15 customers.xml
-rw-r--r-- 1 stambia stambia 16495 9 oct. 09:16 Invoice
-rw-r--r-- 1 stambia stambia 126000 9 oct. 09:14 ORDERS.CSV
-rw-r--r-- 1 stambia stambia 251222 9 oct. 09:16 PRODUCTS.TXT

 

We want to get the list of those files, and pass each file name to a different subprocess, depending on the file extension :

  • .csv files => subprocessCsv
  • .xml files => subprocessXml
  • other files => subprocessFlat

To do this, we are going to use the FileWait action, which can be used as a bind source since version S17.2.8.

 

The medata

We only need a metadata for the directory which contains the files :

DirMetadata

 

The process

Create a new process, and add a "Wait for files" action.

Drag the "inputdir" directory metadata on this action, and set the property WAIT_FILE_NB_FILES to -1.

This means that the FileWait action will wait for an unlimited number of files.

Note : if we specify a WAIT_FILE_TIMEOUT of 60000, the action would last 1 minute and continuously detect new incoming files during this minute. Here, we do not want this behaviour, so the action will end after getting the currently existing files.

p01filewait

 

Now that the FileWait action gets the files list, we are going to bind it to 3 ExecuteDelivery actions.

Each bind link will have an execution condition, in order to execute the delivery only for the files that have the required extension.

Add three ExecuteDelivery actions to the process, and configure them like this :

  • ProcessCSV
    • DELIV_NAME: subprocessCsv
    • fileName: :{FILE_NAME}:
  • ProcessXML
    • DELIV_NAME: subprocessXml
    • fileName: :{FILE_NAME}:
  • ProcessFlat
    • DELIV_NAME: subprocessFlat
    • fileName: :{FILE_NAME}:

Then, create the bind links between the Filewait action and the ExecuteDelivery actions:

p02ExecuteDeliv

 

Now here is how to specify the execution condition. Select a bind link, and edit the Execution Condition in the properties view:

p03bindcondition

 

Here are the 3 conditions we chose to implement :

  • Link to ProcessCsv: %b(rhino){(":{FILE_NAME}:".substr(-4).toLowerCase()==".csv")}b(rhino)%
  • Link to ProcessXml: %b(rhino){(":{FILE_NAME}:".substr(-4).toLowerCase()==".xml")}b(rhino)%
  • Link to ProcessFlat: %b(rhino){(":{FILE_NAME}:".substr(-4).toLowerCase()!=".csv") && (":{FILE_NAME}:".substr(-4).toLowerCase()!=".xml")}b(rhino)%

Please see the article "How to condition the execution of a bound action", for more information on this type of condition.

 

Execution

After executing the process, you can see the Number of files that were detected by the FileWait action :

exec

 

And also the number of executions of each ExecuteDelivery :

exec2

 

You have no rights to post comments

Articles

Suggest a new Article!