Disabling Interceptors
You can disable interceptors in a session if necessary. You can do it programmatically by using the sessionService class, or declaratively via ImpEx import.
You can disable interceptors for data integration scenarios to relax certain constraints imposed on a data model. Disabling interceptors may also be useful from the performance point of view. If you are sure that your data doesn't violate a particular interceptor, you can disable it for a given operation.
Disable Interceptors Programmatically
To disable interceptors in code, use the sessionService.executeInLocalViewWithParams method. It is an implementation of a template method pattern and takes a map of attributes that are set in a session before execution of the provided callback method, and reverted afterwards.
-
disable.interceptor.beans (InterceptorExecutionPolicy#DISABLED_INTERCEPTOR_BEANS constant) This attribute takes a set of Spring bean IDs.
-
disable.interceptor.types (InterceptorExecutionPolicy#DISABLED_INTERCEPTOR_TYPES constant) This attribute takes a set of interceptor types (de.hybris.platform.servicelayer.interceptor.impl.InterceptorExecutionPolicy.InterceptorType) that you want to disable.
-
disable.UniqueAttributesValidator.for.types (InterceptorExecutionPolicy#DISABLED_UNIQUE_ATTRIBUTE_VALIDATOR_FOR_ITEM_TYPES) This attribute takes a set of item types for which you want to disable UniqueAttributesValidator.
final CurrencyModel currency = modelService.create(CurrencyModel.class);
currency.setSymbol("$");
currency.setIsocode("USD");
currency.setDigits(-1);
modelService.save(currency); // throws ModelSavingException caused by InterceptorException
final Map<String, Object> params = ImmutableMap.of(InterceptorExecutionPolicy.DISABLED_INTERCEPTOR_TYPES,
ImmutableSet.of(InterceptorExecutionPolicy.InterceptorType.VALIDATE));
sessionService.executeInLocalViewWithParams(params, new SessionExecutionBody()
{
@Override
public void executeWithoutResult()
{
final CurrencyModel currency = modelService.create(CurrencyModel.class);
currency.setSymbol("$");
currency.setIsocode("Dollar");
currency.setDigits(-1);
modelService.save(currency); // save successful - all validate interceptors are disabled
}
});
final Map<String, Object> params = ImmutableMap.of(InterceptorExecutionPolicy.DISABLED_INTERCEPTOR_BEANS, ImmutableSet.of("validateCurrencyDataInterceptor"));
sessionService.executeInLocalViewWithParams(params, new SessionExecutionBody()
{
@Override
public void executeWithoutResult()
{
final CurrencyModel currency = modelService.create(CurrencyModel.class);
currency.setSymbol("$");
currency.setIsocode("Dollar");
currency.setDigits(-1);
modelService.save(currency); // save successful - validateCurrencyDataInterceptor interceptor is disabled
}
});
In case we know that there is no Currency with the Dollar IsoCode, we can disable UniqueAttributesValidator for the Currency type, as shown in the code:
final Map<String, Object> params = ImmutableMap.of(InterceptorExecutionPolicy.DISABLED_UNIQUE_ATTRIBUTE_VALIDATOR_FOR_ITEM_TYPES, ImmutableSet.of("Currency"));
sessionService.executeInLocalViewWithParams(params, new SessionExecutionBody()
{
@Override
public void executeWithoutResult()
{
final CurrencyModel currency = modelService.create(CurrencyModel.class);
currency.setSymbol("$");
currency.setIsocode("Dollar");
currency.setDigits(-1);
modelService.save(currency); // save successful - UniqueAttributesValidator not called
}
});
Disable Interceptors via ImpEx
INSERT_UPDATE Currency;isocode[unique=true];digits;symbol ;EUR_Test;-2;€
with the following exception:
[de.hybris.platform.servicelayer.i18n.interceptors.ValidateCurrencyDataInterceptor@13097d1b]: Number of digits for CurrencyModel must be greater than 0.;EUR;-2;€
INSERT_UPDATE Currency[disable.interceptor.types=validate];isocode[unique=true];symbol;digits; ;EUR_Test2;$;-2;
INSERT_UPDATE Currency[disable.interceptor.beans='validateCurrencyDataInterceptor'];isocode[unique=true];symbol;digits; ;EUR_Test;$;-2;
To disable UniqueAttributesValidator, specify a comma-separated item types for which you want to disable it:
INSERT_UPDATE Currency[disable.UniqueAttributesValidator.for.types='Currency'];isocode[unique=true];symbol;digits; ;EUR_Test;$;-2;
If you want to specify more than one ID, put the bean IDs in apostrophes: <'beanID'>.