munna
munna

Reputation: 91

How do I skip certain ValidateInterceptor?

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?

Upvotes: 7

Views: 11004

Answers (3)

tucecang
tucecang

Reputation: 1

The simpliest way: unregisterInterceptor

Go to HAC -> Scripting Languages -> Groovy

def inteceptorMapping = spring.getBean("yourInterceptorMappingBeanId")
registry = spring.getBean("interceptorRegistry");
registry.unregisterInterceptor(inteceptorMapping);

Upvotes: 0

Mouad EL Fakir
Mouad EL Fakir

Reputation: 3759

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 like INSERT, UPDATE and REMOVE are performed using ModelService, thus the ServiceLayer infrastructure like interceptors and validators are triggered.
  • Legacy mode : it's a very quick 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 :

  1. In local.properties set impex.legacy.mode = true and restart the server.
<!-- local.properties -->

impex.legacy.mode = true
  1. Or if you do import using HAC, check legacy mode checkbox :

enter image description here

  1. Or set the configuration directly into theimpex 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>

Upvotes: 10

alain.janinm
alain.janinm

Reputation: 20065

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 beans
  • InterceptorExecutionPolicy.DISABLED_INTERCEPTOR_TYPES : to disable a kind of interceptor - validator for example
  • InterceptorExecutionPolicy.DISABLED_UNIQUE_ATTRIBUTE_VALIDATOR_FOR_ITEM_TYPES : to disable UniqueAttributesValidatoron 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

Upvotes: 19

Related Questions