Initial Data Process :
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.
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.
To try this out you need the Professional
Subscription License. And you need to add following two modules. For that go to General Setup -> Application -> Module Management -> Add Modules.
Search and install the following modules.
- Initial Data Load.
- Initial Data Load Extension for Java.
Developing Java File:
/*
************************************************************************************
* Copyright (C) 2009-2010 Openbravo S.L.U.
* Licensed under the Openbravo Commercial License version 1.0
* You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
* or in the legal folder of this module distribution.
************************************************************************************
*/
package org.ram.www.intial;
import java.lang.*;
import java.util.*;
import org.openbravo.idl.proc.Parameter;
import org.openbravo.idl.proc.Validator;
import org.openbravo.dal.service.OBQuery;
import org.openbravo.base.exception.OBException;
import org.openbravo.base.provider.OBProvider;
import org.openbravo.base.structure.BaseOBObject;
import org.openbravo.dal.core.OBContext;
import org.openbravo.dal.service.OBDal;
import org.openbravo.erpCommon.utility.Utility;
import org.openbravo.idl.proc.DALUtils;
import org.openbravo.idl.proc.Value;
import org.openbravo.model.common.currency.Currency;
import org.openbravo.model.common.uom.UOM;
import org.openbravo.module.idljava.proc.IdlServiceJava;
import org.openbravo.base.model.ModelProvider;
import org.xyz.www.cscrmstat;
/**
* Converts Excel Data in to Database Records @Initial Data Load
*
* @author Hsakarpmar
*/
public class StatusList extends IdlServiceJava {
************************************************************************************
* Copyright (C) 2009-2010 Openbravo S.L.U.
* Licensed under the Openbravo Commercial License version 1.0
* You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
* or in the legal folder of this module distribution.
************************************************************************************
*/
package org.ram.www.intial;
import java.lang.*;
import java.util.*;
import org.openbravo.idl.proc.Parameter;
import org.openbravo.idl.proc.Validator;
import org.openbravo.dal.service.OBQuery;
import org.openbravo.base.exception.OBException;
import org.openbravo.base.provider.OBProvider;
import org.openbravo.base.structure.BaseOBObject;
import org.openbravo.dal.core.OBContext;
import org.openbravo.dal.service.OBDal;
import org.openbravo.erpCommon.utility.Utility;
import org.openbravo.idl.proc.DALUtils;
import org.openbravo.idl.proc.Value;
import org.openbravo.model.common.currency.Currency;
import org.openbravo.model.common.uom.UOM;
import org.openbravo.module.idljava.proc.IdlServiceJava;
import org.openbravo.base.model.ModelProvider;
import org.xyz.www.cscrmstat;
/**
* Converts Excel Data in to Database Records @Initial Data Load
*
* @author Hsakarpmar
*/
public class StatusList extends IdlServiceJava {
@Override
public String getEntityName() {
return "CS_CRM_Status";
}
@Override
public Parameter[] getParameters() {
return new Parameter[] {
new Parameter("sno", Parameter.STRING),
new Parameter("status", Parameter.STRING)
};
}
@Override
protected Object[] validateProcess(Validator validator, String... values) throws Exception {
System.out.println("validate process");
validator.checkNotNull(validator.checkString(values[1], 32), "status");
System.out.println("after validated method");
return values;
}
@Override
public BaseOBObject internalProcess(Object... values) throws Exception {
System.out.println("internal process method method");
return createcscrmstat((String)values[0],(String)values[1]);
}
public BaseOBObject createcscrmstat(final String sno,final String status)throws Exception {
System.out.println("control in results method");
cscrmstat dummy= findDALInstance(false, cscrmstat.class, new Value("commercialName", status));
public Parameter[] getParameters() {
return new Parameter[] {
new Parameter("sno", Parameter.STRING),
new Parameter("status", Parameter.STRING)
};
}
@Override
protected Object[] validateProcess(Validator validator, String... values) throws Exception {
System.out.println("validate process");
validator.checkNotNull(validator.checkString(values[1], 32), "status");
System.out.println("after validated method");
return values;
}
@Override
public BaseOBObject internalProcess(Object... values) throws Exception {
System.out.println("internal process method method");
return createcscrmstat((String)values[0],(String)values[1]);
}
public BaseOBObject createcscrmstat(final String sno,final String status)throws Exception {
System.out.println("control in results method");
cscrmstat dummy= findDALInstance(false, cscrmstat.class, new Value("commercialName", status));
if(dummy!= null){
System.out.println(dummy);
System.out.println("if condition cscrmstat.class ");
System.out.println(dummy);
System.out.println("if condition cscrmstat.class ");
}
else{
dummy = OBProvider.getInstance().get(cscrmstat.class);
System.out.println(dummy);
dummy.setCommercialName(status);
}
OBDal.getInstance().save(dummy);
OBDal.getInstance().flush();
OBDal.getInstance().commitAndClose();
return dummy;
}
}
else{
dummy = OBProvider.getInstance().get(cscrmstat.class);
System.out.println(dummy);
dummy.setCommercialName(status);
}
OBDal.getInstance().save(dummy);
OBDal.getInstance().flush();
OBDal.getInstance().commitAndClose();
return dummy;
}
}
You can place it where ever you want to, but just be careful to provide
the proper Java package name. Also, ensure that you place the Java file
in the correct module, so that it is packaged, when you run an
"export.database".
------------------------------------------------- Code Explanation ------------------------------------------------
public Parameter[] getParameters() {
return new Parameter[] {
new Parameter("sno", Parameter.STRING),
new Parameter("status", Parameter.STRING)
};
}
return new Parameter[] {
new Parameter("sno", Parameter.STRING),
new Parameter("status", Parameter.STRING)
};
}
The parameters in the above method should be in the same order as they
appear in the input file. However, the parameter names used in the
method need not be the same as the column header in the input file.
public BaseOBObject createcscrmstat(final String sno,final String status)throws Exception {
System.out.println("control in results method");
cscrmstat dummy= findDALInstance(false, cscrmstat.class, new Value("commercialName", status));
System.out.println("control in results method");
cscrmstat dummy= findDALInstance(false, cscrmstat.class, new Value("commercialName", status));
if(dummy!= null){
System.out.println(dummy);
System.out.println("if condition cscrmstat.class ");
} System.out.println(dummy);
System.out.println("if condition cscrmstat.class ");
else{
dummy = OBProvider.getInstance().get(cscrmstat.class);
System.out.println(dummy);
dummy.setCommercialName(status);
}
OBDal.getInstance().save(dummy);
OBDal.getInstance().flush();
OBDal.getInstance().commitAndClose();
return dummy;
}
}
The createcscrmstat() method inserts values into the desired table using
OBProvider. The internalProcess() method, which is inherited from
IdlServiceJava class, is used to call the appropriate method with
appropriate parameters.
-------------------------------------------------------------------------------------------------------------------------
Define the Process:
After developing your code. need to register. Please follow as below,
- Go to Master Data Management -> Initial Data Load -> Setup -> Entity Default Value
- Register your Java file here as shown in the screen shot.
Pay special attention on the class name while adding the entity default value.
- Import the data using import window
- Go to Master Data Management -> Initial Data Load -> Process -> Import
- Choose the input file
- Choose the entity as Master Status List.
Validate the input file. If the file has invalid data, it will show the invalid data in the log.
Once the input values are validated, the data can be loaded into the actual table by clicking on the process.If there are any issues while processing the input data,
appropriate messages will be logged in the message box provided under
the Log header in the import screen.
After Successfully Processed imports check out the window (Table in which your inserting).
For more clarification and issues please comment below.