I have created a VariantValueCategory
and wanted to skip the ValidateInterceptor
as it was not allowing me to create VariantValueCategory
either by Impex
or by HMC
. Can any one suggest me how do I skip ValidateInterceptor
or any Interceptor
?
Answer for hybris >= v6
Check Mouad El Fakir's answer for previous version
You can disable interceptor through code and Impex.
Using code
You can run your save model code using sessionService.executeInLocalViewWithParams
and you can use parameters to avoid to use interceptors.
There are 3 types of policies :
InterceptorExecutionPolicy.DISABLED_INTERCEPTOR_BEANS
: to disable a list of beansInterceptorExecutionPolicy.DISABLED_INTERCEPTOR_TYPES
: to disable a kind of interceptor - validator for exampleInterceptorExecutionPolicy.DISABLED_UNIQUE_ATTRIBUTE_VALIDATOR_FOR_ITEM_TYPES
: to disableUniqueAttributesValidator
on a set of type
Example 1 - Disable beans
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
}
});
Example 2 - Disable interceptors type
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
}
});
Example 3 - Disable by type
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
}
});
Using Impex
It's the same thing with impex you can add 3 parameters to achieve the same thing as code
Example 1 - Disable beans [disable.interceptor.beans='yourDataInterceptorToDisable']
INSERT_UPDATE YourType[disable.interceptor.beans='yourDataInterceptorToDisable'];isocode[unique=true];toto;titi;
;something;toto;titi;
Example 2 - Disable interceptors type [disable.interceptor.types=validate]
INSERT_UPDATE YourType[disable.interceptor.types=validate];isocode[unique=true];toto;titi;
;something;toto;titi;
Example 3 - Disable by type [disable.UniqueAttributesValidator.for.types='YourType']
INSERT_UPDATE YourType[disable.UniqueAttributesValidator.for.types='YourType'];isocode[unique=true];toto;titi;
;something;toto;titi;
Ref : https://help.hybris.com/6.3.0/hcd/9ce1b60e12714a7dba6ea7e66b4f7acd.html
Actually there are two modes of importing data with ImpEx in Hybris :
- Active mode : it uses the
ServiceLayer
to do import. It means that actions likeINSERT
,UPDATE
andREMOVE
are performed usingModelService
, thus theServiceLayer
infrastructure likeinterceptors
andvalidators
are triggered. - Legacy mode : it's a very quick
CRUDE
import, which means it's bypassing theServiceLayer
of Hybris, hence nointerceptors
and novalidators
are invoked.
So how to enable legacy mode ? will You can do this in three different ways :
- In
local.properties
setimpex.legacy.mode = true
and restart the server.
<!-- local.properties -->
impex.legacy.mode = true
- Or if you do import using
HAC
, checklegacy mode
checkbox :
- Or set the configuration directly into the
impex
like this :
INSERT_UPDATE VariantValueCategory[impex.legacy.mode=true] ;myAttribute
...
However if you want to disable completely the interceptor
from being called (not just for impexes), you can replace it with a VoidInterceptor
.
VoidInterceptor : it's an empty interceptor, it does nothing at all.
So if we suppose that you want to prevent this interceptor variantCategoryValidateInterceptor
from being invoked, you can replace it like this :
<!-- 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>
impex.legacy.mode
way was to aggressive, it bypass all interceptors. You can't be precise and just skip one specific validator. There are now cleaner way to disable interceptor. Please check my answer! –
Battue The simpliest way: unregisterInterceptor
Go to HAC -> Scripting Languages -> Groovy
def inteceptorMapping = spring.getBean("yourInterceptorMappingBeanId")
registry = spring.getBean("interceptorRegistry");
registry.unregisterInterceptor(inteceptorMapping);
© 2022 - 2024 — McMap. All rights reserved.