我创建了VariantValueCategory
并希望跳过ValidateInterceptor
,因为它不允许我通过VariantValueCategory
或Impex
创建HMC
。任何人都可以建议我如何跳过ValidateInterceptor
或任何Interceptor
?
答案 0 :(得分:9)
查看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一样,你可以添加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
进行导入。这意味着INSERT
,UPDATE
和REMOVE
等操作都是使用ModelService
执行的,因此ServiceLayer
基础设施如interceptors
和validators
被触发。CRUDE
导入,这意味着它绕过了Hybris的ServiceLayer
,因此没有{{1}并且不会调用interceptors
。那么如何启用传统模式?你可以用三种不同的方式做到这一点:
validators
设置local.properties
并重新启动服务器。impex.legacy.mode = true
<!-- local.properties -->
impex.legacy.mode = true
导入,请选中HAC
复选框:legacy mode
,如下所示: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);