Opentaps-Ofbiz架构分析

本文深入解析OpenTAPS企业级应用系统,探讨其基于ofbiz开发的模块化结构,详细介绍了项目与模块配置、数据源管理、实体类定义、脚本与服务定义等内容,以及登录流程和视图渲染过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://opentaps.org/index.php?option=com_content&task=view&id=22&Itemid=46

定义:opentaps是一个基于ofbiz基础开发的完全开源的企业级应用系统。

1.项目结构:

opentaps每一个模块都是单独可拆卸的结构,通过xml文件进行配置。各个模块之间耦合度非常低,可以为不同的模块配置不同的数据源。
在这里插入图片描述
component-load.xml为总的配置文件,其中指定了本项目下包含的其他所有模块,这是其他模块加载的入口。

<load-component component-location="opentaps-common"/>
<load-component component-location="crmsfa"/>
<load-component component-location="financials"/>
<load-component component-location="purchasing"/>
<load-component component-location="warehouse"/>
<load-component component-location="dataimport"/>
<load-component component-location="opentaps-tests"/>
<load-component component-location="homeapps"/>
<load-component component-location="asterisk"/>
<load-component component-location="search"/>
<load-component component-location="amazon"/>
<load-component component-location="activities"/>
<load-component component-location="translations"/>

2:模块结构

模块结构基本固定,并且没有一个模块都有着类似的目录结构。
在这里插入图片描述
build里存放编译之后的字节码文件和jar包,
config里存放的properties,主要用来做前端的展示,存放了logo的路径,网页的title,css样式等配置。
data里存放了一些种子数据的配置文件,权限的配置文件。
entitydef里存放的是实体类的定义,实体类所属group的定义。group代表了实体类与数据库之间的对应关系。在/opentaps-1.5/framework/entity/config/entityengine.xml实体引擎的配置文件里有这样的配置

<delegator name="default" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main" distributed-cache-clear-enabled="false">
        <group-map group-name="org.ofbiz" datasource-name="localmysql"/>
        <group-map group-name="org.ofbiz.olap" datasource-name="localmysql"/>
        <group-map group-name="org.ofbiz.tenant" datasource-name="localmysqltenant"/>
        <group-map group-name="org.opentaps.analytics" datasource-name="analytics"/>
        <group-map group-name="org.opentaps.testing" datasource-name="testing"/>

这里group-name就是对应配置实体时候设置的group。这个文件反映了group与数据库之间的具体关系。
script存放了一些beanshell文件这些文件是一种兼容java语法的脚本语言。在opentaps里主要用来通过调用hibernate来操作数据库。不知道这里的beanshell与下面webapp里的beanshell有什么区别。还有另外一些xml配置文件不知道是用来做什么的。
servicedef存放了关于Service定义的xml配置文件。后面有一个登录的示例说明如何调用service。
templates存放freemarker模版,opentaps用的是freemarker技术来渲染html页面。理论上也可以用其他的技术来展示view层。
webapp里存放了项目web相关的内容,在WEN-INF下有一些重要的文件
在这里插入图片描述

controller.xml通过request-map和view-map配置了url和处理类的映射关系,视图的映射关系。
action里存放了渲染视图时获取所需数据的beanshell脚本。

以login为例运行的流程
登录地址http://localhost:8080/opentaps/control/login,系统通过通过component-load.xml加载了homeapps模块,自然包括模块下的controller.xml文件。这个文件中有一个关于/login的的request-map

<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="myHomeMain"/>
        <response name="requirePasswordChange" type="view" value="requirePasswordChange"/>
        <response name="error" type="view" value="login"/>
    </request-map>
    <view-map name="myHomeMain" type="screen" page="component://crmsfa/widget/crmsfa/screens/myhome/MyHomeScreens.xml#myHome"/>

/login的请求会被转到org.ofbiz.webapp.control.LoginWorker.login()方法处理。

LocalDispatcher dispatcher = ContextFilter.makeWebappDispatcher(servletContext, delegator);
dispatcher.runSync("userLogin", UtilMisc.toMap("login.username", username, "login.password", password, "visitId", visitId, "locale", UtilHttp.getLocale(request)));

这个方法获取到了一个LocalDispatcher ,这是一个接口,实际运行的是GenericDispatcher类,随后调用runSync方法从context中获取一个userlogin的service。这个service在前文提到过的service.xml中有如下配置

<!-- UserLogin services -->
<service name="userLogin" engine="java" location="org.ofbiz.common.login.LoginServices" invoke="userLogin">
    <description>Used to Automatically Authenticate a username/password; create a UserLogin object</description>
    <implements service="authenticationInterface"/>
</service>

org.ofbiz.common.login.LoginServices.userLogin()方法。这个方法里通过

userLogin = delegator.findOne(“UserLogin”, isServiceAuth, “userLoginId”, username);
1
这个方法调用了beanshell脚本查询User_Login表中数据。然后比对用户密码,返回一个map包含了登录比对的结果。
一般情况下,当登录成功后,返回success视图时,会找到一个名为myHomeMain的视图。随后找到一个MyHomeScreens.xml配置文件。

<screen name="myHome">
    <section>
        <actions>
            <set field="pageTitleLabel" value="CrmMyHome"/>  
            <set field="sectionHeaderUiLabel" value="CrmMyHome"/>
            <set field="listSortTarget" value="myHome"/> <!-- pending  list sorting target -->
            <!-- calendar parameters -->
            <set field="defaultCalendarScreen" value="CalendarDay"/>
            <set field="calendarView" value="${parameters.calendarView}"/>
            <set field="calendarTarget" value="myHome"/>
            <set field="currentPage" value="myHome"/>
            <script location="component://crmsfa/webapp/crmsfa/WEB-INF/actions/includes/pagination.bsh"/>
            <script location="component://crmsfa/webapp/crmsfa/WEB-INF/actions/activities/setMyActivities.bsh"/>
            <script location="component://crmsfa/webapp/crmsfa/WEB-INF/actions/activities/findActivities.bsh"/> 
            <java location="org.opentaps.crmsfa.calendar.CalendarAction" invoke="calendarCommon"/>
            <script location="component://crmsfa/webapp/crmsfa/WEB-INF/actions/activities/pendingEmails.bsh"/>
        </actions>
        <widgets>
            <decorator-screen name="main-section-decorator">
                <decorator-section name="section-body">
                    <container style="subSectionBlock">
                        <!-- Calendar -->
                        <platform-specific><html><html-template location="component://crmsfa/webapp/crmsfa/calendar/submenus/calendar.ftl"/></html></platform-specific>
                    </container>

                    <!-- pending activities -->
                    <container style="subSectionBlock">
                        <platform-specific><html><html-template location="component://crmsfa/webapp/crmsfa/activities/pendingActivities.ftl"/></html></platform-specific>
                    </container>

                    <!-- pending emails -->
                    <container style="subSectionBlock">
                        <platform-specific><html><html-template location="component://crmsfa/webapp/crmsfa/activities/pendingEmails.ftl"/></html></platform-specific>
                    </container>

                    <container style="subSectionBlock">
                        <platform-specific><html><html-template location="component://crmsfa/webapp/crmsfa/activities/pendingOutboundEmails.ftl"/></html></platform-specific>
                    </container>
                </decorator-section>
            </decorator-screen>
        </widgets>
    </section>
</screen>

这里配置了一个名为myHome的screen。配置文件中action部分表示了需要设置的参数,以及需要运行的beanshell脚本。widgets表示页面的布局。这里讲页面分成了不同的部分。可以理解为这里配置了页面布局中的一个div。内容为platform-specific指定的ftl文件。


本文来自 liumuchengquan 的优快云 博客 ,全文地址请点击:https://blog.youkuaiyun.com/liumuchengquan/article/details/53668686?utm_source=copy

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值