ofbiz迷你语言

2024-03-11 21:08
文章标签 语言 迷你 ofbiz

本文主要是介绍ofbiz迷你语言,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 

simple-map-processor  simple-method XML files

simple-map-processor的两个主要功能:校验,转换

Simple Map Processors Example

<!DOCTYPE simple-map-processors PUBLIC "-//OFBiz//DTD Simple Methods//EN" "http://www.ofbiz.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>

simple-method 是可以被Control Servlet 或 a service 调用的Event的的简单实现

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

Sm 可以被作为static 方法调用(调用者可以是Control Servlet or a service),或者作为一个类调用(调用者可以是Control Servlet or a service),也可以通过一个Entity 的 controller 配置文件:

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

或一个 service 通过一个entry 在一个 services.xml 文件,像下面:

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

Mini-Language 可以调用 Simple Map Processors, Services and bsh scripts, 操作 entity 相关的操作, and 创建消息返回给调用者. Specific operations can be 附上 in if blocks to execute conditionally and values or fields can be copied around in the maps, lists and method environment.

有许多标签可以得到或者设置属性 到/从一个 request 或者 session object 当被作为一个事件调用 或者设置属性作为返回结果当作为一个服务的时候。如果你包含一个env-to-request 操作,它将仅仅被作为一个enent的时候才会被调用 。一个a env-to-result 操作见仅仅被作为一个service时才可以调用。 Everything else is the same when called as an event or a service which makes it easy to write 灵活的逻辑that can be mounted/applied in various ways.

下面是simple-method标签的完整的属性表:

 

AttributeName

Reqd?

DefaultValue

Description

method-name

Y

N/A

A 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-description

Y

N/A

A short description of the method for certain system error messages.

login-required

N

"true"

Is a logged in user (UserLogin object, or login.username and login.password Strings) required to run this method? "true" or "false".

use-transaction

N

"true"

Create a transaction if none exists for this thread? "true" or "false".

default-error-code

N

"error"

The default error return code.

default-success-code

N

"success"

The default success return code.

parameter-map-name

N

"parameters"

As event: copy of request parameters
As service: incoming context

event-request-object-name

N

"request"

(as event only)

event-response-code-name

N

"_response_code_"

(as event only)

event-error-message-name

N

"_error_message_"

(as event only)

event-event-message-name

N

"_event_message_"

(as event only)

service-response-message-name

N

"responseMessage"

(as service only)

service-error-message-name

N

"errorMessage"

(as service only)

service-error-message-list-name

N

"errorMessageList"

(as service only)

service-success-message-name

N

"successMessage"

(as service only)

service-success-message-list-name

N

"successMessageList"

(as service only)

delegator-name

N

"delegator"

A GenericDelegator object to use in the method

security-name

N

"security"

A Security object to use in the method

dispatcher-name

N

"dispatcher"

A LocalDispatcher object to use in the method


访问特殊 Contex的语法

访问Map成员,属性field-name="product.productName" 将引用product Map的productName成员,另一种写法是map-name="product" field-name="productName" ,下面的写法更加自由:name="products.widget.productName",这句将访问products (Map类型)的widget成员(也是一个Map类型)的productName成员

访问List 成员,例子:field-name="products[0].productName"将访问products(List类型)的第一个元素的productName属性。为了更有用,,你可以从环境中得到一个List的索引,如:field-name="products[${currentIndex}].productName",甚至一个Map的引用:field-name="products[${currentIndex}].${currentMember}"

Call Operations

call-map-processor

call-map-processor 标签调用一个简单的map processor 从一个存在的map 或创建一个新的map 或者添加到已经存在的map中去,如果这个名字的out-map 已经存在的话。 Resulting messages 被加入一个命名的 list, 如果这个名字的list不存在的话,一个新的List就会被创建. 记住,同一个context中所有的map和list必须有唯一的名字

 

AttributeName

Required?

Description

xml-resource

N

The full path and filename on the classpath of the XML file which contains an external map processor to execute. This is only required if an external map processor is desired.

processor-name

N

The name of the external map processor to execute in the specified xml-resource. This is only required if an external map processor is desired.

in-map-name

Y

The name of a map in the method environment to use as the input map.

out-map-name

Y

The name of a map in the method environment to use as the output map. Will be created if it does not exist already. If already exists will be added to in place.

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 it does not exist. Defaults to "error_list".

Sub-ElementName

HowMany

Description

simple-map-processor

0 or 1

Uses the same definition as the simple-map-processor in the context of a simple-map-processors XML file. Allows for an inlined simple-map-processor.

call-service

这个标签通过服务引擎调用一个服务,如果特殊的error code被返回,那么事件会被丢弃,当前线程中的事务会被回滚。否则,就继续处理下去

result-to-request 和 result-to-session elements will be 忽略当调用一个service context的时候

 

AttributeName

Required?

Description

service-name

Y

 

in-map-name

Y

 

include-user-login

N

Defaults to "true".

error-code

N

Defaults to "error".

success-code

N

Defaults to "success".

Sub-ElementName

HowMany

Description

error-prefix

0 or 1

 

error-suffix

0 or 1

 

success-prefix

0 or 1

 

success-suffix

0 or 1

 

message-prefix

0 or 1

 

message-suffix

0 or 1

 

default-message

0 or 1

 

results-to-map

0 to many

 

result-to-field

0 to many

 

result-to-request

0 to many

 

result-to-session

0 to many

 

result-to-result

0 to many

 

call-service-asynch

返回结果会被忽略,因此没有返回消息会被使用,但会有系统错误,如:数据库错误

 

AttributeName

Required?

Description

service-name

Y

 

in-map-name

Y

 

include-user-login

N

Defaults to "true".

call-bsh

bsh的context 是当前simple-method 环境中的maps, lists 和特殊的objects whose names are defined in the simple-method attributes.

The current env 不能被修改, but if a Map 被返回 by the bsh block ,map 中的成员将被存入当前的 env.

Error messages go on the error list and are handled with the check-errors tag.

 

AttributeName

Required?

Description

resource

N

 

error-list-name

N

Defaults to "error_list".

call-simple-method

call-simple-method 标签调用另一个simple-method 在同一个 context中, 包括所有的environment fields, either the event or service objects that the calling simple-method was called with.

 

AttributeName

Required?

Description

xml-resource

N

The 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-name

Y

The 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

out-map 同上,simple-map-processor 标签可以放在 call-map-processor 标签里面。

 

AttributeName

Required?

Description

xml-resource

N

The full path and filename on the classpath of the XML file which contains an external map processor to execute. This is only required if an external map processor is desired.

processor-name

N

The name of the external map processor to execute in the specified xml-resource. This is only required if an external map processor is desired.

in-map-name

Y

The name of a map in the method environment to use as the input map.

out-map-name

Y

The name of a map in the method environment to use as the output map. Will be created if it does not exist already. If already exists will be added to in place.

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 it does not exist. Defaults to "error_list".

Sub-ElementName

HowMany

Description

simple-map-processor

0 or 1

Uses the same definition as the simple-map-processor in the context of a simple-map-processors XML file. Allows for an inlined simple-map-processor.

call-object-method

Calls a method on an existing object that exists in a field in the environment or in a map in the environment.

The string and field sub-elements are passed to the method as arguments in the order they are specified. If the sub-elements do not match the method arguments an error will be returned.

The return value will be put in the named field if an value is returned and if a field and optionally a map name are specified.

 

AttributeName

Required?

Description

obj-field-name

Y

The name of the field the object is in that has the method to be called.

obj-map-name

N

The name of the map the field of the object is in that has the method to be called. If this is not specified the environment will be used to find the field in.

method-name

Y

The name of the method to call on the given object.

ret-field-name

N

The name of the field to put the result in. If not specified any return value will be ignored.

ret-map-name

N

The name of the map the field of the return value is in. If not specified but the field name is then the environment will be used to find the field in.

Sub-ElementName

HowMany

Description

string

0 to many

Used to specify an inline String argument to the method call.

field

0 to many

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

call-class-method

Calls a static method on a class.

The string and field sub-elements are passed to the method as arguments in the order they are specified. If the sub-elements do not match the method arguments an error will be returned.

The return value will be put in the named field if an value is returned and if a field and optionally a map name are specified.

 

AttributeName

Required?

Description

class-name

Y

The name of the class to call the static method on.

method-name

Y

The name of the static method to call on the given class.

ret-field-name

N

The name of the field to put the result in. If not specified any return value will be ignored.

ret-map-name

N

The name of the map the field of the return value is in. If not specified but the field name is then the environment will be used to find the field in.

Sub-ElementName

HowMany

Description

string

0 to many

Used to specify an inline String argument to the method call.

field

0 to many

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


call-simple-method

Method Environment Operations

map-to-map

field-to-field

The field-to-field tag copies a field from a map to a field in another map.

field-to-list

The field-to-list tag appends a field to the specified list.

env-to-field

The env-to-field tag copies a field from the method environment to a field in a map.

field-to-env

The field-to-env tag copies a field from a map to a field in the method environment.

string-to-field

The string-to-field tag puts the inlined string value in the specified field.

string-to-list

The string-to-list tag appends the inlined string value in the specified List.

to-string

The to-string tag converts the Object in the specified field to a String, putting the string in the same field.

clear-field

The clear-field tag clears/removes the specified field.

 

AttributeName

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.

iterate

The operations contained by the iterate tag will be executed for each of the entries in the list, and will make the current entry available in the method environment by the entry-name specified. This tag can contain any of the simple-method operations, including the conditional/if operations.

first-from-list

The first-from-list tag will get the first entry from the given list and put it in the environment field with the given entry-name.

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

now-date-to-env

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

sequenced-id-to-env

The sequenced-id-to-env tag gets a sequenced ID from the Entity Engine (through the delegator) and puts it in the specified method environment field. The object will be a java.lang.Long, but can of course be converted to a String.

 

AttributeName

Required?

Description

sequence-name

Y

The name of the sequence to pass to the delegator. The same name must always be used for sequenced IDs that will be used for a certain entity field otherwise non-unique keys may result.

env-name

Y

The name of the method environment field the sequenced ID will be put in.

set-current-user-login

The set-current-user-login tag sets the UserLogin GenericValue object to be used for authentication for the rest of the method. This is mostly used for calling services, etc.

 

AttributeName

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.

find-by-and

The find-by-and tag uses the delegator to find entity values by anding the fields passed in the map. The resulting GenericValue objects will be placed in the method environment using the specified list-name.

filter-list-by-and

The filter-list-by-and tag filters the given list by the fields in the specified map.

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.

 

AttributeName

Required?

Description

value-name

Y

The name of the method environment field that contains the GenericValue object.

entity-name

Y

The name of the entity to construct an instance of.

map-name

N

The name of a map in the method environment that will be used for the entity fields.

clone-value

The clone-value tag make a copy of the value in the method environment field specified by value-name. The resulting GenericValue object will be placed in the method environment using the specified new-value-name.

 

AttributeName

Required?

Description

value-name

Y

The name of the method environment field that contains the GenericValue object.

new-value-name

Y

The name of the method environment field that will contain the new GenericValue object.

create-value

The create-value tag persists the specified GenericValue object by creating a new instance of the entity in the datasource. An error will result if an instance of the entity exists in the datasource with the same primary key.

 

AttributeName

Required?

Description

value-name

Y

The name of the method environment field that contains the GenericValue object.

store-value

The store-value tag persists the specified GenericValue object by updating the instance of the entity in the datasource. An error will result if an instance of the entity does not exist in the datasource with the same primary key.

 

AttributeName

Required?

Description

value-name

Y

The name of the method environment field that contains the GenericValue object.

remove-value

The remove-value tag removes the specified GenericValue object by removing the instance of the entity in the datasource. An error will result if an instance of the entity does not exist in the datasource with the same primary key.

 

AttributeName

Required?

Description

value-name

Y

The name of the method environment field that contains the GenericValue object.

remove-by-and

The remove-by-and tag uses the delegator to remove entity values from the datasource and is constrained by anding the fields passed in the map. Make sure the map contains something, or all values will be removed.

 

AttributeName

Required?

Description

entity-name

Y

The name of the entity to remove instances of.

map-name

Y

The name of a map in the method environment that will be used for the entity fields.

clear-cache-line

Uses the delegator to clear elements from the cache; intelligently looks at the map passed to see if it is a byPrimaryKey, and byAnd, or an all.

 

AttributeName

Required?

Description

entity-name

Y

The name of the entity to clear cache lines of.

map-name

Y

The name of a map in the method environment that will be used for the entity fields. If the fields in the map form the full primary key the entry will be removed from the byPrimaryKey cache. If the map exists but the fields do not include a full primary key the entry will be removed from the byAnd cache. If no map-name is specified the entry will be removed from the all cache.

clear-entity-caches

This is a very simple tag that should be used sparingly because of the performance impact. It clears all lines from all Entity Engine caches. It has no attributes or sub-elements.

set-pk-fields

Looks for each PK field in the named map and if it exists there it will copy it into the named value object.

 

AttributeName

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.

set-nonpk-fields

Looks for each non-PK field in the named map and if it exists there it will copy it into the named value object.

 

AttributeName

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

Simple Methods Example

<!DOCTYPE simple-methods PUBLIC "-//OFBiz//DTD Simple Methods//EN" "http://www.ofbiz.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>

这篇关于ofbiz迷你语言的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/799081

相关文章

科研绘图系列:R语言扩展物种堆积图(Extended Stacked Barplot)

介绍 R语言的扩展物种堆积图是一种数据可视化工具,它不仅展示了物种的堆积结果,还整合了不同样本分组之间的差异性分析结果。这种图形表示方法能够直观地比较不同物种在各个分组中的显著性差异,为研究者提供了一种有效的数据解读方式。 加载R包 knitr::opts_chunk$set(warning = F, message = F)library(tidyverse)library(phyl

透彻!驯服大型语言模型(LLMs)的五种方法,及具体方法选择思路

引言 随着时间的发展,大型语言模型不再停留在演示阶段而是逐步面向生产系统的应用,随着人们期望的不断增加,目标也发生了巨大的变化。在短短的几个月的时间里,人们对大模型的认识已经从对其zero-shot能力感到惊讶,转变为考虑改进模型质量、提高模型可用性。 「大语言模型(LLMs)其实就是利用高容量的模型架构(例如Transformer)对海量的、多种多样的数据分布进行建模得到,它包含了大量的先验

C语言 | Leetcode C语言题解之第393题UTF-8编码验证

题目: 题解: static const int MASK1 = 1 << 7;static const int MASK2 = (1 << 7) + (1 << 6);bool isValid(int num) {return (num & MASK2) == MASK1;}int getBytes(int num) {if ((num & MASK1) == 0) {return

MiniGPT-3D, 首个高效的3D点云大语言模型,仅需一张RTX3090显卡,训练一天时间,已开源

项目主页:https://tangyuan96.github.io/minigpt_3d_project_page/ 代码:https://github.com/TangYuan96/MiniGPT-3D 论文:https://arxiv.org/pdf/2405.01413 MiniGPT-3D在多个任务上取得了SoTA,被ACM MM2024接收,只拥有47.8M的可训练参数,在一张RTX

如何确定 Go 语言中 HTTP 连接池的最佳参数?

确定 Go 语言中 HTTP 连接池的最佳参数可以通过以下几种方式: 一、分析应用场景和需求 并发请求量: 确定应用程序在特定时间段内可能同时发起的 HTTP 请求数量。如果并发请求量很高,需要设置较大的连接池参数以满足需求。例如,对于一个高并发的 Web 服务,可能同时有数百个请求在处理,此时需要较大的连接池大小。可以通过压力测试工具模拟高并发场景,观察系统在不同并发请求下的性能表现,从而

C语言:柔性数组

数组定义 柔性数组 err int arr[0] = {0}; // ERROR 柔性数组 // 常见struct Test{int len;char arr[1024];} // 柔性数组struct Test{int len;char arr[0];}struct Test *t;t = malloc(sizeof(Test) + 11);strcpy(t->arr,

C语言指针入门 《C语言非常道》

C语言指针入门 《C语言非常道》 作为一个程序员,我接触 C 语言有十年了。有的朋友让我推荐 C 语言的参考书,我不敢乱推荐,尤其是国内作者写的书,往往七拼八凑,漏洞百出。 但是,李忠老师的《C语言非常道》值得一读。对了,李老师有个官网,网址是: 李忠老师官网 最棒的是,有配套的教学视频,可以试看。 试看点这里 接下来言归正传,讲解指针。以下内容很多都参考了李忠老师的《C语言非

C 语言基础之数组

文章目录 什么是数组数组变量的声明多维数组 什么是数组 数组,顾名思义,就是一组数。 假如班上有 30 个同学,让你编程统计每个人的分数,求最高分、最低分、平均分等。如果不知道数组,你只能这样写代码: int ZhangSan_score = 95;int LiSi_score = 90;......int LiuDong_score = 100;int Zhou

C 语言的基本数据类型

C 语言的基本数据类型 注:本文面向 C 语言初学者,如果你是熟手,那就不用看了。 有人问我,char、short、int、long、float、double 等这些关键字到底是什么意思,如果说他们是数据类型的话,那么为啥有这么多数据类型呢? 如果写了一句: int a; 那么执行的时候在内存中会有什么变化呢? 橡皮泥大家都玩过吧,一般你买橡皮泥的时候,店家会赠送一些模板。 上

linux中使用rust语言在不同进程之间通信

第一种:使用mmap映射相同文件 fn main() {let pid = std::process::id();println!(