FR [ 2042844 ] PO.get_Translation improvements

This commit is contained in:
teo_sarca 2008-08-18 08:14:01 +00:00
parent fc486133a5
commit 13e407caff
3 changed files with 47 additions and 35 deletions

View File

@ -204,7 +204,7 @@ public final class MCountry extends X_C_Country
{ {
if (m_trlName != null && s_AD_Language != null) if (m_trlName != null && s_AD_Language != null)
{ {
m_trlName = get_Translation("Name", s_AD_Language); m_trlName = get_Translation(COLUMNNAME_Name, s_AD_Language);
if (m_trlName == null) if (m_trlName == null)
s_AD_Language = null; // assume that there is no translation s_AD_Language = null; // assume that there is no translation
} }

View File

@ -219,10 +219,7 @@ public class MDocType extends X_C_DocType
{ {
if (AD_Language == null || AD_Language.length() == 0) if (AD_Language == null || AD_Language.length() == 0)
return super.getPrintName(); return super.getPrintName();
String retValue = get_Translation ("PrintName", AD_Language); return get_Translation (COLUMNNAME_PrintName, AD_Language);
if (retValue != null)
return retValue;
return super.getPrintName();
} // getPrintName } // getPrintName
/** /**

View File

@ -70,6 +70,7 @@ import org.w3c.dom.Element;
* <li>BF [ 1704828 ] PO.is_Changed() and PO.is_ValueChanged are not consistent * <li>BF [ 1704828 ] PO.is_Changed() and PO.is_ValueChanged are not consistent
* <li>FR [ 1720995 ] Add PO.saveEx() and PO.deleteEx() methods * <li>FR [ 1720995 ] Add PO.saveEx() and PO.deleteEx() methods
* <li>BF [ 1990856 ] PO.set_Value* : truncate string more than needed * <li>BF [ 1990856 ] PO.set_Value* : truncate string more than needed
* <li>FR [ 2042844 ] PO.get_Translation improvements
*/ */
public abstract class PO public abstract class PO
implements Serializable, Comparator, Evaluatee implements Serializable, Comparator, Evaluatee
@ -1760,50 +1761,64 @@ public abstract class PO
} // setAD_User_ID } // setAD_User_ID
/** /**
* Get Translation of column * Get Translation of column (if needed).
* @param columnName * It checks if the base language is used or the column is not translated.
* @param AD_Language * If there is no translation then it fallback to original value.
* @return translation or null if not found * @param columnName
* @param AD_Language
* @return translated string
* @throws IllegalArgumentException if columnName or AD_Language is null or model has multiple PK
*/ */
protected String get_Translation (String columnName, String AD_Language) public String get_Translation (String columnName, String AD_Language)
{ {
//
// Check if columnName, AD_Language is valid or table support translation (has 1 PK) => error
if (columnName == null || AD_Language == null if (columnName == null || AD_Language == null
|| m_IDs.length > 1 || m_IDs[0].equals(I_ZERO) || m_IDs.length > 1 || m_IDs[0].equals(I_ZERO)
|| !(m_IDs[0] instanceof Integer)) || !(m_IDs[0] instanceof Integer))
{ {
log.severe ("Invalid Argument: ColumnName" + columnName throw new IllegalArgumentException("ColumnName=" + columnName
+ ", AD_Language=" + AD_Language + ", AD_Language=" + AD_Language
+ ", ID.length=" + m_IDs.length + ", ID=" + m_IDs[0]); + ", ID.length=" + m_IDs.length
return null; + ", ID=" + m_IDs[0]);
} }
int ID = ((Integer)m_IDs[0]).intValue();
String retValue = null; String retValue = null;
StringBuffer sql = new StringBuffer ("SELECT ").append(columnName) //
.append(" FROM ").append(p_info.getTableName()).append("_Trl WHERE ") // Check if NOT base language and column is translated => load trl from db
.append(m_KeyColumns[0]).append("=?") if (!Env.isBaseLanguage(AD_Language, get_TableName())
.append(" AND AD_Language=?"); && p_info.isColumnTranslated(p_info.getColumnIndex(columnName))
PreparedStatement pstmt = null; )
ResultSet rs = null;
try
{ {
pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); // Load translation from database
pstmt.setInt (1, ID); int ID = ((Integer)m_IDs[0]).intValue();
pstmt.setString (2, AD_Language); StringBuffer sql = new StringBuffer ("SELECT ").append(columnName)
rs = pstmt.executeQuery (); .append(" FROM ").append(p_info.getTableName()).append("_Trl WHERE ")
if (rs.next ()) .append(m_KeyColumns[0]).append("=?")
retValue = rs.getString(1); .append(" AND AD_Language=?");
retValue = DB.getSQLValueString(get_TrxName(), sql.toString(), ID, AD_Language);
} }
catch (Exception e) //
{ // If no translation found or not translated, fallback to original:
log.log(Level.SEVERE, sql.toString(), e); if (retValue == null) {
} Object val = get_Value(columnName);
finally { retValue = (val != null ? val.toString() : null);
DB.close(rs, pstmt);
rs = null; pstmt = null;
} }
//
return retValue; return retValue;
} // get_Translation } // get_Translation
/**
* Get Translation of column
* @param ctx context
* @param columnName
* @return translation
*/
public String get_Translation (String columnName)
{
return get_Translation(columnName, Env.getAD_Language(getCtx()));
}
/** /**
* Is new record * Is new record
* @return true if new * @return true if new