* more robust support for ad_client_id and ad_org_id.

* fixed bug for official id and uuid support.
This commit is contained in:
Heng Sin Low 2010-07-27 11:58:15 +08:00
parent 1e4cdbf1eb
commit ffcbd20aaa
3 changed files with 32 additions and 42 deletions

View File

@ -7,6 +7,8 @@ import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.I_AD_Client;
import org.compiere.model.I_AD_Org;
import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.model.POInfo;
@ -190,8 +192,10 @@ public class PoExporter {
{
if (!preservedOrg)
addString("AD_Org_ID", "@AD_Org_ID@", new AttributesImpl());
else
addTableReference("AD_Org", "Value", new AttributesImpl());
else {
addTableReference(I_AD_Client.Table_Name, I_AD_Client.COLUMNNAME_Value, new AttributesImpl());
addTableReference(I_AD_Org.Table_Name, I_AD_Org.COLUMNNAME_Value, new AttributesImpl());
}
}
}

View File

@ -138,54 +138,26 @@ public class PoFiller{
Element e = element.properties.get(qName);
if (e == null)
return 0;
String value = e.contents.toString();
String reference = e.attributes.getValue("reference");
String referenceKey = e.attributes.getValue("reference-key");
String columnName = qName;
if (value != null && value.trim().length() > 0)
{
if ("table".equals(reference))
{
String[] names = referenceKey.split("[.]");
if (names.length < 2)
return 0;
if (po.get_ColumnIndex(columnName) >= 0) {
String tableName = names[0];
String searchColumn = names[1];
int id = handler.findIdByColumn(po.getCtx(), tableName, searchColumn, value.trim());
if (id > 0) {
po.set_ValueOfColumn(columnName, id);
return id;
}
if (value != null && value.trim().length() > 0) {
int id = ReferenceUtils.resolveReference(ctx, e);
if (columnName.equals("AD_Client_ID") && id > 0) {
if (id != Env.getAD_Client_ID(ctx)) {
return -1;
} else {
return 0;
}
}
else if ("id".equals(reference))
{
int id = Integer.parseInt(value);
po.set_ValueOfColumn(e.getElementValue(), id);
return id;
}
else if ("uuid".equals(reference))
{
int id = handler.findIdByColumn(po.getCtx(), referenceKey, referenceKey + "_UU", value.trim());
if (po.get_ColumnIndex(columnName) >= 0) {
if (id > 0) {
po.set_ValueOfColumn(columnName, id);
return id;
}
return -1;
return -1;
} else {
return 0;
}
else
{
throw new IllegalArgumentException("Unknown table reference type="+reference);
}
}
else
{
} else {
return 0;
}
}
@ -205,8 +177,10 @@ public class PoFiller{
po.setAD_Org_ID(0);
else if (sAD_Org_ID != null && sAD_Org_ID.equals("@AD_Org_ID@"))
po.setAD_Org_ID(Env.getAD_Org_ID(ctx));
else
setTableReference("AD_Org.Value");
else {
if (setTableReference("AD_Client_ID") >= 0)
setTableReference("AD_Org_ID");
}
for(String qName : element.properties.keySet()) {
if (excludes != null ){

View File

@ -110,6 +110,18 @@ public class GenericPOElementHandler extends AbstractElementHandler implements I
}
PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> excludes = defaultExcludeList(tableName);
if (po.get_ID() == 0) {
Element idElement = element.properties.get(tableName + "_ID");
if (idElement != null && idElement.contents != null && idElement.contents.length() > 0) {
int id = 0;
try {
id = Integer.parseInt(idElement.contents.toString());
if (id > 0 && id <= PackOut.MAX_OFFICIAL_ID) {
po.set_ValueOfColumn(tableName + "_ID", id);
}
} catch (Exception e) {}
}
}
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;