View source | Discuss this page | Page history | Printable version   
Main Page
Upload file
What links here
Recent changes

PDF Books
Add page
Show collection (0 pages)
Collections help


How to use Import Entry to distribute changes



This howto gives insight in how to write functionality which distribute changes using asynchronous events which are always executed at some point.

This type of functionality can for example be used to notify another system of a change without blocking the process which executes the change locally.

The approach shown here uses the Openbravo Import Entry framework. The import entry framework is used within OB for high volume data synchronization from WebPOS to the server.

This howto will guide you through the details on how to use the import entry framework for distributing changes in an asynchronous way. The approach works both in a single as well as a multi-server environment.

This howto assumes that the reader is familiar with the main concepts/information provided by the retail developers guide.

Example: distributing changes of customers

The example shown here has as goal to distribute changes done to customers from WebPOS to other systems.

First Step: Create Import Entry Record

The code below shows how to create a new import entry record within the customer loader hook. Openbravo provides many server side hooks which you can use. Alternatively you can use a business event handler to be create an import entry record in the same db transaction as the business documents.

import org.codehaus.jettison.json.JSONObject;
import org.openbravo.base.provider.OBProvider;
import org.openbravo.dal.core.OBContext;
import org.openbravo.dal.service.OBDal;
import org.openbravo.erpCommon.utility.SequenceIdData;
import org.openbravo.model.common.businesspartner.BusinessPartner;
import org.openbravo.retail.posterminal.CustomerLoaderHook;
import org.openbravo.service.importprocess.ImportEntry;
import org.openbravo.service.importprocess.ImportEntryManager;
public class MyCustomerLoaderHook implements CustomerLoaderHook {
  private ImportEntryManager importEntryManager
  public void exec(JSONObject jsonCustomer, BusinessPartner customer) throws Exception {
    String id = SequenceIdData.getUUID();
    importEntryManager.createImportEntry(id, "MY_CUST_UPDATE",
        "{'customerId': '" + jsonCustomer.get("id") + "'}", false);
    ImportEntry importEntry = OBDal.getInstance().get(ImportEntry.class, id);
    // do any other things you want to do with the import entry record


Instead of calling the ImportEntryManager.createImportEntry you can also directly create a new ImportEntry and save it. See the code within the ImportEntryManager.createImportEntry for details.

Second/Last Step: Create the Processor

The import entry record must be processed so it can notify the external system for the changes. For this purpose an import entry processor needs to be created.

import org.codehaus.jettison.json.JSONObject;
import org.openbravo.base.weld.WeldUtils;
import org.openbravo.dal.service.OBDal;
import org.openbravo.model.common.businesspartner.BusinessPartner;
import org.openbravo.service.importprocess.ImportEntry;
import org.openbravo.service.importprocess.ImportEntryManager.ImportEntryQualifier;
import org.openbravo.service.importprocess.ImportEntryProcessor;
import com.openbravo.but.integration.rcu.connection.RCUConnection;
@ImportEntryQualifier(entity = "MY_CUST_UPDATE")
public class RCUCustomerImportEntryProcessor extends ImportEntryProcessor {
  protected ImportEntryProcessRunnable createImportEntryProcessRunnable() {
    return WeldUtils.getInstanceFromStaticBeanManager(RCUBusinessPartnerRunnable.class);
  protected boolean canHandleImportEntry(ImportEntry importEntryInformation) {
    return "MY_CUST_UPDATE".equals(importEntryInformation.getTypeofdata());
  protected String getProcessSelectionKey(ImportEntry importEntry) {
    return importEntry.getOrganization().getId();
  private static class RCUBusinessPartnerRunnable extends ImportEntryProcessRunnable {
    protected void processEntry(ImportEntry importEntry) throws Exception {
      // call MyCust with updated customer, the importEntry has the json
      // in importEntry.getJsonInfo()
      JSONObject request = new JSONObject(importEntry.getJsonInfo());
      if (request.has("customerId")) {
        MyCustConnection.createCustomer(request.getString("customerId"), false);
      } else {
        String id = request.getString("locationId");
        BusinessPartner bp = OBDal.getInstance().get(BusinessPartner.class, id);
      // at the end set the ImportEntry as processed



After implementing the import entry processor there is nothing else to be done. The import entry manager will automatically pick up any new import entries and call the processor automatically.

Advantages of using the OB Import Entry Framework

Using the Import Entry framework for this logic has some benefits/advantages:

Retrieved from ""

This page has been accessed 129 times. This page was last modified on 21 November 2016, at 12:39. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.