我已经创建了一个VariantValueCategory
,并且希望跳过ValidateInterceptor
,因为它不允许我通过Impex
或HMC
创建VariantValueCategory
。有人能建议我如何跳过ValidateInterceptor
或Interceptor
吗?
发布于 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
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
发布于 2017-02-28 23:04:22
实际上,在海布里有两种使用ImpEx导入数据的模式:
ServiceLayer
进行导入。这意味着像INSERT
、UPDATE
和REMOVE
这样的操作是使用ModelService
执行的,因此触发了interceptors
和validators
等ServiceLayer
基础设施。CRUDE
导入,这意味着它绕过了海布里斯的ServiceLayer
,因此不会调用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
...
但是,如果您想完全禁止调用interceptor
(不只是针对impexes),可以用VoidInterceptor
替换它。
VoidInterceptor :它是一个空拦截器,什么也不做。
因此,如果我们假设您希望防止调用这个拦截器variantCategoryValidateInterceptor
,您可以这样替换它:
<!-- 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>
发布于 2020-07-08 12:45:54
最简单的方法:unregisterInterceptor
转到HAC ->脚本语言-> Groovy
def inteceptorMapping = spring.getBean("yourInterceptorMappingBeanId")
registry = spring.getBean("interceptorRegistry");
registry.unregisterInterceptor(inteceptorMapping);
https://stackoverflow.com/questions/42519548
复制相似问题