Workflow Configuration

|  | ## Workflow Configuration

Introduction

Workflows are first class objects in the Cheshire3 system -- they're configured at the same time and in the same way as other objects. Their function is to provide an easy way to define a series of common steps that can be reused by different Cheshire3 databases/systems, as opposed to writing customised code to achieve the same end result for each.

Build workflows are the most common type as the data must generally pass through a lot of different functions on different objects, however as explained previously the differences between databases are often only in one section. By using workflows, we can simply define the changed section rather than writing code to do the same task over and over again.

The disadvantage, currently, of workflows is that it is very complicated to find out what is going wrong if something fails. If your data is very clean, then a workflow is probably the right solution, however if the data is likely to have XML parse errors or has to go through many different preParsers and you want to verify each step, then hand written code may be a better solution for you.

The distribution comes with a generic build workflow object called 'buildIndexWorkflow'. It then calls 'buildIndexSingleWorkflow' to handle each individual document, also supplied. This second workflow then calls 'PreParserWorkflow', of which a trivial one is supplied, but this is very unlikely to suit your particular needs, and should be customised as required. An example would be if you were trying to build a database of legacy SGML documents, your PreParserWorkflow would probably need to call an SGML PreParser, configured to deal with the non-XML conformant parts of that particular SGML DTD

For a full explanation of the different tags used in workflow configuration, and what they do, see the Configuration section dealing with workflows.

Example 1

Simple workflow configuration:

    01  <subConfig type="workflow" id="PreParserWorkflow">
    02    <objectType>workflow.SimpleWorkflow</objectType>
    03    <workflow>
    04      <!-- input type:  document -->
    05      <object type="preParser" ref="SgmlPreParser"/>
    06      <object type="preParser" ref="CharacterEntityPreParser"/>
    07    </workflow>
    08  </subConfig>

Example 2

Slightly more complex workflow configurations:

    01  <subConfig type="workflow" id="buildIndexWorkflow">
    02    <objectType>workflow.SimpleWorkflow</objectType>
    03    <workflow>
    04      <!-- input type:  documentFactory -->
    05      <log>Loading records</log>
    06      <object type="recordStore" function="begin_storing"/>
    07      <object type="database" function="begin_indexing"/>
    08      <for-each>
    09        <object type="workflow" ref="buildIndexSingleWorkflow"/>
    10      </for-each>
    11      <object type="recordStore" function="commit_storing"/>
    12      <object type="database" function="commit_metadata"/>
    13      <object type="database" function="commit_indexing"/>
    14    </workflow>
    15  </subConfig>
    16
    17  <subConfig type="workflow" id="buildIndexSingleWorkflow">
    18    <objectType>workflow.SimpleWorkflow</objectType>
    19    <workflow>
    20      <!-- input type:  document -->
    21      <object type="workflow" ref="PreParserWorkflow"/>
    22      <try>
    23        <object type="parser" ref="SaxParser"/>
    24      </try>
    25      <except>
    26        <log>Unparsable Record</log>
    27      </except>
    28      <object type="recordStore" function="create_record"/>
    29      <object type="database" function="addRecord"/>
    30      <object type="database" function="indexRecord"/>
    31      <log>Loaded Record</log>
    32    </workflow>
    33  </subConfig>

Explanation

The first two lines of each configuration example are exactly the same as all previous objects. Then there is one new section -- workflow. This contains a series of instructions for what to do, primarily by listing objects to handle the data.

The workflow in example 1 is an example of how to override the PreParserWorkflow for a specific database. In this case we start by giving the document input object to the SgmlPreParser in line 5, and the result of that is given to the CharacterEntityPreParser in line 6. Note that lines 4 and 20 are just comments and are not required.

The workflows in Example 2 are slightly more complex with some additional constructions. Lines 5, 26, 31 use the log instruction to get the workflow to log the fact that it is starting to load records.

In lines 6 and 7 the object tags have a second attribute called 'function'. This contains the name of the function to call when it's not derivable from the input object. For example, a preParser will always call 'process_document', however you need to specify the function to call on a database as there are many available. Note also that there isn't a 'ref' attribute to reference a specific object identifier. In this case it uses the current session to determine which server, database, recordStore and so forth should be used. This allows the workflow to be used in multiple contexts (i.e. if configured at the server level it can be used by several databases).

The for-each block (lines 8-10) then iterates through the documents in the supplied documentFactory, calling another workflow, buildIndexSingleWorkflow (configured in lines 17-33), on each of them. Like the preParser objects mentioned earlier, workflow objects called don't need to be told which function to call - the system will always call their 'process' function. Finally the database and recordStore have their commit functions called to ensure that everything is written out to disk.

The second workflow in Example 2 is called by the first, and in turn calls the PreParserWorkflow configured in Example 1. It then calls a parser, carrying out some error handling as it does so (lines 22-27), and then makes further calls to the recordStore (line 28) and database (lines 29-30) objects to store and index the record produced.