转 ofbiz各配置文件作用以及工作流程

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了转 ofbiz各配置文件作用以及工作流程相关的知识,希望对你有一定的参考价值。

1.当客户端发出请求时,调用第一个配置文件WEB-INF/controller.xml,根据请求的地址
处理方法1:直接调用java类的方法
<request-map uri="login">
 

       <security https="true" auth="false"/>
        <event type="java" path="org.ofbiz.webapp.control.LoginWorker" invoke="login"/>
        <response name="success" type="view" value="main"/>
        <response name="error" type="view" value="login"/>
</request-map>
如果为login,会查找path="org.ofbiz.webapp.control.LoginWorker"这个类的invoke="login"
这个方法进行处理
处理方式2:通过service配置文件取查找对应的service(常用)
    <request-map uri="createForum">
        <security https="true" auth="true"/>
        <event type="service" path="" invoke="createForum"/>
        <response name="success" type="view" value="FindForum"/>
        <response name="error" type="view" value="FindForum"/>
    </request-map>
表示调用的类型为type="service"调用的方法为invoke="createForum"
2.进入servicedef/services.xml,这是service的配置文件
  
从里面找到上面对应的配置信息
<service name="createForum" default-entity-name="GroupForum" engine="simple"
            location="org/ofbiz/group/GroupServices.xml" invoke="createForum" auth="true">
        <description>Create a GroupForum</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="forumName" optional="false"/>
</service>
文件配置的createForum这个文件实现的相关信息location="org/ofbiz/group/GroupServices.xml"表示实现
是通过minilanguage配置文件
3.进入script下面的org/ofbiz/group/GroupServices.xml文件
通过minilanguage配置文件
    <simple-method method-name="createForum" short-description="create a GroupForum">
        <make-value entity-name="GroupForum" value-name="newEntity"/>
        <sequenced-id-to-env sequence-name="GroupForum" env-name="newEntity.forumId"/> <!-- get the next sequenced ID -->
        <field-to-result field-name="newEntity.forumId" result-name="forumId"/>
        <set-nonpk-fields map-name="parameters" value-name="newEntity"/>
        <create-value value-name="newEntity"/>

    </simple-method>
配置了对entity-name="GroupForum"实体的创建的相关信息和操作,该步骤可以用java代码实现.
4.进入实体配置文件部分
entitymodel.xml
<entity entity-name="GroupForum" package-name="org.ofbiz.group" title="GroupForum Entity">
        <field name="forumId" type="id-ne"><!-- primary sequenced ID --></field>
        <field name="forumName" type="name"></field>
        <field name="description" type="description"></field>
        <field name="authorID" type="id"></field>
        <field name="created" type="date-time"></field>     
        <prim-key field="forumId"/>
    </entity>
配置了entity-name="GroupForum" 的实体与数据库映射文件

entitygroup.xml
<entitygroup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/entitygroup.xsd">       
    <entity-group group="org.ofbiz" entity="GroupForum"/>
    <entity-group group="org.ofbiz" entity="GroupCategory"/>
    <entity-group group="org.ofbiz" entity="GroupThread"/>
    <entity-group group="org.ofbiz" entity="GroupPost"/>
</entitygroup>
配置了实体名称的组

5.service执行成功后会返回到展现逻辑配置部分,也就是WEB-INF/controller.xml中
<request-map uri="login">
        <security https="true" auth="false"/>
        <event type="java" path="org.ofbiz.webapp.control.LoginWorker" invoke="login"/>
        <response name="success" type="view" value="main"/>
        <response name="error" type="view" value="login"/>
</request-map>
现在会请求到main中,
<view-map name="main" type="screen" page="component://group/widget/group/CommonScreens.xml#main"/>
在WEB-INF/controller.xml中找到main的配置信息
该显示用screen配置显示component://group/widget/group/CommonScreens.xml#main

6.现在根据地址找到配置文件component://group/widget/group/CommonScreens.xml
#main表示该文件中name为main的screen
<screen name="main">
        <section>
    <actions>
                <set field="titleProperty" value="OrderOrderTaskList"/>
                <set field="headerItem" value="tasklist"/>
                <script location="component://order/webapp/ordermgr/WEB-INF/actions/task/ordertasklist.bsh"/>
            </actions>
            <widgets>
                <decorator-screen name="main-decorator">
                    <decorator-section name="body">
                        <container style="screenlet">
                            <container style="screenlet-header">
                                <label style="boxhead" text="Main Page"/>
                            </container>
                            <container style="screenlet-body">
                                <section>
                                    <condition><if-empty field-name="userLogin"/></condition>
                                    <widgets>
                                        <container><label text="${uiLabelMap.ExampleMessage}"/></container>
                                    </widgets>
                                </section>
                                <container><label text="${uiLabelMap.Welcome}"/></container>
                            </container>
                        </container>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
<screen name="login">
        <section>
            <widgets>
                <decorator-screen name="main-decorator">
                    <decorator-section name="body">
                        <platform-specific>
                            <html><html-template location="component://common/webcommon/login.ftl"/></html>
                        </platform-specific>
                    </decorator-section>
                </decorator-screen>
            </widgets>
        </section>
    </screen>
</screens>
该配置文件配置了显示的数据以及显示的格式
其中数据是通过.bsh文件和service提供的,而显示的格式为ftl文件提供的

7.进入group\webapp\group\WEB-INF\actions\forum在
bsh为beansheel配置文件,语法与java类似,在这儿是为了提供显示数据

import java.util.*;
import java.io.*;
import org.ofbiz.entity.*;
import org.ofbiz.base.util.*;

security = request.getAttribute("security");
delegator = request.getAttribute("delegator");
userLogin = session.getAttribute("userLogin");
person = null;
if (userLogin != null ) {
    person = userLogin.getRelatedOne("Person");
}
forumId = request.getParameter("forumId");
categoryId = request.getParameter("categoryId");
if ( categroyId == null ||UtilValidate.isEmpty(categoryId) ){
categoryId = delegator.getNextSeqId("GroupCategory");
}

groupCategory = delegator.findByPrimaryKey("GroupCategory", UtilMisc.toMap("categoryId", categoryId));
context.put("forumId", forumId);
context.put("categoryId", categoryId);
context.put("groupCategory", groupCategory);
context.put("person", person);
该文件把需要的数据放到返回的上下文中

8.进入到group\webapp\group\forum\listForum.ftl
该文件为Freemarker的文件,作用是代替jsp作显示层
<#if forums?has_content>
Some of the famous celebrities who have visited our site:


<table>
<ul>
    <#list forums as forum>
<tr>
       <li><td><a href ="EditForum?forumId=${forum.forumId?if_exists}">${forum.forumId?if_exists}</a></td>
           <td>12 ${forum.forumName?if_exists}</td>
           <td> ${forum.description?if_exists}</td>
          
       <li><td><a href ="deleteForum?forumId=${forum.forumId?if_exists}">${forum.forumId?if_exists}</a></td>
</tr>

<tr>
       <li><td><a href ="FindCategory?forumId=${forum.forumId?if_exists}">${forum.forumId?if_exists}</a></td>
           <td><a href ="EditCategory?forumId=${forum.forumId?if_exists}">${forum.forumId?if_exists}</a></td>
           <td> </td>
          
       <li><td></td>
</tr>


    </#list>
</ul>
</table>
</#if>

通过一些表达式和判断把数据显示出来,这样整个请求完毕




其他配置文件的作用:
data目录下的配置文件:
<entity-engine-xml>
    <UserLogin userLoginId="DemoBuyer" currentPassword="47ca69ebb4bdc9ae0adec130880165d2cc05db1a" passwordHint=""/>
    <UserLogin userLoginId="DemoRepAll" currentPassword="47ca69ebb4bdc9ae0adec130880165d2cc05db1a" passwordHint=""/>
    <UserLogin userLoginId="DemoRepStore" currentPassword="47ca69ebb4bdc9ae0adec130880165d2cc05db1a" passwordHint=""/>
    <UserLogin userLoginId="DemoCustCompany" currentPassword="47ca69ebb4bdc9ae0adec130880165d2cc05db1a" passwordHint=""/>
    <UserLogin userLoginId="DemoCustAgent" currentPassword="47ca69ebb4bdc9ae0adec130880165d2cc05db1a" passwordHint=""/>
    <UserLogin userLoginId="DemoCustomer" currentPassword="47ca69ebb4bdc9ae0adec130880165d2cc05db1a" passwordHint=""/>
    <UserLogin userLoginId="supplier" partyId="externaluser" currentPassword="47ca69ebb4bdc9ae0adec130880165d2cc05db1a" passwordHint=""/>
    <UserLoginSecurityGroup groupId="ORDERSUPPLIER_LTD" userLoginId="supplier" fromDate="2001-01-01 12:00:00.0"/>
</entity-engine-xml>
配置了系统启动时后需要添加的一些数据

config目录下的配置文件:为国际化配置信息
   <property key="OrderCaughtExceptionOnCartUpdate">
        <value xml:lang="en">Caught exception on cart update. </value>
        <value xml:lang="es">Excepción capturada en la actualización del carro.</value>
        <value xml:lang="fr">%Exception attrapée dans la mise à jour du chariot. %</value>
        <value xml:lang="it">Eccezione sull‘aggiornamento carrello. </value>
        <value xml:lang="ro">Exceptie la actualizarea cosului. </value>
        <value xml:lang="zh">更新购物车时发生意外情况 </value>
    </property>

widget里面的form配置文件:
    <form name="OrderPurchaseProductOptions" type="single" target="OrderPurchaseReportProduct.pdf" title="" extends="OrderPurchaseReportOptions">
        <field name="fromOrderDate" title="${uiLabelMap.OrderReportFromDate}"><date-time type="timestamp"/></field>
        <field name="thruOrderDate" title="${uiLabelMap.OrderReportThruDate}"><date-time type="timestamp"/></field>
        <field name="submitButton" title="${uiLabelMap.CommonRun}" widget-style="smallSubmit"><submit button-type="button"/></field>
    </form>
配置了一些表单信息,和screen一样,但是他可以直接显示数据不需要使用Freemaerker的文ftl文件作页面布局,根据配置信息可以直接生成

ofbiz-componet.xml文件配置了项目要加载的配置文件的信息,它可以告诉OFBIZ应用程序组件的相关信息:数据模型,商业逻辑,用户接口,种子数据,以及其他程序需要的资源。
   <ofbiz-component name="order"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-component.xsd">
    <resource-loader name="main" type="component"/>
    <classpath type="jar" location="build/lib/*"/>
    <classpath type="dir" location="config"/>
    <classpath type="dir" location="script"/>
    <classpath type="dir" location="email"/>
    <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_old.xml"/>
    <entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel_view.xml"/>
    <entity-resource type="group" reader-name="main" loader="main" location="entitydef/entitygroup.xml"/>
    <entity-resource type="eca" reader-name="main" loader="main" location="entitydef/eecas.xml"/>
    <entity-resource type="data" reader-name="seed" loader="main" location="data/OrderTypeData.xml"/>
    <entity-resource type="data" reader-name="seed-initial" loader="main" location="data/OrderScheduledServices.xml"/>
    <entity-resource type="data" reader-name="seed" loader="main" location="data/OrderSecurityData.xml"/>
    <entity-resource type="data" reader-name="demo" loader="main" location="data/OrderDemoUser.xml"/>
    <entity-resource type="data" reader-name="demo" loader="main" location="data/OrderProcessWorkflow.xml"/>
    <service-resource type="model" loader="main" location="servicedef/services.xml"/>
    <service-resource type="model" loader="main" location="servicedef/services_cart.xml"/>
    <service-resource type="model" loader="main" location="servicedef/services_shoppinglist.xml"/>
    <service-resource type="model" loader="main" location="servicedef/services_request.xml"/>
    <service-resource type="model" loader="main" location="servicedef/services_quote.xml"/>
    <service-resource type="model" loader="main" location="servicedef/services_requirement.xml"/>
    <service-resource type="model" loader="main" location="servicedef/services_return.xml"/>
    <service-resource type="model" loader="main" location="servicedef/services_opportunity.xml"/>
    <service-resource type="model" loader="main" location="servicedef/services_upgrade.xml"/>
    <service-resource type="eca" loader="main" location="servicedef/secas.xml"/>
   
    <test-suite loader="main" location="testdef/OrderTest.xml"/>
   
    <webapp name="order"
        title="Order"
        server="default-server"
        location="webapp/ordermgr"
        base-permission="OFBTOOLS,ORDERMGR"
        mount-point="/ordermgr"/>
</ofbiz-component>


eca.xml配置了调用指定的entity或者service触发的对应事件
entity:
    <eca entity="OrderHeader" operation="create-store" event="return">
        <condition field-name="statusId" operator="equals" value="ORDER_COMPLETED"/>
        <condition field-name="needsInventoryIssuance" operator="equals" value="Y"/>
        <action service="issueImmediatelyFulfilledOrder" mode="sync"/>
    </eca>
service:
    <eca service="changeOrderItemStatus" event="commit">
        <condition field-name="statusId" operator="equals" value="ITEM_CANCELLED"/>
        <action service="cancelOrderInventoryReservation" mode="sync"/>
        <action service="recalcShippingTotal" mode="sync"/>
        <action service="recalcTaxTotal" mode="sync"/>
        <action service="resetGrandTotal" mode="sync"/>
        <action service="checkOrderItemStatus" mode="sync"/>
    </eca>

entityengine.xml配置了数据库连接的相关信息
    <datasource name="localmssql"
            helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"
            schema-name="dbo"
            field-type-name="mssql"
            check-on-start="true"//启用的数据库连接
            add-missing-on-start="true"
            join-style="ansi"
            alias-view-columns="false"
            use-fk-initially-deferred="false">
        <read-data reader-name="seed"/>
        <read-data reader-name="seed-initial"/>
        <read-data reader-name="demo"/>
        <read-data reader-name="ext"/>
        <inline-jdbc
                jdbc-driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"
                jdbc-uri="jdbc:sqlserver://10.0.70.15:1433;databaseName=ofbiz;SelectMethod=cursor;"
                jdbc-username="ofbiz"
                jdbc-password="ofbiz"
                isolation-level="ReadCommitted"
                pool-minsize="2"
                pool-maxsize="250"/>
        <!-- <jndi-jdbc jndi-server-name="default" jndi-name="comp/env/jdbc/xa/localmssql" isolation-level="ReadCommitted"/> --> <!-- Orion Style JNDI name -->
    </datasource>

以上是关于转 ofbiz各配置文件作用以及工作流程的主要内容,如果未能解决你的问题,请参考以下文章

Linux常见的重要目录及各目录作用

ofBiz-groovy-freemarker

Linux之目录结构以及各目录在系统中的作用

Android Studio 的简单配置使用以及各文件用途

Android Studio 的简单配置使用以及各文件用途

Android Studio 的简单配置使用以及各文件用途