Written By: David E. Jones, jonesde@ofbiz.org
...
Table of Contents
- Introduction
- The Simple Map Processor Mini-Language
- Simple Map Processor Overview
- Make In String Operations
- Process Field Operations
- Simple Map Processors Example
- The Simple Method Mini-Language
- Simple Method Overview
- Special Context Access Syntax
- Call Operations
- Java Call Operations
- Control and Error Handling Operations
- Event Specific Operations
- Service Specific Operations
- Method Environment Operations
- Entity Engine Misc. Operations
- Entity Engine Find Operations
- Entity Engine Value Operations
- Entity Engine List Operations
- Entity Engine Transaction Operations
- Conditional (If) Operations
- Other Operations
- Simple Methods Example
...
Anchor | ||||
---|---|---|---|---|
|
...
The Mini-Language concept in Open For Business is similar to the Gang of Four Interpreter pattern, or the Mark Grand Little Language pattern. This is also the central theme of the Building Parsers with Java book by Steven John Metsker which the OFBiz Rule Engine is based on. The idea is to create simple languages that simplify complex or frequently performed tasks.
...
Code Block |
---|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="[to be modified www.ofbiz.org/dtds/simple-methods.xsd]"> |
Anchor | ||||
---|---|---|---|---|
|
- Simple Map Processor Overview
- Make In String Operations
- Process Field Operations
- Simple Map Processors Example
...
Anchor | ||||
---|---|---|---|---|
|
The Simple Map Processor Mini-Language performes two primary tasks: validation and conversion. It does this in a context of moving values from one Map to another. The input map will commonly contain Strings, but can contain other object types like Integer, Long, Float, Double, java.sql.Date, Time, and Timestamp.
Panel | ||
---|---|---|
NOTE: The reference information for the simple-map-processor has been moved to annotations in We hope to recommended soon a tool that will use XSL/Transform to render the documentation directly from the XSD file in Browsers |
...
Anchor | ||||
---|---|---|---|---|
|
Code Block |
---|
<simple-map-processors xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="[to be modified www.ofbiz.org/dtds/simple-methods.xsd]"> <simple-map-processor name="update"> <make-in-string field="estimatedStartDate"> <in-field field="estimatedStartYear"><constant>-</constant> <in-field field="estimatedStartMonth"><constant>-</constant> <in-field field="estimatedStartDay"><constant>T</constant> <in-field field="estimatedStartHour"><constant>:</constant> <in-field field="estimatedStartMinute"><constant>:</constant> <in-field field="estimatedStartSecond"> </make-in-string> <process field="workEffortId"><copy replace="false"/></process> <process field="scopeEnumId"><copy/></process> <process field="currentStatusId"> <copy/> <not-empty> <fail-message message="Status is missing."/> </not-empty> </process> <process field="priority"> <convert type="Long"> <fail-message message="Priority is not a valid whole number."/> </convert> </process> <process field="estimatedStartDate"> <compare-field operator="less" field="estimatedCompletionDate" type="Timestamp" format="yyyy-MM-dd'T'HH:mm:ss"> <fail-message message="Estimated Start date/time must be BEFORE End date/time."/> </compare-field> <convert type="Timestamp" format="yyyy-MM-dd'T'HH:mm:ss"> <fail-message message="Estimated Start Date is not a valid Date-Time."/> </convert> </process> <process field="estimatedCompletionDate"> <convert type="Timestamp"> <fail-message message="Estimated Completion Date is not a valid Date-Time."/> </convert> </process> <process field="estimatedMilliSeconds"> <convert type="Double"> <fail-message message="Estimated Milli-seconds is not a valid number."/> </convert> </process> </simple-map-processor> <simple-map-processor name="delete"> <process field="workEffortId"> <copy/> <not-empty> <fail-message message="Work Effort ID is missing."/> </not-empty> </process> </simple-map-processor> </simple-map-processors> |
...
The Simple Method Mini-Language
- Simple Method Overview
- Special Context Access Syntax
- Call Operations
- Java Call Operations
- Control and Error Handling Operations
- Event Specific Operations
- Service Specific Operations
- Method Environment Operations
- Entity Engine Misc. Operations
- Entity Engine Find Operations
- Entity Engine Value Operations
- Entity Engine List Operations
- Entity Engine Transaction Operations
- Conditional (If) Operations
- Other Operations
- Simple Methods Example
...
Simple Method Overview
Anchor | ||||
---|---|---|---|---|
|
The Simple Method Mini-Language is a simple way to implement an event that is invoked by the Control Servlet or a service that is invoked by the Service Engine. A Simple Method can be invoked through the static methods on the SimpleMethod class, or as an event through an entry in the controller configuration XML file like the following:
...
In this Mini-Language you can invoke Simple Map Processors, Services and bsh scripts, perform entity related operations, and create messages to return to the caller. Specific operations can be enclosed in if blocks to execute conditionally and values or fields can be copied around in the maps, lists and method environment.
There are a number of tags which can be used to get and set attributes to/from a request or session object when called as an event or to set attributes in the result when called as a service. These operations are only applied when applicable. In other words if you include an env-to-request operation it will only be invoked when the simple-method is called as an event and an env-to-result operation will only be invoked when the simple-method is called as a service. Everything else is the same when called as an event or a service which makes it easy to write flexible logic that can be mounted/applied in various ways.
There are a number of objects that exist in the method environment when a simple-method starts or that are used as it executes to keep track of certain information. Some will exist when called as an event or a service, these are marked in the XSD. Each name can be overridden using an attribute on the simple-method tag. The defaults are listed below in the XSD.
Panel | ||
---|---|---|
NOTE: The reference information for simple-method has been moved to annotations in |
...
Special Context Access Syntax
In strings and field names a special syntax is supported to flexibly access Map member, List elements and to insert environment values into string constants.
...
Okay, enough of the general stuff, you may find in the XSD file descriptions of the available operations. Here is simply a categorized list of them.
...
Call Operations
call-map-processor
call-service
call-service-asynch
call-bsh
call-simple-method
...
Java Call Operations
create-object
call-object-method
call-class-method
...
Control and Error Handling Operations
check-errors
add-error
return
...
Event Specific Operations
field-to-request
field-to-session
request-to-field
request-parameters-to-list
session-to-field
webapp-property-to-field
Service Specific Operations
field-to-result
...
Method Environment Operations
map-to-map
field-to-list
order-map-list (not documented in XSD yet)
set (not documented in XSD yet)
string-append (not documented in XSD yet)
string-to-list (not documented in XSD yet)
to-string
clear-field
...
field-to-field (deprecated, do not use)
env-to-env (deprecated, do not use)
env-to-field (deprecated, do not use)
field-to-env (deprecated, do not use)
string-to-field (deprecated, do not use)
...
Control Operations
iterate
first-from-list
...
Entity Engine Misc. Operations
now-timestamp-to-env
now-date-to-env
...
Attribute Name | Required? | Description |
---|---|---|
value-name | Y | The name of the method environment field that contains the UserLogin GenericValue object. |
...
Entity Engine Find Operations
find-by-primary-key
The find-by-primary-key tag uses the delegator to find an entity value by its primary key. The resulting GenericValue object will be placed in the method environment using the specified value-name.
...
Attribute Name | Required? | Description |
---|---|---|
list-name | Y | The name of the method environment field that contains the list of GenericValue objects. |
to-list-name | N | The name of the method environment field the filtered list will be put into. Defaults to the value of the list-name attribute (ie goes to the same place it came from, replacing the old list). |
valid-date-name | N | The name of a field in the method environment date to filter by. Defaults to now. |
from-field-name | N | The name of the GenericValue field to use as the beginning effective date. Defaults to fromDate. |
thru-field-name | N | The name of the GenericValue field to use as the ending effective date. Defaults to thruDate. |
all-same | N | Specifies whether or not all GenericValue objects in the list are of the same entity. Defaults to true. |
...
Entity Engine Value Operations
make-value
The make-value tag uses the delegator to construct an entity value. The resulting value will not necessarily exist in the database, but will simply be assembled using the entity-name and fields map. The resulting GenericValue object will be placed in the method environment using the specified value-name.
...
Attribute Name | Required? | Description |
---|---|---|
value-name | Y | The name of the method environment field that contains the GenericValue object. |
map-name | Y | The name of a map in the method environment that will be used for the entity fields. |
set-if-null | N | Specifies whether or not to set fields that are null or empty. Defaults to true. |
...
Entity Engine List Operations
store-list
The store-list tag uses the delegator to store all entity values in the list. This is different than storing a single value in that values in the list will be inserted if it does not exist or updated if it does exist.
...
Attribute Name | Required? | Description |
---|---|---|
list-name | Y | The name of the method environment field that contains the list of GenericValue objects. |
...
Entity Engine Transaction Operations
transaction-begin
The transaction-begin tag will begin a transaction if one is not already in place. If a transaction is begun the environment field named as the began-transaction-name will be set to true, otherwise it will be set to false.
...
Attribute Name | Required? | Description |
---|---|---|
began-transaction-name | N | The name of the method environment field that contains a Boolean specifying whether or not a transaction was begun in the current transaction demarcation. Defaults to "beganTransaction". |
...
Conditional (If) Operations
if
The if operation offers a flexible way of specifying combinations of conditions, alternate conditions, and operations to run on true evaluation of the conditions or to run otherwise.
...
Attribute Name | Required? | Description |
field-name | Y | The name of the field that contains the ID value to check. |
map-name | N | The name of the Map that contains the field. If not specified the environment will be used to find the field. |
error-list-name | N | The name of a list in the method environment that the error messages will be added to. Will be created if does not exist. Defaults to "error_list". |
Sub-Element Name | How Many | Description |
fail-message | one | An inline failure message. |
fail-property | one | A failure message from a properties file. |
...
Other Operations
property-to-field
The property-to-field tag puts the inlined string value in the specified field.
...
Here is an example of an XML snippet that performs the calculationa=b+(((c+x+2)-d)/e), or in Reverse Polish Notation (a little bit closer to the resulting XML, and the notation used in the Rule Engine)a=(b,/(((c,x,2),-d),e)). Here is the XML: <calculate field-name="a">
<calcop operator="get" field-name="b"/>
<calcop operator="divide">
<calcop operator="multiply">
<calcop operator="add" field-name="c">
<calcop operator="get" field-name="x"/>
<number value="2"/>
</calcop>
<calcop operator="negative" field-name="d"/>
</calcop>
<calcop operator="get" field-name="e"/>
</calcop>
</calculate>
...
Simple Methods Example
Wiki Markup |
---|
<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="\[<span style="color: #ff0000"><strong>to be modified</strong></span> [www.ofbiz.org/dtds/simple-methods.xsd]\]"><simple-method method-name="createProduct" short-description="Create an Product"> <check-permission permission="CATALOG" action="_CREATE"><fail-message message="Security Error: to run createProduct you must have the CATALOG_CREATE or CATALOG_ADMIN permission"/></check-permission> <check-id field-name="productId" map-name="parameters"/> <check-errors/> |
...