SAP Hybris的Convertor, Populator, Facade和DTO这几个概念是如何协同工作的

Hybris里极其重要的概念。
之前的issue谈到了Hybris MVC里的M指的是DTO,JSP作为V显示DTO的value,而DB层的Model和DTO的结构不一致。
那么,数据从DB读取之后,需要经过一个转换,写入到DTO。执行这个转换的role,就是Convertor+Populator。

注:DTO是软件设计里一个common的概念,不是Hybris特有。定义见wiki

Hybris官方定义

(1) Facade: A facade is a software design pattern that abstracts from an underlying implementation and offers an alternate, often reduced and less complex interface.

(2) DTO:Data Transfer Objects (DTOs) are objects created to only contain values and have no business logic except for getter and setter methods. Using DTOs, you can "combine" Hybris items - for example, this document adds price- and media-related data to a product object.
先看CRM。

line 17的方法从CDS view里读取persistent data:

这样做类比。

可以看到CRM两个layer之间的转换非常light weight,仅仅是几个赋值操作。
Hybris里把这个赋值操作封装到了两个新的object里:Converter和Populator。
为什么要搞这么麻烦:

(1) Data objects are constructed from Models or other Service Layer objects using Converters and Populators. The Data object is always created from a prototype-scoped spring bean that is defined in the beans.xml file for the extension.

(2) Converters create new instances of Data objects and call Populators to populate these.
即Converter负责创建Data object的实例(就是Java class的实例), Populator负责call这个实例的setter方法把业务数据写入data obeject,这样JSP绑定到这些data object的某个属性的field就能显示出来值。

既然Hybris基于Spring,那么也要follow Spring的一些原则:

(1) No concrete Converters should be written, all converters should be Spring configured only and should use the AbstractConverter base class.

(2) No Populator should be called directly in code, Converters should be Spring injected and used.

(3) All conversion logic should exist in Populators and these should be well-encapsulated and independent.

Populators

Populators break the conversion process of filling out a Data Object down into a pipeline of population tasks or steps. Each Populator carries out one or more related updates to the Data Object prototype. Each population step can invoke services or copy data from the source business object to the prototype Facade Data object. Facades always use a Converter to create a new instance of a Data Object prototype and then invoke Populators or other Converters to fulfill the task of building up the Data Object.

看具体的例子:

这个文件位置:
"C:\Hybris\6.5.0.0.23546\hybris\bin\ext-accelerator\acceleratorservices\src\de\hybris\platform\acceleratorservices\payment\cybersource\converters\populators\PaymentDataPopulator.java"

为什么要单独抽象这两个object出来?和CRM Genil layer的实现一对比就清楚了。

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

原文地址:https://www.cnblogs.com/sap-jerry/p/12153772.html

时间: 2024-08-01 03:55:08

SAP Hybris的Convertor, Populator, Facade和DTO这几个概念是如何协同工作的的相关文章

金庸和古龙,Netweaver和微服务,以及SAP Hybris Revenue Cloud

这周Jerry在长沙客户现场待了几天,感谢易总和彩亮的款待.终于有机会和关注这个公众号的一些CRM顾问们进行线下互动,感觉很不错.得知公众号里某些文章帮助顾问们解决了一些工作中的实际问题,我很高兴.感谢大家的支持,只要时间允许,这个公众号我会一直写下去. 和CRM顾问们中午吃饭时聊到了SAP一些新的云产品采用了微服务架构开发,因此我写了这篇文章. 如果要找金庸小说里帮助Jerry提高编程水平最有用的一句话,无疑是:重剑无锋,大巧不工. 杨过被郭芙斩断一臂后,以前掌握的编程语言,哦不,以前掌握的武

SAP Hybris的build callback和SAP ABAP的SGEN事务码

这个issue AIM in CRM and C4C里介绍了C4C和CRM的After import mechanism. 在Hybris里,客户把2个G的Hybris安装包下载下来,然后在命令行里运行命令安装,实际上就是用ant的build命令. 为什么要执行build: The reasons why you need to build SAP Hybris Commerce are as follows: (1) SAP Hybris Commerce is an extendable c

SAP SADL和SAP Hybris DTO

When you need a simpler or more convenient format for some of the data to display in JSPs 上面是从help.hybris.com摘录出来的原话,解释为什么我们需要DTO. 简单来说,就是因为Service Layer定义的model格式和UI需要的格式不是完全一样,如果UI直接消费Service Layer的model,代码写起来非常难看,而且会产生UI layer和service layer的强耦合. 更

SAP Hybris Commerce product读取的调试截图

通过debugger观察到Product facade调用ProductService,Service又调用DAO通过flexible search去DB根据product code 358639取数据. 类似SE16,也可以直接在Hybris Admin console里执行执行flexible search: 搜到1条记录: 从DB里取出的product数据和在debugger里观察到的一致.可以看看Hybris里product有哪些重要的field: 要获取更多Jerry的原创文章,请关注

SAP Hybris的类型系统更改和ABAP的LOAD_PROGRAM_TABLE_MISMATCH

如果正在运行一个transaction,这个时候系统有一个transport request import进来, 这个TR包含了一些DDIC object的change, 并且这些DDIC object正在被当前transaction使用,就会出现这个exception: SAP的建议是在晚上user很少的时候import TR.用SGEN只能通过在user launch transaction之前预先生成最新的ABAP LOAD来避免这个问题,但是对于TR import之前已经load到mem

SAP Hybris里搜索显示结果的实现原理

CRM Hybris Hybris是怎么实现的? 我问过Hybris成都同事了,Hybris里没有CRM WebUI里F2的概念.所以只能靠自己人肉. 前面的issue讲到product template page,在里面找到用来实现product list的component. 然后找到这个pageination的实现: 在这里显示文本: Spring Theme的语法: The theme support provided by the Spring web MVC framework en

SAP ABAP SICF事务码和SAP Hybris的链式过滤器filter chain

ABAP SICF SICF里的node是树上的节点. 如果当前节点的handler class为空: 则回溯到其parent节点,直至定位到一个有handler class的node位置. Hybris 通过debug会看到有一堆的filter参与进去: Hybris帮助文档有一些常用filter的介绍: 上面debug screenshot里诸多的filter是如何串成一个chain的?在storefront的web.xml里查找到filter chain的名称:storefrontTena

在SAP Hybris commerce Storefront里购物下单

操作过程和大家平时在网上购物没有太大差别. 选中一款心仪的产品,点击Add to cart加到购物车里: 点击Check out结帐: 生成一个购物车ID: 维护发货地址: 维护发货方式: 点击Place order按钮生成订单: 界面显示生成的订单ID: 要获取更多Jerry的原创文章,请关注公众号"汪子熙": 原文地址:https://www.cnblogs.com/sap-jerry/p/11791029.html

VO、DTO与领域模型的概念

业务对象模型(也叫领域模型 domain model)是描述业务用例实现的对象模型.它是对业务角色和业务实体之间应该如何联系和协作以执行业务的一种抽象.业务对象模型从业务角色内部的观点定义了业务用例.该模型为产生预期效果确定了业务人员以及他们处理和使用的对象("业务类和对象")之间应该具有的静态和动态关系.它注重业务中承担的角色及其当前职责.这些模型类的对象组合在一起可以执行所有的业务用例. 参考博文: 领域模型的概念 VO.DTO与领域模型