Title : How to customise pre-persistence hook and validate from postman
Quicklinks:
Integration API Module
Persistence Hooks
In case of B2BUnit replication , Pre-persist hook "SapCpiB2BUnitPersistenceHook" is used by standard . in this tutorial , SapCpiB2BUnitPersistenceHook will be customised to support B2B unit replication with empty addresses and the same will be validated via postman .
package org.custom.integration.sapcpiproductexchange.inbound.events;
import de.hybris.platform.b2b.model.B2BUnitModel;
import de.hybris.platform.core.model.ItemModel;
import de.hybris.platform.sap.sapcpicustomerexchangeb2b.inbound.events.SapCpiB2BUnitPersistenceHook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;
import java.util.Optional;
/**
* This replaces SapCpiB2BUnitPersistenceHook to handle empty address scenario
*/
public class CustomCpiB2BUnitPersistenceHook extends SapCpiB2BUnitPersistenceHook
{
private static final Logger LOG = LoggerFactory.getLogger(CustomCpiB2BUnitPersistenceHook.class);
@Override
public Optional<ItemModel> execute(final ItemModel item)
{
if (item instanceof B2BUnitModel b2BUnitModel)
{
LOG.info("The persistence hook customCpiB2BUnitPersistenceHook is called!");
//Process addresses in case not empty
if (!CollectionUtils.isEmpty(b2BUnitModel.getAddresses()))
{
return super.execute(item);
}
}
return Optional.of(item);
}
}
<!-- Inbound Custom B2BUnit Pre-Persistence Hook -->
<bean id="customCpiB2BUnitPersistenceHook"
class="org.custom.integration.sapcpiproductexchange.inbound.events.CustomCpiB2BUnitPersistenceHook"/>
<requires-extension name="sapcpicustomerexchangeb2b"/>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
9 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |