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.
Triggering a notification Service using EECA can be done by following these steps:
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"/>
<?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">
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>
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.
Commonly used EECA attribute values are shown in the following table:
eca tag (Required) | ||
---|---|---|
Attribute name |
Required? |
Description |
|
Yes |
The name of the entity on which this operation and Event are to be applied to. |
|
Yes |
Valid values: |
|
Yes |
Valid Values: |
To configure action
elements for an EECA, the following configuration attribute values are supported:
action tag (Required) | ||
---|---|---|
Attribute name |
Required? |
Description |
|
Yes |
The name of the Service to call if this operation is encountered. |
|
Yes |
Valid values: |
|
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 |
|
Yes |
The name entity field. |
|
Yes |
Valid values: |
|
No |
Valid values: Default: |
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 | ||
---|---|---|
Attribute name |
Required? |
Description |
|
Yes |
Indicates the value is an entity field. |
|
No |
The name of the field. |
3.145.12.156