*refactoring. *support for official id and uuid

This commit is contained in:
Heng Sin Low 2010-07-26 16:30:17 +08:00
parent 77dd90d40f
commit fe50780448
47 changed files with 1931 additions and 1703 deletions

View File

@ -1,42 +0,0 @@
ad.menu=org.adempiere.pipo2.handler.MenuElementHandler
ad.window=org.adempiere.pipo2.handler.WindowElementHandler
ad.window.access=org.adempiere.pipo2.handler.WindowAccessElementHandler
ad.preference=org.adempiere.pipo2.handler.PreferenceElementHandler
ad.window.tab=org.adempiere.pipo2.handler.TabElementHandler
ad.tab.field=org.adempiere.pipo2.handler.FieldElementHandler
ad.process=org.adempiere.pipo2.handler.ProcessElementHandler
ad.process.parameter=org.adempiere.pipo2.handler.ProcessParaElementHandler
ad.process-access=org.adempiere.pipo2.handler.ProcessAccessElementHandler
ad.message=org.adempiere.pipo2.handler.MessageElementHandler
ad.dynamic-validation=org.adempiere.pipo2.handler.DynValRuleElementHandler
ad.workflow=org.adempiere.pipo2.handler.WorkflowElementHandler
ad.workflow.node=org.adempiere.pipo2.handler.WorkflowNodeElementHandler
ad.workflow.node.next=org.adempiere.pipo2.handler.WorkflowNodeNextElementHandler
ad.workflow.node.next-condition=org.adempiere.pipo2.handler.WorkflowNodeNextConditionElementHandler
ad.workflow-access=org.adempiere.pipo2.handler.WorkflowAccessElementHandler
ad.table=org.adempiere.pipo2.handler.TableElementHandler
ad.table.column=org.adempiere.pipo2.handler.ColumnElementHandler
ad.role=org.adempiere.pipo2.handler.RoleElementHandler
ad.user-role=org.adempiere.pipo2.handler.UserRoleElementHandler
ad.organization-role=org.adempiere.pipo2.handler.OrgRoleElementHandler
ad.form=org.adempiere.pipo2.handler.FormElementHandler
ad.form-access=org.adempiere.pipo2.handler.FormAccessElementHandler
ad.task=org.adempiere.pipo2.handler.TaskElementHandler
ad.task-access=org.adempiere.pipo2.handler.TaskAccessElementHandler
ad.import-format=org.adempiere.pipo2.handler.ImpFormatElementHandler
ad.import-format.row=org.adempiere.pipo2.handler.ImpFormatRowElementHandler
ad.code-snippet=org.adempiere.pipo2.handler.CodeSnipitElementHandler
ad.dist-file=org.adempiere.pipo2.handler.DistFileElementHandler
ad.report-view=org.adempiere.pipo2.handler.ReportViewElementHandler
ad.report-view.column=org.adempiere.pipo2.handler.ReportViewColElementHandler
ad.printformat=org.adempiere.pipo2.handler.PrintFormatElementHandler
ad.printformat.item=org.adempiere.pipo2.handler.PrintFormatItemElementHandler
ad.print-paper=org.adempiere.pipo2.handler.PrintPaperElementHandler
ad.SQLStatement=org.adempiere.pipo2.handler.SQLStatementElementHandler
ad.reference=org.adempiere.pipo2.handler.ReferenceElementHandler
ad.reference.list=org.adempiere.pipo2.handler.ReferenceListElementHandler
ad.reference.table=org.adempiere.pipo2.handler.ReferenceTableElementHandler
ad.fieldgroup=org.adempiere.pipo2.handler.FieldGroupElementHandler
ad.element=org.adempiere.pipo2.handler.AdElementHandler
ad.trl=org.adempiere.pipo2.handler.CommonTranslationHandler
ad.po.generic=org.adempiere.pipo2.handler.GenericPOElementHandler

View File

@ -1,23 +0,0 @@
#Properties files
ad,menu=org.adempiere.pipo2.handler.MenuElementHandler
ad.process=org.adempiere.pipo2.handler.ProcessElementHandler
ad.report-view=org.adempiere.pipo2.handler.ReportViewElementHandler
ad.po.generic=org.adempiere.pipo2.handler.GenericPOElementHandler
ad.table=org.adempiere.pipo2.handler.TableElementHandler
ad.form=org.adempiere.pipo2.handler.FormElementHandler
ad.window=org.adempiere.pipo2.handler.WindowElementHandler
ad.role=org.adempiere.pipo2.handler.RoleElementHandler
ad.SQLStatement=org.adempiere.pipo2.handler.SQLStatementElementHandler
ad.import-format=org.adempiere.pipo2.handler.ImpFormatElementHandler
ad.reference=org.adempiere.pipo2.handler.ReferenceElementHandler
ad.code-snippet=org.adempiere.pipo2.handler.CodeSnippetElementHandler
ad.workflow=org.adempiere.pipo2.handler.WorkflowElementHandler
ad.dynamic-validation=org.adempiere.pipo2.handler.DynValRuleElementHandler
ad.message=org.adempiere.pipo2.handler.MessageElementHandler
ad.printformat=org.adempiere.pipo2.handler.PrintFormatElementHandler
ad.printformat.item=org.adempiere.pipo2.handler.PrintFormatItemElementHandler
ad.print-paper=org.adempiere.pipo2.handler.PrintPaperElementHandler
ad.task=org.adempiere.pipo2.handler.TaskElementHandler
ad.fieldgroup=org.adempiere.pipo2.handler.FieldGroupElementHandler
ad.element=org.adempiere.pipo2.handler.AdElementHandler

View File

@ -31,6 +31,7 @@ import javax.xml.transform.sax.TransformerHandler;
import org.compiere.model.PO; import org.compiere.model.PO;
import org.compiere.model.POInfo; import org.compiere.model.POInfo;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Package_Imp_Backup; import org.compiere.model.X_AD_Package_Imp_Backup;
import org.compiere.model.X_AD_Package_Imp_Detail; import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
@ -227,7 +228,8 @@ public abstract class AbstractElementHandler implements ElementHandler {
backup.setAD_Column_ID(columnID); backup.setAD_Column_ID(columnID);
backup.setAD_Reference_ID(referenceID); backup.setAD_Reference_ID(referenceID);
backup.setColValue(from.get_Value(i) != null ? from.get_Value(i).toString() : null); Object value = from.get_ValueOld(i);
backup.setColValue(value != null ? value.toString() : null);
backup.saveEx(getTrxName(ctx)); backup.saveEx(getTrxName(ctx));
} }
@ -516,4 +518,37 @@ public abstract class AbstractElementHandler implements ElementHandler {
char[] contents = str != null ? str.toCharArray() : new char[0]; char[] contents = str != null ? str.toCharArray() : new char[0];
document.characters(contents,0,contents.length); document.characters(contents,0,contents.length);
} }
/**
* Find po by uuid or id
* @param <T>
* @param ctx
* @param element
* @return T
*/
protected <T extends PO> T findPO(Properties ctx, Element element) {
T po = null;
String tableName = element.getElementValue();
String uuidColumn = tableName + "_UU";
String idColumn = tableName + "_ID";
if (element.properties.containsKey(uuidColumn)) {
String uuid = element.properties.get(uuidColumn).contents.toString();
if (uuid != null && uuid.trim().length() == 36) {
Query query = new Query(ctx, tableName, uuidColumn+"=?", getTrxName(ctx));
po = query.setParameters(uuid.trim()).firstOnly();
}
} else if (element.properties.containsKey(idColumn)) {
String id = element.properties.get(idColumn).contents.toString();
if (id != null && id.trim().length() > 0) {
Query query = new Query(ctx, tableName, idColumn+"=?", getTrxName(ctx));
po = query.setParameters(id.trim()).firstOnly();
}
}
return po;
}
protected void addTypeName(AttributesImpl atts, String typeName) {
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", typeName);
}
} }

View File

@ -11,9 +11,7 @@ import org.compiere.model.MTable;
import org.compiere.model.PO; import org.compiere.model.PO;
import org.compiere.model.POInfo; import org.compiere.model.POInfo;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.DisplayType; import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;
@ -154,43 +152,19 @@ public class PoExporter {
} }
public void addTableReference(String tableName, String searchColumn, AttributesImpl atts) { public void addTableReference(String tableName, String searchColumn, AttributesImpl atts) {
addTableReference(tableName + "_ID", tableName, searchColumn, atts); String columnName = tableName + "_ID";
addTableReference(columnName, tableName, searchColumn, atts);
} }
public void addTableReference(String columnName, String tableName, String searchColumn, AttributesImpl atts) { public void addTableReference(String columnName, String tableName, String searchColumn, AttributesImpl atts) {
String keyColumn = tableName + "_ID";
String sql = "SELECT " + searchColumn + " FROM "
+ tableName + " WHERE " + keyColumn + " = ?";
int id = po.get_Value(columnName) != null ? (Integer)po.get_Value(columnName) : 0; int id = po.get_Value(columnName) != null ? (Integer)po.get_Value(columnName) : 0;
if (id > 0 && id <= PackOut.MAX_OFFICIAL_ID) addTableReference(columnName, tableName, searchColumn, id, atts);
{ }
atts.addAttribute("", "", "reference", "CDATA", "id");
String value = Integer.toString(id); public void addTableReference(String columnName, String tableName, String searchColumn, int id, AttributesImpl atts) {
String value = ReferenceUtils.getTableReference(tableName, searchColumn, id, atts);
addString(columnName, value, atts); addString(columnName, value, atts);
} }
else
{
MTable table = MTable.get(Env.getCtx(), tableName);
if (table.get_ColumnIndex(tableName + "_UU") >= 0 )
{
sql = "SELECT " + tableName + "_UU" + " FROM "
+ tableName + " WHERE " + keyColumn + " = ?";
String value = id > 0 ? DB.getSQLValueString(null, sql, id) : "";
atts.addAttribute("", "", "reference", "CDATA", "uuid");
atts.addAttribute("", "", "reference-key", "CDATA", tableName);
addString(columnName, value, atts);
}
else
{
String value = id > 0 ? DB.getSQLValueString(null, sql, id) : "";
StringBuffer buffer = new StringBuffer();
buffer.append(tableName).append(".").append(searchColumn);
atts.addAttribute("", "", "reference", "CDATA", "table");
atts.addAttribute("", "", "reference-key", "CDATA", buffer.toString());
addString(columnName, value, atts);
}
}
}
public void export(List<String> excludes) { public void export(List<String> excludes) {
export(excludes, false); export(excludes, false);
@ -269,19 +243,7 @@ public class PoExporter {
searchColumn = "DocumentNo"; searchColumn = "DocumentNo";
} }
} }
if (searchColumn.endsWith("_ID")) {
StringBuffer buffer = new StringBuffer();
if (!columnName.equals(searchColumn))
{
buffer.append(columnName).append(".");
}
buffer.append(tableName).append(".").append(searchColumn);
int id = po.get_Value(columnName) != null ? (Integer)po.get_Value(columnName) : 0;
String value = id > 0 ? Integer.toString(id) : "";
addString(buffer.toString(), value, new AttributesImpl());
} else {
addTableReference(columnName, tableName, searchColumn, new AttributesImpl()); addTableReference(columnName, tableName, searchColumn, new AttributesImpl());
}
} else if (DisplayType.List == displayType) { } else if (DisplayType.List == displayType) {
add(columnName, "", new AttributesImpl()); add(columnName, "", new AttributesImpl());
} else if (DisplayType.isLookup(displayType)) { } else if (DisplayType.isLookup(displayType)) {
@ -316,19 +278,7 @@ public class PoExporter {
} }
} }
} }
if (searchColumn.endsWith("_ID")) {
StringBuffer buffer = new StringBuffer();
if (!columnName.equals(searchColumn))
{
buffer.append(columnName).append(".");
}
buffer.append(tableName).append(".").append(searchColumn);
int id = po.get_Value(columnName) != null ? (Integer)po.get_Value(columnName) : 0;
String value = id > 0 ? Integer.toString(id) : "";
addString(buffer.toString(), value, new AttributesImpl());
} else {
addTableReference(columnName, tableName, searchColumn, new AttributesImpl()); addTableReference(columnName, tableName, searchColumn, new AttributesImpl());
}
} else if (DisplayType.isLOB(displayType)) { } else if (DisplayType.isLOB(displayType)) {
addBlob(columnName); addBlob(columnName);
} else { } else {

View File

@ -0,0 +1,113 @@
package org.adempiere.pipo2;
import java.util.Properties;
import org.compiere.model.MTable;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.helpers.AttributesImpl;
public class ReferenceUtils {
public static int resolveReference(Properties ctx, Element e)
{
String value = e.contents.toString();
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), null);
}
else if (isIDLookup(e))
{
int id = Integer.parseInt(value);
return id;
}
else if (isUUIDLookup(e))
{
return IDFinder.findIdByColumn(referenceKey, referenceKey + "_UU", value.trim(), Env.getAD_Client_ID(ctx), null);
}
else
{
throw new IllegalArgumentException("Unknown table reference type="+e.attributes.getValue("reference"));
}
}
else
{
return 0;
}
}
public static boolean isLookup(Element element)
{
if (isIDLookup(element) || isUUIDLookup(element) || isTableLookup(element))
return true;
else
return false;
}
public static boolean isIDLookup(Element element)
{
return "id".equals(element.properties.get("reference"));
}
public static boolean isUUIDLookup(Element element)
{
return "uuid".equals(element.properties.get("reference"));
}
public static boolean isTableLookup(Element element)
{
return "table".equals(element.properties.get("reference"));
}
public static String getTableReference(String tableName, String searchColumn, int id, AttributesImpl atts)
{
String keyColumn = tableName + "_ID";
String sql = "SELECT " + searchColumn + " FROM "
+ tableName + " WHERE " + keyColumn + " = ?";
if (id > 0 && id <= PackOut.MAX_OFFICIAL_ID)
{
atts.addAttribute("", "", "reference", "CDATA", "id");
String value = Integer.toString(id);
return value;
}
else if (id == 0)
{
atts.addAttribute("", "", "reference", "CDATA", "id");
return "";
}
else
{
MTable table = MTable.get(Env.getCtx(), tableName);
if (table.get_ColumnIndex(tableName + "_UU") >= 0 )
{
sql = "SELECT " + tableName + "_UU" + " FROM "
+ tableName + " WHERE " + keyColumn + " = ?";
String value = DB.getSQLValueString(null, sql, id);
if (value != null && value.trim().length() > 0)
{
atts.addAttribute("", "", "reference", "CDATA", "uuid");
atts.addAttribute("", "", "reference-key", "CDATA", tableName);
return value.trim();
}
}
String value = DB.getSQLValueString(null, sql, id);
StringBuffer buffer = new StringBuffer();
buffer.append(tableName).append(".").append(searchColumn);
atts.addAttribute("", "", "reference", "CDATA", "table");
atts.addAttribute("", "", "reference-key", "CDATA", buffer.toString());
return value;
}
}
}

View File

@ -32,6 +32,7 @@ import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.MPackageExp; import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail; import org.compiere.model.MPackageExpDetail;
import org.compiere.model.M_Element;
import org.compiere.model.X_AD_Element; import org.compiere.model.X_AD_Element;
import org.compiere.model.X_AD_Package_Imp_Detail; import org.compiere.model.X_AD_Package_Imp_Detail;
@ -55,44 +56,50 @@ public class AdElementHandler extends AbstractElementHandler implements IPackOut
if (isProcessElement(ctx, entitytype)) { if (isProcessElement(ctx, entitytype)) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Element.Table_Name, X_AD_Element.Table_ID); M_Element mElement = findPO(ctx, element);
if (mElement == null) {
int id = findIdByColumn(ctx, X_AD_Element.Table_Name, X_AD_Element.COLUMNNAME_ColumnName, ColumnName); int id = findIdByColumn(ctx, X_AD_Element.Table_Name, X_AD_Element.COLUMNNAME_ColumnName, ColumnName);
mElement = new M_Element(ctx, id, getTrxName(ctx));
X_AD_Element mAdElement = new X_AD_Element(ctx, id, getTrxName(ctx)); }
List<String> excludes = defaultExcludeList(X_AD_Element.Table_Name); List<String> excludes = defaultExcludeList(X_AD_Element.Table_Name);
if (id <= 0 && isOfficialId(element, "AD_Element_ID")) if (mElement.getAD_Element_ID() == 0 && isOfficialId(element, "AD_Element_ID"))
mAdElement.setAD_Element_ID(getIntValue(element, "AD_Element_ID")); mElement.setAD_Element_ID(getIntValue(element, "AD_Element_ID"));
if (id > 0) {
if (processedElements.contains(id)) { if (processedElements.contains(mElement.getAD_Element_ID())) {
element.skip = true; element.skip = true;
return; return;
} }
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), AD_ELEMENT, mAdElement);
action = "Update";
} else {
action = "New";
}
PoFiller pf = new PoFiller(ctx, mAdElement, element, this); PoFiller pf = new PoFiller(ctx, mElement, element, this);
List<String> notfounds = pf.autoFill(excludes); List<String> notfounds = pf.autoFill(excludes);
if (notfounds.size() > 0) { if (notfounds.size() > 0) {
element.defer = true; element.defer = true;
return; return;
} }
if (mAdElement.save(getTrxName(ctx)) == true) { if (mElement.is_new() || mElement.is_Changed()) {
logImportDetail(ctx, impDetail, 1, mAdElement.getName(), X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Element.Table_Name, X_AD_Element.Table_ID);
mAdElement.get_ID(), action); if (!mElement.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), AD_ELEMENT, mElement);
action = "Update";
} else {
action = "New";
}
element.recordId = mAdElement.getAD_Element_ID(); if (mElement.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mElement.getName(),
mElement.get_ID(), action);
processedElements.add(mAdElement.getAD_Element_ID()); element.recordId = mElement.getAD_Element_ID();
processedElements.add(mElement.getAD_Element_ID());
} else { } else {
logImportDetail(ctx, impDetail, 0, mAdElement.getName(), logImportDetail(ctx, impDetail, 0, mElement.getName(),
mAdElement.get_ID(), action); mElement.get_ID(), action);
throw new POSaveFailedException("Reference"); throw new POSaveFailedException("Reference");
} }
}
} else { } else {
element.skip = true; element.skip = true;
} }
@ -116,9 +123,8 @@ public class AdElementHandler extends AbstractElementHandler implements IPackOut
X_AD_Element m_AdElement = new X_AD_Element(ctx, adElement_id, null); X_AD_Element m_AdElement = new X_AD_Element(ctx, adElement_id, null);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.element");
atts.addAttribute("", "", "type-name", "CDATA", "ad.element"); document.startElement("", "", "AD_Element", atts);
document.startElement("", "", "element", atts);
createAdElementBinding(ctx, document, m_AdElement); createAdElementBinding(ctx, document, m_AdElement);
PackOut packOut = (PackOut)ctx.get("PackOutProcess"); PackOut packOut = (PackOut)ctx.get("PackOutProcess");
@ -132,7 +138,7 @@ public class AdElementHandler extends AbstractElementHandler implements IPackOut
log.info(e.toString()); log.info(e.toString());
} }
document.endElement("", "", "element"); document.endElement("", "", "AD_Element");
} }

View File

@ -204,8 +204,7 @@ public class CodeSnippetElementHandler extends AbstractElementHandler implements
String NewCode = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_New); String NewCode = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Package_Code_New);
String ReleaseNo = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo); String ReleaseNo = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.code-snippet");
atts.addAttribute("", "", "type-name", "CDATA", "ad.code-snippet");
createSnipitBinding(atts, FileDir, FileName, OldCode, NewCode, ReleaseNo); createSnipitBinding(atts, FileDir, FileName, OldCode, NewCode, ReleaseNo);
document.startElement("","","codesnippet",atts); document.startElement("","","codesnippet",atts);
document.endElement("","","codesnippet"); document.endElement("","","codesnippet");

View File

@ -29,11 +29,12 @@ import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackIn;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.DatabaseAccessException; import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Column;
import org.compiere.model.I_AD_Table;
import org.compiere.model.MColumn; import org.compiere.model.MColumn;
import org.compiere.model.MTable; import org.compiere.model.MTable;
import org.compiere.model.X_AD_Column; import org.compiere.model.X_AD_Column;
@ -50,52 +51,35 @@ public class ColumnElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) public void startElement(Properties ctx, Element element)
throws SAXException { throws SAXException {
PackIn packIn = (PackIn)ctx.get("PackInProcess");
int success = 0; int success = 0;
String entitytype = getStringValue(element, "EntityType"); String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) { if (isProcessElement(ctx, entitytype)) {
if (isParentDefer(element, "table")) { if (isParentDefer(element, I_AD_Table.Table_Name)) {
element.defer = true; element.defer = true;
return; return;
} }
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Column.Table_Name, X_AD_Column.Table_ID);
List<String> excludes = defaultExcludeList(X_AD_Column.Table_Name); List<String> excludes = defaultExcludeList(X_AD_Column.Table_Name);
String columnName = getStringValue(element, "ColumnName", excludes); String columnName = getStringValue(element, "ColumnName", excludes);
String tableName = getStringValue(element, "AD_Table_ID", excludes);
MColumn mColumn = findPO(ctx, element);
if (mColumn == null) {
int tableid = 0; int tableid = 0;
if (getParentId(element, "table") > 0) { if (getParentId(element, I_AD_Table.Table_Name) > 0) {
tableid = getParentId(element, "table"); tableid = getParentId(element, "table");
} else { } else {
tableid = packIn.getTableId(tableName); mColumn = new MColumn(ctx, 0, getTrxName(ctx));
PoFiller filler = new PoFiller(ctx, mColumn, element, this);
filler.setTableReference("AD_Table_ID");
tableid = mColumn.getAD_Table_ID();
} }
if (tableid <= 0) { int AD_Column_ID = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnName, "AD_Table", tableid);
tableid = findIdByColumn(ctx, "AD_Table", "TableName", tableName); mColumn = new MColumn(ctx, AD_Column_ID > 0 ? AD_Column_ID : 0, getTrxName(ctx));
if (tableid > 0) if (mColumn.getAD_Column_ID() == 0 && isOfficialId(element, "AD_Column_ID")) {
packIn.addTable(tableName, tableid);
}
int id = packIn.getColumnId(tableName, columnName);
if (id <= 0) {
id = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName",
columnName, "AD_Table", tableid);
if (id > 0) {
packIn.addColumn(tableName, columnName, id);
}
}
MColumn mColumn = new MColumn(ctx, id, getTrxName(ctx));
if (id <= 0 && isOfficialId(element, "AD_Column_ID")) {
mColumn.setAD_Column_ID(getIntValue(element, "AD_Column_ID")); mColumn.setAD_Column_ID(getIntValue(element, "AD_Column_ID"));
} }
String action = null;
if (id > 0) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), "AD_Column", mColumn);
action = "Update";
} else {
action = "New";
mColumn.setAD_Table_ID(tableid);
} }
mColumn.setColumnName(columnName); mColumn.setColumnName(columnName);
mColumn.setIsSyncDatabase(getStringValue(element, "IsSyncDatabase", excludes)); mColumn.setIsSyncDatabase(getStringValue(element, "IsSyncDatabase", excludes));
@ -106,6 +90,18 @@ public class ColumnElementHandler extends AbstractElementHandler {
return; return;
} }
if (!mColumn.is_new() && !mColumn.is_Changed())
return;
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Column.Table_Name, X_AD_Column.Table_ID);
String action = null;
if (!mColumn.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), "AD_Column", mColumn);
action = "Update";
} else {
action = "New";
}
// Setup Element. // Setup Element.
if (mColumn.getAD_Element_ID() == 0) { if (mColumn.getAD_Element_ID() == 0) {
X_AD_Element adElement = new X_AD_Element(ctx, 0, getTrxName(ctx)); X_AD_Element adElement = new X_AD_Element(ctx, 0, getTrxName(ctx));
@ -311,11 +307,10 @@ public class ColumnElementHandler extends AbstractElementHandler {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
X_AD_Column m_Column = new X_AD_Column(ctx, AD_Column_ID, X_AD_Column m_Column = new X_AD_Column(ctx, AD_Column_ID,
getTrxName(ctx)); getTrxName(ctx));
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.table.column");
atts.addAttribute("", "", "type-name", "CDATA", "ad.table.column"); document.startElement("", "", I_AD_Column.Table_Name, atts);
document.startElement("", "", "column", atts);
createColumnBinding(ctx, document, m_Column); createColumnBinding(ctx, document, m_Column);
document.endElement("", "", "column"); document.endElement("", "", I_AD_Column.Table_Name);
} }
private void createColumnBinding(Properties ctx, TransformerHandler document, private void createColumnBinding(Properties ctx, TransformerHandler document,

View File

@ -208,8 +208,7 @@ public class CommonTranslationHandler extends AbstractElementHandler implements
while(rs.next()){ while(rs.next()){
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.trl");
atts.addAttribute("", "", "type-name", "CDATA", "ad.trl");
document.startElement("", "", "trl", atts); document.startElement("", "", "trl", atts);
addTextProperty(null, SPECIAL_ATRRIBUTE_TABLE_NAME, parentTable); addTextProperty(null, SPECIAL_ATRRIBUTE_TABLE_NAME, parentTable);
getAttsForOneTrlRow(ctx, document, exportableColumns, rs); getAttsForOneTrlRow(ctx, document, exportableColumns, rs);

View File

@ -185,8 +185,7 @@ public class DistFileElementHandler extends AbstractElementHandler {
String Target_Directory = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory); String Target_Directory = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory);
String ReleaseNo = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo); String ReleaseNo = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.dist-file");
atts.addAttribute("", "", "type-name", "CDATA", "ad.dist-file");
document.startElement("","","distfile",atts); document.startElement("","","distfile",atts);
addTextProperty(document,"filename",FileName); addTextProperty(document,"filename",FileName);
addTextProperty(document,"sourceDirectory",Source_Directory); addTextProperty(document,"sourceDirectory",Source_Directory);

View File

@ -29,6 +29,7 @@ import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Val_Rule;
import org.compiere.model.MPackageExp; import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail; import org.compiere.model.MPackageExpDetail;
import org.compiere.model.X_AD_Package_Exp_Detail; import org.compiere.model.X_AD_Package_Exp_Detail;
@ -45,23 +46,16 @@ public class DynValRuleElementHandler extends AbstractElementHandler implements
public void startElement(Properties ctx, Element element) throws SAXException { public void startElement(Properties ctx, Element element) throws SAXException {
String entitytype = getStringValue(element, "EntityType"); String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) { if (isProcessElement(ctx, entitytype)) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Val_Rule.Table_Name,
X_AD_Val_Rule.Table_ID);
String name = getStringValue(element, "Name"); String name = getStringValue(element, "Name");
int id = findIdByColumn(ctx, "AD_Val_Rule", "Name", name);
X_AD_Val_Rule mValRule = new X_AD_Val_Rule(ctx, id, getTrxName(ctx)); X_AD_Val_Rule mValRule = findPO(ctx, element);
if (id <= 0 && isOfficialId(element, "AD_Val_Rule_ID")) if (mValRule == null)
{
int id = findIdByColumn(ctx, "AD_Val_Rule", "Name", name);
mValRule = new X_AD_Val_Rule(ctx, id > 0 ? id : 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")); mValRule.setAD_Val_Rule_ID(getIntValue(element, "AD_Val_Rule_ID"));
String action = null;
if (id > 0){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Val_Rule.Table_Name, mValRule);
action = "Update";
}
else{
action = "New";
}
List<String> excludes = defaultExcludeList(X_AD_Val_Rule.Table_Name); List<String> excludes = defaultExcludeList(X_AD_Val_Rule.Table_Name);
@ -72,6 +66,18 @@ public class DynValRuleElementHandler extends AbstractElementHandler implements
return; return;
} }
if (mValRule.is_new() || mValRule.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Val_Rule.Table_Name,
X_AD_Val_Rule.Table_ID);
String action = null;
if (!mValRule.is_new()){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Val_Rule.Table_Name, mValRule);
action = "Update";
}
else{
action = "New";
}
if (mValRule.save(getTrxName(ctx)) == true){ if (mValRule.save(getTrxName(ctx)) == true){
logImportDetail (ctx, impDetail, 1, mValRule.getName(), mValRule.get_ID(),action); logImportDetail (ctx, impDetail, 1, mValRule.getName(), mValRule.get_ID(),action);
} }
@ -79,6 +85,7 @@ public class DynValRuleElementHandler extends AbstractElementHandler implements
logImportDetail (ctx, impDetail, 0, mValRule.getName(), mValRule.get_ID(),action); logImportDetail (ctx, impDetail, 0, mValRule.getName(), mValRule.get_ID(),action);
throw new POSaveFailedException("Failed to save dynamic validation rule."); throw new POSaveFailedException("Failed to save dynamic validation rule.");
} }
}
} else { } else {
element.skip = true; element.skip = true;
} }
@ -96,11 +103,10 @@ public class DynValRuleElementHandler extends AbstractElementHandler implements
rules.add(AD_Val_Rule_ID); rules.add(AD_Val_Rule_ID);
X_AD_Val_Rule m_ValRule = new X_AD_Val_Rule (ctx, AD_Val_Rule_ID, null); X_AD_Val_Rule m_ValRule = new X_AD_Val_Rule (ctx, AD_Val_Rule_ID, null);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.dynamic-validation");
atts.addAttribute("", "", "type-name", "CDATA", "ad.dynamic-validation"); document.startElement("","",I_AD_Val_Rule.Table_Name, atts);
document.startElement("","","dynvalrule", atts);
createDynamicValidationRuleBinding(ctx,document,m_ValRule); createDynamicValidationRuleBinding(ctx,document,m_ValRule);
document.endElement("","","dynvalrule"); document.endElement("","",I_AD_Val_Rule.Table_Name);
} }

View File

@ -25,10 +25,12 @@ import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.IPackOutHandler; import org.adempiere.pipo2.IPackOutHandler;
import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackIn;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Field;
import org.compiere.model.I_AD_Tab;
import org.compiere.model.MField; import org.compiere.model.MField;
import org.compiere.model.X_AD_Field; import org.compiere.model.X_AD_Field;
import org.compiere.model.X_AD_Package_Imp_Detail; import org.compiere.model.X_AD_Package_Imp_Detail;
@ -41,68 +43,73 @@ public class FieldElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) public void startElement(Properties ctx, Element element)
throws SAXException { throws SAXException {
PackIn packIn = getPackInProcess(ctx);
String entitytype = getStringValue(element, "EntityType"); String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) { if (isProcessElement(ctx, entitytype)) {
if (isParentDefer(element, "tab")) { if (isParentDefer(element, I_AD_Tab.Table_Name)) {
element.defer = true; element.defer = true;
return; return;
} }
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Field.Table_Name,
X_AD_Field.Table_ID);
List<String>excludes = defaultExcludeList(X_AD_Field.Table_Name); List<String>excludes = defaultExcludeList(X_AD_Field.Table_Name);
int tabid = getParentId(element, "tab") ; int tabid = getParentId(element, I_AD_Tab.Table_Name) ;
if (tabid <= 0) { if (tabid <= 0) {
element.defer = true; element.defer = true;
return; return;
} }
String tableName = element.parent.properties.get("AD_Table_ID").contents.toString(); MField mField = findPO(ctx, element);
if (mField == null)
{
int AD_Table_ID = ReferenceUtils.resolveReference(ctx, element.parent.properties.get("AD_Table_ID"));
Element columnElement = element.parent.properties.get("AD_Column_ID");
int AD_Column_ID = 0;
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement))
{
AD_Column_ID = ReferenceUtils.resolveReference(ctx, columnElement);
}
else
{
String colname = getStringValue(element, "AD_Column_ID", excludes); String colname = getStringValue(element, "AD_Column_ID", excludes);
int columnid = packIn.getColumnId(tableName, colname); AD_Column_ID = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", colname, "AD_Table", AD_Table_ID);
if (columnid <= 0) {
int tableid = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Table_ID FROM AD_Tab WHERE AD_Tab_ID = ?", tabid);
columnid = findIdByColumnAndParentId(ctx, "AD_Column",
"ColumnName", colname, "AD_Table", tableid);
if (columnid > 0)
packIn.addColumn(tableName, colname, columnid);
}
if (columnid <= 0) {
element.defer = true;
return;
} }
StringBuffer sqlB = new StringBuffer( StringBuffer sqlB = new StringBuffer(
"select AD_Field_ID from AD_Field where AD_Column_ID = ") "select AD_Field_ID from AD_Field where AD_Column_ID = ")
.append(columnid) .append(AD_Column_ID)
.append(" and AD_Tab_ID = ?"); .append(" and AD_Tab_ID = ?");
int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), tabid); int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), tabid);
MField mField = new MField(ctx, id, getTrxName(ctx)); mField = new MField(ctx, id > 0 ? id : 0, getTrxName(ctx));
if (mField.is_new()) {
mField.setAD_Column_ID(AD_Column_ID);
mField.setAD_Tab_ID(tabid);
}
}
PoFiller filler = new PoFiller(ctx, mField, element, this); PoFiller filler = new PoFiller(ctx, mField, element, this);
if (id <= 0 && isOfficialId(element, "AD_Field_ID")) if (mField.getAD_Field_ID() == 0 && isOfficialId(element, "AD_Field_ID"))
{ {
filler.setInteger("AD_Field_ID"); filler.setInteger("AD_Field_ID");
} }
String action = null;
if (id > 0) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Field.Table_Name, mField);
action = "Update";
} else {
action = "New";
}
mField.setAD_Column_ID(columnid);
mField.setAD_Tab_ID(tabid);
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) { if (notfounds.size() > 0) {
element.defer = true; element.defer = true;
return; return;
} }
if (mField.is_new() || mField.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Field.Table_Name,
X_AD_Field.Table_ID);
String action = null;
if (!mField.is_new()){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), I_AD_Field.Table_Name, mField);
action = "Update";
}
else{
action = "New";
}
if (mField.save(getTrxName(ctx)) == true) { if (mField.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mField.getName(), mField logImportDetail(ctx, impDetail, 1, mField.getName(), mField
.get_ID(), action); .get_ID(), action);
@ -112,6 +119,7 @@ public class FieldElementHandler extends AbstractElementHandler {
.get_ID(), action); .get_ID(), action);
throw new POSaveFailedException("Failed to save field definition."); throw new POSaveFailedException("Failed to save field definition.");
} }
}
} else { } else {
element.skip = true; element.skip = true;
} }
@ -126,9 +134,8 @@ public class FieldElementHandler extends AbstractElementHandler {
X_AD_Field.COLUMNNAME_AD_Field_ID); X_AD_Field.COLUMNNAME_AD_Field_ID);
X_AD_Field m_Field = new X_AD_Field(ctx, AD_Field_ID, null); X_AD_Field m_Field = new X_AD_Field(ctx, AD_Field_ID, null);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.tab.field");
atts.addAttribute("", "", "type-name", "CDATA", "ad.tab.field"); document.startElement("", "", I_AD_Field.Table_Name, atts);
document.startElement("", "", "field", atts);
createFieldBinding(ctx, document, m_Field); createFieldBinding(ctx, document, m_Field);
PackOut packOut = (PackOut)ctx.get("PackOutProcess"); PackOut packOut = (PackOut)ctx.get("PackOutProcess");
@ -164,7 +171,7 @@ public class FieldElementHandler extends AbstractElementHandler {
log.info(e.toString()); log.info(e.toString());
} }
document.endElement("", "", "field"); document.endElement("", "", I_AD_Field.Table_Name);
} }
private void createFieldBinding(Properties ctx, TransformerHandler document, private void createFieldBinding(Properties ctx, TransformerHandler document,

View File

@ -30,6 +30,7 @@ import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_FieldGroup;
import org.compiere.model.MPackageExp; import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail; import org.compiere.model.MPackageExpDetail;
import org.compiere.model.X_AD_FieldGroup; import org.compiere.model.X_AD_FieldGroup;
@ -56,29 +57,23 @@ public class FieldGroupElementHandler extends AbstractElementHandler implements
if (isProcessElement(ctx, entitytype)) { if (isProcessElement(ctx, entitytype)) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_FieldGroup.Table_Name, X_AD_FieldGroup fieldGroup = findPO(ctx, element);
X_AD_FieldGroup.Table_ID); if (fieldGroup == null)
{
int id = findIdByColumn(ctx, X_AD_FieldGroup.Table_Name, X_AD_FieldGroup.COLUMNNAME_Name, name); int id = findIdByColumn(ctx, X_AD_FieldGroup.Table_Name, X_AD_FieldGroup.COLUMNNAME_Name, name);
fieldGroup = new X_AD_FieldGroup(ctx, id > 0 ? id : 0, getTrxName(ctx));
X_AD_FieldGroup fieldGroup = new X_AD_FieldGroup(ctx, id, }
getTrxName(ctx));
PoFiller pf = new PoFiller(ctx, fieldGroup, element, this); PoFiller pf = new PoFiller(ctx, fieldGroup, element, this);
List<String> excludes = defaultExcludeList(X_AD_FieldGroup.Table_Name); List<String> excludes = defaultExcludeList(X_AD_FieldGroup.Table_Name);
if (id <= 0 && isOfficialId(element, "AD_FieldGroup_ID")) if (fieldGroup.getAD_FieldGroup_ID() == 0 && isOfficialId(element, "AD_FieldGroup_ID"))
{ {
pf.setInteger("AD_FieldGroup_ID"); pf.setInteger("AD_FieldGroup_ID");
} }
if (id > 0) { if (processedFieldGroups.contains(fieldGroup.getAD_FieldGroup_ID())) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_FieldGroup.Table_Name, fieldGroup);
action = "Update";
if (processedFieldGroups.contains(id)) {
element.skip = true; element.skip = true;
return; return;
} }
} else {
action = "New";
}
List<String> notfounds = pf.autoFill(excludes); List<String> notfounds = pf.autoFill(excludes);
if (notfounds.size() > 0) { if (notfounds.size() > 0) {
@ -86,6 +81,16 @@ public class FieldGroupElementHandler extends AbstractElementHandler implements
return; return;
} }
if (fieldGroup.is_new() || fieldGroup.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_FieldGroup.Table_Name,
X_AD_FieldGroup.Table_ID);
if (!fieldGroup.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_FieldGroup.Table_Name, fieldGroup);
action = "Update";
} else {
action = "New";
}
if (fieldGroup.save(getTrxName(ctx)) == true) { if (fieldGroup.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, fieldGroup.getName(), logImportDetail(ctx, impDetail, 1, fieldGroup.getName(),
fieldGroup.get_ID(), action); fieldGroup.get_ID(), action);
@ -99,6 +104,7 @@ public class FieldGroupElementHandler extends AbstractElementHandler implements
fieldGroup.get_ID(), action); fieldGroup.get_ID(), action);
throw new POSaveFailedException("Reference"); throw new POSaveFailedException("Reference");
} }
}
} else { } else {
element.skip = true; element.skip = true;
} }
@ -122,9 +128,8 @@ public class FieldGroupElementHandler extends AbstractElementHandler implements
X_AD_FieldGroup fieldGroup = new X_AD_FieldGroup(ctx, fieldGroup_id, null); X_AD_FieldGroup fieldGroup = new X_AD_FieldGroup(ctx, fieldGroup_id, null);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.field-group");
atts.addAttribute("", "", "type-name", "CDATA", "ad.field-group"); document.startElement("", "", I_AD_FieldGroup.Table_Name, atts);
document.startElement("", "", "fieldgroup", atts);
createAdElementBinding(ctx, document, fieldGroup); createAdElementBinding(ctx, document, fieldGroup);
@ -137,7 +142,7 @@ public class FieldGroupElementHandler extends AbstractElementHandler implements
{ {
log.info(e.toString()); log.info(e.toString());
} }
document.endElement("", "", "fieldgroup"); document.endElement("", "", I_AD_FieldGroup.Table_Name);
} }

View File

@ -25,12 +25,14 @@ import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PoFiller; 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.MFormAccess;
import org.compiere.model.Query; import org.compiere.model.Query;
import org.compiere.model.X_AD_Form; import org.compiere.model.X_AD_Form;
import org.compiere.model.X_AD_Form_Access; import org.compiere.model.X_AD_Form_Access;
import org.compiere.model.X_AD_Role; import org.compiere.model.X_AD_Role;
import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;
@ -40,37 +42,40 @@ public class FormAccessElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) throws SAXException { public void startElement(Properties ctx, Element element) throws SAXException {
List<String> excludes = defaultExcludeList(X_AD_Form_Access.Table_Name); List<String> excludes = defaultExcludeList(X_AD_Form_Access.Table_Name);
int roleId = 0; MFormAccess po = findPO(ctx, element);
String roleName = getStringValue(element, "rolename", excludes); if (po == null) {
if (getParentId(element, "role") > 0) { int AD_Role_ID = 0;
roleId = getParentId(element, "role"); if (getParentId(element, I_AD_Role.Table_Name) > 0) {
AD_Role_ID = getParentId(element, I_AD_Role.Table_Name);
} else { } else {
roleId = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Role_ID FROM AD_Role WHERE Name= ? AND AD_Client_ID = ?", roleName, Env.getAD_Client_ID(ctx)); AD_Role_ID = ReferenceUtils.resolveReference(ctx, element.properties.get("AD_Role_ID"));
} }
if (roleId <= 0) if (AD_Role_ID <= 0)
{ {
element.defer = true; element.defer = true;
return; return;
} }
String formName = getStringValue(element, "formname", excludes); int AD_Form_ID = ReferenceUtils.resolveReference(ctx, element.properties.get("AD_Form_ID"));
int formId = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Form_ID FROM AD_Form WHERE Name= ? AND AD_Client_ID = ?", formName, Env.getAD_Client_ID(ctx)); if (AD_Form_ID <= 0)
if (formId <= 0)
{ {
element.defer = true; element.defer = true;
return; return;
} }
MFormAccess po = null;
Query query = new Query(ctx, "AD_Form_Access", "AD_Form_ID = ? AND AD_Role_ID = ?", getTrxName(ctx)); Query query = new Query(ctx, "AD_Form_Access", "AD_Form_ID = ? AND AD_Role_ID = ?", getTrxName(ctx));
po = query.setParameters(new Object[]{formId, roleId}) po = query.setParameters(new Object[]{AD_Form_ID, AD_Role_ID})
.setClient_ID() .setClient_ID()
.<MFormAccess>first(); .<MFormAccess>first();
if (po == null) if (po == null)
{ {
po = new MFormAccess(ctx, 0, null); po = new MFormAccess(ctx, 0, null);
po.setAD_Form_ID(formId); po.setAD_Form_ID(AD_Form_ID);
po.setAD_Role_ID(roleId); po.setAD_Role_ID(AD_Role_ID);
}
excludes.add("AD_Form_ID");
excludes.add("AD_Role_ID");
} }
PoFiller filler = new PoFiller(ctx, po, element, this); PoFiller filler = new PoFiller(ctx, po, element, this);
@ -90,11 +95,10 @@ public class FormAccessElementHandler extends AbstractElementHandler {
int AD_Form_ID = Env.getContextAsInt(ctx, X_AD_Form.COLUMNNAME_AD_Form_ID); int AD_Form_ID = Env.getContextAsInt(ctx, X_AD_Form.COLUMNNAME_AD_Form_ID);
int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.form-access");
atts.addAttribute("", "", "type-name", "CDATA", "ad.form-access"); document.startElement("", "", I_AD_Form_Access.Table_Name, atts);
document.startElement("", "", "formaccess", atts);
createFormAccessBinding(ctx, document, AD_Form_ID, AD_Role_ID); createFormAccessBinding(ctx, document, AD_Form_ID, AD_Role_ID);
document.endElement("", "", "formaccess"); document.endElement("", "", I_AD_Form_Access.Table_Name);
} }
private void createFormAccessBinding(Properties ctx, TransformerHandler document, private void createFormAccessBinding(Properties ctx, TransformerHandler document,
@ -105,12 +109,6 @@ public class FormAccessElementHandler extends AbstractElementHandler {
if (po != null) { if (po != null) {
PoExporter filler = new PoExporter(ctx, document, po); PoExporter filler = new PoExporter(ctx, document, po);
List<String> excludes = defaultExcludeList(X_AD_Form_Access.Table_Name); List<String> excludes = defaultExcludeList(X_AD_Form_Access.Table_Name);
excludes.add("AD_Form_ID");
excludes.add("AD_Role_ID");
String name = DB.getSQLValueString(getTrxName(ctx), "SELECT Name FROM AD_Form WHERE AD_Form_ID = ?", formId);
filler.addString("formname", name, new AttributesImpl());
name = DB.getSQLValueString(getTrxName(ctx), "SELECT Name FROM AD_Role WHERE AD_Role_ID = ?", roleId);
filler.addString("rolename", name, new AttributesImpl());
filler.export(excludes); filler.export(excludes);
} }
} }

View File

@ -30,6 +30,7 @@ import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Form;
import org.compiere.model.MForm; import org.compiere.model.MForm;
import org.compiere.model.MPackageExp; import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail; import org.compiere.model.MPackageExpDetail;
@ -49,30 +50,36 @@ public class FormElementHandler extends AbstractElementHandler implements IPackO
String entitytype = getStringValue(element, "EntityType"); String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) { if (isProcessElement(ctx, entitytype)) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Form.Table_Name, MForm mForm = findPO(ctx, element);
X_AD_Form.Table_ID); if (mForm == null) {
String name = getStringValue(element, "Name"); String name = getStringValue(element, "Name");
int id = findIdByName(ctx, "AD_Form", name); int id = findIdByName(ctx, "AD_Form", name);
MForm mForm = new MForm(ctx, id, getTrxName(ctx)); mForm = new MForm(ctx, id > 0 ? id : 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mForm, element, this); PoFiller filler = new PoFiller(ctx, mForm, element, this);
String action = null; if (mForm.getAD_Form_ID() == 0 && isOfficialId(element, "AD_Form_ID"))
if (id <= 0 && isOfficialId(element, "AD_Form_ID"))
{ {
filler.setInteger("AD_Form_ID"); filler.setInteger("AD_Form_ID");
} }
if (id > 0){
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mForm.is_new() || mForm.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Form.Table_Name,
X_AD_Form.Table_ID);
String action = null;
if (!mForm.is_new()){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Form.Table_Name, mForm); backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Form.Table_Name, mForm);
action = "Update"; action = "Update";
} }
else{ else{
action = "New"; action = "New";
} }
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mForm.save(getTrxName(ctx)) == true){ if (mForm.save(getTrxName(ctx)) == true){
logImportDetail (ctx, impDetail, 1, mForm.getName(), mForm.get_ID(), action); logImportDetail (ctx, impDetail, 1, mForm.getName(), mForm.get_ID(), action);
@ -81,6 +88,7 @@ public class FormElementHandler extends AbstractElementHandler implements IPackO
logImportDetail (ctx, impDetail, 0, mForm.getName(), mForm.get_ID(), action); logImportDetail (ctx, impDetail, 0, mForm.getName(), mForm.get_ID(), action);
throw new POSaveFailedException("Failed to save form definition"); throw new POSaveFailedException("Failed to save form definition");
} }
}
} else { } else {
element.skip = true; element.skip = true;
} }
@ -97,11 +105,10 @@ public class FormElementHandler extends AbstractElementHandler implements IPackO
forms.add(AD_Form_ID); forms.add(AD_Form_ID);
X_AD_Form m_Form = new X_AD_Form (ctx, AD_Form_ID, null); X_AD_Form m_Form = new X_AD_Form (ctx, AD_Form_ID, null);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.form");
atts.addAttribute("", "", "type-name", "CDATA", "ad.form"); document.startElement("","",I_AD_Form.Table_Name,atts);
document.startElement("","","form",atts);
createFormBinding(ctx, document, m_Form); createFormBinding(ctx, document, m_Form);
document.endElement("","","form"); document.endElement("","",I_AD_Form.Table_Name);
} }
private void createFormBinding(Properties ctx, TransformerHandler document, X_AD_Form m_Form) private void createFormBinding(Properties ctx, TransformerHandler document, X_AD_Form m_Form)

View File

@ -62,6 +62,8 @@ public class GenericPOElementHandler extends AbstractElementHandler implements I
public void startElement(Properties ctx, Element element) throws SAXException { public void startElement(Properties ctx, Element element) throws SAXException {
String tableName = element.getElementValue(); String tableName = element.getElementValue();
PO po = findPO(ctx, element);
if (po == null) {
MTable table = MTable.get(ctx, tableName); MTable table = MTable.get(ctx, tableName);
POInfo info = POInfo.getPOInfo(ctx, table.getAD_Table_ID()); POInfo info = POInfo.getPOInfo(ctx, table.getAD_Table_ID());
MColumn columns[] = table.getColumns(false); MColumn columns[] = table.getColumns(false);
@ -101,10 +103,11 @@ public class GenericPOElementHandler extends AbstractElementHandler implements I
} }
} }
Query query = new Query(ctx, table, whereClause.toString(), getTrxName(ctx)); Query query = new Query(ctx, table, whereClause.toString(), getTrxName(ctx));
PO po = query.setParameters(parameters).first(); po = query.setParameters(parameters).first();
if (po == null) { if (po == null) {
po = new GenericPO(tableName, ctx, 0); po = new GenericPO(tableName, ctx, 0);
} }
}
PoFiller filler = new PoFiller(ctx, po, element, this); PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> excludes = defaultExcludeList(tableName); List<String> excludes = defaultExcludeList(tableName);
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
@ -144,8 +147,7 @@ public class GenericPOElementHandler extends AbstractElementHandler implements I
int AD_Client_ID = po.getAD_Client_ID(); int AD_Client_ID = po.getAD_Client_ID();
if (AD_Client_ID != Env.getAD_Client_ID(ctx)) if (AD_Client_ID != Env.getAD_Client_ID(ctx))
continue; continue;
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.po.generic");
atts.addAttribute("", "", "type-name", "CDATA", "ad.po.generic");
document.startElement("","", tableName, atts); document.startElement("","", tableName, atts);
PoExporter filler = new PoExporter(ctx, document, po); PoExporter filler = new PoExporter(ctx, document, po);
filler.export(excludes); filler.export(excludes);

View File

@ -33,6 +33,7 @@ import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.DatabaseAccessException; import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_ImpFormat;
import org.compiere.model.MPackageExp; import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail; import org.compiere.model.MPackageExpDetail;
import org.compiere.model.X_AD_ImpFormat; import org.compiere.model.X_AD_ImpFormat;
@ -52,34 +53,39 @@ public class ImpFormatElementHandler extends AbstractElementHandler implements
public void startElement(Properties ctx, Element element) public void startElement(Properties ctx, Element element)
throws SAXException { throws SAXException {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_ImpFormat.Table_Name,
X_AD_ImpFormat.Table_ID);
String action = null;
List<String> excludes = defaultExcludeList(X_AD_ImpFormat.Table_Name); List<String> excludes = defaultExcludeList(X_AD_ImpFormat.Table_Name);
String name = getStringValue(element, "Name"); String name = getStringValue(element, "Name");
X_AD_ImpFormat mImpFormat = findPO(ctx, element);
if (mImpFormat == null) {
int id = findIdByName(ctx, "AD_ImpFormat", name); int id = findIdByName(ctx, "AD_ImpFormat", name);
X_AD_ImpFormat mImpFormat = new X_AD_ImpFormat(ctx, id, mImpFormat = new X_AD_ImpFormat(ctx, id > 0 ? id : 0,
getTrxName(ctx)); getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mImpFormat, element, this); PoFiller filler = new PoFiller(ctx, mImpFormat, element, this);
if (id <= 0 && isOfficialId(element, "AD_ImpFormat_ID")) if (mImpFormat.getAD_ImpFormat_ID() == 0 && isOfficialId(element, "AD_ImpFormat_ID"))
{ {
filler.setInteger("AD_ImpFormat_ID"); filler.setInteger("AD_ImpFormat_ID");
} }
if (id > 0) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_ImpFormat.Table_Name, mImpFormat);
action = "Update";
} else {
action = "New";
}
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) { if (notfounds.size() > 0) {
element.defer = true; element.defer = true;
return; return;
} }
if (mImpFormat.is_new() || mImpFormat.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_ImpFormat.Table_Name,
X_AD_ImpFormat.Table_ID);
String action = null;
if (!mImpFormat.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_ImpFormat.Table_Name, mImpFormat);
action = "Update";
} else {
action = "New";
}
if (mImpFormat.save(getTrxName(ctx)) == true) { if (mImpFormat.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mImpFormat.getName(), mImpFormat logImportDetail(ctx, impDetail, 1, mImpFormat.getName(), mImpFormat
.get_ID(), action); .get_ID(), action);
@ -89,6 +95,7 @@ public class ImpFormatElementHandler extends AbstractElementHandler implements
throw new POSaveFailedException("Failed to save Import Format."); throw new POSaveFailedException("Failed to save Import Format.");
} }
} }
}
public void endElement(Properties ctx, Element element) throws SAXException { public void endElement(Properties ctx, Element element) throws SAXException {
} }
@ -103,9 +110,8 @@ public class ImpFormatElementHandler extends AbstractElementHandler implements
formats.add(import_id); formats.add(import_id);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
X_AD_ImpFormat m_ImpFormat = new X_AD_ImpFormat(ctx, import_id, null); X_AD_ImpFormat m_ImpFormat = new X_AD_ImpFormat(ctx, import_id, null);
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.import-format");
atts.addAttribute("", "", "type-name", "CDATA", "ad.import-format"); document.startElement("", "", I_AD_ImpFormat.Table_Name, atts);
document.startElement("", "", "impformat", atts);
createImpFormatBinding(ctx, document, m_ImpFormat); createImpFormatBinding(ctx, document, m_ImpFormat);
String sql = "SELECT * FROM AD_ImpFormat_Row WHERE AD_ImpFormat_ID= " String sql = "SELECT * FROM AD_ImpFormat_Row WHERE AD_ImpFormat_ID= "
@ -127,7 +133,7 @@ public class ImpFormatElementHandler extends AbstractElementHandler implements
} finally { } finally {
DB.close(rs, pstmt); DB.close(rs, pstmt);
} }
document.endElement("", "", "impformat"); document.endElement("", "", I_AD_ImpFormat.Table_Name);
} }

View File

@ -26,8 +26,10 @@ import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.MTable; 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_ImpFormat_Row;
import org.compiere.model.X_AD_Package_Imp_Detail; import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.util.DB; import org.compiere.util.DB;
@ -42,17 +44,22 @@ public class ImpFormatRowElementHandler extends AbstractElementHandler {
String action = null; String action = null;
List<String> excludes = defaultExcludeList(X_AD_ImpFormat_Row.Table_Name); List<String> excludes = defaultExcludeList(X_AD_ImpFormat_Row.Table_Name);
if (isParentDefer(element, "impformat")) { if (isParentDefer(element, I_AD_ImpFormat.Table_Name)) {
element.defer = true; element.defer = true;
return; return;
} }
X_AD_ImpFormat_Row mImpFormatRow = findPO(ctx, element);
if (mImpFormatRow == null) {
int impFormatId = 0; int impFormatId = 0;
String impFormatName = getStringValue(element, "AD_ImpFormat.Name", excludes); if (getParentId(element, I_AD_ImpFormat.Table_Name) > 0) {
if (getParentId(element, "impformat") > 0) { impFormatId = getParentId(element, I_AD_ImpFormat.Table_Name);
impFormatId = getParentId(element, "impformat");
} else { } else {
impFormatId = findIdByName(ctx, "AD_ImpFormat", impFormatName); Element e = element.properties.get(I_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_ID);
if (ReferenceUtils.isIDLookup(e) || ReferenceUtils.isUUIDLookup(e))
impFormatId = ReferenceUtils.resolveReference(ctx, e);
else
impFormatId = findIdByName(ctx, "AD_ImpFormat", e.contents.toString());
} }
if (impFormatId <= 0) { if (impFormatId <= 0) {
@ -60,53 +67,67 @@ public class ImpFormatRowElementHandler extends AbstractElementHandler {
return; return;
} }
String tableName = getStringValue(element, "AD_Table.TableName", excludes); Element tableElement = element.properties.get(I_AD_ImpFormat.COLUMNNAME_AD_Table_ID);
int tableId = 0; int tableId = 0;
if (ReferenceUtils.isIDLookup(tableElement) || ReferenceUtils.isUUIDLookup(tableElement)) {
tableId = ReferenceUtils.resolveReference(ctx, tableElement);
} else {
String tableName = getStringValue(element, I_AD_ImpFormat.COLUMNNAME_AD_Table_ID, excludes);
if (tableName != null && tableName.trim().length() > 0) { if (tableName != null && tableName.trim().length() > 0) {
tableId = findIdByColumn(ctx, "AD_Table", "TableName", tableName); tableId = findIdByColumn(ctx, "AD_Table", "TableName", tableName);
}
if (tableId <= 0) { if (tableId <= 0) {
element.defer = true; element.defer = true;
return; return;
} }
} }
String columnName = getStringValue(element, "AD_Column.ColumnName", excludes); Element columnElement = element.properties.get(I_AD_ImpFormat_Row.COLUMNNAME_AD_Column_ID);
int columnId = 0; int columnId = 0;
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) {
columnId = ReferenceUtils.resolveReference(ctx, columnElement);
} else {
String columnName = getStringValue(element, I_AD_ImpFormat_Row.COLUMNNAME_AD_Column_ID, excludes);
if (columnName != null && columnName.trim().length() > 0) { if (columnName != null && columnName.trim().length() > 0) {
columnId = findIdByColumnAndParentId (ctx, "AD_Column","ColumnName", columnName, "AD_Table", tableId); columnId = findIdByColumnAndParentId (ctx, "AD_Column","ColumnName", columnName, "AD_Table", tableId);
}
if (columnId <= 0) { if (columnId <= 0) {
element.defer = true; element.defer = true;
return; return;
} }
} }
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_ImpFormat_Row.Table_Name,
X_AD_ImpFormat_Row.Table_ID);
StringBuffer sqlB = new StringBuffer ("SELECT AD_ImpFormat_Row_ID FROM AD_ImpFormat_Row WHERE AD_Column_ID=? AND AD_ImpFormat_ID=?"); StringBuffer sqlB = new StringBuffer ("SELECT AD_ImpFormat_Row_ID FROM AD_ImpFormat_Row WHERE AD_Column_ID=? AND AD_ImpFormat_ID=?");
int id = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),columnId,impFormatId); int id = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),columnId,impFormatId);
X_AD_ImpFormat_Row mImpFormatRow = new X_AD_ImpFormat_Row(ctx, id, getTrxName(ctx)); mImpFormatRow = new X_AD_ImpFormat_Row(ctx, id > 0 ? id : 0, getTrxName(ctx));
mImpFormatRow.setAD_Column_ID(columnId);
mImpFormatRow.setAD_ImpFormat_ID(impFormatId);
}
PoFiller filler = new PoFiller(ctx, mImpFormatRow, element, this); PoFiller filler = new PoFiller(ctx, mImpFormatRow, element, this);
if (id <= 0 && isOfficialId(element, "AD_ImpFormat_Row_ID")) if (mImpFormatRow.getAD_ImpFormat_Row_ID() == 0 && isOfficialId(element, "AD_ImpFormat_Row_ID"))
{ {
filler.setInteger("AD_ImpFormat_Row_ID"); filler.setInteger("AD_ImpFormat_Row_ID");
} }
if (id > 0){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_ImpFormat_Row.Table_Name, mImpFormatRow);
action = "Update";
}
else{
action = "New";
}
mImpFormatRow.setAD_Column_ID(columnId);
mImpFormatRow.setAD_ImpFormat_ID(impFormatId);
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) { if (notfounds.size() > 0) {
element.defer = true; element.defer = true;
return; return;
} }
if (mImpFormatRow.is_new() || mImpFormatRow.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_ImpFormat_Row.Table_Name,
X_AD_ImpFormat_Row.Table_ID);
if (!mImpFormatRow.is_new()){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_ImpFormat_Row.Table_Name, mImpFormatRow);
action = "Update";
}
else{
action = "New";
}
if (mImpFormatRow.save(getTrxName(ctx)) == true){ if (mImpFormatRow.save(getTrxName(ctx)) == true){
logImportDetail (ctx, impDetail, 1, mImpFormatRow.getName(), mImpFormatRow.get_ID(),action); logImportDetail (ctx, impDetail, 1, mImpFormatRow.getName(), mImpFormatRow.get_ID(),action);
} }
@ -115,6 +136,7 @@ public class ImpFormatRowElementHandler extends AbstractElementHandler {
throw new POSaveFailedException("Failed to import Import Format Row."); throw new POSaveFailedException("Failed to import Import Format Row.");
} }
} }
}
public void endElement(Properties ctx, Element element) throws SAXException { public void endElement(Properties ctx, Element element) throws SAXException {
} }
@ -124,11 +146,10 @@ public class ImpFormatRowElementHandler extends AbstractElementHandler {
int AD_ImpFormat_Row_ID = Env.getContextAsInt(ctx, X_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_Row_ID); int AD_ImpFormat_Row_ID = Env.getContextAsInt(ctx, X_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_Row_ID);
X_AD_ImpFormat_Row m_ImpFormat_Row = new X_AD_ImpFormat_Row (ctx, AD_ImpFormat_Row_ID, getTrxName(ctx)); X_AD_ImpFormat_Row m_ImpFormat_Row = new X_AD_ImpFormat_Row (ctx, AD_ImpFormat_Row_ID, getTrxName(ctx));
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.import-format.row");
atts.addAttribute("", "", "type-name", "CDATA", "ad.import-format.row"); document.startElement("","",I_AD_ImpFormat_Row.Table_Name,atts);
document.startElement("","","impformatrow",atts);
createImpFormatRowBinding(ctx,document,m_ImpFormat_Row); createImpFormatRowBinding(ctx,document,m_ImpFormat_Row);
document.endElement("","","impformatrow"); document.endElement("","",I_AD_ImpFormat_Row.Table_Name);
} }
private void createImpFormatRowBinding(Properties ctx, TransformerHandler document, X_AD_ImpFormat_Row m_ImpFormat_Row) private void createImpFormatRowBinding(Properties ctx, TransformerHandler document, X_AD_ImpFormat_Row m_ImpFormat_Row)
@ -138,15 +159,8 @@ public class ImpFormatRowElementHandler extends AbstractElementHandler {
String sql = null; String sql = null;
excludes.add("AD_Column_ID");
sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?";
String columnName = DB.getSQLValueString(null,sql,m_ImpFormat_Row.getAD_Column_ID());
filler.addString("AD_Column.ColumnName", columnName, new AttributesImpl());
sql = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?";
int tableId = DB.getSQLValue(null, sql,m_ImpFormat_Row.getAD_Column_ID()); int tableId = DB.getSQLValue(null, sql,m_ImpFormat_Row.getAD_Column_ID());
String tableName = MTable.getTableName(Env.getCtx(), tableId); filler.addTableReference("AD_Table_ID", "AD_Table", "TableName", tableId, new AttributesImpl());
filler.addString("AD_Table.TableName", tableName, new AttributesImpl());
if (m_ImpFormat_Row.getAD_ImpFormat_Row_ID() <= PackOut.MAX_OFFICIAL_ID) if (m_ImpFormat_Row.getAD_ImpFormat_Row_ID() <= PackOut.MAX_OFFICIAL_ID)
{ {

View File

@ -32,6 +32,8 @@ import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_Menu;
import org.compiere.model.MPackageExp; import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail; import org.compiere.model.MPackageExpDetail;
import org.compiere.model.X_AD_Menu; import org.compiere.model.X_AD_Menu;
@ -50,30 +52,20 @@ public class MenuElementHandler extends AbstractElementHandler implements IPackO
public void startElement(Properties ctx, Element element) public void startElement(Properties ctx, Element element)
throws SAXException { throws SAXException {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Menu.Table_Name,
X_AD_Menu.Table_ID);
String action = null;
List<String> excludes = defaultExcludeList(X_AD_Menu.Table_Name); List<String> excludes = defaultExcludeList(X_AD_Menu.Table_Name);
StringBuffer sqlB = null; X_AD_Menu mMenu = findPO(ctx, element);
if (mMenu == null) {
String menuName = getStringValue(element, "Name", excludes); String menuName = getStringValue(element, "Name");
int menuId = findIdByColumn(ctx, "AD_Menu", "Name", menuName); int menuId = findIdByColumn(ctx, "AD_Menu", "Name", menuName);
X_AD_Menu mMenu = new X_AD_Menu(ctx, menuId, getTrxName(ctx)); mMenu = new X_AD_Menu(ctx, menuId > 0 ? menuId : 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mMenu, element, this); PoFiller filler = new PoFiller(ctx, mMenu, element, this);
if (menuId <= 0 && isOfficialId(element, "AD_Menu_ID")) if (mMenu.getAD_Menu_ID() == 0 && isOfficialId(element, "AD_Menu_ID"))
{ {
filler.setInteger("AD_Menu_ID"); filler.setInteger("AD_Menu_ID");
} }
if (menuId > 0) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Menu.Table_Name, mMenu);
action = "Update";
} else {
action = "New";
}
mMenu.setName(menuName);
List<String> notFounds = filler.autoFill(excludes); List<String> notFounds = filler.autoFill(excludes);
if (notFounds.size() > 0) { if (notFounds.size() > 0) {
@ -81,6 +73,18 @@ public class MenuElementHandler extends AbstractElementHandler implements IPackO
return; return;
} }
if (!mMenu.is_new() && !mMenu.is_Changed())
return;
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Menu.Table_Name,
X_AD_Menu.Table_ID);
String action = null;
if (!mMenu.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Menu.Table_Name, mMenu);
action = "Update";
} else {
action = "New";
}
if (mMenu.save(getTrxName(ctx)) == true) { if (mMenu.save(getTrxName(ctx)) == true) {
try { try {
logImportDetail(ctx, impDetail, 1, mMenu.getName(), mMenu logImportDetail(ctx, impDetail, 1, mMenu.getName(), mMenu
@ -96,11 +100,19 @@ public class MenuElementHandler extends AbstractElementHandler implements IPackO
log.info("setmenu:" + e); log.info("setmenu:" + e);
} }
} }
String parent = getStringValue(element, "ADParentMenuNameID");
int parentId = findIdByName(ctx, "AD_Menu", parent);
Element parentElement = element.properties.get("Parent_ID");
int parentId = 0;
if (ReferenceUtils.isIDLookup(parentElement) || ReferenceUtils.isUUIDLookup(parentElement)) {
parentId = ReferenceUtils.resolveReference(ctx, parentElement);
} else {
String parent = getStringValue(element, "Parent_ID");
parentId = findIdByName(ctx, "AD_Menu", parent);
}
StringBuffer updateSQL = null;
String sql = "SELECT count(Parent_ID) FROM AD_TREENODEMM WHERE AD_Tree_ID = 10" String sql = "SELECT count(Parent_ID) FROM AD_TREENODEMM WHERE AD_Tree_ID = 10"
+ " AND Node_ID = " + menuId; + " AND Node_ID = " + mMenu.getAD_Menu_ID();
int countRecords = DB.getSQLValue(getTrxName(ctx), sql); int countRecords = DB.getSQLValue(getTrxName(ctx), sql);
if (countRecords > 0) { if (countRecords > 0) {
sql = "select * from AD_TREENODEMM where AD_Tree_ID = 10 and " sql = "select * from AD_TREENODEMM where AD_Tree_ID = 10 and "
@ -110,7 +122,7 @@ public class MenuElementHandler extends AbstractElementHandler implements IPackO
try { try {
pstmt = DB.prepareStatement(sql, pstmt = DB.prepareStatement(sql,
getTrxName(ctx)); getTrxName(ctx));
pstmt.setInt(1, menuId); pstmt.setInt(1, mMenu.getAD_Menu_ID());
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) { if (rs.next()) {
@ -152,20 +164,20 @@ public class MenuElementHandler extends AbstractElementHandler implements IPackO
DB.close(rs, pstmt); DB.close(rs, pstmt);
} }
sqlB = new StringBuffer("UPDATE AD_TREENODEMM ").append( updateSQL = new StringBuffer("UPDATE AD_TREENODEMM ").append(
"SET Parent_ID = " + parentId).append( "SET Parent_ID = " + parentId).append(
" , SeqNo = " + getStringValue(element, "ADParentSeqno")).append( " , SeqNo = " + getStringValue(element, "SeqNo")).append(
" WHERE AD_Tree_ID = 10").append( " WHERE AD_Tree_ID = 10").append(
" AND Node_ID = " + mMenu.getAD_Menu_ID()); " AND Node_ID = " + mMenu.getAD_Menu_ID());
} else { } else {
sqlB = new StringBuffer("Insert INTO AD_TREENODEMM").append( updateSQL = new StringBuffer("Insert INTO AD_TREENODEMM").append(
"(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, ").append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, ").append(
"Parent_ID, SeqNo, AD_Tree_ID, Node_ID)").append( "Parent_ID, SeqNo, AD_Tree_ID, Node_ID)").append(
"VALUES(0, 0, 0, 0, ").append( "VALUES(0, 0, 0, 0, ").append(
parentId + "," + getStringValue(element, "ADParentSeqno") + ", 10, " parentId + "," + getStringValue(element, "SeqNo") + ", 10, "
+ mMenu.getAD_Menu_ID() + ")"); + mMenu.getAD_Menu_ID() + ")");
} }
DB.executeUpdateEx(sqlB.toString(), getTrxName(ctx)); DB.executeUpdateEx(updateSQL.toString(), getTrxName(ctx));
} }
public void endElement(Properties ctx, Element element) throws SAXException { public void endElement(Properties ctx, Element element) throws SAXException {
@ -179,12 +191,11 @@ public class MenuElementHandler extends AbstractElementHandler implements IPackO
createApplication(ctx, document, AD_Menu_ID); createApplication(ctx, document, AD_Menu_ID);
} else { } else {
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.menu");
atts.addAttribute("", "", "type-name", "CDATA", "ad.menu"); document.startElement("", "", I_AD_Menu.Table_Name, atts);
document.startElement("", "", "menu", atts);
createMenuBinding(ctx, document, m_Menu); createMenuBinding(ctx, document, m_Menu);
createModule(ctx, document, AD_Menu_ID); createModule(ctx, document, AD_Menu_ID);
document.endElement("", "", "menu"); document.endElement("", "", I_AD_Menu.Table_Name);
} }
} }
@ -193,18 +204,14 @@ public class MenuElementHandler extends AbstractElementHandler implements IPackO
PoExporter filler = new PoExporter(ctx, document, m_Menu); PoExporter filler = new PoExporter(ctx, document, m_Menu);
List<String> excludes = defaultExcludeList(X_AD_Menu.Table_Name); List<String> excludes = defaultExcludeList(X_AD_Menu.Table_Name);
String sql = null; String sql = "SELECT Parent_ID FROM AD_TreeNoDemm WHERE AD_Tree_ID = 10 and Node_ID=?";
String name = null;
sql = "SELECT Parent_ID FROM AD_TreeNoDemm WHERE AD_Tree_ID = 10 and Node_ID=?";
int id = DB.getSQLValue(null, sql, m_Menu.getAD_Menu_ID()); int id = DB.getSQLValue(null, sql, m_Menu.getAD_Menu_ID());
if (id > 0) { if (id > 0) {
sql = "SELECT Name FROM AD_Menu WHERE AD_Menu_ID=?"; filler.addTableReference("Parent_ID", "AD_Menu", "Name", id, new AttributesImpl());
name = DB.getSQLValueString(null, sql, id);
filler.addString("ADParentMenuNameID", name, new AttributesImpl());
} }
sql = "SELECT SeqNo FROM AD_TreeNoDemm WHERE AD_Tree_ID = 10 and Node_ID=?"; sql = "SELECT SeqNo FROM AD_TreeNoDemm WHERE AD_Tree_ID = 10 and Node_ID=?";
int seqNo = DB.getSQLValue(null, sql, m_Menu.getAD_Menu_ID()); int seqNo = DB.getSQLValue(null, sql, m_Menu.getAD_Menu_ID());
filler.addString("ADParentSeqno", Integer.toString(seqNo), new AttributesImpl()); filler.addString("SeqNo", Integer.toString(seqNo), new AttributesImpl());
if (m_Menu.getAD_Menu_ID() <= PackOut.MAX_OFFICIAL_ID) if (m_Menu.getAD_Menu_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.addString("AD_Menu_ID", Integer.toString(m_Menu.getAD_Menu_ID()), new AttributesImpl()); filler.addString("AD_Menu_ID", Integer.toString(m_Menu.getAD_Menu_ID()), new AttributesImpl());
@ -232,7 +239,7 @@ public class MenuElementHandler extends AbstractElementHandler implements IPackO
X_AD_Menu m_Menu = new X_AD_Menu(ctx, rs.getInt("AD_Menu_ID"), X_AD_Menu m_Menu = new X_AD_Menu(ctx, rs.getInt("AD_Menu_ID"),
null); null);
document.startElement("", "", "menu", atts); document.startElement("", "", I_AD_Menu.Table_Name, atts);
createMenuBinding(ctx, document, m_Menu); createMenuBinding(ctx, document, m_Menu);
if (rs.getInt("AD_WINDOW_ID") > 0 if (rs.getInt("AD_WINDOW_ID") > 0
|| rs.getInt("AD_WORKFLOW_ID") > 0 || rs.getInt("AD_WORKFLOW_ID") > 0
@ -268,7 +275,7 @@ public class MenuElementHandler extends AbstractElementHandler implements IPackO
} else { } else {
createModule(ctx, document, rs.getInt("Node_ID")); createModule(ctx, document, rs.getInt("Node_ID"));
} }
document.endElement("", "", "menu"); document.endElement("", "", I_AD_Menu.Table_Name);
} }
} catch (Exception e) { } catch (Exception e) {
log.log(Level.SEVERE, "getWindows", e); log.log(Level.SEVERE, "getWindows", e);
@ -298,7 +305,7 @@ public class MenuElementHandler extends AbstractElementHandler implements IPackO
// Menu tag Start. // Menu tag Start.
X_AD_Menu m_Menu = new X_AD_Menu(ctx, rs.getInt("AD_Menu_ID"), X_AD_Menu m_Menu = new X_AD_Menu(ctx, rs.getInt("AD_Menu_ID"),
null); null);
document.startElement("", "", "menu", atts); document.startElement("", "", I_AD_Menu.Table_Name, atts);
createMenuBinding(ctx, document, m_Menu); createMenuBinding(ctx, document, m_Menu);
if (rs.getInt("AD_WINDOW_ID") > 0 if (rs.getInt("AD_WINDOW_ID") > 0
|| rs.getInt("AD_WORKFLOW_ID") > 0 || rs.getInt("AD_WORKFLOW_ID") > 0
@ -335,7 +342,7 @@ public class MenuElementHandler extends AbstractElementHandler implements IPackO
} else { } else {
createModule(ctx, document, rs.getInt("Node_ID")); createModule(ctx, document, rs.getInt("Node_ID"));
} }
document.endElement("", "", "menu"); document.endElement("", "", I_AD_Menu.Table_Name);
} }
} catch (Exception e) { } catch (Exception e) {
log.log(Level.SEVERE, "getWindows", e); log.log(Level.SEVERE, "getWindows", e);

View File

@ -29,6 +29,7 @@ import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Message;
import org.compiere.model.MMessage; import org.compiere.model.MMessage;
import org.compiere.model.MPackageExp; import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail; import org.compiere.model.MPackageExpDetail;
@ -46,31 +47,36 @@ public class MessageElementHandler extends AbstractElementHandler implements IPa
public void startElement(Properties ctx, Element element) throws SAXException { public void startElement(Properties ctx, Element element) throws SAXException {
String entitytype = getStringValue(element, "EntityType"); String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) { if (isProcessElement(ctx, entitytype)) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Message.Table_Name, MMessage mMessage = findPO(ctx, element);
X_AD_Message.Table_ID); if (mMessage == null) {
String value = getStringValue(element, "Value"); String value = getStringValue(element, "Value");
int id = findIdByColumn(ctx, "AD_Message", "value", value); int id = findIdByColumn(ctx, "AD_Message", "value", value);
MMessage mMessage = new MMessage(ctx, id, getTrxName(ctx)); mMessage = new MMessage(ctx, id > 0 ? id : 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mMessage, element, this); PoFiller filler = new PoFiller(ctx, mMessage, element, this);
List<String> excludes = defaultExcludeList(X_AD_Message.Table_Name); List<String> excludes = defaultExcludeList(X_AD_Message.Table_Name);
String action = null;
if (id <= 0 && isOfficialId(element, "AD_Message_ID"))
filler.setInteger("AD_Message_ID");
if (id > 0){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Message.Table_Name, mMessage);
action = "Update";
}
else{
action = "New";
}
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) { if (notfounds.size() > 0) {
element.defer = true; element.defer = true;
return; return;
} }
if (mMessage.is_new() || mMessage.is_Changed()) {
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";
}
else{
action = "New";
}
if (mMessage.save(getTrxName(ctx)) == true){ if (mMessage.save(getTrxName(ctx)) == true){
logImportDetail (ctx, impDetail, 1, mMessage.getValue(), mMessage.get_ID(),action); logImportDetail (ctx, impDetail, 1, mMessage.getValue(), mMessage.get_ID(),action);
} }
@ -78,6 +84,7 @@ public class MessageElementHandler extends AbstractElementHandler implements IPa
logImportDetail (ctx, impDetail, 0, mMessage.getValue(), mMessage.get_ID(),action); logImportDetail (ctx, impDetail, 0, mMessage.getValue(), mMessage.get_ID(),action);
throw new POSaveFailedException("Failed to save message."); throw new POSaveFailedException("Failed to save message.");
} }
}
} else { } else {
element.skip = true; element.skip = true;
} }
@ -95,11 +102,10 @@ public class MessageElementHandler extends AbstractElementHandler implements IPa
messages.add(AD_Message_ID); messages.add(AD_Message_ID);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
X_AD_Message m_Message = new X_AD_Message (ctx, AD_Message_ID, null); X_AD_Message m_Message = new X_AD_Message (ctx, AD_Message_ID, null);
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.message");
atts.addAttribute("", "", "type-name", "CDATA", "ad.message"); document.startElement("","",I_AD_Message.Table_Name,atts);
document.startElement("","","message",atts);
createMessageBinding(ctx,document,m_Message); createMessageBinding(ctx,document,m_Message);
document.endElement("","","message"); document.endElement("","",I_AD_Message.Table_Name);
} }
private void createMessageBinding(Properties ctx, TransformerHandler document, X_AD_Message m_Message) private void createMessageBinding(Properties ctx, TransformerHandler document, X_AD_Message m_Message)

View File

@ -22,13 +22,15 @@ import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.PoFiller; 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.Query;
import org.compiere.model.X_AD_Role; import org.compiere.model.X_AD_Role;
import org.compiere.model.X_AD_Role_OrgAccess; import org.compiere.model.X_AD_Role_OrgAccess;
import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;
@ -38,19 +40,21 @@ public class OrgRoleElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) throws SAXException { public void startElement(Properties ctx, Element element) throws SAXException {
List<String> excludes = defaultExcludeList(X_AD_Role_OrgAccess.Table_Name); List<String> excludes = defaultExcludeList(X_AD_Role_OrgAccess.Table_Name);
X_AD_Role_OrgAccess po = findPO(ctx, element);
if (po == null) {
int roleId = 0; int roleId = 0;
String roleName = getStringValue(element, "rolename", excludes); if (getParentId(element, I_AD_Role.Table_Name) > 0) {
if (getParentId(element, "role") > 0) { roleId = getParentId(element, I_AD_Role.Table_Name);
roleId = getParentId(element, "role");
} else { } else {
roleId = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Role_ID FROM AD_Role WHERE Name = ? AND AD_Client_ID = ?", roleName, Env.getAD_Client_ID(ctx)); Element roleElement = element.properties.get("AD_Role_ID");
roleId = ReferenceUtils.resolveReference(ctx, roleElement);
} }
String orgName = getStringValue(element, "orgname", excludes); Element orgElement = element.properties.get("AD_Org_ID");
int orgId = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Org_ID FROM AD_Org WHERE Name = ? AND AD_Client_ID = ?", orgName, Env.getAD_Client_ID(ctx)); int orgId = ReferenceUtils.resolveReference(ctx, orgElement);
Query query = new Query(ctx, "AD_Role_OrgAccess", "AD_Role_ID=? and AD_Org_ID=?", getTrxName(ctx)); Query query = new Query(ctx, "AD_Role_OrgAccess", "AD_Role_ID=? and AD_Org_ID=?", getTrxName(ctx));
X_AD_Role_OrgAccess po = query.setParameters(new Object[]{roleId, orgId}) po = query.setParameters(new Object[]{roleId, orgId})
.setClient_ID() .setClient_ID()
.<X_AD_Role_OrgAccess>first(); .<X_AD_Role_OrgAccess>first();
@ -59,6 +63,9 @@ public class OrgRoleElementHandler extends AbstractElementHandler {
po.setAD_Org_ID(orgId); po.setAD_Org_ID(orgId);
po.setAD_Role_ID(roleId); po.setAD_Role_ID(roleId);
} }
excludes.add("AD_Org_ID");
excludes.add("AD_Role_ID");
}
PoFiller filler = new PoFiller(ctx, po, element, this); PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
@ -77,29 +84,25 @@ public class OrgRoleElementHandler extends AbstractElementHandler {
int AD_Org_ID = Env.getContextAsInt(ctx, "AD_Org_ID"); int AD_Org_ID = Env.getContextAsInt(ctx, "AD_Org_ID");
int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.organization-role");
atts.addAttribute("", "", "type-name", "CDATA", "ad.organization-role"); document.startElement("", "", I_AD_Role_OrgAccess.Table_Name, atts);
document.startElement("", "", "OrgAccess", atts);
createOrgAccessBinding(ctx, document, AD_Org_ID, AD_Role_ID); createOrgAccessBinding(ctx, document, AD_Org_ID, AD_Role_ID);
document.endElement("", "", "OrgAccess"); document.endElement("", "", I_AD_Role_OrgAccess.Table_Name);
} }
private void createOrgAccessBinding(Properties ctx, TransformerHandler document, private void createOrgAccessBinding(Properties ctx, TransformerHandler document,
int orgId, int roleId) { int orgId, int roleId) {
String sql = null;
String name = null;
Query query = new Query(ctx, "AD_Role_OrgAccess", "AD_Role_ID=? and AD_Org_ID=?", getTrxName(ctx)); Query query = new Query(ctx, "AD_Role_OrgAccess", "AD_Role_ID=? and AD_Org_ID=?", getTrxName(ctx));
X_AD_Role_OrgAccess po = query.setParameters(new Object[]{roleId, orgId}).<X_AD_Role_OrgAccess>first(); X_AD_Role_OrgAccess po = query.setParameters(new Object[]{roleId, orgId}).<X_AD_Role_OrgAccess>first();
PoExporter filler = new PoExporter(ctx, document, po); PoExporter filler = new PoExporter(ctx, document, po);
sql = "SELECT Name FROM AD_Org WHERE AD_Org_ID=?"; AttributesImpl orgRefAtts = new AttributesImpl();
name = DB.getSQLValueString(null, sql, orgId); String orgReference = ReferenceUtils.getTableReference("AD_Org", "Name", orgId, orgRefAtts);
filler.addString("orgname", name, new AttributesImpl()); filler.addString("AD_Org_ID", orgReference, orgRefAtts);
sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?"; AttributesImpl roleRefAtts = new AttributesImpl();
name = DB.getSQLValueString(null, sql, roleId); String roleReference = ReferenceUtils.getTableReference("AD_Role", "Name", roleId, roleRefAtts);
filler.addString("rolename", name, new AttributesImpl()); filler.addString("AD_Role_ID", roleReference, roleRefAtts);
List<String> excludes = defaultExcludeList(X_AD_Role_OrgAccess.Table_Name); List<String> excludes = defaultExcludeList(X_AD_Role_OrgAccess.Table_Name);
excludes.add("AD_Org_ID"); excludes.add("AD_Org_ID");

View File

@ -27,6 +27,7 @@ import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Preference;
import org.compiere.model.MPreference; import org.compiere.model.MPreference;
import org.compiere.model.Query; import org.compiere.model.Query;
import org.compiere.model.X_AD_Package_Imp_Detail; import org.compiere.model.X_AD_Package_Imp_Detail;
@ -40,9 +41,11 @@ public class PreferenceElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) public void startElement(Properties ctx, Element element)
throws SAXException { throws SAXException {
MPreference m_Preference = new MPreference(ctx, 0, getTrxName(ctx));
List<String> excludes = defaultExcludeList(X_AD_Preference.Table_Name); List<String> excludes = defaultExcludeList(X_AD_Preference.Table_Name);
PoFiller filler = new PoFiller(ctx, m_Preference, element, this); MPreference mPreference = findPO(ctx, element);
if (mPreference == null) {
mPreference = new MPreference(ctx, 0, getTrxName(ctx));
PoFiller filler = new PoFiller(ctx, mPreference, element, this);
List<String> notFounds = filler.autoFill(excludes); List<String> notFounds = filler.autoFill(excludes);
if (notFounds.size() > 0) { if (notFounds.size() > 0) {
element.defer = true; element.defer = true;
@ -51,7 +54,7 @@ public class PreferenceElementHandler extends AbstractElementHandler {
Query query = new Query(ctx, "AD_Preference", "Attribute = ? AND coalesce(AD_User_ID,0) = ? AND coalesce(AD_Window_ID,0) = ?", getTrxName(ctx)); Query query = new Query(ctx, "AD_Preference", "Attribute = ? AND coalesce(AD_User_ID,0) = ? AND coalesce(AD_Window_ID,0) = ?", getTrxName(ctx));
MPreference tmp = query MPreference tmp = query
.setParameters(new Object[]{m_Preference.getAttribute(), m_Preference.getAD_User_ID(), m_Preference.getAD_Window_ID()}) .setParameters(new Object[]{mPreference.getAttribute(), mPreference.getAD_User_ID(), mPreference.getAD_Window_ID()})
.first(); .first();
if (tmp != null) { if (tmp != null) {
filler = new PoFiller(ctx, tmp, element, this); filler = new PoFiller(ctx, tmp, element, this);
@ -60,32 +63,41 @@ public class PreferenceElementHandler extends AbstractElementHandler {
element.defer = true; element.defer = true;
return; return;
} }
m_Preference = tmp; mPreference = tmp;
}
} else {
PoFiller filler = new PoFiller(ctx, mPreference, element, this);
List<String> notFounds = filler.autoFill(excludes);
if (notFounds.size() > 0) {
element.defer = true;
return;
}
} }
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_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Preference.Table_Name,
X_AD_Preference.Table_ID); X_AD_Preference.Table_ID);
String Object_Status = null; String action = null;
int id = m_Preference.get_ID(); if (!mPreference.is_new()) {
if (id <= 0 && isOfficialId(element, "AD_Preference_ID")) backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Preference.Table_Name, mPreference);
m_Preference.setAD_Preference_ID(Integer.parseInt(getStringValue(element, "AD_Preference_ID"))); action = "Update";
if (id > 0) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Preference.Table_Name, m_Preference);
Object_Status = "Update";
} else { } else {
Object_Status = "New"; action = "New";
} }
if (m_Preference.save(getTrxName(ctx)) == true) { if (mPreference.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, m_Preference.getAttribute(), logImportDetail(ctx, impDetail, 1, mPreference.getAttribute(),
m_Preference.get_ID(), Object_Status); mPreference.get_ID(), action);
} else { } else {
logImportDetail(ctx, impDetail, 0, m_Preference.getAttribute(), logImportDetail(ctx, impDetail, 0, mPreference.getAttribute(),
m_Preference.get_ID(), Object_Status); mPreference.get_ID(), action);
throw new POSaveFailedException("Failed to save Preference"); throw new POSaveFailedException("Failed to save Preference");
} }
} }
}
public void endElement(Properties ctx, Element element) throws SAXException { public void endElement(Properties ctx, Element element) throws SAXException {
} }
@ -97,11 +109,10 @@ public class PreferenceElementHandler extends AbstractElementHandler {
X_AD_Preference m_Preference = new X_AD_Preference(ctx, X_AD_Preference m_Preference = new X_AD_Preference(ctx,
AD_Preference_ID, getTrxName(ctx)); AD_Preference_ID, getTrxName(ctx));
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.preference");
atts.addAttribute("", "", "type-name", "CDATA", "ad.preference"); document.startElement("", "", I_AD_Preference.Table_Name, atts);
document.startElement("", "", "preference", atts);
createPreferenceBinding(ctx, document, m_Preference); createPreferenceBinding(ctx, document, m_Preference);
document.endElement("", "", "preference"); document.endElement("", "", I_AD_Preference.Table_Name);
} }
private void createPreferenceBinding(Properties ctx, TransformerHandler document, private void createPreferenceBinding(Properties ctx, TransformerHandler document,

View File

@ -33,6 +33,7 @@ import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_PrintFormat;
import org.compiere.model.MPackageExp; import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail; import org.compiere.model.MPackageExpDetail;
import org.compiere.model.X_AD_Package_Exp_Detail; import org.compiere.model.X_AD_Package_Exp_Detail;
@ -50,25 +51,17 @@ public class PrintFormatElementHandler extends AbstractElementHandler implements
public void startElement(Properties ctx, Element element) public void startElement(Properties ctx, Element element)
throws SAXException { throws SAXException {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_PrintFormat.Table_Name,
X_AD_PrintFormat.Table_ID);
String action = null;
X_AD_PrintFormat mPrintFormat = findPO(ctx, element);
if (mPrintFormat == null) {
String name = getStringValue(element, "Name"); String name = getStringValue(element, "Name");
int id = findIdByColumn(ctx, "AD_PrintFormat", "Name", name); int id = findIdByColumn(ctx, "AD_PrintFormat", "Name", name);
X_AD_PrintFormat mPrintFormat = new X_AD_PrintFormat(ctx, id, getTrxName(ctx)); mPrintFormat = new X_AD_PrintFormat(ctx, id > 0 ? id : 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mPrintFormat, element, this); PoFiller filler = new PoFiller(ctx, mPrintFormat, element, this);
List<String> excludes = defaultExcludeList(X_AD_PrintFormat.Table_Name); List<String> excludes = defaultExcludeList(X_AD_PrintFormat.Table_Name);
if (id <= 0 && isOfficialId(element, "AD_PrintFormat_ID")) if (mPrintFormat.getAD_PrintFormat_ID() == 0 && isOfficialId(element, "AD_PrintFormat_ID"))
mPrintFormat.setAD_PrintFormat_ID(getIntValue(element, "AD_PrintFormat_ID")); mPrintFormat.setAD_PrintFormat_ID(getIntValue(element, "AD_PrintFormat_ID"));
if (id > 0) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_PrintFormat.Table_Name, mPrintFormat);
action = "Update";
} else {
action = "New";
}
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) { if (notfounds.size() > 0) {
@ -76,6 +69,16 @@ public class PrintFormatElementHandler extends AbstractElementHandler implements
return; return;
} }
if (mPrintFormat.is_new() || mPrintFormat.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_PrintFormat.Table_Name,
X_AD_PrintFormat.Table_ID);
String action = null;
if (!mPrintFormat.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_PrintFormat.Table_Name, mPrintFormat);
action = "Update";
} else {
action = "New";
}
if (mPrintFormat.save(getTrxName(ctx)) == true) { if (mPrintFormat.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mPrintFormat.getName(), logImportDetail(ctx, impDetail, 1, mPrintFormat.getName(),
mPrintFormat.get_ID(), action); mPrintFormat.get_ID(), action);
@ -86,6 +89,7 @@ public class PrintFormatElementHandler extends AbstractElementHandler implements
throw new POSaveFailedException("Failed to save Print Format"); throw new POSaveFailedException("Failed to save Print Format");
} }
} }
}
public void endElement(Properties ctx, Element element) throws SAXException { public void endElement(Properties ctx, Element element) throws SAXException {
} }
@ -108,9 +112,8 @@ public class PrintFormatElementHandler extends AbstractElementHandler implements
throw new SAXException(e); throw new SAXException(e);
} }
} }
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.print-format");
atts.addAttribute("", "", "type-name", "CDATA", "ad.print-format"); document.startElement("", "", I_AD_PrintFormat.Table_Name, atts);
document.startElement("", "", "printformat", atts);
createPrintFormatBinding(ctx, document, m_Printformat); createPrintFormatBinding(ctx, document, m_Printformat);
String sql = "SELECT AD_PrintFormatItem_ID FROM AD_PrintFormatItem WHERE AD_PrintFormat_ID= " String sql = "SELECT AD_PrintFormatItem_ID FROM AD_PrintFormatItem WHERE AD_PrintFormat_ID= "
@ -129,7 +132,7 @@ public class PrintFormatElementHandler extends AbstractElementHandler implements
} finally { } finally {
DB.close(rs, pstmt); DB.close(rs, pstmt);
} }
document.endElement("", "", "printformat"); document.endElement("", "", I_AD_PrintFormat.Table_Name);
} }
@ -147,6 +150,9 @@ public class PrintFormatElementHandler extends AbstractElementHandler implements
PoExporter filler = new PoExporter(ctx, document, m_Printformat); PoExporter filler = new PoExporter(ctx, document, m_Printformat);
List<String> excludes = defaultExcludeList(X_AD_PrintFormat.Table_Name); List<String> excludes = defaultExcludeList(X_AD_PrintFormat.Table_Name);
if (m_Printformat.getAD_PrintFormat_ID() <= PackOut.MAX_OFFICIAL_ID) {
filler.add("AD_PrintFormat_ID", new AttributesImpl());
}
filler.export(excludes); filler.export(excludes);
} }

View File

@ -28,7 +28,9 @@ import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_PrintFormatItem;
import org.compiere.model.MPackageExp; import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail; import org.compiere.model.MPackageExpDetail;
import org.compiere.model.X_AD_Package_Imp_Detail; import org.compiere.model.X_AD_Package_Imp_Detail;
@ -42,23 +44,22 @@ public class PrintFormatItemElementHandler extends AbstractElementHandler implem
public void startElement(Properties ctx, Element element) public void startElement(Properties ctx, Element element)
throws SAXException { throws SAXException {
String action = null;
List<String> excludes = defaultExcludeList(X_AD_PrintFormatItem.Table_Name); List<String> excludes = defaultExcludeList(X_AD_PrintFormatItem.Table_Name);
if (isParentDefer(element, "printformat")) { if (isParentDefer(element, I_AD_PrintFormatItem.Table_Name)) {
element.defer = true; element.defer = true;
return; return;
} }
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_PrintFormatItem.Table_Name, X_AD_PrintFormatItem mPrintFormatItem = findPO(ctx, element);
X_AD_PrintFormatItem.Table_ID); if (mPrintFormatItem == null) {
String printformatName = getStringValue(element, "AD_PrintFormat.Name", excludes);
int parentId = 0; int parentId = 0;
if (getParentId(element, "printformat") > 0) { if (getParentId(element, I_AD_PrintFormatItem.Table_Name) > 0) {
parentId = getParentId(element, "printformat"); parentId = getParentId(element, I_AD_PrintFormatItem.Table_Name);
} else { } else {
parentId = findIdByColumn(ctx, "AD_PrintFormat", "Name", printformatName); Element pfElement = element.properties.get(I_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormat_ID);
parentId = ReferenceUtils.resolveReference(ctx, pfElement);
} }
if (parentId <= 0) { if (parentId <= 0) {
element.defer = true; element.defer = true;
@ -67,37 +68,41 @@ public class PrintFormatItemElementHandler extends AbstractElementHandler implem
String name = getStringValue(element, "Name"); String name = getStringValue(element, "Name");
int id = findIdByNameAndParentId(ctx, "AD_PrintFormatItem", name, "AD_PrintFormat", parentId); int id = findIdByNameAndParentId(ctx, "AD_PrintFormatItem", name, "AD_PrintFormat", parentId);
mPrintFormatItem = new X_AD_PrintFormatItem(ctx, id > 0 ? id : 0, getTrxName(ctx));
X_AD_PrintFormatItem mPrintFormatItem = new X_AD_PrintFormatItem(ctx, mPrintFormatItem.setAD_PrintFormat_ID(parentId);
id, getTrxName(ctx)); excludes.add(I_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormat_ID);
}
PoFiller filler = new PoFiller(ctx, mPrintFormatItem, element, this); PoFiller filler = new PoFiller(ctx, mPrintFormatItem, element, this);
if (id <= 0 && isOfficialId(element, "AD_PrintFormatItem_ID")) if (mPrintFormatItem.getAD_PrintFormatItem_ID() == 0 && isOfficialId(element, "AD_PrintFormatItem_ID"))
filler.setInteger("AD_PrintFormatItem_ID"); filler.setInteger("AD_PrintFormatItem_ID");
if (id > 0) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_PrintFormatItem.Table_Name, mPrintFormatItem); excludes.add("AD_Table_ID");
action = "Update"; 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, columnElement);
} else { } else {
action = "New"; Element tableElement = element.properties.get("AD_Table_ID");
} int tableId = ReferenceUtils.resolveReference(ctx, tableElement);
mPrintFormatItem.setAD_PrintFormat_ID(parentId); String columnName = getStringValue(element, "AD_Column_ID");
String tableName = getStringValue(element, "AD_Table.TableName", excludes); columnId = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnName,
int tableId = findIdByColumn(ctx, "AD_Table", "TableName", tableName);
String columnName = getStringValue(element, "AD_Column.ColumnName", excludes);
int columnId = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnName,
"AD_Table", tableId); "AD_Table", tableId);
}
if (columnId > 0) if (columnId > 0)
mPrintFormatItem.setAD_Column_ID(columnId); mPrintFormatItem.setAD_Column_ID(columnId);
String pftChildName = getStringValue(element, "AD_PrintFormatChild_ID.AD_PrintFormat.Name", excludes); excludes.add("AD_PrintFormatChild_ID");
if (pftChildName != null && pftChildName.trim().length() > 0) { Element pfchildElement = element.properties.get(I_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormatChild_ID);
id = findIdByColumn(ctx, "AD_PrintFormat", "Name", pftChildName); int AD_PrintFormatChild_ID = ReferenceUtils.resolveReference(ctx, pfchildElement);
if (id <= 0) { 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.defer = true;
element.unresolved = "AD_PrintFormat: " + pftChildName; element.unresolved = "AD_PrintFormat: " + pfchildElement.contents;
return; return;
}
mPrintFormatItem.setAD_PrintFormatChild_ID(id);
} }
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
@ -106,6 +111,16 @@ public class PrintFormatItemElementHandler extends AbstractElementHandler implem
return; return;
} }
if (mPrintFormatItem.is_new() || mPrintFormatItem.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_PrintFormatItem.Table_Name,
X_AD_PrintFormatItem.Table_ID);
String action = null;
if (!mPrintFormatItem.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_PrintFormatItem.Table_Name, mPrintFormatItem);
action = "Update";
} else {
action = "New";
}
if (mPrintFormatItem.save(getTrxName(ctx)) == true) { if (mPrintFormatItem.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mPrintFormatItem.getName(), logImportDetail(ctx, impDetail, 1, mPrintFormatItem.getName(),
mPrintFormatItem.get_ID(), action); mPrintFormatItem.get_ID(), action);
@ -115,6 +130,7 @@ public class PrintFormatItemElementHandler extends AbstractElementHandler implem
throw new POSaveFailedException("PrintFormatItem"); throw new POSaveFailedException("PrintFormatItem");
} }
} }
}
public void endElement(Properties ctx, Element element) throws SAXException { public void endElement(Properties ctx, Element element) throws SAXException {
} }
@ -126,29 +142,27 @@ public class PrintFormatItemElementHandler extends AbstractElementHandler implem
X_AD_PrintFormatItem m_PrintFormatItem = new X_AD_PrintFormatItem(ctx, X_AD_PrintFormatItem m_PrintFormatItem = new X_AD_PrintFormatItem(ctx,
AD_PrintFormatItem_ID, null); AD_PrintFormatItem_ID, null);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.print-format.item");
atts.addAttribute("", "", "type-name", "CDATA", "ad.print-format.item"); document.startElement("", "", I_AD_PrintFormatItem.Table_Name, atts);
document.startElement("", "", "printformatitem", atts);
createPrintFormatItemBinding(ctx, document, m_PrintFormatItem); createPrintFormatItemBinding(ctx, document, m_PrintFormatItem);
document.endElement("", "", "printformatitem"); document.endElement("", "", I_AD_PrintFormatItem.Table_Name);
} }
private void createPrintFormatItemBinding(Properties ctx, TransformerHandler document, private void createPrintFormatItemBinding(Properties ctx, TransformerHandler document,
X_AD_PrintFormatItem m_PrintformatItem) { X_AD_PrintFormatItem mPrintformatItem) {
PoExporter filler = new PoExporter(ctx, document, m_PrintformatItem); PoExporter filler = new PoExporter(ctx, document, mPrintformatItem);
List<String> excludes = defaultExcludeList(X_AD_PrintFormatItem.Table_Name); List<String> excludes = defaultExcludeList(X_AD_PrintFormatItem.Table_Name);
if (m_PrintformatItem.getAD_PrintFormatItem_ID() <= PackOut.MAX_OFFICIAL_ID) if (mPrintformatItem.getAD_PrintFormatItem_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_PrintFormatItem_ID", new AttributesImpl()); filler.add("AD_PrintFormatItem_ID", new AttributesImpl());
if (m_PrintformatItem.getAD_Column_ID() > 0) { if (mPrintformatItem.getAD_Column_ID() > 0) {
String sql = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?"; String sql = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?";
int tableID = DB.getSQLValue(null, sql, m_PrintformatItem int tableID = DB.getSQLValue(null, sql, mPrintformatItem.getAD_Column_ID());
.getAD_Column_ID()); AttributesImpl referenceAtts = new AttributesImpl();
sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; String value = ReferenceUtils.getTableReference("AD_Table", "TableName", tableID, referenceAtts);
String name = DB.getSQLValueString(null, sql, tableID); filler.addString("AD_Table.TableName", value, referenceAtts);
filler.addString("AD_Table.TableName", name, new AttributesImpl());
} }
filler.export(excludes); filler.export(excludes);

View File

@ -29,6 +29,7 @@ import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_PrintPaper;
import org.compiere.model.MPackageExp; import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail; import org.compiere.model.MPackageExpDetail;
import org.compiere.model.X_AD_Package_Imp_Detail; import org.compiere.model.X_AD_Package_Imp_Detail;
@ -42,26 +43,20 @@ public class PrintPaperElementHandler extends AbstractElementHandler implements
public void startElement(Properties ctx, Element element) public void startElement(Properties ctx, Element element)
throws SAXException { throws SAXException {
String action = null;
List<String> excludes = defaultExcludeList(X_AD_PrintPaper.Table_Name); List<String> excludes = defaultExcludeList(X_AD_PrintPaper.Table_Name);
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_PrintPaper.Table_Name, X_AD_PrintPaper.Table_ID); X_AD_PrintPaper printPaper = findPO(ctx, element);
if (printPaper == null) {
String printPaperName = getStringValue(element, "Name", excludes); String printPaperName = getStringValue(element, "Name", excludes);
int id = findIdByName(ctx, "AD_PrintPaper", printPaperName); int id = findIdByName(ctx, "AD_PrintPaper", printPaperName);
X_AD_PrintPaper printPaper = new X_AD_PrintPaper(ctx, printPaper = new X_AD_PrintPaper(ctx, id > 0 ? id : 0, getTrxName(ctx));
id, getTrxName(ctx)); }
PoFiller filler = new PoFiller(ctx, printPaper, element, this); PoFiller filler = new PoFiller(ctx, printPaper, element, this);
if (id <= 0 && isOfficialId(element, "AD_PrintPaper_ID")) if (printPaper.getAD_PrintPaper_ID() == 0 && isOfficialId(element, "AD_PrintPaper_ID"))
filler.setInteger("AD_PrintPaper_ID"); filler.setInteger("AD_PrintPaper_ID");
if (id > 0) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), "AD_PrintPaper", printPaper);
action = "Update";
} else {
action = "New";
}
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) { if (notfounds.size() > 0) {
@ -69,6 +64,15 @@ public class PrintPaperElementHandler extends AbstractElementHandler implements
return; return;
} }
if (printPaper.is_new() || printPaper.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_PrintPaper.Table_Name, X_AD_PrintPaper.Table_ID);
String action = null;
if (!printPaper.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), "AD_PrintPaper", printPaper);
action = "Update";
} else {
action = "New";
}
if (printPaper.save(getTrxName(ctx)) == true) { if (printPaper.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, printPaper.getName(), logImportDetail(ctx, impDetail, 1, printPaper.getName(),
printPaper.get_ID(), action); printPaper.get_ID(), action);
@ -78,6 +82,7 @@ public class PrintPaperElementHandler extends AbstractElementHandler implements
throw new POSaveFailedException("PrintPaper"); throw new POSaveFailedException("PrintPaper");
} }
} }
}
public void endElement(Properties ctx, Element element) throws SAXException { public void endElement(Properties ctx, Element element) throws SAXException {
} }
@ -89,11 +94,10 @@ public class PrintPaperElementHandler extends AbstractElementHandler implements
X_AD_PrintPaper printPaper = new X_AD_PrintPaper(ctx, X_AD_PrintPaper printPaper = new X_AD_PrintPaper(ctx,
AD_PrintPaper_ID, null); AD_PrintPaper_ID, null);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.print-paper");
atts.addAttribute("", "", "type-name", "CDATA", "ad.print-paper"); document.startElement("", "", I_AD_PrintPaper.Table_Name, atts);
document.startElement("", "", "printpaper", atts);
createPrintPaperBinding(ctx, document, printPaper); createPrintPaperBinding(ctx, document, printPaper);
document.endElement("", "", "printpaper"); document.endElement("", "", I_AD_PrintPaper.Table_Name);
} }
private void createPrintPaperBinding(Properties ctx, TransformerHandler document, private void createPrintPaperBinding(Properties ctx, TransformerHandler document,

View File

@ -25,11 +25,13 @@ import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PoFiller; 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.Query;
import org.compiere.model.X_AD_Process; import org.compiere.model.X_AD_Process;
import org.compiere.model.X_AD_Process_Access; import org.compiere.model.X_AD_Process_Access;
import org.compiere.model.X_AD_Role; import org.compiere.model.X_AD_Role;
import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;
@ -41,17 +43,18 @@ public class ProcessAccessElementHandler extends AbstractElementHandler {
int processid =0; int processid =0;
List<String> excludes = defaultExcludeList(X_AD_Process_Access.Table_Name); List<String> excludes = defaultExcludeList(X_AD_Process_Access.Table_Name);
String roleName = getStringValue(element, "AD_Role.Name", excludes); X_AD_Process_Access po = findPO(ctx, element);
if (getParentId(element, "role") > 0) { if (po == null) {
roleid = getParentId(element, "role"); if (getParentId(element, I_AD_Role.Table_Name) > 0) {
roleid = getParentId(element, I_AD_Role.Table_Name);
} else { } else {
roleid = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Role_ID FROM AD_Role WHERE Name = ? AND AD_Client_ID = ?", roleName, Env.getAD_Client_ID(ctx)); Element roleElement = element.properties.get(I_AD_Process_Access.COLUMNNAME_AD_Role_ID);
roleid = ReferenceUtils.resolveReference(ctx, roleElement);
} }
String processName = getStringValue(element, "AD_Process.Value", excludes); Element processElement = element.properties.get(I_AD_Process_Access.COLUMNNAME_AD_Process_ID);
processid = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Process_ID FROM AD_Process WHERE Value = ? AND AD_Client_ID = ?", processName, Env.getAD_Client_ID(ctx)); processid = ReferenceUtils.resolveReference(ctx, processElement);
X_AD_Process_Access po = null;
Query query = new Query(ctx, "AD_Process_Access", "AD_Role_ID=? and AD_Process_ID=?", getTrxName(ctx)); Query query = new Query(ctx, "AD_Process_Access", "AD_Role_ID=? and AD_Process_ID=?", getTrxName(ctx));
po = query.setParameters(new Object[]{roleid, processid}).first(); po = query.setParameters(new Object[]{roleid, processid}).first();
if (po == null) if (po == null)
@ -60,6 +63,9 @@ public class ProcessAccessElementHandler extends AbstractElementHandler {
po.setAD_Process_ID(processid); po.setAD_Process_ID(processid);
po.setAD_Role_ID(roleid); 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);
}
PoFiller filler = new PoFiller(ctx, po, element, this); PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) { if (notfounds.size() > 0) {
@ -77,11 +83,10 @@ public class ProcessAccessElementHandler extends AbstractElementHandler {
int AD_Process_ID = Env.getContextAsInt(ctx, X_AD_Process.COLUMNNAME_AD_Process_ID); int AD_Process_ID = Env.getContextAsInt(ctx, X_AD_Process.COLUMNNAME_AD_Process_ID);
int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.process-access");
atts.addAttribute("", "", "type-name", "CDATA", "ad.process-access"); document.startElement("", "", I_AD_Process_Access.Table_Name, atts);
document.startElement("", "", "processaccess", atts);
createProcessAccessBinding(ctx, document, AD_Process_ID, AD_Role_ID); createProcessAccessBinding(ctx, document, AD_Process_ID, AD_Role_ID);
document.endElement("", "", "processaccess"); document.endElement("", "", I_AD_Process_Access.Table_Name);
} }
private void createProcessAccessBinding(Properties ctx, TransformerHandler document, private void createProcessAccessBinding(Properties ctx, TransformerHandler document,

View File

@ -30,6 +30,7 @@ import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Process;
import org.compiere.model.MPackageExp; import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail; import org.compiere.model.MPackageExpDetail;
import org.compiere.model.Query; import org.compiere.model.Query;
@ -49,29 +50,18 @@ public class ProcessElementHandler extends AbstractElementHandler implements IPa
public void startElement(Properties ctx, Element element) public void startElement(Properties ctx, Element element)
throws SAXException { throws SAXException {
int id = 0;
String entitytype = getStringValue(element, "EntityType"); String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) { if (isProcessElement(ctx, entitytype)) {
X_AD_Process mProcess = findPO(ctx, element);
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Process.Table_Name, if (mProcess == null) {
X_AD_Process.Table_ID);
String value = getStringValue(element, "Value"); String value = getStringValue(element, "Value");
// Get New process. // Get New process.
id = findIdByColumn(ctx, "AD_Process", "Value", value); int id = findIdByColumn(ctx, "AD_Process", "Value", value);
mProcess = new X_AD_Process(ctx, id > 0 ? id : 0, getTrxName(ctx));
X_AD_Process mProcess = null;
String action = null;
if (id > 0) {
mProcess = new X_AD_Process(ctx, id, getTrxName(ctx));
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Process.Table_Name, mProcess);
action = "Update";
} else {
mProcess = new X_AD_Process(ctx, id, getTrxName(ctx));
action = "New";
} }
if (id <= 0 && isOfficialId(element, "AD_Process_ID"))
if (mProcess.getAD_Process_ID() == 0 && isOfficialId(element, "AD_Process_ID"))
mProcess.setAD_Process_ID(Integer.parseInt(getStringValue(element, "AD_Process_ID"))); mProcess.setAD_Process_ID(Integer.parseInt(getStringValue(element, "AD_Process_ID")));
PoFiller filler = new PoFiller(ctx, mProcess, element, this); PoFiller filler = new PoFiller(ctx, mProcess, element, this);
@ -83,6 +73,17 @@ public class ProcessElementHandler extends AbstractElementHandler implements IPa
return; return;
} }
if (mProcess.is_new() || mProcess.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Process.Table_Name,
X_AD_Process.Table_ID);
String action = null;
if (!mProcess.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Process.Table_Name, mProcess);
action = "Update";
} else {
action = "New";
}
if (mProcess.save(getTrxName(ctx)) == true) { if (mProcess.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mProcess.getName(), mProcess logImportDetail(ctx, impDetail, 1, mProcess.getName(), mProcess
.get_ID(), action); .get_ID(), action);
@ -92,6 +93,7 @@ public class ProcessElementHandler extends AbstractElementHandler implements IPa
.get_ID(), action); .get_ID(), action);
throw new POSaveFailedException("Process"); throw new POSaveFailedException("Process");
} }
}
} else { } else {
element.skip = true; element.skip = true;
} }
@ -117,7 +119,6 @@ public class ProcessElementHandler extends AbstractElementHandler implements IPa
{ {
IPackOutHandler handler = packOut.getHandler("R"); IPackOutHandler handler = packOut.getHandler("R");
handler.packOut(packOut,null,null,document,null,m_Process.getAD_ReportView_ID()); handler.packOut(packOut,null,null,document,null,m_Process.getAD_ReportView_ID());
} }
if (m_Process.isReport() && m_Process.getAD_PrintFormat_ID() > 0) if (m_Process.isReport() && m_Process.getAD_PrintFormat_ID() > 0)
{ {
@ -128,9 +129,8 @@ public class ProcessElementHandler extends AbstractElementHandler implements IPa
IPackOutHandler handler = packOut.getHandler("F"); IPackOutHandler handler = packOut.getHandler("F");
handler.packOut(packOut,null,null,document,null,m_Process.getAD_Workflow_ID()); handler.packOut(packOut,null,null,document,null,m_Process.getAD_Workflow_ID());
} }
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.process");
atts.addAttribute("", "", "type-name", "CDATA", "ad.process"); document.startElement("", "", I_AD_Process.Table_Name, atts);
document.startElement("", "", "process", atts);
createProcessBinding(ctx, document, m_Process); createProcessBinding(ctx, document, m_Process);
Query query = new Query(ctx, "AD_Process_PARA", "AD_Process_ID = ?", getTrxName(ctx)); Query query = new Query(ctx, "AD_Process_PARA", "AD_Process_ID = ?", getTrxName(ctx));
@ -157,8 +157,7 @@ public class ProcessElementHandler extends AbstractElementHandler implements IPa
createProcessPara(ctx, document, para.getAD_Process_Para_ID()); createProcessPara(ctx, document, para.getAD_Process_Para_ID());
} }
document.endElement("", "", I_AD_Process.Table_Name);
document.endElement("", "", "process");
} catch (Exception e) { } catch (Exception e) {
throw new AdempiereException(e); throw new AdempiereException(e);
} }

View File

@ -28,7 +28,10 @@ import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Process;
import org.compiere.model.I_AD_Process_Para;
import org.compiere.model.X_AD_Package_Imp_Detail; import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_Process_Para; import org.compiere.model.X_AD_Process_Para;
import org.compiere.util.Env; import org.compiere.util.Env;
@ -43,50 +46,37 @@ public class ProcessParaElementHandler extends AbstractElementHandler {
String entitytype = getStringValue(element, "EntityType"); String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) { if (isProcessElement(ctx, entitytype)) {
if (isParentDefer(element, "process")) { if (isParentDefer(element, I_AD_Process.Table_Name)) {
element.defer = true; element.defer = true;
return; return;
} }
X_AD_Process_Para mProcessPara = findPO(ctx, element);
if (mProcessPara == null) {
String name = getStringValue(element, "Name"); String name = getStringValue(element, "Name");
int id = 0; int id = 0;
int masterId = 0; int masterId = 0;
String processValue = ""; if (getParentId(element, I_AD_Process.Table_Name) > 0) {
if (getParentId(element, "process") > 0) {
masterId = getParentId(element, "process"); masterId = getParentId(element, "process");
} else { } else {
processValue = getStringValue(element, "AD_Process.Value", excludes); Element processElement = element.properties.get(I_AD_Process_Para.COLUMNNAME_AD_Process_ID);
if (processValue != null && processValue.trim().length() > 0) { masterId = ReferenceUtils.resolveReference(ctx, processElement);
masterId = findIdByColumn(ctx, "AD_Process", "Value", processValue);
}
} }
if (masterId <= 0) { if (masterId <= 0) {
element.defer = true; element.defer = true;
element.unresolved = "AD_Process: " + processValue; element.unresolved = "AD_Process: " + getStringValue(element, I_AD_Process_Para.COLUMNNAME_AD_Process_ID);
return; return;
} }
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Process_Para.Table_Name, id = findIdByColumnAndParentId(ctx, "AD_Process_Para", "Name", name, "AD_Process", masterId);
X_AD_Process_Para.Table_ID); mProcessPara = new X_AD_Process_Para(ctx, id > 0 ? id : 0, getTrxName(ctx));
mProcessPara.setAD_Process_ID(masterId);
id = findIdByColumnAndParentId(ctx, "AD_Process_Para", "Name", excludes.add(I_AD_Process_Para.COLUMNNAME_AD_Process_ID);
name, "AD_Process", masterId);
X_AD_Process_Para mProcessPara = new X_AD_Process_Para(ctx, id,
getTrxName(ctx));
String action = null;
if (id <= 0 && isOfficialId(element, "AD_Process_Para_ID"))
mProcessPara.setAD_Process_Para_ID(Integer.parseInt(getStringValue(element, "AD_Process_Para_ID")));
if (id > 0) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Process_Para.Table_Name,
mProcessPara);
action = "Update";
} else {
action = "New";
} }
mProcessPara.setAD_Process_ID(masterId); 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); PoFiller filler = new PoFiller(ctx, mProcessPara, element, this);
@ -96,6 +86,17 @@ public class ProcessParaElementHandler extends AbstractElementHandler {
return; return;
} }
if (mProcessPara.is_new() || mProcessPara.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Process_Para.Table_Name,
X_AD_Process_Para.Table_ID);
String action = null;
if (!mProcessPara.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Process_Para.Table_Name,
mProcessPara);
action = "Update";
} else {
action = "New";
}
if (mProcessPara.save(getTrxName(ctx)) == true) { if (mProcessPara.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mProcessPara.getName(), logImportDetail(ctx, impDetail, 1, mProcessPara.getName(),
mProcessPara.get_ID(), action); mProcessPara.get_ID(), action);
@ -104,6 +105,7 @@ public class ProcessParaElementHandler extends AbstractElementHandler {
mProcessPara.get_ID(), action); mProcessPara.get_ID(), action);
throw new POSaveFailedException("ProcessPara"); throw new POSaveFailedException("ProcessPara");
} }
}
} else { } else {
element.skip = true; element.skip = true;
} }
@ -129,11 +131,10 @@ public class ProcessParaElementHandler extends AbstractElementHandler {
} }
} }
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.process.parameter");
atts.addAttribute("", "", "type-name", "CDATA", "ad.process.parameter"); document.startElement("", "", I_AD_Process_Para.Table_Name, atts);
document.startElement("", "", "processpara", atts);
createProcessParaBinding(ctx, document, m_Processpara); createProcessParaBinding(ctx, document, m_Processpara);
document.endElement("", "", "processpara"); document.endElement("", "", I_AD_Process_Para.Table_Name);
} }
private void createProcessParaBinding(Properties ctx, TransformerHandler document, private void createProcessParaBinding(Properties ctx, TransformerHandler document,

View File

@ -34,6 +34,7 @@ import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.DatabaseAccessException; import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Reference;
import org.compiere.model.MPackageExp; import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail; import org.compiere.model.MPackageExpDetail;
import org.compiere.model.X_AD_Package_Exp_Detail; import org.compiere.model.X_AD_Package_Exp_Detail;
@ -55,49 +56,52 @@ public class ReferenceElementHandler extends AbstractElementHandler implements I
public void startElement(Properties ctx, Element element) public void startElement(Properties ctx, Element element)
throws SAXException { throws SAXException {
String Object_Status = null;
String entitytype = getStringValue(element, "EntityType"); String entitytype = getStringValue(element, "EntityType");
String name = getStringValue(element, "Name"); String name = getStringValue(element, "Name");
if (isProcessElement(ctx, entitytype)) { if (isProcessElement(ctx, entitytype)) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Reference.Table_Name, X_AD_Reference mReference = findPO(ctx, element);
X_AD_Reference.Table_ID); if (mReference == null) {
int id = findIdByName(ctx, "AD_Reference", name); int id = findIdByName(ctx, "AD_Reference", name);
mReference = new X_AD_Reference(ctx, id > 0 ? id : 0, getTrxName(ctx));
X_AD_Reference m_Reference = new X_AD_Reference(ctx, id, getTrxName(ctx)); }
List<String> excludes = defaultExcludeList(X_AD_Reference.Table_Name); List<String> excludes = defaultExcludeList(X_AD_Reference.Table_Name);
if (id <= 0 && isOfficialId(element, "AD_Reference_ID")) if (mReference.getAD_Reference_ID() == 0 && isOfficialId(element, "AD_Reference_ID"))
m_Reference.setAD_Reference_ID(getIntValue(element, "AD_Reference_ID")); mReference.setAD_Reference_ID(getIntValue(element, "AD_Reference_ID"));
if (id > 0) {
backupRecord(ctx, impDetail.getAD_Package_Imp_ID(), X_AD_Reference.Table_Name, m_Reference);
Object_Status = "Update";
if (references.contains(id)) {
element.skip = true;
return;
}
} else {
Object_Status = "New";
}
PoFiller filler = new PoFiller(ctx, m_Reference, element, this); PoFiller filler = new PoFiller(ctx, mReference, element, this);
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) { if (notfounds.size() > 0) {
element.defer = true; element.defer = true;
return; return;
} }
if (m_Reference.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, m_Reference.getName(), if (mReference.is_new() || mReference.is_Changed()) {
m_Reference.get_ID(), Object_Status); X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Reference.Table_Name,
references.add(m_Reference.getAD_Reference_ID()); X_AD_Reference.Table_ID);
element.recordId = m_Reference.getAD_Reference_ID(); String action = null;
if (!mReference.is_new()) {
if (references.contains(mReference.getAD_Reference_ID())) {
element.skip = true;
return;
}
backupRecord(ctx, impDetail.getAD_Package_Imp_ID(), X_AD_Reference.Table_Name, mReference);
action = "Update";
} else { } else {
logImportDetail(ctx, impDetail, 0, m_Reference.getName(), action = "New";
m_Reference.get_ID(), Object_Status); }
if (mReference.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mReference.getName(),
mReference.get_ID(), action);
references.add(mReference.getAD_Reference_ID());
element.recordId = mReference.getAD_Reference_ID();
} else {
logImportDetail(ctx, impDetail, 0, mReference.getName(),
mReference.get_ID(), action);
throw new POSaveFailedException("Reference"); throw new POSaveFailedException("Reference");
} }
}
} else { } else {
element.skip = true; element.skip = true;
} }
@ -119,9 +123,8 @@ public class ReferenceElementHandler extends AbstractElementHandler implements I
X_AD_Reference m_Reference = new X_AD_Reference(ctx, Reference_id, getTrxName(ctx)); X_AD_Reference m_Reference = new X_AD_Reference(ctx, Reference_id, getTrxName(ctx));
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.reference");
atts.addAttribute("", "", "type-name", "CDATA", "ad.reference"); document.startElement("", "", I_AD_Reference.Table_Name, atts);
document.startElement("", "", "reference", atts);
createReferenceBinding(ctx, document, m_Reference); createReferenceBinding(ctx, document, m_Reference);
if (m_Reference.getValidationType().compareTo("L") == 0) { if (m_Reference.getValidationType().compareTo("L") == 0) {
@ -156,7 +159,7 @@ public class ReferenceElementHandler extends AbstractElementHandler implements I
} else if (m_Reference.getValidationType().compareTo("T") == 0) { } else if (m_Reference.getValidationType().compareTo("T") == 0) {
createReferenceTable(ctx, document, Reference_id); createReferenceTable(ctx, document, Reference_id);
} }
document.endElement("", "", "reference"); document.endElement("", "", I_AD_Reference.Table_Name);
} }

View File

@ -26,7 +26,10 @@ import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException; 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_Package_Imp_Detail;
import org.compiere.model.X_AD_Ref_List; import org.compiere.model.X_AD_Ref_List;
import org.compiere.util.Env; import org.compiere.util.Env;
@ -37,7 +40,7 @@ public class ReferenceListElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) public void startElement(Properties ctx, Element element)
throws SAXException { throws SAXException {
String action = null;
String entitytype = getStringValue(element, "EntityType"); String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) { if (isProcessElement(ctx, entitytype)) {
if (isParentSkip(element, null)) { if (isParentSkip(element, null)) {
@ -45,29 +48,24 @@ public class ReferenceListElementHandler extends AbstractElementHandler {
return; return;
} }
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Ref_List.Table_Name, X_AD_Ref_List mRefList = findPO(ctx, element);
X_AD_Ref_List.Table_ID); if (mRefList == null) {
String value = getStringValue(element, "Value"); String value = getStringValue(element, "Value");
int AD_Reference_ID = 0; int AD_Reference_ID = 0;
if (getParentId(element, "reference") > 0) { if (getParentId(element, I_AD_Reference.Table_Name) > 0) {
AD_Reference_ID = getParentId(element, "reference"); AD_Reference_ID = getParentId(element, I_AD_Reference.Table_Name);
} else { } else {
String referenceName = getStringValue(element, "AD_Reference.Name"); Element referenceElement = element.properties.get(I_AD_Ref_List.COLUMNNAME_AD_Reference_ID);
AD_Reference_ID = findIdByColumn(ctx, "AD_Reference", "Name", referenceName); AD_Reference_ID = ReferenceUtils.resolveReference(ctx, referenceElement);
} }
int AD_Ref_List_ID = findIdByColumnAndParentId(ctx, "AD_Ref_List", "Value", value, "AD_Reference", AD_Reference_ID); int AD_Ref_List_ID = findIdByColumnAndParentId(ctx, "AD_Ref_List", "Value", value, "AD_Reference", AD_Reference_ID);
X_AD_Ref_List mRefList = new X_AD_Ref_List(ctx, AD_Ref_List_ID, getTrxName(ctx)); mRefList = new X_AD_Ref_List(ctx, AD_Ref_List_ID, getTrxName(ctx));
if (AD_Ref_List_ID <= 0 && isOfficialId(element, "AD_Ref_List_ID"))
mRefList.setAD_Ref_List_ID(getIntValue(element, "AD_Ref_List_ID"));
if (AD_Ref_List_ID > 0) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Ref_List.Table_Name, mRefList);
action = "Update";
} else {
action = "New";
} }
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); PoFiller filler = new PoFiller(ctx, mRefList, element, this);
List<String> excludes = defaultExcludeList(X_AD_Ref_List.Table_Name); List<String> excludes = defaultExcludeList(X_AD_Ref_List.Table_Name);
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
@ -76,6 +74,16 @@ public class ReferenceListElementHandler extends AbstractElementHandler {
return; return;
} }
if (mRefList.is_new() || mRefList.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Ref_List.Table_Name,
X_AD_Ref_List.Table_ID);
String action = null;
if (!mRefList.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Ref_List.Table_Name, mRefList);
action = "Update";
} else {
action = "New";
}
if (mRefList.save(getTrxName(ctx)) == true) { if (mRefList.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mRefList.getName(), logImportDetail(ctx, impDetail, 1, mRefList.getName(),
mRefList.get_ID(), action); mRefList.get_ID(), action);
@ -84,6 +92,7 @@ public class ReferenceListElementHandler extends AbstractElementHandler {
mRefList.get_ID(), action); mRefList.get_ID(), action);
throw new POSaveFailedException("ReferenceList"); throw new POSaveFailedException("ReferenceList");
} }
}
} else { } else {
element.skip = true; element.skip = true;
} }
@ -99,11 +108,10 @@ public class ReferenceListElementHandler extends AbstractElementHandler {
X_AD_Ref_List m_Ref_List = new X_AD_Ref_List(ctx, AD_Ref_List_ID, X_AD_Ref_List m_Ref_List = new X_AD_Ref_List(ctx, AD_Ref_List_ID,
getTrxName(ctx)); getTrxName(ctx));
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.reference.list");
atts.addAttribute("", "", "type-name", "CDATA", "ad.reference.list"); document.startElement("", "", I_AD_Ref_List.Table_Name, atts);
document.startElement("", "", "referencelist", atts);
createRefListBinding(ctx, document, m_Ref_List); createRefListBinding(ctx, document, m_Ref_List);
document.endElement("", "", "referencelist"); document.endElement("", "", I_AD_Ref_List.Table_Name);
} }
private void createRefListBinding(Properties ctx, TransformerHandler document, private void createRefListBinding(Properties ctx, TransformerHandler document,

View File

@ -29,7 +29,10 @@ import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.DatabaseAccessException; 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_Package_Imp_Detail;
import org.compiere.model.X_AD_Ref_Table; import org.compiere.model.X_AD_Ref_Table;
import org.compiere.util.DB; import org.compiere.util.DB;
@ -45,18 +48,20 @@ public class ReferenceTableElementHandler extends AbstractElementHandler {
List<String > excludes = defaultExcludeList(X_AD_Ref_Table.Table_Name); List<String > excludes = defaultExcludeList(X_AD_Ref_Table.Table_Name);
String entitytype = getStringValue(element, "EntityType"); String entitytype = getStringValue(element, "EntityType");
String name = getStringValue(element, "AD_Reference_ID", excludes);
if (isProcessElement(ctx, entitytype)) { if (isProcessElement(ctx, entitytype)) {
if (isParentSkip(element, null)) { if (isParentSkip(element, null)) {
element.skip = true; element.skip = true;
return; return;
} }
X_AD_Ref_Table refTable = findPO(ctx, element);
if (refTable == null) {
int AD_Reference_ID = 0; int AD_Reference_ID = 0;
if (getParentId(element, "reference") > 0) { if (getParentId(element, I_AD_Reference.Table_Name) > 0) {
AD_Reference_ID = getParentId(element, "reference"); AD_Reference_ID = getParentId(element, I_AD_Reference.Table_Name);
} else { } else {
AD_Reference_ID = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Reference_ID FROM AD_Reference WHERE Name = ? AND AD_Client_ID = ?", name, Env.getAD_Client_ID(ctx)); Element referenceElement = element.properties.get(I_AD_Ref_Table.COLUMNNAME_AD_Reference_ID);
AD_Reference_ID = ReferenceUtils.resolveReference(ctx, referenceElement);
} }
if (AD_Reference_ID <= 0 && isOfficialId(element, "AD_Reference_ID")) if (AD_Reference_ID <= 0 && isOfficialId(element, "AD_Reference_ID"))
AD_Reference_ID = getIntValue(element, "AD_Reference_ID"); AD_Reference_ID = getIntValue(element, "AD_Reference_ID");
@ -68,15 +73,18 @@ public class ReferenceTableElementHandler extends AbstractElementHandler {
pstmt = DB.prepareStatement(sql, getTrxName(ctx)); pstmt = DB.prepareStatement(sql, getTrxName(ctx));
pstmt.setInt(1, AD_Reference_ID); pstmt.setInt(1, AD_Reference_ID);
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
X_AD_Ref_Table refTable = null;
String action = null;
if (rs.next()) { if (rs.next()) {
refTable = new X_AD_Ref_Table(ctx, rs, getTrxName(ctx)); refTable = new X_AD_Ref_Table(ctx, rs, getTrxName(ctx));
action = "Update";
} else { } else {
refTable = new X_AD_Ref_Table(ctx, 0, getTrxName(ctx)); refTable = new X_AD_Ref_Table(ctx, 0, getTrxName(ctx));
action = "New";
} }
} catch (Exception e) {
throw new DatabaseAccessException(e.getLocalizedMessage(), e);
} finally {
DB.close(rs, pstmt);
}
}
String action = refTable.is_new() ? "New" : "Update";
PoFiller filler = new PoFiller(ctx, refTable, element, this); PoFiller filler = new PoFiller(ctx, refTable, element, this);
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) { if (notfounds.size() > 0) {
@ -84,22 +92,32 @@ public class ReferenceTableElementHandler extends AbstractElementHandler {
return; return;
} }
int tableId = refTable.getAD_Table_ID(); int tableId = refTable.getAD_Table_ID();
String columnName = getStringValue(element, "AD_Display", excludes); Element displayElement = element.properties.get("AD_Display");
int columnId = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnName, "AD_Table", tableId); int displayColumnId = 0;
refTable.setAD_Display(columnId); if (ReferenceUtils.isIDLookup(displayElement) || ReferenceUtils.isUUIDLookup(displayElement)) {
columnName = getStringValue(element, "AD_Key", excludes); displayColumnId = ReferenceUtils.resolveReference(ctx, displayElement);
columnId = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnName, "AD_Table", tableId); } else {
refTable.setAD_Key(columnId); displayColumnId = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", displayElement.contents.toString(), "AD_Table", tableId);
}
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, keyElement);
} else {
keyColumnId = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", keyElement.contents.toString(), "AD_Table", tableId);
}
refTable.setAD_Key(keyColumnId);
if (refTable.is_new() || refTable.is_Changed()) {
refTable.saveEx(); refTable.saveEx();
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Ref_Table.Table_Name, X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Ref_Table.Table_Name,
X_AD_Ref_Table.Table_ID); X_AD_Ref_Table.Table_ID);
logImportDetail(ctx, impDetail, 1, name, AD_Reference_ID, action); logImportDetail(ctx, impDetail, 1, refTable.getAD_Reference().getName(), refTable.getAD_Reference_ID(), action);
} catch (Exception e) {
throw new DatabaseAccessException(e.getLocalizedMessage(), e);
} finally {
DB.close(rs, pstmt);
} }
} else { } else {
element.skip = true; element.skip = true;
@ -114,11 +132,10 @@ public class ReferenceTableElementHandler extends AbstractElementHandler {
int Reference_id = Env.getContextAsInt(ctx, int Reference_id = Env.getContextAsInt(ctx,
X_AD_Ref_Table.COLUMNNAME_AD_Reference_ID); X_AD_Ref_Table.COLUMNNAME_AD_Reference_ID);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.reference.table");
atts.addAttribute("", "", "type-name", "CDATA", "ad.reference.table"); document.startElement("", "", I_AD_Ref_Table.Table_Name, atts);
document.startElement("", "", "referencetable", atts);
createReferenceTableBinding(ctx, document, Reference_id); createReferenceTableBinding(ctx, document, Reference_id);
document.endElement("", "", "referencetable"); document.endElement("", "", I_AD_Ref_Table.Table_Name);
} }
private void createReferenceTableBinding(Properties ctx, private void createReferenceTableBinding(Properties ctx,

View File

@ -26,7 +26,10 @@ import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException; 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.X_AD_Package_Imp_Detail; import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_ReportView_Col; import org.compiere.model.X_AD_ReportView_Col;
import org.compiere.util.DB; import org.compiere.util.DB;
@ -38,37 +41,43 @@ public class ReportViewColElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) public void startElement(Properties ctx, Element element)
throws SAXException { throws SAXException {
String action = null;
List<String> excludes = defaultExcludeList(X_AD_ReportView_Col.Table_Name); List<String> excludes = defaultExcludeList(X_AD_ReportView_Col.Table_Name);
String entitytype = getStringValue(element,"EntityType"); String entitytype = getStringValue(element,"EntityType");
if (isProcessElement(ctx, entitytype)) { if (isProcessElement(ctx, entitytype)) {
String name = getStringValue(element, "AD_ReportView.Name", excludes); excludes.add("AD_Table_ID");
X_AD_ReportView_Col mReportviewCol = findPO(ctx, element);
if (mReportviewCol == null) {
int AD_ReportView_ID = 0; int AD_ReportView_ID = 0;
if (getParentId(element, "reportview") > 0) { if (getParentId(element, I_AD_ReportView.Table_Name) > 0) {
AD_ReportView_ID = getParentId(element, "reportview"); AD_ReportView_ID = getParentId(element, I_AD_ReportView.Table_Name);
} else { } else {
AD_ReportView_ID = findIdByColumn(ctx, "AD_ReportView", "Name", name); Element rvElement = element.properties.get(I_AD_ReportView_Col.COLUMNNAME_AD_ReportView_ID);
AD_ReportView_ID = ReferenceUtils.resolveReference(ctx, rvElement);
} }
if (AD_ReportView_ID <= 0) { if (AD_ReportView_ID <= 0) {
element.defer = true; element.defer = true;
return; return;
} }
name = getStringValue(element, "AD_Column.ColumnName", excludes);
int AD_Column_ID = 0; int AD_Column_ID = 0;
if (name != null && name.trim().length() > 0) { Element columnElement = element.properties.get(I_AD_ReportView_Col.COLUMNNAME_AD_Column_ID);
AD_Column_ID = findIdByColumn(ctx, "AD_Column", "Name", name); if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) {
AD_Column_ID = ReferenceUtils.resolveReference(ctx, columnElement);
} else {
if (columnElement.contents != null && columnElement.contents.length() > 0) {
Element tableElement = element.properties.get("AD_Table_ID");
int AD_Table_ID = ReferenceUtils.resolveReference(ctx, tableElement);
AD_Column_ID = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnElement.contents.toString(),
"AD_Table", AD_Table_ID);
if (AD_Column_ID <= 0) { if (AD_Column_ID <= 0) {
element.defer = true; element.defer = true;
return; return;
} }
} }
}
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_ReportView_Col.Table_Name, String functionColumn = getStringValue(element, "FunctionColumn");
X_AD_ReportView_Col.Table_ID);
String functionColumn = getStringValue(element, "FunctionColumn", excludes);
StringBuffer sql = new StringBuffer("SELECT AD_Reportview_Col_ID FROM AD_Reportview_Col ") StringBuffer sql = new StringBuffer("SELECT AD_Reportview_Col_ID FROM AD_Reportview_Col ")
.append(" WHERE AD_Column_ID "); .append(" WHERE AD_Column_ID ");
if (AD_Column_ID > 0) if (AD_Column_ID > 0)
@ -79,24 +88,19 @@ public class ReportViewColElementHandler extends AbstractElementHandler {
sql.append(" AND AD_ReportView_ID = ?"); sql.append(" AND AD_ReportView_ID = ?");
int id = DB.getSQLValue(getTrxName(ctx), sql.toString(), functionColumn, AD_ReportView_ID); int id = DB.getSQLValue(getTrxName(ctx), sql.toString(), functionColumn, AD_ReportView_ID);
if (id < 0) id = 0; mReportviewCol = new X_AD_ReportView_Col(ctx, id > 0 ? id : 0, getTrxName(ctx));
X_AD_ReportView_Col mReportviewCol = new X_AD_ReportView_Col(ctx,
id, getTrxName(ctx));
if (id <= 0 && isOfficialId(element, "AD_ReportView_Col_ID"))
mReportviewCol.setAD_ReportView_Col_ID(getIntValue(element, "AD_ReportView_Col_ID"));
if (id > 0) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_ReportView_Col.Table_Name,
mReportviewCol);
action = "Update";
} else {
action = "New";
}
mReportviewCol.setAD_ReportView_ID(AD_ReportView_ID); mReportviewCol.setAD_ReportView_ID(AD_ReportView_ID);
if (AD_Column_ID > 0) { if (AD_Column_ID > 0) {
mReportviewCol.setAD_Column_ID(id); mReportviewCol.setAD_Column_ID(id);
} }
mReportviewCol.setFunctionColumn(functionColumn); mReportviewCol.setFunctionColumn(functionColumn);
excludes.add("FunctionColumn");
excludes.add("AD_ReportView_ID");
excludes.add("AD_Column_ID");
}
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); PoFiller filler = new PoFiller(ctx, mReportviewCol, element, this);
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
@ -105,6 +109,17 @@ public class ReportViewColElementHandler extends AbstractElementHandler {
return; return;
} }
if (mReportviewCol.is_new() || mReportviewCol.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_ReportView_Col.Table_Name,
X_AD_ReportView_Col.Table_ID);
String action = null;
if (!mReportviewCol.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_ReportView_Col.Table_Name,
mReportviewCol);
action = "Update";
} else {
action = "New";
}
if (mReportviewCol.save(getTrxName(ctx)) == true) { if (mReportviewCol.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, "" + mReportviewCol.getAD_ReportView_ID(), logImportDetail(ctx, impDetail, 1, "" + mReportviewCol.getAD_ReportView_ID(),
mReportviewCol.get_ID(), action); mReportviewCol.get_ID(), action);
@ -113,6 +128,7 @@ public class ReportViewColElementHandler extends AbstractElementHandler {
mReportviewCol.get_ID(),action); mReportviewCol.get_ID(),action);
throw new POSaveFailedException("ReportViewCol"); throw new POSaveFailedException("ReportViewCol");
} }
}
} else { } else {
element.skip = true; element.skip = true;
} }
@ -128,11 +144,10 @@ public class ReportViewColElementHandler extends AbstractElementHandler {
X_AD_ReportView_Col m_Reportview_Col = new X_AD_ReportView_Col(ctx, X_AD_ReportView_Col m_Reportview_Col = new X_AD_ReportView_Col(ctx,
AD_ReportView_Col_ID, getTrxName(ctx)); AD_ReportView_Col_ID, getTrxName(ctx));
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.report-view.column");
atts.addAttribute("", "", "type-name", "CDATA", "ad.report-view.column"); document.startElement("", "", I_AD_ReportView_Col.Table_Name, atts);
document.startElement("", "", "reportviewcol", atts);
createReportViewColBinding(ctx, document, m_Reportview_Col); createReportViewColBinding(ctx, document, m_Reportview_Col);
document.endElement("", "", "reportviewcol"); document.endElement("", "", I_AD_ReportView_Col.Table_Name);
} }
private void createReportViewColBinding(Properties ctx, TransformerHandler document, private void createReportViewColBinding(Properties ctx, TransformerHandler document,
@ -143,8 +158,13 @@ public class ReportViewColElementHandler extends AbstractElementHandler {
if (m_Reportview_Col.getAD_ReportView_Col_ID() <= PackOut.MAX_OFFICIAL_ID) if (m_Reportview_Col.getAD_ReportView_Col_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_ReportView_Col_ID", new AttributesImpl()); filler.add("AD_ReportView_Col_ID", new AttributesImpl());
filler.addTableReference("AD_Column_ID", "AD_Column", "ColumnName", new AttributesImpl()); if (m_Reportview_Col.getAD_Column_ID() > 0) {
excludes.add("AD_Column_ID"); int AD_Table_ID = m_Reportview_Col.getAD_Column().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); filler.export(excludes);
} }
} }

View File

@ -32,6 +32,7 @@ import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_ReportView;
import org.compiere.model.MPackageExp; import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail; import org.compiere.model.MPackageExpDetail;
import org.compiere.model.X_AD_Package_Exp_Detail; import org.compiere.model.X_AD_Package_Exp_Detail;
@ -51,29 +52,35 @@ public class ReportViewElementHandler extends AbstractElementHandler implements
public void startElement(Properties ctx, Element element) public void startElement(Properties ctx, Element element)
throws SAXException { throws SAXException {
String action = null;
List<String> excludes = defaultExcludeList(X_AD_ReportView.Table_Name); List<String> excludes = defaultExcludeList(X_AD_ReportView.Table_Name);
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_ReportView.Table_Name, X_AD_ReportView mReportview = findPO(ctx, element);
X_AD_ReportView.Table_ID); if (mReportview == null) {
String name = getStringValue(element, "Name"); String name = getStringValue(element, "Name");
int id = findIdByName(ctx, "AD_ReportView", name); int id = findIdByName(ctx, "AD_ReportView", name);
X_AD_ReportView mReportview = new X_AD_ReportView(ctx, id, getTrxName(ctx)); mReportview = new X_AD_ReportView(ctx, id, getTrxName(ctx));
PoFiller filler = new PoFiller(ctx, mReportview, element, this);
if (id <= 0 && isOfficialId(element, "AD_ReportView_ID"))
mReportview.setAD_ReportView_ID(getIntValue(element, "AD_ReportView_ID"));
if (id > 0) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_ReportView.Table_Name, mReportview);
action = "Update";
} else {
action = "New";
} }
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); List<String> notfound = filler.autoFill(excludes);
if (notfound.size() > 0) { if (notfound.size() > 0) {
element.defer = true; element.defer = true;
return; return;
} }
if (mReportview.is_new() || mReportview.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_ReportView.Table_Name,
X_AD_ReportView.Table_ID);
String action = null;
if (!mReportview.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_ReportView.Table_Name, mReportview);
action = "Update";
} else {
action = "New";
}
if (mReportview.save(getTrxName(ctx)) == true) { if (mReportview.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mReportview.getName(), logImportDetail(ctx, impDetail, 1, mReportview.getName(),
mReportview.get_ID(), action); mReportview.get_ID(), action);
@ -84,6 +91,7 @@ public class ReportViewElementHandler extends AbstractElementHandler implements
throw new POSaveFailedException("ReportView"); throw new POSaveFailedException("ReportView");
} }
} }
}
public void endElement(Properties ctx, Element element) throws SAXException { public void endElement(Properties ctx, Element element) throws SAXException {
} }
@ -107,11 +115,10 @@ public class ReportViewElementHandler extends AbstractElementHandler implements
throw new AdempiereException(e); throw new AdempiereException(e);
} }
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.report-view");
atts.addAttribute("", "", "type-name", "CDATA", "ad.report-view"); document.startElement("", "", I_AD_ReportView.Table_Name, atts);
document.startElement("", "", "reportView", atts);
createReportViewBinding(ctx, document, m_Reportview); createReportViewBinding(ctx, document, m_Reportview);
document.endElement("", "", "reportView"); document.endElement("", "", I_AD_ReportView.Table_Name);
String sql = "SELECT AD_PrintFormat_ID FROM AD_PrintFormat WHERE AD_ReportView_ID= " String sql = "SELECT AD_PrintFormat_ID FROM AD_PrintFormat WHERE AD_ReportView_ID= "
+ AD_ReportView_ID; + AD_ReportView_ID;

View File

@ -31,8 +31,10 @@ import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.DatabaseAccessException; import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Role;
import org.compiere.model.MPackageExp; import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail; import org.compiere.model.MPackageExpDetail;
import org.compiere.model.MRole; import org.compiere.model.MRole;
@ -65,64 +67,18 @@ public class RoleElementHandler extends AbstractElementHandler implements IPackO
public void startElement(Properties ctx, Element element) public void startElement(Properties ctx, Element element)
throws SAXException { throws SAXException {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Role.Table_Name,
X_AD_Role.Table_ID);
List<String> excludes = defaultExcludeList(X_AD_Role.Table_Name); List<String> excludes = defaultExcludeList(X_AD_Role.Table_Name);
MRole mRole = findPO(ctx, element);
if (mRole == null) {
String name = getStringValue(element, "Name", excludes); String name = getStringValue(element, "Name", excludes);
int id = findIdByName(ctx, "AD_Role", name); int id = findIdByName(ctx, "AD_Role", name);
MRole mRole = new MRole(ctx, id, getTrxName(ctx)); mRole = new MRole(ctx, id > 0 ? id : 0, getTrxName(ctx));
String action = null;
if (id <= 0 && isOfficialId(element, "AD_Role_ID"))
mRole.setAD_Role_ID(getIntValue(element, "AD_Role_ID"));
if (id > 0) {
action = "Update";
} else {
action = "New";
}
mRole.setName(name); mRole.setName(name);
name = getStringValue(element, "treemenuname", excludes);
if (name != null && name.trim().length() > 0) {
id = findIdByColumn(ctx, "AD_Tree", "Name", name);
if (id <= 0) {
element.defer = true;
return;
}
mRole.setAD_Tree_Menu_ID(id);
} }
name = getStringValue(element, "treeorgname", excludes); if (mRole.getAD_Role_ID() == 0 && isOfficialId(element, "AD_Role_ID"))
if (name != null && name.trim().length() > 0) { mRole.setAD_Role_ID(getIntValue(element, "AD_Role_ID"));
id = findIdByColumn(ctx, "AD_Tree", "Name", name);
if (id <= 0) {
element.defer = true;
return;
}
mRole.setAD_Tree_Org_ID(id);
}
name = getStringValue(element, "currencycode", excludes);
if (name != null && name.trim().length() > 0) {
id = findIdByColumn(ctx, "C_Currency", "ISO_Code", name);
if (id <= 0) {
element.defer = true;
return;
}
mRole.setC_Currency_ID(id);
}
name = getStringValue(element, "supervisorid", excludes);
if (name != null && name.trim().length() > 0) {
id = findIdByColumn(ctx, "AD_User", "Name", name);
if (id <= 0) {
element.defer = true;
return;
}
mRole.setC_Currency_ID(id);
}
PoFiller filler = new PoFiller(ctx, mRole, element, this); PoFiller filler = new PoFiller(ctx, mRole, element, this);
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
@ -131,6 +87,15 @@ public class RoleElementHandler extends AbstractElementHandler implements IPackO
return; return;
} }
if (mRole.is_new() || mRole.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Role.Table_Name,
X_AD_Role.Table_ID);
String action = null;
if (!mRole.is_new()) {
action = "Update";
} else {
action = "New";
}
if (mRole.save(getTrxName(ctx)) == true) { if (mRole.save(getTrxName(ctx)) == true) {
element.recordId = mRole.getAD_Role_ID(); element.recordId = mRole.getAD_Role_ID();
logImportDetail(ctx, impDetail, 1, mRole.getName(), mRole.get_ID(), logImportDetail(ctx, impDetail, 1, mRole.getName(), mRole.get_ID(),
@ -142,6 +107,7 @@ public class RoleElementHandler extends AbstractElementHandler implements IPackO
throw new POSaveFailedException("Role"); throw new POSaveFailedException("Role");
} }
} }
}
public void endElement(Properties ctx, Element element) throws SAXException { public void endElement(Properties ctx, Element element) throws SAXException {
} }
@ -155,9 +121,8 @@ public class RoleElementHandler extends AbstractElementHandler implements IPackO
roles.add(Role_id); roles.add(Role_id);
X_AD_Role m_Role = new X_AD_Role(ctx, Role_id, null); X_AD_Role m_Role = new X_AD_Role(ctx, Role_id, null);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.role");
atts.addAttribute("", "", "type-name", "CDATA", "ad.role"); document.startElement("", "", I_AD_Role.Table_Name, atts);
document.startElement("", "", "role", atts);
createRoleBinding(ctx, document, m_Role); createRoleBinding(ctx, document, m_Role);
// Process org access // Process org access
@ -279,7 +244,7 @@ public class RoleElementHandler extends AbstractElementHandler implements IPackO
} finally { } finally {
DB.close(rs, pstmt); DB.close(rs, pstmt);
} }
document.endElement("", "", "role"); document.endElement("", "", I_AD_Role.Table_Name);
} }
private void createTaskAccess(Properties ctx, TransformerHandler document, private void createTaskAccess(Properties ctx, TransformerHandler document,
@ -349,46 +314,19 @@ public class RoleElementHandler extends AbstractElementHandler implements IPackO
private void createRoleBinding(Properties ctx, TransformerHandler document, private void createRoleBinding(Properties ctx, TransformerHandler document,
X_AD_Role m_Role) { X_AD_Role m_Role) {
String sql = null;
String name = null;
PoExporter filler = new PoExporter(ctx, document, m_Role); PoExporter filler = new PoExporter(ctx, document, m_Role);
List<String> excludes = defaultExcludeList(X_AD_Role.Table_Name); List<String> excludes = defaultExcludeList(X_AD_Role.Table_Name);
if (m_Role.getAD_Role_ID() <= PackOut.MAX_OFFICIAL_ID) if (m_Role.getAD_Role_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_Role_ID", new AttributesImpl()); filler.add("AD_Role_ID", new AttributesImpl());
if (m_Role.getAD_Tree_Menu_ID() > 0) {
sql = "SELECT Name FROM AD_Tree WHERE AD_Tree_ID=? AND AD_Tree.TreeType='MM'";
name = DB.getSQLValueString(null, sql, m_Role.getAD_Tree_Menu_ID());
filler.addString("treemenuname", name, new AttributesImpl());
} else
filler.addString("treemenuname", "", new AttributesImpl());
if (m_Role.getAD_Tree_Org_ID() > 0) {
sql = "SELECT Name FROM AD_Tree WHERE AD_Tree_ID=? AND AD_Tree.TreeType='OO'";
name = DB.getSQLValueString(null, sql, m_Role.getAD_Tree_Org_ID());
filler.addString("treeorgname", name, new AttributesImpl());
} else
filler.addString("treeorgname", "", new AttributesImpl());
if (m_Role.getC_Currency_ID() > 0) { if (m_Role.getC_Currency_ID() > 0) {
sql = "SELECT ISO_Code FROM C_Currency WHERE C_Currency_ID=?"; AttributesImpl currencyAtts = new AttributesImpl();
name = DB.getSQLValueString(null, sql, m_Role.getC_Currency_ID()); String value = ReferenceUtils.getTableReference("C_Currency", "ISO_Code", m_Role.getC_Currency_ID(), currencyAtts);
filler.addString("currencycode", name, new AttributesImpl()); filler.addString("C_Currency_ID", value, currencyAtts);
} else } else
filler.addString("currencycode", "", new AttributesImpl()); filler.addString("C_Currency_ID", "", new AttributesImpl());
if (m_Role.getSupervisor_ID() > 0) {
sql = "SELECT Name FROM AD_User WHERE AD_User_ID=?";
name = DB.getSQLValueString(null, sql, m_Role.getC_Currency_ID());
filler.addString("supervisorid", name, new AttributesImpl());
} else
filler.addString("supervisorid", "", new AttributesImpl());
excludes.add(X_AD_Role.COLUMNNAME_Supervisor_ID);
excludes.add(X_AD_Role.COLUMNNAME_C_Currency_ID); excludes.add(X_AD_Role.COLUMNNAME_C_Currency_ID);
excludes.add(X_AD_Role.COLUMNNAME_AD_Tree_Org_ID);
excludes.add(X_AD_Role.COLUMNNAME_AD_Tree_Menu_ID);
filler.export(excludes); filler.export(excludes);
} }

View File

@ -95,8 +95,7 @@ public class SQLStatementElementHandler extends AbstractElementHandler implement
String SQLStatement = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement); String SQLStatement = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement);
String DBType = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_DBType); String DBType = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_DBType);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.sql-statement");
atts.addAttribute("", "", "type-name", "CDATA", "ad.sql-statement");
document.startElement("","","SQLStatement",atts); document.startElement("","","SQLStatement",atts);
createSQLStatmentBinding(document, SQLStatement, DBType); createSQLStatmentBinding(document, SQLStatement, DBType);
document.endElement("","","SQLStatement"); document.endElement("","","SQLStatement");

View File

@ -31,8 +31,11 @@ import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.DatabaseAccessException; import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Tab;
import org.compiere.model.I_AD_Window;
import org.compiere.model.MTab; import org.compiere.model.MTab;
import org.compiere.model.X_AD_Field; import org.compiere.model.X_AD_Field;
import org.compiere.model.X_AD_Package_Imp_Detail; import org.compiere.model.X_AD_Package_Imp_Detail;
@ -51,78 +54,96 @@ public class TabElementHandler extends AbstractElementHandler {
String entitytype = getStringValue(element, "EntityType"); String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) { if (isProcessElement(ctx, entitytype)) {
if (isParentDefer(element, "window")) { if (isParentDefer(element, I_AD_Window.Table_Name)) {
element.defer = true; element.defer = true;
return; return;
} }
MTab mTab = findPO(ctx, element);
if (mTab == null) {
String name = getStringValue(element, "Name", excludes); String name = getStringValue(element, "Name", excludes);
String windowName = getStringValue(element, "AD_Window_ID", excludes);
int windowId = 0; int windowId = 0;
if (getParentId(element, "window") > 0) { if (getParentId(element, I_AD_Window.Table_Name) > 0) {
windowId = getParentId(element, "window"); windowId = getParentId(element, I_AD_Window.Table_Name);
} else { } else {
windowId = findIdByName(ctx, "AD_Window", windowName); Element windowElement = element.properties.get(I_AD_Tab.COLUMNNAME_AD_Window_ID);
windowId = ReferenceUtils.resolveReference(ctx, windowElement);
} }
if (windowId <= 0) { if (windowId <= 0) {
element.defer = true; element.defer = true;
return; return;
} }
String tableName = getStringValue(element, "AD_Table_ID", excludes); Element tableElement = element.properties.get(I_AD_Tab.COLUMNNAME_AD_Table_ID);
int tableId = findIdByColumn(ctx, "AD_Table", "TableName", tableName); int tableId = ReferenceUtils.resolveReference(ctx, tableElement);
if (tableId <= 0) { if (tableId <= 0) {
element.defer = true; element.defer = true;
return; return;
} }
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Tab.Table_Name,
X_AD_Tab.Table_ID);
String sql = "SELECT AD_Tab_ID FROM AD_Tab where AD_Window_ID = ? " String sql = "SELECT AD_Tab_ID FROM AD_Tab where AD_Window_ID = ? "
+ " AND Name = ?" + " AND Name = ?"
+ " AND AD_Table_ID = ?"; + " AND AD_Table_ID = ?";
int id = DB.getSQLValue(getTrxName(ctx), sql, windowId, tableName, tableId); int id = DB.getSQLValue(getTrxName(ctx), sql, windowId, name, tableId);
MTab mTab = new MTab(ctx, id, getTrxName(ctx)); mTab = new MTab(ctx, id > 0 ? id : 0, getTrxName(ctx));
PoFiller filler = new PoFiller(ctx, mTab, element, this);
if (id <= 0 && isOfficialId(element, "AD_Tab_ID"))
mTab.setAD_Tab_ID(getIntValue(element, "AD_Tab_ID"));
String action = null;
if (id > 0){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Tab.Table_Name,mTab);
action = "Update";
}
else{
action = "New";
}
mTab.setAD_Table_ID(tableId); mTab.setAD_Table_ID(tableId);
mTab.setName(name); mTab.setName(name);
String columnName = getStringValue(element,"AD_Column_ID", excludes);
if (columnName != null && columnName.trim().length() > 0){
int columnId = findIdByColumnAndParentId (ctx, "AD_Column","ColumnName", columnName, "AD_Table", tableId);
mTab.setAD_Column_ID(columnId);
}
columnName = getStringValue(element, X_AD_Tab.COLUMNNAME_AD_ColumnSortOrder_ID, excludes);
if (columnName != null && columnName.trim().length() > 0){
int columnId = findIdByColumnAndParentId (ctx, "AD_Column","ColumnName", columnName, "AD_Table", tableId);
mTab.setAD_ColumnSortOrder_ID(columnId);
}
columnName = getStringValue(element, X_AD_Tab.COLUMNNAME_AD_ColumnSortYesNo_ID, excludes);
if (columnName != null && columnName.trim().length() > 0){
int columnId = findIdByColumnAndParentId (ctx, "AD_Column","ColumnName", columnName, "AD_Table", tableId);
mTab.setAD_ColumnSortYesNo_ID(columnId);
}
mTab.setAD_Window_ID(windowId); mTab.setAD_Window_ID(windowId);
}
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, columnElement);
} 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, columnElement);
} 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, columnElement);
} 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); List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) { if (notfounds.size() > 0) {
element.defer = true; element.defer = true;
return; return;
} }
if (mTab.is_new() || mTab.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Tab.Table_Name,
X_AD_Tab.Table_ID);
String action = null;
if (!mTab.is_new()){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Tab.Table_Name,mTab);
action = "Update";
}
else{
action = "New";
}
if (mTab.save(getTrxName(ctx)) == true){ if (mTab.save(getTrxName(ctx)) == true){
logImportDetail (ctx, impDetail, 1, mTab.getName(), mTab.get_ID(),action); logImportDetail (ctx, impDetail, 1, mTab.getName(), mTab.get_ID(),action);
element.recordId = mTab.getAD_Tab_ID(); element.recordId = mTab.getAD_Tab_ID();
@ -130,6 +151,7 @@ public class TabElementHandler extends AbstractElementHandler {
logImportDetail (ctx, impDetail, 0, mTab.getName(), mTab.get_ID(),action); logImportDetail (ctx, impDetail, 0, mTab.getName(), mTab.get_ID(),action);
throw new POSaveFailedException("Tab"); throw new POSaveFailedException("Tab");
} }
}
} else { } else {
element.skip = true; element.skip = true;
} }
@ -145,9 +167,8 @@ public class TabElementHandler extends AbstractElementHandler {
int AD_Tab_ID = Env.getContextAsInt(ctx, X_AD_Tab.COLUMNNAME_AD_Tab_ID); int AD_Tab_ID = Env.getContextAsInt(ctx, X_AD_Tab.COLUMNNAME_AD_Tab_ID);
X_AD_Tab m_Tab = new X_AD_Tab (ctx, AD_Tab_ID, getTrxName(ctx)); X_AD_Tab m_Tab = new X_AD_Tab (ctx, AD_Tab_ID, getTrxName(ctx));
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.window.tab");
atts.addAttribute("", "", "type-name", "CDATA", "ad.window.tab"); document.startElement("","",I_AD_Tab.Table_Name,atts);
document.startElement("","","tab",atts);
createTabBinding(ctx,document,m_Tab); createTabBinding(ctx,document,m_Tab);
//Fields tags. //Fields tags.
String sql = "SELECT AD_Field_ID FROM AD_FIELD WHERE AD_TAB_ID = " + AD_Tab_ID String sql = "SELECT AD_Field_ID FROM AD_FIELD WHERE AD_TAB_ID = " + AD_Tab_ID
@ -171,7 +192,7 @@ public class TabElementHandler extends AbstractElementHandler {
{ {
DB.close(rs, pstmt); DB.close(rs, pstmt);
} }
document.endElement("","","tab"); document.endElement("","",I_AD_Tab.Table_Name);
if(m_Tab.getAD_Process_ID() > 0 ) if(m_Tab.getAD_Process_ID() > 0 )
{ {

View File

@ -33,6 +33,7 @@ import org.adempiere.pipo2.PackIn;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Table;
import org.compiere.model.MPackageExp; import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail; import org.compiere.model.MPackageExpDetail;
import org.compiere.model.MTable; import org.compiere.model.MTable;
@ -57,6 +58,8 @@ public class TableElementHandler extends AbstractElementHandler implements IPack
String entitytype = getStringValue(element, "EntityType"); String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) { if (isProcessElement(ctx, entitytype)) {
MTable mTable = findPO(ctx, element);
if (mTable == null) {
String tableName = getStringValue(element, "TableName", excludes); String tableName = getStringValue(element, "TableName", excludes);
int id = packIn.getTableId(tableName); int id = packIn.getTableId(tableName);
@ -69,37 +72,44 @@ public class TableElementHandler extends AbstractElementHandler implements IPack
return; return;
} }
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Table.Table_Name, mTable = new MTable(ctx, id > 0 ? id : 0, getTrxName(ctx));
X_AD_Table.Table_ID); mTable.setTableName(tableName);
}
if (mTable.getAD_Table_ID() == 0 && isOfficialId(element, "AD_Table_ID"))
MTable mTable = new MTable(ctx, id, getTrxName(ctx));
if (id <= 0 && isOfficialId(element, "AD_Table_ID"))
{ {
mTable.setAD_Table_ID(getIntValue(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) {
element.defer = true;
return;
}
if (mTable.is_new() || mTable.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Table.Table_Name,
X_AD_Table.Table_ID);
String action = null; String action = null;
if (id > 0){ if (!mTable.is_new()){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(),X_AD_Table.Table_Name,mTable); backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(),X_AD_Table.Table_Name,mTable);
action = "Update"; action = "Update";
} }
else{ else{
action = "New"; action = "New";
mTable.setTableName(tableName);
} }
PoFiller filler = new PoFiller(ctx, mTable, element, this);
filler.autoFill(excludes);
if (mTable.save(getTrxName(ctx)) == true){ if (mTable.save(getTrxName(ctx)) == true){
logImportDetail (ctx, impDetail, 1, mTable.getName(),mTable.get_ID(),action); logImportDetail (ctx, impDetail, 1, mTable.getName(),mTable.get_ID(),action);
tables.add(mTable.getAD_Table_ID()); tables.add(mTable.getAD_Table_ID());
packIn.addTable(tableName, mTable.getAD_Table_ID()); packIn.addTable(mTable.getTableName(), mTable.getAD_Table_ID());
element.recordId = mTable.getAD_Table_ID(); element.recordId = mTable.getAD_Table_ID();
} }
else{ else{
logImportDetail (ctx, impDetail, 0, mTable.getName(), mTable.get_ID(),action); logImportDetail (ctx, impDetail, 0, mTable.getName(), mTable.get_ID(),action);
throw new POSaveFailedException("Table"); throw new POSaveFailedException("Table");
} }
}
} else { } else {
element.skip = true; element.skip = true;
} }
@ -118,9 +128,8 @@ public class TableElementHandler extends AbstractElementHandler implements IPack
//Export table if not already done so //Export table if not already done so
if (!exported){ if (!exported){
X_AD_Table m_Table = new X_AD_Table (ctx, AD_Table_ID, null); X_AD_Table m_Table = new X_AD_Table (ctx, AD_Table_ID, null);
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.table");
atts.addAttribute("", "", "type-name", "CDATA", "ad.table"); document.startElement("","",I_AD_Table.Table_Name,atts);
document.startElement("","","table",atts);
createTableBinding(ctx,document,m_Table); createTableBinding(ctx,document,m_Table);
String sql = "SELECT * FROM AD_Column WHERE AD_Table_ID = ? " String sql = "SELECT * FROM AD_Column WHERE AD_Table_ID = ? "
@ -169,7 +178,7 @@ public class TableElementHandler extends AbstractElementHandler implements IPack
} finally { } finally {
DB.close(rs, pstmt); DB.close(rs, pstmt);
} }
document.endElement("","","table"); document.endElement("","",I_AD_Table.Table_Name);
} }
} }
@ -191,14 +200,13 @@ public class TableElementHandler extends AbstractElementHandler implements IPack
private void createTableBinding(Properties ctx, TransformerHandler document, X_AD_Table m_Table) private void createTableBinding(Properties ctx, TransformerHandler document, X_AD_Table m_Table)
{ {
PoExporter filler = new PoExporter(ctx, document, m_Table);
if (m_Table.getAD_Table_ID() <= PackOut.MAX_OFFICIAL_ID) if (m_Table.getAD_Table_ID() <= PackOut.MAX_OFFICIAL_ID)
{ {
PoExporter filler = new PoExporter(ctx, document, null); filler.add("AD_Table_ID", new AttributesImpl());
filler.addString("AD_Table_ID", Integer.toString(m_Table.getAD_Table_ID()), new AttributesImpl());
} }
List<String> excludes = defaultExcludeList(X_AD_Table.Table_Name); List<String> excludes = defaultExcludeList(X_AD_Table.Table_Name);
PoExporter filler = new PoExporter(ctx, document, m_Table);
filler.export(excludes); filler.export(excludes);
} }

View File

@ -25,11 +25,13 @@ import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PoFiller; 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.Query;
import org.compiere.model.X_AD_Role; import org.compiere.model.X_AD_Role;
import org.compiere.model.X_AD_Task; import org.compiere.model.X_AD_Task;
import org.compiere.model.X_AD_Task_Access; import org.compiere.model.X_AD_Task_Access;
import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;
@ -41,23 +43,28 @@ public class TaskAccessElementHandler extends AbstractElementHandler {
int taskid =0; int taskid =0;
List<String> excludes = defaultExcludeList(X_AD_Task_Access.Table_Name); List<String> excludes = defaultExcludeList(X_AD_Task_Access.Table_Name);
String roleName = getStringValue(element, "AD_Role.Name", excludes); X_AD_Task_Access po = findPO(ctx, element);
if (getParentId(element, "role") > 0) { if (po == null) {
roleid = getParentId(element, "role"); if (getParentId(element, I_AD_Role.Table_Name) > 0) {
roleid = getParentId(element, I_AD_Role.Table_Name);
} else { } else {
roleid = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Role_ID FROM AD_Role WHERE Name = ? AND AD_Client_ID = ?", roleName, Env.getAD_Client_ID(ctx)); Element roleElement = element.properties.get(I_AD_Task_Access.COLUMNNAME_AD_Role_ID);
roleid = ReferenceUtils.resolveReference(ctx, roleElement);
} }
String taskName = getStringValue(element, "AD_Task.Name", excludes); Element taskElement = element.properties.get(I_AD_Task_Access.COLUMNNAME_AD_Task_ID);
taskid = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Task_ID FROM AD_Task WHERE Name = ? AND AD_Client_ID = ?", taskName, Env.getAD_Client_ID(ctx)); taskid = ReferenceUtils.resolveReference(ctx, taskElement);
Query query = new Query(ctx, "AD_Task_Access", "AD_Role_ID=? and AD_Task_ID=?", getTrxName(ctx)); Query query = new Query(ctx, "AD_Task_Access", "AD_Role_ID=? and AD_Task_ID=?", getTrxName(ctx));
X_AD_Task_Access po = query.setParameters(new Object[]{roleid, taskid}).first(); po = query.setParameters(new Object[]{roleid, taskid}).first();
if (po == null){ if (po == null){
po = new X_AD_Task_Access(ctx, 0, getTrxName(ctx)); po = new X_AD_Task_Access(ctx, 0, getTrxName(ctx));
po.setAD_Role_ID(roleid); po.setAD_Role_ID(roleid);
po.setAD_Task_ID(taskid); 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);
}
PoFiller filler = new PoFiller(ctx, po, element, this); PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) { if (notfounds.size() > 0) {
@ -75,11 +82,10 @@ public class TaskAccessElementHandler extends AbstractElementHandler {
int AD_Task_ID = Env.getContextAsInt(ctx, X_AD_Task.COLUMNNAME_AD_Task_ID); int AD_Task_ID = Env.getContextAsInt(ctx, X_AD_Task.COLUMNNAME_AD_Task_ID);
int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.task-access");
atts.addAttribute("", "", "type-name", "CDATA", "ad.task-access"); document.startElement("", "", I_AD_Task_Access.Table_Name, atts);
document.startElement("", "", "taskAccess", atts);
createTaskAccessBinding(ctx, document, AD_Task_ID, AD_Role_ID); createTaskAccessBinding(ctx, document, AD_Task_ID, AD_Role_ID);
document.endElement("", "", "taskAccess"); document.endElement("", "", I_AD_Task_Access.Table_Name);
} }
private void createTaskAccessBinding(Properties ctx, TransformerHandler document, private void createTaskAccessBinding(Properties ctx, TransformerHandler document,

View File

@ -30,6 +30,7 @@ import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Task;
import org.compiere.model.MPackageExp; import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail; import org.compiere.model.MPackageExpDetail;
import org.compiere.model.MTask; import org.compiere.model.MTask;
@ -50,27 +51,33 @@ public class TaskElementHandler extends AbstractElementHandler implements IPackO
String entitytype = getStringValue(element, "EntityType"); String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) { if (isProcessElement(ctx, entitytype)) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Task.Table_Name, MTask mTask = findPO(ctx, element);
X_AD_Task.Table_ID); if (mTask == null) {
String name = getStringValue(element, "Name"); String name = getStringValue(element, "Name");
int id = findIdByName(ctx, "AD_Task", name); int id = findIdByName(ctx, "AD_Task", name);
MTask mTask = new MTask(ctx, id, getTrxName(ctx)); mTask = new MTask(ctx, id > 0 ? id : 0, getTrxName(ctx));
String action = null;
if (id <= 0 && isOfficialId(element, "AD_Task_ID"))
mTask.setAD_Task_ID(getIntValue(element, "AD_Task_ID"));
if (id > 0) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Task.Table_Name, mTask);
action = "Update";
} else {
action = "New";
} }
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); PoFiller filler = new PoFiller(ctx, mTask, element, this);
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) { if (notfounds.size() > 0) {
element.defer = true; element.defer = true;
return; return;
} }
if (mTask.is_new() || mTask.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Task.Table_Name,
X_AD_Task.Table_ID);
String action = null;
if (!mTask.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Task.Table_Name, mTask);
action = "Update";
} else {
action = "New";
}
if (mTask.save(getTrxName(ctx)) == true) { if (mTask.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mTask.getName(), mTask.get_ID(), logImportDetail(ctx, impDetail, 1, mTask.getName(), mTask.get_ID(),
action); action);
@ -79,6 +86,7 @@ public class TaskElementHandler extends AbstractElementHandler implements IPackO
action); action);
throw new POSaveFailedException("Task"); throw new POSaveFailedException("Task");
} }
}
} else { } else {
element.skip = true; element.skip = true;
} }
@ -95,11 +103,10 @@ public class TaskElementHandler extends AbstractElementHandler implements IPackO
tasks.add(AD_Task_ID); tasks.add(AD_Task_ID);
X_AD_Task m_Task = new X_AD_Task(ctx, AD_Task_ID, null); X_AD_Task m_Task = new X_AD_Task(ctx, AD_Task_ID, null);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.task");
atts.addAttribute("", "", "type-name", "CDATA", "ad.task"); document.startElement("", "", I_AD_Task.Table_Name, atts);
document.startElement("", "", "task", atts);
createTaskBinding(ctx, document, m_Task); createTaskBinding(ctx, document, m_Task);
document.endElement("", "", "task"); document.endElement("", "", I_AD_Task.Table_Name);
} }

View File

@ -25,11 +25,12 @@ import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PoFiller; 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.Query;
import org.compiere.model.X_AD_Role; import org.compiere.model.X_AD_Role;
import org.compiere.model.X_AD_User; import org.compiere.model.X_AD_User;
import org.compiere.model.X_AD_User_Roles; import org.compiere.model.X_AD_User_Roles;
import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;
@ -43,27 +44,33 @@ public class UserRoleElementHandler extends AbstractElementHandler {
List<String> excludes = defaultExcludeList(X_AD_User_Roles.Table_Name); List<String> excludes = defaultExcludeList(X_AD_User_Roles.Table_Name);
String userName = getStringValue(element, "AD_User.Name", excludes); X_AD_User_Roles po = findPO(ctx, element);
userid = DB.getSQLValue(getTrxName(ctx), "SELECT AD_User_ID FROM AD_User WHERE Name = ? AND AD_Client_ID = ?", userName, Env.getAD_Client_ID(ctx)); if (po == null) {
Element userElement = element.properties.get(I_AD_User_Roles.COLUMNNAME_AD_User_ID);
userid = ReferenceUtils.resolveReference(ctx, userElement);
String roleName = getStringValue(element, "rolename", excludes);
if (getParentId(element, "role") > 0) { if (getParentId(element, "role") > 0) {
roleid = getParentId(element, "role"); roleid = getParentId(element, "role");
} else { } else {
roleid = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Role_ID FROM AD_Role WHERE Name= ? AND AD_Client_ID = ?", roleName, Env.getAD_Client_ID(ctx)); Element roleElement = element.properties.get(I_AD_User_Roles.COLUMNNAME_AD_Role_ID);
roleid = ReferenceUtils.resolveReference(ctx, roleElement);
} }
String orgName = getStringValue(element, "AD_Org.Name", excludes); Element orgElement = element.properties.get(I_AD_User_Roles.COLUMNNAME_AD_Org_ID);
orgid = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Org_ID FROM AD_Org WHERE Name = ? AND AD_Client_ID = ?", orgName, Env.getAD_Client_ID(ctx)); orgid = ReferenceUtils.resolveReference(ctx, orgElement);
Query query = new Query(ctx, "AD_User_Roles", "AD_User_ID = ? AND AD_Role_ID = ? AND AD_Org_ID = ?", getTrxName(ctx)); Query query = new Query(ctx, "AD_User_Roles", "AD_User_ID = ? AND AD_Role_ID = ? AND AD_Org_ID = ?", getTrxName(ctx));
X_AD_User_Roles po = query.setParameters(new Object[]{userid, roleid, orgid}).first(); po = query.setParameters(new Object[]{userid, roleid, orgid}).first();
if (po == null) { if (po == null) {
po = new X_AD_User_Roles(ctx, 0, getTrxName(ctx)); po = new X_AD_User_Roles(ctx, 0, getTrxName(ctx));
po.setAD_Org_ID(orgid); po.setAD_Org_ID(orgid);
po.setAD_Role_ID(roleid); po.setAD_Role_ID(roleid);
po.setAD_User_ID(userid); 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);
}
PoFiller filler = new PoFiller(ctx, po, element, this); PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) { if (notfounds.size() > 0) {
@ -82,11 +89,10 @@ public class UserRoleElementHandler extends AbstractElementHandler {
int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID);
int AD_Org_ID = Env.getContextAsInt(ctx, "AD_Org_ID"); int AD_Org_ID = Env.getContextAsInt(ctx, "AD_Org_ID");
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.user-role");
atts.addAttribute("", "", "type-name", "CDATA", "ad.user-role"); document.startElement("", "", I_AD_User_Roles.Table_Name, atts);
document.startElement("", "", "userRole", atts);
createUserAssignBinding(ctx, document, AD_User_ID,AD_Role_ID, AD_Org_ID); createUserAssignBinding(ctx, document, AD_User_ID,AD_Role_ID, AD_Org_ID);
document.endElement("", "", "userRole"); document.endElement("", "", I_AD_User_Roles.Table_Name);
} }
private void createUserAssignBinding(Properties ctx, TransformerHandler document, private void createUserAssignBinding(Properties ctx, TransformerHandler document,

View File

@ -25,11 +25,13 @@ import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PoFiller; 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.Query;
import org.compiere.model.X_AD_Role; import org.compiere.model.X_AD_Role;
import org.compiere.model.X_AD_Window; import org.compiere.model.X_AD_Window;
import org.compiere.model.X_AD_Window_Access; import org.compiere.model.X_AD_Window_Access;
import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;
@ -41,31 +43,34 @@ public class WindowAccessElementHandler extends AbstractElementHandler {
int windowid =0; int windowid =0;
List<String> excludes = defaultExcludeList(X_AD_Window_Access.Table_Name); List<String> excludes = defaultExcludeList(X_AD_Window_Access.Table_Name);
String roleName = getStringValue(element, "AD_Role.Name", excludes); X_AD_Window_Access po = findPO(ctx, element);
if (getParentId(element, "role") > 0) { if (po == null) {
roleid = getParentId(element, "role"); if (getParentId(element, I_AD_Role.Table_Name) > 0) {
roleid = getParentId(element, I_AD_Role.Table_Name);
} else { } else {
roleid = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Role_ID FROM AD_Role WHERE Name = ? AND AD_Client_ID = ?", roleName, Env.getAD_Client_ID(ctx)); Element roleElement = element.properties.get(I_AD_Window_Access.COLUMNNAME_AD_Role_ID);
roleid = ReferenceUtils.resolveReference(ctx, roleElement);
} }
if (roleid <= 0) { if (roleid <= 0) {
element.defer = true; element.defer = true;
return; return;
} }
String windowName = getStringValue(element, "AD_Window.Name", excludes); Element windowElement = element.properties.get(I_AD_Window_Access.COLUMNNAME_AD_Window_ID);
windowid = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Window_ID FROM AD_Window WHERE Name = ? AND AD_Client_ID = ?", windowName, Env.getAD_Client_ID(ctx)); windowid = ReferenceUtils.resolveReference(ctx, windowElement);
if (windowid <= 0) { if (windowid <= 0) {
element.defer = true; element.defer = true;
return; return;
} }
Query query = new Query(ctx, "AD_Window_Access", "AD_Role_ID=? and AD_Window_ID=?", getTrxName(ctx)); Query query = new Query(ctx, "AD_Window_Access", "AD_Role_ID=? and AD_Window_ID=?", getTrxName(ctx));
X_AD_Window_Access po = query.setParameters(new Object[]{roleid, windowid}).first(); po = query.setParameters(new Object[]{roleid, windowid}).first();
if (po == null) { if (po == null) {
po = new X_AD_Window_Access(ctx, 0, getTrxName(ctx)); po = new X_AD_Window_Access(ctx, 0, getTrxName(ctx));
po.setAD_Role_ID(roleid); po.setAD_Role_ID(roleid);
po.setAD_Window_ID(windowid); po.setAD_Window_ID(windowid);
} }
}
PoFiller filler = new PoFiller(ctx, po, element, this); PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) { if (notfounds.size() > 0) {
@ -83,11 +88,10 @@ public class WindowAccessElementHandler extends AbstractElementHandler {
int AD_Window_ID = Env.getContextAsInt(ctx, X_AD_Window.COLUMNNAME_AD_Window_ID); int AD_Window_ID = Env.getContextAsInt(ctx, X_AD_Window.COLUMNNAME_AD_Window_ID);
int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.window-access");
atts.addAttribute("", "", "type-name", "CDATA", "ad.window-access"); document.startElement("", "", I_AD_Window_Access.Table_Name, atts);
document.startElement("", "", "windowAccess", atts);
createWindowAccessBinding(ctx, document, AD_Window_ID, AD_Role_ID); createWindowAccessBinding(ctx, document, AD_Window_ID, AD_Role_ID);
document.endElement("", "", "windowAccess"); document.endElement("", "", I_AD_Window_Access.Table_Name);
} }
private void createWindowAccessBinding(Properties ctx, TransformerHandler document, private void createWindowAccessBinding(Properties ctx, TransformerHandler document,

View File

@ -34,6 +34,7 @@ import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.DatabaseAccessException; import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Window;
import org.compiere.model.MPackageExp; import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail; import org.compiere.model.MPackageExpDetail;
import org.compiere.model.MWindow; import org.compiere.model.MWindow;
@ -60,34 +61,43 @@ public class WindowElementHandler extends AbstractElementHandler implements IPac
String entitytype = getStringValue(element, "EntityType"); String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) { if (isProcessElement(ctx, entitytype)) {
MWindow mWindow = findPO(ctx, element);
if (mWindow == null) {
String name = getStringValue(element, "Name", excludes); String name = getStringValue(element, "Name", excludes);
int id = findIdByName(ctx, "AD_Window", name); int id = findIdByName(ctx, "AD_Window", name);
if (id > 0 && windows.contains(id)) { if (id > 0 && windows.contains(id)) {
return; return;
} }
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Window.Table_Name, mWindow = new MWindow(ctx, id > 0 ? id : 0, getTrxName(ctx));
X_AD_Window.Table_ID);
MWindow mWindow = new MWindow(ctx, id, getTrxName(ctx));
if (id <= 0 && isOfficialId(element, "AD_Window_ID"))
mWindow.setAD_Window_ID(getIntValue(element, "AD_Window_ID"));
String action = null;
if (id > 0) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Window.Table_Name, mWindow);
action = "Update";
} else {
action = "New";
}
mWindow.setName(name); mWindow.setName(name);
} 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); PoFiller filler = new PoFiller(ctx, mWindow, element, this);
excludes.add("Name");
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) { if (notfounds.size() > 0) {
element.defer = true; element.defer = true;
return; return;
} }
if (mWindow.is_new() || mWindow.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Window.Table_Name,
X_AD_Window.Table_ID);
String action = null;
if (!mWindow.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Window.Table_Name, mWindow);
action = "Update";
} else {
action = "New";
}
if (mWindow.save(getTrxName(ctx)) == true) { if (mWindow.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mWindow.getName(), mWindow logImportDetail(ctx, impDetail, 1, mWindow.getName(), mWindow
.get_ID(), action); .get_ID(), action);
@ -98,6 +108,7 @@ public class WindowElementHandler extends AbstractElementHandler implements IPac
.get_ID(), action); .get_ID(), action);
throw new POSaveFailedException("Window"); throw new POSaveFailedException("Window");
} }
}
} else { } else {
element.skip = true; element.skip = true;
} }
@ -113,9 +124,8 @@ public class WindowElementHandler extends AbstractElementHandler implements IPac
X_AD_Window m_Window = new X_AD_Window(ctx, AD_Window_ID, null); X_AD_Window m_Window = new X_AD_Window(ctx, AD_Window_ID, null);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.window");
atts.addAttribute("", "", "type-name", "CDATA", "ad.window"); document.startElement("", "", I_AD_Window.Table_Name, atts);
document.startElement("", "", "window", atts);
createWindowBinding(ctx, document, m_Window); createWindowBinding(ctx, document, m_Window);
// Tab Tag // Tab Tag
String sql = "SELECT AD_Tab_ID, AD_Table_ID FROM AD_TAB WHERE AD_WINDOW_ID = " String sql = "SELECT AD_Tab_ID, AD_Table_ID FROM AD_TAB WHERE AD_WINDOW_ID = "
@ -148,7 +158,7 @@ public class WindowElementHandler extends AbstractElementHandler implements IPac
//TODO: export of ad_image and ad_color use //TODO: export of ad_image and ad_color use
// Loop tags. // Loop tags.
document.endElement("", "", "window"); document.endElement("", "", I_AD_Window.Table_Name);
// Preference Tag // Preference Tag
sql = "SELECT AD_Preference_ID FROM AD_PREFERENCE WHERE AD_WINDOW_ID = ?"; sql = "SELECT AD_Preference_ID FROM AD_PREFERENCE WHERE AD_WINDOW_ID = ?";

View File

@ -25,11 +25,13 @@ import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PoFiller; 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.Query;
import org.compiere.model.X_AD_Role; import org.compiere.model.X_AD_Role;
import org.compiere.model.X_AD_Workflow; import org.compiere.model.X_AD_Workflow;
import org.compiere.model.X_AD_Workflow_Access; import org.compiere.model.X_AD_Workflow_Access;
import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;
@ -41,18 +43,18 @@ public class WorkflowAccessElementHandler extends AbstractElementHandler {
int workflowid =0; int workflowid =0;
List<String> excludes = defaultExcludeList(X_AD_Workflow_Access.Table_Name); List<String> excludes = defaultExcludeList(X_AD_Workflow_Access.Table_Name);
String roleName = getStringValue(element, "AD_Role.Name", excludes); X_AD_Workflow_Access po = findPO(ctx, element);
if (getParentId(element, "role") > 0) { if (po == null) {
roleid = getParentId(element, "role"); if (getParentId(element, I_AD_Role.Table_Name) > 0) {
roleid = getParentId(element, I_AD_Role.Table_Name);
} else { } else {
roleid = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Role_ID FROM AD_Role WHERE Name = ? AND AD_Client_ID = ?", roleName, Env.getAD_Client_ID(ctx)); Element roleElement = element.properties.get(I_AD_Workflow_Access.COLUMNNAME_AD_Role_ID);
roleid = ReferenceUtils.resolveReference(ctx, roleElement);
} }
String workflowValue = getStringValue(element, "AD_Workflow.Value", excludes); Element wfElement = element.properties.get(I_AD_Workflow_Access.COLUMNNAME_AD_Workflow_ID);
if (workflowValue != null && workflowValue.trim().length() > 0) workflowid = ReferenceUtils.resolveReference(ctx, wfElement);
workflowid = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Workflow_ID FROM AD_Workflow WHERE Value = ? AND AD_Client_ID = ?", workflowValue, Env.getAD_Client_ID(ctx));
X_AD_Workflow_Access po = null;
Query query = new Query(ctx, "AD_Workflow_Access", "AD_Role_ID=? and AD_Workflow_ID=?", getTrxName(ctx)); Query query = new Query(ctx, "AD_Workflow_Access", "AD_Role_ID=? and AD_Workflow_ID=?", getTrxName(ctx));
po = query.setParameters(new Object[]{roleid, workflowid}).first(); po = query.setParameters(new Object[]{roleid, workflowid}).first();
if (po == null) { if (po == null) {
@ -60,6 +62,9 @@ public class WorkflowAccessElementHandler extends AbstractElementHandler {
po.setAD_Role_ID(roleid); po.setAD_Role_ID(roleid);
po.setAD_Workflow_ID(workflowid); 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);
}
PoFiller filler = new PoFiller(ctx, po, element, this); PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
@ -78,11 +83,10 @@ public class WorkflowAccessElementHandler extends AbstractElementHandler {
int AD_Workflow_ID = Env.getContextAsInt(ctx, X_AD_Workflow.COLUMNNAME_AD_Workflow_ID); int AD_Workflow_ID = Env.getContextAsInt(ctx, X_AD_Workflow.COLUMNNAME_AD_Workflow_ID);
int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.workflow-access");
atts.addAttribute("", "", "type-name", "CDATA", "ad.workflow-access"); document.startElement("", "", I_AD_Workflow_Access.Table_Name, atts);
document.startElement("", "", "workflowAccess", atts);
createWorkflowAccessBinding(ctx, document, AD_Workflow_ID, AD_Role_ID); createWorkflowAccessBinding(ctx, document, AD_Workflow_ID, AD_Role_ID);
document.endElement("", "", "workflowAccess"); document.endElement("", "", I_AD_Workflow_Access.Table_Name);
} }
private void createWorkflowAccessBinding(Properties ctx, TransformerHandler document, private void createWorkflowAccessBinding(Properties ctx, TransformerHandler document,

View File

@ -32,6 +32,7 @@ import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException; import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Workflow;
import org.compiere.model.MPackageExp; import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail; import org.compiere.model.MPackageExpDetail;
import org.compiere.model.X_AD_Package_Exp_Detail; import org.compiere.model.X_AD_Package_Exp_Detail;
@ -61,6 +62,8 @@ public class WorkflowElementHandler extends AbstractElementHandler implements IP
String entitytype = getStringValue(element, "EntityType"); String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) { if (isProcessElement(ctx, entitytype)) {
MWorkflow mWorkflow = findPO(ctx, element);
if (mWorkflow == null) {
String workflowValue = getStringValue(element, "Value", excludes); String workflowValue = getStringValue(element, "Value", excludes);
int id = findIdByColumn(ctx, "AD_Workflow", "Value", workflowValue); int id = findIdByColumn(ctx, "AD_Workflow", "Value", workflowValue);
if (id > 0 && workflows.contains(id)) { if (id > 0 && workflows.contains(id)) {
@ -68,27 +71,30 @@ public class WorkflowElementHandler extends AbstractElementHandler implements IP
return; return;
} }
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Workflow.Table_Name, mWorkflow = new MWorkflow(ctx, id > 0 ? id : 0, getTrxName(ctx));
X_AD_Workflow.Table_ID); mWorkflow.setValue(workflowValue);
MWorkflow mWorkflow = new MWorkflow(ctx, id, getTrxName(ctx));
PoFiller filler = new PoFiller(ctx, mWorkflow, element, this);
String action = null;
if (id <= 0 && isOfficialId(element, "AD_Workflow_ID"))
filler.setInteger("AD_Workflow_ID");
if (id > 0) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Workflow.Table_Name, mWorkflow);
action = "Update";
} else {
action = "New";
} }
mWorkflow.setValue(workflowValue); 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); List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) { if (notfounds.size() > 0) {
element.defer = true; element.defer = true;
return; return;
} }
if (mWorkflow.is_new() || mWorkflow.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Workflow.Table_Name,
X_AD_Workflow.Table_ID);
String action = null;
if (!mWorkflow.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Workflow.Table_Name, mWorkflow);
action = "Update";
} else {
action = "New";
}
if (mWorkflow.save(getTrxName(ctx)) == true) { if (mWorkflow.save(getTrxName(ctx)) == true) {
log.info("m_Workflow save success"); log.info("m_Workflow save success");
logImportDetail(ctx,impDetail, 1, mWorkflow.getName(), mWorkflow logImportDetail(ctx,impDetail, 1, mWorkflow.getName(), mWorkflow
@ -101,6 +107,7 @@ public class WorkflowElementHandler extends AbstractElementHandler implements IP
.get_ID(), action); .get_ID(), action);
throw new POSaveFailedException("MWorkflow"); throw new POSaveFailedException("MWorkflow");
} }
}
} else { } else {
element.skip = true; element.skip = true;
} }
@ -160,7 +167,7 @@ public class WorkflowElementHandler extends AbstractElementHandler implements IP
atts.addAttribute("", "", "type", "CDATA", "object"); atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.workflow"); atts.addAttribute("", "", "type-name", "CDATA", "ad.workflow");
document.startElement("", "", "workflow", atts); document.startElement("", "", I_AD_Workflow.Table_Name, atts);
createWorkflowBinding(ctx, document, m_Workflow); createWorkflowBinding(ctx, document, m_Workflow);
String sql = "SELECT AD_WF_Node_ID FROM AD_WF_Node WHERE AD_Workflow_ID = " String sql = "SELECT AD_WF_Node_ID FROM AD_WF_Node WHERE AD_Workflow_ID = "
+ AD_Workflow_ID; + AD_Workflow_ID;
@ -197,7 +204,7 @@ public class WorkflowElementHandler extends AbstractElementHandler implements IP
throw new DBException(e); throw new DBException(e);
} finally { } finally {
DB.close(rs, pstmt); DB.close(rs, pstmt);
document.endElement("", "", "workflow"); document.endElement("", "", I_AD_Workflow.Table_Name);
} }
} }

View File

@ -27,7 +27,10 @@ import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException; 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_Package_Imp_Detail;
import org.compiere.model.X_AD_WF_Node; import org.compiere.model.X_AD_WF_Node;
import org.compiere.util.DB; import org.compiere.util.DB;
@ -47,53 +50,58 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler {
element.skip = true; element.skip = true;
return; return;
} }
if (isParentDefer(element, "workflow")) { if (isParentDefer(element, I_AD_Workflow.Table_Name)) {
element.unresolved = "Parent element mark as defer: " + getStringValue(element, "AD_Workflow.Value"); element.unresolved = "Parent element mark as defer: " + getStringValue(element, "AD_Workflow.Value");
element.defer = true; element.defer = true;
return; return;
} }
X_AD_WF_Node mWFNode = findPO(ctx, element);
if (mWFNode == null) {
int workflowId = 0; int workflowId = 0;
String workflowValue = getStringValue(element, "AD_Workflow.Value", excludes); Element wfElement = element.properties.get(I_AD_WF_Node.COLUMNNAME_AD_Workflow_ID);
if (getParentId(element, "workflow") > 0) { if (getParentId(element, I_AD_Workflow.Table_Name) > 0) {
workflowId = getParentId(element, "workflow"); workflowId = getParentId(element, I_AD_Workflow.Table_Name);
} else { } else {
workflowId = findIdByColumn(ctx, "AD_Workflow", "Value", workflowValue); workflowId = ReferenceUtils.resolveReference(ctx, wfElement);
} }
if (workflowId <= 0) { if (workflowId <= 0) {
element.defer = true; element.defer = true;
element.unresolved = "AD_Workflow: " + workflowValue; element.unresolved = "AD_Workflow: " + wfElement.contents;
return; return;
} }
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_WF_Node.Table_Name,
X_AD_WF_Node.Table_ID);
String workflowNodeValue = getStringValue(element, "Value", excludes); String workflowNodeValue = getStringValue(element, "Value", excludes);
StringBuffer sqlB = new StringBuffer( StringBuffer sqlB = new StringBuffer(
"SELECT AD_WF_Node_ID FROM AD_WF_Node WHERE AD_Workflow_ID=? and Value =?"); "SELECT AD_WF_Node_ID FROM AD_WF_Node WHERE AD_Workflow_ID=? and Value =?");
int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), workflowId, workflowNodeValue); int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), workflowId, workflowNodeValue);
mWFNode = new X_AD_WF_Node(ctx, id > 0 ? id : 0, getTrxName(ctx));
X_AD_WF_Node mWFNode = new X_AD_WF_Node(ctx, id, getTrxName(ctx)); mWFNode.setValue(workflowNodeValue);
PoFiller filler = new PoFiller(ctx, mWFNode, element, this);
String action = null;
if (id <= 0 && isOfficialId(element, "AD_WF_Node_ID"))
mWFNode.setAD_WF_Node_ID(getIntValue(element, "AD_WF_Node_ID"));
if (id > 0) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_WF_Node.Table_Name, mWFNode);
action = "Update";
} else {
action = "New";
}
mWFNode.setValue(workflowValue);
mWFNode.setAD_Workflow_ID(workflowId); mWFNode.setAD_Workflow_ID(workflowId);
excludes.add(I_AD_WF_Node.COLUMNNAME_AD_Workflow_ID);
excludes.add("Value");
}
PoFiller filler = new PoFiller(ctx, mWFNode, element, this);
List<String> notfounds = filler.autoFill(excludes); List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) { if (notfounds.size() > 0) {
element.defer = true; element.defer = true;
return; return;
} }
if (mWFNode.is_new() || mWFNode.is_Changed()) {
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";
} else {
action = "New";
}
if (mWFNode.save(getTrxName(ctx)) == true) { if (mWFNode.save(getTrxName(ctx)) == true) {
log.info("m_WFNode save success"); log.info("m_WFNode save success");
logImportDetail(ctx, impDetail, 1, mWFNode.getName(), mWFNode logImportDetail(ctx, impDetail, 1, mWFNode.getName(), mWFNode
@ -104,6 +112,7 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler {
.get_ID(), action); .get_ID(), action);
throw new POSaveFailedException("WorkflowNode"); throw new POSaveFailedException("WorkflowNode");
} }
}
} else { } else {
element.skip = true; element.skip = true;
} }
@ -120,11 +129,10 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler {
X_AD_WF_Node m_WF_Node = new X_AD_WF_Node(ctx, AD_WF_Node_ID, X_AD_WF_Node m_WF_Node = new X_AD_WF_Node(ctx, AD_WF_Node_ID,
getTrxName(ctx)); getTrxName(ctx));
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.workflow.node");
atts.addAttribute("", "", "type-name", "CDATA", "ad.workflow.node"); document.startElement("", "", I_AD_WF_Node.Table_Name, atts);
document.startElement("", "", "workflowNode", atts);
createWorkflowNodeBinding(ctx, document, m_WF_Node); createWorkflowNodeBinding(ctx, document, m_WF_Node);
document.endElement("", "", "workflowNode"); document.endElement("", "", I_AD_WF_Node.Table_Name);
} }
private void createWorkflowNodeBinding(Properties ctx, TransformerHandler document, private void createWorkflowNodeBinding(Properties ctx, TransformerHandler document,

View File

@ -26,7 +26,10 @@ import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException; 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.X_AD_Package_Imp_Detail; import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_WF_NextCondition; import org.compiere.model.X_AD_WF_NextCondition;
import org.compiere.util.DB; import org.compiere.util.DB;
@ -49,97 +52,106 @@ public class WorkflowNodeNextConditionElementHandler extends
return; return;
} }
MWFNextCondition mWFNodeNextCondition = findPO(ctx, element);
if (mWFNodeNextCondition == null) {
int workflowId = 0; int workflowId = 0;
String workflowValue = getStringValue(element, "AD_Workflow.Value", excludes); Element wfElement = element.properties.get("AD_Workflow_ID");
if (getParentId(element, "workflow") > 0) { if (getParentId(element, I_AD_Workflow.Table_Name) > 0) {
workflowId = getParentId(element, "workflow"); workflowId = getParentId(element, I_AD_Workflow.Table_Name);
} else { } else {
workflowId = findIdByColumn(ctx, "AD_Workflow", "Value", workflowValue); workflowId = ReferenceUtils.resolveReference(ctx, wfElement);
} }
if (workflowId <= 0) { if (workflowId <= 0) {
element.defer = true; element.defer = true;
element.unresolved = "AD_Workflow: " + workflowValue; element.unresolved = "AD_Workflow: " + wfElement.contents;
return; return;
} }
String workflowNodeValue = getStringValue(element, "AD_WF_Node.Value", excludes); int AD_WF_NodeNext_ID = 0;
String workflowNodeNextValue = getStringValue(element, "AD_WF_Next_ID.AD_WF_Node.Value", excludes); Element nodeNextElement = element.properties.get(I_AD_WF_NextCondition.COLUMNNAME_AD_WF_NodeNext_ID);
if (ReferenceUtils.isIDLookup(nodeNextElement) || ReferenceUtils.isUUIDLookup(nodeNextElement)) {
String sql = "SELECT AD_WF_Node_ID FROM AD_WF_Node WHERE AD_Workflow_ID=? AND Value=? AND AD_Client_ID=?"; AD_WF_NodeNext_ID = ReferenceUtils.resolveReference(ctx, nodeNextElement);
} else {
int wfNodeId = DB.getSQLValue(getTrxName(ctx), sql, Element wfnElement = element.properties.get("AD_WF_Node_ID");
workflowId, workflowNodeValue, Env.getAD_Client_ID(ctx)); int wfNodeId = ReferenceUtils.resolveReference(ctx, wfnElement);
if (wfNodeId <= 0) { if (wfNodeId <= 0) {
element.unresolved = "AD_WF_Node=" + workflowNodeValue; element.unresolved = "AD_WF_Node=" + wfnElement.contents;
element.defer = true; element.defer = true;
return; return;
} }
int wfNodeNextId = DB.getSQLValue(getTrxName(ctx), sql, Element nextElement = element.properties.get("AD_WF_Next_ID");
workflowId, workflowNodeNextValue, Env.getAD_Client_ID(ctx)); int wfNodeNextId = ReferenceUtils.resolveReference(ctx, nextElement);
if (wfNodeNextId <= 0) { if (wfNodeNextId <= 0) {
element.unresolved = "AD_WF_Node=" + workflowNodeNextValue; element.unresolved = "AD_WF_Node=" + nextElement.contents;
element.defer = true; element.defer = true;
return; return;
} }
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_WF_NextCondition.Table_Name, String sql = "SELECT AD_WF_NodeNext_ID FROM AD_WF_NodeNext WHERE AD_WF_Node_ID =? and AD_WF_Next_ID =?";
X_AD_WF_NextCondition.Table_ID); AD_WF_NodeNext_ID = DB.getSQLValue(getTrxName(ctx), sql, wfNodeId, wfNodeNextId);
}
sql = "SELECT AD_WF_NodeNext_ID FROM AD_WF_NodeNext WHERE AD_WF_Node_ID =? and AD_WF_Next_ID =?"; String sql = "SELECT AD_WF_NextCondition_ID FROM AD_WF_NextCondition WHERE AD_WF_NodeNext_ID =?";
int AD_WF_NodeNext_ID = DB.getSQLValue(getTrxName(ctx), sql, wfNodeId, wfNodeNextId);
sql = "SELECT AD_WF_NextCondition_ID FROM AD_WF_NextCondition WHERE AD_WF_NodeNext_ID =?";
int id = DB.getSQLValue(getTrxName(ctx), sql, AD_WF_NodeNext_ID); int id = DB.getSQLValue(getTrxName(ctx), sql, AD_WF_NodeNext_ID);
MWFNextCondition m_WFNodeNextCondition = new MWFNextCondition(ctx, mWFNodeNextCondition = new MWFNextCondition(ctx, id > 0 ? id : 0, getTrxName(ctx));
id, getTrxName(ctx)); mWFNodeNextCondition.setAD_WF_NodeNext_ID(AD_WF_NodeNext_ID);
PoFiller filler = new PoFiller(ctx, m_WFNodeNextCondition, element, this);
String Object_Status = null;
if (id <= 0 && isOfficialId(element, "AD_WF_NextCondition_ID"))
filler.setInteger("AD_WF_NextCondition_ID");
if (id > 0) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_WF_NextCondition.Table_Name,
m_WFNodeNextCondition);
Object_Status = "Update";
} else {
Object_Status = "New";
} }
String tableName = getStringValue(element, "AD_Table.TableName", excludes); PoFiller filler = new PoFiller(ctx, mWFNodeNextCondition, element, this);
String columnName = getStringValue(element, "AD_Column.ColumnName", excludes); if (mWFNodeNextCondition.get_ID() == 0 && isOfficialId(element, "AD_WF_NextCondition_ID"))
sql = "SELECT AD_Column.AD_Column_ID FROM AD_Column, AD_Table WHERE AD_Column.AD_Table_ID = AD_Table.AD_Table_ID and AD_Table.TableName = ?" filler.setInteger("AD_WF_NextCondition_ID");
+ " and AD_Column.ColumnName = ?";
int columnId = DB.getSQLValue(getTrxName(ctx), sql, tableName, columnName); Element tableElement = element.properties.get("AD_Table_ID");
m_WFNodeNextCondition.setAD_Column_ID(columnId); Element columnElement = element.properties.get("AD_Column_ID");
m_WFNodeNextCondition.setAD_WF_NodeNext_ID(AD_WF_NodeNext_ID); int columnId = 0;
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) {
columnId = ReferenceUtils.resolveReference(ctx, columnElement);
} else {
int AD_Table_ID = ReferenceUtils.resolveReference(ctx, tableElement);
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); List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) { if (notfounds.size() > 0) {
element.defer = true; element.defer = true;
return; return;
} }
if (m_WFNodeNextCondition.save(getTrxName(ctx)) == true) {
if (mWFNodeNextCondition.is_new() || mWFNodeNextCondition.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_WF_NextCondition.Table_Name,
X_AD_WF_NextCondition.Table_ID);
String action = null;
if (!mWFNodeNextCondition.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_WF_NextCondition.Table_Name,
mWFNodeNextCondition);
action = "Update";
} else {
action = "New";
}
if (mWFNodeNextCondition.save(getTrxName(ctx)) == true) {
log.info("m_WFNodeNextCondition save success"); log.info("m_WFNodeNextCondition save success");
logImportDetail( logImportDetail(
ctx, ctx,
impDetail, impDetail,
1, 1,
String.valueOf(m_WFNodeNextCondition.get_ID()), String.valueOf(mWFNodeNextCondition.get_ID()),
m_WFNodeNextCondition.get_ID(), mWFNodeNextCondition.get_ID(),
Object_Status); action);
} else { } else {
log.info("m_WFNodeNextCondition save failure"); log.info("m_WFNodeNextCondition save failure");
logImportDetail( logImportDetail(
ctx, ctx,
impDetail, impDetail,
0, 0,
String.valueOf(m_WFNodeNextCondition.get_ID()), String.valueOf(mWFNodeNextCondition.get_ID()),
m_WFNodeNextCondition.get_ID(), mWFNodeNextCondition.get_ID(),
Object_Status); action);
throw new POSaveFailedException("WorkflowNodeNextCondition"); throw new POSaveFailedException("WorkflowNodeNextCondition");
} }
}
} else { } else {
element.skip = true; element.skip = true;
} }
@ -155,47 +167,40 @@ public class WorkflowNodeNextConditionElementHandler extends
X_AD_WF_NextCondition m_WF_NodeNextCondition = new X_AD_WF_NextCondition( X_AD_WF_NextCondition m_WF_NodeNextCondition = new X_AD_WF_NextCondition(
ctx, ad_wf_nodenextcondition_id, null); ctx, ad_wf_nodenextcondition_id, null);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.workflow.node.next-condition");
atts.addAttribute("", "", "type-name", "CDATA", "ad.workflow.node.next-condition"); document.startElement("", "", I_AD_WF_NextCondition.Table_Name, atts);
document.startElement("", "", "workflowNodeNextCondition", atts);
createWorkflowNodeNextConditionBinding(ctx, document, m_WF_NodeNextCondition); createWorkflowNodeNextConditionBinding(ctx, document, m_WF_NodeNextCondition);
document.endElement("", "", "workflowNodeNextCondition"); document.endElement("", "", I_AD_WF_NextCondition.Table_Name);
} }
private void createWorkflowNodeNextConditionBinding(Properties ctx, TransformerHandler document, X_AD_WF_NextCondition m_WF_NodeNextCondition) { private void createWorkflowNodeNextConditionBinding(Properties ctx, TransformerHandler document, X_AD_WF_NextCondition mWFNodeNextCondition) {
PoExporter filler = new PoExporter(ctx, document, m_WF_NodeNextCondition); PoExporter filler = new PoExporter(ctx, document, mWFNodeNextCondition);
List<String> excludes = defaultExcludeList(X_AD_WF_NextCondition.Table_Name); List<String> excludes = defaultExcludeList(X_AD_WF_NextCondition.Table_Name);
String sql = null; if (mWFNodeNextCondition.getAD_WF_NextCondition_ID() <= PackOut.MAX_OFFICIAL_ID)
String name = null;
if (m_WF_NodeNextCondition.getAD_WF_NextCondition_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_WF_NextCondition_ID", new AttributesImpl()); filler.add("AD_WF_NextCondition_ID", new AttributesImpl());
sql = "SELECT max(AD_Workflow.Value) FROM AD_Workflow, AD_WF_Node, AD_WF_NodeNext WHERE AD_Workflow.AD_Workflow_ID = AD_WF_Node.AD_Workflow_ID and AD_WF_Node.AD_WF_Node_ID = AD_WF_NodeNext.AD_WF_Node_ID and AD_WF_NodeNext.AD_WF_NodeNext_ID = ? "; int AD_workflow_ID = mWFNodeNextCondition.getAD_WF_NodeNext().getAD_WF_Node().getAD_Workflow_ID();
name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition AttributesImpl wfAttributes = new AttributesImpl();
.getAD_WF_NodeNext_ID()); String value = ReferenceUtils.getTableReference("AD_Workflow", "Value", AD_workflow_ID, wfAttributes);
filler.addString("AD_Workflow.Value", name, new AttributesImpl()); filler.addString("AD_Workflow_ID", value, wfAttributes);
sql = "SELECT max(AD_WF_Node.Value) FROM AD_WF_Node, AD_WF_NodeNext WHERE AD_WF_Node.AD_WF_Node_ID = AD_WF_NodeNext.AD_WF_Node_ID and AD_WF_NodeNext.AD_WF_NodeNext_ID = ? "; int AD_WF_Node_ID = mWFNodeNextCondition.getAD_WF_NodeNext().getAD_WF_Node_ID();
name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition AttributesImpl wfnAttributes = new AttributesImpl();
.getAD_WF_NodeNext_ID()); value = ReferenceUtils.getTableReference("AD_WF_Node", "Value", AD_WF_Node_ID, wfnAttributes);
filler.addString("AD_WF_Node.Value", name, new AttributesImpl()); filler.addString("AD_WF_Node_ID", value, wfnAttributes);
sql = "SELECT max(AD_WF_Node.Value) FROM AD_WF_Node, AD_WF_NodeNext, AD_WF_NextCondition WHERE AD_WF_Node.AD_WF_Node_ID = AD_WF_NodeNext.AD_WF_Next_ID and AD_WF_NodeNext.AD_WF_NodeNext_ID = ? group by AD_WF_Node.Name"; int AD_WF_Next_ID = mWFNodeNextCondition.getAD_WF_NodeNext().getAD_WF_Next_ID();
name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition AttributesImpl nextAttributes = new AttributesImpl();
.getAD_WF_NodeNext_ID()); value = ReferenceUtils.getTableReference("AD_WF_Node", "Value", AD_WF_Next_ID, nextAttributes);
filler.addString("AD_WF_Next_ID.AD_WF_Node.Value", name, new AttributesImpl()); filler.addString("AD_WF_Next_ID", value, nextAttributes);
if (m_WF_NodeNextCondition.getAD_Column_ID() > 0) { if (mWFNodeNextCondition.getAD_Column_ID() > 0) {
int AD_Table_ID = mWFNodeNextCondition.getAD_Column().getAD_Table_ID();
sql = "SELECT AD_Table.TableName FROM AD_Table, AD_Column, AD_WF_NextCondition WHERE AD_Column.AD_Table_ID=AD_Table.AD_Table_ID and AD_Column.AD_Column_ID = ?"; AttributesImpl tableAttributes = new AttributesImpl();
name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition value = ReferenceUtils.getTableReference("AD_Table", "TableName", AD_Table_ID, tableAttributes);
.getAD_Column_ID()); filler.addString("AD_Table_ID", value, tableAttributes);
filler.addString("AD_Table.TableName", name, new AttributesImpl());
} else {
filler.add("AD_Table.TableName","", new AttributesImpl());
} }
excludes.add("AD_WF_NodeNext_ID");
filler.export(excludes); filler.export(excludes);
} }

View File

@ -26,7 +26,11 @@ import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element; import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller; import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException; 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_Package_Imp_Detail;
import org.compiere.model.X_AD_WF_NodeNext; import org.compiere.model.X_AD_WF_NodeNext;
import org.compiere.util.DB; import org.compiere.util.DB;
@ -47,61 +51,76 @@ public class WorkflowNodeNextElementHandler extends AbstractElementHandler {
return; return;
} }
String workflowValue = getStringValue(element, "AD_Workflow.Value", excludes); MWFNodeNext mWFNodeNext = findPO(ctx, element);
if (mWFNodeNext == null) {
int workflowId = 0; int workflowId = 0;
if (getParentId(element, "workflow") > 0) { Element wfElement = element.properties.get(I_AD_WF_Node.COLUMNNAME_AD_Workflow_ID);
workflowId = getParentId(element, "workflow"); if (getParentId(element, I_AD_Workflow.Table_Name) > 0) {
workflowId = getParentId(element, I_AD_Workflow.Table_Name);
} else { } else {
workflowId = findIdByColumn(ctx, "AD_Workflow", "Value", workflowValue); workflowId = ReferenceUtils.resolveReference(ctx, wfElement);
} }
if (workflowId <= 0) { if (workflowId <= 0) {
element.defer = true; element.defer = true;
element.unresolved = "AD_Workflow: " + workflowValue; element.unresolved = "AD_Workflow: " + wfElement.contents;
return; return;
} }
String workflowNodeValue = getStringValue(element, "AD_WF_Node.ValuTe", excludes); int wfNodeId = 0;
String workflowNodeNextValue = getStringValue(element, "AD_WF_Next_ID.AD_WF_Node.Value", excludes); Element wfnElement = element.properties.get(I_AD_WF_NodeNext.COLUMNNAME_AD_WF_Node_ID);
if (ReferenceUtils.isIDLookup(wfnElement) || ReferenceUtils.isUUIDLookup(wfnElement)) {
int 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, workflowNodeValue, Env.getAD_Client_ID(ctx)); wfNodeId = ReferenceUtils.resolveReference(ctx, wfnElement);
} 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));
}
if (wfNodeId <= 0) { if (wfNodeId <= 0) {
element.defer = true; element.defer = true;
element.unresolved = "AD_WF_Node: " + workflowNodeValue; element.unresolved = "AD_WF_Node: " + wfnElement.contents;
return; return;
} }
int 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, workflowNodeNextValue, Env.getAD_Client_ID(ctx)); 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, nextElement);
} 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));
}
if (AD_WF_Next_ID <= 0) { if (AD_WF_Next_ID <= 0) {
element.defer = true; element.defer = true;
element.unresolved = "AD_WF_Node: " + workflowNodeNextValue; element.unresolved = "AD_WF_Node: " + nextElement.contents;
return; return;
} }
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_WF_NodeNext.Table_Name,
X_AD_WF_NodeNext.Table_ID);
int 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); int 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 mWFNodeNext = new MWFNodeNext(ctx, AD_WF_NodeNext_ID, getTrxName(ctx)); mWFNodeNext = new MWFNodeNext(ctx, AD_WF_NodeNext_ID, getTrxName(ctx));
PoFiller filler = new PoFiller(ctx, mWFNodeNext, element, this);
String action = null;
if (AD_WF_NodeNext_ID <= 0 && isOfficialId(element, "AD_WF_NodeNext_ID"))
mWFNodeNext.setAD_WF_NodeNext_ID(getIntValue(element, "AD_WF_NodeNext_ID"));
if (AD_WF_NodeNext_ID > 0){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_WF_NodeNext.Table_Name,mWFNodeNext);
action = "Update";
} else{
action = "New";
}
mWFNodeNext.setAD_WF_Node_ID(wfNodeId); mWFNodeNext.setAD_WF_Node_ID(wfNodeId);
mWFNodeNext.setAD_WF_Next_ID(AD_WF_Next_ID); mWFNodeNext.setAD_WF_Next_ID(AD_WF_Next_ID);
}
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); List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) { if (notfounds.size() > 0) {
element.defer = true; element.defer = true;
return; return;
} }
if (mWFNodeNext.is_new() || mWFNodeNext.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_WF_NodeNext.Table_Name,
X_AD_WF_NodeNext.Table_ID);
String action = null;
if (!mWFNodeNext.is_new()){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_WF_NodeNext.Table_Name,mWFNodeNext);
action = "Update";
} else{
action = "New";
}
if (mWFNodeNext.save(getTrxName(ctx)) == true){ if (mWFNodeNext.save(getTrxName(ctx)) == true){
log.info("m_WFNodeNext save success"); log.info("m_WFNodeNext save success");
logImportDetail (ctx, impDetail, 1, String.valueOf(mWFNodeNext.get_ID()),mWFNodeNext.get_ID(), action); logImportDetail (ctx, impDetail, 1, String.valueOf(mWFNodeNext.get_ID()),mWFNodeNext.get_ID(), action);
@ -110,6 +129,7 @@ public class WorkflowNodeNextElementHandler extends AbstractElementHandler {
logImportDetail (ctx, impDetail, 0, String.valueOf(mWFNodeNext.get_ID()), mWFNodeNext.get_ID(), action); logImportDetail (ctx, impDetail, 0, String.valueOf(mWFNodeNext.get_ID()), mWFNodeNext.get_ID(), action);
throw new POSaveFailedException("WorkflowNodeNext"); throw new POSaveFailedException("WorkflowNodeNext");
} }
}
} else { } else {
element.skip = true; element.skip = true;
} }
@ -124,12 +144,10 @@ public class WorkflowNodeNextElementHandler extends AbstractElementHandler {
X_AD_WF_NodeNext m_WF_NodeNext = new X_AD_WF_NodeNext( X_AD_WF_NodeNext m_WF_NodeNext = new X_AD_WF_NodeNext(
ctx, ad_wf_nodenext_id, null); ctx, ad_wf_nodenext_id, null);
AttributesImpl atts = new AttributesImpl(); AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object"); addTypeName(atts, "ad.workflow.node.next-element");
atts.addAttribute("", "", "type-name", "CDATA", "ad.workflow.node.next-element"); document.startElement("", "", I_AD_WF_NodeNext.Table_Name, atts);
document.startElement("", "", "workflowNodeNext",
atts);
createWorkflowNodeNextBinding(ctx, document, m_WF_NodeNext); createWorkflowNodeNextBinding(ctx, document, m_WF_NodeNext);
document.endElement("", "", "workflowNodeNext"); document.endElement("", "", I_AD_WF_NodeNext.Table_Name);
} }