...
The check-id tag checks to see if the ID value in the given field is a valid ID string. Valid IDs can be any sequence of characters or digits but must not containt the following characters: space [ ], doublequote ["], single quote ['], ampersand [&], question mark [?], less-than sign [<], greater-than sign [>].
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.
Attribute Name | Required? | Description |
---|---|---|
resource | Y | The resource location of the properties file. |
property | Y | The property whose value will be put in the field. |
default | N | The default value to use if the specified property is empty. |
map-name | N | The 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-name | Y | The name (key) of the map field to use. |
log
The log tag logs a message used the OFBiz Debug class, which uses Log4J to log to the console, a file, or some other location. The message is a concatenation of the message attribute and then all of the field and string sub-element values in the order they are specified.
Attribute Name | Required? | Description |
---|---|---|
level | Y | The logging/debug level to use. Must be one of the following: verbose | timing | info | important | warning | error | fatal | always. These are the standard OFBiz logging levels. |
message | N | A shortcut for simple messages. If used along with field and/or string sub-elements the inline string in the message will come first. |
Sub-Element Name | How Many | Description |
---|---|---|
field | 0 to many | Inserts the value of the field into the message where specified. |
string | 0 to many | Inserts the value of the inline string into the message where specified |
calculate
The calculate tag performs the specified calculation and puts the result in an object in the field of the specified map (see the calculate element attribute descriptions above). The type of the object can be specified with the type attribute, but defaults to Double.
The calculate tag can contain calcop and number tags, and the calcop tag can also contain these two tags to enable nested calculations.
Each calcop tag has three attributes: operator, map-name and field-name. Only the operator is required. The operator specifies the operation to perform on the given field and nested calcops and numbers. It must be one of the following: get | add | subtract | multiply | divide | negative.
Regardless of the operator the action is very similar. It translates to a formula like the following: (V1 [operator] V2 [operator] V3)
. In other words a final result is calculated by applying the operator to the values in the order they are specified. If a field-name (and optionally map-name) is specifies on the calcop tag that field will be used as the first value, otherwise the first nested calcop or number will be the first value.
The get operator is just an alias for add. It adds all of the values under it. Likewise the negative operator is almost an alias for subtract, with the exception that the first value is negated instead of left positive. For convenience the calculate tag itself acts like an add, in other words the calcops and numbers under it are all added together.
Attribute Name | Required? | Description |
---|---|---|
map-name | N | The 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-name | Y | The name (key) of the map field to use. |
type | N | The object type to put into this field. Can be: Double | Float | Long | Integer. The default is Double. |
Sub-Element Name | How Many | Description |
---|---|---|
calcop | 0 to many | This tag is used to apply an operator in the calculation. It can have calcop and number tags nested under it, making it also act like a parenthesis. It has three attributes: operator, map-name, and field-name. These are described below. |
number | 0 to many | This is used to put a numeric constant (a number) into the calculation. It has one attribute: value. This must be a properly formatted number or an error will result. |
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:
<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
<!DOCTYPE simple-methods PUBLIC "-//OFBiz//DTD Simple Methods//EN" "http://ofbiz.apache.org/dtds/simple-methods.dtd">
<simple-methods>
<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/>
<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="nowTimestamp"/>
<env-to-field env-name="nowTimestamp" field-name="lastModifiedDate" map-name="newEntity"/>
<env-to-field env-name="nowTimestamp" field-name="createdDate" map-name="newEntity"/>
<field-to-field field-name="userLoginId" map-name="userLogin" to-field-name="lastModifiedByUserLogin" to-map-name="newEntity"/>
<field-to-field field-name="userLoginId" map-name="userLogin" to-field-name="createdByUserLogin" to-map-name="newEntity"/>
<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>