Apache OFBiz 学习笔记 之 服务引擎 二
<entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/>
<entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel_olap.xml"/>
<entity-resource type="group" reader-name="main" loader="main" location="entitydef/entitygroup_olap.xml"/>
<entity-resource type="data" reader-name="seed" loader="main" location="data/CommonSecurityData.xml"/>
<entity-resource type="data" reader-name="seed" loader="main" location="data/CommonSystemPropertyData.xml"/>
<entity-resource type="data" reader-name="seed" loader="main" location="data/CommonTypeData.xml"/>
<entity-resource type="data" reader-name="seed" loader="main" location="data/CountryCodeData.xml"/>
<entity-resource type="data" reader-name="seed" loader="main" location="data/CurrencyData.xml"/>
服务参数
<attribute name="partyId" type="String" mode="IN" optional="true"/>
<attribute name="noteId" type="String" mode="OUT"/>
<attribute name="nodeId" type="String" mode="INOUT"/>
name
|
type
|
mode
|
optional
|
说明
|
responseMessage
|
String
|
OUT
|
true
|
返回信息(success/error/fail)
|
errorMessage
|
String
|
OUT
|
true
|
错误信息
|
errorMessageList
|
java.util.List
|
OUT
|
true
|
错误信息列表
|
successMessage
|
String
|
OUT
|
true
|
成功信息
|
successMessageList
|
java.util.List
|
OUT
|
true
|
成功信息列表
|
userLogin | org.ofbiz.entity.GenericValue | INOUT | true | 登陆用户对象,用于权限验证 |
locale | java.util.Locale | INOUT | true | 国际化本地对象 |
<attribute name="partyId" type="String" mode="IN" optional="true"/>
<attribute name="partyId" type="String" mode="IN" optional="false"/>
<!-- mass order changes -->
<service name="massOrderChangeInterface" engine="interface" location="" invoke="">
<description>Interface for Mass Order Change Services</description>
<attribute name="orderIdList" type="List" mode="IN" optional="false"/>
</service>
<service name="massPickOrders" engine="java" transaction-timeout="300"
location="org.ofbiz.order.order.OrderServices" invoke="massPickOrders" auth="true">
<implements service="massOrderChangeInterface"/>
</service>
<service name="massChangeOrderApproved" engine="java" transaction-timeout="300"
location="org.ofbiz.order.order.OrderServices" invoke="massChangeApproved" auth="true">
<implements service="massOrderChangeInterface"/>
</service>
<service name="massProcessOrders" engine="java" transaction-timeout="300"
location="org.ofbiz.order.order.OrderServices" invoke="massProcessOrders" auth="true">
<implements service="massOrderChangeInterface"/>
</service>
// make the list per facility
List<String> orderIds = UtilGenerics.checkList(context.get("orderIdList"));
<service name="massPrintOrders" engine="java" transaction-timeout="300"
location="org.ofbiz.order.order.OrderServices" invoke="massPrintOrders" auth="true">
<implements service="massOrderChangeInterface"/>
<attribute name="screenLocation" type="String" mode="IN" optional="false"/>
<attribute name="printerName" type="String" mode="IN" optional="true"/>
</service>
String screenLocation = (String) context.get("screenLocation");
String printerName = (String) context.get("printerName"); // make the list per facility
List<String> orderIds = UtilGenerics.checkList(context.get("orderIdList"));
<service name="getPerson" engine="java"
location="org.ofbiz.party.party.PartyServices" invoke="getPerson">
<description>Gets a person entity from the cache/database</description>
<attribute name="partyId" type="String" mode="IN"/>
<attribute name="lookupPerson" type="org.ofbiz.entity.GenericValue" mode="OUT"/>
</service>
public static Map<String, Object> findOrders(DispatchContext dctx, Map<String, ? extends Object> context) {
Security security = dctx.getSecurity();
// check security flag for purchase orders
boolean canViewPo = security.hasEntityPermission("ORDERMGR", "_PURCHASE_VIEW", userLogin);
if (!canViewPo) {
conditions.add(EntityCondition.makeCondition("orderTypeId", EntityOperator.NOT_EQUAL, "PURCHASE_ORDER"));
}
}
<!-- Party Relationship services -->
<service name="createPartyRelationship" default-entity-name="PartyRelationship" engine="simple"
location="component://party/script/org/ofbiz/party/party/PartyServices.xml" invoke="createPartyRelationship" auth="true">
<description>
Create a Relationship between two Parties;
if partyIdFrom is not specified the partyId of the current userLogin will be used;
if roleTypeIds are not specified they will default to "_NA_".
If a partyIdFrom is passed in, it will be used if the userLogin has PARTYMGR_REL_CREATE permission.
</description>
<permission-service service-name="partyRelationshipPermissionCheck" main-action="CREATE"/>
<auto-attributes include="pk" mode="IN" optional="true"/>
<auto-attributes include="nonpk" mode="IN" optional="true"/>
<override name="partyIdTo" optional="false"/>
</service>
<!-- PartyRelationship services -->
<simple-method method-name="createPartyRelationship" short-description="createPartyRelationship">
<if-empty field="parameters.roleTypeIdFrom"><set field="parameters.roleTypeIdFrom" value="_NA_"/></if-empty>
<if-empty field="parameters.roleTypeIdTo"><set field="parameters.roleTypeIdTo" value="_NA_"/></if-empty>
<if-empty field="parameters.partyIdFrom"><set field="parameters.partyIdFrom" from-field="userLogin.partyId"/></if-empty> <if-empty field="parameters.fromDate"><now-timestamp field="parameters.fromDate"/></if-empty> <!-- check if not already exist -->
<entity-and entity-name="PartyRelationship" list="partyRels" filter-by-date="true">
<field-map field-name="partyIdFrom" from-field="parameters.partyIdFrom"/>
<field-map field-name="roleTypeIdFrom" from-field="parameters.roleTypeIdFrom"/>
<field-map field-name="partyIdTo" from-field="parameters.partyIdTo"/>
<field-map field-name="roleTypeIdTo" from-field="parameters.roleTypeIdTo"/>
</entity-and> <if-empty field="partyRels">
<make-value value-field="newEntity" entity-name="PartyRelationship"/>
<set-pk-fields map="parameters" value-field="newEntity"/>
<set-nonpk-fields map="parameters" value-field="newEntity"/>
<create-value value-field="newEntity"/>
</if-empty>
</simple-method>
<!-- Example & Related Services -->
<service name="createExample" default-entity-name="Example" engine="entity-auto" invoke="create" auth="true">
<description>Create a Example</description>
<permission-service service-name="exampleGenericPermission" main-action="CREATE"/>
<auto-attributes include="pk" mode="OUT" optional="false"/>
<auto-attributes include="nonpk" mode="IN" optional="true"/>
<override name="exampleTypeId" optional="false"/>
<override name="statusId" optional="false"/>
<override name="exampleName" optional="false"/>
</service>
<!-- RiTA (Remote) Implementations -->
<service name="ritaCCAuthRemote" engine="rmi"
location="rita-rmi" invoke="ritaCCAuth">
<description>RiTA Credit Card Pre-Authorization/Sale</description>
<implements service="ccAuthInterface"/>
</service>
<service-location name="rita-rmi" location="rmi://localhost:1099/RMIDispatcher"/>
<!-- RiTA (Local) Implementations -->
<service name="ritaCCAuth" engine="java" export="true"
location="org.ofbiz.accounting.thirdparty.gosoftware.RitaServices" invoke="ccAuth">
<description>RiTA Credit Card Pre-Authorization/Sale</description>
<implements service="ccAuthInterface"/>
</service>
<service-group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/service-group.xsd"> <group name="updateWorkEffortAndAssoc" send-mode="all" >
<invoke name="updateWorkEffort" mode="sync"/>
<invoke name="updateWorkEffortAssoc" mode="sync"/>
</group>
<group name="createWorkEffortRequestItemAndRequestItem" send-mode="all" >
<invoke name="checkCustRequestItemExists" mode="sync" result-to-context="true"/>
<invoke name="createWorkEffortRequestItem" mode="sync"/>
</group>
</service-group>
public static String indexTree(HttpServletRequest request, HttpServletResponse response) { Map<String, Object> result;
Map<String, Object> serviceInMap = FastMap.newInstance();
HttpSession session = request.getSession();
GenericValue userLogin = (GenericValue)session.getAttribute("userLogin");
serviceInMap.put("userLogin", userLogin);
LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
Map<String, Object> paramMap = UtilHttp.getParameterMap(request);
String siteId = (String)paramMap.get("contentId");
serviceInMap.put("contentId", siteId);
try {
result = dispatcher.runSync("indexTree", serviceInMap);
} catch (GenericServiceException e) {
String errorMsg = "Error calling the indexTree service." + e.toString();
Debug.logError(e, errorMsg, module);
request.setAttribute("_ERROR_MESSAGE_", errorMsg + e.toString());
return "error";
}
String errMsg = ServiceUtil.getErrorMessage(result);
if (Debug.infoOn()) Debug.logInfo("errMsg:" + errMsg, module);
if (Debug.infoOn()) Debug.logInfo("result:" + result, module);
if (UtilValidate.isEmpty(errMsg)) {
List<String> badIndexList = UtilGenerics.checkList(result.get("badIndexList"));
if (Debug.infoOn()) Debug.logInfo("badIndexList:" + badIndexList, module);
String badIndexMsg = StringUtil.join(badIndexList, "\n") + badIndexList.size() + " entities not indexed";
Integer goodIndexCount = (Integer)result.get("goodIndexCount");
String goodIndexMsg = goodIndexCount + " entities indexed.";
if (Debug.infoOn()) Debug.logInfo("goodIndexCount:" + goodIndexCount, module);
ServiceUtil.setMessages(request, badIndexMsg, goodIndexMsg, null);
return "success";
} else {
ServiceUtil.setMessages(request, errMsg, null, null);
return "error";
}
}
调用服务
try {
result = dispatcher.runSync("indexTree", serviceInMap);
} catch (GenericServiceException e) {
String errorMsg = "Error calling the indexTree service." + e.toString();
Debug.logError(e, errorMsg, module);
request.setAttribute("_ERROR_MESSAGE_", errorMsg + e.toString());
return "error";
}
<service name="indexTree" auth="true" engine="java" validate="true" transaction-timeout="7200"
location="org.ofbiz.content.search.SearchServices" invoke="indexTree">
<description>Index content under publish point</description>
<attribute mode="IN" name="contentId" optional="false" type="String"/>
<attribute mode="OUT" name="badIndexList" optional="true" type="List"/>
<attribute mode="OUT" name="goodIndexCount" optional="true" type="Integer"/>
</service>
<simple-method method-name="createPaymentAndApplication" short-description="Create a payment and a payment application for the full amount">
<set-service-fields service-name="createPayment" map="parameters" to-map="createPaymentInMap"/>
<call-service service-name="createPayment" in-map-name="createPaymentInMap">
<result-to-field field="paymentId" result-name="paymentId"/>
</call-service>
<check-errors/>
<set-service-fields service-name="createPaymentApplication" map="parameters" to-map="createPaymentAppInMap"/>
<set field="createPaymentAppInMap.paymentId" from-field="paymentId"/>
<set field="createPaymentAppInMap.amountApplied" from-field="parameters.amount"/>
<call-service service-name="createPaymentApplication" in-map-name="createPaymentAppInMap">
<result-to-field field="paymentApplicationId" result-name="paymentApplicationId"/>
</call-service>
<check-errors/>
<field-to-result field="paymentId" result-name="paymentId"/>
<field-to-result field="paymentApplicationId" result-name="paymentApplicationId"/>
</simple-method>
<call-service service-name="createPayment" in-map-name="createPaymentInMap">
<result-to-field field="paymentId" result-name="paymentId"/>
</call-service>
<simple-method method-name="createPayment" short-description="Create a Payment">
<if>
<condition>
<and>
<not><if-has-permission permission="PAY_INFO" action="_CREATE"/></not>
<not><if-compare-field field="userLogin.partyId" to-field="parameters.partyIdFrom" operator="equals"/></not>
<not><if-compare-field field="userLogin.partyId" to-field="parameters.partyIdTo" operator="equals"/></not>
</and>
</condition>
<then>
<add-error>
<fail-property resource="AccountingUiLabels" property="AccountingCreatePaymentPermissionError"/>
</add-error>
</then>
</if>
<check-errors/> <make-value entity-name="Payment" value-field="payment"/>
<if-empty field="parameters.paymentId">
<sequenced-id sequence-name="Payment" field="payment.paymentId"/>
<else>
<set field="payment.paymentId" from-field="parameters.paymentId"/>
</else>
</if-empty>
<field-to-result field="payment.paymentId" result-name="paymentId"/> <if-not-empty field="parameters.paymentMethodId">
<entity-one entity-name="PaymentMethod" value-field="paymentMethod">
<field-map field-name="paymentMethodId" from-field="parameters.paymentMethodId"/>
</entity-one>
<if-compare-field field="parameters.paymentMethodTypeId" operator="not-equals" to-field="paymentMethod.paymentMethodTypeId">
<log level="info" message="Replacing passed payment method type [${parameters.paymentMethodTypeId}] with payment method type [${paymentMethod.paymentMethodTypeId}] for payment method [${parameters.paymentMethodId}]"/>
<set field="parameters.paymentMethodTypeId" from-field="paymentMethod.paymentMethodTypeId"/>
</if-compare-field>
</if-not-empty>
<if-not-empty field="parameters.paymentPreferenceId">
<entity-one value-field="orderPaymentPreference" entity-name="OrderPaymentPreference">
<field-map field-name="orderPaymentPreferenceId" from-field="parameters.paymentPreferenceId"/>
</entity-one>
<if-empty field="parameters.paymentMethodId">
<set field="parameters.paymentMethodId" from-field="orderPaymentPreference.paymentMethodId"/>
</if-empty>
<if-empty field="parameters.paymentMethodTypeId">
<set field="parameters.paymentMethodTypeId" from-field="orderPaymentPreference.paymentMethodTypeId"/>
</if-empty>
</if-not-empty>
<if-empty field="parameters.paymentMethodTypeId">
<add-error>
<fail-property resource="AccountingUiLabels" property="AccountingPaymentMethodIdPaymentMethodTypeIdNullError"/>
</add-error>
</if-empty> <set-nonpk-fields map="parameters" value-field="payment"/>
<if-empty field="payment.effectiveDate">
<now-timestamp field="payment.effectiveDate"/>
</if-empty>
<create-value value-field="payment"/>
</simple-method>
异步方式调用
<simple-method method-name="sendInvoicePerEmail" short-description="Send an invoice per Email">
<set-service-fields service-name="sendMailFromScreen" map="parameters" to-map="emailParams"/>
<set field="emailParams.xslfoAttachScreenLocation" value="component://accounting/widget/AccountingPrintScreens.xml#InvoicePDF"/>
<set field="emailParams.bodyParameters.invoiceId" from-field="parameters.invoiceId"/>
<set field="emailParams.bodyParameters.userLogin" from-field="parameters.userLogin"/>
<set field="emailParams.bodyParameters.other" from-field="parameters.other"/><!-- to to print in 'other currency' -->
<call-service-asynch service-name="sendMailFromScreen" in-map-name="emailParams"/>
<property-to-field resource="AccountingUiLabels" property="AccountingEmailScheduledToSend" field="successMessage"/>
</simple-method>
异步调用代码
<call-service-asynch service-name="sendMailFromScreen" in-map-name="emailParams"/>
<service name="sendOrderConfirmation" engine="java" require-new-transaction="true" max-retry="3"
location="org.ofbiz.order.order.OrderServices" invoke="sendOrderConfirmNotification">
<description>Send a order confirmation</description>
<implements service="orderNotificationInterface"/>
</service>
dispatcher.runSync(servicename, context,transactionTimeOut,requireNewTransaction);
dispatcher.runAsync(servicename, context,requester,persist,transactionTimeOut,requireNewTransaction);
Apache OFBiz 学习笔记 之 服务引擎 二的更多相关文章
- Apache OFBiz 学习笔记 之 服务引擎 一
概述 服务定义为一段独立的逻辑顺序,当多个服务组合一起时可完成不同类型的业务需求 服务有很多类型,WorkFlow.Rules.Java.SOAP.BeanShell等.java类型的 ...
- Apache OFBiz 学习笔记 之 实体引擎
1.概述 entity engine和常见的ORM有一点很大的不同,他的mapping object只有一个 GenericEntity,称它的entity engine 为adaptive ...
- Apache Flink学习笔记
Apache Flink学习笔记 简介 大数据的计算引擎分为4代 第一代:Hadoop承载的MapReduce.它将计算分为两个阶段,分别为Map和Reduce.对于上层应用来说,就要想办法去拆分算法 ...
- Java菜鸟学习笔记--数组篇(三):二维数组
定义 //1.二维数组的定义 //2.二维数组的内存空间 //3.不规则数组 package me.array; public class Array2Demo{ public static void ...
- JavaScript学习笔记之数组(二)
JavaScript学习笔记之数组(二) 1.['1','2','3'].map(parseInt) 输出什么,为什么? ['1','2','3'].map(parseInt)//[1,NaN,NaN ...
- vue2.0学习笔记之路由(二)路由嵌套+动画
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vue2.0学习笔记之路由(二)路由嵌套
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 基于jersey和Apache Tomcat构建Restful Web服务(二)
基于jersey和Apache Tomcat构建Restful Web服务(二) 上篇博客介绍了REST以及Jersey并使用其搭建了一个简单的“Hello World”,那么本次呢,再来点有趣的东西 ...
- SpringCloud学习笔记:服务支撑组件
SpringCloud学习笔记:服务支撑组件 服务支撑组件 在微服务的演进过程中,为了最大化利用微服务的优势,保障系统的高可用性,需要通过一些服务支撑组件来协助服务间有效的协作.各个服务支撑组件的原理 ...
随机推荐
- hdu 1133 Buy the Ticket
首先,记50的为0,100的为1. 当m=4,n=3时,其中的非法序列有0110010; 从不合法的1后面开始,0->1,1->0,得到序列式0111101 也就是说,非法序列变为了n-1 ...
- SQO2008配置管理工具服务显示远程过程调用失败
前两天,装了VS2012后,打开SQL2008配置管理工具,发现SQL服务名称里什么也没有,只有一个提示:(如图) 卸载了一个叫"Microsoft SQL Server 2012Local ...
- hdu1875
http://acm.hdu.edu.cn/showproblem.php?pid=1875 2 2 10 10 20 20 3 1 1 2 2 1000 1000 给定坐标 //最小生成树 #inc ...
- 读书笔记:7个示例科普CPU Cache
本文转自陈皓老师的个人博客酷壳:http://coolshell.cn/articles/10249.html 7个示例科普CPU Cache (感谢网友 @我的上铺叫路遥 翻译投稿) CPU cac ...
- java使用Apache POI操作excel文件
官方介绍 HSSF is the POI Project's pure Java implementation of the Excel '97(-2007) file format. XSSF is ...
- linux下用非root用户重启导致ssh无法连接的问题
问题描述 安装好了centOS服务器,一直用Secure CRT工具通过ssh服务来远程连接linux,很方便的进行各种操作.今天偶然尝试了一下在非root的一般用户下执行重启服务器的命令,发现一般用 ...
- Android TextView多行文本滚动实现
Android中我们为了实现文本的滚动可以在ScrollView中嵌入一个TextView,其实TextView自己也可以实现多行滚动的,毕竟ScrollView必须只能有一个直接的子类布局.只要在l ...
- 纯后台生成highcharts图片有哪些方法?
比如说,领导抛给你一个需求,把一些数据做成图表,每天通过邮件发送,让领导能在邮件中就看到图片,你会有什么思路呢?本人使用的是phantomjs这个神器,它的内核是WebKit引擎,不提供图形界面,只能 ...
- Android 自定义控件-TextView
很多时候系统自带的View满足不了设计的要求,就需要自定义View控件.自定义View首先要实现一个继承自View的类.添加类的构造方法,override父类的方法,如onDraw,(onMeasur ...
- POJ 2409 Let it Bead(polay计数)
题目链接:http://poj.org/problem?id=2409 题意:给出一个长度为m的项链,每个珠子可以用n种颜色涂色.翻转和旋转后相同的算作一种.有多少种不同的项链? 思路: (1) 对于 ...