Fix problems with old DataElementHandler

- NPE when the name of a record was null
- NPE when the key1name or key2name were null
- add client filter when looking for a record (it was reading records from other clients in multitenant environment)
Heng Sin, can you please review these potential errors against the structure of the new pipo2
This commit is contained in:
Carlos Ruiz 2011-02-27 00:42:44 -05:00
parent 4882320f29
commit 01a936b63f
1 changed files with 5 additions and 4 deletions

View File

@ -106,7 +106,7 @@ public class DataElementHandler extends AbstractElementHandler {
String d_rowname = atts.getValue("name"); String d_rowname = atts.getValue("name");
// name can be null if there are keyXname attributes. // name can be null if there are keyXname attributes.
if (!d_rowname.equals("")){ if (d_rowname != null && !d_rowname.equals("")){
int id = get_ID(ctx, d_tablename, d_rowname); int id = get_ID(ctx, d_tablename, d_rowname);
genericPO = table.getPO(id, getTrxName(ctx)); genericPO = table.getPO(id, getTrxName(ctx));
if (id > 0){ if (id > 0){
@ -136,6 +136,7 @@ public class DataElementHandler extends AbstractElementHandler {
} }
if (whereand.equals(" where")) if (whereand.equals(" where"))
log.warning("no name or keyXname attribute defined."); log.warning("no name or keyXname attribute defined.");
sql = sql+whereand+" AD_Client_ID="+getClientId(ctx);
// Load GenericPO from rs, in fact ID could not exist e.g. Attribute Value // Load GenericPO from rs, in fact ID could not exist e.g. Attribute Value
try { try {
PreparedStatement pstmt = DB.prepareStatement(sql, getTrxName(ctx)); PreparedStatement pstmt = DB.prepareStatement(sql, getTrxName(ctx));
@ -157,7 +158,7 @@ public class DataElementHandler extends AbstractElementHandler {
genericPO = table.getPO(0, getTrxName(ctx)); genericPO = table.getPO(0, getTrxName(ctx));
// set keyXname. // set keyXname.
CURRENT_KEY = "key1name"; CURRENT_KEY = "key1name";
if (!atts.getValue(CURRENT_KEY).equals("")) { if (atts.getValue(CURRENT_KEY) != null && !atts.getValue(CURRENT_KEY).equals("")) {
String colName = atts.getValue(CURRENT_KEY); String colName = atts.getValue(CURRENT_KEY);
String valueObject = atts.getValue("lookup"+CURRENT_KEY); String valueObject = atts.getValue("lookup"+CURRENT_KEY);
if (colName.endsWith("_ID") && valueObject.contains("SELECT")) if (colName.endsWith("_ID") && valueObject.contains("SELECT"))
@ -165,7 +166,7 @@ public class DataElementHandler extends AbstractElementHandler {
genericPO.set_ValueOfColumn(colName, valueObject); genericPO.set_ValueOfColumn(colName, valueObject);
} }
CURRENT_KEY = "key2name"; CURRENT_KEY = "key2name";
if (!atts.getValue(CURRENT_KEY).equals("")) { if (atts.getValue(CURRENT_KEY) != null && !atts.getValue(CURRENT_KEY).equals("")) {
String colName = atts.getValue(CURRENT_KEY); String colName = atts.getValue(CURRENT_KEY);
String valueObject = atts.getValue("lookup"+CURRENT_KEY); String valueObject = atts.getValue("lookup"+CURRENT_KEY);
if (colName.endsWith("_ID") && valueObject.contains("SELECT")) if (colName.endsWith("_ID") && valueObject.contains("SELECT"))
@ -194,7 +195,7 @@ public class DataElementHandler extends AbstractElementHandler {
if (getClientId(ctx) > 0 && genericPO.getAD_Client_ID() != getClientId(ctx)) if (getClientId(ctx) > 0 && genericPO.getAD_Client_ID() != getClientId(ctx))
genericPO.set_ValueOfColumn("AD_Client_ID", getClientId(ctx)); genericPO.set_ValueOfColumn("AD_Client_ID", getClientId(ctx));
// if new. TODO: no defaults for keyXname. // if new. TODO: no defaults for keyXname.
if (!d_rowname.equals("") && ((Integer)(genericPO.get_Value(d_tablename+"_ID"))).intValue() == 0) { if (d_rowname != null && !d_rowname.equals("") && ((Integer)(genericPO.get_Value(d_tablename+"_ID"))).intValue() == 0) {
log.info("new genericPO, table: "+d_tablename+" name:"+d_rowname); log.info("new genericPO, table: "+d_tablename+" name:"+d_rowname);
genericPO.set_ValueOfColumn("Name", d_rowname); genericPO.set_ValueOfColumn("Name", d_rowname);
// Set defaults. // Set defaults.