Versions Compared

Key

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

Written Originally written By: David E. Jones, jonesde@ofbiz.org

...

To specify the XMLschema for a simple-methods or simple-map-processors XML file use the following:

Code Block
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/simple-methods.xsd">

...

The Simple Map Processor Mini-Language performs 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

(info) NOTE: The reference information for the simple-map-processor has been moved to annotations in the http://ofbiz.apache.org/dtds/simple-methods.xsdfile. The idea is to now to use an XML completion tool in development. If you are interested by this issue please take a look at https://issues.apache.org/jira/browse/OFBIZ-571

As static documentation you may find a simple-methods.html generated file in attachments. This file may be out of date but with the attached simple-methods.xsl file you are able to generate an updated file. In such case please feel free to put a comment below in order to let us know, thanks.

Anchor
smapex
smapex
Simple Map Processors Example

...

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:

Code Block
<event type="simple" path="org/ofbiz/commonapp/workeffort/workeffort/WorkEffortSimpleEvents.xml" invoke="update"/>

or as a service through an entry in a services.xml file like the following:

Code Block
<service name="createPartyRole" engine="simple" location="org/ofbiz/commonapp/party/party/PartyRoleServices.xml" invoke="createPartyRole" auth="true">
	<description>Create a Party Role (add a Role to a Party)</description>
	<attribute name="partyId" type="String" mode="IN" optional="true"/>
	<attribute name="roleTypeId" type="String" mode="IN" optional="false"/>
</service>

The path or location for a Simple Method is the classpath and filename of the XML file.

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

(info) NOTE: The reference information for simple-method has been moved to annotations in the http://ofbiz.apache.org/dtds/simple-methods.xsdfile. The idea is to now to use an XML completion tool in development. If you are interested by this issue please take a look at https://issues.apache.org/jira/browse/OFBIZ-571

As static documentation you may find a simple-methods.html generated file in attachments with reference information. This file may be out of date but with the also attached simple-methods.xsl file you are able to generate an updated file. In such case please feel free to put a comment below in order to let us know about that, thanks.

Special Context Access Syntax

...

Here is an example of an XML snippet that performs the calculation a=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:

Code Block
<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>

...

<now-timestamp-to-env env-name="newEntity.lastModifiedDate"/>
<now-timestamp-to-env env-name="newEntity.createdDate"/>
<set from-field="userLogin.userLoginId" field="newEntity.lastModifiedByUserLogin"/>
<set from-field="userLogin.userLoginId" field="newEntity.createdByUserLogin"/>
<create-value value-name="newEntity"/>unmigrated-wiki-markup

<\!-\- induce keywords if autoCreateKeywords is emtpy or Y-\->
<if-empty field-name="autoCreateKeywords" map-name="newEntity">
<call-bsh><\!\[CDATA[org.ofbiz.commonapp.product.product.KeywordSearch.induceKeywords(newEntity);]\]></call-bsh>
<else>
<if-compare field-name="autoCreateKeywords" map-name="newEntity" operator="equals" value="Y">
<call-bsh><\!\[CDATA[org.ofbiz.commonapp.product.product.KeywordSearch.induceKeywords(newEntity);]\]></call-bsh>
</if-compare>
</else>
</if-empty>
</simple-method>
<simple-method event-name="create" short-description="Create Work Effort">
<call-map-processor xml-resource="org/ofbiz/commonapp/workeffort/workeffort/WorkEffortMapProcessors.xml"
processor-name="update" in-map-name="parameters" out-map-name="context"/>
<check-errors/>
<call-service service-name="createWorkEffort" in-map-name="context">
<default-message>Work Effort successfully created.</default-message>
<result-to-request result-name="workEffortId"/></service>
</simple-method>
<simple-method event-name="update" short-description="Update Work Effort">
<call-map-processor xml-resource="org/ofbiz/commonapp/workeffort/workeffort/WorkEffortMapProcessors.xml"
processor-name="update" in-map-name="parameters" out-map-name="context"/>
<check-errors/>
<call-service service-name="updateWorkEffort" in-map-name="context">
<default-message>Work Effort successfully updated.</default-message></service>
</simple-method>

</simple-methods>