Jump to: navigation, search

SMILA/Documentation/HowTo/How to filter and access record data in BPEL

< SMILA‎ | Documentation‎ | HowTo
Revision as of 08:28, 24 January 2012 by Juergen.schumacher.attensity.com (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This tutorial shows how to add record attributes to a BPEL workflow object and read or write them. Note that this procedure is only necessary if you want to make record data available for being used in BPEL, e.g. to evaluate conditions in the BPEL pipeline or to pass data to external webservices. It is not required for the usage of pipelets.

Adding record data to the BPEL workflow object

Because the workflow object contains the record IDs only, it is not possible by default to access the data contained in a record. However, you can configure the blackboard service to add particular attributes and annotations to the workflow object to make theme available for being used in BPEL. This is achieved by providing the file org.eclipse.smila.blackboard/RecordFilters.xml in the global configuration folder and defining a filter named workflow-object that lists all attributes and annotations that you want to have access to in BPEL. The name of this filter is defined by the record.filter parameter set in the configuration file of the processing service found at org.eclipse.smila.processing.bpel/processor.properties. If you wish to write data to attributes you will have to add them to the filter likewise.

Example

The following listing shows an exemplary configuration of the file RecordFilters.xml. It adds a couple of attributes (e.g. Filename, Path, LastModifiedData, ...) to the workflow object. For some of the attributes the keepAnnotations parameter is set to "true" to define that the object should include the annotations of the corresponding attribute too.

<RecordFilters>
  <Filter name="workflow-object">
    <Attribute name="Filename"/>
    <Attribute name="Path"/>
    <Attribute name="LastModifiedDate"/>
    <Attribute name="Url"/>
    <Attribute name="Title"/>
    <Attribute name="Extension"/>
    <Attribute name="Size"/>
    <Attribute name="MimeType"/>
  </Filter>
</RecordFilters>

Using records in BPEL

Next to the configuration of the attribute/annotation filter mentioned above, you will have to make sure that the following requirements are met if you wish to access records in BPEL:

  • The XML namespaces for processor and record must be defined.
  • The processor processor.wsdl must be imported.
  • A variable (e.g. request) must be defined that contains the ProcessorMessage.

Here are the corresponding XML snippets:

<process ...  xmlns:proc="http://www.eclipse.org/smila/processor" xmlns:rec="http://www.eclipse.org/smila/record" ... >
    ...
  <import location="processor.wsdl" namespace="http://www.eclipse.org/smila/processor"
    importType="http://schemas.xmlsoap.org/wsdl/" />
    ...
  <variables>
    <variable name="request" messageType="proc:ProcessorMessage" />
  </variables>
    ...
</process>

Provided that you added the filter configuration and ensured the requirements above it is possible to access records and their contents via the variable request. This variable contains an array of records. Each record can be accessed via its index number (starting at 1). So to be able to process all records, you will have to wrap the record access and execution of any business logic in a loop.

Here are some templates to access (read or write):

  • an attribute value: $<variable>.records/rec:Record[position()=<index>]/rec:Val[@key="<Attribute-Name>"]

For more details on the XML schemas and the WSDL see the files id.xsd, record.xsd, and processor.wsdl in the folder configuration/org.eclipse.smila.processing.bpel/pipelines.

Examples

Reading an attribute

The value of the attribute Title is read from the first record and stored in the variable input.param.

...
<assign name="copy-attribute-to-variable">			
    <copy>
        <from>$request.records/rec:Record[position()=1]/rec:Val[@key="Title"]</from>
        <to>$input.param</to>
    </copy>
</assign>
...

Writing an attribute

The value of the variable response.param is stored in the attribute Title of the second record.

...
<assign name="copy-variable-to-attribute">
    <copy>
        <from>$response.param</from>
        <to>$request.records/rec:Record[position()=2]/rec:Val[@key="Title"]/text()</to>
    </copy>
</assign>
...

Note that in standard BPEL the target element that you want to write data to, must already exist before text can be stored in it, thus it is not possible to add new attributes, literal, and values to the workflow object this simply.

Examples in SMILA source code

Have a look at the pipelines of the standard configuration in SMILA.application/configuration/org.eclipse.smila.processing.bpel/pipelines or the test pipelines in bundle org.eclipse.smila.processing.bpel.test/configuration/org.eclipse.smila.processing.bpel/pipelines. You can find lots of examples for usage of BPEL control structures and XPath queries in there.