Log in / create account
View source | Discuss page | Page history | Printable version   
Community Hurdle Assessment
ADVERTISEMENT
Accounting eLearning Courses
PDF Tools
Add page
Print collection (0 pages)
Collections help
Partnerships
SourceForge.net Logo
Openbravo ERP at SourceForge

SourceForge.net Logo
Openbravo POS at SourceForge

Open Solution Alliance Logo
Openbravo at Open Solutions Alliance

How to migrate code 2.2x

Contents

Introduction

Openbravo 2.2x introduces several changes and new features. Among others:

This document describes the steps to migrate the self-developed sources from a 2.14 or lower version into 2.2x.

New directory tree structure

Starting with v2.20, Openbravo has a new directory tree structure. In order to separate the core components (XmlEngine, Sqlc, HttpBaseServlet) and WAD from the ERP itself, it has been divided into different projects. For more information about it, check the Directory tree description document.

New combo system

Main structure

The new combo system has the following structure:

try {
  ComboTableData comboTableData = new ComboTableData(this, "--TYPE--", "--COLUMN--", "--REFERENCE--", "--VALIDATION--", Utility.getContext(this, vars, "#User_Org", "--WINDOW NAME--"), Utility.getContext(this, vars, "#User_Client", "--WINDOW NAME--"), 0);
  Utility.fillSQLParameters(this, vars, null, comboTableData, "--WINDOW NAME--", "--DEFAULT VALUE--");
  xmlDocument.setData("--REPORT NAME--","liststructure", comboTableData.select(false));
  comboTableData = null;
} catch (Exception ex) {
  throw new ServletException(ex);
}

We have to fill the fields in uppercase:

  1. TYPE: the combo type: TABLEDIR, TABLE or LIST
  2. COLUMN: column with the values of the combo. It's mandatory for the TABLEDIR combos and recommended for the TABLE and LIST ones. It makes it easier to understand.
  3. REFERENCE: reference used by the TABLE and LIST types. In case of the TABLEDIRs it should be “”. We can either write the name or its ID.
  4. VALIDATION: in case there's a validation. We can either write the name or its ID.
  5. WINDOW NAME: the window name.
  6. REPORT NAME: it must match the report name in the mapping XML file.
  7. DEFAULT VALUE: default combo value.

We will see an example for each type of Combo.

TABLEDIR

import org.openbravo.erpCommon.reference.TableDirData;
       xmlDocument.setData("reportC_BP_GROUPID","liststructure",TableDirData.selectC_BP_Group_ID(this, Utility.getContext(this, vars, "#User_Org", "ReportRefundInvoiceCustomerDimensionalAnalyses"), Utility.getContext(this, vars, "#User_Client", "ReportRefundInvoiceCustomerDimensionalAnalyses"), strPartnerGroup));
import org.openbravo.erpCommon.utility.ComboTableData;

try {
  ComboTableData comboTableData = new ComboTableData(this, "TABLEDIR", "C_BP_Group_ID", "", "", Utility.getContext(this, vars, "#User_Org", "ReportRefundInvoiceCustomerDimensionalAnalyses"), Utility.getContext(this, vars, "#User_Client", "ReportRefundInvoiceCustomerDimensionalAnalyses"), 0);
  Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportRefundInvoiceCustomerDimensionalAnalyses", strPartnerGroup);
  xmlDocument.setData("reportC_BP_GROUPID","liststructure", comboTableData.select(false));
  comboTableData = null;
} catch (Exception ex) { 
  throw new ServletException(ex);
}

LIST

import org.openbravo.erpCommon.reference.ListData;

xmlDocument.setData("reportPaymentRule", "liststructure", ListData.select(this, "195", ""));
import org.openbravo.erpCommon.utility.ComboTableData;

try {
  ComboTableData comboTableData = new ComboTableData(this, "LIST", "", "All_Payment Rule", "", Utility.getContext(this, vars, "#User_Org", "ChangeOrderOrg"), Utility.getContext(this, vars, "#User_Client","ChangeOrderOrg"), 0);
  Utility.fillSQLParameters(this, vars, null, comboTableData, "ChangeOrderOrg", "");
  xmlDocument.setData("reportPaymentRule","liststructure", comboTableData.select(false));
  comboTableData = null;
} catch (Exception ex) {
  throw new ServletException(ex);
}

TABLE

import org.openbravo.erpCommon.reference.TableListValData;

TableListValData[] tlv = TableListValData.select159_119(this, Utility.getContext(this, vars, "#User_Org", strWindowId), Utility.getContext(this, vars, "#User_Client", strWindowId), strBPartner, "");
import org.openbravo.erpCommon.utility.ComboTableData;
import org.openbravo.data.FieldProvider;

FieldProvider [] tlv = null;
try {
  ComboTableData comboTableData = new ComboTableData(this, "TABLE", "", "C_BPartner Location", "C_BPartner Location - Bill To", Utility.getContext(this, vars, "#User_Org", strWindowId), Utility.getContext(this, vars, "#User_Client", strWindowId), 0);
  Utility.fillSQLParameters(this, vars, null, comboTableData, strWindowId, "");
  tlv = comboTableData.select(false);
  comboTableData = null;
} catch (Exception ex) {
  throw new ServletException(ex);
}

IMPORTANT NOTE: when the combo uses the FieldProvider interface (like this example), all the methods of this interface must be replaced by getField("method"). For example:

resultado.append("new Array(\"" + tlv[i].id + "\", \"" +  FormatUtilities.replaceJS(tlv[i].name) + "\", \"" + (tlv[i].id.equalsIgnoreCase(strLocation)?"true":"false") + "\")");
resultado.append("new Array(\"" + tlv[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tlv[i].getField("name")) + "\", \"" + (tlv[i].getField("id").equalsIgnoreCase(strLocation)?"true":"false") + "\")");

Deprecated classes

Now these 3 type of combos use the org.openbravo.erpCommon.utility.ComboTableData class. Therefore the following classes have been marked as deprecated and are no longer available for use:

import org.openbravo.erpCommon.reference.ListData;
import org.openbravo.erpCommon.reference.TableDirData;
import org.openbravo.erpCommon.reference.TableDirTrlData;
import org.openbravo.erpCommon.reference.TableDirValData;
import org.openbravo.erpCommon.reference.TableDirValTrlData;
import org.openbravo.erpCommon.reference.TableListData
import org.openbravo.erpCommon.reference.TableListTrlData;
import org.openbravo.erpCommon.reference.TableListValData;
import org.openbravo.erpCommon.reference.TableListValTrlData;

Language detection

Finally, notice that this new combo system takes care of the language detection, so all the *TrlData combos are no longer necessary. Thus they should be deleted. For example:

if (vars.getLanguage().equals("en_US")) {
  xmlDocument.setData("reportCategory","liststructure", TableDirData.selectM_Product_Category_ID(this, Utility.getContext(this, vars, "#User_Org", "ABCproduct"), Utility.getContext(this, vars, "#User_Client", "ABCproduct"), ""));
} else {
  xmlDocument.setData("reportCategory","liststructure", TableDirTrlData.selectM_Product_Category_ID(this, Utility.getContext(this, vars, "#User_Org", "ABCproduct"), Utility.getContext(this, vars, "#User_Client", "ABCproduct"), ""));
}

As said we delete the if-else structure and the structure containing the TableDirTrlData. There's only the first structure left, and this would be transformed into:

try {
  ComboTableData comboTableData = new ComboTableData(this, "TABLEDIR", "M_Product_Category_ID", "", "", Utility.getContext(this, vars, "#User_Org", "ABCproduct"), Utility.getContext(this, vars, "#User_Client", "ABCproduct"), 0);
  Utility.fillSQLParameters(this, vars, null, comboTableData, "ABCproduct", "");
  xmlDocument.setData("reportCategory","liststructure", comboTableData.select(false));
  comboTableData = null;
} catch (Exception ex) {
  throw new ServletException(ex);
}

Repackaged classes

OLD NEW
org.openbravo.base.CPStandAlone org.openbravo.database.CPStandAlone
org.openbravo.base.ConnectionProvider org.openbravo.database.ConnectionProvider
org.openbravo.base.ConnectionProviderImpl org.openbravo.database.ConnectionProviderImpl
org.openbravo.data.MultiPartRequest org.openbravo.base.MultiPartRequest
org.openbravo.base.PoolNotFoundException org.openbravo.database.PoolNotFoundException
org.openbravo.data.FileToDataLoader org.openbravo.utils.FileToDataLoader
org.openbravo.data.RDMSIndependent org.openbravo.database.RDMSIndependent
org.openbravo.data.StandAloneConnection org.openbravo.database.StandAloneConnection

In a UNIX system we can perform this replacements with Sed:

[/opt/AppsOpenbravo]$ find -type f -name "*.java" | while read file; do sed -i -f imports "$file"; done

Where imports is a text file with all the replacements:

s/import org\.openbravo\.base\.CPStandAlone/import org.openbravo.database.CPStandAlone/g
s/import org\.openbravo\.base\.ConnectionProvider/import org.openbravo.database.ConnectionProvider/g
s/import org\.openbravo\.base\.ConnectionProviderImpl/import org.openbravo.database.ConnectionProviderImpl/g
s/import org\.openbravo\.data\.MultiPartRequest/import org.openbravo.base.MultiPartRequest/g
s/import org\.openbravo\.base\.PoolNotFoundException/import org.openbravo.database.PoolNotFoundException/g
s/import org\.openbravo\.data\.FileToDataLoader/import org.openbravo.utils.FileToDataLoader/g
s/import org\.openbravo\.data\.RDMSIndependent/import org.openbravo.database.RDMSIndependent/g
s/import org\.openbravo\.data\.StandAloneConnection/import org.openbravo.database.StandAloneConnection/g

UTF-8 support

In order to have full UTF-8 support we should do the following changes.

HTML

The HTML META tag should be the following:

<META http-equiv="Content-Type" content="text/html; charset=UTF-8">

We could use Sed again:

[/opt/AppsOpenbravo/src]$ find -type f -name "*.html" | while read file;do sed -i 's%<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">%<META http-equiv="Content-Type" content="text/html; charset=UTF-8">%g' "$file";done

XML

The XML header should be:

<?xml version="1.0" encoding="UTF-8"?>

With Sed:

[/opt/AppsOpenbravo/src]$ find -type f | while read file;do sed -i 's%<?xml version="1.0" encoding="ISO-8859-1"?>%<?xml version="1.0" encoding="UTF-8"?>%g' "$file"; done

Java

setContentType-s in java should indictate the character set:

response.setContentType("text/html")

into

response.setContentType("text/html; charset=UTF-8")


With Sed:

[/opt/AppsOpenbravo/src]$ find -type f -name "*.java" | while read file;do sed -i 's%response.setContentType("text/html")%response.setContentType("text/html; charset=UTF-8")%g' "$file"; done

File encoding

Convert all source files to UTF-8.

In case we are converting from ISO-8859-1 we could use the following bash script. It requires iconv and recode:

#!/bin/bash
CONVERT=1
echo $1
iconv -f utf8 -t utf8 "$1" > file.tmp

if [ "`diff $1 file.tmp`" = "" ];then
  echo "OK, it's UTF-8"
else
  echo "Not UTF-8 valid"
  if [ $CONVERT -eq 1 ];then
    echo "Converting..." && recode latin1..UTF-8 "$1"
  fi
fi
rm file.tmp

If we save it as utf8chk.sh, we could run it this way:

[/opt/AppsOpenbravo/src]$ find -type f | while read file;do sh utf8chk.sh "$file"; done

The javascript files should also be encoded into UTF-8.

Openbravo.properties

It's located in the config directory. It is required for the compilation and there we can define things such as the date format. In this particular case, we'd have to edit the following files:

dateFormat.js = %d-%m-%Y 
dateFormat.sql = DD-MM-YYYY 
dateFormat.java = dd-MM-yyyy 

Oracle version: we should change the NLS_DATE_FORMAT parameter in the ALTER SESSION line. PostgreSQL version: unnecessary. It is defined via the SET command (ie. SET DATESTYLE = 'nonEuropean';) In PostgreSQL also exists a function dateformat() where is specified the date format (DD-MM-YYYY by default) and it is used for cast functions.

var defaultDateFormat = "%d-%m-%Y";

Retrieved from "http://wiki.openbravo.com/wiki/How_to_migrate_code_2.2x"

This page has been accessed 2,057 times. This page was last modified 14:05, 24 September 2008. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.


Category: Development