IDEMPIERE-1297 2Pack: Remove code for the lookup of record and reference using business key.

This commit is contained in:
Heng Sin Low 2013-08-23 14:23:45 +08:00
parent 363b1be214
commit f724aa2656
46 changed files with 250 additions and 1615 deletions

View File

@ -50,21 +50,14 @@ public class AdElementHandler extends AbstractElementHandler {
String action = null;
String entitytype = getStringValue(element, "EntityType");
String ColumnName = getStringValue(element, "ColumnName");
if (isProcessElement(ctx.ctx, entitytype)) {
M_Element mElement = findPO(ctx, element);
if (mElement == null) {
int id = 0;
if (!hasUUIDKey(ctx, element)) {
id = findIdByColumn(ctx, X_AD_Element.Table_Name, X_AD_Element.COLUMNNAME_ColumnName, ColumnName, /*ignorecase=*/true);
}
mElement = new M_Element(ctx.ctx, id, getTrxName(ctx));
mElement = new M_Element(ctx.ctx, 0, getTrxName(ctx));
}
List<String> excludes = defaultExcludeList(X_AD_Element.Table_Name);
if (mElement.getAD_Element_ID() == 0 && isOfficialId(element, "AD_Element_ID"))
mElement.setAD_Element_ID(getIntValue(element, "AD_Element_ID"));
if (processedElements.contains(mElement.getAD_Element_ID())) {
element.skip = true;
@ -123,6 +116,8 @@ public class AdElementHandler extends AbstractElementHandler {
return;
}
}
verifyPackOutRequirement(mAdElement);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");

View File

@ -27,14 +27,12 @@ import org.adempiere.pipo2.PIPOContext;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.MAttachment;
import org.compiere.model.PO;
import org.compiere.model.X_AD_Attachment;
import org.compiere.model.X_AD_AttachmentNote;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -49,35 +47,9 @@ public class AttachmentElementHandler extends AbstractElementHandler {
MAttachment mAttachment = findPO(ctx, element);
if (mAttachment == null) {
int AD_Table_ID = ReferenceUtils.resolveReference(ctx.ctx, element.properties.get("AD_Table_ID"), getTrxName(ctx));
if (AD_Table_ID <= 0) {
element.defer = true;
element.unresolved = "AD_Table_ID";
return;
}
Element recordElement = element.properties.get("Record_ID");
int Record_ID = ReferenceUtils.resolveReference(ctx.ctx, recordElement, getTrxName(ctx));
if (Record_ID <= 0) {
element.defer = true;
element.unresolved = "Record_ID";
return;
}
int id = 0;
if (!hasUUIDKey(ctx, element)) {
DB.getSQLValue(getTrxName(ctx), "SELECT AD_Attachment_ID FROM AD_Attachment WHERE Record_ID="+Record_ID+" AND AD_Table_ID="+AD_Table_ID);
}
mAttachment = new MAttachment(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
if (mAttachment.is_new()) {
mAttachment.setAD_Table_ID(AD_Table_ID);
mAttachment.setRecord_ID(Record_ID);
}
mAttachment = new MAttachment(ctx.ctx, 0, getTrxName(ctx));
}
List<String> excludes = defaultExcludeList(X_AD_Attachment.Table_Name);
excludes.add("AD_Table_ID");
excludes.add("Record_ID");
if (mAttachment.getAD_Attachment_ID() == 0 && isOfficialId(element, "AD_Attachment_ID"))
mAttachment.setAD_Attachment_ID(getIntValue(element, "AD_Attachment_ID"));
if (attachments.contains(mAttachment.getAD_Attachment_ID())) {
element.skip = true;
@ -137,6 +109,8 @@ public class AttachmentElementHandler extends AbstractElementHandler {
}
}
verifyPackOutRequirement(mAttachment);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", "AD_Attachment", atts);

View File

@ -64,23 +64,7 @@ public class ColumnElementHandler extends AbstractElementHandler {
MColumn mColumn = findPO(ctx, element);
if (mColumn == null) {
int tableid = 0;
if (getParentId(element, I_AD_Table.Table_Name) > 0) {
tableid = getParentId(element, I_AD_Table.Table_Name);
} else {
mColumn = new MColumn(ctx.ctx, 0, getTrxName(ctx));
PoFiller filler = new PoFiller(ctx, mColumn, element, this);
filler.setTableReference("AD_Table_ID");
tableid = mColumn.getAD_Table_ID();
}
int AD_Column_ID = 0;
if (!hasUUIDKey(ctx, element)) {
AD_Column_ID = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnName, "AD_Table", tableid, /*ignorecase=*/true);
}
mColumn = new MColumn(ctx.ctx, AD_Column_ID > 0 ? AD_Column_ID : 0, getTrxName(ctx));
if (mColumn.getAD_Column_ID() == 0 && isOfficialId(element, "AD_Column_ID")) {
mColumn.setAD_Column_ID(getIntValue(element, "AD_Column_ID"));
}
mColumn = new MColumn(ctx.ctx, 0, getTrxName(ctx));
}
mColumn.setColumnName(columnName);
@ -310,6 +294,8 @@ public class ColumnElementHandler extends AbstractElementHandler {
}
}
verifyPackOutRequirement(m_Column);
addTypeName(atts, "table");
document.startElement("", "", I_AD_Column.Table_Name, atts);
createColumnBinding(ctx, document, m_Column);
@ -327,7 +313,7 @@ public class ColumnElementHandler extends AbstractElementHandler {
filler.addString("IsSyncDatabase", "Y", new AttributesImpl());
filler.addTableReference("AD_Table", "TableName", new AttributesImpl());
filler.addTableReference("AD_Reference_Value_ID", "AD_Reference", "Name", new AttributesImpl());
filler.addTableReference("AD_Reference_Value_ID", "AD_Reference", new AttributesImpl());
excludes.add("IsSyncDatabase");
excludes.add("AD_Table_ID");

View File

@ -40,19 +40,11 @@ public class DynValRuleElementHandler extends AbstractElementHandler {
public void startElement(PIPOContext ctx, Element element) throws SAXException {
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx.ctx, entitytype)) {
String name = getStringValue(element, "Name");
X_AD_Val_Rule mValRule = findPO(ctx, element);
if (mValRule == null)
{
int id = 0;
if (!hasUUIDKey(ctx, element)) {
id = findIdByColumn(ctx, "AD_Val_Rule", "Name", name);
}
mValRule = new X_AD_Val_Rule(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
mValRule = new X_AD_Val_Rule(ctx.ctx, 0, getTrxName(ctx));
}
if (mValRule.getAD_Val_Rule_ID() == 0 && isOfficialId(element, "AD_Val_Rule_ID"))
mValRule.setAD_Val_Rule_ID(getIntValue(element, "AD_Val_Rule_ID"));
List<String> excludes = defaultExcludeList(X_AD_Val_Rule.Table_Name);
@ -106,6 +98,8 @@ public class DynValRuleElementHandler extends AbstractElementHandler {
}
}
verifyPackOutRequirement(m_ValRule);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("","",I_AD_Val_Rule.Table_Name, atts);

View File

@ -55,22 +55,14 @@ public class EntityTypeElementHandler extends AbstractElementHandler{
List<String> excludes = defaultExcludeList(X_AD_EntityType.Table_Name);
String entitytype = getStringValue(element, "EntityType");
String name = getStringValue(element, "Name");
String action = null;
if (isProcessElement(ctx.ctx, entitytype)) {
X_AD_EntityType m_EntityType = findPO(ctx, element);
if (m_EntityType == null) {
int id = 0;
if (!hasUUIDKey(ctx, element)) {
id = findIdByColumn(ctx, X_AD_EntityType.Table_Name, X_AD_EntityType.COLUMNNAME_Name, name, /*ignorecase=*/true);
}
m_EntityType = new X_AD_EntityType(ctx.ctx, id, getTrxName(ctx));
m_EntityType = new X_AD_EntityType(ctx.ctx, 0, getTrxName(ctx));
}
if (m_EntityType.getAD_EntityType_ID() == 0 && isOfficialId(element, "AD_EntityType_ID"))
m_EntityType.setAD_EntityType_ID(getIntValue(element, "AD_EntityType_ID"));
if (entityTypes.contains(m_EntityType.getAD_EntityType_ID())) {
element.skip = true;
return;
@ -134,6 +126,7 @@ public class EntityTypeElementHandler extends AbstractElementHandler{
}
if(createElement){
verifyPackOutRequirement(m_EntityType);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", X_AD_EntityType.Table_Name, atts);

View File

@ -28,7 +28,6 @@ import org.adempiere.pipo2.PIPOContext;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Field;
import org.compiere.model.I_AD_FieldGroup;
@ -37,7 +36,6 @@ import org.compiere.model.I_AD_Tab;
import org.compiere.model.MField;
import org.compiere.model.X_AD_Field;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -54,81 +52,14 @@ public class FieldElementHandler extends AbstractElementHandler {
}
List<String>excludes = defaultExcludeList(X_AD_Field.Table_Name);
excludes.add("AD_Window_ID");
excludes.add("AD_Tab_ID");
int tabid = getParentId(element, I_AD_Tab.Table_Name) ;
if (tabid <= 0) {
Element tabElement = element.properties.get("AD_Tab_ID");
if (ReferenceUtils.isIDLookup(tabElement) || ReferenceUtils.isUUIDLookup(tabElement)) {
tabid = ReferenceUtils.resolveReference(ctx.ctx, tabElement, getTrxName(ctx));
} else {
String tabName = getStringValue(element, "AD_Tab_ID");
int AD_Window_ID = ReferenceUtils.resolveReference(ctx.ctx, element.properties.get("AD_Window_ID"), getTrxName(ctx));
if (AD_Window_ID > 0) {
tabid = findIdByNameAndParentId(ctx, "AD_Tab", tabName, "AD_Window", AD_Window_ID);
}
}
}
if (tabid <= 0) {
element.defer = true;
element.unresolved = "AD_Tab_ID";
return;
}
excludes.add("AD_Table_ID");
excludes.add("AD_Column_ID");
int AD_Table_ID = ReferenceUtils.resolveReference(ctx.ctx, element.properties.get("AD_Table_ID"), getTrxName(ctx));
Element columnElement = element.properties.get("AD_Column_ID");
int AD_Column_ID = 0;
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement))
{
AD_Column_ID = ReferenceUtils.resolveReference(ctx.ctx, columnElement, getTrxName(ctx));
}
else
{
String colname = getStringValue(element, "AD_Column_ID", excludes);
AD_Column_ID = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", colname, "AD_Table", AD_Table_ID);
}
if (AD_Column_ID == 0) {
element.defer = true;
element.unresolved = "AD_Column_ID";
return;
}
MField mField = findPO(ctx, element);
if (mField == null)
{
int id = 0;
if (!hasUUIDKey(ctx, element)) {
StringBuffer sqlB = new StringBuffer(
"select AD_Field_ID from AD_Field where AD_Column_ID = ")
.append(AD_Column_ID)
.append(" and AD_Tab_ID = ?");
id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), tabid);
}
mField = new MField(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
if (mField.is_new()) {
mField.setAD_Column_ID(AD_Column_ID);
mField.setAD_Tab_ID(tabid);
}
} else {
if (mField.getAD_Tab_ID() != tabid) {
mField.setAD_Tab_ID(tabid);
}
if (mField.getAD_Column_ID() != AD_Column_ID) {
mField.setAD_Column_ID(AD_Column_ID);
}
}
mField = new MField(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mField, element, this);
if (mField.getAD_Field_ID() == 0 && isOfficialId(element, "AD_Field_ID"))
{
filler.setInteger("AD_Field_ID");
}
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
@ -191,9 +122,9 @@ public class FieldElementHandler extends AbstractElementHandler {
}
}
catch(Exception e)
{
{
throw new SAXException(e);
}
}
if (ctx.packOut.getFromDate() != null) {
if (m_Field.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) {
@ -201,6 +132,8 @@ public class FieldElementHandler extends AbstractElementHandler {
}
}
verifyPackOutRequirement(m_Field);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", X_AD_Field.Table_Name, atts);
@ -224,20 +157,6 @@ public class FieldElementHandler extends AbstractElementHandler {
filler.add("AD_Field_ID", new AttributesImpl());
}
int AD_Table_ID = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?", m_Field.getAD_Column_ID());
if (AD_Table_ID > 0) {
AttributesImpl atts = new AttributesImpl();
filler.addTableReference("AD_Table_ID", "AD_Table", "TableName", AD_Table_ID, atts);
}
excludes.add("AD_Tab_ID");
AttributesImpl atts = new AttributesImpl();
filler.addTableReference("AD_Tab_ID", "AD_Tab", "Name", m_Field.getAD_Tab_ID(), atts);
if (atts.getValue("reference").equals("table")) {
int AD_Window_ID = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Window_ID FROM AD_Tab WHERE AD_Tab_ID=?", m_Field.getAD_Tab_ID());
filler.addTableReference("AD_Window_ID", "AD_Window", "Name", AD_Window_ID, new AttributesImpl());
}
filler.export(excludes);
}

View File

@ -51,26 +51,16 @@ public class FieldGroupElementHandler extends AbstractElementHandler {
if (log.isLoggable(Level.INFO)) log.info(elementValue + " " + getStringValue(element, "Name"));
String entitytype = getStringValue(element, "EntityType");
String name = getStringValue(element, "Name");
if (isProcessElement(ctx.ctx, entitytype)) {
X_AD_FieldGroup fieldGroup = findPO(ctx, element);
if (fieldGroup == null)
{
int id = 0;
if (!hasUUIDKey(ctx, element)) {
id = findIdByColumn(ctx, X_AD_FieldGroup.Table_Name, X_AD_FieldGroup.COLUMNNAME_Name, name);
}
fieldGroup = new X_AD_FieldGroup(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
fieldGroup = new X_AD_FieldGroup(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller pf = new PoFiller(ctx, fieldGroup, element, this);
List<String> excludes = defaultExcludeList(X_AD_FieldGroup.Table_Name);
if (fieldGroup.getAD_FieldGroup_ID() == 0 && isOfficialId(element, "AD_FieldGroup_ID"))
{
pf.setInteger("AD_FieldGroup_ID");
}
if (processedFieldGroups.contains(fieldGroup.getAD_FieldGroup_ID())) {
element.skip = true;
return;
@ -132,6 +122,8 @@ public class FieldGroupElementHandler extends AbstractElementHandler {
}
}
verifyPackOutRequirement(fieldGroup);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", I_AD_FieldGroup.Table_Name, atts);

View File

@ -26,9 +26,7 @@ import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_Form_Access;
import org.compiere.model.I_AD_Role;
import org.compiere.model.MFormAccess;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Form;
@ -45,42 +43,7 @@ public class FormAccessElementHandler extends AbstractElementHandler {
MFormAccess po = findPO(ctx, element);
if (po == null) {
int AD_Role_ID = 0;
if (getParentId(element, I_AD_Role.Table_Name) > 0) {
AD_Role_ID = getParentId(element, I_AD_Role.Table_Name);
} else {
AD_Role_ID = ReferenceUtils.resolveReference(ctx.ctx, element.properties.get("AD_Role_ID"), getTrxName(ctx));
}
if (AD_Role_ID <= 0)
{
element.defer = true;
element.unresolved = "AD_Role_ID";
return;
}
int AD_Form_ID = ReferenceUtils.resolveReference(ctx.ctx, element.properties.get("AD_Form_ID"), getTrxName(ctx));
if (AD_Form_ID <= 0)
{
element.defer = true;
element.unresolved = "AD_Form_ID";
return;
}
if (!hasUUIDKey(ctx, element)) {
Query query = new Query(ctx.ctx, "AD_Form_Access", "AD_Form_ID = ? AND AD_Role_ID = ?", getTrxName(ctx));
po = query.setParameters(new Object[]{AD_Form_ID, AD_Role_ID})
.setClient_ID()
.<MFormAccess>first();
}
if (po == null)
{
po = new MFormAccess(ctx.ctx, 0, getTrxName(ctx));
po.setAD_Form_ID(AD_Form_ID);
po.setAD_Role_ID(AD_Role_ID);
}
excludes.add("AD_Form_ID");
excludes.add("AD_Role_ID");
po = new MFormAccess(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, po, element, this);
@ -113,6 +76,8 @@ public class FormAccessElementHandler extends AbstractElementHandler {
}
}
verifyPackOutRequirement(po);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Form_Access.Table_Name, atts);

View File

@ -47,20 +47,9 @@ public class FormElementHandler extends AbstractElementHandler {
if (isProcessElement(ctx.ctx, entitytype)) {
MForm mForm = findPO(ctx, element);
if (mForm == null) {
String name = getStringValue(element, "Name");
int id = 0;
if (!hasUUIDKey(ctx, element)) {
id = findIdByName(ctx, "AD_Form", name);
}
mForm = new MForm(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
mForm = new MForm(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mForm, element, this);
if (mForm.getAD_Form_ID() == 0 && isOfficialId(element, "AD_Form_ID"))
{
filler.setInteger("AD_Form_ID");
}
PoFiller filler = new PoFiller(ctx, mForm, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
@ -111,6 +100,8 @@ public class FormElementHandler extends AbstractElementHandler {
}
}
verifyPackOutRequirement(m_Form);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("","",I_AD_Form.Table_Name,atts);

View File

@ -19,7 +19,6 @@ package org.adempiere.pipo2.handler;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
@ -36,15 +35,10 @@ import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.MColumn;
import org.compiere.model.MRole;
import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.model.POInfo;
import org.compiere.model.Query;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -71,117 +65,11 @@ public class GenericPOElementHandler extends AbstractElementHandler {
PO po = findPO(ctx, element);
if (po == null) {
String uuidColumn = PO.getUUIDColumnName(tableName);
String idColumn = tableName + "_ID";
MTable table = MTable.get(ctx.ctx, tableName);
if ((!element.properties.containsKey(uuidColumn) || element.properties.get(uuidColumn).contents == null || element.properties.get(uuidColumn).contents.toString().trim().length() == 0)
&& (!element.properties.containsKey(idColumn) || element.properties.get(idColumn).contents == null || element.properties.get(idColumn).contents.toString().trim().length() == 0)) {
POInfo info = POInfo.getPOInfo(ctx.ctx, table.getAD_Table_ID());
MColumn columns[] = table.getColumns(false);
StringBuilder whereClause = new StringBuilder();
List<Object> parameters = new ArrayList<Object>();
boolean search = true;
for(int i = 0; i < columns.length; i++) {
MColumn column = columns[i];
if (column.isParent()) {
int parentId = 0;
String parentTableName = null;
if (column.getAD_Reference_ID() == DisplayType.TableDir) {
parentTableName = column.getColumnName().substring(0, column.getColumnName().length() - 3);
} else {
String searchColumn = info.getColumnLookup(i).getColumnName();
parentTableName = searchColumn.substring(0, searchColumn.indexOf("."));
}
Element parent = element.parent;
while (parent != null) {
if (parent.getElementValue().equalsIgnoreCase(parentTableName)) {
parentId = parent.recordId;
break;
}
parent = parent.parent;
}
if (parentId == 0) {
Element parentElement = element.properties.get(column.getColumnName());
if (parentElement != null) {
parentId = ReferenceUtils.resolveReference(ctx.ctx, parentElement, getTrxName(ctx));
}
}
if (parentId > 0) {
if (whereClause.length() > 0)
whereClause.append(" AND ");
whereClause.append(column.getColumnName()).append(" = ?");
parameters.add(parentId);
} else {
search = false;
break;
}
} else if (column.isIdentifier()) {
if (whereClause.length() > 0)
whereClause.append(" AND ");
whereClause.append(column.getColumnName()).append(" = ? ");
String refTableName = null;
if (column.getAD_Reference_ID() == DisplayType.TableDir) {
refTableName = column.getColumnName().substring(0, column.getColumnName().length() - 3);
} else if (column.getAD_Reference_ID() == DisplayType.Table ||
column.getAD_Reference_ID() == DisplayType.Search) {
String searchColumn = info.getColumnLookup(i).getColumnName();
refTableName = searchColumn.substring(0, searchColumn.indexOf("."));
}
if (refTableName == null) {
parameters.add(getStringValue(element, column.getColumnName()));
} else {
int refId = 0;
Element parent = element.parent;
while (parent != null) {
if (parent.getElementValue().equalsIgnoreCase(refTableName)) {
refId = parent.recordId;
break;
}
parent = parent.parent;
}
if (refId == 0) {
Element refElement = element.properties.get(column.getColumnName());
if (refElement != null) {
refId = ReferenceUtils.resolveReference(ctx.ctx, refElement, getTrxName(ctx));
}
}
if (refId > 0) {
parameters.add(refId);
} else {
search = false;
break;
}
}
}
}
if (whereClause.length() > 0 && search) {
Query query = new Query(ctx.ctx, table, whereClause.toString(), getTrxName(ctx));
po = query.setParameters(parameters).setApplyAccessFilter(true).first();
}
}
if (po == null) {
po = table.getPO(0, getTrxName(ctx));
}
po = table.getPO(0, getTrxName(ctx));
}
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_ValueNoCheck(tableName + "_ID", id);
}
} catch (Exception e) {}
}
}
List<String> notfounds = filler.autoFill(excludes);
/* Verify if the table has entitytype and check dictionary maintenance */
int idxet = po.get_ColumnIndex("EntityType");
@ -248,13 +136,11 @@ public class GenericPOElementHandler extends AbstractElementHandler {
}
}
if (createElement) {
verifyPackOutRequirement(po);
addTypeName(atts, "table");
document.startElement("","", tableName, atts);
PoExporter filler = new PoExporter(ctx, document, po);
filler.export(excludes, true);
if (po.get_ID() > 0 && po.get_ID() < 1000000) {
filler.add(tableName+"_ID", new AttributesImpl());
}
}
}
@ -306,6 +192,7 @@ public class GenericPOElementHandler extends AbstractElementHandler {
}
}
if (createElement) {
verifyPackOutRequirement(po);
List<String> excludes = defaultExcludeList(tables[index]);
addTypeName(atts, "table");
document.startElement("", "", tables[index], atts);

View File

@ -49,24 +49,12 @@ public class ImpFormatElementHandler extends AbstractElementHandler {
throws SAXException {
List<String> excludes = defaultExcludeList(X_AD_ImpFormat.Table_Name);
String name = getStringValue(element, "Name");
X_AD_ImpFormat mImpFormat = findPO(ctx, element);
if (mImpFormat == null) {
int id = 0;
if (!hasUUIDKey(ctx, element)) {
id = findIdByName(ctx, "AD_ImpFormat", name);
}
mImpFormat = new X_AD_ImpFormat(ctx.ctx, id > 0 ? id : 0,
getTrxName(ctx));
mImpFormat = new X_AD_ImpFormat(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mImpFormat, element, this);
if (mImpFormat.getAD_ImpFormat_ID() == 0 && isOfficialId(element, "AD_ImpFormat_ID"))
{
filler.setInteger("AD_ImpFormat_ID");
}
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
@ -116,6 +104,7 @@ public class ImpFormatElementHandler extends AbstractElementHandler {
}
if (createElement) {
verifyPackOutRequirement(m_ImpFormat);
addTypeName(atts, "table");
document.startElement("", "", I_AD_ImpFormat.Table_Name, atts);
createImpFormatBinding(ctx, document, m_ImpFormat);

View File

@ -26,13 +26,11 @@ import org.adempiere.pipo2.PIPOContext;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_ImpFormat;
import org.compiere.model.I_AD_ImpFormat_Row;
import org.compiere.model.X_AD_ImpFormat_Row;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -51,73 +49,9 @@ public class ImpFormatRowElementHandler extends AbstractElementHandler {
X_AD_ImpFormat_Row mImpFormatRow = findPO(ctx, element);
if (mImpFormatRow == null) {
int impFormatId = 0;
if (getParentId(element, I_AD_ImpFormat.Table_Name) > 0) {
impFormatId = getParentId(element, I_AD_ImpFormat.Table_Name);
} else {
Element e = element.properties.get(I_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_ID);
if (ReferenceUtils.isIDLookup(e) || ReferenceUtils.isUUIDLookup(e))
impFormatId = ReferenceUtils.resolveReference(ctx.ctx, e, getTrxName(ctx));
else
impFormatId = findIdByName(ctx, "AD_ImpFormat", e.contents.toString());
}
if (impFormatId <= 0) {
element.defer = true;
element.unresolved = "AD_ImpFormat_ID";
return;
}
Element tableElement = element.properties.get(I_AD_ImpFormat.COLUMNNAME_AD_Table_ID);
int tableId = 0;
if (ReferenceUtils.isIDLookup(tableElement) || ReferenceUtils.isUUIDLookup(tableElement)) {
tableId = ReferenceUtils.resolveReference(ctx.ctx, tableElement, getTrxName(ctx));
} else {
String tableName = getStringValue(element, I_AD_ImpFormat.COLUMNNAME_AD_Table_ID, excludes);
if (tableName != null && tableName.trim().length() > 0) {
tableId = findIdByColumn(ctx, "AD_Table", "TableName", tableName);
}
if (tableId <= 0) {
element.defer = true;
element.unresolved = "AD_Table_ID";
return;
}
}
Element columnElement = element.properties.get(I_AD_ImpFormat_Row.COLUMNNAME_AD_Column_ID);
int columnId = 0;
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) {
columnId = ReferenceUtils.resolveReference(ctx.ctx, columnElement, getTrxName(ctx));
} else {
String columnName = getStringValue(element, I_AD_ImpFormat_Row.COLUMNNAME_AD_Column_ID, excludes);
if (columnName != null && columnName.trim().length() > 0) {
columnId = findIdByColumnAndParentId (ctx, "AD_Column","ColumnName", columnName, "AD_Table", tableId);
}
if (columnId <= 0) {
element.defer = true;
element.unresolved = "AD_Column_ID";
return;
}
}
int id = 0;
if (!hasUUIDKey(ctx, element)) {
StringBuilder sqlB = new StringBuilder ("SELECT AD_ImpFormat_Row_ID FROM AD_ImpFormat_Row WHERE AD_Column_ID=? AND AD_ImpFormat_ID=?");
id = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),columnId,impFormatId);
}
mImpFormatRow = new X_AD_ImpFormat_Row(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
mImpFormatRow.setAD_Column_ID(columnId);
mImpFormatRow.setAD_ImpFormat_ID(impFormatId);
mImpFormatRow = new X_AD_ImpFormat_Row(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mImpFormatRow, element, this);
if (mImpFormatRow.getAD_ImpFormat_Row_ID() == 0 && isOfficialId(element, "AD_ImpFormat_Row_ID"))
{
filler.setInteger("AD_ImpFormat_Row_ID");
}
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
@ -162,6 +96,8 @@ public class ImpFormatRowElementHandler extends AbstractElementHandler {
}
}
verifyPackOutRequirement(m_ImpFormat_Row);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("","",I_AD_ImpFormat_Row.Table_Name,atts);
@ -174,11 +110,6 @@ public class ImpFormatRowElementHandler extends AbstractElementHandler {
PoExporter filler = new PoExporter(ctx, document, m_ImpFormat_Row);
List<String> excludes = defaultExcludeList(X_AD_ImpFormat_Row.Table_Name);
String sql = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?";
int tableId = DB.getSQLValue(null, sql,m_ImpFormat_Row.getAD_Column_ID());
filler.addTableReference("AD_Table_ID", "AD_Table", "TableName", tableId, new AttributesImpl());
if (m_ImpFormat_Row.getAD_ImpFormat_Row_ID() <= PackOut.MAX_OFFICIAL_ID)
{
filler.add("AD_ImpFormat_Row_ID", new AttributesImpl());

View File

@ -59,20 +59,9 @@ public class MenuElementHandler extends AbstractElementHandler {
X_AD_Menu mMenu = findPO(ctx, element);
if (mMenu == null) {
int menuId = 0;
if (!hasUUIDKey(ctx, element)) {
String menuName = getStringValue(element, "Name");
menuId = findIdByColumn(ctx, "AD_Menu", "Name", menuName);
}
mMenu = new X_AD_Menu(ctx.ctx, menuId > 0 ? menuId : 0, getTrxName(ctx));
mMenu = new X_AD_Menu(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mMenu, element, this);
if (mMenu.getAD_Menu_ID() == 0 && isOfficialId(element, "AD_Menu_ID"))
{
filler.setInteger("AD_Menu_ID");
}
List<String> notFounds = filler.autoFill(excludes);
if (notFounds.size() > 0) {
element.defer = true;
@ -112,86 +101,83 @@ public class MenuElementHandler extends AbstractElementHandler {
Element parentElement = element.properties.get("Parent_ID");
int parentId = 0;
if (parentElement != null) {
if (ReferenceUtils.isIDLookup(parentElement) || ReferenceUtils.isUUIDLookup(parentElement)) {
parentId = ReferenceUtils.resolveReference(ctx.ctx, parentElement, getTrxName(ctx));
} else {
String parent = getStringValue(element, "Parent_ID");
parentId = findIdByName(ctx, "AD_Menu", parent);
}
parentId = ReferenceUtils.resolveReference(ctx.ctx, parentElement, getTrxName(ctx));
}
StringBuffer updateSQL = null;
int AD_Tree_ID = getDefaultMenuTreeId();
String sql = "SELECT count(Parent_ID) FROM AD_TREENODEMM WHERE AD_Tree_ID = "+AD_Tree_ID
+ " AND Node_ID = " + mMenu.getAD_Menu_ID();
int countRecords = DB.getSQLValue(getTrxName(ctx), sql);
if (countRecords > 0) {
sql = "select * from AD_TREENODEMM where AD_Tree_ID = "+AD_Tree_ID+" and "
+ " Node_ID =?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql,
getTrxName(ctx));
pstmt.setInt(1, mMenu.getAD_Menu_ID());
rs = pstmt.executeQuery();
if (rs.next()) {
String colValue = null;
ResultSetMetaData meta = rs.getMetaData();
int columns = meta.getColumnCount();
int tableID = X_AD_TreeNodeMM.Table_ID;
for (int q = 1; q <= columns; q++) {
String colName = meta.getColumnName(q).toUpperCase();
sql = "SELECT AD_Column_ID FROM AD_column WHERE Upper(ColumnName) = ? AND AD_Table_ID = ?";
int columnID = DB.getSQLValue(getTrxName(ctx), sql, colName, tableID);
sql = "SELECT AD_Reference_ID FROM AD_COLUMN WHERE AD_Column_ID = ?";
int referenceID = DB.getSQLValue(getTrxName(ctx), sql, columnID);
if (referenceID == 20 || referenceID == 28)
if (rs.getObject(q).equals("Y"))
colValue = "true";
if (parentId > 0) {
StringBuffer updateSQL = null;
int AD_Tree_ID = getDefaultMenuTreeId();
String sql = "SELECT count(Parent_ID) FROM AD_TREENODEMM WHERE AD_Tree_ID = "+AD_Tree_ID
+ " AND Node_ID = " + mMenu.getAD_Menu_ID();
int countRecords = DB.getSQLValue(getTrxName(ctx), sql);
if (countRecords > 0) {
sql = "select * from AD_TREENODEMM where AD_Tree_ID = "+AD_Tree_ID+" and "
+ " Node_ID =?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql,
getTrxName(ctx));
pstmt.setInt(1, mMenu.getAD_Menu_ID());
rs = pstmt.executeQuery();
if (rs.next()) {
String colValue = null;
ResultSetMetaData meta = rs.getMetaData();
int columns = meta.getColumnCount();
int tableID = X_AD_TreeNodeMM.Table_ID;
for (int q = 1; q <= columns; q++) {
String colName = meta.getColumnName(q).toUpperCase();
sql = "SELECT AD_Column_ID FROM AD_column WHERE Upper(ColumnName) = ? AND AD_Table_ID = ?";
int columnID = DB.getSQLValue(getTrxName(ctx), sql, colName, tableID);
sql = "SELECT AD_Reference_ID FROM AD_COLUMN WHERE AD_Column_ID = ?";
int referenceID = DB.getSQLValue(getTrxName(ctx), sql, columnID);
if (referenceID == 20 || referenceID == 28)
if (rs.getObject(q).equals("Y"))
colValue = "true";
else
colValue = "false";
else
colValue = "false";
else
{
Object obj = rs.getObject(q);
colValue = obj == null ? "" : obj.toString();
{
Object obj = rs.getObject(q);
colValue = obj == null ? "" : obj.toString();
}
X_AD_Package_Imp_Backup backup = new X_AD_Package_Imp_Backup(ctx.ctx, 0, getTrxName(ctx));
backup.setAD_Package_Imp_Detail_ID(impDetail.getAD_Package_Imp_Detail_ID());
backup.setAD_Package_Imp_ID(getPackageImpId(ctx.ctx));
backup.setAD_Table_ID(tableID);
backup.setAD_Column_ID(columnID);
backup.setAD_Reference_ID(referenceID);
backup.setColValue(colValue);
backup.saveEx();
}
X_AD_Package_Imp_Backup backup = new X_AD_Package_Imp_Backup(ctx.ctx, 0, getTrxName(ctx));
backup.setAD_Package_Imp_Detail_ID(impDetail.getAD_Package_Imp_Detail_ID());
backup.setAD_Package_Imp_ID(getPackageImpId(ctx.ctx));
backup.setAD_Table_ID(tableID);
backup.setAD_Column_ID(columnID);
backup.setAD_Reference_ID(referenceID);
backup.setColValue(colValue);
backup.saveEx();
}
} catch (Exception e) {
throw new DBException(e);
} finally {
DB.close(rs, pstmt);
}
} catch (Exception e) {
throw new DBException(e);
} finally {
DB.close(rs, pstmt);
updateSQL = new StringBuffer("UPDATE AD_TREENODEMM ").append(
"SET Parent_ID = " + parentId).append(
" , SeqNo = " + getStringValue(element, "SeqNo")).append(
" WHERE AD_Tree_ID = "+AD_Tree_ID).append(
" AND Node_ID = " + mMenu.getAD_Menu_ID());
} else {
updateSQL = new StringBuffer("Insert INTO AD_TREENODEMM").append(
"(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, ").append(
"Parent_ID, SeqNo, AD_Tree_ID, Node_ID)").append(
"VALUES(0, 0, 0, 0, ").append(
parentId + "," + getStringValue(element, "SeqNo") + ", "+AD_Tree_ID+", "
+ mMenu.getAD_Menu_ID() + ")");
}
updateSQL = new StringBuffer("UPDATE AD_TREENODEMM ").append(
"SET Parent_ID = " + parentId).append(
" , SeqNo = " + getStringValue(element, "SeqNo")).append(
" WHERE AD_Tree_ID = "+AD_Tree_ID).append(
" AND Node_ID = " + mMenu.getAD_Menu_ID());
} else {
updateSQL = new StringBuffer("Insert INTO AD_TREENODEMM").append(
"(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, ").append(
"Parent_ID, SeqNo, AD_Tree_ID, Node_ID)").append(
"VALUES(0, 0, 0, 0, ").append(
parentId + "," + getStringValue(element, "SeqNo") + ", "+AD_Tree_ID+", "
+ mMenu.getAD_Menu_ID() + ")");
DB.executeUpdate(updateSQL.toString(), getTrxName(ctx));
}
DB.executeUpdate(updateSQL.toString(), getTrxName(ctx));
}
private int getDefaultMenuTreeId() {
@ -210,6 +196,7 @@ public class MenuElementHandler extends AbstractElementHandler {
if (m_Menu.isSummary() == false) {
createApplication(ctx, document, AD_Menu_ID);
} else {
verifyPackOutRequirement(m_Menu);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Menu.Table_Name, atts);
@ -237,7 +224,7 @@ public class MenuElementHandler extends AbstractElementHandler {
String sql = "SELECT Parent_ID FROM AD_TreeNoDemm WHERE AD_Tree_ID = "+AD_Tree_ID+" and Node_ID=?";
int id = DB.getSQLValue(null, sql, m_Menu.getAD_Menu_ID());
if (id > 0) {
filler.addTableReference("Parent_ID", "AD_Menu", "Name", id, new AttributesImpl());
filler.addTableReference("Parent_ID", "AD_Menu", id, new AttributesImpl());
}
sql = "SELECT SeqNo FROM AD_TreeNoDemm WHERE AD_Tree_ID = "+AD_Tree_ID+" and Node_ID=?";
int seqNo = DB.getSQLValue(null, sql, m_Menu.getAD_Menu_ID());
@ -266,8 +253,8 @@ public class MenuElementHandler extends AbstractElementHandler {
rs = pstmt.executeQuery();
while (rs.next()) {
X_AD_Menu m_Menu = new X_AD_Menu(ctx.ctx, rs.getInt("AD_Menu_ID"),
null);
X_AD_Menu m_Menu = new X_AD_Menu(ctx.ctx, rs.getInt("AD_Menu_ID"), null);
verifyPackOutRequirement(m_Menu);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Menu.Table_Name, atts);
@ -344,6 +331,7 @@ public class MenuElementHandler extends AbstractElementHandler {
// Menu tag Start.
X_AD_Menu m_Menu = new X_AD_Menu(ctx.ctx, rs.getInt("AD_Menu_ID"),
null);
verifyPackOutRequirement(m_Menu);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Menu.Table_Name, atts);

View File

@ -47,12 +47,7 @@ public class MessageElementHandler extends AbstractElementHandler {
if (isProcessElement(ctx.ctx, entitytype)) {
MMessage mMessage = findPO(ctx, element);
if (mMessage == null) {
int id = 0;
if (!hasUUIDKey(ctx, element)) {
String value = getStringValue(element, "Value");
id = findIdByColumn(ctx, "AD_Message", "value", value);
}
mMessage = new MMessage(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
mMessage = new MMessage(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mMessage, element, this);
List<String> excludes = defaultExcludeList(X_AD_Message.Table_Name);
@ -73,9 +68,6 @@ public class MessageElementHandler extends AbstractElementHandler {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Message.Table_Name,
X_AD_Message.Table_ID);
String action = null;
if (mMessage.getAD_Message_ID() == 0 && isOfficialId(element, "AD_Message_ID"))
filler.setInteger("AD_Message_ID");
if (!mMessage.is_new()){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Message.Table_Name, mMessage);
action = "Update";
@ -116,6 +108,8 @@ public class MessageElementHandler extends AbstractElementHandler {
}
}
verifyPackOutRequirement(m_Message);
addTypeName(atts, "table");
document.startElement("","",I_AD_Message.Table_Name,atts);
createMessageBinding(ctx,document,m_Message);

View File

@ -31,22 +31,14 @@ public class ModelValidatorElementHandler extends AbstractElementHandler{
String action = null;
String entitytype = getStringValue(element, "EntityType");
String name = getStringValue(element, "Name");
if (isProcessElement(ctx.ctx, entitytype)) {
X_AD_ModelValidator validator = findPO(ctx, element);
if (validator == null) {
int id = 0;
if (!hasUUIDKey(ctx, element)) {
id = findIdByColumn(ctx, X_AD_ModelValidator.Table_Name, X_AD_ModelValidator.COLUMNNAME_Name, name, /*ignorecase=*/true);
}
validator = new X_AD_ModelValidator(ctx.ctx, id, getTrxName(ctx));
validator = new X_AD_ModelValidator(ctx.ctx, 0, getTrxName(ctx));
}
List<String> excludes = defaultExcludeList(X_AD_ModelValidator.Table_Name);
if (validator.getAD_ModelValidator_ID() == 0 && isOfficialId(element, "AD_ModelValidator_ID"))
validator.setAD_ModelValidator_ID(getIntValue(element, "AD_ModelValidator_ID"));
if (validators.contains(validator.getAD_ModelValidator_ID())) {
element.skip = true;
return;
@ -91,8 +83,6 @@ public class ModelValidatorElementHandler extends AbstractElementHandler{
@Override
public void endElement(PIPOContext ctx, Element element) throws SAXException {
// TODO Auto-generated method stub
}
@ -110,6 +100,8 @@ public class ModelValidatorElementHandler extends AbstractElementHandler{
}
}
verifyPackOutRequirement(validator);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", "AD_ModelValidator", atts);

View File

@ -46,22 +46,14 @@ public class ModificationElementHandler extends AbstractElementHandler{
String action = null;
String entitytype = getStringValue(element, "EntityType");
String name = getStringValue(element, "Name");
if (isProcessElement(ctx.ctx, entitytype)) {
X_AD_Modification modification = findPO(ctx, element);
if (modification == null) {
int id = 0;
if (!hasUUIDKey(ctx, element)) {
id = findIdByColumn(ctx, X_AD_Modification.Table_Name, X_AD_Modification.COLUMNNAME_Name, name, /*ignorecase=*/true);
}
modification = new X_AD_Modification(ctx.ctx, id, getTrxName(ctx));
modification = new X_AD_Modification(ctx.ctx, 0, getTrxName(ctx));
}
List<String> excludes = defaultExcludeList(X_AD_Modification.Table_Name);
if (modification.getAD_Modification_ID() == 0 && isOfficialId(element, X_AD_Modification.COLUMNNAME_AD_Modification_ID))
modification.setAD_Modification_ID(getIntValue(element, X_AD_Modification.COLUMNNAME_AD_Modification_ID));
if (modifications.contains(modification.getAD_Modification_ID())) {
element.skip = true;
return;
@ -123,6 +115,8 @@ public class ModificationElementHandler extends AbstractElementHandler{
}
}
verifyPackOutRequirement(modification);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", X_AD_Modification.Table_Name, atts);

View File

@ -26,8 +26,6 @@ import org.adempiere.pipo2.PIPOContext;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_Role;
import org.compiere.model.I_AD_Role_OrgAccess;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Role;
@ -43,37 +41,7 @@ public class OrgRoleElementHandler extends AbstractElementHandler {
X_AD_Role_OrgAccess po = findPO(ctx, element);
if (po == null) {
int roleId = 0;
if (getParentId(element, I_AD_Role.Table_Name) > 0) {
roleId = getParentId(element, I_AD_Role.Table_Name);
} else {
Element roleElement = element.properties.get("AD_Role_ID");
roleId = ReferenceUtils.resolveReference(ctx.ctx, roleElement, getTrxName(ctx));
}
if (roleId <= 0) {
element.defer = true;
element.unresolved = "AD_Role_ID";
return;
}
Element orgElement = element.properties.get("AD_Org_ID");
int orgId = ReferenceUtils.resolveReference(ctx.ctx, orgElement, getTrxName(ctx));
if (!hasUUIDKey(ctx, element)) {
Query query = new Query(ctx.ctx, "AD_Role_OrgAccess", "AD_Role_ID=? and AD_Org_ID=?", getTrxName(ctx));
po = query.setParameters(new Object[]{roleId, orgId})
.setClient_ID()
.<X_AD_Role_OrgAccess>first();
}
if (po == null) {
po = new X_AD_Role_OrgAccess(ctx.ctx, 0, getTrxName(ctx));
po.setAD_Org_ID(orgId);
po.setAD_Role_ID(roleId);
}
excludes.add("AD_Org_ID");
excludes.add("AD_Role_ID");
po = new X_AD_Role_OrgAccess(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, po, element, this);
@ -103,6 +71,8 @@ public class OrgRoleElementHandler extends AbstractElementHandler {
}
}
verifyPackOutRequirement(po);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Role_OrgAccess.Table_Name, atts);
@ -114,17 +84,8 @@ public class OrgRoleElementHandler extends AbstractElementHandler {
private void createOrgAccessBinding(PIPOContext ctx, TransformerHandler document,
X_AD_Role_OrgAccess po) {
PoExporter filler = new PoExporter(ctx, document, po);
AttributesImpl orgRefAtts = new AttributesImpl();
String orgReference = ReferenceUtils.getTableReference("AD_Org", "Name", po.getAD_Org_ID(), orgRefAtts);
filler.addString("AD_Org_ID", orgReference, orgRefAtts);
AttributesImpl roleRefAtts = new AttributesImpl();
String roleReference = ReferenceUtils.getTableReference("AD_Role", "Name", po.getAD_Role_ID(), roleRefAtts);
filler.addString("AD_Role_ID", roleReference, roleRefAtts);
List<String> excludes = defaultExcludeList(X_AD_Role_OrgAccess.Table_Name);
excludes.add("AD_Org_ID");
excludes.add("AD_Role_ID");
filler.export(excludes);
}

View File

@ -77,9 +77,6 @@ public class PreferenceElementHandler extends AbstractElementHandler {
}
}
if (mPreference.get_ID() == 0 && isOfficialId(element, "AD_Preference_ID"))
mPreference.setAD_Preference_ID(Integer.parseInt(getStringValue(element, "AD_Preference_ID")));
if (mPreference.is_new() || mPreference.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Preference.Table_Name,
X_AD_Preference.Table_ID);
@ -121,6 +118,8 @@ public class PreferenceElementHandler extends AbstractElementHandler {
}
}
verifyPackOutRequirement(m_Preference);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", X_AD_Preference.Table_Name, atts);

View File

@ -52,18 +52,10 @@ public class PrintFormatElementHandler extends AbstractElementHandler {
X_AD_PrintFormat mPrintFormat = findPO(ctx, element);
if (mPrintFormat == null) {
int id = 0;
if (!hasUUIDKey(ctx, element)) {
String name = getStringValue(element, "Name");
id = findIdByColumn(ctx, "AD_PrintFormat", "Name", name);
}
mPrintFormat = new X_AD_PrintFormat(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
mPrintFormat = new X_AD_PrintFormat(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mPrintFormat, element, this);
List<String> excludes = defaultExcludeList(X_AD_PrintFormat.Table_Name);
if (mPrintFormat.getAD_PrintFormat_ID() == 0 && isOfficialId(element, "AD_PrintFormat_ID"))
mPrintFormat.setAD_PrintFormat_ID(getIntValue(element, "AD_PrintFormat_ID"));
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
@ -143,6 +135,7 @@ public class PrintFormatElementHandler extends AbstractElementHandler {
}
if (createElement) {
verifyPackOutRequirement(m_Printformat);
addTypeName(atts, "table");
document.startElement("", "", I_AD_PrintFormat.Table_Name, atts);
createPrintFormatBinding(ctx, document, m_Printformat);

View File

@ -28,12 +28,10 @@ import org.adempiere.pipo2.PIPOContext;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_PrintFormatItem;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_PrintFormatItem;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -52,61 +50,9 @@ public class PrintFormatItemElementHandler extends AbstractElementHandler {
X_AD_PrintFormatItem mPrintFormatItem = findPO(ctx, element);
if (mPrintFormatItem == null) {
int parentId = 0;
if (getParentId(element, I_AD_PrintFormatItem.Table_Name) > 0) {
parentId = getParentId(element, I_AD_PrintFormatItem.Table_Name);
} else {
Element pfElement = element.properties.get(I_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormat_ID);
parentId = ReferenceUtils.resolveReference(ctx.ctx, pfElement, getTrxName(ctx));
}
if (parentId <= 0) {
element.defer = true;
element.unresolved = "AD_PrintFormat_ID";
return;
}
int id = 0;
if (!hasUUIDKey(ctx, element)) {
String name = getStringValue(element, "Name");
id = findIdByNameAndParentId(ctx, "AD_PrintFormatItem", name, "AD_PrintFormat", parentId);
}
mPrintFormatItem = new X_AD_PrintFormatItem(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
mPrintFormatItem.setAD_PrintFormat_ID(parentId);
excludes.add(I_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormat_ID);
mPrintFormatItem = new X_AD_PrintFormatItem(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mPrintFormatItem, element, this);
if (mPrintFormatItem.getAD_PrintFormatItem_ID() == 0 && isOfficialId(element, "AD_PrintFormatItem_ID"))
filler.setInteger("AD_PrintFormatItem_ID");
excludes.add("AD_Table_ID");
excludes.add("AD_Column_ID");
int columnId = 0;
Element columnElement = element.properties.get("AD_Column_ID");
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) {
columnId = ReferenceUtils.resolveReference(ctx.ctx, columnElement, getTrxName(ctx));
} else {
Element tableElement = element.properties.get("AD_Table_ID");
int tableId = ReferenceUtils.resolveReference(ctx.ctx, tableElement, getTrxName(ctx));
String columnName = getStringValue(element, "AD_Column_ID");
columnId = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnName,
"AD_Table", tableId);
}
if (columnId > 0)
mPrintFormatItem.setAD_Column_ID(columnId);
excludes.add("AD_PrintFormatChild_ID");
Element pfchildElement = element.properties.get(I_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormatChild_ID);
int AD_PrintFormatChild_ID = ReferenceUtils.resolveReference(ctx.ctx, pfchildElement, getTrxName(ctx));
if (AD_PrintFormatChild_ID > 0) {
mPrintFormatItem.setAD_PrintFormatChild_ID(AD_PrintFormatChild_ID);
} else if (pfchildElement.contents != null && pfchildElement.contents.length() > 0) {
element.defer = true;
element.unresolved = "AD_PrintFormat: " + pfchildElement.contents;
return;
}
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
@ -156,6 +102,8 @@ public class PrintFormatItemElementHandler extends AbstractElementHandler {
}
}
verifyPackOutRequirement(m_PrintFormatItem);
PackOut packOut = ctx.packOut;
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
@ -181,13 +129,6 @@ public class PrintFormatItemElementHandler extends AbstractElementHandler {
if (mPrintformatItem.getAD_PrintFormatItem_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_PrintFormatItem_ID", new AttributesImpl());
if (mPrintformatItem.getAD_Client_ID() == 0 && mPrintformatItem.getAD_Column_ID() > 0) {
String sql = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?";
int tableID = DB.getSQLValue(null, sql, mPrintformatItem.getAD_Column_ID());
AttributesImpl referenceAtts = new AttributesImpl();
filler.addTableReference("AD_Table_ID", "AD_Table", "TableName", tableID, referenceAtts);
}
filler.export(excludes);
}

View File

@ -45,19 +45,9 @@ public class PrintPaperElementHandler extends AbstractElementHandler {
X_AD_PrintPaper printPaper = findPO(ctx, element);
if (printPaper == null) {
String printPaperName = getStringValue(element, "Name", excludes);
int id = 0;
if (!hasUUIDKey(ctx, element)) {
id = findIdByName(ctx, "AD_PrintPaper", printPaperName);
}
printPaper = new X_AD_PrintPaper(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
printPaper.setName(printPaperName);
printPaper = new X_AD_PrintPaper(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, printPaper, element, this);
if (printPaper.getAD_PrintPaper_ID() == 0 && isOfficialId(element, "AD_PrintPaper_ID"))
filler.setInteger("AD_PrintPaper_ID");
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
@ -104,6 +94,8 @@ public class PrintPaperElementHandler extends AbstractElementHandler {
}
}
verifyPackOutRequirement(printPaper);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", I_AD_PrintPaper.Table_Name, atts);

View File

@ -26,9 +26,7 @@ import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_Process_Access;
import org.compiere.model.I_AD_Role;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Process;
import org.compiere.model.X_AD_Process_Access;
@ -40,45 +38,11 @@ import org.xml.sax.helpers.AttributesImpl;
public class ProcessAccessElementHandler extends AbstractElementHandler {
public void startElement(PIPOContext ctx, Element element) throws SAXException {
int roleid =0;
int processid =0;
List<String> excludes = defaultExcludeList(X_AD_Process_Access.Table_Name);
X_AD_Process_Access po = findPO(ctx, element);
if (po == null) {
if (getParentId(element, I_AD_Role.Table_Name) > 0) {
roleid = getParentId(element, I_AD_Role.Table_Name);
} else {
Element roleElement = element.properties.get("AD_Role_ID");
roleid = ReferenceUtils.resolveReference(ctx.ctx, roleElement, getTrxName(ctx));
}
if (roleid <= 0) {
element.defer = true;
element.unresolved = "AD_Role_ID";
return;
}
Element processElement = element.properties.get(I_AD_Process_Access.COLUMNNAME_AD_Process_ID);
processid = ReferenceUtils.resolveReference(ctx.ctx, processElement, getTrxName(ctx));
if (processid <= 0) {
element.defer = true;
element.unresolved = "AD_Process_ID " + (processElement.contents != null ? processElement.contents.toString() : "");
return;
}
if (!hasUUIDKey(ctx, element)) {
Query query = new Query(ctx.ctx, "AD_Process_Access", "AD_Role_ID=? and AD_Process_ID=?", getTrxName(ctx));
po = query.setParameters(new Object[]{roleid, processid}).first();
}
if (po == null)
{
po = new X_AD_Process_Access(ctx.ctx, 0, getTrxName(ctx));
po.setAD_Process_ID(processid);
po.setAD_Role_ID(roleid);
}
excludes.add(I_AD_Process_Access.COLUMNNAME_AD_Role_ID);
excludes.add(I_AD_Process_Access.COLUMNNAME_AD_Process_ID);
po = new X_AD_Process_Access(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> notfounds = filler.autoFill(excludes);
@ -110,6 +74,8 @@ public class ProcessAccessElementHandler extends AbstractElementHandler {
}
}
verifyPackOutRequirement(po);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Process_Access.Table_Name, atts);

View File

@ -57,19 +57,8 @@ public class ProcessElementHandler extends AbstractElementHandler {
if (isProcessElement(ctx.ctx, entitytype)) {
X_AD_Process mProcess = findPO(ctx, element);
if (mProcess == null) {
String value = getStringValue(element, "Value");
// Get New process.
int id = 0;
if (!hasUUIDKey(ctx, element)) {
id = findIdByColumn(ctx, "AD_Process", "Value", value);
}
mProcess = new X_AD_Process(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
mProcess = new X_AD_Process(ctx.ctx, 0, getTrxName(ctx));
}
if (mProcess.getAD_Process_ID() == 0 && isOfficialId(element, "AD_Process_ID"))
mProcess.setAD_Process_ID(Integer.parseInt(getStringValue(element, "AD_Process_ID")));
PoFiller filler = new PoFiller(ctx, mProcess, element, this);
List<String> excludes = defaultExcludeList(X_AD_Process.Table_Name);
@ -158,6 +147,7 @@ public class ProcessElementHandler extends AbstractElementHandler {
}
if (createElement) {
verifyPackOutRequirement(m_Process);
addTypeName(atts, "table");
document.startElement("", "", I_AD_Process.Table_Name, atts);
createProcessBinding(ctx, document, m_Process);

View File

@ -28,7 +28,6 @@ import org.adempiere.pipo2.PIPOContext;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Element;
import org.compiere.model.I_AD_Process;
@ -54,33 +53,8 @@ public class ProcessParaElementHandler extends AbstractElementHandler {
X_AD_Process_Para mProcessPara = findPO(ctx, element);
if (mProcessPara == null) {
String name = getStringValue(element, "ColumnName");
int id = 0;
int masterId = 0;
if (getParentId(element, I_AD_Process.Table_Name) > 0) {
masterId = getParentId(element, I_AD_Process.Table_Name);
} else {
Element processElement = element.properties.get(I_AD_Process_Para.COLUMNNAME_AD_Process_ID);
masterId = ReferenceUtils.resolveReference(ctx.ctx, processElement, getTrxName(ctx));
}
if (masterId <= 0) {
element.defer = true;
element.unresolved = "AD_Process: " + getStringValue(element, I_AD_Process_Para.COLUMNNAME_AD_Process_ID);
return;
}
if (!hasUUIDKey(ctx, element)) {
id = findIdByColumnAndParentId(ctx, "AD_Process_Para", "ColumnName", name, "AD_Process", masterId);
}
mProcessPara = new X_AD_Process_Para(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
mProcessPara.setAD_Process_ID(masterId);
excludes.add(I_AD_Process_Para.COLUMNNAME_AD_Process_ID);
mProcessPara = new X_AD_Process_Para(ctx.ctx, 0, getTrxName(ctx));
}
if (mProcessPara.getAD_Process_Para_ID() == 0 && isOfficialId(element, "AD_Process_Para_ID"))
mProcessPara.setAD_Process_Para_ID(Integer.parseInt(getStringValue(element, "AD_Process_Para_ID")));
PoFiller filler = new PoFiller(ctx, mProcessPara, element, this);
List<String> notfounds = filler.autoFill(excludes);
@ -145,6 +119,9 @@ public class ProcessParaElementHandler extends AbstractElementHandler {
return;
}
}
verifyPackOutRequirement(m_Processpara);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Process_Para.Table_Name, atts);

View File

@ -54,22 +54,14 @@ public class ReferenceElementHandler extends AbstractElementHandler {
public void startElement(PIPOContext ctx, Element element)
throws SAXException {
String entitytype = getStringValue(element, "EntityType");
String name = getStringValue(element, "Name");
if (isProcessElement(ctx.ctx, entitytype)) {
X_AD_Reference mReference = findPO(ctx, element);
if (mReference == null) {
int id = 0;
if (!hasUUIDKey(ctx, element)) {
id = findIdByName(ctx, "AD_Reference", name);
}
mReference = new X_AD_Reference(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
mReference = new X_AD_Reference(ctx.ctx, 0, getTrxName(ctx));
}
List<String> excludes = defaultExcludeList(X_AD_Reference.Table_Name);
if (mReference.getAD_Reference_ID() == 0 && isOfficialId(element, "AD_Reference_ID"))
mReference.setAD_Reference_ID(getIntValue(element, "AD_Reference_ID"));
PoFiller filler = new PoFiller(ctx, mReference, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
@ -131,6 +123,7 @@ public class ReferenceElementHandler extends AbstractElementHandler {
PackOut packOut = ctx.packOut;
packOut.getCtx().ctx.put("Table_Name",X_AD_Reference.Table_Name);
if (createElement) {
verifyPackOutRequirement(m_Reference);
addTypeName(atts, "table");
document.startElement("", "", I_AD_Reference.Table_Name, atts);
createReferenceBinding(ctx, document, m_Reference);

View File

@ -27,10 +27,8 @@ import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Ref_List;
import org.compiere.model.I_AD_Reference;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_Ref_List;
import org.compiere.util.Env;
@ -51,25 +49,9 @@ public class ReferenceListElementHandler extends AbstractElementHandler {
X_AD_Ref_List mRefList = findPO(ctx, element);
if (mRefList == null) {
String value = getStringValue(element, "Value");
int AD_Reference_ID = 0;
if (getParentId(element, I_AD_Reference.Table_Name) > 0) {
AD_Reference_ID = getParentId(element, I_AD_Reference.Table_Name);
} else {
Element referenceElement = element.properties.get(I_AD_Ref_List.COLUMNNAME_AD_Reference_ID);
AD_Reference_ID = ReferenceUtils.resolveReference(ctx.ctx, referenceElement, getTrxName(ctx));
}
int AD_Ref_List_ID = 0;
if (!hasUUIDKey(ctx, element)) {
AD_Ref_List_ID = findIdByColumnAndParentId(ctx, "AD_Ref_List", "Value", value, "AD_Reference", AD_Reference_ID);
}
mRefList = new X_AD_Ref_List(ctx.ctx, AD_Ref_List_ID, getTrxName(ctx));
mRefList = new X_AD_Ref_List(ctx.ctx, 0, getTrxName(ctx));
}
if (mRefList.getAD_Ref_List_ID() == 0 && isOfficialId(element, "AD_Ref_List_ID"))
mRefList.setAD_Ref_List_ID(getIntValue(element, "AD_Ref_List_ID"));
PoFiller filler = new PoFiller(ctx, mRefList, element, this);
List<String> excludes = defaultExcludeList(X_AD_Ref_List.Table_Name);
List<String> notfounds = filler.autoFill(excludes);
@ -120,6 +102,9 @@ public class ReferenceListElementHandler extends AbstractElementHandler {
return;
}
}
verifyPackOutRequirement(m_Ref_List);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Ref_List.Table_Name, atts);

View File

@ -32,7 +32,6 @@ import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.compiere.model.I_AD_Ref_Table;
import org.compiere.model.I_AD_Reference;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_Ref_Table;
import org.compiere.model.X_AD_Reference;
@ -57,37 +56,7 @@ public class ReferenceTableElementHandler extends AbstractElementHandler {
X_AD_Ref_Table refTable = findPO(ctx, element);
if (refTable == null) {
int AD_Reference_ID = 0;
if (getParentId(element, I_AD_Reference.Table_Name) > 0) {
AD_Reference_ID = getParentId(element, I_AD_Reference.Table_Name);
} else {
Element referenceElement = element.properties.get(I_AD_Ref_Table.COLUMNNAME_AD_Reference_ID);
AD_Reference_ID = ReferenceUtils.resolveReference(ctx.ctx, referenceElement, getTrxName(ctx));
}
if (AD_Reference_ID <= 0 && isOfficialId(element, "AD_Reference_ID"))
AD_Reference_ID = getIntValue(element, "AD_Reference_ID");
if (!hasUUIDKey(ctx, element)) {
String sql = "SELECT * FROM AD_Ref_Table WHERE AD_Reference_ID = ?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
pstmt.setInt(1, AD_Reference_ID);
rs = pstmt.executeQuery();
if (rs.next()) {
refTable = new X_AD_Ref_Table(ctx.ctx, rs, getTrxName(ctx));
} else {
refTable = new X_AD_Ref_Table(ctx.ctx, 0, getTrxName(ctx));
}
} catch (Exception e) {
throw new DatabaseAccessException(e.getLocalizedMessage(), e);
} finally {
DB.close(rs, pstmt);
}
} else {
refTable = new X_AD_Ref_Table(ctx.ctx, 0, getTrxName(ctx));
}
refTable = new X_AD_Ref_Table(ctx.ctx, 0, getTrxName(ctx));
}
String action = refTable.is_new() ? "New" : "Update";
PoFiller filler = new PoFiller(ctx, refTable, element, this);
@ -97,24 +66,13 @@ public class ReferenceTableElementHandler extends AbstractElementHandler {
element.unresolved = notfounds.toString();
return;
}
int tableId = refTable.getAD_Table_ID();
Element displayElement = element.properties.get("AD_Display");
int displayColumnId = 0;
if (ReferenceUtils.isIDLookup(displayElement) || ReferenceUtils.isUUIDLookup(displayElement)) {
displayColumnId = ReferenceUtils.resolveReference(ctx.ctx, displayElement, getTrxName(ctx));
} else {
displayColumnId = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", displayElement.contents.toString(), "AD_Table", tableId);
}
int displayColumnId = ReferenceUtils.resolveReference(ctx.ctx, displayElement, getTrxName(ctx));
refTable.setAD_Display(displayColumnId);
Element keyElement = element.properties.get("AD_Key");
int keyColumnId = 0;
if (ReferenceUtils.isIDLookup(keyElement) || ReferenceUtils.isUUIDLookup(keyElement)) {
keyColumnId = ReferenceUtils.resolveReference(ctx.ctx, keyElement, getTrxName(ctx));
} else {
keyColumnId = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", keyElement.contents.toString(), "AD_Table", tableId);
}
int keyColumnId = ReferenceUtils.resolveReference(ctx.ctx, keyElement, getTrxName(ctx));
refTable.setAD_Key(keyColumnId);
if (refTable.is_new() || refTable.is_Changed()) {
@ -160,6 +118,8 @@ public class ReferenceTableElementHandler extends AbstractElementHandler {
}
}
verifyPackOutRequirement(refTable);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", X_AD_Ref_Table.Table_Name, atts);
@ -175,8 +135,8 @@ public class ReferenceTableElementHandler extends AbstractElementHandler {
excludes.add("ad_display");
excludes.add("ad_key");
filler.export(excludes);
filler.addTableReference("AD_Display", "AD_Column", "ColumnName", new AttributesImpl());
filler.addTableReference("AD_Key", "AD_Column", "ColumnName", new AttributesImpl());
filler.addTableReference("AD_Display", "AD_Column", new AttributesImpl());
filler.addTableReference("AD_Key", "AD_Column", new AttributesImpl());
document.endElement("", "", X_AD_Ref_Table.Table_Name);
}

View File

@ -26,14 +26,10 @@ import org.adempiere.pipo2.PIPOContext;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_ReportView;
import org.compiere.model.I_AD_ReportView_Col;
import org.compiere.model.MColumn;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_ReportView_Col;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -49,65 +45,9 @@ public class ReportViewColElementHandler extends AbstractElementHandler {
excludes.add("AD_Table_ID");
X_AD_ReportView_Col mReportviewCol = findPO(ctx, element);
if (mReportviewCol == null) {
int AD_ReportView_ID = 0;
if (getParentId(element, I_AD_ReportView.Table_Name) > 0) {
AD_ReportView_ID = getParentId(element, I_AD_ReportView.Table_Name);
} else {
Element rvElement = element.properties.get(I_AD_ReportView_Col.COLUMNNAME_AD_ReportView_ID);
AD_ReportView_ID = ReferenceUtils.resolveReference(ctx.ctx, rvElement, getTrxName(ctx));
}
if (AD_ReportView_ID <= 0) {
element.defer = true;
element.unresolved = "AD_ReportView_ID";
return;
}
int AD_Column_ID = 0;
Element columnElement = element.properties.get(I_AD_ReportView_Col.COLUMNNAME_AD_Column_ID);
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) {
AD_Column_ID = ReferenceUtils.resolveReference(ctx.ctx, columnElement, getTrxName(ctx));
} else {
if (columnElement.contents != null && columnElement.contents.length() > 0) {
Element tableElement = element.properties.get("AD_Table_ID");
int AD_Table_ID = ReferenceUtils.resolveReference(ctx.ctx, tableElement, getTrxName(ctx));
AD_Column_ID = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnElement.contents.toString(),
"AD_Table", AD_Table_ID);
if (AD_Column_ID <= 0) {
element.defer = true;
element.unresolved = "AD_Column_ID";
return;
}
}
}
String functionColumn = getStringValue(element, "FunctionColumn");
StringBuffer sql = new StringBuffer("SELECT AD_Reportview_Col_ID FROM AD_Reportview_Col ")
.append(" WHERE AD_Column_ID ");
if (AD_Column_ID > 0)
sql.append(" = " + AD_Column_ID);
else
sql.append(" IS NULL ");
sql.append(" AND FunctionColumn = ?");
sql.append(" AND AD_ReportView_ID = ?");
int id = 0;
if (!hasUUIDKey(ctx, element)) {
id = DB.getSQLValue(getTrxName(ctx), sql.toString(), functionColumn, AD_ReportView_ID);
}
mReportviewCol = new X_AD_ReportView_Col(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
mReportviewCol.setAD_ReportView_ID(AD_ReportView_ID);
if (AD_Column_ID > 0) {
mReportviewCol.setAD_Column_ID(AD_Column_ID);
}
mReportviewCol.setFunctionColumn(functionColumn);
excludes.add("FunctionColumn");
excludes.add("AD_ReportView_ID");
excludes.add("AD_Column_ID");
mReportviewCol = new X_AD_ReportView_Col(ctx.ctx, 0, getTrxName(ctx));
}
if (mReportviewCol.getAD_ReportView_Col_ID() == 0 && isOfficialId(element, "AD_ReportView_Col_ID"))
mReportviewCol.setAD_ReportView_Col_ID(getIntValue(element, "AD_ReportView_Col_ID"));
PoFiller filler = new PoFiller(ctx, mReportviewCol, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
@ -160,6 +100,8 @@ public class ReportViewColElementHandler extends AbstractElementHandler {
}
}
verifyPackOutRequirement(m_Reportview_Col);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", X_AD_ReportView_Col.Table_Name, atts);
@ -175,15 +117,6 @@ public class ReportViewColElementHandler extends AbstractElementHandler {
if (m_Reportview_Col.getAD_ReportView_Col_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_ReportView_Col_ID", new AttributesImpl());
if (m_Reportview_Col.getAD_Column_ID() > 0) {
int AD_Column_ID = m_Reportview_Col.getAD_Column_ID();
MColumn mColumn = new MColumn(ctx.ctx, AD_Column_ID, getTrxName(ctx));
int AD_Table_ID = mColumn.getAD_Table_ID();
AttributesImpl tableAtts = new AttributesImpl();
String value = ReferenceUtils.getTableReference("AD_Table", "TableName", AD_Table_ID, tableAtts);
filler.addString("AD_Table_ID", value, tableAtts);
}
filler.export(excludes);
}

View File

@ -54,17 +54,9 @@ public class ReportViewElementHandler extends AbstractElementHandler {
X_AD_ReportView mReportview = findPO(ctx, element);
if (mReportview == null) {
int id = 0;
if (!hasUUIDKey(ctx, element)) {
String name = getStringValue(element, "Name");
id = findIdByName(ctx, "AD_ReportView", name);
}
mReportview = new X_AD_ReportView(ctx.ctx, id, getTrxName(ctx));
mReportview = new X_AD_ReportView(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mReportview, element, this);
if (mReportview.getAD_ReportView_ID() == 0 && isOfficialId(element, "AD_ReportView_ID"))
mReportview.setAD_ReportView_ID(getIntValue(element, "AD_ReportView_ID"));
List<String> notfound = filler.autoFill(excludes);
if (notfound.size() > 0) {
element.defer = true;
@ -123,6 +115,7 @@ public class ReportViewElementHandler extends AbstractElementHandler {
}
if (createElement) {
verifyPackOutRequirement(m_Reportview);
addTypeName(atts, "table");
document.startElement("", "", I_AD_ReportView.Table_Name, atts);
createReportViewBinding(ctx, document, m_Reportview);

View File

@ -29,7 +29,6 @@ import org.adempiere.pipo2.PIPOContext;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Role;
@ -65,18 +64,9 @@ public class RoleElementHandler extends AbstractElementHandler {
MRole mRole = findPO(ctx, element);
if (mRole == null) {
String name = getStringValue(element, "Name", excludes);
int id = 0;
if (!hasUUIDKey(ctx, element)) {
id = findIdByName(ctx, "AD_Role", name);
}
mRole = new MRole(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
mRole.setName(name);
mRole = new MRole(ctx.ctx, 0, getTrxName(ctx));
}
if (mRole.getAD_Role_ID() == 0 && isOfficialId(element, "AD_Role_ID"))
mRole.setAD_Role_ID(getIntValue(element, "AD_Role_ID"));
PoFiller filler = new PoFiller(ctx, mRole, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
@ -126,6 +116,7 @@ public class RoleElementHandler extends AbstractElementHandler {
}
if (createElement) {
verifyPackOutRequirement(m_Role);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Role.Table_Name, atts);
@ -330,14 +321,6 @@ public class RoleElementHandler extends AbstractElementHandler {
if (m_Role.getAD_Role_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_Role_ID", new AttributesImpl());
if (m_Role.getC_Currency_ID() > 0) {
AttributesImpl currencyAtts = new AttributesImpl();
String value = ReferenceUtils.getTableReference("C_Currency", "ISO_Code", m_Role.getC_Currency_ID(), currencyAtts);
filler.addString("C_Currency_ID", value, currencyAtts);
} else
filler.addString("C_Currency_ID", "", new AttributesImpl());
excludes.add(X_AD_Role.COLUMNNAME_C_Currency_ID);
filler.export(excludes);
}

View File

@ -31,7 +31,6 @@ import org.adempiere.pipo2.PIPOContext;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Process;
@ -62,77 +61,10 @@ public class TabElementHandler extends AbstractElementHandler {
MTab mTab = findPO(ctx, element);
if (mTab == null) {
String name = getStringValue(element, "Name", excludes);
int windowId = 0;
if (getParentId(element, I_AD_Window.Table_Name) > 0) {
windowId = getParentId(element, I_AD_Window.Table_Name);
} else {
Element windowElement = element.properties.get(I_AD_Tab.COLUMNNAME_AD_Window_ID);
windowId = ReferenceUtils.resolveReference(ctx.ctx, windowElement, getTrxName(ctx));
}
if (windowId <= 0) {
element.defer = true;
element.unresolved = "AD_Window_ID";
return;
}
Element tableElement = element.properties.get(I_AD_Tab.COLUMNNAME_AD_Table_ID);
int tableId = ReferenceUtils.resolveReference(ctx.ctx, tableElement, getTrxName(ctx));
if (tableId <= 0) {
element.defer = true;
element.unresolved = "AD_Table_ID";
return;
}
int id = 0;
if (!hasUUIDKey(ctx, element)) {
String sql = "SELECT AD_Tab_ID FROM AD_Tab where AD_Window_ID = ? "
+ " AND Name = ?"
+ " AND AD_Table_ID = ?";
id = DB.getSQLValue(getTrxName(ctx), sql, windowId, name, tableId);
}
mTab = new MTab(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
mTab.setAD_Table_ID(tableId);
mTab.setName(name);
mTab.setAD_Window_ID(windowId);
mTab = new MTab(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mTab, element, this);
if (mTab.getAD_Tab_ID() == 0 && isOfficialId(element, "AD_Tab_ID"))
mTab.setAD_Tab_ID(getIntValue(element, "AD_Tab_ID"));
Element columnElement = element.properties.get(I_AD_Tab.COLUMNNAME_AD_Column_ID);
int AD_Column_ID = 0;
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) {
AD_Column_ID = ReferenceUtils.resolveReference(ctx.ctx, columnElement, getTrxName(ctx));
} else if (columnElement.contents != null && columnElement.contents.length() > 0){
AD_Column_ID = findIdByColumnAndParentId (ctx, "AD_Column","ColumnName", columnElement.contents.toString(),
"AD_Table", mTab.getAD_Table_ID());
}
mTab.setAD_Column_ID(AD_Column_ID);
columnElement = element.properties.get(I_AD_Tab.COLUMNNAME_AD_ColumnSortOrder_ID);
AD_Column_ID = 0;
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) {
AD_Column_ID = ReferenceUtils.resolveReference(ctx.ctx, columnElement, getTrxName(ctx));
} else if (columnElement.contents != null && columnElement.contents.length() > 0){
AD_Column_ID = findIdByColumnAndParentId (ctx, "AD_Column","ColumnName", columnElement.contents.toString(),
"AD_Table", mTab.getAD_Table_ID());
}
mTab.setAD_ColumnSortOrder_ID(AD_Column_ID);
columnElement = element.properties.get(I_AD_Tab.COLUMNNAME_AD_ColumnSortYesNo_ID);
AD_Column_ID = 0;
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) {
AD_Column_ID = ReferenceUtils.resolveReference(ctx.ctx, columnElement, getTrxName(ctx));
} else if (columnElement.contents != null && columnElement.contents.length() > 0){
AD_Column_ID = findIdByColumnAndParentId (ctx, "AD_Column","ColumnName", columnElement.contents.toString(),
"AD_Table", mTab.getAD_Table_ID());
}
mTab.setAD_ColumnSortYesNo_ID(AD_Column_ID);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
@ -184,6 +116,7 @@ public class TabElementHandler extends AbstractElementHandler {
}
}
if (createElement) {
verifyPackOutRequirement(m_Tab);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("","",I_AD_Tab.Table_Name,atts);

View File

@ -58,29 +58,9 @@ public class TableElementHandler extends AbstractElementHandler {
MTable mTable = findPO(ctx, element);
if (mTable == null) {
int id = 0;
String tableName = getStringValue(element, "TableName", excludes);
if (!hasUUIDKey(ctx, element)) {
id = packIn.getTableId(tableName);
if (id <= 0) {
id = findIdByColumn(ctx, "AD_Table", "TableName", tableName);
if (id > 0)
packIn.addTable(tableName, id);
}
if (id > 0 && isTableProcess(ctx, id)) {
return;
}
}
mTable = new MTable(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
mTable.setTableName(tableName);
mTable = new MTable(ctx.ctx, 0, getTrxName(ctx));
}
if (mTable.getAD_Table_ID() == 0 && isOfficialId(element, "AD_Table_ID"))
{
mTable.setAD_Table_ID(getIntValue(element, "AD_Table_ID"));
}
PoFiller filler = new PoFiller(ctx, mTable, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
@ -135,6 +115,7 @@ public class TableElementHandler extends AbstractElementHandler {
}
}
if (createElement) {
verifyPackOutRequirement(m_Table);
addTypeName(atts, "table");
document.startElement("","",I_AD_Table.Table_Name,atts);
createTableBinding(ctx,document,m_Table);
@ -199,15 +180,6 @@ public class TableElementHandler extends AbstractElementHandler {
ctx.ctx.remove(X_AD_Column.COLUMNNAME_AD_Column_ID);
}
private boolean isTableProcess(PIPOContext ctx, int AD_Table_ID) {
if (tables.contains(AD_Table_ID))
return true;
else {
tables.add(AD_Table_ID);
return false;
}
}
private void createTableBinding(PIPOContext ctx, TransformerHandler document, X_AD_Table m_Table)
{
PoExporter filler = new PoExporter(ctx, document, m_Table);

View File

@ -26,8 +26,6 @@ import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_Role;
import org.compiere.model.I_AD_Task_Access;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Role;
@ -40,44 +38,11 @@ import org.xml.sax.helpers.AttributesImpl;
public class TaskAccessElementHandler extends AbstractElementHandler {
public void startElement(PIPOContext ctx, Element element) throws SAXException {
int roleid =0;
int taskid =0;
List<String> excludes = defaultExcludeList(X_AD_Task_Access.Table_Name);
X_AD_Task_Access po = findPO(ctx, element);
if (po == null) {
if (getParentId(element, I_AD_Role.Table_Name) > 0) {
roleid = getParentId(element, I_AD_Role.Table_Name);
} else {
Element roleElement = element.properties.get("AD_Role_ID");
roleid = ReferenceUtils.resolveReference(ctx.ctx, roleElement, getTrxName(ctx));
}
if (roleid <= 0) {
element.defer = true;
element.unresolved = "AD_Role_ID";
return;
}
Element taskElement = element.properties.get(I_AD_Task_Access.COLUMNNAME_AD_Task_ID);
taskid = ReferenceUtils.resolveReference(ctx.ctx, taskElement, getTrxName(ctx));
if (taskid <= 0) {
element.defer = true;
element.unresolved = "AD_Task_ID";
return;
}
if (!hasUUIDKey(ctx, element)) {
Query query = new Query(ctx.ctx, "AD_Task_Access", "AD_Role_ID=? and AD_Task_ID=?", getTrxName(ctx));
po = query.setParameters(new Object[]{roleid, taskid}).first();
}
if (po == null){
po = new X_AD_Task_Access(ctx.ctx, 0, getTrxName(ctx));
po.setAD_Role_ID(roleid);
po.setAD_Task_ID(taskid);
}
excludes.add(I_AD_Task_Access.COLUMNNAME_AD_Role_ID);
excludes.add(I_AD_Task_Access.COLUMNNAME_AD_Task_ID);
po = new X_AD_Task_Access(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> notfounds = filler.autoFill(excludes);
@ -104,6 +69,7 @@ public class TaskAccessElementHandler extends AbstractElementHandler {
return;
}
}
verifyPackOutRequirement(po);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Task_Access.Table_Name, atts);

View File

@ -48,17 +48,9 @@ public class TaskElementHandler extends AbstractElementHandler {
MTask mTask = findPO(ctx, element);
if (mTask == null) {
int id = 0;
if (!hasUUIDKey(ctx, element)) {
String name = getStringValue(element, "Name");
id = findIdByName(ctx, "AD_Task", name);
}
mTask = new MTask(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
mTask = new MTask(ctx.ctx, 0, getTrxName(ctx));
}
if (mTask.getAD_Task_ID() == 0 && isOfficialId(element, "AD_Task_ID"))
mTask.setAD_Task_ID(getIntValue(element, "AD_Task_ID"));
PoFiller filler = new PoFiller(ctx, mTask, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
@ -108,6 +100,7 @@ public class TaskElementHandler extends AbstractElementHandler {
return;
}
}
verifyPackOutRequirement(m_Task);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Task.Table_Name, atts);

View File

@ -26,7 +26,6 @@ import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_User_Roles;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Role;
@ -40,52 +39,11 @@ public class UserRoleElementHandler extends AbstractElementHandler {
public void startElement(PIPOContext ctx, Element element)
throws SAXException {
int roleid =0;
int userid =0;
int orgid =0;
List<String> excludes = defaultExcludeList(X_AD_User_Roles.Table_Name);
X_AD_User_Roles po = findPO(ctx, element);
if (po == null) {
Element userElement = element.properties.get(I_AD_User_Roles.COLUMNNAME_AD_User_ID);
userid = ReferenceUtils.resolveReference(ctx.ctx, userElement, getTrxName(ctx));
if (userid <= 0) {
element.defer = true;
element.unresolved = "AD_User_ID " + (userElement.contents != null ? userElement.contents.toString() : "");
return;
}
if (getParentId(element, X_AD_Role.Table_Name) > 0) {
roleid = getParentId(element, X_AD_Role.Table_Name);
} else {
Element roleElement = element.properties.get("AD_Role_ID");
roleid = ReferenceUtils.resolveReference(ctx.ctx, roleElement,
getTrxName(ctx));
}
if (roleid <= 0)
{
element.defer = true;
element.unresolved = "AD_Role_ID";
return;
}
Element orgElement = element.properties.get(I_AD_User_Roles.COLUMNNAME_AD_Org_ID);
orgid = ReferenceUtils.resolveReference(ctx.ctx, orgElement, getTrxName(ctx));
if (!hasUUIDKey(ctx, element)) {
Query query = new Query(ctx.ctx, "AD_User_Roles", "AD_User_ID = ? AND AD_Role_ID = ? AND AD_Org_ID = ?", getTrxName(ctx));
po = query.setParameters(new Object[]{userid, roleid, orgid}).first();
}
if (po == null) {
po = new X_AD_User_Roles(ctx.ctx, 0, getTrxName(ctx));
po.setAD_Org_ID(orgid);
po.setAD_Role_ID(roleid);
po.setAD_User_ID(userid);
}
excludes.add(I_AD_User_Roles.COLUMNNAME_AD_User_ID);
excludes.add(I_AD_User_Roles.COLUMNNAME_AD_Role_ID);
excludes.add(I_AD_User_Roles.COLUMNNAME_AD_Org_ID);
po = new X_AD_User_Roles(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> notfounds = filler.autoFill(excludes);
@ -116,6 +74,7 @@ public class UserRoleElementHandler extends AbstractElementHandler {
return;
}
}
verifyPackOutRequirement(po);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", I_AD_User_Roles.Table_Name, atts);
@ -127,15 +86,11 @@ public class UserRoleElementHandler extends AbstractElementHandler {
private void createUserAssignBinding(PIPOContext ctx,
TransformerHandler document, X_AD_User_Roles po) {
PoExporter filler = new PoExporter(ctx, document, po);
AttributesImpl orgRefAtts = new AttributesImpl();
String orgReference = ReferenceUtils.getTableReference("AD_Org", "Name", po.getAD_Org_ID(), orgRefAtts);
filler.addString("AD_Org_ID", orgReference, orgRefAtts);
verifyPackOutRequirement(po);
List<String> excludes = defaultExcludeList(X_AD_User_Roles.Table_Name);
excludes.add("AD_Org_ID");
filler.export(excludes);
filler.export(excludes, true);
}
@Override

View File

@ -26,8 +26,6 @@ import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_Role;
import org.compiere.model.I_AD_Window_Access;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Role;
@ -40,41 +38,11 @@ import org.xml.sax.helpers.AttributesImpl;
public class WindowAccessElementHandler extends AbstractElementHandler {
public void startElement(PIPOContext ctx, Element element) throws SAXException {
int roleid =0;
int windowid =0;
List<String> excludes = defaultExcludeList(X_AD_Window_Access.Table_Name);
X_AD_Window_Access po = findPO(ctx, element);
if (po == null) {
if (getParentId(element, I_AD_Role.Table_Name) > 0) {
roleid = getParentId(element, I_AD_Role.Table_Name);
} else {
Element roleElement = element.properties.get(I_AD_Window_Access.COLUMNNAME_AD_Role_ID);
roleid = ReferenceUtils.resolveReference(ctx.ctx, roleElement, getTrxName(ctx));
}
if (roleid <= 0) {
element.defer = true;
element.unresolved = "AD_Role_ID";
return;
}
Element windowElement = element.properties.get(I_AD_Window_Access.COLUMNNAME_AD_Window_ID);
windowid = ReferenceUtils.resolveReference(ctx.ctx, windowElement, getTrxName(ctx));
if (windowid <= 0) {
element.defer = true;
element.unresolved = "AD_Window_ID";
return;
}
if (!hasUUIDKey(ctx, element)) {
Query query = new Query(ctx.ctx, "AD_Window_Access", "AD_Role_ID=? and AD_Window_ID=?", getTrxName(ctx));
po = query.setParameters(new Object[]{roleid, windowid}).first();
}
if (po == null) {
po = new X_AD_Window_Access(ctx.ctx, 0, getTrxName(ctx));
po.setAD_Role_ID(roleid);
po.setAD_Window_ID(windowid);
}
po = new X_AD_Window_Access(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> notfounds = filler.autoFill(excludes);
@ -101,6 +69,7 @@ public class WindowAccessElementHandler extends AbstractElementHandler {
return;
}
}
verifyPackOutRequirement(po);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Window_Access.Table_Name, atts);

View File

@ -63,25 +63,13 @@ public class WindowElementHandler extends AbstractElementHandler {
if (isProcessElement(ctx.ctx, entitytype)) {
MWindow mWindow = findPO(ctx, element);
if (mWindow == null) {
int id = 0;
String name = getStringValue(element, "Name", excludes);
if (!hasUUIDKey(ctx, element)) {
id = findIdByName(ctx, "AD_Window", name);
if (id > 0 && windows.contains(id)) {
return;
}
}
mWindow = new MWindow(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
mWindow.setName(name);
mWindow = new MWindow(ctx.ctx, 0, getTrxName(ctx));
} else {
if (windows.contains(mWindow.getAD_Window_ID())) {
return;
}
}
if (mWindow.getAD_Window_ID() == 0 && isOfficialId(element, "AD_Window_ID"))
mWindow.setAD_Window_ID(getIntValue(element, "AD_Window_ID"));
PoFiller filler = new PoFiller(ctx, mWindow, element, this);
List<String> notfounds = filler.autoFill(excludes);
@ -162,6 +150,7 @@ public class WindowElementHandler extends AbstractElementHandler {
}
if (createElement) {
verifyPackOutRequirement(m_Window);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Window.Table_Name, atts);

View File

@ -26,8 +26,6 @@ import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_Role;
import org.compiere.model.I_AD_Workflow_Access;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Role;
@ -41,43 +39,11 @@ import org.xml.sax.helpers.AttributesImpl;
public class WorkflowAccessElementHandler extends AbstractElementHandler {
public void startElement(PIPOContext ctx, Element element) throws SAXException {
int roleid =0;
int workflowid =0;
List<String> excludes = defaultExcludeList(X_AD_Workflow_Access.Table_Name);
MWorkflowAccess po = findPO(ctx, element);
if (po == null) {
if (getParentId(element, I_AD_Role.Table_Name) > 0) {
roleid = getParentId(element, I_AD_Role.Table_Name);
} else {
Element roleElement = element.properties.get(I_AD_Workflow_Access.COLUMNNAME_AD_Role_ID);
roleid = ReferenceUtils.resolveReference(ctx.ctx, roleElement, getTrxName(ctx));
}
if (roleid <= 0) {
element.defer = true;
element.unresolved = "AD_Role_ID";
return;
}
Element wfElement = element.properties.get(I_AD_Workflow_Access.COLUMNNAME_AD_Workflow_ID);
workflowid = ReferenceUtils.resolveReference(ctx.ctx, wfElement, getTrxName(ctx));
if (workflowid <= 0) {
element.defer = true;
element.unresolved = "AD_Workflow_ID";
}
if (!hasUUIDKey(ctx, element)) {
Query query = new Query(ctx.ctx, "AD_Workflow_Access", "AD_Role_ID=? and AD_Workflow_ID=?", getTrxName(ctx));
po = query.setParameters(new Object[]{roleid, workflowid}).first();
}
if (po == null) {
po = new MWorkflowAccess(ctx.ctx, 0, getTrxName(ctx));
po.setAD_Role_ID(roleid);
po.setAD_Workflow_ID(workflowid);
}
excludes.add(I_AD_Workflow_Access.COLUMNNAME_AD_Role_ID);
excludes.add(I_AD_Workflow_Access.COLUMNNAME_AD_Workflow_ID);
po = new MWorkflowAccess(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, po, element, this);
@ -106,6 +72,7 @@ public class WorkflowAccessElementHandler extends AbstractElementHandler {
return;
}
}
verifyPackOutRequirement(po);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", I_AD_Workflow_Access.Table_Name, atts);

View File

@ -63,23 +63,10 @@ public class WorkflowElementHandler extends AbstractElementHandler {
MWorkflow mWorkflow = findPO(ctx, element);
if (mWorkflow == null) {
int id = 0;
String workflowValue = getStringValue(element, "Value", excludes);
if (!hasUUIDKey(ctx, element)) {
id = findIdByColumn(ctx, "AD_Workflow", "Value", workflowValue);
if (id > 0 && workflows.contains(id)) {
element.skip = true;
return;
}
}
mWorkflow = new MWorkflow(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
mWorkflow.setValue(workflowValue);
mWorkflow = new MWorkflow(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mWorkflow, element, this);
if (mWorkflow.getAD_Workflow_ID() == 0 && isOfficialId(element, "AD_Workflow_ID"))
filler.setInteger("AD_Workflow_ID");
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;

View File

@ -28,13 +28,10 @@ import org.adempiere.pipo2.PIPOContext;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_WF_Node;
import org.compiere.model.I_AD_Workflow;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_WF_Node;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.wf.MWFNode;
import org.compiere.wf.MWorkflow;
@ -61,31 +58,7 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler {
MWFNode mWFNode = findPO(ctx, element);
if (mWFNode == null) {
int workflowId = 0;
Element wfElement = element.properties.get(I_AD_WF_Node.COLUMNNAME_AD_Workflow_ID);
if (getParentId(element, I_AD_Workflow.Table_Name) > 0) {
workflowId = getParentId(element, I_AD_Workflow.Table_Name);
} else {
workflowId = ReferenceUtils.resolveReference(ctx.ctx, wfElement, getTrxName(ctx));
}
if (workflowId <= 0) {
element.defer = true;
element.unresolved = "AD_Workflow: " + wfElement.contents;
return;
}
String workflowNodeValue = getStringValue(element, "Value", excludes);
int id = 0;
if (!hasUUIDKey(ctx, element)) {
StringBuilder sqlB = new StringBuilder(
"SELECT AD_WF_Node_ID FROM AD_WF_Node WHERE AD_Workflow_ID=? and Value =?");
id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), workflowId, workflowNodeValue);
}
mWFNode = new MWFNode(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
mWFNode.setValue(workflowNodeValue);
mWFNode.setAD_Workflow_ID(workflowId);
excludes.add(I_AD_WF_Node.COLUMNNAME_AD_Workflow_ID);
excludes.add("Value");
mWFNode = new MWFNode(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mWFNode, element, this);
@ -100,8 +73,6 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_WF_Node.Table_Name,
X_AD_WF_Node.Table_ID);
String action = null;
if (mWFNode.getAD_WF_Node_ID() == 0 && isOfficialId(element, "AD_WF_Node_ID"))
mWFNode.setAD_WF_Node_ID(getIntValue(element, "AD_WF_Node_ID"));
if (!mWFNode.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_WF_Node.Table_Name, mWFNode);
action = "Update";
@ -143,6 +114,7 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler {
return;
}
}
verifyPackOutRequirement(m_WF_Node);
addTypeName(atts, "table");
document.startElement("", "", I_AD_WF_Node.Table_Name, atts);
createWorkflowNodeBinding(ctx, document, m_WF_Node);

View File

@ -26,18 +26,12 @@ import org.adempiere.pipo2.PIPOContext;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_WF_NextCondition;
import org.compiere.model.I_AD_Workflow;
import org.compiere.model.MColumn;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_WF_NextCondition;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.wf.MWFNextCondition;
import org.compiere.wf.MWFNode;
import org.compiere.wf.MWFNodeNext;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -57,53 +51,10 @@ public class WorkflowNodeNextConditionElementHandler extends
MWFNextCondition mWFNodeNextCondition = findPO(ctx, element);
if (mWFNodeNextCondition == null) {
int workflowId = 0;
Element wfElement = element.properties.get("AD_Workflow_ID");
if (getParentId(element, I_AD_Workflow.Table_Name) > 0) {
workflowId = getParentId(element, I_AD_Workflow.Table_Name);
} else {
workflowId = ReferenceUtils.resolveReference(ctx.ctx, wfElement, getTrxName(ctx));
}
if (workflowId <= 0) {
element.defer = true;
element.unresolved = "AD_Workflow: " + wfElement.contents;
return;
}
Element nextElement = element.properties.get("AD_WF_NodeNext_ID");
int wfNodeNextId = ReferenceUtils.resolveReference(ctx.ctx, nextElement, getTrxName(ctx));
if (wfNodeNextId <= 0) {
element.unresolved = "AD_WF_NodeNext=" + nextElement.contents;
element.defer = true;
return;
}
int id = 0;
if (!hasUUIDKey(ctx, element)) {
int seqNo = getIntValue(element, "SeqNo");
String sql = "SELECT AD_WF_NextCondition_ID FROM AD_WF_NextCondition WHERE AD_WF_NodeNext_ID =? AND SeqNo=?";
id = DB.getSQLValue(getTrxName(ctx), sql, new Object[] {wfNodeNextId, seqNo});
}
mWFNodeNextCondition = new MWFNextCondition(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx));
mWFNodeNextCondition.setAD_WF_NodeNext_ID(wfNodeNextId);
mWFNodeNextCondition = new MWFNextCondition(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mWFNodeNextCondition, element, this);
if (mWFNodeNextCondition.get_ID() == 0 && isOfficialId(element, "AD_WF_NextCondition_ID"))
filler.setInteger("AD_WF_NextCondition_ID");
Element tableElement = element.properties.get("AD_Table_ID");
Element columnElement = element.properties.get("AD_Column_ID");
int columnId = 0;
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) {
columnId = ReferenceUtils.resolveReference(ctx.ctx, columnElement, getTrxName(ctx));
} else {
int AD_Table_ID = ReferenceUtils.resolveReference(ctx.ctx, tableElement, getTrxName(ctx));
columnId = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnElement.contents.toString(), "AD_Table", AD_Table_ID);
}
mWFNodeNextCondition.setAD_Column_ID(columnId);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
@ -164,6 +115,7 @@ public class WorkflowNodeNextConditionElementHandler extends
return;
}
}
verifyPackOutRequirement(m_WF_NodeNextCondition);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", I_AD_WF_NextCondition.Table_Name, atts);
@ -178,32 +130,6 @@ public class WorkflowNodeNextConditionElementHandler extends
if (mWFNodeNextCondition.getAD_WF_NextCondition_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_WF_NextCondition_ID", new AttributesImpl());
MWFNodeNext mWFNodeNext = new MWFNodeNext(ctx.ctx, mWFNodeNextCondition.getAD_WF_NodeNext_ID(), getTrxName(ctx));
MWFNode mWFNode = new MWFNode(ctx.ctx, mWFNodeNext.getAD_WF_Node_ID(), getTrxName(ctx));
int AD_workflow_ID = mWFNode.getAD_Workflow_ID();
AttributesImpl wfAttributes = new AttributesImpl();
String value = ReferenceUtils.getTableReference("AD_Workflow", "Value", AD_workflow_ID, wfAttributes);
filler.addString("AD_Workflow_ID", value, wfAttributes);
int AD_WF_Node_ID = mWFNodeNext.getAD_WF_Node_ID();
AttributesImpl wfnAttributes = new AttributesImpl();
value = ReferenceUtils.getTableReference("AD_WF_Node", "Value", AD_WF_Node_ID, wfnAttributes);
filler.addString("AD_WF_Node_ID", value, wfnAttributes);
int AD_WF_Next_ID = mWFNodeNext.getAD_WF_Next_ID();
AttributesImpl nextAttributes = new AttributesImpl();
value = ReferenceUtils.getTableReference("AD_WF_Node", "Value", AD_WF_Next_ID, nextAttributes);
filler.addString("AD_WF_Next_ID", value, nextAttributes);
if (mWFNodeNextCondition.getAD_Column_ID() > 0) {
int AD_Column_ID = mWFNodeNextCondition.getAD_Column_ID();
MColumn mColumn = new MColumn(ctx.ctx, AD_Column_ID, getTrxName(ctx));
int AD_Table_ID = mColumn.getAD_Table_ID();
AttributesImpl tableAttributes = new AttributesImpl();
value = ReferenceUtils.getTableReference("AD_Table", "TableName", AD_Table_ID, tableAttributes);
filler.addString("AD_Table_ID", value, tableAttributes);
}
filler.export(excludes);
}

View File

@ -26,14 +26,10 @@ import org.adempiere.pipo2.PIPOContext;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_WF_Node;
import org.compiere.model.I_AD_WF_NodeNext;
import org.compiere.model.I_AD_Workflow;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_WF_NodeNext;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.wf.MWFNodeNext;
import org.xml.sax.SAXException;
@ -53,61 +49,10 @@ public class WorkflowNodeNextElementHandler extends AbstractElementHandler {
MWFNodeNext mWFNodeNext = findPO(ctx, element);
if (mWFNodeNext == null) {
int workflowId = 0;
Element wfElement = element.properties.get(I_AD_WF_Node.COLUMNNAME_AD_Workflow_ID);
if (getParentId(element, I_AD_Workflow.Table_Name) > 0) {
workflowId = getParentId(element, I_AD_Workflow.Table_Name);
} else {
workflowId = ReferenceUtils.resolveReference(ctx.ctx, wfElement, getTrxName(ctx));
}
if (workflowId <= 0) {
element.defer = true;
element.unresolved = "AD_Workflow: " + wfElement.contents;
return;
}
int wfNodeId = 0;
Element wfnElement = element.properties.get(I_AD_WF_NodeNext.COLUMNNAME_AD_WF_Node_ID);
if (ReferenceUtils.isIDLookup(wfnElement) || ReferenceUtils.isUUIDLookup(wfnElement)) {
wfNodeId = ReferenceUtils.resolveReference(ctx.ctx, wfnElement, getTrxName(ctx));
} else {
wfNodeId = DB.getSQLValue(getTrxName(ctx), "SELECT AD_WF_Node_Id FROM AD_WF_Node WHERE AD_Workflow_ID=? AND Value=? AND AD_Client_ID=?",
workflowId, wfnElement.contents.toString(), Env.getAD_Client_ID(ctx.ctx));
}
if (wfNodeId <= 0) {
element.defer = true;
element.unresolved = "AD_WF_Node: " + wfnElement.contents;
return;
}
int AD_WF_Next_ID = 0;
Element nextElement = element.properties.get(I_AD_WF_NodeNext.COLUMNNAME_AD_WF_Next_ID);
if (ReferenceUtils.isIDLookup(nextElement) || ReferenceUtils.isUUIDLookup(nextElement)) {
AD_WF_Next_ID = ReferenceUtils.resolveReference(ctx.ctx, nextElement, getTrxName(ctx));
} else {
AD_WF_Next_ID = DB.getSQLValue(getTrxName(ctx), "SELECT AD_WF_Node_Id FROM AD_WF_Node WHERE AD_Workflow_ID=? AND Value=? AND AD_Client_ID=?",
workflowId, nextElement.contents.toString(), Env.getAD_Client_ID(ctx.ctx));
}
if (AD_WF_Next_ID <= 0) {
element.defer = true;
element.unresolved = "AD_WF_Node: " + nextElement.contents;
return;
}
int AD_WF_NodeNext_ID = 0;
if (!hasUUIDKey(ctx, element)) {
AD_WF_NodeNext_ID = DB.getSQLValue(getTrxName(ctx), "SELECT AD_WF_NodeNext_ID FROM AD_WF_NodeNext WHERE AD_WF_Node_ID=? and AD_WF_NEXT_ID =?", wfNodeId, AD_WF_Next_ID);
}
mWFNodeNext = new MWFNodeNext(ctx.ctx, AD_WF_NodeNext_ID, getTrxName(ctx));
mWFNodeNext.setAD_WF_Node_ID(wfNodeId);
mWFNodeNext.setAD_WF_Next_ID(AD_WF_Next_ID);
mWFNodeNext = new MWFNodeNext(ctx.ctx, 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mWFNodeNext, element, this);
if (mWFNodeNext.getAD_WF_NodeNext_ID() == 0 && isOfficialId(element, "AD_WF_NodeNext_ID"))
mWFNodeNext.setAD_WF_NodeNext_ID(getIntValue(element, "AD_WF_NodeNext_ID"));
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
@ -155,6 +100,7 @@ public class WorkflowNodeNextElementHandler extends AbstractElementHandler {
return;
}
}
verifyPackOutRequirement(m_WF_NodeNext);
AttributesImpl atts = new AttributesImpl();
addTypeName(atts, "table");
document.startElement("", "", I_AD_WF_NodeNext.Table_Name, atts);
@ -173,9 +119,6 @@ public class WorkflowNodeNextElementHandler extends AbstractElementHandler {
if (m_WF_NodeNext.getAD_WF_NodeNext_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_WF_NodeNext_ID", new AttributesImpl());
int AD_Workflow_ID = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Workflow_ID FROM AD_WF_Node WHERE AD_WF_Node_ID=?", m_WF_NodeNext.getAD_WF_Node_ID());
filler.addTableReference("AD_Workflow_ID", "AD_Workflow", "Value", AD_Workflow_ID, new AttributesImpl());
filler.export(excludes);
}

View File

@ -29,6 +29,8 @@ import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.compiere.model.MColumn;
import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.model.POInfo;
import org.compiere.model.Query;
@ -37,6 +39,7 @@ import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Util;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -54,43 +57,6 @@ public abstract class AbstractElementHandler implements ElementHandler {
protected CLogger log = CLogger.getCLogger(getClass());
/**
* Get ID from Name for a table.
*
* @param tableName
* @param name
*
*/
public int findIdByName (PIPOContext ctx, String tableName, String name) {
return IDFinder.findIdByName(tableName, name, getClientId(ctx.ctx), getTrxName(ctx));
}
/**
* Get ID from column value for a table.
*
* @param tableName
* @param columName
* @param name
*/
public int findIdByColumn (PIPOContext ctx, String tableName, String columnName, Object value, boolean ignorecase) {
int id = 0;
if ("AD_Table".equals(tableName) && "TableName".equals(columnName) && value != null) {
id = ctx.packIn.getTableId(value.toString());
if (id <= 0) {
id = IDFinder.findIdByColumn(tableName, columnName, value, getClientId(ctx.ctx), ignorecase, getTrxName(ctx));
if (id > 0) {
ctx.packIn.addTable(value.toString(), id);
}
}
} else {
id = IDFinder.findIdByColumn(tableName, columnName, value, getClientId(ctx.ctx), ignorecase, getTrxName(ctx));
}
return id;
}
public int findIdByColumn (PIPOContext ctx, String tableName, String columnName, Object value) {
return findIdByColumn (ctx, tableName, columnName, value, false);
}
/**
* @param ctx
* @param type
@ -136,58 +102,6 @@ public abstract class AbstractElementHandler implements ElementHandler {
ctx.packIn.addImportDetail(detail);
}
/**
* Get ID from Name for a table with a parent name reference.
*
* @param tableName
* @param name
* @param tableNameMaster
* @param nameMaster
*/
public int findIdByNameAndParentName (PIPOContext ctx, String tableName, String name, String tableNameMaster, String nameMaster) {
return IDFinder.findIdByNameAndParentName(tableName, name, tableNameMaster, nameMaster, getClientId(ctx.ctx), getTrxName(ctx));
}
/**
* Get ID from column value for a table with a parent id reference.
*
* @param tableName
* @param name
* @param tableNameMaster
* @param nameMaster
*/
public int findIdByColumnAndParentId (PIPOContext ctx, String tableName, String columnName, String name, String tableNameMaster, int masterID) {
return IDFinder.findIdByColumnAndParentId(tableName, columnName, name, tableNameMaster, masterID, getClientId(ctx.ctx),
getTrxName(ctx));
}
/**
* Get ID from column value for a table with a parent id reference.
*
* @param tableName
* @param name
* @param tableNameMaster
* @param nameMaster
* @param ignoreCase
*/
public int findIdByColumnAndParentId (PIPOContext ctx, String tableName, String columnName, String name, String tableNameMaster, int masterID, boolean ignoreCase) {
return IDFinder.findIdByColumnAndParentId(tableName, columnName, name, tableNameMaster, masterID, getClientId(ctx.ctx),
ignoreCase, getTrxName(ctx));
}
/**
* Get ID from Name for a table with a parent reference ID.
*
* @param tableName
* @param name
* @param tableNameMaster
* @param masterID
*/
public int findIdByNameAndParentId (PIPOContext ctx, String tableName, String name, String tableNameMaster, int masterID) {
return IDFinder.findIdByNameAndParentId(tableName, name, tableNameMaster, masterID, getClientId(ctx.ctx), getTrxName(ctx));
}
/**
* Make backup copy of record.
*
@ -200,7 +114,8 @@ public abstract class AbstractElementHandler implements ElementHandler {
public void backupRecord(PIPOContext ctx, int AD_Package_Imp_Detail_ID, String tableName,PO from){
// Create new record
int tableID = findIdByColumn(ctx, "AD_Table", "TableName", tableName);
MTable mTable = MTable.get(ctx.ctx, tableName);
int tableID = mTable.getAD_Table_ID();
POInfo poInfo = POInfo.getPOInfo(ctx.ctx, tableID);
PreparedStatement pstmtReferenceId = DB.prepareStatement("SELECT AD_Reference_ID FROM AD_COLUMN WHERE AD_Column_ID = ?", getTrxName(ctx));
@ -210,7 +125,8 @@ public abstract class AbstractElementHandler implements ElementHandler {
for (int i = 0; i < poInfo.getColumnCount(); i++){
if (from.is_ValueChanged(i)) {
int columnID =findIdByColumnAndParentId (ctx, "AD_Column", "ColumnName", poInfo.getColumnName(i), "AD_Table", tableID);
MColumn mColumn = mTable.getColumn(poInfo.getColumnName(i));
int columnID = mColumn.getAD_Column_ID();
int referenceID=0;
@ -456,7 +372,6 @@ public abstract class AbstractElementHandler implements ElementHandler {
excludes.add("createdby");
excludes.add("updated");
excludes.add("updatedby");
excludes.add(tableName + "_ID");
return excludes;
}
@ -559,7 +474,7 @@ public abstract class AbstractElementHandler implements ElementHandler {
String idColumn = tableName + "_ID";
if (element.properties.containsKey(uuidColumn)) {
String uuid = element.properties.get(uuidColumn).contents.toString();
if (uuid != null && uuid.trim().length() == 36) {
if (uuid != null && uuid.trim().length() == 36) {
Query query = new Query(ctx.ctx, tableName, uuidColumn+"=?", getTrxName(ctx));
po = query.setParameters(uuid.trim()).firstOnly();
}
@ -574,8 +489,8 @@ public abstract class AbstractElementHandler implements ElementHandler {
}
return po;
}
protected boolean hasUUIDKey(PIPOContext ctx, Element element) {
protected boolean hasUUIDKey(PIPOContext ctx, Element element) {
String tableName = element.getElementValue();
String uuidColumn = PO.getUUIDColumnName(tableName);
String uuid = null;
@ -604,4 +519,12 @@ public abstract class AbstractElementHandler implements ElementHandler {
protected void addTypeName(AttributesImpl atts, String typeName) {
atts.addAttribute("", "", "type", "CDATA", typeName);
}
protected void verifyPackOutRequirement(PO po) {
String uidColumn = po.getUUIDColumnName();
String[] keys = po.get_KeyColumns();
if (Util.isEmpty((String)po.get_Value(uidColumn)) && (keys == null || keys.length != 1 || po.get_ID() > MTable.MAX_OFFICIAL_ID)) {
throw new IllegalStateException("2Pack doesn't work with record without official Id and UUID");
}
}
}

View File

@ -153,18 +153,18 @@ public class PoExporter {
addTextElement("IsActive", (Boolean)po.isActive() == true ? "true" : "false", atts);
}
public void addTableReference(String tableName, String searchColumn, AttributesImpl atts) {
public void addTableReference(String tableName, AttributesImpl atts) {
String columnName = tableName + "_ID";
addTableReference(columnName, tableName, searchColumn, atts);
addTableReference(columnName, tableName, atts);
}
public void addTableReference(String columnName, String tableName, String searchColumn, AttributesImpl atts) {
public void addTableReference(String columnName, String tableName, AttributesImpl atts) {
int id = po.get_Value(columnName) != null ? (Integer)po.get_Value(columnName) : 0;
addTableReference(columnName, tableName, searchColumn, id, atts);
addTableReference(columnName, tableName, id, atts);
}
public void addTableReference(String columnName, String tableName, String searchColumn, int id, AttributesImpl atts) {
String value = ReferenceUtils.getTableReference(tableName, searchColumn, id, atts);
public void addTableReference(String columnName, String tableName, int id, AttributesImpl atts) {
String value = ReferenceUtils.getTableReference(tableName, id, atts);
addString(columnName, value, atts);
}
@ -219,85 +219,50 @@ public class PoExporter {
if (exclude)
continue;
}
//only export official id
if (columnName.equalsIgnoreCase(info.getTableName()+"_ID")) {
int id = po.get_ID();
if (id > 0 && id <= MTable.MAX_OFFICIAL_ID) {
add(columnName, new AttributesImpl());
}
continue;
}
int displayType = info.getColumnDisplayType(i);
if (DisplayType.YesNo == displayType) {
add(columnName, false, new AttributesImpl());
} else if (DisplayType.TableDir == displayType || DisplayType.ID == displayType) {
String tableName = null;
String searchColumn = null;
if ("Record_ID".equalsIgnoreCase(columnName) && po.get_ColumnIndex("AD_Table_ID") >= 0) {
int AD_Table_ID = po.get_Value(po.get_ColumnIndex("AD_Table_ID")) != null
? (Integer)po.get_Value(po.get_ColumnIndex("AD_Table_ID")) : 0;
tableName = MTable.getTableName(ctx.ctx, AD_Table_ID);
searchColumn = tableName + "_ID";
} else if (po.get_TableName().equals("AD_TreeNode") && columnName.equals("Parent_ID")) {
int AD_Tree_ID = po.get_ValueAsInt("AD_Tree_ID");
int AD_Table_ID = DB.getSQLValue(po.get_TrxName(), "SELECT AD_Table_ID From AD_Tree WHERE AD_Tree_ID="+AD_Tree_ID);
tableName = MTable.getTableName(po.getCtx(), AD_Table_ID);
searchColumn = tableName+"_ID";
} else if (po.get_TableName().equals("AD_TreeNode") && columnName.equals("Node_ID")) {
int AD_Tree_ID = po.get_ValueAsInt("AD_Tree_ID");
int AD_Table_ID = DB.getSQLValue(po.get_TrxName(), "SELECT AD_Table_ID From AD_Tree WHERE AD_Tree_ID="+AD_Tree_ID);
tableName = MTable.getTableName(po.getCtx(), AD_Table_ID);
searchColumn = tableName+"_ID";
} else {
//remove _ID
searchColumn = columnName;
tableName = columnName.substring(0, columnName.length() - 3);
if (tableName.equalsIgnoreCase("ad_table")) {
searchColumn = "TableName";
} else if (tableName.equalsIgnoreCase("ad_column") || tableName.equalsIgnoreCase("ad_element")) {
searchColumn = "ColumnName";
}
}
if (searchColumn.endsWith("_ID")) {
int AD_Table_ID = MTable.getTable_ID(tableName);
POInfo pInfo = POInfo.getPOInfo(po.getCtx(), AD_Table_ID);
if (pInfo.getColumnIndex("Value") >= 0) {
searchColumn = "Value";
} else if (pInfo.getColumnIndex("Name") >= 0) {
searchColumn = "Name";
} else if (pInfo.getColumnIndex("DocumentNo") >= 0) {
searchColumn = "DocumentNo";
}
}
addTableReference(columnName, tableName, searchColumn, new AttributesImpl());
addTableReference(columnName, tableName, new AttributesImpl());
} else if (DisplayType.List == displayType) {
add(columnName, "", new AttributesImpl());
} else if (DisplayType.isLookup(displayType)) {
String searchColumn = null;
String tableName = null;
if ("Record_ID".equalsIgnoreCase(columnName) && po.get_ColumnIndex("AD_Table_ID") >= 0) {
int AD_Table_ID = po.get_Value(po.get_ColumnIndex("AD_Table_ID")) != null
? (Integer)po.get_Value(po.get_ColumnIndex("AD_Table_ID")) : 0;
tableName = MTable.getTableName(ctx.ctx, AD_Table_ID);
searchColumn = tableName + "_ID";
} else if (info.getColumnLookup(i) != null){
searchColumn = info.getColumnLookup(i).getColumnName();
tableName = searchColumn.substring(0, searchColumn.indexOf("."));
searchColumn = searchColumn.substring(searchColumn.indexOf(".")+1);
} else {
searchColumn = columnName;
}
if (searchColumn.endsWith("_ID")) {
if (tableName.equalsIgnoreCase("ad_table")) {
searchColumn = "TableName";
} else if (tableName.equalsIgnoreCase("ad_column") || tableName.equalsIgnoreCase("ad_element")){
searchColumn = "ColumnName";
} else {
int AD_Table_ID = MTable.getTable_ID(tableName);
POInfo pInfo = POInfo.getPOInfo(po.getCtx(), AD_Table_ID);
if (pInfo.getColumnIndex("Value") >= 0) {
searchColumn = "Value";
} else if (pInfo.getColumnIndex("Name") >= 0) {
searchColumn = "Name";
} else if (pInfo.getColumnIndex("DocumentNo") >= 0) {
searchColumn = "DocumentNo";
}
}
}
addTableReference(columnName, tableName, searchColumn, new AttributesImpl());
String lookupColumn = info.getColumnLookup(i).getColumnName();
tableName = lookupColumn.substring(0, lookupColumn.indexOf("."));
}
addTableReference(columnName, tableName, new AttributesImpl());
} else if (DisplayType.isLOB(displayType)) {
addBlob(columnName);
} else if (columnName.equals(po.getUUIDColumnName()) && po.get_Value(columnName) == null) {

View File

@ -7,10 +7,12 @@ import java.util.ArrayList;
import java.util.List;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.model.POInfo;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Util;
public class PoFiller{
@ -134,29 +136,6 @@ public class PoFiller{
po.set_ValueNoCheck(qName, bd);
}
public static int findTableReference(PIPOContext ctx, AbstractElementHandler handler, Element element, String qName) {
Element propertyElement = element.properties.get(qName);
if (propertyElement == null)
return 0;
int id = 0;
String value = propertyElement.contents.toString();
if (value != null && value.trim().length() > 0)
{
String[] names = qName.split("[.]");
if (names.length < 2)
return 0;
String columnName = names[0];
if (names.length != 3)
columnName = columnName + "_ID";
String tableName = names.length == 3 ? names[1] : names[0];
String searchColumn = names.length == 3 ? names[2] : names[1];
id = handler.findIdByColumn(ctx, tableName, searchColumn, value.trim());
}
return id;
}
/**
*
* @param qName
@ -236,7 +215,7 @@ public class PoFiller{
continue;
}
Element e = element.properties.get(qName);
if (ReferenceUtils.isTableLookup(e) || ReferenceUtils.isUUIDLookup(e)) {
if (ReferenceUtils.isLookup(e)) {
int id = setTableReference(qName);
if (id < 0) {
notFounds.add(qName);
@ -245,6 +224,17 @@ public class PoFiller{
int index = info.getColumnIndex(qName);
if (index < 0)
continue;
//only import official id
if (qName.equalsIgnoreCase(po.get_TableName()+"_ID")) {
String value = e != null ? e.contents.toString() : null;
Integer i = !Util.isEmpty(value) ? new Integer(value) : null;
if (i != null && i.intValue() > 0 && i.intValue() <= MTable.MAX_OFFICIAL_ID) {
setInteger(qName);
}
continue;
}
if (info.getColumnClass(index) == Boolean.class) {
setBoolean(qName);
} else if (info.getColumnClass(index) == BigDecimal.class){

View File

@ -1,13 +1,7 @@
package org.adempiere.pipo2;
import java.io.UnsupportedEncodingException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
import org.adempiere.exceptions.DBException;
import org.apache.commons.codec.binary.Hex;
import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.util.DB;
@ -29,17 +23,7 @@ public class ReferenceUtils {
String referenceKey = e.attributes.getValue("reference-key");
if (value != null && value.trim().length() > 0)
{
if (isTableLookup(e))
{
String[] names = referenceKey.split("[.]");
if (names.length < 2)
return 0;
String tableName = names[0];
String searchColumn = names[1];
return IDFinder.findIdByColumn(tableName, searchColumn, value.trim(), Env.getAD_Client_ID(ctx), trxName);
}
else if (isIDLookup(e))
if (isIDLookup(e))
{
int id = Integer.parseInt(value);
return id;
@ -50,7 +34,7 @@ public class ReferenceUtils {
}
else
{
throw new IllegalArgumentException("Unknown table reference type="+e.attributes.getValue("reference"));
throw new IllegalArgumentException("Unknown column reference type="+e.attributes.getValue("reference"));
}
}
else
@ -61,7 +45,7 @@ public class ReferenceUtils {
public static boolean isLookup(Element element)
{
if (isIDLookup(element) || isUUIDLookup(element) || isTableLookup(element))
if (isIDLookup(element) || isUUIDLookup(element))
return true;
else
return false;
@ -77,12 +61,7 @@ public class ReferenceUtils {
return "uuid".equals(element.attributes.getValue("reference"));
}
public static boolean isTableLookup(Element element)
{
return "table".equals(element.attributes.getValue("reference"));
}
public static String getTableReference(String tableName, String searchColumn, int id, AttributesImpl atts)
public static String getTableReference(String tableName, int id, AttributesImpl atts)
{
String keyColumn = tableName + "_ID";
if ( (id > 0 && id <= PackOut.MAX_OFFICIAL_ID)
@ -118,55 +97,11 @@ public class ReferenceUtils {
return value.trim();
}
}
//search column
if (searchColumn.indexOf(",") > 0) {
//composite search column
String value = "";
String[] columns = searchColumn.split("[,]");
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = DB.prepareStatement("SELECT " + searchColumn + " FROM " + tableName, null);
rs = stmt.executeQuery();
if (rs.next()) {
for(int i = 0; i < columns.length; i++) {
Object o = rs.getObject(i+1);
String s = o != null ? o.toString() : "";
if (s.length() > 0) {
char[] chars = Hex.encodeHex(s.getBytes("UTF-8"));
s = new String(chars);
}
if (i == 0) {
value = s;
} else {
value = value+","+s;
}
}
}
} catch (SQLException e) {
throw new DBException(e);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
} finally {
DB.close(rs, stmt);
}
StringBuilder buffer = new StringBuilder();
buffer.append(tableName).append(".").append(searchColumn);
atts.addAttribute("", "", "reference", "CDATA", "table");
atts.addAttribute("", "", "reference-key", "CDATA", buffer.toString());
return value;
} else {
String sql = "SELECT " + searchColumn + " FROM "
+ tableName + " WHERE " + keyColumn + " = ?";
String value = DB.getSQLValueString(null, sql, id);
StringBuilder buffer = new StringBuilder();
buffer.append(tableName).append(".").append(searchColumn);
atts.addAttribute("", "", "reference", "CDATA", "table");
atts.addAttribute("", "", "reference-key", "CDATA", buffer.toString());
return value;
}
}
//should never reach here
atts.addAttribute("", "", "reference", "CDATA", "id");
return "";
}
}