`
brandNewUser
  • 浏览: 446279 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

ApacheOFBiz的相关介绍以及使用总结(一)

阅读更多

由于最近一段时间在给一个创业的公司做客户关系管理CRM系统,限于人力要求(其实是没有多少人力),只能看能否有稳定,开源的半成品进行改造,而且最好不需要前端(js)相关开发人员的支援就可以把事情做成,经过一段时间(其实也就是1周)的调研,最好把目标锁定在OFBiz上。

 

OFBiz简介,什么是OFBiz

 
OFBiz is an Apache Software Foundation top level project.
 
Apache  OFBiz全称是The ApacheOpen For Business Project。是开放的电子商务平台,是一个非常著名的开源项目,提供了创建基于最新的J2EE/XML规范和技术标准,构建大中型企业级、快平台、跨数据库、跨应用服务器的多层、分布式电子商务类WEB应用系统的框架。
 
OFBiz几乎实现了所有的J2EE核心设计模式,各个模块之间的耦合比较松散,用户能够比较容易的根据自己的需要进行拆卸,非常灵活。下面介绍一下它的目录结构以及文件说明。
 
可以参考一些blog中关于OFBiz的讨论:
 

 

 

Apache OFBiz进行环境部署

 
Apache OFBiz是一个商业软件架构,opentaps 基于 Apache OFBiz 的解决方案,其官方网站地址:
 
在官网中下载最新版本的OFBiz:apache-ofbiz-13.07.02.zip
 
将其解压,执行命令
 
ant
ant load-demo
cd tools
./startofbiz.sh
 
 
执行完成后,就可以在本机的下面url中的查看相应的功能:
 
 
其中,管理员的用户名 admin/ofbiz,登录后的界面如下(其中修改了默认的视觉风格): 


 

一些重要的配置文件

 
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->

component-load.xml 

 
路径:ofbiz\application\,该配置文件的作用为模块加载文件,定义了所有在OFBIZ启动时需要加载的应用程序的位置,当你创建了新的应用程序时,别忘了在该文件中添加应用程序的位置信息,在 ofbiz\hot-deploy\目录下的应用程序不需要在component-load.xml里定义,ofbiz启动时会自动加载所有hot- deploy下的内容。
 

ofbiz-component.xml  

 
位置:基于ofbiz的任何应用程序根目录下,指出该应用程序数据模型(<entity-resource>),商业逻辑(<service-resource>),web应用程序(<webapp.../>)的位置。
例子:  

<entity-resource type="model" reader-name="main"   loader="main" location="entitydef/entitymodel.xml" />   
<service-resource type="model" loader="main"   location="servicedef/services_agreement.xml" />
<webapp name="accounting" title="Accounting" server="default-server" location="webapp/accounting"  base-permission="OFBTOOLS,ACCOUNTING" mount-point="/accounting" />  
 
 

web.xml  

 
位置:应用程序\webapp\accounting\WEB-INF,用于配置main servlet(s),控制后台服务器(如tomcat server),及一些相关参数。 
 

controller.xml  

位置:应用程序\webapp\accounting\WEB-INF,作用:负责控制接收到的请求request。任何到来的请求,无论是屏幕请求,还是服务请求或事件请求,都要经过controller.xml的处理,然后转交给相应的部分处理。
例子:  
<request-map uri="main">  
<security https="true" auth="true" />   
<response name="success" type="view" value="main" />
</request-map>   
<view-map name="main" type="screen"   page="component://accounting/widget/CommonScreens.xml#main" />
 
(当请求"main"到来时,在controller.xml中,先找到<request-map uri="main">,根据其value="main",继续向下找到view-map name="main"
,最后得到该请求该返回的页面位置:page="component://accounting/widget /CommonScreens.xml#main" ) 
 

 

在OFBiz中,是根据模块-请求-服务-页面的总体流程来实现的,每个模块的配置文件如下:
 
<?xml version="1.0" encoding="UTF-8"?>
<ofbiz-component name="basicconfig"
                 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"/>
    <entity-resource type="data" reader-name="main" loader="main" location="data/BasicDataTypeData.xml"/>
    <entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/>
    <service-resource type="model" loader="main" location="servicedef/services_consultant.xml"/>
    <webapp name="basicconfig"
            title="BasicConfig"
            description="BasicConfigDescription"
            server="default-server"
            base-permission="OFBTOOLS,BASICCONFIG"
            location="webapp/basicconfig"
            mount-point="/basicconfig"
            app-bar-display="true">
    </webapp>

</ofbiz-component> 
 
其中涉及到 实体模型文件,服务模型文件,webapp声明部分。
 

OFBiz中的服务

 

其中的服务实现有两种,其中src对应其中的java类,此时声明service的engine为java,而没有使用OFBiz中自带的特殊服务类型,下面就是服务声明部分:
<service name="createConsultant" engine="java"
             location="com.xxx.basicconfig.service.ConsultantServices" invoke="createConsultant" auth="true">
        <description>Get commission receiving parties and amounts for a product. &lt;br/&gt;
            amount input is for the entire quantity. &lt;br/&gt;&lt;br/&gt;
            Returns a List of Maps each containing &lt;br/&gt;
            partyIdFrom String commission paying party &lt;br/&gt;
            partyIdTo String commission receiving party &lt;br/&gt;
            commission BigDecimal Commission &lt;br/&gt;
            days Long term days &lt;br/&gt;
            currencyUomId String Currency &lt;br/&gt;
            productId String Product Id &lt;br/&gt;
            Will use the virtual product if no agreement is found for a variant product. If no quantity is specified,
            defaults to one (1).
        </description>
        <!--<permission-service service-name="acctgCommissionPermissionCheck" main-action="VIEW"/>-->
        <attribute name="consultantName" type="String" mode="IN" optional="false"/>
        <attribute name="consultantCode" type="String" mode="IN" optional="false"/>
        <attribute name="consultantEmail" type="String" mode="IN" optional="false"/>
        <attribute name="consultantGender" type="String" mode="IN" optional="false"/>
        <attribute name="consultantCity" type="String" mode="IN" optional="false"/>
        <!--<attribute name="commissions" type="List" mode="OUT" optional="false"/>-->
    </service>
 
其中涉及到了服务名称,引擎类型(java),如果引擎是java类,location就使用了对应的Java类完整路径,invoke中指定了该类型调用的方法。
 
属性列表中声明了该服务所输入/输出的所有的参数列表,如果在调用该服务时,参数并没有满足要求,比如名称,类型,输入(IN)且optional=false的参数没有传过来,则会报错。
 
服务类的方式采用类型的静态方法(保证无状态),其实现举例如下:
 
public static Map<String, Object> deleteConsultant(DispatchContext dispatchContext, Map<String, Object> context) {
        String consultantId = (String) context.get("userId");
        Delegator delegator = dispatchContext.getDelegator();
        GenericPK dsConsultant = delegator.makePKSingle("UserLoginSecurity", consultantId);

        try {
            delegator.removeByPrimaryKey(dsConsultant);
        } catch (GenericEntityException e) {
            Debug.logWarning(e.getMessage(), module);
            return ServiceUtil.returnError(e.getMessageList());
        }
        return new HashMap<>();
    }
 
 在Map结构的Context中,根据key(也就是service文件中声明的属性名称,mode需为IN/INOUT)来拿到其对应的值,返回一个Map,其中的key对应service文件声明的属性,mode对应OUT,需要将该名称的属性值放到Map中。
 
在服务实现中无可避免地需要使用数据层服务,这个时候,就需要dispatchContext.getDelegator()方法来拿到Delegator作为数据端的代理,使用OFBiz中的数据模型服务来操纵数据库。关于Delegator以及数据服务端,在下一篇总结中介绍。
 
 
 
  • 大小: 334.3 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics