Skip to main content

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.

Comments

Popular posts from this blog

My 10 years in Application Development

It's been around 10 years since I started programming. May be a bit more, if I have to include my first attempts at C programming in school. But it would be a grave insult to call remembering ten lines of code and just replicating it to put a star on the screen. I also did a course on Visual basic, but it was more gimmicks that Application development. But it was truly in the year 2007 when I started my Master in Computer Applications that I found a new flare for developing applications. 
I was very late to computers in general and even when I joined my Masters, computers were not really accessible to me. But when I joined my Masters where one is actually expected to hone the skills which they already have, but in case it was were I was learning the skills, initially it was very difficult. I was not sure what computers had for me nor I had a natural flair for programming. But the thing about computers that attracted me was the visual medium it gave. Initially it was just a door t…

Changing Timezone in Postgresql, Ubuntu

Timezone and locale are integral concepts that one should be aware of when implementing a System. For example. if you create a database in PostgreSql, it will use the default System settings for the database. Lets say you have a server in UK and your client is US. If the client tries to retrieve the current date or time, it is going to show the UK time and not the US one.
Today I encountered a different issue in our client place where the Ubuntu timezone and PostgreSql timezone were showing a incorrect values. Instead of Indian Standard Time (IST) it was showing Pacific Daylight Time(PDT). These are the steps that I followed to change the timezone to IST in PostgreSql and Ubuntu.
Changing timezone in Ubuntu:
sudo dpkg-reconfigure tzdataYou will be prompted to choose the continent and then the area. Provided screen shots where we configure the location.
Use TAB key to navigate to the OK button and then press Enter.

The changes will get reflected immediately. To check it you can open a n…

கிறுக்கனின் கிறுக்கல்கள் - அழுகையின் சிறப்பு

அழுகை என்பதை வெறுத்தவன் நான்... என்னை ஒரு நாள் பிரிந்திருக்க முடியாமல் , கைப்பேசியில் நீ சிந்திய உன் கண்ணீர் ஓசை என் காதில் கேட்கும் வரை...

பின்குறிப்பு: கிறுக்கனின் கிறுக்கல்கள் எங்கிருந்தோ தழுவப்பட்டது போல் தோன்றினால் கிறுக்கன் ( நான் உண்மையை ஏற்றுக்கொள்பவன்..:) ) பொறுப்பல்ல. கிறுக்கனின் கிறுக்கல்களில் வரும் கிறுக்கல்கள் யாவும் என் சிறய மூளையில் உதித்ததே ஆகும்.  Inspirations could have been drawn from somewhere else, but its the execution that counts....Isn't it ?