Versions Compared

Key

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

...

Code Block
<simple-map-processors xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xsi:noNamespaceSchemaLocation="http://ofbiz.apache.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."/                                <!-- Note that fail-message is used here for the purpose of demonstration; 
                                but in general it's better to use fail-property because fail-message is not localisable -->
			</convert>not-empty>
		</process>
		<process field="estimatedMilliSecondspriority">
			<convert type="DoubleLong">
				<fail-message message="EstimatedPriority Milli-seconds is not a valid whole number."/>
			</convert>
		</process>
	</simple-map-processor>
	<simple-map-processor name="delete">
		<process field="workEffortIdestimatedStartDate">
			<copy/>
			<not-empty>
				<fail-message message="Work Effort ID is missing<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."/>
			</notcompare-empty>field>
		</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

...

	<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
simpmeth
simpmeth

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

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.

The ${} (dollar-sign-curly-brace) syntax can be used to insert an environment variable value in pretty much any string constant in a simple-method file. Not only can it be used to reference top-level environment variables, the syntax elements described below can be used to access values in sub-structures.

You can use the "." (dot) syntax to access Map members. For example if you specify the attribute field-name="product.productName"it will reference the productName member of the productMap. This would be the same as specifying map-name="product" field-name="productName". Note that this is, of course, more flexible than a field-name/map-name combination because the Map structure can be multiple levels deep. For example if you have use the attributefield-name="products.widget.productName" it will reference the productName in the widget Map which is in the products Map.

Wiki Markup
The "\[\]" (square-brace) syntax can be used to access list elements. For example you can specify the attribute field-name="products\[0\].productName"and it will reference the productName of the first (position zero) element in the products List. To make this more useful you can pull a list index from the environment using something like field-name="products\[$\{currentIndex\}\].productName".

Wiki Markup
There are two extensions to the \[\] syntax that can be used when referring to an environment location that is the target of an operation. If you do not include a number between the square braces the value will be put at the end of the list. If you put a "+" (plus sign) in front of the number between the square braces (ie: \[+2\]) it will insert the value before that position in the list instead of replacing the value at that location. For example, specifying \[+0\] would insert the value at the beginning of the list.

Wiki Markup
In fact, you can use the $\{\} syntax to substitute any string or other value at any location in a field-name or other string constant. So, you could even reference a Map member named in some other environment variable. For example you could use field-name="products\[$\{currentIndex\}\].productName".

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-

...

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

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.

The ${} (dollar-sign-curly-brace) syntax can be used to insert an environment variable value in pretty much any string constant in a simple-method file. Not only can it be used to reference top-level environment variables, the syntax elements described below can be used to access values in sub-structures.

You can use the "." (dot) syntax to access Map members. For example if you specify the attribute field-name="product.productName"it will reference the productName member of the productMap. This would be the same as specifying map-name="product" field-name="productName". Note that this is, of course, more flexible than a field-name/map-name combination because the Map structure can be multiple levels deep. For example if you have use the attributefield-name="products.widget.productName" it will reference the productName in the widget Map which is in the products Map.

Wiki Markup
The "\[\]" (square-brace) syntax can be used to access list elements. For example you can specify the attribute field-name="products\[0\].productName"and it will reference the productName of the first (position zero) element in the products List. To make this more useful you can pull a list index from the environment using something like field-name="products\[$\{currentIndex\}\].productName".

Wiki Markup
There are two extensions to the \[\] syntax that can be used when referring to an environment location that is the target of an operation. If you do not include a number between the square braces the value will be put at the end of the list. If you put a "+" (plus sign) in front of the number between the square braces (ie: \[+2\]) it will insert the value before that position in the list instead of replacing the value at that location. For example, specifying \[+0\] would insert the value at the beginning of the list.

Wiki Markup
In fact, you can use the $\{\} syntax to substitute any string or other value at any location in a field-name or other string constant. So, you could even reference a Map member named in some other environment variable. For example you could use field-name="products\[$\{currentIndex\}\].productName".

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

...

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>

...

Simple Methods Example

Code Block

<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

...


        xsi:noNamespaceSchemaLocation="[http://ofbiz.apache.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"/> 
            <!-- Note that fail-message is used here for the purpose of demonstration; 
                 but in general it's better to use fail-property because fail-message is not localisable -->
        </check-permission>
        <check-id field-name="productId" map-name="

...

parameters"/>
        <check-errors/>

...



    <make-value value-name="newEntity" entity-name="Product"/>

...


    <set-nonpk-fields map-name="parameters" value-name="newEntity"/>

...


    <set-pk-fields map-name="parameters" value-name="newEntity"/>

...



    <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"/>

...



    <!-- 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>