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

PDF Books
Show collection (0 pages)
Collections help

Search

ERP 2.50:Developers Guide/How to Create Your Own Import Process with IDL/it

Contents

Introduzione

Il processo di importazione è utilizzato per caricare i dati nelle finestre di Openbravo a partire da file di input. Openbravo ha fornito la possibilità di caricare prodotti, business partners , ecc, Ora abbiamo la possibilità di creare processo di importazione per il proprio modulo con un semplice file java (Consultare [[1]]). Questo processo legge i dati da file CSV (il formato di input viene analizzato utilizzando il file IdlServiceJava.java). Questo può anche essere esteso per leggere l'input da altri formati, creando un file di servizio simile a IdlServiceJava. Per provare questo è necessaria l'abbonamento alla licenza professionale.

Obiettivo

Questo how-to si concentrerà sulla creazione di un processo di caricamento di importazione in Openbravo ERP e spiegherà anche, con un esempio, come caricare i dati in moduli personalizzati utilizzando il processo di caricamento di importazione.

Spiegazione passo passo

Installare Moduli Richiesti

Creare File di Processo

 
 
 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@FugoConsulting
 */
 public class ImportFrequency extends IdlServiceJava {
 
 private static Logger log=Logger.getLogger(ImportFrequency.class);
 
 @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 = new Date();
 frequency.setDate(date);
 
 OBDal.getInstance().save(frequency);
 OBDal.getInstance().flush();
 } catch (Exception e) {
 e.printStackTrace();
 }
 
// End process
 OBDal.getInstance().commitAndClose();
 
return frequency;
 }
 }
 

The Java File in the above example is created inside <Openbravo Source folder>/modules/mymodule/erpCommon/ad_process. 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".

 
 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) };
 }

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 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 = new Date();
 frequency.setDate(date);
 
OBDal.getInstance().save(frequency);
 OBDal.getInstance().flush();
 } catch (Exception e) {
 e.printStackTrace();
 }
 
// End process
 OBDal.getInstance().commitAndClose();
 
return frequency;
 }

The createFrequency() 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.


Registrare il Processo

Entitydefaultvalue1.png

Pay special attention on the class name while adding the entity default value.

ImportLoader1.png

Aftervalidate.png

Afterprocess.png

Retrieved from "http://wiki.openbravo.com/wiki/ERP_2.50:Developers_Guide/How_to_Create_Your_Own_Import_Process_with_IDL/it"

This page has been accessed 1,962 times. This page was last modified on 14 June 2011, at 11:04. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.