首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何跳过某些ValidateInterceptor?

如何跳过某些ValidateInterceptor?
EN

Stack Overflow用户
提问于 2017-02-28 22:01:41
回答 3查看 7.5K关注 0票数 7

我已经创建了一个VariantValueCategory,并且希望跳过ValidateInterceptor,因为它不允许我通过ImpexHMC创建VariantValueCategory。有人能建议我如何跳过ValidateInterceptorInterceptor吗?

EN

回答 3

Stack Overflow用户

发布于 2017-03-01 09:52:49

狂妄自大的答案-- >= v6

查看Mouad El Fakir的先前版本的答案

您可以通过代码和Impex禁用拦截器。

使用代码

您可以使用sessionService.executeInLocalViewWithParams运行保存模型代码,也可以使用参数来避免使用拦截器。

有三种政策:

  • InterceptorExecutionPolicy.DISABLED_INTERCEPTOR_BEANS:禁用bean列表
  • InterceptorExecutionPolicy.DISABLED_INTERCEPTOR_TYPES:例如禁用一种拦截器-验证器
  • InterceptorExecutionPolicy.DISABLED_UNIQUE_ATTRIBUTE_VALIDATOR_FOR_ITEM_TYPES:在一组类型上禁用UniqueAttributesValidator

示例1-禁用bean

代码语言:javascript
运行
复制
final Map<String, Object> params = ImmutableMap.of(InterceptorExecutionPolicy.DISABLED_INTERCEPTOR_BEANS, ImmutableSet.of("yourDataInterceptorToDisable"));

sessionService.executeInLocalViewWithParams(params, new SessionExecutionBody()
{
    @Override
    public void executeWithoutResult()
    {
        //Do your stuff  
        modelService.save(something);   // save successful - yourDataInterceptor interceptor is disabled
    }
});

示例2-禁用类型的拦截器

代码语言:javascript
运行
复制
final Map<String, Object> params = ImmutableMap.of(InterceptorExecutionPolicy.DISABLED_INTERCEPTOR_TYPES,
                ImmutableSet.of(InterceptorExecutionPolicy.DisabledType.VALIDATE));
sessionService.executeInLocalViewWithParams(params, new SessionExecutionBody()
{
    @Override
    public void executeWithoutResult()
    {
        //Do your stuff  
        modelService.save(something);    // save successful - all validate interceptors are disabled
    }
});

示例3-按类型禁用

代码语言:javascript
运行
复制
final Map<String, Object> params = ImmutableMap.of(InterceptorExecutionPolicy.DISABLED_UNIQUE_ATTRIBUTE_VALIDATOR_FOR_ITEM_TYPES, ImmutableSet.of("YourType"));

sessionService.executeInLocalViewWithParams(params, new SessionExecutionBody()
{
    @Override
    public void executeWithoutResult()
    {
        //Do your stuff  
        modelService.save(something);   // save successful - UniqueAttributesValidator not called
    }
});

使用Impex

使用impex是一样的,您可以添加3个参数来实现与代码相同的功能

示例1-禁用bean [disable.interceptor.beans='yourDataInterceptorToDisable']

代码语言:javascript
运行
复制
INSERT_UPDATE YourType[disable.interceptor.beans='yourDataInterceptorToDisable'];isocode[unique=true];toto;titi;
;something;toto;titi;

示例2-禁用 [disable.interceptor.types=validate]类型的拦截器

代码语言:javascript
运行
复制
INSERT_UPDATE YourType[disable.interceptor.types=validate];isocode[unique=true];toto;titi;
;something;toto;titi;

示例3-按 [disable.UniqueAttributesValidator.for.types='YourType']类型禁用

代码语言:javascript
运行
复制
INSERT_UPDATE YourType[disable.UniqueAttributesValidator.for.types='YourType'];isocode[unique=true];toto;titi;
;something;toto;titi;

参考文献:https://help.hybris.com/6.3.0/hcd/9ce1b60e12714a7dba6ea7e66b4f7acd.html

票数 19
EN

Stack Overflow用户

发布于 2017-02-28 23:04:22

实际上,在海布里有两种使用ImpEx导入数据的模式:

  • 活动模式:它使用ServiceLayer进行导入。这意味着像INSERTUPDATEREMOVE这样的操作是使用ModelService执行的,因此触发了interceptorsvalidatorsServiceLayer基础设施。
  • Legacy模式:这是一个非常快速的CRUDE导入,这意味着它绕过了海布里斯的ServiceLayer,因此不会调用interceptorsvalidators

那么,如何启用遗留模式?你能用三种不同的方式做这件事吗?

  1. local.properties中,设置impex.legacy.mode = true并重新启动服务器。
代码语言:javascript
运行
复制
<!-- local.properties -->

impex.legacy.mode = true
  1. 或者,如果确实使用HAC导入,请选中legacy mode复选框:

  1. 或者将配置直接设置到impex中,如下所示:
代码语言:javascript
运行
复制
INSERT_UPDATE VariantValueCategory[impex.legacy.mode=true] ;myAttribute
...

但是,如果您想完全禁止调用interceptor (不只是针对impexes),可以用VoidInterceptor替换它。

VoidInterceptor :它是一个空拦截器,什么也不做。

因此,如果我们假设您希望防止调用这个拦截器variantCategoryValidateInterceptor,您可以这样替换它:

代码语言:javascript
运行
复制
<!-- in my*-spring.xml -->

<bean id="variantValueCategoryVoidInterceptorMapping" class="de.hybris.platform.servicelayer.interceptor.impl.InterceptorMapping">

    <property name="interceptor" ref="VoidInterceptor"/>

    <property name="typeCode" value="VariantValueCategory"/>

    <property name="replacedInterceptors" ref="variantCategoryValidateInterceptor"/>

</bean>
票数 10
EN

Stack Overflow用户

发布于 2020-07-08 12:45:54

最简单的方法:unregisterInterceptor

转到HAC ->脚本语言-> Groovy

代码语言:javascript
运行
复制
def inteceptorMapping = spring.getBean("yourInterceptorMappingBeanId")
registry = spring.getBean("interceptorRegistry");
registry.unregisterInterceptor(inteceptorMapping);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42519548

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档