如何跳过某些ValidateInterceptor?

时间:2017-02-28 22:01:41

标签: hybris impex

我创建了VariantValueCategory并希望跳过ValidateInterceptor,因为它不允许我通过VariantValueCategoryImpex创建HMC。任何人都可以建议我如何跳过ValidateInterceptor或任何Interceptor

3 个答案:

答案 0 :(得分:9)

回答hybris> = v6

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

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

使用代码

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

有三种政策:

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

示例1 - 禁用bean

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 - 禁用拦截器类型

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 - 按类型停用

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']

INSERT_UPDATE YourType[disable.interceptor.beans='yourDataInterceptorToDisable'];isocode[unique=true];toto;titi;
;something;toto;titi;

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

INSERT_UPDATE YourType[disable.interceptor.types=validate];isocode[unique=true];toto;titi;
;something;toto;titi;

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

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

答案 1 :(得分:6)

实际上,在Hybris中使用 ImpEx 导入数据有两种模式

  • 活动模式:它使用ServiceLayer进行导入。这意味着INSERTUPDATEREMOVE等操作都是使用ModelService执行的,因此ServiceLayer基础设施如interceptorsvalidators被触发。
  • 传统模式:它非常快CRUDE导入,这意味着它绕过了Hybris的ServiceLayer,因此没有{{1}并且不会调用interceptors

那么如何启用传统模式?你可以用三种不同的方式做到这一点:

  1. validators设置local.properties并重新启动服务器。
  2. impex.legacy.mode = true
    1. 或者,如果您使用<!-- local.properties --> impex.legacy.mode = true 导入,请选中HAC复选框:
    2. enter image description here

      1. 或者将配置直接设置为legacy mode,如下所示:
      2. impex

        但是,如果要完全禁用INSERT_UPDATE VariantValueCategory[impex.legacy.mode=true] ;myAttribute ... 被调用(不仅仅是针对impexes),您可以将其替换为interceptor

          

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

        因此,如果我们假设您要阻止调用此拦截器VoidInterceptor,则可以将其替换为:

        variantCategoryValidateInterceptor

答案 2 :(得分:0)

最简单的方法:取消注册拦截器

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

def inteceptorMapping = spring.getBean("yourInterceptorMappingBeanId")
registry = spring.getBean("interceptorRegistry");
registry.unregisterInterceptor(inteceptorMapping);