Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

In progress of being transferred to the Wiki.

Once transferred will need to confirm if this is deprecated and then archive.

Table of Contents

Table of Contents

Introduction

he 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.

...

The only difference between the two DOCTYPE definitions is the root node to use from the DTD.

The Simple Map Processor Mini-Language

  • Simple Map Processor Overview
  • Make In String Operations
  • Process Field Operations
  • Simple Map Processors Example

Simple Map Processor Overview

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.

NOTE: The reference information for the simple-map-processor has been moved to annotations in the simple-methods.xsd file.

Simple Map Processors Example

<!DOCTYPE simple-map-processors PUBLIC "-//OFBiz//DTD Simple Methods//EN" "http://ofbiz.apache.org/dtds/simple-methods.dtd">

<simple-map-processors>
<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

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:

...

Attribute NameReqd?Default ValueDescription
method-nameYN/AA name (preferably a legal Java identifier) for this method. This name must be unique for the XML file it is in as it will be used to reference this method externally.
short-descriptionYN/AA short description of the method for certain system error messages.
login-requiredN"true"Is a logged in user (UserLogin object, or login.username and login.password Strings) required to run this method? "true" or "false".
use-transactionN"true"Create a transaction if none exists for this thread? "true" or "false".
default-error-codeN"error"The default error return code.
default-success-codeN"success"The default success return code.
parameter-map-nameN"parameters"As event: copy of request parameters
As service: incoming context
event-request-object-nameN"request"(as event only)
event-response-code-nameN"_response_code_"(as event only)
event-error-message-nameN"_error_message_"(as event only)
event-event-message-nameN"_event_message_"(as event only)
service-response-message-nameN"responseMessage"(as service only)
service-error-message-nameN"errorMessage"(as service only)
service-error-message-list-nameN"errorMessageList"(as service only)
service-success-message-nameN"successMessage"(as service only)
service-success-message-list-nameN"successMessageList"(as service only)
delegator-nameN"delegator"A GenericDelegator object to use in the method
security-nameN"security"A Security object to use in the method
dispatcher-nameN"dispatcher"A LocalDispatcher object to use in the method

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, here is a catalog and description of the available operations.

Call Operations

call-map-processor

The call-map-processor tag invokes a simple map processor from an existing map, creating a new map or adding to an existing one if the named out-map already exists. Resulting messages are added to the named list, and a new list is created if a list with the given name does not yet exist. Note that all lists and maps exist in the same context and must have unique names.

...

Attribute NameRequired?Description
xml-resourceNThe full path and filename on the classpath of the XML file which contains an external simple-method to execute. This is only required if a simple-method in a different file is desired.
method-nameYThe name of the simple-method to execute in the specified xml-resource, or in the current XML file if no xml-resource is specified.

Java Call Operations

create-object

Creates an object of the given class and if the field-name is specified saves it in that field.

...

Sub-Element NameHow ManyDescription
string0 to manyUsed to specify an inline String argument to the method call.
field0 to manyUsed to specify a field to be passed as an argument to the method call. The field can be in a map in the environment or if no map-name is specified then the field will come directly from the environment.

Control and Error Handling Operations

check-errors

The message lists from invoking are not checked until the check-errors tag is used. The named list is checked and if it contains any messages they are put in the servlet request object and the specified error code is returned to the control servlet.

...

Attribute NameRequired?Description
response-codeNThe string to return as a response code. Defaults to "success".

Event Specific Operations

field-to-request

The field-to-request tag copies a field from a map to the specified servlet request attribute.

...

Attribute NameRequired?Description
resourceYThe resource location of the properties file inside the webapp, and relative to the root of the webapp (can be inside a war file). An example of this is "/WEB-INF/myprops.properties".
propertyYThe property whose value will be put in the field.
defaultNA default value to use if the property value is null or empty. This will also be used when NOT running as an event.
map-nameNThe name of the map in the method environment. If not specified the field-name will be used to set the field in the method environment.
field-nameYThe name (key) of the map field to use.

Service Specific Operations

field-to-result

The field-to-result tag copies a field from a map to the specified service result field.

...

Attribute NameRequired?Description
map-nameNThe name of the map in the method environment. If not specified the field-name will be used to get the field from the method environment.
field-nameYThe name (key) of the map field to use.
result-nameNThe name of the request attribute to use. Defaults to the field-name.

Method Environment Operations

map-to-map

The map-to-map tag copies all fields from one map to another map

...

Attribute NameRequired?Description
entry-nameYThe name of the method environment field that will contain the first entry in the list.
list-nameYThe name of the method environment field that contains the list to get the first entry from.

Entity Engine Misc. Operations

now-timestamp-to-env

The now-timestamp-to-env tag creates a java.sql.Timestamp object with the current date and time in it and puts it in a field in the method environment.

...

Attribute NameRequired?Description
value-nameYThe 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.