我创建了一个VariantValueCategory
并想跳过ValidateInterceptor
它,因为它不允许我创建VariantValueCategory
by Impex
或by HMC
.任何人都可以建议我如何跳过 ValidateInterceptor
或任何Interceptor
?
ala*_*inm 10
查看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
}
});
Run Code Online (Sandbox Code Playgroud)
示例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
}
});
Run Code Online (Sandbox Code Playgroud)
示例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
}
});
Run Code Online (Sandbox Code Playgroud)
与impex一样,你可以添加3个参数来实现与代码相同的功能
示例1 - 禁用bean [disable.interceptor.beans='yourDataInterceptorToDisable']
INSERT_UPDATE YourType[disable.interceptor.beans='yourDataInterceptorToDisable'];isocode[unique=true];toto;titi;
;something;toto;titi;
Run Code Online (Sandbox Code Playgroud)
示例2 - 禁用拦截器类型 [disable.interceptor.types=validate]
INSERT_UPDATE YourType[disable.interceptor.types=validate];isocode[unique=true];toto;titi;
;something;toto;titi;
Run Code Online (Sandbox Code Playgroud)
示例3 - 按类型禁用 [disable.UniqueAttributesValidator.for.types='YourType']
INSERT_UPDATE YourType[disable.UniqueAttributesValidator.for.types='YourType'];isocode[unique=true];toto;titi;
;something;toto;titi;
Run Code Online (Sandbox Code Playgroud)
参考:https://help.hybris.com/6.3.0/hcd/9ce1b60e12714a7dba6ea7e66b4f7acd.html
实际上在Hybris中有两种使用ImpEx导入数据的模式:
ServiceLayer
导入.这意味着,行动一样INSERT
,UPDATE
和REMOVE
使用进行ModelService
,因此,ServiceLayer
如基础设施interceptors
和validators
被触发.CRUDE
导入,这意味着它绕过了ServiceLayer
Hybris,因此没有interceptors
和没有validators
被调用.那么如何启用传统模式呢?你能用三种不同的方式做到这一点:
local.properties
设置impex.legacy.mode = true
并重新启动服务器.<!-- local.properties -->
impex.legacy.mode = true
Run Code Online (Sandbox Code Playgroud)
HAC
,请legacy mode
选中复选框:impex
:INSERT_UPDATE VariantValueCategory[impex.legacy.mode=true] ;myAttribute
...
Run Code Online (Sandbox Code Playgroud)
但是,如果要完全禁用interceptor
被调用(不仅仅是for impexes),可以用a替换它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>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2164 次 |
最近记录: |