*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.POInfo;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Package_Imp_Backup;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.util.CLogger;
@ -227,7 +228,8 @@ public abstract class AbstractElementHandler implements ElementHandler {
backup.setAD_Column_ID(columnID);
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));
}
@ -516,4 +518,37 @@ public abstract class AbstractElementHandler implements ElementHandler {
char[] contents = str != null ? str.toCharArray() : new char[0];
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.POInfo;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -154,42 +152,18 @@ public class PoExporter {
}
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) {
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;
if (id > 0 && id <= PackOut.MAX_OFFICIAL_ID)
{
atts.addAttribute("", "", "reference", "CDATA", "id");
String value = Integer.toString(id);
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);
}
}
addTableReference(columnName, tableName, searchColumn, id, atts);
}
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);
}
public void export(List<String> excludes) {
@ -269,19 +243,7 @@ public class PoExporter {
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) {
add(columnName, "", new AttributesImpl());
} 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)) {
addBlob(columnName);
} 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.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail;
import org.compiere.model.M_Element;
import org.compiere.model.X_AD_Element;
import org.compiere.model.X_AD_Package_Imp_Detail;
@ -54,44 +55,50 @@ public class AdElementHandler extends AbstractElementHandler implements IPackOut
String ColumnName = getStringValue(element, "ColumnName");
if (isProcessElement(ctx, entitytype)) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Element.Table_Name, X_AD_Element.Table_ID);
int id = findIdByColumn(ctx, X_AD_Element.Table_Name, X_AD_Element.COLUMNNAME_ColumnName, ColumnName);
X_AD_Element mAdElement = new X_AD_Element(ctx, id, getTrxName(ctx));
M_Element mElement = findPO(ctx, element);
if (mElement == null) {
int id = findIdByColumn(ctx, X_AD_Element.Table_Name, X_AD_Element.COLUMNNAME_ColumnName, ColumnName);
mElement = new M_Element(ctx, id, getTrxName(ctx));
}
List<String> excludes = defaultExcludeList(X_AD_Element.Table_Name);
if (id <= 0 && isOfficialId(element, "AD_Element_ID"))
mAdElement.setAD_Element_ID(getIntValue(element, "AD_Element_ID"));
if (id > 0) {
if (processedElements.contains(id)) {
element.skip = true;
return;
}
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), AD_ELEMENT, mAdElement);
action = "Update";
} else {
action = "New";
if (mElement.getAD_Element_ID() == 0 && isOfficialId(element, "AD_Element_ID"))
mElement.setAD_Element_ID(getIntValue(element, "AD_Element_ID"));
if (processedElements.contains(mElement.getAD_Element_ID())) {
element.skip = true;
return;
}
PoFiller pf = new PoFiller(ctx, mAdElement, element, this);
PoFiller pf = new PoFiller(ctx, mElement, element, this);
List<String> notfounds = pf.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mAdElement.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mAdElement.getName(),
mAdElement.get_ID(), action);
element.recordId = mAdElement.getAD_Element_ID();
processedElements.add(mAdElement.getAD_Element_ID());
} else {
logImportDetail(ctx, impDetail, 0, mAdElement.getName(),
mAdElement.get_ID(), action);
throw new POSaveFailedException("Reference");
if (mElement.is_new() || mElement.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Element.Table_Name, X_AD_Element.Table_ID);
if (!mElement.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), AD_ELEMENT, mElement);
action = "Update";
} else {
action = "New";
}
if (mElement.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mElement.getName(),
mElement.get_ID(), action);
element.recordId = mElement.getAD_Element_ID();
processedElements.add(mElement.getAD_Element_ID());
} else {
logImportDetail(ctx, impDetail, 0, mElement.getName(),
mElement.get_ID(), action);
throw new POSaveFailedException("Reference");
}
}
} else {
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);
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.element");
document.startElement("", "", "element", atts);
addTypeName(atts, "ad.element");
document.startElement("", "", "AD_Element", atts);
createAdElementBinding(ctx, document, m_AdElement);
PackOut packOut = (PackOut)ctx.get("PackOutProcess");
@ -132,7 +138,7 @@ public class AdElementHandler extends AbstractElementHandler implements IPackOut
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 ReleaseNo = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo);
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.code-snippet");
addTypeName(atts, "ad.code-snippet");
createSnipitBinding(atts, FileDir, FileName, OldCode, NewCode, ReleaseNo);
document.startElement("","","codesnippet",atts);
document.endElement("","","codesnippet");

View File

@ -29,11 +29,12 @@ import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackIn;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.DatabaseAccessException;
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.MTable;
import org.compiere.model.X_AD_Column;
@ -50,52 +51,35 @@ public class ColumnElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element)
throws SAXException {
PackIn packIn = (PackIn)ctx.get("PackInProcess");
int success = 0;
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
if (isParentDefer(element, "table")) {
if (isParentDefer(element, I_AD_Table.Table_Name)) {
element.defer = true;
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);
String columnName = getStringValue(element, "ColumnName", excludes);
String tableName = getStringValue(element, "AD_Table_ID", excludes);
int tableid = 0;
if (getParentId(element, "table") > 0) {
tableid = getParentId(element, "table");
} else {
tableid = packIn.getTableId(tableName);
}
if (tableid <= 0) {
tableid = findIdByColumn(ctx, "AD_Table", "TableName", tableName);
if (tableid > 0)
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 = findPO(ctx, element);
if (mColumn == null) {
int tableid = 0;
if (getParentId(element, I_AD_Table.Table_Name) > 0) {
tableid = getParentId(element, "table");
} else {
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();
}
}
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"));
}
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);
}
int AD_Column_ID = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnName, "AD_Table", tableid);
mColumn = new MColumn(ctx, AD_Column_ID > 0 ? AD_Column_ID : 0, getTrxName(ctx));
if (mColumn.getAD_Column_ID() == 0 && isOfficialId(element, "AD_Column_ID")) {
mColumn.setAD_Column_ID(getIntValue(element, "AD_Column_ID"));
}
}
mColumn.setColumnName(columnName);
mColumn.setIsSyncDatabase(getStringValue(element, "IsSyncDatabase", excludes));
@ -105,6 +89,18 @@ public class ColumnElementHandler extends AbstractElementHandler {
element.defer = true;
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.
if (mColumn.getAD_Element_ID() == 0) {
@ -311,11 +307,10 @@ public class ColumnElementHandler extends AbstractElementHandler {
AttributesImpl atts = new AttributesImpl();
X_AD_Column m_Column = new X_AD_Column(ctx, AD_Column_ID,
getTrxName(ctx));
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.table.column");
document.startElement("", "", "column", atts);
addTypeName(atts, "ad.table.column");
document.startElement("", "", I_AD_Column.Table_Name, atts);
createColumnBinding(ctx, document, m_Column);
document.endElement("", "", "column");
document.endElement("", "", I_AD_Column.Table_Name);
}
private void createColumnBinding(Properties ctx, TransformerHandler document,

View File

@ -208,8 +208,7 @@ public class CommonTranslationHandler extends AbstractElementHandler implements
while(rs.next()){
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.trl");
addTypeName(atts, "ad.trl");
document.startElement("", "", "trl", atts);
addTextProperty(null, SPECIAL_ATRRIBUTE_TABLE_NAME, parentTable);
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 ReleaseNo = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo);
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.dist-file");
addTypeName(atts, "ad.dist-file");
document.startElement("","","distfile",atts);
addTextProperty(document,"filename",FileName);
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.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Val_Rule;
import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail;
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 {
String entitytype = getStringValue(element, "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");
int id = findIdByColumn(ctx, "AD_Val_Rule", "Name", name);
X_AD_Val_Rule mValRule = new X_AD_Val_Rule(ctx, id, getTrxName(ctx));
if (id <= 0 && isOfficialId(element, "AD_Val_Rule_ID"))
X_AD_Val_Rule mValRule = findPO(ctx, element);
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"));
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);
@ -71,13 +65,26 @@ public class DynValRuleElementHandler extends AbstractElementHandler implements
element.defer = true;
return;
}
if (mValRule.save(getTrxName(ctx)) == true){
logImportDetail (ctx, impDetail, 1, mValRule.getName(), mValRule.get_ID(),action);
}
else{
logImportDetail (ctx, impDetail, 0, mValRule.getName(), mValRule.get_ID(),action);
throw new POSaveFailedException("Failed to save dynamic validation rule.");
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){
logImportDetail (ctx, impDetail, 1, mValRule.getName(), mValRule.get_ID(),action);
}
else{
logImportDetail (ctx, impDetail, 0, mValRule.getName(), mValRule.get_ID(),action);
throw new POSaveFailedException("Failed to save dynamic validation rule.");
}
}
} else {
element.skip = true;
@ -96,11 +103,10 @@ public class DynValRuleElementHandler extends AbstractElementHandler implements
rules.add(AD_Val_Rule_ID);
X_AD_Val_Rule m_ValRule = new X_AD_Val_Rule (ctx, AD_Val_Rule_ID, null);
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.dynamic-validation");
document.startElement("","","dynvalrule", atts);
addTypeName(atts, "ad.dynamic-validation");
document.startElement("","",I_AD_Val_Rule.Table_Name, atts);
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.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackIn;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Field;
import org.compiere.model.I_AD_Tab;
import org.compiere.model.MField;
import org.compiere.model.X_AD_Field;
import org.compiere.model.X_AD_Package_Imp_Detail;
@ -41,76 +43,82 @@ public class FieldElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element)
throws SAXException {
PackIn packIn = getPackInProcess(ctx);
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
if (isParentDefer(element, "tab")) {
if (isParentDefer(element, I_AD_Tab.Table_Name)) {
element.defer = true;
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);
int tabid = getParentId(element, "tab") ;
int tabid = getParentId(element, I_AD_Tab.Table_Name) ;
if (tabid <= 0) {
element.defer = true;
return;
}
String tableName = element.parent.properties.get("AD_Table_ID").contents.toString();
String colname = getStringValue(element, "AD_Column_ID", excludes);
int columnid = packIn.getColumnId(tableName, colname);
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);
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);
AD_Column_ID = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", colname, "AD_Table", AD_Table_ID);
}
StringBuffer sqlB = new StringBuffer(
"select AD_Field_ID from AD_Field where AD_Column_ID = ")
.append(AD_Column_ID)
.append(" and AD_Tab_ID = ?");
int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), tabid);
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);
}
}
if (columnid <= 0) {
element.defer = true;
return;
}
StringBuffer sqlB = new StringBuffer(
"select AD_Field_ID from AD_Field where AD_Column_ID = ")
.append(columnid)
.append(" and AD_Tab_ID = ?");
int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), tabid);
MField mField = new MField(ctx, id, getTrxName(ctx));
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");
}
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);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mField.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mField.getName(), mField
.get_ID(), action);
element.recordId = mField.getAD_Field_ID();
} else {
logImportDetail(ctx, impDetail, 0, mField.getName(), mField
.get_ID(), action);
throw new POSaveFailedException("Failed to save field definition.");
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) {
logImportDetail(ctx, impDetail, 1, mField.getName(), mField
.get_ID(), action);
element.recordId = mField.getAD_Field_ID();
} else {
logImportDetail(ctx, impDetail, 0, mField.getName(), mField
.get_ID(), action);
throw new POSaveFailedException("Failed to save field definition.");
}
}
} else {
element.skip = true;
@ -126,9 +134,8 @@ public class FieldElementHandler extends AbstractElementHandler {
X_AD_Field.COLUMNNAME_AD_Field_ID);
X_AD_Field m_Field = new X_AD_Field(ctx, AD_Field_ID, null);
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.tab.field");
document.startElement("", "", "field", atts);
addTypeName(atts, "ad.tab.field");
document.startElement("", "", I_AD_Field.Table_Name, atts);
createFieldBinding(ctx, document, m_Field);
PackOut packOut = (PackOut)ctx.get("PackOutProcess");
@ -164,7 +171,7 @@ public class FieldElementHandler extends AbstractElementHandler {
log.info(e.toString());
}
document.endElement("", "", "field");
document.endElement("", "", I_AD_Field.Table_Name);
}
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.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_FieldGroup;
import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail;
import org.compiere.model.X_AD_FieldGroup;
@ -56,48 +57,53 @@ public class FieldGroupElementHandler extends AbstractElementHandler implements
if (isProcessElement(ctx, entitytype)) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_FieldGroup.Table_Name,
X_AD_FieldGroup.Table_ID);
int id = findIdByColumn(ctx, X_AD_FieldGroup.Table_Name, X_AD_FieldGroup.COLUMNNAME_Name, name);
X_AD_FieldGroup fieldGroup = new X_AD_FieldGroup(ctx, id,
getTrxName(ctx));
X_AD_FieldGroup fieldGroup = findPO(ctx, element);
if (fieldGroup == null)
{
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));
}
PoFiller pf = new PoFiller(ctx, fieldGroup, element, this);
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");
}
if (id > 0) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_FieldGroup.Table_Name, fieldGroup);
action = "Update";
if (processedFieldGroups.contains(id)) {
element.skip = true;
return;
}
} else {
action = "New";
if (processedFieldGroups.contains(fieldGroup.getAD_FieldGroup_ID())) {
element.skip = true;
return;
}
List<String> notfounds = pf.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (fieldGroup.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, fieldGroup.getName(),
fieldGroup.get_ID(), action);
element.recordId = fieldGroup.getAD_FieldGroup_ID();
processedFieldGroups.add(fieldGroup.getAD_FieldGroup_ID());
} else {
logImportDetail(ctx, impDetail, 0, fieldGroup.getName(),
fieldGroup.get_ID(), action);
throw new POSaveFailedException("Reference");
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) {
logImportDetail(ctx, impDetail, 1, fieldGroup.getName(),
fieldGroup.get_ID(), action);
element.recordId = fieldGroup.getAD_FieldGroup_ID();
processedFieldGroups.add(fieldGroup.getAD_FieldGroup_ID());
} else {
logImportDetail(ctx, impDetail, 0, fieldGroup.getName(),
fieldGroup.get_ID(), action);
throw new POSaveFailedException("Reference");
}
}
} else {
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);
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.field-group");
document.startElement("", "", "fieldgroup", atts);
addTypeName(atts, "ad.field-group");
document.startElement("", "", I_AD_FieldGroup.Table_Name, atts);
createAdElementBinding(ctx, document, fieldGroup);
@ -137,7 +142,7 @@ public class FieldGroupElementHandler extends AbstractElementHandler implements
{
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.Element;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_Form_Access;
import org.compiere.model.I_AD_Role;
import org.compiere.model.MFormAccess;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Form;
import org.compiere.model.X_AD_Form_Access;
import org.compiere.model.X_AD_Role;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -40,37 +42,40 @@ public class FormAccessElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) throws SAXException {
List<String> excludes = defaultExcludeList(X_AD_Form_Access.Table_Name);
int roleId = 0;
String roleName = getStringValue(element, "rolename", excludes);
if (getParentId(element, "role") > 0) {
roleId = getParentId(element, "role");
} 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));
}
if (roleId <= 0)
{
element.defer = true;
return;
}
String formName = getStringValue(element, "formname", excludes);
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 (formId <= 0)
{
element.defer = true;
return;
}
MFormAccess po = null;
Query query = new Query(ctx, "AD_Form_Access", "AD_Form_ID = ? AND AD_Role_ID = ?", getTrxName(ctx));
po = query.setParameters(new Object[]{formId, roleId})
.setClient_ID()
.<MFormAccess>first();
if (po == null)
{
po = new MFormAccess(ctx, 0, null);
po.setAD_Form_ID(formId);
po.setAD_Role_ID(roleId);
MFormAccess po = findPO(ctx, element);
if (po == null) {
int AD_Role_ID = 0;
if (getParentId(element, I_AD_Role.Table_Name) > 0) {
AD_Role_ID = getParentId(element, I_AD_Role.Table_Name);
} else {
AD_Role_ID = ReferenceUtils.resolveReference(ctx, element.properties.get("AD_Role_ID"));
}
if (AD_Role_ID <= 0)
{
element.defer = true;
return;
}
int AD_Form_ID = ReferenceUtils.resolveReference(ctx, element.properties.get("AD_Form_ID"));
if (AD_Form_ID <= 0)
{
element.defer = true;
return;
}
Query query = new Query(ctx, "AD_Form_Access", "AD_Form_ID = ? AND AD_Role_ID = ?", getTrxName(ctx));
po = query.setParameters(new Object[]{AD_Form_ID, AD_Role_ID})
.setClient_ID()
.<MFormAccess>first();
if (po == null)
{
po = new MFormAccess(ctx, 0, null);
po.setAD_Form_ID(AD_Form_ID);
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);
@ -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_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID);
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.form-access");
document.startElement("", "", "formaccess", atts);
addTypeName(atts, "ad.form-access");
document.startElement("", "", I_AD_Form_Access.Table_Name, atts);
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,
@ -105,12 +109,6 @@ public class FormAccessElementHandler extends AbstractElementHandler {
if (po != null) {
PoExporter filler = new PoExporter(ctx, document, po);
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);
}
}

View File

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

View File

@ -62,48 +62,51 @@ public class GenericPOElementHandler extends AbstractElementHandler implements I
public void startElement(Properties ctx, Element element) throws SAXException {
String tableName = element.getElementValue();
MTable table = MTable.get(ctx, tableName);
POInfo info = POInfo.getPOInfo(ctx, table.getAD_Table_ID());
MColumn columns[] = table.getColumns(false);
StringBuffer whereClause = new StringBuffer();
List<Object> parameters = new ArrayList<Object>();
for(int i = 0; i < columns.length; i++) {
MColumn column = columns[i];
if (column.isIdentifier()) {
if (whereClause.length() > 0)
whereClause.append(" AND ");
whereClause.append(column.getColumnName()).append(" = ? ");
parameters.add(getStringValue(element, column.getColumnName()));
} else if (column.isParent()) {
int parentId = 0;
String parentTableName = null;
if (column.getAD_Reference_ID() == DisplayType.TableDir) {
parentTableName = column.getColumnName().substring(0, column.getColumnName().length() - 3);
} else {
String searchColumn = info.getColumnLookup(i).getColumnName();
parentTableName = searchColumn.substring(0, searchColumn.indexOf("."));
}
Element parent = element.parent;
while (parent != null) {
if (parent.getElementValue().equalsIgnoreCase(parentTableName)) {
parentId = parent.recordId;
break;
}
parent = parent.parent;
}
if (parentId > 0) {
PO po = findPO(ctx, element);
if (po == null) {
MTable table = MTable.get(ctx, tableName);
POInfo info = POInfo.getPOInfo(ctx, table.getAD_Table_ID());
MColumn columns[] = table.getColumns(false);
StringBuffer whereClause = new StringBuffer();
List<Object> parameters = new ArrayList<Object>();
for(int i = 0; i < columns.length; i++) {
MColumn column = columns[i];
if (column.isIdentifier()) {
if (whereClause.length() > 0)
whereClause.append(" AND ");
whereClause.append(column.getColumnName()).append(" = ?");
parameters.add(parentId);
whereClause.append(column.getColumnName()).append(" = ? ");
parameters.add(getStringValue(element, column.getColumnName()));
} else if (column.isParent()) {
int parentId = 0;
String parentTableName = null;
if (column.getAD_Reference_ID() == DisplayType.TableDir) {
parentTableName = column.getColumnName().substring(0, column.getColumnName().length() - 3);
} else {
String searchColumn = info.getColumnLookup(i).getColumnName();
parentTableName = searchColumn.substring(0, searchColumn.indexOf("."));
}
Element parent = element.parent;
while (parent != null) {
if (parent.getElementValue().equalsIgnoreCase(parentTableName)) {
parentId = parent.recordId;
break;
}
parent = parent.parent;
}
if (parentId > 0) {
if (whereClause.length() > 0)
whereClause.append(" AND ");
whereClause.append(column.getColumnName()).append(" = ?");
parameters.add(parentId);
}
}
}
}
Query query = new Query(ctx, table, whereClause.toString(), getTrxName(ctx));
PO po = query.setParameters(parameters).first();
if (po == null) {
po = new GenericPO(tableName, ctx, 0);
Query query = new Query(ctx, table, whereClause.toString(), getTrxName(ctx));
po = query.setParameters(parameters).first();
if (po == null) {
po = new GenericPO(tableName, ctx, 0);
}
}
PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> excludes = defaultExcludeList(tableName);
@ -144,8 +147,7 @@ public class GenericPOElementHandler extends AbstractElementHandler implements I
int AD_Client_ID = po.getAD_Client_ID();
if (AD_Client_ID != Env.getAD_Client_ID(ctx))
continue;
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.po.generic");
addTypeName(atts, "ad.po.generic");
document.startElement("","", tableName, atts);
PoExporter filler = new PoExporter(ctx, document, po);
filler.export(excludes);

View File

@ -33,6 +33,7 @@ import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_ImpFormat;
import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail;
import org.compiere.model.X_AD_ImpFormat;
@ -52,41 +53,47 @@ public class ImpFormatElementHandler extends AbstractElementHandler implements
public void startElement(Properties ctx, Element element)
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);
String name = getStringValue(element, "Name");
int id = findIdByName(ctx, "AD_ImpFormat", name);
X_AD_ImpFormat mImpFormat = new X_AD_ImpFormat(ctx, id,
getTrxName(ctx));
X_AD_ImpFormat mImpFormat = findPO(ctx, element);
if (mImpFormat == null) {
int id = findIdByName(ctx, "AD_ImpFormat", name);
mImpFormat = new X_AD_ImpFormat(ctx, id > 0 ? id : 0,
getTrxName(ctx));
}
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");
}
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);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mImpFormat.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mImpFormat.getName(), mImpFormat
.get_ID(), action);
} else {
logImportDetail(ctx, impDetail, 0, mImpFormat.getName(), mImpFormat
.get_ID(), action);
throw new POSaveFailedException("Failed to save Import Format.");
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) {
logImportDetail(ctx, impDetail, 1, mImpFormat.getName(), mImpFormat
.get_ID(), action);
} else {
logImportDetail(ctx, impDetail, 0, mImpFormat.getName(), mImpFormat
.get_ID(), action);
throw new POSaveFailedException("Failed to save Import Format.");
}
}
}
@ -103,9 +110,8 @@ public class ImpFormatElementHandler extends AbstractElementHandler implements
formats.add(import_id);
AttributesImpl atts = new AttributesImpl();
X_AD_ImpFormat m_ImpFormat = new X_AD_ImpFormat(ctx, import_id, null);
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.import-format");
document.startElement("", "", "impformat", atts);
addTypeName(atts, "ad.import-format");
document.startElement("", "", I_AD_ImpFormat.Table_Name, atts);
createImpFormatBinding(ctx, document, m_ImpFormat);
String sql = "SELECT * FROM AD_ImpFormat_Row WHERE AD_ImpFormat_ID= "
@ -127,7 +133,7 @@ public class ImpFormatElementHandler extends AbstractElementHandler implements
} finally {
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.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
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_Package_Imp_Detail;
import org.compiere.util.DB;
@ -42,77 +44,97 @@ public class ImpFormatRowElementHandler extends AbstractElementHandler {
String action = null;
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;
return;
}
int impFormatId = 0;
String impFormatName = getStringValue(element, "AD_ImpFormat.Name", excludes);
if (getParentId(element, "impformat") > 0) {
impFormatId = getParentId(element, "impformat");
} else {
impFormatId = findIdByName(ctx, "AD_ImpFormat", impFormatName);
}
if (impFormatId <= 0) {
element.defer = true;
return;
}
String tableName = getStringValue(element, "AD_Table.TableName", excludes);
int tableId = 0;
if (tableName != null && tableName.trim().length() > 0) {
tableId = findIdByColumn(ctx, "AD_Table", "TableName", tableName);
if (tableId <= 0) {
X_AD_ImpFormat_Row mImpFormatRow = findPO(ctx, element);
if (mImpFormatRow == null) {
int impFormatId = 0;
if (getParentId(element, I_AD_ImpFormat.Table_Name) > 0) {
impFormatId = getParentId(element, I_AD_ImpFormat.Table_Name);
} else {
Element e = element.properties.get(I_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_ID);
if (ReferenceUtils.isIDLookup(e) || ReferenceUtils.isUUIDLookup(e))
impFormatId = ReferenceUtils.resolveReference(ctx, e);
else
impFormatId = findIdByName(ctx, "AD_ImpFormat", e.contents.toString());
}
if (impFormatId <= 0) {
element.defer = true;
return;
}
}
String columnName = getStringValue(element, "AD_Column.ColumnName", excludes);
int columnId = 0;
if (columnName != null && columnName.trim().length() > 0) {
columnId = findIdByColumnAndParentId (ctx, "AD_Column","ColumnName", columnName, "AD_Table", tableId);
if (columnId <= 0) {
element.defer = true;
return;
Element tableElement = element.properties.get(I_AD_ImpFormat.COLUMNNAME_AD_Table_ID);
int tableId = 0;
if (ReferenceUtils.isIDLookup(tableElement) || ReferenceUtils.isUUIDLookup(tableElement)) {
tableId = ReferenceUtils.resolveReference(ctx, tableElement);
} else {
String tableName = getStringValue(element, I_AD_ImpFormat.COLUMNNAME_AD_Table_ID, excludes);
if (tableName != null && tableName.trim().length() > 0) {
tableId = findIdByColumn(ctx, "AD_Table", "TableName", tableName);
}
if (tableId <= 0) {
element.defer = true;
return;
}
}
Element columnElement = element.properties.get(I_AD_ImpFormat_Row.COLUMNNAME_AD_Column_ID);
int columnId = 0;
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) {
columnId = ReferenceUtils.resolveReference(ctx, columnElement);
} else {
String columnName = getStringValue(element, I_AD_ImpFormat_Row.COLUMNNAME_AD_Column_ID, excludes);
if (columnName != null && columnName.trim().length() > 0) {
columnId = findIdByColumnAndParentId (ctx, "AD_Column","ColumnName", columnName, "AD_Table", tableId);
}
if (columnId <= 0) {
element.defer = true;
return;
}
}
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);
mImpFormatRow = new X_AD_ImpFormat_Row(ctx, id > 0 ? id : 0, getTrxName(ctx));
mImpFormatRow.setAD_Column_ID(columnId);
mImpFormatRow.setAD_ImpFormat_ID(impFormatId);
}
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=?");
int id = DB.getSQLValue(getTrxName(ctx),sqlB.toString(),columnId,impFormatId);
X_AD_ImpFormat_Row mImpFormatRow = new X_AD_ImpFormat_Row(ctx, id, getTrxName(ctx));
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");
}
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);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mImpFormatRow.save(getTrxName(ctx)) == true){
logImportDetail (ctx, impDetail, 1, mImpFormatRow.getName(), mImpFormatRow.get_ID(),action);
}
else{
logImportDetail (ctx, impDetail, 0, mImpFormatRow.getName(), mImpFormatRow.get_ID(),action);
throw new POSaveFailedException("Failed to import Import Format Row.");
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){
logImportDetail (ctx, impDetail, 1, mImpFormatRow.getName(), mImpFormatRow.get_ID(),action);
}
else{
logImportDetail (ctx, impDetail, 0, mImpFormatRow.getName(), mImpFormatRow.get_ID(),action);
throw new POSaveFailedException("Failed to import Import Format Row.");
}
}
}
@ -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);
X_AD_ImpFormat_Row m_ImpFormat_Row = new X_AD_ImpFormat_Row (ctx, AD_ImpFormat_Row_ID, getTrxName(ctx));
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.import-format.row");
document.startElement("","","impformatrow",atts);
addTypeName(atts, "ad.import-format.row");
document.startElement("","",I_AD_ImpFormat_Row.Table_Name,atts);
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)
@ -138,15 +159,8 @@ public class ImpFormatRowElementHandler extends AbstractElementHandler {
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());
String tableName = MTable.getTableName(Env.getCtx(), tableId);
filler.addString("AD_Table.TableName", tableName, new AttributesImpl());
filler.addTableReference("AD_Table_ID", "AD_Table", "TableName", tableId, new AttributesImpl());
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.PackOut;
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.MPackageExpDetail;
import org.compiere.model.X_AD_Menu;
@ -49,38 +51,40 @@ public class MenuElementHandler extends AbstractElementHandler implements IPackO
public void startElement(Properties ctx, Element element)
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);
StringBuffer sqlB = null;
String menuName = getStringValue(element, "Name", excludes);
int menuId = findIdByColumn(ctx, "AD_Menu", "Name", menuName);
X_AD_Menu mMenu = new X_AD_Menu(ctx, menuId, getTrxName(ctx));
X_AD_Menu mMenu = findPO(ctx, element);
if (mMenu == null) {
String menuName = getStringValue(element, "Name");
int menuId = findIdByColumn(ctx, "AD_Menu", "Name", menuName);
mMenu = new X_AD_Menu(ctx, menuId > 0 ? menuId : 0, getTrxName(ctx));
}
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");
}
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);
if (notFounds.size() > 0) {
element.defer = true;
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) {
try {
logImportDetail(ctx, impDetail, 1, mMenu.getName(), mMenu
@ -96,11 +100,19 @@ public class MenuElementHandler extends AbstractElementHandler implements IPackO
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"
+ " AND Node_ID = " + menuId;
+ " AND Node_ID = " + mMenu.getAD_Menu_ID();
int countRecords = DB.getSQLValue(getTrxName(ctx), sql);
if (countRecords > 0) {
sql = "select * from AD_TREENODEMM where AD_Tree_ID = 10 and "
@ -110,7 +122,7 @@ public class MenuElementHandler extends AbstractElementHandler implements IPackO
try {
pstmt = DB.prepareStatement(sql,
getTrxName(ctx));
pstmt.setInt(1, menuId);
pstmt.setInt(1, mMenu.getAD_Menu_ID());
rs = pstmt.executeQuery();
if (rs.next()) {
@ -152,20 +164,20 @@ public class MenuElementHandler extends AbstractElementHandler implements IPackO
DB.close(rs, pstmt);
}
sqlB = new StringBuffer("UPDATE AD_TREENODEMM ").append(
updateSQL = new StringBuffer("UPDATE AD_TREENODEMM ").append(
"SET Parent_ID = " + parentId).append(
" , SeqNo = " + getStringValue(element, "ADParentSeqno")).append(
" , SeqNo = " + getStringValue(element, "SeqNo")).append(
" WHERE AD_Tree_ID = 10").append(
" AND Node_ID = " + mMenu.getAD_Menu_ID());
} 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(
"Parent_ID, SeqNo, AD_Tree_ID, Node_ID)").append(
"VALUES(0, 0, 0, 0, ").append(
parentId + "," + getStringValue(element, "ADParentSeqno") + ", 10, "
parentId + "," + getStringValue(element, "SeqNo") + ", 10, "
+ 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 {
@ -179,12 +191,11 @@ public class MenuElementHandler extends AbstractElementHandler implements IPackO
createApplication(ctx, document, AD_Menu_ID);
} else {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.menu");
document.startElement("", "", "menu", atts);
addTypeName(atts, "ad.menu");
document.startElement("", "", I_AD_Menu.Table_Name, atts);
createMenuBinding(ctx, document, m_Menu);
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);
List<String> excludes = defaultExcludeList(X_AD_Menu.Table_Name);
String sql = null;
String name = null;
sql = "SELECT Parent_ID FROM AD_TreeNoDemm WHERE AD_Tree_ID = 10 and Node_ID=?";
String 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());
if (id > 0) {
sql = "SELECT Name FROM AD_Menu WHERE AD_Menu_ID=?";
name = DB.getSQLValueString(null, sql, id);
filler.addString("ADParentMenuNameID", name, new AttributesImpl());
filler.addTableReference("Parent_ID", "AD_Menu", "Name", id, new AttributesImpl());
}
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());
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)
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"),
null);
document.startElement("", "", "menu", atts);
document.startElement("", "", I_AD_Menu.Table_Name, atts);
createMenuBinding(ctx, document, m_Menu);
if (rs.getInt("AD_WINDOW_ID") > 0
|| rs.getInt("AD_WORKFLOW_ID") > 0
@ -268,7 +275,7 @@ public class MenuElementHandler extends AbstractElementHandler implements IPackO
} else {
createModule(ctx, document, rs.getInt("Node_ID"));
}
document.endElement("", "", "menu");
document.endElement("", "", I_AD_Menu.Table_Name);
}
} catch (Exception e) {
log.log(Level.SEVERE, "getWindows", e);
@ -298,7 +305,7 @@ public class MenuElementHandler extends AbstractElementHandler implements IPackO
// Menu tag Start.
X_AD_Menu m_Menu = new X_AD_Menu(ctx, rs.getInt("AD_Menu_ID"),
null);
document.startElement("", "", "menu", atts);
document.startElement("", "", I_AD_Menu.Table_Name, atts);
createMenuBinding(ctx, document, m_Menu);
if (rs.getInt("AD_WINDOW_ID") > 0
|| rs.getInt("AD_WORKFLOW_ID") > 0
@ -335,7 +342,7 @@ public class MenuElementHandler extends AbstractElementHandler implements IPackO
} else {
createModule(ctx, document, rs.getInt("Node_ID"));
}
document.endElement("", "", "menu");
document.endElement("", "", I_AD_Menu.Table_Name);
}
} catch (Exception 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.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Message;
import org.compiere.model.MMessage;
import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail;
@ -45,38 +46,44 @@ public class MessageElementHandler extends AbstractElementHandler implements IPa
public void startElement(Properties ctx, Element element) throws SAXException {
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Message.Table_Name,
X_AD_Message.Table_ID);
String value = getStringValue(element, "Value");
int id = findIdByColumn(ctx, "AD_Message", "value", value);
if (isProcessElement(ctx, entitytype)) {
MMessage mMessage = findPO(ctx, element);
if (mMessage == null) {
String value = getStringValue(element, "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);
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);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mMessage.save(getTrxName(ctx)) == true){
logImportDetail (ctx, impDetail, 1, mMessage.getValue(), mMessage.get_ID(),action);
}
else{
logImportDetail (ctx, impDetail, 0, mMessage.getValue(), mMessage.get_ID(),action);
throw new POSaveFailedException("Failed to save message.");
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){
logImportDetail (ctx, impDetail, 1, mMessage.getValue(), mMessage.get_ID(),action);
}
else{
logImportDetail (ctx, impDetail, 0, mMessage.getValue(), mMessage.get_ID(),action);
throw new POSaveFailedException("Failed to save message.");
}
}
} else {
element.skip = true;
@ -95,11 +102,10 @@ public class MessageElementHandler extends AbstractElementHandler implements IPa
messages.add(AD_Message_ID);
AttributesImpl atts = new AttributesImpl();
X_AD_Message m_Message = new X_AD_Message (ctx, AD_Message_ID, null);
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.message");
document.startElement("","","message",atts);
addTypeName(atts, "ad.message");
document.startElement("","",I_AD_Message.Table_Name,atts);
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)

View File

@ -22,13 +22,15 @@ import java.util.Properties;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_Role;
import org.compiere.model.I_AD_Role_OrgAccess;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Role;
import org.compiere.model.X_AD_Role_OrgAccess;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -38,26 +40,31 @@ public class OrgRoleElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element) throws SAXException {
List<String> excludes = defaultExcludeList(X_AD_Role_OrgAccess.Table_Name);
int roleId = 0;
String roleName = getStringValue(element, "rolename", excludes);
if (getParentId(element, "role") > 0) {
roleId = getParentId(element, "role");
} 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));
}
X_AD_Role_OrgAccess po = findPO(ctx, element);
if (po == null) {
int roleId = 0;
if (getParentId(element, I_AD_Role.Table_Name) > 0) {
roleId = getParentId(element, I_AD_Role.Table_Name);
} else {
Element roleElement = element.properties.get("AD_Role_ID");
roleId = ReferenceUtils.resolveReference(ctx, roleElement);
}
String orgName = getStringValue(element, "orgname", excludes);
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));
Element orgElement = element.properties.get("AD_Org_ID");
int orgId = ReferenceUtils.resolveReference(ctx, orgElement);
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})
Query query = new Query(ctx, "AD_Role_OrgAccess", "AD_Role_ID=? and AD_Org_ID=?", getTrxName(ctx));
po = query.setParameters(new Object[]{roleId, orgId})
.setClient_ID()
.<X_AD_Role_OrgAccess>first();
if (po == null) {
po = new X_AD_Role_OrgAccess(ctx, 0, getTrxName(ctx));
po.setAD_Org_ID(orgId);
po.setAD_Role_ID(roleId);
if (po == null) {
po = new X_AD_Role_OrgAccess(ctx, 0, getTrxName(ctx));
po.setAD_Org_ID(orgId);
po.setAD_Role_ID(roleId);
}
excludes.add("AD_Org_ID");
excludes.add("AD_Role_ID");
}
PoFiller filler = new PoFiller(ctx, po, element, this);
@ -77,29 +84,25 @@ public class OrgRoleElementHandler extends AbstractElementHandler {
int AD_Org_ID = Env.getContextAsInt(ctx, "AD_Org_ID");
int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID);
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.organization-role");
document.startElement("", "", "OrgAccess", atts);
addTypeName(atts, "ad.organization-role");
document.startElement("", "", I_AD_Role_OrgAccess.Table_Name, atts);
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,
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));
X_AD_Role_OrgAccess po = query.setParameters(new Object[]{roleId, orgId}).<X_AD_Role_OrgAccess>first();
PoExporter filler = new PoExporter(ctx, document, po);
sql = "SELECT Name FROM AD_Org WHERE AD_Org_ID=?";
name = DB.getSQLValueString(null, sql, orgId);
filler.addString("orgname", name, new AttributesImpl());
AttributesImpl orgRefAtts = new AttributesImpl();
String orgReference = ReferenceUtils.getTableReference("AD_Org", "Name", orgId, orgRefAtts);
filler.addString("AD_Org_ID", orgReference, orgRefAtts);
sql = "SELECT Name FROM AD_Role WHERE AD_Role_ID=?";
name = DB.getSQLValueString(null, sql, roleId);
filler.addString("rolename", name, new AttributesImpl());
AttributesImpl roleRefAtts = new AttributesImpl();
String roleReference = ReferenceUtils.getTableReference("AD_Role", "Name", roleId, roleRefAtts);
filler.addString("AD_Role_ID", roleReference, roleRefAtts);
List<String> excludes = defaultExcludeList(X_AD_Role_OrgAccess.Table_Name);
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.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Preference;
import org.compiere.model.MPreference;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Package_Imp_Detail;
@ -40,50 +41,61 @@ public class PreferenceElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element)
throws SAXException {
MPreference m_Preference = new MPreference(ctx, 0, getTrxName(ctx));
List<String> excludes = defaultExcludeList(X_AD_Preference.Table_Name);
PoFiller filler = new PoFiller(ctx, m_Preference, element, this);
List<String> notFounds = filler.autoFill(excludes);
if (notFounds.size() > 0) {
element.defer = true;
return;
}
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
.setParameters(new Object[]{m_Preference.getAttribute(), m_Preference.getAD_User_ID(), m_Preference.getAD_Window_ID()})
.first();
if (tmp != null) {
filler = new PoFiller(ctx, tmp, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
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);
if (notFounds.size() > 0) {
element.defer = true;
return;
}
m_Preference = tmp;
}
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Preference.Table_Name,
X_AD_Preference.Table_ID);
String Object_Status = null;
int id = m_Preference.get_ID();
if (id <= 0 && isOfficialId(element, "AD_Preference_ID"))
m_Preference.setAD_Preference_ID(Integer.parseInt(getStringValue(element, "AD_Preference_ID")));
if (id > 0) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Preference.Table_Name, m_Preference);
Object_Status = "Update";
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
.setParameters(new Object[]{mPreference.getAttribute(), mPreference.getAD_User_ID(), mPreference.getAD_Window_ID()})
.first();
if (tmp != null) {
filler = new PoFiller(ctx, tmp, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
mPreference = tmp;
}
} else {
Object_Status = "New";
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 (m_Preference.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, m_Preference.getAttribute(),
m_Preference.get_ID(), Object_Status);
} else {
logImportDetail(ctx, impDetail, 0, m_Preference.getAttribute(),
m_Preference.get_ID(), Object_Status);
throw new POSaveFailedException("Failed to save Preference");
if (mPreference.is_new() || mPreference.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Preference.Table_Name,
X_AD_Preference.Table_ID);
String action = null;
if (!mPreference.is_new()) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Preference.Table_Name, mPreference);
action = "Update";
} else {
action = "New";
}
if (mPreference.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mPreference.getAttribute(),
mPreference.get_ID(), action);
} else {
logImportDetail(ctx, impDetail, 0, mPreference.getAttribute(),
mPreference.get_ID(), action);
throw new POSaveFailedException("Failed to save Preference");
}
}
}
@ -97,11 +109,10 @@ public class PreferenceElementHandler extends AbstractElementHandler {
X_AD_Preference m_Preference = new X_AD_Preference(ctx,
AD_Preference_ID, getTrxName(ctx));
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.preference");
document.startElement("", "", "preference", atts);
addTypeName(atts, "ad.preference");
document.startElement("", "", I_AD_Preference.Table_Name, atts);
createPreferenceBinding(ctx, document, m_Preference);
document.endElement("", "", "preference");
document.endElement("", "", I_AD_Preference.Table_Name);
}
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.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_PrintFormat;
import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail;
import org.compiere.model.X_AD_Package_Exp_Detail;
@ -50,40 +51,43 @@ public class PrintFormatElementHandler extends AbstractElementHandler implements
public void startElement(Properties ctx, Element element)
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;
String name = getStringValue(element, "Name");
int id = findIdByColumn(ctx, "AD_PrintFormat", "Name", name);
X_AD_PrintFormat mPrintFormat = new X_AD_PrintFormat(ctx, id, getTrxName(ctx));
X_AD_PrintFormat mPrintFormat = findPO(ctx, element);
if (mPrintFormat == null) {
String name = getStringValue(element, "Name");
int id = findIdByColumn(ctx, "AD_PrintFormat", "Name", name);
mPrintFormat = new X_AD_PrintFormat(ctx, id > 0 ? id : 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mPrintFormat, element, this);
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"));
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);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mPrintFormat.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mPrintFormat.getName(),
mPrintFormat.get_ID(), action);
element.recordId = mPrintFormat.getAD_PrintFormat_ID();
} else {
logImportDetail(ctx, impDetail, 0, mPrintFormat.getName(),
mPrintFormat.get_ID(), action);
throw new POSaveFailedException("Failed to save Print Format");
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) {
logImportDetail(ctx, impDetail, 1, mPrintFormat.getName(),
mPrintFormat.get_ID(), action);
element.recordId = mPrintFormat.getAD_PrintFormat_ID();
} else {
logImportDetail(ctx, impDetail, 0, mPrintFormat.getName(),
mPrintFormat.get_ID(), action);
throw new POSaveFailedException("Failed to save Print Format");
}
}
}
@ -108,9 +112,8 @@ public class PrintFormatElementHandler extends AbstractElementHandler implements
throw new SAXException(e);
}
}
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.print-format");
document.startElement("", "", "printformat", atts);
addTypeName(atts, "ad.print-format");
document.startElement("", "", I_AD_PrintFormat.Table_Name, atts);
createPrintFormatBinding(ctx, document, m_Printformat);
String sql = "SELECT AD_PrintFormatItem_ID FROM AD_PrintFormatItem WHERE AD_PrintFormat_ID= "
@ -129,7 +132,7 @@ public class PrintFormatElementHandler extends AbstractElementHandler implements
} finally {
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);
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);
}

View File

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

View File

@ -29,6 +29,7 @@ import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_PrintPaper;
import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail;
import org.compiere.model.X_AD_Package_Imp_Detail;
@ -41,27 +42,21 @@ public class PrintPaperElementHandler extends AbstractElementHandler implements
public void startElement(Properties ctx, Element element)
throws SAXException {
String action = null;
List<String> excludes = defaultExcludeList(X_AD_PrintPaper.Table_Name);
X_AD_PrintPaper printPaper = findPO(ctx, element);
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_PrintPaper.Table_Name, X_AD_PrintPaper.Table_ID);
String printPaperName = getStringValue(element, "Name", excludes);
int id = findIdByName(ctx, "AD_PrintPaper", printPaperName);
X_AD_PrintPaper printPaper = new X_AD_PrintPaper(ctx,
id, getTrxName(ctx));
if (printPaper == null) {
String printPaperName = getStringValue(element, "Name", excludes);
int id = findIdByName(ctx, "AD_PrintPaper", printPaperName);
printPaper = new X_AD_PrintPaper(ctx, id > 0 ? id : 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, printPaper, element, this);
if (id <= 0 && isOfficialId(element, "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";
}
if (printPaper.getAD_PrintPaper_ID() == 0 && isOfficialId(element, "AD_PrintPaper_ID"))
filler.setInteger("AD_PrintPaper_ID");
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
@ -69,13 +64,23 @@ public class PrintPaperElementHandler extends AbstractElementHandler implements
return;
}
if (printPaper.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, printPaper.getName(),
printPaper.get_ID(), action);
} else {
logImportDetail(ctx, impDetail, 0, printPaper.getName(),
printPaper.get_ID(), action);
throw new POSaveFailedException("PrintPaper");
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) {
logImportDetail(ctx, impDetail, 1, printPaper.getName(),
printPaper.get_ID(), action);
} else {
logImportDetail(ctx, impDetail, 0, printPaper.getName(),
printPaper.get_ID(), action);
throw new POSaveFailedException("PrintPaper");
}
}
}
@ -89,11 +94,10 @@ public class PrintPaperElementHandler extends AbstractElementHandler implements
X_AD_PrintPaper printPaper = new X_AD_PrintPaper(ctx,
AD_PrintPaper_ID, null);
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.print-paper");
document.startElement("", "", "printpaper", atts);
addTypeName(atts, "ad.print-paper");
document.startElement("", "", I_AD_PrintPaper.Table_Name, atts);
createPrintPaperBinding(ctx, document, printPaper);
document.endElement("", "", "printpaper");
document.endElement("", "", I_AD_PrintPaper.Table_Name);
}
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.Element;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_Process_Access;
import org.compiere.model.I_AD_Role;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Process;
import org.compiere.model.X_AD_Process_Access;
import org.compiere.model.X_AD_Role;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -41,24 +43,28 @@ public class ProcessAccessElementHandler extends AbstractElementHandler {
int processid =0;
List<String> excludes = defaultExcludeList(X_AD_Process_Access.Table_Name);
String roleName = getStringValue(element, "AD_Role.Name", excludes);
if (getParentId(element, "role") > 0) {
roleid = getParentId(element, "role");
} 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));
}
X_AD_Process_Access po = findPO(ctx, element);
if (po == null) {
if (getParentId(element, I_AD_Role.Table_Name) > 0) {
roleid = getParentId(element, I_AD_Role.Table_Name);
} else {
Element roleElement = element.properties.get(I_AD_Process_Access.COLUMNNAME_AD_Role_ID);
roleid = ReferenceUtils.resolveReference(ctx, roleElement);
}
String processName = getStringValue(element, "AD_Process.Value", excludes);
processid = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Process_ID FROM AD_Process WHERE Value = ? AND AD_Client_ID = ?", processName, Env.getAD_Client_ID(ctx));
X_AD_Process_Access po = null;
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();
if (po == null)
{
po = new X_AD_Process_Access(ctx, 0, getTrxName(ctx));
po.setAD_Process_ID(processid);
po.setAD_Role_ID(roleid);
Element processElement = element.properties.get(I_AD_Process_Access.COLUMNNAME_AD_Process_ID);
processid = ReferenceUtils.resolveReference(ctx, processElement);
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();
if (po == null)
{
po = new X_AD_Process_Access(ctx, 0, getTrxName(ctx));
po.setAD_Process_ID(processid);
po.setAD_Role_ID(roleid);
}
excludes.add(I_AD_Process_Access.COLUMNNAME_AD_Role_ID);
excludes.add(I_AD_Process_Access.COLUMNNAME_AD_Process_ID);
}
PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> notfounds = filler.autoFill(excludes);
@ -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_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID);
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.process-access");
document.startElement("", "", "processaccess", atts);
addTypeName(atts, "ad.process-access");
document.startElement("", "", I_AD_Process_Access.Table_Name, atts);
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,

View File

@ -30,6 +30,7 @@ import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Process;
import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail;
import org.compiere.model.Query;
@ -49,29 +50,18 @@ public class ProcessElementHandler extends AbstractElementHandler implements IPa
public void startElement(Properties ctx, Element element)
throws SAXException {
int id = 0;
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
X_AD_Process mProcess = findPO(ctx, element);
if (mProcess == null) {
String value = getStringValue(element, "Value");
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Process.Table_Name,
X_AD_Process.Table_ID);
String value = getStringValue(element, "Value");
// Get New process.
id = findIdByColumn(ctx, "AD_Process", "Value", value);
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";
// Get New process.
int id = findIdByColumn(ctx, "AD_Process", "Value", value);
mProcess = new X_AD_Process(ctx, id > 0 ? id : 0, getTrxName(ctx));
}
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")));
PoFiller filler = new PoFiller(ctx, mProcess, element, this);
@ -83,14 +73,26 @@ public class ProcessElementHandler extends AbstractElementHandler implements IPa
return;
}
if (mProcess.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mProcess.getName(), mProcess
.get_ID(), action);
element.recordId = mProcess.getAD_Process_ID();
} else {
logImportDetail(ctx, impDetail, 0, mProcess.getName(), mProcess
.get_ID(), action);
throw new POSaveFailedException("Process");
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) {
logImportDetail(ctx, impDetail, 1, mProcess.getName(), mProcess
.get_ID(), action);
element.recordId = mProcess.getAD_Process_ID();
} else {
logImportDetail(ctx, impDetail, 0, mProcess.getName(), mProcess
.get_ID(), action);
throw new POSaveFailedException("Process");
}
}
} else {
element.skip = true;
@ -117,7 +119,6 @@ public class ProcessElementHandler extends AbstractElementHandler implements IPa
{
IPackOutHandler handler = packOut.getHandler("R");
handler.packOut(packOut,null,null,document,null,m_Process.getAD_ReportView_ID());
}
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");
handler.packOut(packOut,null,null,document,null,m_Process.getAD_Workflow_ID());
}
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.process");
document.startElement("", "", "process", atts);
addTypeName(atts, "ad.process");
document.startElement("", "", I_AD_Process.Table_Name, atts);
createProcessBinding(ctx, document, m_Process);
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());
}
document.endElement("", "", "process");
document.endElement("", "", I_AD_Process.Table_Name);
} catch (Exception 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.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
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_Process_Para;
import org.compiere.util.Env;
@ -43,66 +46,65 @@ public class ProcessParaElementHandler extends AbstractElementHandler {
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
if (isParentDefer(element, "process")) {
if (isParentDefer(element, I_AD_Process.Table_Name)) {
element.defer = true;
return;
}
String name = getStringValue(element, "Name");
X_AD_Process_Para mProcessPara = findPO(ctx, element);
if (mProcessPara == null) {
String name = getStringValue(element, "Name");
int id = 0;
int masterId = 0;
String processValue = "";
if (getParentId(element, "process") > 0) {
masterId = getParentId(element, "process");
} else {
processValue = getStringValue(element, "AD_Process.Value", excludes);
if (processValue != null && processValue.trim().length() > 0) {
masterId = findIdByColumn(ctx, "AD_Process", "Value", processValue);
int id = 0;
int masterId = 0;
if (getParentId(element, I_AD_Process.Table_Name) > 0) {
masterId = getParentId(element, "process");
} else {
Element processElement = element.properties.get(I_AD_Process_Para.COLUMNNAME_AD_Process_ID);
masterId = ReferenceUtils.resolveReference(ctx, processElement);
}
if (masterId <= 0) {
element.defer = true;
element.unresolved = "AD_Process: " + getStringValue(element, I_AD_Process_Para.COLUMNNAME_AD_Process_ID);
return;
}
id = findIdByColumnAndParentId(ctx, "AD_Process_Para", "Name", name, "AD_Process", masterId);
mProcessPara = new X_AD_Process_Para(ctx, id > 0 ? id : 0, getTrxName(ctx));
mProcessPara.setAD_Process_ID(masterId);
excludes.add(I_AD_Process_Para.COLUMNNAME_AD_Process_ID);
}
if (masterId <= 0) {
element.defer = true;
element.unresolved = "AD_Process: " + processValue;
return;
}
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Process_Para.Table_Name,
X_AD_Process_Para.Table_ID);
id = findIdByColumnAndParentId(ctx, "AD_Process_Para", "Name",
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"))
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")));
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);
PoFiller filler = new PoFiller(ctx, mProcessPara, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mProcessPara.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mProcessPara.getName(),
mProcessPara.get_ID(), action);
} else {
logImportDetail(ctx, impDetail, 0, mProcessPara.getName(),
mProcessPara.get_ID(), action);
throw new POSaveFailedException("ProcessPara");
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) {
logImportDetail(ctx, impDetail, 1, mProcessPara.getName(),
mProcessPara.get_ID(), action);
} else {
logImportDetail(ctx, impDetail, 0, mProcessPara.getName(),
mProcessPara.get_ID(), action);
throw new POSaveFailedException("ProcessPara");
}
}
} else {
element.skip = true;
@ -129,11 +131,10 @@ public class ProcessParaElementHandler extends AbstractElementHandler {
}
}
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.process.parameter");
document.startElement("", "", "processpara", atts);
addTypeName(atts, "ad.process.parameter");
document.startElement("", "", I_AD_Process_Para.Table_Name, atts);
createProcessParaBinding(ctx, document, m_Processpara);
document.endElement("", "", "processpara");
document.endElement("", "", I_AD_Process_Para.Table_Name);
}
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.exception.DatabaseAccessException;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Reference;
import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail;
import org.compiere.model.X_AD_Package_Exp_Detail;
@ -55,48 +56,51 @@ public class ReferenceElementHandler extends AbstractElementHandler implements I
public void startElement(Properties ctx, Element element)
throws SAXException {
String Object_Status = null;
String entitytype = getStringValue(element, "EntityType");
String name = getStringValue(element, "Name");
if (isProcessElement(ctx, entitytype)) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Reference.Table_Name,
X_AD_Reference.Table_ID);
int id = findIdByName(ctx, "AD_Reference", name);
X_AD_Reference m_Reference = new X_AD_Reference(ctx, id, getTrxName(ctx));
List<String> excludes = defaultExcludeList(X_AD_Reference.Table_Name);
if (id <= 0 && isOfficialId(element, "AD_Reference_ID"))
m_Reference.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";
X_AD_Reference mReference = findPO(ctx, element);
if (mReference == null) {
int id = findIdByName(ctx, "AD_Reference", name);
mReference = new X_AD_Reference(ctx, id > 0 ? id : 0, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, m_Reference, element, this);
List<String> excludes = defaultExcludeList(X_AD_Reference.Table_Name);
if (mReference.getAD_Reference_ID() == 0 && isOfficialId(element, "AD_Reference_ID"))
mReference.setAD_Reference_ID(getIntValue(element, "AD_Reference_ID"));
PoFiller filler = new PoFiller(ctx, mReference, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (m_Reference.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, m_Reference.getName(),
m_Reference.get_ID(), Object_Status);
references.add(m_Reference.getAD_Reference_ID());
element.recordId = m_Reference.getAD_Reference_ID();
} else {
logImportDetail(ctx, impDetail, 0, m_Reference.getName(),
m_Reference.get_ID(), Object_Status);
throw new POSaveFailedException("Reference");
if (mReference.is_new() || mReference.is_Changed()) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Reference.Table_Name,
X_AD_Reference.Table_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 {
action = "New";
}
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");
}
}
} else {
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));
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.reference");
document.startElement("", "", "reference", atts);
addTypeName(atts, "ad.reference");
document.startElement("", "", I_AD_Reference.Table_Name, atts);
createReferenceBinding(ctx, document, m_Reference);
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) {
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.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Ref_List;
import org.compiere.model.I_AD_Reference;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_Ref_List;
import org.compiere.util.Env;
@ -37,7 +40,7 @@ public class ReferenceListElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element)
throws SAXException {
String action = null;
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
if (isParentSkip(element, null)) {
@ -45,29 +48,24 @@ public class ReferenceListElementHandler extends AbstractElementHandler {
return;
}
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Ref_List.Table_Name,
X_AD_Ref_List.Table_ID);
String value = getStringValue(element, "Value");
int AD_Reference_ID = 0;
if (getParentId(element, "reference") > 0) {
AD_Reference_ID = getParentId(element, "reference");
} else {
String referenceName = getStringValue(element, "AD_Reference.Name");
AD_Reference_ID = findIdByColumn(ctx, "AD_Reference", "Name", referenceName);
X_AD_Ref_List mRefList = findPO(ctx, element);
if (mRefList == null) {
String value = getStringValue(element, "Value");
int AD_Reference_ID = 0;
if (getParentId(element, I_AD_Reference.Table_Name) > 0) {
AD_Reference_ID = getParentId(element, I_AD_Reference.Table_Name);
} else {
Element referenceElement = element.properties.get(I_AD_Ref_List.COLUMNNAME_AD_Reference_ID);
AD_Reference_ID = ReferenceUtils.resolveReference(ctx, referenceElement);
}
int AD_Ref_List_ID = findIdByColumnAndParentId(ctx, "AD_Ref_List", "Value", value, "AD_Reference", AD_Reference_ID);
mRefList = new X_AD_Ref_List(ctx, AD_Ref_List_ID, getTrxName(ctx));
}
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));
if (AD_Ref_List_ID <= 0 && isOfficialId(element, "AD_Ref_List_ID"))
if (mRefList.getAD_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";
}
PoFiller filler = new PoFiller(ctx, mRefList, element, this);
List<String> excludes = defaultExcludeList(X_AD_Ref_List.Table_Name);
List<String> notfounds = filler.autoFill(excludes);
@ -76,13 +74,24 @@ public class ReferenceListElementHandler extends AbstractElementHandler {
return;
}
if (mRefList.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mRefList.getName(),
mRefList.get_ID(), action);
} else {
logImportDetail(ctx, impDetail, 0, mRefList.getName(),
mRefList.get_ID(), action);
throw new POSaveFailedException("ReferenceList");
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) {
logImportDetail(ctx, impDetail, 1, mRefList.getName(),
mRefList.get_ID(), action);
} else {
logImportDetail(ctx, impDetail, 0, mRefList.getName(),
mRefList.get_ID(), action);
throw new POSaveFailedException("ReferenceList");
}
}
} else {
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,
getTrxName(ctx));
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.reference.list");
document.startElement("", "", "referencelist", atts);
addTypeName(atts, "ad.reference.list");
document.startElement("", "", I_AD_Ref_List.Table_Name, atts);
createRefListBinding(ctx, document, m_Ref_List);
document.endElement("", "", "referencelist");
document.endElement("", "", I_AD_Ref_List.Table_Name);
}
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.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.compiere.model.I_AD_Ref_Table;
import org.compiere.model.I_AD_Reference;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_Ref_Table;
import org.compiere.util.DB;
@ -45,61 +48,76 @@ public class ReferenceTableElementHandler extends AbstractElementHandler {
List<String > excludes = defaultExcludeList(X_AD_Ref_Table.Table_Name);
String entitytype = getStringValue(element, "EntityType");
String name = getStringValue(element, "AD_Reference_ID", excludes);
if (isProcessElement(ctx, entitytype)) {
if (isParentSkip(element, null)) {
element.skip = true;
return;
}
int AD_Reference_ID = 0;
if (getParentId(element, "reference") > 0) {
AD_Reference_ID = getParentId(element, "reference");
} 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));
}
if (AD_Reference_ID <= 0 && isOfficialId(element, "AD_Reference_ID"))
AD_Reference_ID = getIntValue(element, "AD_Reference_ID");
String sql = "SELECT * FROM AD_Ref_Table WHERE AD_Reference_ID = ?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
pstmt.setInt(1, AD_Reference_ID);
rs = pstmt.executeQuery();
X_AD_Ref_Table refTable = null;
String action = null;
if (rs.next()) {
refTable = new X_AD_Ref_Table(ctx, rs, getTrxName(ctx));
action = "Update";
X_AD_Ref_Table refTable = findPO(ctx, element);
if (refTable == null) {
int AD_Reference_ID = 0;
if (getParentId(element, I_AD_Reference.Table_Name) > 0) {
AD_Reference_ID = getParentId(element, I_AD_Reference.Table_Name);
} else {
refTable = new X_AD_Ref_Table(ctx, 0, getTrxName(ctx));
action = "New";
Element referenceElement = element.properties.get(I_AD_Ref_Table.COLUMNNAME_AD_Reference_ID);
AD_Reference_ID = ReferenceUtils.resolveReference(ctx, referenceElement);
}
PoFiller filler = new PoFiller(ctx, refTable, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
if (AD_Reference_ID <= 0 && isOfficialId(element, "AD_Reference_ID"))
AD_Reference_ID = getIntValue(element, "AD_Reference_ID");
String sql = "SELECT * FROM AD_Ref_Table WHERE AD_Reference_ID = ?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
pstmt.setInt(1, AD_Reference_ID);
rs = pstmt.executeQuery();
if (rs.next()) {
refTable = new X_AD_Ref_Table(ctx, rs, getTrxName(ctx));
} else {
refTable = new X_AD_Ref_Table(ctx, 0, getTrxName(ctx));
}
} catch (Exception e) {
throw new DatabaseAccessException(e.getLocalizedMessage(), e);
} finally {
DB.close(rs, pstmt);
}
int tableId = refTable.getAD_Table_ID();
String columnName = getStringValue(element, "AD_Display", excludes);
int columnId = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnName, "AD_Table", tableId);
refTable.setAD_Display(columnId);
columnName = getStringValue(element, "AD_Key", excludes);
columnId = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnName, "AD_Table", tableId);
refTable.setAD_Key(columnId);
}
String action = refTable.is_new() ? "New" : "Update";
PoFiller filler = new PoFiller(ctx, refTable, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
int tableId = refTable.getAD_Table_ID();
Element displayElement = element.properties.get("AD_Display");
int displayColumnId = 0;
if (ReferenceUtils.isIDLookup(displayElement) || ReferenceUtils.isUUIDLookup(displayElement)) {
displayColumnId = ReferenceUtils.resolveReference(ctx, displayElement);
} else {
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();
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Ref_Table.Table_Name,
X_AD_Ref_Table.Table_ID);
logImportDetail(ctx, impDetail, 1, name, AD_Reference_ID, action);
} catch (Exception e) {
throw new DatabaseAccessException(e.getLocalizedMessage(), e);
} finally {
DB.close(rs, pstmt);
logImportDetail(ctx, impDetail, 1, refTable.getAD_Reference().getName(), refTable.getAD_Reference_ID(), action);
}
} else {
element.skip = true;
@ -114,11 +132,10 @@ public class ReferenceTableElementHandler extends AbstractElementHandler {
int Reference_id = Env.getContextAsInt(ctx,
X_AD_Ref_Table.COLUMNNAME_AD_Reference_ID);
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.reference.table");
document.startElement("", "", "referencetable", atts);
addTypeName(atts, "ad.reference.table");
document.startElement("", "", I_AD_Ref_Table.Table_Name, atts);
createReferenceTableBinding(ctx, document, Reference_id);
document.endElement("", "", "referencetable");
document.endElement("", "", I_AD_Ref_Table.Table_Name);
}
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.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_ReportView;
import org.compiere.model.I_AD_ReportView_Col;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_ReportView_Col;
import org.compiere.util.DB;
@ -37,67 +40,68 @@ import org.xml.sax.helpers.AttributesImpl;
public class ReportViewColElementHandler extends AbstractElementHandler {
public void startElement(Properties ctx, Element element)
throws SAXException {
String action = null;
throws SAXException {
List<String> excludes = defaultExcludeList(X_AD_ReportView_Col.Table_Name);
String entitytype = getStringValue(element,"EntityType");
if (isProcessElement(ctx, entitytype)) {
String name = getStringValue(element, "AD_ReportView.Name", excludes);
int AD_ReportView_ID = 0;
if (getParentId(element, "reportview") > 0) {
AD_ReportView_ID = getParentId(element, "reportview");
} else {
AD_ReportView_ID = findIdByColumn(ctx, "AD_ReportView", "Name", name);
}
if (AD_ReportView_ID <= 0) {
element.defer = true;
return;
}
name = getStringValue(element, "AD_Column.ColumnName", excludes);
int AD_Column_ID = 0;
if (name != null && name.trim().length() > 0) {
AD_Column_ID = findIdByColumn(ctx, "AD_Column", "Name", name);
if (AD_Column_ID <= 0) {
excludes.add("AD_Table_ID");
X_AD_ReportView_Col mReportviewCol = findPO(ctx, element);
if (mReportviewCol == null) {
int AD_ReportView_ID = 0;
if (getParentId(element, I_AD_ReportView.Table_Name) > 0) {
AD_ReportView_ID = getParentId(element, I_AD_ReportView.Table_Name);
} else {
Element rvElement = element.properties.get(I_AD_ReportView_Col.COLUMNNAME_AD_ReportView_ID);
AD_ReportView_ID = ReferenceUtils.resolveReference(ctx, rvElement);
}
if (AD_ReportView_ID <= 0) {
element.defer = true;
return;
}
int AD_Column_ID = 0;
Element columnElement = element.properties.get(I_AD_ReportView_Col.COLUMNNAME_AD_Column_ID);
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) {
AD_Column_ID = ReferenceUtils.resolveReference(ctx, 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) {
element.defer = true;
return;
}
}
}
String functionColumn = getStringValue(element, "FunctionColumn");
StringBuffer sql = new StringBuffer("SELECT AD_Reportview_Col_ID FROM AD_Reportview_Col ")
.append(" WHERE AD_Column_ID ");
if (AD_Column_ID > 0)
sql.append(" = " + AD_Column_ID);
else
sql.append(" IS NULL ");
sql.append(" AND FunctionColumn = ?");
sql.append(" AND AD_ReportView_ID = ?");
int id = DB.getSQLValue(getTrxName(ctx), sql.toString(), functionColumn, AD_ReportView_ID);
mReportviewCol = new X_AD_ReportView_Col(ctx, id > 0 ? id : 0, getTrxName(ctx));
mReportviewCol.setAD_ReportView_ID(AD_ReportView_ID);
if (AD_Column_ID > 0) {
mReportviewCol.setAD_Column_ID(id);
}
mReportviewCol.setFunctionColumn(functionColumn);
excludes.add("FunctionColumn");
excludes.add("AD_ReportView_ID");
excludes.add("AD_Column_ID");
}
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_ReportView_Col.Table_Name,
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 ")
.append(" WHERE AD_Column_ID ");
if (AD_Column_ID > 0)
sql.append(" = " + AD_Column_ID);
else
sql.append(" IS NULL ");
sql.append(" AND FunctionColumn = ?");
sql.append(" AND AD_ReportView_ID = ?");
int id = DB.getSQLValue(getTrxName(ctx), sql.toString(), functionColumn, AD_ReportView_ID);
if (id < 0) id = 0;
X_AD_ReportView_Col mReportviewCol = new X_AD_ReportView_Col(ctx,
id, getTrxName(ctx));
if (id <= 0 && isOfficialId(element, "AD_ReportView_Col_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"));
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);
if (AD_Column_ID > 0) {
mReportviewCol.setAD_Column_ID(id);
}
mReportviewCol.setFunctionColumn(functionColumn);
PoFiller filler = new PoFiller(ctx, mReportviewCol, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
@ -105,13 +109,25 @@ public class ReportViewColElementHandler extends AbstractElementHandler {
return;
}
if (mReportviewCol.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, "" + mReportviewCol.getAD_ReportView_ID(),
mReportviewCol.get_ID(), action);
} else {
logImportDetail(ctx, impDetail, 0, "" + mReportviewCol.getAD_ReportView_ID(),
mReportviewCol.get_ID(),action);
throw new POSaveFailedException("ReportViewCol");
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) {
logImportDetail(ctx, impDetail, 1, "" + mReportviewCol.getAD_ReportView_ID(),
mReportviewCol.get_ID(), action);
} else {
logImportDetail(ctx, impDetail, 0, "" + mReportviewCol.getAD_ReportView_ID(),
mReportviewCol.get_ID(),action);
throw new POSaveFailedException("ReportViewCol");
}
}
} else {
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,
AD_ReportView_Col_ID, getTrxName(ctx));
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.report-view.column");
document.startElement("", "", "reportviewcol", atts);
addTypeName(atts, "ad.report-view.column");
document.startElement("", "", I_AD_ReportView_Col.Table_Name, atts);
createReportViewColBinding(ctx, document, m_Reportview_Col);
document.endElement("", "", "reportviewcol");
document.endElement("", "", I_AD_ReportView_Col.Table_Name);
}
private void createReportViewColBinding(Properties ctx, TransformerHandler document,
@ -142,9 +157,14 @@ public class ReportViewColElementHandler extends AbstractElementHandler {
List<String> excludes = defaultExcludeList(X_AD_ReportView_Col.Table_Name);
if (m_Reportview_Col.getAD_ReportView_Col_ID() <= PackOut.MAX_OFFICIAL_ID)
filler.add("AD_ReportView_Col_ID", new AttributesImpl());
if (m_Reportview_Col.getAD_Column_ID() > 0) {
int AD_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.addTableReference("AD_Column_ID", "AD_Column", "ColumnName", new AttributesImpl());
excludes.add("AD_Column_ID");
filler.export(excludes);
}
}

View File

@ -32,6 +32,7 @@ import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_ReportView;
import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail;
import org.compiere.model.X_AD_Package_Exp_Detail;
@ -51,37 +52,44 @@ public class ReportViewElementHandler extends AbstractElementHandler implements
public void startElement(Properties ctx, Element element)
throws SAXException {
String action = null;
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.Table_ID);
String name = getStringValue(element, "Name");
int id = findIdByName(ctx, "AD_ReportView", name);
X_AD_ReportView 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";
X_AD_ReportView mReportview = findPO(ctx, element);
if (mReportview == null) {
String name = getStringValue(element, "Name");
int id = findIdByName(ctx, "AD_ReportView", name);
mReportview = new X_AD_ReportView(ctx, id, getTrxName(ctx));
}
PoFiller filler = new PoFiller(ctx, mReportview, element, this);
if (mReportview.getAD_ReportView_ID() == 0 && isOfficialId(element, "AD_ReportView_ID"))
mReportview.setAD_ReportView_ID(getIntValue(element, "AD_ReportView_ID"));
List<String> notfound = filler.autoFill(excludes);
if (notfound.size() > 0) {
element.defer = true;
return;
}
if (mReportview.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mReportview.getName(),
mReportview.get_ID(), action);
element.recordId = mReportview.getAD_ReportView_ID();
} else {
logImportDetail(ctx, impDetail, 0, mReportview.getName(),
mReportview.get_ID(), action);
throw new POSaveFailedException("ReportView");
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) {
logImportDetail(ctx, impDetail, 1, mReportview.getName(),
mReportview.get_ID(), action);
element.recordId = mReportview.getAD_ReportView_ID();
} else {
logImportDetail(ctx, impDetail, 0, mReportview.getName(),
mReportview.get_ID(), action);
throw new POSaveFailedException("ReportView");
}
}
}
@ -107,11 +115,10 @@ public class ReportViewElementHandler extends AbstractElementHandler implements
throw new AdempiereException(e);
}
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.report-view");
document.startElement("", "", "reportView", atts);
addTypeName(atts, "ad.report-view");
document.startElement("", "", I_AD_ReportView.Table_Name, atts);
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= "
+ AD_ReportView_ID;

View File

@ -31,8 +31,10 @@ import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Role;
import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail;
import org.compiere.model.MRole;
@ -65,65 +67,19 @@ public class RoleElementHandler extends AbstractElementHandler implements IPackO
public void startElement(Properties ctx, Element element)
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);
String name = getStringValue(element, "Name", excludes);
int id = findIdByName(ctx, "AD_Role", name);
MRole mRole = new MRole(ctx, id, getTrxName(ctx));
String action = null;
if (id <= 0 && isOfficialId(element, "AD_Role_ID"))
MRole mRole = findPO(ctx, element);
if (mRole == null) {
String name = getStringValue(element, "Name", excludes);
int id = findIdByName(ctx, "AD_Role", name);
mRole = new MRole(ctx, id > 0 ? id : 0, getTrxName(ctx));
mRole.setName(name);
}
if (mRole.getAD_Role_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);
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 (name != null && name.trim().length() > 0) {
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);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
@ -131,15 +87,25 @@ public class RoleElementHandler extends AbstractElementHandler implements IPackO
return;
}
if (mRole.save(getTrxName(ctx)) == true) {
element.recordId = mRole.getAD_Role_ID();
logImportDetail(ctx, impDetail, 1, mRole.getName(), mRole.get_ID(),
action);
} else {
logImportDetail(ctx, impDetail, 0, mRole.getName(), mRole.get_ID(),
action);
throw new POSaveFailedException("Role");
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) {
element.recordId = mRole.getAD_Role_ID();
logImportDetail(ctx, impDetail, 1, mRole.getName(), mRole.get_ID(),
action);
} else {
logImportDetail(ctx, impDetail, 0, mRole.getName(), mRole.get_ID(),
action);
throw new POSaveFailedException("Role");
}
}
}
@ -155,9 +121,8 @@ public class RoleElementHandler extends AbstractElementHandler implements IPackO
roles.add(Role_id);
X_AD_Role m_Role = new X_AD_Role(ctx, Role_id, null);
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.role");
document.startElement("", "", "role", atts);
addTypeName(atts, "ad.role");
document.startElement("", "", I_AD_Role.Table_Name, atts);
createRoleBinding(ctx, document, m_Role);
// Process org access
@ -279,7 +244,7 @@ public class RoleElementHandler extends AbstractElementHandler implements IPackO
} finally {
DB.close(rs, pstmt);
}
document.endElement("", "", "role");
document.endElement("", "", I_AD_Role.Table_Name);
}
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,
X_AD_Role m_Role) {
String sql = null;
String name = null;
PoExporter filler = new PoExporter(ctx, document, m_Role);
List<String> excludes = defaultExcludeList(X_AD_Role.Table_Name);
if (m_Role.getAD_Role_ID() <= PackOut.MAX_OFFICIAL_ID)
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) {
sql = "SELECT ISO_Code FROM C_Currency WHERE C_Currency_ID=?";
name = DB.getSQLValueString(null, sql, m_Role.getC_Currency_ID());
filler.addString("currencycode", name, new AttributesImpl());
AttributesImpl currencyAtts = new AttributesImpl();
String value = ReferenceUtils.getTableReference("C_Currency", "ISO_Code", m_Role.getC_Currency_ID(), currencyAtts);
filler.addString("C_Currency_ID", value, currencyAtts);
} else
filler.addString("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_AD_Tree_Org_ID);
excludes.add(X_AD_Role.COLUMNNAME_AD_Tree_Menu_ID);
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 DBType = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_DBType);
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.sql-statement");
addTypeName(atts, "ad.sql-statement");
document.startElement("","","SQLStatement",atts);
createSQLStatmentBinding(document, SQLStatement, DBType);
document.endElement("","","SQLStatement");

View File

@ -31,8 +31,11 @@ import org.adempiere.pipo2.PoExporter;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.DatabaseAccessException;
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.X_AD_Field;
import org.compiere.model.X_AD_Package_Imp_Detail;
@ -51,84 +54,103 @@ public class TabElementHandler extends AbstractElementHandler {
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
if (isParentDefer(element, "window")) {
if (isParentDefer(element, I_AD_Window.Table_Name)) {
element.defer = true;
return;
}
String name = getStringValue(element, "Name", excludes);
String windowName = getStringValue(element, "AD_Window_ID", excludes);
int windowId = 0;
if (getParentId(element, "window") > 0) {
windowId = getParentId(element, "window");
} else {
windowId = findIdByName(ctx, "AD_Window", windowName);
MTab mTab = findPO(ctx, element);
if (mTab == null) {
String name = getStringValue(element, "Name", excludes);
int windowId = 0;
if (getParentId(element, I_AD_Window.Table_Name) > 0) {
windowId = getParentId(element, I_AD_Window.Table_Name);
} else {
Element windowElement = element.properties.get(I_AD_Tab.COLUMNNAME_AD_Window_ID);
windowId = ReferenceUtils.resolveReference(ctx, windowElement);
}
if (windowId <= 0) {
element.defer = true;
return;
}
Element tableElement = element.properties.get(I_AD_Tab.COLUMNNAME_AD_Table_ID);
int tableId = ReferenceUtils.resolveReference(ctx, tableElement);
if (tableId <= 0) {
element.defer = true;
return;
}
String sql = "SELECT AD_Tab_ID FROM AD_Tab where AD_Window_ID = ? "
+ " AND Name = ?"
+ " AND AD_Table_ID = ?";
int id = DB.getSQLValue(getTrxName(ctx), sql, windowId, name, tableId);
mTab = new MTab(ctx, id > 0 ? id : 0, getTrxName(ctx));
mTab.setAD_Table_ID(tableId);
mTab.setName(name);
mTab.setAD_Window_ID(windowId);
}
if (windowId <= 0) {
element.defer = true;
return;
}
String tableName = getStringValue(element, "AD_Table_ID", excludes);
int tableId = findIdByColumn(ctx, "AD_Table", "TableName", tableName);
if (tableId <= 0) {
element.defer = true;
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 = ? "
+ " AND Name = ?"
+ " AND AD_Table_ID = ?";
int id = DB.getSQLValue(getTrxName(ctx), sql, windowId, tableName, tableId);
MTab mTab = new MTab(ctx, id, getTrxName(ctx));
PoFiller filler = new PoFiller(ctx, mTab, element, this);
if (id <= 0 && isOfficialId(element, "AD_Tab_ID"))
if (mTab.getAD_Tab_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.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);
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);
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);
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());
}
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_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_Window_ID(windowId);
mTab.setAD_ColumnSortYesNo_ID(AD_Column_ID);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mTab.save(getTrxName(ctx)) == true){
logImportDetail (ctx, impDetail, 1, mTab.getName(), mTab.get_ID(),action);
element.recordId = mTab.getAD_Tab_ID();
} else {
logImportDetail (ctx, impDetail, 0, mTab.getName(), mTab.get_ID(),action);
throw new POSaveFailedException("Tab");
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){
logImportDetail (ctx, impDetail, 1, mTab.getName(), mTab.get_ID(),action);
element.recordId = mTab.getAD_Tab_ID();
} else {
logImportDetail (ctx, impDetail, 0, mTab.getName(), mTab.get_ID(),action);
throw new POSaveFailedException("Tab");
}
}
} else {
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);
X_AD_Tab m_Tab = new X_AD_Tab (ctx, AD_Tab_ID, getTrxName(ctx));
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.window.tab");
document.startElement("","","tab",atts);
addTypeName(atts, "ad.window.tab");
document.startElement("","",I_AD_Tab.Table_Name,atts);
createTabBinding(ctx,document,m_Tab);
//Fields tags.
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);
}
document.endElement("","","tab");
document.endElement("","",I_AD_Tab.Table_Name);
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.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Table;
import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail;
import org.compiere.model.MTable;
@ -57,48 +58,57 @@ public class TableElementHandler extends AbstractElementHandler implements IPack
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
String tableName = getStringValue(element, "TableName", excludes);
MTable mTable = findPO(ctx, element);
if (mTable == null) {
String tableName = getStringValue(element, "TableName", excludes);
int id = packIn.getTableId(tableName);
if (id <= 0) {
id = findIdByColumn(ctx, "AD_Table", "TableName", tableName);
if (id > 0)
packIn.addTable(tableName, id);
int id = packIn.getTableId(tableName);
if (id <= 0) {
id = findIdByColumn(ctx, "AD_Table", "TableName", tableName);
if (id > 0)
packIn.addTable(tableName, id);
}
if (id > 0 && isTableProcess(ctx, id)) {
return;
}
mTable = new MTable(ctx, id > 0 ? id : 0, getTrxName(ctx));
mTable.setTableName(tableName);
}
if (id > 0 && isTableProcess(ctx, id)) {
return;
}
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Table.Table_Name,
X_AD_Table.Table_ID);
MTable mTable = new MTable(ctx, id, getTrxName(ctx));
if (id <= 0 && isOfficialId(element, "AD_Table_ID"))
if (mTable.getAD_Table_ID() == 0 && isOfficialId(element, "AD_Table_ID"))
{
mTable.setAD_Table_ID(getIntValue(element, "AD_Table_ID"));
}
String action = null;
if (id > 0){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(),X_AD_Table.Table_Name,mTable);
action = "Update";
}
else{
action = "New";
mTable.setTableName(tableName);
}
PoFiller filler = new PoFiller(ctx, mTable, element, this);
filler.autoFill(excludes);
if (mTable.save(getTrxName(ctx)) == true){
logImportDetail (ctx, impDetail, 1, mTable.getName(),mTable.get_ID(),action);
tables.add(mTable.getAD_Table_ID());
packIn.addTable(tableName, mTable.getAD_Table_ID());
element.recordId = mTable.getAD_Table_ID();
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
else{
logImportDetail (ctx, impDetail, 0, mTable.getName(), mTable.get_ID(),action);
throw new POSaveFailedException("Table");
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;
if (!mTable.is_new()){
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(),X_AD_Table.Table_Name,mTable);
action = "Update";
}
else{
action = "New";
}
if (mTable.save(getTrxName(ctx)) == true){
logImportDetail (ctx, impDetail, 1, mTable.getName(),mTable.get_ID(),action);
tables.add(mTable.getAD_Table_ID());
packIn.addTable(mTable.getTableName(), mTable.getAD_Table_ID());
element.recordId = mTable.getAD_Table_ID();
}
else{
logImportDetail (ctx, impDetail, 0, mTable.getName(), mTable.get_ID(),action);
throw new POSaveFailedException("Table");
}
}
} else {
element.skip = true;
@ -118,9 +128,8 @@ public class TableElementHandler extends AbstractElementHandler implements IPack
//Export table if not already done so
if (!exported){
X_AD_Table m_Table = new X_AD_Table (ctx, AD_Table_ID, null);
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.table");
document.startElement("","","table",atts);
addTypeName(atts, "ad.table");
document.startElement("","",I_AD_Table.Table_Name,atts);
createTableBinding(ctx,document,m_Table);
String sql = "SELECT * FROM AD_Column WHERE AD_Table_ID = ? "
@ -169,7 +178,7 @@ public class TableElementHandler extends AbstractElementHandler implements IPack
} finally {
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)
{
PoExporter filler = new PoExporter(ctx, document, m_Table);
if (m_Table.getAD_Table_ID() <= PackOut.MAX_OFFICIAL_ID)
{
PoExporter filler = new PoExporter(ctx, document, null);
filler.addString("AD_Table_ID", Integer.toString(m_Table.getAD_Table_ID()), new AttributesImpl());
filler.add("AD_Table_ID", new AttributesImpl());
}
List<String> excludes = defaultExcludeList(X_AD_Table.Table_Name);
PoExporter filler = new PoExporter(ctx, document, m_Table);
List<String> excludes = defaultExcludeList(X_AD_Table.Table_Name);
filler.export(excludes);
}

View File

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

View File

@ -30,6 +30,7 @@ import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Task;
import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail;
import org.compiere.model.MTask;
@ -50,34 +51,41 @@ public class TaskElementHandler extends AbstractElementHandler implements IPackO
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Task.Table_Name,
X_AD_Task.Table_ID);
String name = getStringValue(element, "Name");
int id = findIdByName(ctx, "AD_Task", name);
MTask mTask = new MTask(ctx, id, 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";
MTask mTask = findPO(ctx, element);
if (mTask == null) {
String name = getStringValue(element, "Name");
int id = findIdByName(ctx, "AD_Task", name);
mTask = new MTask(ctx, id > 0 ? id : 0, getTrxName(ctx));
}
if (mTask.getAD_Task_ID() == 0 && isOfficialId(element, "AD_Task_ID"))
mTask.setAD_Task_ID(getIntValue(element, "AD_Task_ID"));
PoFiller filler = new PoFiller(ctx, mTask, element, this);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mTask.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mTask.getName(), mTask.get_ID(),
action);
} else {
logImportDetail(ctx, impDetail, 0, mTask.getName(), mTask.get_ID(),
action);
throw new POSaveFailedException("Task");
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) {
logImportDetail(ctx, impDetail, 1, mTask.getName(), mTask.get_ID(),
action);
} else {
logImportDetail(ctx, impDetail, 0, mTask.getName(), mTask.get_ID(),
action);
throw new POSaveFailedException("Task");
}
}
} else {
element.skip = true;
@ -95,11 +103,10 @@ public class TaskElementHandler extends AbstractElementHandler implements IPackO
tasks.add(AD_Task_ID);
X_AD_Task m_Task = new X_AD_Task(ctx, AD_Task_ID, null);
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.task");
document.startElement("", "", "task", atts);
addTypeName(atts, "ad.task");
document.startElement("", "", I_AD_Task.Table_Name, atts);
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.Element;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_User_Roles;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Role;
import org.compiere.model.X_AD_User;
import org.compiere.model.X_AD_User_Roles;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -43,26 +44,32 @@ public class UserRoleElementHandler extends AbstractElementHandler {
List<String> excludes = defaultExcludeList(X_AD_User_Roles.Table_Name);
String userName = getStringValue(element, "AD_User.Name", excludes);
userid = DB.getSQLValue(getTrxName(ctx), "SELECT AD_User_ID FROM AD_User WHERE Name = ? AND AD_Client_ID = ?", userName, Env.getAD_Client_ID(ctx));
String roleName = getStringValue(element, "rolename", excludes);
if (getParentId(element, "role") > 0) {
roleid = getParentId(element, "role");
} 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));
}
String orgName = getStringValue(element, "AD_Org.Name", excludes);
orgid = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Org_ID FROM AD_Org WHERE Name = ? AND AD_Client_ID = ?", orgName, Env.getAD_Client_ID(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();
X_AD_User_Roles po = findPO(ctx, element);
if (po == null) {
po = new X_AD_User_Roles(ctx, 0, getTrxName(ctx));
po.setAD_Org_ID(orgid);
po.setAD_Role_ID(roleid);
po.setAD_User_ID(userid);
Element userElement = element.properties.get(I_AD_User_Roles.COLUMNNAME_AD_User_ID);
userid = ReferenceUtils.resolveReference(ctx, userElement);
if (getParentId(element, "role") > 0) {
roleid = getParentId(element, "role");
} else {
Element roleElement = element.properties.get(I_AD_User_Roles.COLUMNNAME_AD_Role_ID);
roleid = ReferenceUtils.resolveReference(ctx, roleElement);
}
Element orgElement = element.properties.get(I_AD_User_Roles.COLUMNNAME_AD_Org_ID);
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));
po = query.setParameters(new Object[]{userid, roleid, orgid}).first();
if (po == null) {
po = new X_AD_User_Roles(ctx, 0, getTrxName(ctx));
po.setAD_Org_ID(orgid);
po.setAD_Role_ID(roleid);
po.setAD_User_ID(userid);
}
excludes.add(I_AD_User_Roles.COLUMNNAME_AD_User_ID);
excludes.add(I_AD_User_Roles.COLUMNNAME_AD_Role_ID);
excludes.add(I_AD_User_Roles.COLUMNNAME_AD_Org_ID);
}
PoFiller filler = new PoFiller(ctx, po, element, this);
List<String> notfounds = filler.autoFill(excludes);
@ -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_Org_ID = Env.getContextAsInt(ctx, "AD_Org_ID");
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.user-role");
document.startElement("", "", "userRole", atts);
addTypeName(atts, "ad.user-role");
document.startElement("", "", I_AD_User_Roles.Table_Name, atts);
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,

View File

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

View File

@ -34,6 +34,7 @@ import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.DatabaseAccessException;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Window;
import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail;
import org.compiere.model.MWindow;
@ -60,43 +61,53 @@ public class WindowElementHandler extends AbstractElementHandler implements IPac
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
String name = getStringValue(element, "Name", excludes);
int id = findIdByName(ctx, "AD_Window", name);
if (id > 0 && windows.contains(id)) {
return;
}
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Window.Table_Name,
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";
MWindow mWindow = findPO(ctx, element);
if (mWindow == null) {
String name = getStringValue(element, "Name", excludes);
int id = findIdByName(ctx, "AD_Window", name);
if (id > 0 && windows.contains(id)) {
return;
}
mWindow = new MWindow(ctx, id > 0 ? id : 0, getTrxName(ctx));
mWindow.setName(name);
} else {
action = "New";
if (windows.contains(mWindow.getAD_Window_ID())) {
return;
}
}
mWindow.setName(name);
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);
excludes.add("Name");
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mWindow.save(getTrxName(ctx)) == true) {
logImportDetail(ctx, impDetail, 1, mWindow.getName(), mWindow
.get_ID(), action);
element.recordId = mWindow.getAD_Window_ID();
windows.add(mWindow.getAD_Window_ID());
} else {
logImportDetail(ctx, impDetail, 0, mWindow.getName(), mWindow
.get_ID(), action);
throw new POSaveFailedException("Window");
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) {
logImportDetail(ctx, impDetail, 1, mWindow.getName(), mWindow
.get_ID(), action);
element.recordId = mWindow.getAD_Window_ID();
windows.add(mWindow.getAD_Window_ID());
} else {
logImportDetail(ctx, impDetail, 0, mWindow.getName(), mWindow
.get_ID(), action);
throw new POSaveFailedException("Window");
}
}
} else {
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);
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.window");
document.startElement("", "", "window", atts);
addTypeName(atts, "ad.window");
document.startElement("", "", I_AD_Window.Table_Name, atts);
createWindowBinding(ctx, document, m_Window);
// Tab Tag
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
// Loop tags.
document.endElement("", "", "window");
document.endElement("", "", I_AD_Window.Table_Name);
// Preference Tag
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.Element;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.compiere.model.I_AD_Role;
import org.compiere.model.I_AD_Workflow_Access;
import org.compiere.model.Query;
import org.compiere.model.X_AD_Role;
import org.compiere.model.X_AD_Workflow;
import org.compiere.model.X_AD_Workflow_Access;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -41,24 +43,27 @@ public class WorkflowAccessElementHandler extends AbstractElementHandler {
int workflowid =0;
List<String> excludes = defaultExcludeList(X_AD_Workflow_Access.Table_Name);
String roleName = getStringValue(element, "AD_Role.Name", excludes);
if (getParentId(element, "role") > 0) {
roleid = getParentId(element, "role");
} 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));
}
String workflowValue = getStringValue(element, "AD_Workflow.Value", excludes);
if (workflowValue != null && workflowValue.trim().length() > 0)
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));
po = query.setParameters(new Object[]{roleid, workflowid}).first();
X_AD_Workflow_Access po = findPO(ctx, element);
if (po == null) {
po = new X_AD_Workflow_Access(ctx, 0, getTrxName(ctx));
po.setAD_Role_ID(roleid);
po.setAD_Workflow_ID(workflowid);
if (getParentId(element, I_AD_Role.Table_Name) > 0) {
roleid = getParentId(element, I_AD_Role.Table_Name);
} else {
Element roleElement = element.properties.get(I_AD_Workflow_Access.COLUMNNAME_AD_Role_ID);
roleid = ReferenceUtils.resolveReference(ctx, roleElement);
}
Element wfElement = element.properties.get(I_AD_Workflow_Access.COLUMNNAME_AD_Workflow_ID);
workflowid = ReferenceUtils.resolveReference(ctx, wfElement);
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();
if (po == null) {
po = new X_AD_Workflow_Access(ctx, 0, getTrxName(ctx));
po.setAD_Role_ID(roleid);
po.setAD_Workflow_ID(workflowid);
}
excludes.add(I_AD_Workflow_Access.COLUMNNAME_AD_Role_ID);
excludes.add(I_AD_Workflow_Access.COLUMNNAME_AD_Workflow_ID);
}
PoFiller filler = new PoFiller(ctx, po, element, this);
@ -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_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID);
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.workflow-access");
document.startElement("", "", "workflowAccess", atts);
addTypeName(atts, "ad.workflow-access");
document.startElement("", "", I_AD_Workflow_Access.Table_Name, atts);
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,

View File

@ -32,6 +32,7 @@ import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_Workflow;
import org.compiere.model.MPackageExp;
import org.compiere.model.MPackageExpDetail;
import org.compiere.model.X_AD_Package_Exp_Detail;
@ -61,45 +62,51 @@ public class WorkflowElementHandler extends AbstractElementHandler implements IP
String entitytype = getStringValue(element, "EntityType");
if (isProcessElement(ctx, entitytype)) {
String workflowValue = getStringValue(element, "Value", excludes);
int id = findIdByColumn(ctx, "AD_Workflow", "Value", workflowValue);
if (id > 0 && workflows.contains(id)) {
element.skip = true;
return;
MWorkflow mWorkflow = findPO(ctx, element);
if (mWorkflow == null) {
String workflowValue = getStringValue(element, "Value", excludes);
int id = findIdByColumn(ctx, "AD_Workflow", "Value", workflowValue);
if (id > 0 && workflows.contains(id)) {
element.skip = true;
return;
}
mWorkflow = new MWorkflow(ctx, id > 0 ? id : 0, getTrxName(ctx));
mWorkflow.setValue(workflowValue);
}
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Workflow.Table_Name,
X_AD_Workflow.Table_ID);
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"))
if (mWorkflow.getAD_Workflow_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);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mWorkflow.save(getTrxName(ctx)) == true) {
log.info("m_Workflow save success");
logImportDetail(ctx,impDetail, 1, mWorkflow.getName(), mWorkflow
.get_ID(), action);
workflows.add(mWorkflow.getAD_Workflow_ID());
element.recordId = mWorkflow.getAD_Workflow_ID();
} else {
log.info("m_Workflow save failure");
logImportDetail(ctx, impDetail, 0, mWorkflow.getName(), mWorkflow
.get_ID(), action);
throw new POSaveFailedException("MWorkflow");
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) {
log.info("m_Workflow save success");
logImportDetail(ctx,impDetail, 1, mWorkflow.getName(), mWorkflow
.get_ID(), action);
workflows.add(mWorkflow.getAD_Workflow_ID());
element.recordId = mWorkflow.getAD_Workflow_ID();
} else {
log.info("m_Workflow save failure");
logImportDetail(ctx, impDetail, 0, mWorkflow.getName(), mWorkflow
.get_ID(), action);
throw new POSaveFailedException("MWorkflow");
}
}
} else {
element.skip = true;
@ -160,7 +167,7 @@ public class WorkflowElementHandler extends AbstractElementHandler implements IP
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.workflow");
document.startElement("", "", "workflow", atts);
document.startElement("", "", I_AD_Workflow.Table_Name, atts);
createWorkflowBinding(ctx, document, m_Workflow);
String sql = "SELECT AD_WF_Node_ID FROM AD_WF_Node WHERE AD_Workflow_ID = "
+ AD_Workflow_ID;
@ -197,7 +204,7 @@ public class WorkflowElementHandler extends AbstractElementHandler implements IP
throw new DBException(e);
} finally {
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.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_WF_Node;
import org.compiere.model.I_AD_Workflow;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_WF_Node;
import org.compiere.util.DB;
@ -47,62 +50,68 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler {
element.skip = true;
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.defer = true;
return;
}
int workflowId = 0;
String workflowValue = getStringValue(element, "AD_Workflow.Value", excludes);
if (getParentId(element, "workflow") > 0) {
workflowId = getParentId(element, "workflow");
} else {
workflowId = findIdByColumn(ctx, "AD_Workflow", "Value", workflowValue);
X_AD_WF_Node mWFNode = findPO(ctx, element);
if (mWFNode == null) {
int workflowId = 0;
Element wfElement = element.properties.get(I_AD_WF_Node.COLUMNNAME_AD_Workflow_ID);
if (getParentId(element, I_AD_Workflow.Table_Name) > 0) {
workflowId = getParentId(element, I_AD_Workflow.Table_Name);
} else {
workflowId = ReferenceUtils.resolveReference(ctx, wfElement);
}
if (workflowId <= 0) {
element.defer = true;
element.unresolved = "AD_Workflow: " + wfElement.contents;
return;
}
String workflowNodeValue = getStringValue(element, "Value", excludes);
StringBuffer sqlB = new StringBuffer(
"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);
mWFNode = new X_AD_WF_Node(ctx, id > 0 ? id : 0, getTrxName(ctx));
mWFNode.setValue(workflowNodeValue);
mWFNode.setAD_Workflow_ID(workflowId);
excludes.add(I_AD_WF_Node.COLUMNNAME_AD_Workflow_ID);
excludes.add("Value");
}
if (workflowId <= 0) {
element.defer = true;
element.unresolved = "AD_Workflow: " + workflowValue;
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);
StringBuffer sqlB = new StringBuffer(
"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);
X_AD_WF_Node mWFNode = new X_AD_WF_Node(ctx, id, getTrxName(ctx));
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);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (mWFNode.save(getTrxName(ctx)) == true) {
log.info("m_WFNode save success");
logImportDetail(ctx, impDetail, 1, mWFNode.getName(), mWFNode
.get_ID(), action);
} else {
log.info("m_WFNode save failure");
logImportDetail(ctx, impDetail, 0, mWFNode.getName(), mWFNode
.get_ID(), action);
throw new POSaveFailedException("WorkflowNode");
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) {
log.info("m_WFNode save success");
logImportDetail(ctx, impDetail, 1, mWFNode.getName(), mWFNode
.get_ID(), action);
} else {
log.info("m_WFNode save failure");
logImportDetail(ctx, impDetail, 0, mWFNode.getName(), mWFNode
.get_ID(), action);
throw new POSaveFailedException("WorkflowNode");
}
}
} else {
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,
getTrxName(ctx));
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.workflow.node");
document.startElement("", "", "workflowNode", atts);
addTypeName(atts, "ad.workflow.node");
document.startElement("", "", I_AD_WF_Node.Table_Name, atts);
createWorkflowNodeBinding(ctx, document, m_WF_Node);
document.endElement("", "", "workflowNode");
document.endElement("", "", I_AD_WF_Node.Table_Name);
}
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.PackOut;
import org.adempiere.pipo2.PoFiller;
import org.adempiere.pipo2.ReferenceUtils;
import org.adempiere.pipo2.exception.POSaveFailedException;
import org.compiere.model.I_AD_WF_NextCondition;
import org.compiere.model.I_AD_Workflow;
import org.compiere.model.X_AD_Package_Imp_Detail;
import org.compiere.model.X_AD_WF_NextCondition;
import org.compiere.util.DB;
@ -49,96 +52,105 @@ public class WorkflowNodeNextConditionElementHandler extends
return;
}
int workflowId = 0;
String workflowValue = getStringValue(element, "AD_Workflow.Value", excludes);
if (getParentId(element, "workflow") > 0) {
workflowId = getParentId(element, "workflow");
} else {
workflowId = findIdByColumn(ctx, "AD_Workflow", "Value", workflowValue);
MWFNextCondition mWFNodeNextCondition = findPO(ctx, element);
if (mWFNodeNextCondition == null) {
int workflowId = 0;
Element wfElement = element.properties.get("AD_Workflow_ID");
if (getParentId(element, I_AD_Workflow.Table_Name) > 0) {
workflowId = getParentId(element, I_AD_Workflow.Table_Name);
} else {
workflowId = ReferenceUtils.resolveReference(ctx, wfElement);
}
if (workflowId <= 0) {
element.defer = true;
element.unresolved = "AD_Workflow: " + wfElement.contents;
return;
}
int AD_WF_NodeNext_ID = 0;
Element nodeNextElement = element.properties.get(I_AD_WF_NextCondition.COLUMNNAME_AD_WF_NodeNext_ID);
if (ReferenceUtils.isIDLookup(nodeNextElement) || ReferenceUtils.isUUIDLookup(nodeNextElement)) {
AD_WF_NodeNext_ID = ReferenceUtils.resolveReference(ctx, nodeNextElement);
} else {
Element wfnElement = element.properties.get("AD_WF_Node_ID");
int wfNodeId = ReferenceUtils.resolveReference(ctx, wfnElement);
if (wfNodeId <= 0) {
element.unresolved = "AD_WF_Node=" + wfnElement.contents;
element.defer = true;
return;
}
Element nextElement = element.properties.get("AD_WF_Next_ID");
int wfNodeNextId = ReferenceUtils.resolveReference(ctx, nextElement);
if (wfNodeNextId <= 0) {
element.unresolved = "AD_WF_Node=" + nextElement.contents;
element.defer = true;
return;
}
String sql = "SELECT AD_WF_NodeNext_ID FROM AD_WF_NodeNext WHERE AD_WF_Node_ID =? and AD_WF_Next_ID =?";
AD_WF_NodeNext_ID = DB.getSQLValue(getTrxName(ctx), sql, wfNodeId, wfNodeNextId);
}
String 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);
mWFNodeNextCondition = new MWFNextCondition(ctx, id > 0 ? id : 0, getTrxName(ctx));
mWFNodeNextCondition.setAD_WF_NodeNext_ID(AD_WF_NodeNext_ID);
}
if (workflowId <= 0) {
element.defer = true;
element.unresolved = "AD_Workflow: " + workflowValue;
return;
}
String workflowNodeValue = getStringValue(element, "AD_WF_Node.Value", excludes);
String workflowNodeNextValue = getStringValue(element, "AD_WF_Next_ID.AD_WF_Node.Value", excludes);
String sql = "SELECT AD_WF_Node_ID FROM AD_WF_Node WHERE AD_Workflow_ID=? AND Value=? AND AD_Client_ID=?";
int wfNodeId = DB.getSQLValue(getTrxName(ctx), sql,
workflowId, workflowNodeValue, Env.getAD_Client_ID(ctx));
if (wfNodeId <= 0) {
element.unresolved = "AD_WF_Node=" + workflowNodeValue;
element.defer = true;
return;
}
int wfNodeNextId = DB.getSQLValue(getTrxName(ctx), sql,
workflowId, workflowNodeNextValue, Env.getAD_Client_ID(ctx));
if (wfNodeNextId <= 0) {
element.unresolved = "AD_WF_Node=" + workflowNodeNextValue;
element.defer = true;
return;
}
X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_WF_NextCondition.Table_Name,
X_AD_WF_NextCondition.Table_ID);
sql = "SELECT AD_WF_NodeNext_ID FROM AD_WF_NodeNext WHERE AD_WF_Node_ID =? and AD_WF_Next_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);
MWFNextCondition m_WFNodeNextCondition = new MWFNextCondition(ctx,
id, getTrxName(ctx));
PoFiller filler = new PoFiller(ctx, m_WFNodeNextCondition, element, this);
String Object_Status = null;
if (id <= 0 && isOfficialId(element, "AD_WF_NextCondition_ID"))
PoFiller filler = new PoFiller(ctx, mWFNodeNextCondition, element, this);
if (mWFNodeNextCondition.get_ID() == 0 && isOfficialId(element, "AD_WF_NextCondition_ID"))
filler.setInteger("AD_WF_NextCondition_ID");
if (id > 0) {
backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_WF_NextCondition.Table_Name,
m_WFNodeNextCondition);
Object_Status = "Update";
Element tableElement = element.properties.get("AD_Table_ID");
Element columnElement = element.properties.get("AD_Column_ID");
int columnId = 0;
if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) {
columnId = ReferenceUtils.resolveReference(ctx, columnElement);
} else {
Object_Status = "New";
int AD_Table_ID = ReferenceUtils.resolveReference(ctx, tableElement);
columnId = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnElement.contents.toString(), "AD_Table", AD_Table_ID);
}
String tableName = getStringValue(element, "AD_Table.TableName", excludes);
String columnName = getStringValue(element, "AD_Column.ColumnName", excludes);
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 = ?"
+ " and AD_Column.ColumnName = ?";
int columnId = DB.getSQLValue(getTrxName(ctx), sql, tableName, columnName);
m_WFNodeNextCondition.setAD_Column_ID(columnId);
m_WFNodeNextCondition.setAD_WF_NodeNext_ID(AD_WF_NodeNext_ID);
mWFNodeNextCondition.setAD_Column_ID(columnId);
List<String> notfounds = filler.autoFill(excludes);
if (notfounds.size() > 0) {
element.defer = true;
return;
}
if (m_WFNodeNextCondition.save(getTrxName(ctx)) == true) {
log.info("m_WFNodeNextCondition save success");
logImportDetail(
ctx,
impDetail,
1,
String.valueOf(m_WFNodeNextCondition.get_ID()),
m_WFNodeNextCondition.get_ID(),
Object_Status);
} else {
log.info("m_WFNodeNextCondition save failure");
logImportDetail(
ctx,
impDetail,
0,
String.valueOf(m_WFNodeNextCondition.get_ID()),
m_WFNodeNextCondition.get_ID(),
Object_Status);
throw new POSaveFailedException("WorkflowNodeNextCondition");
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");
logImportDetail(
ctx,
impDetail,
1,
String.valueOf(mWFNodeNextCondition.get_ID()),
mWFNodeNextCondition.get_ID(),
action);
} else {
log.info("m_WFNodeNextCondition save failure");
logImportDetail(
ctx,
impDetail,
0,
String.valueOf(mWFNodeNextCondition.get_ID()),
mWFNodeNextCondition.get_ID(),
action);
throw new POSaveFailedException("WorkflowNodeNextCondition");
}
}
} else {
element.skip = true;
@ -155,47 +167,40 @@ public class WorkflowNodeNextConditionElementHandler extends
X_AD_WF_NextCondition m_WF_NodeNextCondition = new X_AD_WF_NextCondition(
ctx, ad_wf_nodenextcondition_id, null);
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "", "type", "CDATA", "object");
atts.addAttribute("", "", "type-name", "CDATA", "ad.workflow.node.next-condition");
document.startElement("", "", "workflowNodeNextCondition", atts);
addTypeName(atts, "ad.workflow.node.next-condition");
document.startElement("", "", I_AD_WF_NextCondition.Table_Name, atts);
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) {
PoExporter filler = new PoExporter(ctx, document, m_WF_NodeNextCondition);
private void createWorkflowNodeNextConditionBinding(Properties ctx, TransformerHandler document, X_AD_WF_NextCondition mWFNodeNextCondition) {
PoExporter filler = new PoExporter(ctx, document, mWFNodeNextCondition);
List<String> excludes = defaultExcludeList(X_AD_WF_NextCondition.Table_Name);
String sql = null;
String name = null;
if (m_WF_NodeNextCondition.getAD_WF_NextCondition_ID() <= PackOut.MAX_OFFICIAL_ID)
if (mWFNodeNextCondition.getAD_WF_NextCondition_ID() <= PackOut.MAX_OFFICIAL_ID)
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 = ? ";
name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition
.getAD_WF_NodeNext_ID());
filler.addString("AD_Workflow.Value", name, new AttributesImpl());
int AD_workflow_ID = mWFNodeNextCondition.getAD_WF_NodeNext().getAD_WF_Node().getAD_Workflow_ID();
AttributesImpl wfAttributes = new AttributesImpl();
String value = ReferenceUtils.getTableReference("AD_Workflow", "Value", AD_workflow_ID, wfAttributes);
filler.addString("AD_Workflow_ID", value, wfAttributes);
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 = ? ";
name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition
.getAD_WF_NodeNext_ID());
filler.addString("AD_WF_Node.Value", name, new AttributesImpl());
int AD_WF_Node_ID = mWFNodeNextCondition.getAD_WF_NodeNext().getAD_WF_Node_ID();
AttributesImpl wfnAttributes = new AttributesImpl();
value = ReferenceUtils.getTableReference("AD_WF_Node", "Value", AD_WF_Node_ID, wfnAttributes);
filler.addString("AD_WF_Node_ID", value, wfnAttributes);
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";
name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition
.getAD_WF_NodeNext_ID());
filler.addString("AD_WF_Next_ID.AD_WF_Node.Value", name, new AttributesImpl());
int AD_WF_Next_ID = mWFNodeNextCondition.getAD_WF_NodeNext().getAD_WF_Next_ID();
AttributesImpl nextAttributes = new AttributesImpl();
value = ReferenceUtils.getTableReference("AD_WF_Node", "Value", AD_WF_Next_ID, nextAttributes);
filler.addString("AD_WF_Next_ID", value, nextAttributes);
if (m_WF_NodeNextCondition.getAD_Column_ID() > 0) {
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 = ?";
name = DB.getSQLValueString(null, sql, m_WF_NodeNextCondition
.getAD_Column_ID());
filler.addString("AD_Table.TableName", name, new AttributesImpl());
} else {
filler.add("AD_Table.TableName","", new AttributesImpl());
}
excludes.add("AD_WF_NodeNext_ID");
if (mWFNodeNextCondition.getAD_Column_ID() > 0) {
int AD_Table_ID = mWFNodeNextCondition.getAD_Column().getAD_Table_ID();
AttributesImpl tableAttributes = new AttributesImpl();
value = ReferenceUtils.getTableReference("AD_Table", "TableName", AD_Table_ID, tableAttributes);
filler.addString("AD_Table_ID", value, tableAttributes);
}
filler.export(excludes);
}

View File

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