Entity Event Condition Actions

It is possible to write ECAs for specific entities using an Entity Event Condition Action (EECA) For example, to trigger an Event, say a notification Service, when a field in an entity changes, you could write an EECA as we shall see in this recipe.

How to do it...

Triggering a notification Service using EECA can be done by following these steps:

  1. If one does not already exist, add an entry in the ofbiz-component.xml file to identify the EECA definition file location as shown:
    <entity-resource type="eca" reader-name="main" loader="main"
    location="entitydef/eecas.xml"/>
    
  2. Create or add an EECA definition file with an XML version declaration and an XML XSD schema declaration, as shown here:
    <?xml version="1.0" encoding="UTF-8"?>
    <entity-eca xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation=
    "http://ofbiz.apache.org/dtds/entity-eca.xsd">
    
  3. Add one or more EECA definitions to the EECA definition file. Don't forget to close each eca element declaration with a closing tag (</eca>).
    <!-- To maintain FinAccount.actualBalance and
    FinAccount.availableBalance -->
    <eca entity="FinAccountTrans" operation="create-store"
    event="return">
    <action service="updateFinAccountBalancesFromTrans"
    mode="sync"/>
    </eca>
    
  4. Be sure to close all XML element tags.
  5. Save and close the EECA definition file.
  6. Restart OFBiz to make the changes effective.

How it works...

EECA rules are checked before and/or after a call to access the database. Services defined by the action element are invoked when the configured entity is accessed by way of the operation attribute setting.

There's more...

Commonly used EECA attribute values are shown in the following table:

eca tag (Required)

  

Attribute name

Required?

Description

entity

Yes

The name of the entity on which this operation and Event are to be applied to.

operation

Yes

Valid values: create, store, remove, find, create-store, create-remove, store-remove, create-store-remove, any.

event

Yes

Valid Values: validate, return, run, cache-check, cache-put, cache-clear.

To configure action elements for an EECA, the following configuration attribute values are supported:

action tag (Required)

  

Attribute name

Required?

Description

service

Yes

The name of the Service to call if this operation is encountered.

mode

Yes

Valid values: sync, async.

value-attr

No

Values to pass to the Service being called as a result of this ECA.

To add one or more triggering conditions, add condition element declarations with the appropriate settings:

condition Tag (optional)

Used to trigger actions based on one or more Entity fields meeting the specified conditions.

  

Attribute name

Required?

Description

field-name

Yes

The name entity field.

operator

Yes

Valid values: less, greater, less-equals, greater-equals, equals, not-equals, is-empty, is-not-empty, contains.

type

No

Valid values: PlainString, BigDecimal, Double, Float, Long, Integer, Date, Time, Timestamp, Boolean, Object.

Default: String.

set elements are used to equate entity field(s) or context variables to values. set declarations may be configured as shown:

set Tag (optional)

Use the set declaration to establish or set the ECA on a specific field within an entity.

  

Attribute name

Required?

Description

field-name

Yes

Indicates the value is an entity field.

value

No

The name of the field.

See also

Please see the EECA XSD located at ~framework/entity/dtd/entity-eca.xsd.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.12.156