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
?
Check Mouad El Fakir's answer for previous version
You can disable interceptor through code and Impex.
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 disable UniqueAttributesValidator
on a set of typeExample 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
}
});
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 :
ServiceLayer
to do import. It means that actions like INSERT
, UPDATE
and REMOVE
are performed using ModelService
, thus the ServiceLayer
infrastructure like interceptors
and validators
are triggered.CRUDE
import, which means it's bypassing the ServiceLayer
of Hybris, hence no interceptors
and no validators
are invoked.So how to enable legacy mode ? will You can do this in three different ways :
local.properties
set impex.legacy.mode = true
and restart the server.<!-- local.properties -->
impex.legacy.mode = true
HAC
, check legacy mode
checkbox :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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With