Development Environment

Import Loader Process For Custom Modules

Hi All,
The import loader process is used to load data into the openbravo windows from input files. Openbravo has provided the options to load product, business partner, etc., Now we have the option of creating import process for our own modules with a simple java file (Refer here). Right now this process reads data from csv file(The Input format is parsed using the file IdlServiceJava.java file). This can also be extended to read input from other formats by creating a service file similar to IdlServiceJava. The only catch here is that to try this out you need the Professional Subscription, after all not everything comes free in life…:).  I installed the modules, Initial Data Load and Initial Data Load Extension for Java. I used the sample import process that comes along with initial data load extension module and created a new import process for the window frequency.
Here are the steps which I followed.
1. Creating the Java Process file

 package com.fugoconsulting.xyzz.module.template.erpCommon.ad_process;

import org.openbravo.idl.proc.Parameter;
 import org.openbravo.idl.proc.Validator;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.text.ParseException;
 import java.math.BigDecimal;
 import java.util.Date;
 import org.apache.log4j.*;
import org.openbravo.base.exception.OBException;
 import org.openbravo.base.provider.OBProvider;
 import org.openbravo.base.structure.BaseOBObject;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.idl.proc.Value;
 import org.openbravo.module.idljava.proc.IdlServiceJava;
 import com.fugoconsulting.xyzz.module.template.XYZZFrequency;
/**
 *
 * @author Pandeeswari
 */
 public class ImportFrequency extends IdlServiceJava {
private static Logger log=Logger.getLogger(ImportFrequency.class);
 DateFormat df = new SimpleDateFormat(“dd-MM-yyyy”);
@Override
 public String getEntityName() {
 return “Simple Frequency”;
 }
@Override
 public Parameter[] getParameters() {
 return new Parameter[] {
 new Parameter(“Organization”, Parameter.STRING),
 new Parameter(“SearchKey”, Parameter.STRING),
 new Parameter(“Name”, Parameter.STRING),
 new Parameter(“Description”, Parameter.STRING),
 new Parameter(“Factor”, Parameter.STRING),
 new Parameter(“Date”, Parameter.STRING) };
 }
@Override
 protected Object[] validateProcess(Validator validator, String… values) throws Exception {
 validator.checkOrganization(values[0]);
 validator.checkNotNull(validator.checkString(values[1], 40), “SearchKey”);
 validator.checkNotNull(validator.checkString(values[2], 60), “Name”);
 validator.checkString(values[3], 255);
 validator.checkBigDecimal(values[4]);
 validator.checkDate(values[5]);
 return values;
 }
@Override
 public BaseOBObject internalProcess(Object… values) throws Exception {
return createFrequency((String) values[0], (String) values[1], (String) values[2],
 (String) values[3], (String) values[4], (String) values[5]);
 }
public BaseOBObject createFrequency(final String Organization, final String searchkey,
 final String name, final String description, final String factor,
 final String aDate)
 throws Exception {
// Frequency
 XYZZFrequency frequencyExist = findDALInstance(false, XYZZFrequency.class, new Value(“searchKey”, searchkey));
 if (frequencyExist != null) {
 throw new OBException(Utility.messageBD(conn, “XYZZ_FREQ_EXISTS”, vars.getLanguage())
 + searchkey);
 }
 XYZZFrequency frequency = OBProvider.getInstance().get(XYZZFrequency.class);
try {
 frequency.setActive(true);
 frequency.setOrganization(rowOrganization);
 frequency.setSearchKey(searchkey);
 frequency.setName(name);
 frequency.setDescription(description);
 frequency.setFactor(new BigDecimal(factor));
 // Date date = df.parse(aDate);
 Date  date = new Date();
 frequency.setDate(date);
OBDal.getInstance().save(frequency);
 OBDal.getInstance().flush();
 } catch (Exception e) {
 e.printStackTrace();
 }
// End process
 OBDal.getInstance().commitAndClose();
return frequency;
 }
 }

I have created the Java File inside modules/mymodule/erpCommon/ad_process. You can place it where ever you want but just be careful to provide the proper Java package name.
Inside the getParameters() method, we provide the columns in the same order as it is in the input file. But the parameter names used in the method need not be the same.
The createFrequency() just inserts the value into the table using OBProvider.  The internalProcess(Object… values) Method which is inherited from IdlServiceJava class is used to call the appropriate method with appropriate parameters.
2. Register the file in entity default value
Register the Entity in Master Data Management -> Initial Data Load  -> Setup  -> Entity Default Value
Make Special note on the class name while adding the entity default value.
3. Import the data using import window
  • Go to Master Data Management -> Initial Data Load -> Process -> Import
  • Choose the input file
  • Choose the entity as Frequency
  • Give Validate
  • Once the input values are validated, the data can be loaded into the actual table by giving process.
  • If there occurs any problem with the input data, it will be logged in the boxes provided in the import screen.
Note: I thank my Colleague Pandi for helping me a lot in this regard.
Previous post

New "Title" type nodes in Balance & PL reports

Next post

Purpose of Application Element in Openbravo

No Comment

Leave a reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>