diff --git a/org.adempiere.base/src/org/compiere/model/PO.java b/org.adempiere.base/src/org/compiere/model/PO.java index 7e08c57cd3..572cdcd177 100644 --- a/org.adempiere.base/src/org/compiere/model/PO.java +++ b/org.adempiere.base/src/org/compiere/model/PO.java @@ -863,7 +863,7 @@ public abstract class PO * @param value value * @return true if value set */ - protected final boolean set_ValueNoCheck (String ColumnName, Object value) + public final boolean set_ValueNoCheck (String ColumnName, Object value) { int index = get_ColumnIndex(ColumnName); if (index < 0) diff --git a/org.adempiere.pipo.handlers/plugin.xml b/org.adempiere.pipo.handlers/plugin.xml index 0286b73627..dfe05878c0 100644 --- a/org.adempiere.pipo.handlers/plugin.xml +++ b/org.adempiere.pipo.handlers/plugin.xml @@ -164,6 +164,10 @@ class="org.adempiere.pipo2.handler.ReferenceTableElementHandler" id="AD_Ref_Table"> + + diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/AdElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/AdElementHandler.java index 612ae824a0..3b77579416 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/AdElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/AdElementHandler.java @@ -19,11 +19,11 @@ package org.adempiere.pipo2.handler; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -44,19 +44,19 @@ public class AdElementHandler extends AbstractElementHandler { private final String AD_ELEMENT = "AD_Element"; - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { String action = null; String entitytype = getStringValue(element, "EntityType"); String ColumnName = getStringValue(element, "ColumnName"); - if (isProcessElement(ctx, entitytype)) { - + if (isProcessElement(ctx.ctx, entitytype)) { + 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)); + int id = findIdByColumn(ctx, X_AD_Element.Table_Name, X_AD_Element.COLUMNNAME_ColumnName, ColumnName, /*ignorecase=*/true); + mElement = new M_Element(ctx.ctx, id, getTrxName(ctx)); } List excludes = defaultExcludeList(X_AD_Element.Table_Name); if (mElement.getAD_Element_ID() == 0 && isOfficialId(element, "AD_Element_ID")) @@ -71,6 +71,7 @@ public class AdElementHandler extends AbstractElementHandler { List notfounds = pf.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -94,7 +95,7 @@ public class AdElementHandler extends AbstractElementHandler { } else { logImportDetail(ctx, impDetail, 0, mElement.getName(), mElement.get_ID(), action); - throw new POSaveFailedException("Reference"); + throw new POSaveFailedException("Failed to save Element " + mElement.getName()); } } } else { @@ -102,14 +103,14 @@ public class AdElementHandler extends AbstractElementHandler { } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - protected void create(Properties ctx, TransformerHandler document) + protected void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int adElement_id = Env.getContextAsInt(ctx, + int adElement_id = Env.getContextAsInt(ctx.ctx, X_AD_Element.COLUMNNAME_AD_Element_ID); if (processedElements.contains(adElement_id)) @@ -117,18 +118,22 @@ public class AdElementHandler extends AbstractElementHandler { processedElements.add(adElement_id); - X_AD_Element m_AdElement = new X_AD_Element(ctx, adElement_id, null); + X_AD_Element mAdElement = new X_AD_Element(ctx.ctx, adElement_id, null); + + if (ctx.packOut.getFromDate() != null) { + if (mAdElement.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } AttributesImpl atts = new AttributesImpl(); addTypeName(atts, "table"); document.startElement("", "", "AD_Element", atts); - createAdElementBinding(ctx, document, m_AdElement); - - PackOut packOut = (PackOut)ctx.get("PackOutProcess"); - + createAdElementBinding(ctx, document, mAdElement); + PackOut packOut = ctx.packOut; try{ - new CommonTranslationHandler().packOut(packOut,document,null,m_AdElement.get_ID()); + new CommonTranslationHandler().packOut(packOut,document,null,mAdElement.get_ID()); } catch(Exception e) { @@ -139,7 +144,7 @@ public class AdElementHandler extends AbstractElementHandler { } - private void createAdElementBinding(Properties ctx, TransformerHandler document, + private void createAdElementBinding(PIPOContext ctx, TransformerHandler document, X_AD_Element m_AdElement) { PoExporter filler = new PoExporter(ctx, document, m_AdElement); @@ -152,8 +157,8 @@ public class AdElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception { - Env.setContext(packout.getCtx(), X_AD_Element.COLUMNNAME_AD_Element_ID, recordId); + Env.setContext(packout.getCtx().ctx, X_AD_Element.COLUMNNAME_AD_Element_ID, recordId); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(X_AD_Element.COLUMNNAME_AD_Element_ID); + packout.getCtx().ctx.remove(X_AD_Element.COLUMNNAME_AD_Element_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/AttachmentElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/AttachmentElementHandler.java new file mode 100644 index 0000000000..0246aceb10 --- /dev/null +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/AttachmentElementHandler.java @@ -0,0 +1,178 @@ +/****************************************************************************** + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + * + * Copyright (C) 2005 Robert Klein. robeklein@hotmail.com + * Contributor(s): Low Heng Sin hengsin@avantz.com + *****************************************************************************/ +package org.adempiere.pipo2.handler; + + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.Element; +import org.adempiere.pipo2.ElementHandler; +import org.adempiere.pipo2.PIPOContext; +import org.adempiere.pipo2.PackOut; +import org.adempiere.pipo2.PoExporter; +import org.adempiere.pipo2.PoFiller; +import org.adempiere.pipo2.ReferenceUtils; +import org.adempiere.pipo2.exception.POSaveFailedException; +import org.compiere.model.MAttachment; +import org.compiere.model.PO; +import org.compiere.model.X_AD_Attachment; +import org.compiere.model.X_AD_AttachmentNote; +import org.compiere.model.X_AD_Package_Imp_Detail; +import org.compiere.util.DB; +import org.compiere.util.Env; + +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +public class AttachmentElementHandler extends AbstractElementHandler { + + private List attachments = new ArrayList(); + + public void startElement(PIPOContext ctx, Element element) + throws SAXException { + String action = null; + + MAttachment mAttachment = findPO(ctx, element); + if (mAttachment == null) { + int AD_Table_ID = ReferenceUtils.resolveReference(ctx.ctx, element.properties.get("AD_Table_ID"), getTrxName(ctx)); + if (AD_Table_ID <= 0) { + element.defer = true; + element.unresolved = "AD_Table_ID"; + return; + } + Element recordElement = element.properties.get("Record_ID"); + int Record_ID = ReferenceUtils.resolveReference(ctx.ctx, recordElement, getTrxName(ctx)); + if (Record_ID <= 0) { + element.defer = true; + element.unresolved = "Record_ID"; + return; + } + + int id = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Attachment_ID FROM AD_Attachment WHERE Record_ID="+Record_ID+" AND AD_Table_ID="+AD_Table_ID); + mAttachment = new MAttachment(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); + if (mAttachment.is_new()) { + mAttachment.setAD_Table_ID(AD_Table_ID); + mAttachment.setRecord_ID(Record_ID); + } + } + List excludes = defaultExcludeList(X_AD_Attachment.Table_Name); + excludes.add("AD_Table_ID"); + excludes.add("Record_ID"); + if (mAttachment.getAD_Attachment_ID() == 0 && isOfficialId(element, "AD_Attachment_ID")) + mAttachment.setAD_Attachment_ID(getIntValue(element, "AD_Attachment_ID")); + + if (attachments.contains(mAttachment.getAD_Attachment_ID())) { + element.skip = true; + return; + } + + PoFiller pf = new PoFiller(ctx, mAttachment, element, this); + List notfounds = pf.autoFill(excludes); + if (notfounds.size() > 0) { + element.defer = true; + element.unresolved = notfounds.toString(); + return; + } + + mAttachment.getEntries(); + if (mAttachment.is_new() || mAttachment.is_Changed()) { + X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Attachment.Table_Name, X_AD_Attachment.Table_ID); + if (!mAttachment.is_new()) { + backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Attachment.Table_Name, mAttachment); + action = "Update"; + } else { + action = "New"; + } + + if (mAttachment.save(getTrxName(ctx)) == true) { + logImportDetail(ctx, impDetail, 1, mAttachment.toString(), + mAttachment.get_ID(), action); + + element.recordId = mAttachment.getAD_Attachment_ID(); + + attachments.add(mAttachment.getAD_Attachment_ID()); + + } else { + logImportDetail(ctx, impDetail, 0, mAttachment.toString(), + mAttachment.get_ID(), action); + throw new POSaveFailedException("Failed to save Attachment " + mAttachment.toString()); + } + } + } + + public void endElement(PIPOContext ctx, Element element) throws SAXException { + } + + protected void create(PIPOContext ctx, TransformerHandler document) + throws SAXException { + + + int AD_Attachment_ID = Env.getContextAsInt(ctx.ctx, "AD_Attachment_ID"); + + if (attachments.contains(AD_Attachment_ID)) + return; + + attachments.add(AD_Attachment_ID); + + MAttachment mAttachment = new MAttachment(ctx.ctx, AD_Attachment_ID, getTrxName(ctx)); + + if (ctx.packOut.getFromDate() != null) { + if (mAttachment.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } + + AttributesImpl atts = new AttributesImpl(); + addTypeName(atts, "table"); + document.startElement("", "", "AD_Attachment", atts); + createAttachmentBinding(ctx, document, mAttachment); + + int[] ids = PO.getAllIDs(X_AD_AttachmentNote.Table_Name, "AD_Attachment_ID="+AD_Attachment_ID, getTrxName(ctx)); + if (ids != null && ids.length > 0) { + ElementHandler handler = ctx.packOut.getHandler(X_AD_AttachmentNote.Table_Name); + for (int AD_AttachmentNote_ID : ids ) { + try { + handler.packOut(ctx.packOut, document, null, AD_AttachmentNote_ID); + } catch (Exception e) { + throw new SAXException(e); + } + } + } + document.endElement("", "", "AD_Attachment"); + } + + + private void createAttachmentBinding(PIPOContext ctx, TransformerHandler document, + MAttachment mAttachment) { + + PoExporter filler = new PoExporter(ctx, document, mAttachment); + if (mAttachment.getAD_Attachment_ID() <= PackOut.MAX_OFFICIAL_ID) + filler.add("AD_Attachment_ID", new AttributesImpl()); + + List excludes = defaultExcludeList(X_AD_Attachment.Table_Name); + filler.export(excludes); + } + + public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception + { + packout.getCtx().ctx.put("AD_Attachment_ID", recordId); + this.create(packout.getCtx(), packoutHandler); + packout.getCtx().ctx.remove("AD_Attachment_ID"); + } +} diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/CodeSnippetElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/CodeSnippetElementHandler.java index 182cb72e5e..dd6cbc1697 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/CodeSnippetElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/CodeSnippetElementHandler.java @@ -28,7 +28,6 @@ import java.io.OutputStream; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; @@ -44,12 +43,13 @@ import org.xml.sax.helpers.AttributesImpl; import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.CodeSnippetElementParameters; import org.adempiere.pipo2.Element; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackoutItem; public class CodeSnippetElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) throws SAXException { + public void startElement(PIPOContext ctx, Element element) throws SAXException { String action = null; action = "Update"; String releaseNumber = getStringValue(element, "ReleaseNo"); @@ -68,7 +68,7 @@ public class CodeSnippetElementHandler extends AbstractElementHandler { //get adempiere-all directory try { - packagePath = getPackageDirectory(ctx); + packagePath = getPackageDirectory(ctx.ctx); File parentDirectory = new File(packagePath); while (!parentDirectory.getName().equals("packages")){ parentDirectory = parentDirectory.getParentFile(); @@ -144,9 +144,9 @@ public class CodeSnippetElementHandler extends AbstractElementHandler { } //Record in transaction file - X_AD_Package_Imp_Backup backup = new X_AD_Package_Imp_Backup(ctx, 0, getTrxName(ctx)); - backup.setAD_Org_ID(Env.getAD_Org_ID(ctx)); - backup.setAD_Package_Imp_ID(getPackageImpId(ctx)); + X_AD_Package_Imp_Backup backup = new X_AD_Package_Imp_Backup(ctx.ctx, 0, getTrxName(ctx)); + backup.setAD_Org_ID(Env.getAD_Org_ID(ctx.ctx)); + backup.setAD_Package_Imp_ID(getPackageImpId(ctx.ctx)); backup.setAD_Package_Imp_Org_Dir(targetDirectoryModified+sourceName ); backup.setAD_Package_Imp_Bck_Dir(packagePath+File.separator+"backup"+File.separator+fileDate+"_"+sourceName); backup.saveEx(); @@ -189,18 +189,18 @@ public class CodeSnippetElementHandler extends AbstractElementHandler { } - public void endElement(Properties ctx, Element element) + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext pipoContext, TransformerHandler document) throws SAXException { - String FileDir = Env.getContext(ctx, CodeSnippetElementParameters.DESTINATION_DIRECTORY); - String FileName = Env.getContext(ctx, CodeSnippetElementParameters.DESTINATION_FILE_NAME); - String OldCode = Env.getContext(ctx, CodeSnippetElementParameters.AD_Package_Code_Old); - String NewCode = Env.getContext(ctx, CodeSnippetElementParameters.AD_Package_Code_New); - String ReleaseNo = Env.getContext(ctx, CodeSnippetElementParameters.RELEASE_NO); + String FileDir = Env.getContext(pipoContext.ctx, CodeSnippetElementParameters.DESTINATION_DIRECTORY); + String FileName = Env.getContext(pipoContext.ctx, CodeSnippetElementParameters.DESTINATION_FILE_NAME); + String OldCode = Env.getContext(pipoContext.ctx, CodeSnippetElementParameters.AD_Package_Code_Old); + String NewCode = Env.getContext(pipoContext.ctx, CodeSnippetElementParameters.AD_Package_Code_New); + String ReleaseNo = Env.getContext(pipoContext.ctx, CodeSnippetElementParameters.RELEASE_NO); AttributesImpl atts = new AttributesImpl(); addTypeName(atts, "custom"); createSnipitBinding(atts, FileDir, FileName, OldCode, NewCode, ReleaseNo); @@ -232,16 +232,16 @@ public class CodeSnippetElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception { PackoutItem detail = packout.getCurrentPackoutItem(); - Env.setContext(packout.getCtx(), CodeSnippetElementParameters.DESTINATION_DIRECTORY, (String)detail.getProperty(CodeSnippetElementParameters.DESTINATION_DIRECTORY)); - Env.setContext(packout.getCtx(), CodeSnippetElementParameters.DESTINATION_FILE_NAME, (String)detail.getProperty(CodeSnippetElementParameters.DESTINATION_FILE_NAME)); - Env.setContext(packout.getCtx(), CodeSnippetElementParameters.AD_Package_Code_Old, (String)detail.getProperty(CodeSnippetElementParameters.AD_Package_Code_Old)); - Env.setContext(packout.getCtx(), CodeSnippetElementParameters.AD_Package_Code_New, (String)detail.getProperty(CodeSnippetElementParameters.AD_Package_Code_New)); - Env.setContext(packout.getCtx(), CodeSnippetElementParameters.RELEASE_NO, (String)detail.getProperty(CodeSnippetElementParameters.RELEASE_NO)); + Env.setContext(packout.getCtx().ctx, CodeSnippetElementParameters.DESTINATION_DIRECTORY, (String)detail.getProperty(CodeSnippetElementParameters.DESTINATION_DIRECTORY)); + Env.setContext(packout.getCtx().ctx, CodeSnippetElementParameters.DESTINATION_FILE_NAME, (String)detail.getProperty(CodeSnippetElementParameters.DESTINATION_FILE_NAME)); + Env.setContext(packout.getCtx().ctx, CodeSnippetElementParameters.AD_Package_Code_Old, (String)detail.getProperty(CodeSnippetElementParameters.AD_Package_Code_Old)); + Env.setContext(packout.getCtx().ctx, CodeSnippetElementParameters.AD_Package_Code_New, (String)detail.getProperty(CodeSnippetElementParameters.AD_Package_Code_New)); + Env.setContext(packout.getCtx().ctx, CodeSnippetElementParameters.RELEASE_NO, (String)detail.getProperty(CodeSnippetElementParameters.RELEASE_NO)); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(CodeSnippetElementParameters.DESTINATION_DIRECTORY); - packout.getCtx().remove(CodeSnippetElementParameters.DESTINATION_FILE_NAME); - packout.getCtx().remove(CodeSnippetElementParameters.AD_Package_Code_Old); - packout.getCtx().remove(CodeSnippetElementParameters.AD_Package_Code_New); - packout.getCtx().remove(CodeSnippetElementParameters.RELEASE_NO); + packout.getCtx().ctx.remove(CodeSnippetElementParameters.DESTINATION_DIRECTORY); + packout.getCtx().ctx.remove(CodeSnippetElementParameters.DESTINATION_FILE_NAME); + packout.getCtx().ctx.remove(CodeSnippetElementParameters.AD_Package_Code_Old); + packout.getCtx().ctx.remove(CodeSnippetElementParameters.AD_Package_Code_New); + packout.getCtx().ctx.remove(CodeSnippetElementParameters.RELEASE_NO); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ColumnElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ColumnElementHandler.java index 5b52b0dfeb..f0d5a530b3 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ColumnElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ColumnElementHandler.java @@ -21,12 +21,12 @@ import java.sql.DatabaseMetaData; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; -import java.util.Properties; import java.util.logging.Level; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -49,11 +49,11 @@ import org.xml.sax.helpers.AttributesImpl; public class ColumnElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { int success = 0; String entitytype = getStringValue(element, "EntityType"); - if (isProcessElement(ctx, entitytype)) { + if (isProcessElement(ctx.ctx, entitytype)) { if (isParentDefer(element, I_AD_Table.Table_Name)) { element.defer = true; return; @@ -68,13 +68,13 @@ public class ColumnElementHandler extends AbstractElementHandler { if (getParentId(element, I_AD_Table.Table_Name) > 0) { tableid = getParentId(element, I_AD_Table.Table_Name); } else { - mColumn = new MColumn(ctx, 0, getTrxName(ctx)); + mColumn = new MColumn(ctx.ctx, 0, getTrxName(ctx)); PoFiller filler = new PoFiller(ctx, mColumn, element, this); filler.setTableReference("AD_Table_ID"); tableid = mColumn.getAD_Table_ID(); } - int AD_Column_ID = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnName, "AD_Table", tableid); - mColumn = new MColumn(ctx, AD_Column_ID > 0 ? AD_Column_ID : 0, getTrxName(ctx)); + int AD_Column_ID = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnName, "AD_Table", tableid, /*ignorecase=*/true); + mColumn = new MColumn(ctx.ctx, AD_Column_ID > 0 ? AD_Column_ID : 0, getTrxName(ctx)); if (mColumn.getAD_Column_ID() == 0 && isOfficialId(element, "AD_Column_ID")) { mColumn.setAD_Column_ID(getIntValue(element, "AD_Column_ID")); } @@ -87,6 +87,7 @@ public class ColumnElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -104,7 +105,7 @@ public class ColumnElementHandler extends AbstractElementHandler { // Setup Element. if (mColumn.getAD_Element_ID() == 0) { - X_AD_Element adElement = new X_AD_Element(ctx, 0, getTrxName(ctx)); + X_AD_Element adElement = new X_AD_Element(ctx.ctx, 0, getTrxName(ctx)); adElement.setColumnName(mColumn.getColumnName()); adElement.setEntityType(mColumn.getEntityType()); adElement.setPrintName(mColumn.getColumnName()); @@ -164,11 +165,11 @@ public class ColumnElementHandler extends AbstractElementHandler { } else { logImportDetail(ctx, impDetail, 0, mColumn.getName(), mColumn .get_ID(), action); - throw new POSaveFailedException("Failed to import column."); + throw new POSaveFailedException("Failed to save column " + mColumn.getName()); } if (recreateColumn || syncDatabase) { - MTable table = new MTable(ctx, mColumn.getAD_Table_ID(), getTrxName(ctx)); + MTable table = new MTable(ctx.ctx, mColumn.getAD_Table_ID(), getTrxName(ctx)); if (!table.isView() && !mColumn.isVirtualColumn()) { success = createColumn(ctx, table, mColumn, recreateColumn); @@ -199,7 +200,7 @@ public class ColumnElementHandler extends AbstractElementHandler { * @param v_IsMandatory * */ - private int createColumn(Properties ctx, MTable table, MColumn column, boolean doAlter) { + private int createColumn(PIPOContext ctx, MTable table, MColumn column, boolean doAlter) { int no = 0; @@ -297,23 +298,30 @@ public class ColumnElementHandler extends AbstractElementHandler { return 1; } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int AD_Column_ID = Env.getContextAsInt(ctx, + int AD_Column_ID = Env.getContextAsInt(ctx.ctx, X_AD_Column.COLUMNNAME_AD_Column_ID); AttributesImpl atts = new AttributesImpl(); - X_AD_Column m_Column = new X_AD_Column(ctx, AD_Column_ID, + X_AD_Column m_Column = new X_AD_Column(ctx.ctx, AD_Column_ID, getTrxName(ctx)); + + if (ctx.packOut.getFromDate() != null) { + if (m_Column.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } + addTypeName(atts, "table"); document.startElement("", "", I_AD_Column.Table_Name, atts); createColumnBinding(ctx, document, m_Column); document.endElement("", "", I_AD_Column.Table_Name); } - private void createColumnBinding(Properties ctx, TransformerHandler document, + private void createColumnBinding(PIPOContext ctx, TransformerHandler document, X_AD_Column m_Column) { PoExporter filler = new PoExporter(ctx, document, m_Column); @@ -337,8 +345,8 @@ public class ColumnElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler, int recordId) throws Exception { - Env.setContext(packout.getCtx(), I_AD_Column.COLUMNNAME_AD_Column_ID, recordId); + Env.setContext(packout.getCtx().ctx, I_AD_Column.COLUMNNAME_AD_Column_ID, recordId); create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(I_AD_Column.COLUMNNAME_AD_Column_ID); + packout.getCtx().ctx.remove(I_AD_Column.COLUMNNAME_AD_Column_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/CommonTranslationHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/CommonTranslationHandler.java index 427b883ced..f7517799f2 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/CommonTranslationHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/CommonTranslationHandler.java @@ -5,12 +5,12 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.exceptions.DBException; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.ElementHandler; @@ -30,9 +30,9 @@ public class CommonTranslationHandler extends AbstractElementHandler implements private HashMap> cacheColumns = new HashMap>();//Key: table name. Value: set of PIPO columns - public void startElement(Properties ctx, Element element) throws SAXException { + public void startElement(PIPOContext ctx, Element element) throws SAXException { - if(! isHandleTranslations(ctx)){ + if(! isHandleTranslations(ctx.ctx)){ return;//translation import option is disabled } @@ -64,7 +64,7 @@ public class CommonTranslationHandler extends AbstractElementHandler implements private boolean isRecordExists(String tableName, int parentID, - String language, Properties ctx) { + String language, PIPOContext ctx) { String sql = "SELECT AD_Client_ID FROM " + tableName +" WHERE " + @@ -79,7 +79,7 @@ public class CommonTranslationHandler extends AbstractElementHandler implements private void insertTranslation(String tableName, int parentID, - Properties ctx, Element element) throws SAXException{ + PIPOContext ctx, Element element) throws SAXException{ String parentTable = tableName.substring(0, tableName.length()-4); ArrayList columns = getTranslatedColumns(parentTable); @@ -133,7 +133,7 @@ public class CommonTranslationHandler extends AbstractElementHandler implements private void updateTranslation(String tableName, int parentID, - Properties ctx, Element element) throws SAXException{ + PIPOContext ctx, Element element) throws SAXException{ String parentTable = tableName.substring(0, tableName.length()-4); ArrayList columns = getTranslatedColumns(parentTable); StringBuffer buffer = new StringBuffer("UPDATE "+tableName+" SET "); @@ -173,22 +173,22 @@ public class CommonTranslationHandler extends AbstractElementHandler implements } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) throws SAXException { + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - String parenTableName = Env.getContext(ctx, CONTEXT_KEY_PARENT_TABLE); + String parenTableName = Env.getContext(ctx.ctx, CONTEXT_KEY_PARENT_TABLE); - int parentRecordID = Env.getContextAsInt(ctx, CONTEXT_KEY_PARENT_RECORD_ID); + int parentRecordID = Env.getContextAsInt(ctx.ctx, CONTEXT_KEY_PARENT_RECORD_ID); createTranslationTags(ctx, parenTableName, parentRecordID, document); } - private void createTranslationTags(Properties ctx, String parentTable, + private void createTranslationTags(PIPOContext ctx, String parentTable, int parentRecordID, TransformerHandler document) throws SAXException { ArrayList translatedColumns = getTranslatedColumns(parentTable); @@ -221,7 +221,7 @@ public class CommonTranslationHandler extends AbstractElementHandler implements } } - private void exportRow(Properties ctx, TransformerHandler document, ArrayList columns, + private void exportRow(PIPOContext ctx, TransformerHandler document, ArrayList columns, ResultSet rs) throws Exception { PoExporter af = new PoExporter(ctx, document, null); @@ -289,12 +289,12 @@ public class CommonTranslationHandler extends AbstractElementHandler implements public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception { - if("true".equals(packout.getCtx().getProperty("isHandleTranslations"))){ - Env.setContext(packout.getCtx(), CommonTranslationHandler.CONTEXT_KEY_PARENT_TABLE,X_AD_Element.Table_Name); - Env.setContext(packout.getCtx(), CommonTranslationHandler.CONTEXT_KEY_PARENT_RECORD_ID,recordId); + if("true".equals(packout.getCtx().ctx.getProperty("isHandleTranslations"))){ + Env.setContext(packout.getCtx().ctx, CommonTranslationHandler.CONTEXT_KEY_PARENT_TABLE,X_AD_Element.Table_Name); + Env.setContext(packout.getCtx().ctx, CommonTranslationHandler.CONTEXT_KEY_PARENT_RECORD_ID,recordId); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(CommonTranslationHandler.CONTEXT_KEY_PARENT_TABLE); - packout.getCtx().remove(CommonTranslationHandler.CONTEXT_KEY_PARENT_RECORD_ID); + packout.getCtx().ctx.remove(CommonTranslationHandler.CONTEXT_KEY_PARENT_TABLE); + packout.getCtx().ctx.remove(CommonTranslationHandler.CONTEXT_KEY_PARENT_RECORD_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/DistFileElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/DistFileElementHandler.java index 72c6110b8d..f3ea3b23b9 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/DistFileElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/DistFileElementHandler.java @@ -22,12 +22,12 @@ import java.io.InputStream; import java.io.OutputStream; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.Element; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackoutItem; import org.compiere.Adempiere; @@ -53,7 +53,7 @@ public class DistFileElementHandler extends AbstractElementHandler { this.fileDest=fileDest; } - public void startElement(Properties ctx, Element element) throws SAXException { + public void startElement(PIPOContext ctx, Element element) throws SAXException { String action = null; String releaseNumber = getStringValue(element,"ReleaseNo"); @@ -72,7 +72,7 @@ public class DistFileElementHandler extends AbstractElementHandler { //get adempiere-all directory try { - packagePath = getPackageDirectory(ctx); + packagePath = getPackageDirectory(ctx.ctx); File parentDirectory = new File(packagePath); while (!parentDirectory.getName().equals("packages")){ parentDirectory = parentDirectory.getParentFile(); @@ -165,25 +165,25 @@ public class DistFileElementHandler extends AbstractElementHandler { } } //Record in transaction file - X_AD_Package_Imp_Backup backup = new X_AD_Package_Imp_Backup(ctx, 0, getTrxName(ctx)); - backup.setAD_Org_ID(Env.getAD_Org_ID(ctx)); + X_AD_Package_Imp_Backup backup = new X_AD_Package_Imp_Backup(ctx.ctx, 0, getTrxName(ctx)); + backup.setAD_Org_ID(Env.getAD_Org_ID(ctx.ctx)); backup.setAD_Package_Imp_Org_Dir(fullTargetPath+fileName); backup.setAD_Package_Imp_Bck_Dir(packagePath+File.separator+"backup"+File.separator+fileDate+"_"+fileName); - backup.setAD_Package_Imp_ID(getPackageImpId(ctx)); + backup.setAD_Package_Imp_ID(getPackageImpId(ctx.ctx)); backup.saveEx(); } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - String FileName = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_FileName); - String Source_Directory = Env.getContext(ctx, "Source_Directory"); - String Target_Directory = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory); - String ReleaseNo = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo); + String FileName = Env.getContext(ctx.ctx, X_AD_Package_Exp_Detail.COLUMNNAME_FileName); + String Source_Directory = Env.getContext(ctx.ctx, "Source_Directory"); + String Target_Directory = Env.getContext(ctx.ctx, X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory); + String ReleaseNo = Env.getContext(ctx.ctx, X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo); AttributesImpl atts = new AttributesImpl(); addTypeName(atts, "custom"); document.startElement("","","Dist_File",atts); @@ -197,22 +197,20 @@ public class DistFileElementHandler extends AbstractElementHandler { public void doPackout(PackOut packout, MPackageExp header, PackoutItem detail,TransformerHandler packOutDocument,TransformerHandler packageDocument,AttributesImpl atts,int recordId) throws Exception { - Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_FileName, (String)detail.getProperty("FileName")); - Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo, (String)detail.getProperty("ReleaseNo")); - Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory, (String)detail.getProperty("TargetDirectory")); - Env.setContext(packout.getCtx(), "Source_Directory", fileDest); + Env.setContext(packout.getCtx().ctx, X_AD_Package_Exp_Detail.COLUMNNAME_FileName, (String)detail.getProperty("FileName")); + Env.setContext(packout.getCtx().ctx, X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo, (String)detail.getProperty("ReleaseNo")); + Env.setContext(packout.getCtx().ctx, X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory, (String)detail.getProperty("TargetDirectory")); + Env.setContext(packout.getCtx().ctx, "Source_Directory", fileDest); this.create(packout.getCtx(), packOutDocument); - packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_FileName); - packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo); - packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory); - packout.getCtx().remove("Source_Directory"); + packout.getCtx().ctx.remove(X_AD_Package_Exp_Detail.COLUMNNAME_FileName); + packout.getCtx().ctx.remove(X_AD_Package_Exp_Detail.COLUMNNAME_ReleaseNo); + packout.getCtx().ctx.remove(X_AD_Package_Exp_Detail.COLUMNNAME_Target_Directory); + packout.getCtx().ctx.remove("Source_Directory"); } @Override public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler, int recordId) throws Exception { - // TODO Auto-generated method stub - } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/DynValRuleElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/DynValRuleElementHandler.java index 1e640e73a6..e87476484b 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/DynValRuleElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/DynValRuleElementHandler.java @@ -18,11 +18,11 @@ package org.adempiere.pipo2.handler; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -40,16 +40,16 @@ public class DynValRuleElementHandler extends AbstractElementHandler { private List rules = new ArrayList(); - public void startElement(Properties ctx, Element element) throws SAXException { + public void startElement(PIPOContext ctx, Element element) throws SAXException { String entitytype = getStringValue(element, "EntityType"); - if (isProcessElement(ctx, entitytype)) { + if (isProcessElement(ctx.ctx, entitytype)) { String name = getStringValue(element, "Name"); 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)); + mValRule = new X_AD_Val_Rule(ctx.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")); @@ -60,6 +60,7 @@ public class DynValRuleElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -80,7 +81,7 @@ public class DynValRuleElementHandler extends AbstractElementHandler { } else{ logImportDetail (ctx, impDetail, 0, mValRule.getName(), mValRule.get_ID(),action); - throw new POSaveFailedException("Failed to save dynamic validation rule."); + throw new POSaveFailedException("Failed to save dynamic validation rule " + mValRule.getName()); } } } else { @@ -89,16 +90,23 @@ public class DynValRuleElementHandler extends AbstractElementHandler { } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - protected void create(Properties ctx, TransformerHandler document) + protected void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int AD_Val_Rule_ID = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID); + int AD_Val_Rule_ID = Env.getContextAsInt(ctx.ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID); if (rules.contains(AD_Val_Rule_ID)) return; rules.add(AD_Val_Rule_ID); - X_AD_Val_Rule m_ValRule = new X_AD_Val_Rule (ctx, AD_Val_Rule_ID, null); + X_AD_Val_Rule m_ValRule = new X_AD_Val_Rule (ctx.ctx, AD_Val_Rule_ID, null); + + if (ctx.packOut.getFromDate() != null) { + if (m_ValRule.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } + AttributesImpl atts = new AttributesImpl(); addTypeName(atts, "table"); document.startElement("","",I_AD_Val_Rule.Table_Name, atts); @@ -107,7 +115,7 @@ public class DynValRuleElementHandler extends AbstractElementHandler { } - private void createDynamicValidationRuleBinding(Properties ctx, TransformerHandler document, X_AD_Val_Rule m_ValRule) + private void createDynamicValidationRuleBinding(PIPOContext ctx, TransformerHandler document, X_AD_Val_Rule m_ValRule) { PoExporter filler = new PoExporter(ctx, document, m_ValRule); Listexcludes = defaultExcludeList(X_AD_Val_Rule.Table_Name); @@ -122,9 +130,9 @@ public class DynValRuleElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception { - Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID, recordId); + Env.setContext(packout.getCtx().ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID, recordId); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID); + packout.getCtx().ctx.remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Val_Rule_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/FieldElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/FieldElementHandler.java index 6aa853c930..c4b29f82ba 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/FieldElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/FieldElementHandler.java @@ -17,12 +17,12 @@ package org.adempiere.pipo2.handler; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.ElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -33,7 +33,6 @@ import org.compiere.model.I_AD_Field; import org.compiere.model.I_AD_FieldGroup; import org.compiere.model.I_AD_Reference; import org.compiere.model.I_AD_Tab; -import org.compiere.model.I_AD_Val_Rule; import org.compiere.model.MField; import org.compiere.model.X_AD_Field; import org.compiere.model.X_AD_Package_Imp_Detail; @@ -44,32 +43,47 @@ import org.xml.sax.helpers.AttributesImpl; public class FieldElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { String entitytype = getStringValue(element, "EntityType"); - if (isProcessElement(ctx, entitytype)) { + if (isProcessElement(ctx.ctx, entitytype)) { if (isParentDefer(element, I_AD_Tab.Table_Name)) { element.defer = true; return; } Listexcludes = defaultExcludeList(X_AD_Field.Table_Name); + excludes.add("AD_Window_ID"); + excludes.add("AD_Tab_ID"); int tabid = getParentId(element, I_AD_Tab.Table_Name) ; + if (tabid <= 0) { + Element tabElement = element.properties.get("AD_Tab_ID"); + if (ReferenceUtils.isIDLookup(tabElement) || ReferenceUtils.isUUIDLookup(tabElement)) { + tabid = ReferenceUtils.resolveReference(ctx.ctx, tabElement, getTrxName(ctx)); + } else { + String tabName = getStringValue(element, "AD_Tab_ID"); + int AD_Window_ID = ReferenceUtils.resolveReference(ctx.ctx, element.properties.get("AD_Window_ID"), getTrxName(ctx)); + if (AD_Window_ID > 0) { + tabid = findIdByNameAndParentId(ctx, "AD_Tab", tabName, "AD_Window", AD_Window_ID); + } + } + } if (tabid <= 0) { element.defer = true; + element.unresolved = "AD_Tab_ID"; return; } - MField mField = findPO(ctx, element); - if (mField == null) - { - int AD_Table_ID = ReferenceUtils.resolveReference(ctx, element.parent.properties.get("AD_Table_ID"), getTrxName(ctx)); + excludes.add("AD_Table_ID"); + excludes.add("AD_Column_ID"); + + int AD_Table_ID = ReferenceUtils.resolveReference(ctx.ctx, element.properties.get("AD_Table_ID"), getTrxName(ctx)); Element columnElement = element.properties.get("AD_Column_ID"); int AD_Column_ID = 0; if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) { - AD_Column_ID = ReferenceUtils.resolveReference(ctx, columnElement, getTrxName(ctx)); + AD_Column_ID = ReferenceUtils.resolveReference(ctx.ctx, columnElement, getTrxName(ctx)); } else { @@ -79,20 +93,32 @@ public class FieldElementHandler extends AbstractElementHandler { if (AD_Column_ID == 0) { element.defer = true; + element.unresolved = "AD_Column_ID"; return; } + MField mField = findPO(ctx, element); + if (mField == null) + { 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)); + mField = new MField(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); if (mField.is_new()) { mField.setAD_Column_ID(AD_Column_ID); mField.setAD_Tab_ID(tabid); } + } else { + if (mField.getAD_Tab_ID() != tabid) { + mField.setAD_Tab_ID(tabid); } + if (mField.getAD_Column_ID() != AD_Column_ID) { + mField.setAD_Column_ID(AD_Column_ID); + } + } + PoFiller filler = new PoFiller(ctx, mField, element, this); if (mField.getAD_Field_ID() == 0 && isOfficialId(element, "AD_Field_ID")) { @@ -102,6 +128,7 @@ public class FieldElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -124,7 +151,7 @@ public class FieldElementHandler extends AbstractElementHandler { } else { logImportDetail(ctx, impDetail, 0, mField.getName(), mField .get_ID(), action); - throw new POSaveFailedException("Failed to save field definition."); + throw new POSaveFailedException("Failed to save field definition " + mField.getName()); } } } else { @@ -132,20 +159,16 @@ public class FieldElementHandler extends AbstractElementHandler { } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int AD_Field_ID = Env.getContextAsInt(ctx, + int AD_Field_ID = Env.getContextAsInt(ctx.ctx, 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(); - addTypeName(atts, "table"); - document.startElement("", "", I_AD_Field.Table_Name, atts); - createFieldBinding(ctx, document, m_Field); + X_AD_Field m_Field = new X_AD_Field(ctx.ctx, AD_Field_ID, null); - PackOut packOut = (PackOut)ctx.get("PackOutProcess"); + PackOut packOut = ctx.packOut; try { @@ -160,28 +183,26 @@ public class FieldElementHandler extends AbstractElementHandler { ElementHandler handler = packOut.getHandler(I_AD_Reference.Table_Name); handler.packOut(packOut,document,null,m_Field.getAD_Reference_ID()); } - - if (m_Field.getAD_Reference_Value_ID()>0) - { - ElementHandler handler = packOut.getHandler(I_AD_Reference.Table_Name); - handler.packOut(packOut,document,null,m_Field.getAD_Reference_Value_ID()); - } - - if (m_Field.getAD_Val_Rule_ID()>0) - { - ElementHandler handler = packOut.getHandler(I_AD_Val_Rule.Table_Name); - handler.packOut(packOut,document,null,m_Field.getAD_Val_Rule_ID()); - } } catch(Exception e) - { - log.info(e.toString()); + { + throw new SAXException(e); + } + + if (ctx.packOut.getFromDate() != null) { + if (m_Field.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } } - document.endElement("", "", I_AD_Field.Table_Name); + AttributesImpl atts = new AttributesImpl(); + addTypeName(atts, "table"); + document.startElement("", "", X_AD_Field.Table_Name, atts); + createFieldBinding(ctx, document, m_Field); + document.endElement("", "", X_AD_Field.Table_Name); } - private void createFieldBinding(Properties ctx, TransformerHandler document, + private void createFieldBinding(PIPOContext ctx, TransformerHandler document, X_AD_Field m_Field) { List excludes = defaultExcludeList(X_AD_Field.Table_Name); @@ -190,6 +211,20 @@ public class FieldElementHandler extends AbstractElementHandler { filler.add("AD_Field_ID", new AttributesImpl()); } + int AD_Table_ID = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?", m_Field.getAD_Column_ID()); + if (AD_Table_ID > 0) { + AttributesImpl atts = new AttributesImpl(); + filler.addTableReference("AD_Table_ID", "AD_Table", "TableName", AD_Table_ID, atts); + } + + excludes.add("AD_Tab_ID"); + AttributesImpl atts = new AttributesImpl(); + filler.addTableReference("AD_Tab_ID", "AD_Tab", "Name", m_Field.getAD_Tab_ID(), atts); + if (atts.getValue("reference").equals("table")) { + int AD_Window_ID = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Window_ID FROM AD_Tab WHERE AD_Tab_ID=?", m_Field.getAD_Tab_ID()); + filler.addTableReference("AD_Window_ID", "AD_Window", "Name", AD_Window_ID, new AttributesImpl()); + } + filler.export(excludes); } @@ -197,8 +232,8 @@ public class FieldElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler, int recordId) throws Exception { - Env.setContext(packout.getCtx(), I_AD_Field.COLUMNNAME_AD_Field_ID, recordId); + Env.setContext(packout.getCtx().ctx, I_AD_Field.COLUMNNAME_AD_Field_ID, recordId); create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(I_AD_Field.COLUMNNAME_AD_Field_ID); + packout.getCtx().ctx.remove(I_AD_Field.COLUMNNAME_AD_Field_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/FieldGroupElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/FieldGroupElementHandler.java index b4080fb3a1..b05aa06bab 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/FieldGroupElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/FieldGroupElementHandler.java @@ -19,11 +19,11 @@ package org.adempiere.pipo2.handler; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -42,7 +42,7 @@ public class FieldGroupElementHandler extends AbstractElementHandler { private List processedFieldGroups = new ArrayList(); - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { String elementValue = element.getElementValue(); String action = null; @@ -52,13 +52,13 @@ public class FieldGroupElementHandler extends AbstractElementHandler { String entitytype = getStringValue(element, "EntityType"); String name = getStringValue(element, "Name"); - if (isProcessElement(ctx, entitytype)) { + if (isProcessElement(ctx.ctx, entitytype)) { 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)); + fieldGroup = new X_AD_FieldGroup(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); } PoFiller pf = new PoFiller(ctx, fieldGroup, element, this); List excludes = defaultExcludeList(X_AD_FieldGroup.Table_Name); @@ -75,6 +75,7 @@ public class FieldGroupElementHandler extends AbstractElementHandler { List notfounds = pf.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -99,7 +100,7 @@ public class FieldGroupElementHandler extends AbstractElementHandler { } else { logImportDetail(ctx, impDetail, 0, fieldGroup.getName(), fieldGroup.get_ID(), action); - throw new POSaveFailedException("Reference"); + throw new POSaveFailedException("Failed to save Field Group " + fieldGroup.getName()); } } } else { @@ -107,14 +108,14 @@ public class FieldGroupElementHandler extends AbstractElementHandler { } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - protected void create(Properties ctx, TransformerHandler document) + protected void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int fieldGroup_id = Env.getContextAsInt(ctx, + int fieldGroup_id = Env.getContextAsInt(ctx.ctx, X_AD_FieldGroup.COLUMNNAME_AD_FieldGroup_ID); if (processedFieldGroups.contains(fieldGroup_id)) @@ -122,7 +123,13 @@ public class FieldGroupElementHandler extends AbstractElementHandler { processedFieldGroups.add(fieldGroup_id); - X_AD_FieldGroup fieldGroup = new X_AD_FieldGroup(ctx, fieldGroup_id, null); + X_AD_FieldGroup fieldGroup = new X_AD_FieldGroup(ctx.ctx, fieldGroup_id, null); + + if (ctx.packOut.getFromDate() != null) { + if (fieldGroup.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } AttributesImpl atts = new AttributesImpl(); addTypeName(atts, "table"); @@ -130,7 +137,7 @@ public class FieldGroupElementHandler extends AbstractElementHandler { createAdElementBinding(ctx, document, fieldGroup); - PackOut packOut = (PackOut)ctx.get("PackOutProcess"); + PackOut packOut = ctx.packOut; try{ new CommonTranslationHandler().packOut(packOut,document,null,fieldGroup.get_ID()); @@ -143,7 +150,7 @@ public class FieldGroupElementHandler extends AbstractElementHandler { } - private void createAdElementBinding(Properties ctx, TransformerHandler document, + private void createAdElementBinding(PIPOContext ctx, TransformerHandler document, X_AD_FieldGroup fieldGroup) { PoExporter filler = new PoExporter(ctx, document, fieldGroup); @@ -157,9 +164,9 @@ public class FieldGroupElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception { - Env.setContext(packout.getCtx(), X_AD_FieldGroup.COLUMNNAME_AD_FieldGroup_ID, recordId); + Env.setContext(packout.getCtx().ctx, X_AD_FieldGroup.COLUMNNAME_AD_FieldGroup_ID, recordId); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(X_AD_FieldGroup.COLUMNNAME_AD_FieldGroup_ID); + packout.getCtx().ctx.remove(X_AD_FieldGroup.COLUMNNAME_AD_FieldGroup_ID); } } \ No newline at end of file diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/FileElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/FileElementHandler.java index 1a88609c43..0da89781b0 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/FileElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/FileElementHandler.java @@ -1,7 +1,6 @@ package org.adempiere.pipo2.handler; import java.io.File; -import java.util.Properties; import java.util.logging.Level; import javax.xml.transform.sax.TransformerHandler; @@ -10,6 +9,7 @@ import org.adempiere.exceptions.AdempiereException; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.ElementHandler; import org.adempiere.pipo2.FileElementParameters; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackoutDocument; import org.adempiere.pipo2.PackoutItem; @@ -88,11 +88,11 @@ public class FileElementHandler implements ElementHandler { } @Override - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { } @Override - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/FormAccessElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/FormAccessElementHandler.java index 0a3f424eee..25f2a78be3 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/FormAccessElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/FormAccessElementHandler.java @@ -17,11 +17,11 @@ package org.adempiere.pipo2.handler; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; @@ -40,7 +40,7 @@ import org.xml.sax.helpers.AttributesImpl; public class FormAccessElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) throws SAXException { + public void startElement(PIPOContext ctx, Element element) throws SAXException { List excludes = defaultExcludeList(X_AD_Form_Access.Table_Name); MFormAccess po = findPO(ctx, element); @@ -49,28 +49,30 @@ public class FormAccessElementHandler extends AbstractElementHandler { 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"), getTrxName(ctx)); + AD_Role_ID = ReferenceUtils.resolveReference(ctx.ctx, element.properties.get("AD_Role_ID"), getTrxName(ctx)); } if (AD_Role_ID <= 0) { element.defer = true; + element.unresolved = "AD_Role_ID"; return; } - int AD_Form_ID = ReferenceUtils.resolveReference(ctx, element.properties.get("AD_Form_ID"), getTrxName(ctx)); + int AD_Form_ID = ReferenceUtils.resolveReference(ctx.ctx, element.properties.get("AD_Form_ID"), getTrxName(ctx)); if (AD_Form_ID <= 0) { element.defer = true; + element.unresolved = "AD_Form_ID"; return; } - Query query = new Query(ctx, "AD_Form_Access", "AD_Form_ID = ? AND AD_Role_ID = ?", getTrxName(ctx)); + Query query = new Query(ctx.ctx, "AD_Form_Access", "AD_Form_ID = ? AND AD_Role_ID = ?", getTrxName(ctx)); po = query.setParameters(new Object[]{AD_Form_ID, AD_Role_ID}) .setClient_ID() .first(); if (po == null) { - po = new MFormAccess(ctx, 0, null); + po = new MFormAccess(ctx.ctx, 0, getTrxName(ctx)); po.setAD_Form_ID(AD_Form_ID); po.setAD_Role_ID(AD_Role_ID); } @@ -83,43 +85,51 @@ public class FormAccessElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } po.saveEx(); } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - 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(); - addTypeName(atts, "table"); - document.startElement("", "", I_AD_Form_Access.Table_Name, atts); - createFormAccessBinding(ctx, document, AD_Form_ID, AD_Role_ID); - document.endElement("", "", I_AD_Form_Access.Table_Name); + int AD_Form_ID = Env.getContextAsInt(ctx.ctx, X_AD_Form.COLUMNNAME_AD_Form_ID); + int AD_Role_ID = Env.getContextAsInt(ctx.ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); + + MFormAccess po = null; + Query query = new Query(ctx.ctx, "AD_Form_Access", "AD_Form_ID = ? AND AD_Role_ID = ?", getTrxName(ctx)); + po = query.setParameters(new Object[]{AD_Form_ID, AD_Role_ID}).first(); + + if (po != null) { + + if (ctx.packOut.getFromDate() != null) { + if (po.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } + + AttributesImpl atts = new AttributesImpl(); + addTypeName(atts, "table"); + document.startElement("", "", I_AD_Form_Access.Table_Name, atts); + createFormAccessBinding(ctx, document, po); + document.endElement("", "", I_AD_Form_Access.Table_Name); + } } - private void createFormAccessBinding(Properties ctx, TransformerHandler document, - int formId, int roleId) { - 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}).first(); - if (po != null) { - PoExporter filler = new PoExporter(ctx, document, po); - List excludes = defaultExcludeList(X_AD_Form_Access.Table_Name); - filler.export(excludes); - } + private void createFormAccessBinding(PIPOContext ctx, TransformerHandler document, + MFormAccess po) { + PoExporter filler = new PoExporter(ctx, document, po); + List excludes = defaultExcludeList(X_AD_Form_Access.Table_Name); + filler.export(excludes); } @Override public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler, int recordId) throws Exception { - // TODO Auto-generated method stub - } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/FormElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/FormElementHandler.java index f838389294..a037691d60 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/FormElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/FormElementHandler.java @@ -19,11 +19,11 @@ package org.adempiere.pipo2.handler; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -42,16 +42,16 @@ public class FormElementHandler extends AbstractElementHandler { private List forms = new ArrayList(); - public void startElement(Properties ctx, Element element) throws SAXException { + public void startElement(PIPOContext ctx, Element element) throws SAXException { List excludes = defaultExcludeList(X_AD_Form.Table_Name); String entitytype = getStringValue(element, "EntityType"); - if (isProcessElement(ctx, entitytype)) { + if (isProcessElement(ctx.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)); + mForm = new MForm(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); } PoFiller filler = new PoFiller(ctx, mForm, element, this); @@ -63,6 +63,7 @@ public class FormElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -83,7 +84,7 @@ public class FormElementHandler extends AbstractElementHandler { } else{ logImportDetail (ctx, impDetail, 0, mForm.getName(), mForm.get_ID(), action); - throw new POSaveFailedException("Failed to save form definition"); + throw new POSaveFailedException("Failed to save form definition " + mForm.getName()); } } } else { @@ -91,16 +92,23 @@ public class FormElementHandler extends AbstractElementHandler { } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - protected void create(Properties ctx, TransformerHandler document) + protected void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int AD_Form_ID = Env.getContextAsInt(ctx, "AD_Form_ID"); + int AD_Form_ID = Env.getContextAsInt(ctx.ctx, "AD_Form_ID"); if (forms.contains(AD_Form_ID)) return; forms.add(AD_Form_ID); - X_AD_Form m_Form = new X_AD_Form (ctx, AD_Form_ID, null); + X_AD_Form m_Form = new X_AD_Form (ctx.ctx, AD_Form_ID, null); + + if (ctx.packOut.getFromDate() != null) { + if (m_Form.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } + AttributesImpl atts = new AttributesImpl(); addTypeName(atts, "table"); document.startElement("","",I_AD_Form.Table_Name,atts); @@ -108,7 +116,7 @@ public class FormElementHandler extends AbstractElementHandler { document.endElement("","",I_AD_Form.Table_Name); } - private void createFormBinding(Properties ctx, TransformerHandler document, X_AD_Form m_Form) + private void createFormBinding(PIPOContext ctx, TransformerHandler document, X_AD_Form m_Form) { PoExporter filler = new PoExporter(ctx, document, m_Form); List excludes = defaultExcludeList(X_AD_Form.Table_Name); @@ -121,8 +129,8 @@ public class FormElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception { - Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Form_ID, recordId); + Env.setContext(packout.getCtx().ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Form_ID, recordId); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Form_ID); + packout.getCtx().ctx.remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Form_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/GenericPOElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/GenericPOElementHandler.java index 38db379171..1254469bf7 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/GenericPOElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/GenericPOElementHandler.java @@ -21,7 +21,6 @@ import java.sql.ResultSet; import java.sql.Statement; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; @@ -29,11 +28,13 @@ import org.adempiere.exceptions.AdempiereException; import org.adempiere.model.GenericPO; import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.DataElementParameters; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PackoutItem; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PoFiller; +import org.adempiere.pipo2.ReferenceUtils; import org.compiere.model.MColumn; import org.compiere.model.MRole; import org.compiere.model.MTable; @@ -54,56 +55,112 @@ import org.xml.sax.helpers.AttributesImpl; */ public class GenericPOElementHandler extends AbstractElementHandler { - public GenericPOElementHandler() { + private String tableName; + + public GenericPOElementHandler(String tableName) { + this.tableName = tableName; } - public void startElement(Properties ctx, Element element) throws SAXException { + public void startElement(PIPOContext ctx, Element element) throws SAXException { String tableName = element.getElementValue(); 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 parameters = new ArrayList(); - 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; + String uuidColumn = PO.getUUIDColumnName(tableName); + String idColumn = tableName + "_ID"; + MTable table = MTable.get(ctx.ctx, tableName); + if ((!element.properties.containsKey(uuidColumn) || element.properties.get(uuidColumn).contents == null || element.properties.get(uuidColumn).contents.toString().trim().length() > 0) + && (!element.properties.containsKey(idColumn) || element.properties.get(idColumn).contents == null || element.properties.get(idColumn).contents.toString().trim().length() > 0)) { + POInfo info = POInfo.getPOInfo(ctx.ctx, table.getAD_Table_ID()); + MColumn columns[] = table.getColumns(false); + StringBuffer whereClause = new StringBuffer(); + List parameters = new ArrayList(); + boolean search = true; + for(int i = 0; i < columns.length; i++) { + MColumn column = columns[i]; + if (column.isParent()) { + int parentId = 0; + String parentTableName = null; + if (column.getAD_Reference_ID() == DisplayType.TableDir) { + parentTableName = column.getColumnName().substring(0, column.getColumnName().length() - 3); + } else { + String searchColumn = info.getColumnLookup(i).getColumnName(); + parentTableName = searchColumn.substring(0, searchColumn.indexOf(".")); + } + + Element parent = element.parent; + while (parent != null) { + if (parent.getElementValue().equalsIgnoreCase(parentTableName)) { + parentId = parent.recordId; + break; + } + parent = parent.parent; + } + + if (parentId == 0) { + Element parentElement = element.properties.get(column.getColumnName()); + if (parentElement != null) { + parentId = ReferenceUtils.resolveReference(ctx.ctx, parentElement, getTrxName(ctx)); + } + } + if (parentId > 0) { + if (whereClause.length() > 0) + whereClause.append(" AND "); + whereClause.append(column.getColumnName()).append(" = ?"); + parameters.add(parentId); + } else { + search = false; break; } - parent = parent.parent; - } - if (parentId > 0) { + } else if (column.isIdentifier()) { if (whereClause.length() > 0) whereClause.append(" AND "); - whereClause.append(column.getColumnName()).append(" = ?"); - parameters.add(parentId); + whereClause.append(column.getColumnName()).append(" = ? "); + + String refTableName = null; + if (column.getAD_Reference_ID() == DisplayType.TableDir) { + refTableName = column.getColumnName().substring(0, column.getColumnName().length() - 3); + } else if (column.getAD_Reference_ID() == DisplayType.Table || + column.getAD_Reference_ID() == DisplayType.Search) { + String searchColumn = info.getColumnLookup(i).getColumnName(); + refTableName = searchColumn.substring(0, searchColumn.indexOf(".")); + } + + if (refTableName == null) { + parameters.add(getStringValue(element, column.getColumnName())); + } else { + int refId = 0; + Element parent = element.parent; + while (parent != null) { + if (parent.getElementValue().equalsIgnoreCase(refTableName)) { + refId = parent.recordId; + break; + } + parent = parent.parent; + } + + if (refId == 0) { + Element refElement = element.properties.get(column.getColumnName()); + if (refElement != null) { + refId = ReferenceUtils.resolveReference(ctx.ctx, refElement, getTrxName(ctx)); + } + } + if (refId > 0) { + parameters.add(refId); + } else { + search = false; + break; + } + } } } - } - Query query = new Query(ctx, table, whereClause.toString(), getTrxName(ctx)); - po = query.setParameters(parameters).first(); + if (whereClause.length() > 0 && search) { + Query query = new Query(ctx.ctx, table, whereClause.toString(), getTrxName(ctx)); + po = query.setParameters(parameters).setApplyAccessFilter(true).first(); + } + } if (po == null) { - po = new GenericPO(tableName, ctx, 0); + po = table.getPO(0, getTrxName(ctx)); } } PoFiller filler = new PoFiller(ctx, po, element, this); @@ -115,27 +172,39 @@ public class GenericPOElementHandler extends AbstractElementHandler { try { id = Integer.parseInt(idElement.contents.toString()); if (id > 0 && id <= PackOut.MAX_OFFICIAL_ID) { - po.set_ValueOfColumn(tableName + "_ID", id); + po.set_ValueNoCheck(tableName + "_ID", id); } } catch (Exception e) {} } } List notfounds = filler.autoFill(excludes); + /* Verify if the table has entitytype and check dictionary maintenance */ + int idxet = po.get_ColumnIndex("EntityType"); + if (idxet >= 0) { + String entityType = (String) po.get_Value(idxet); + if (! isProcessElement(ctx.ctx, entityType)) { + log.info("Generic PO not processed as it's official " + po.toString()); + element.skip = true; + return; + } + } + if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } po.saveEx(); } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { AttributesImpl atts = new AttributesImpl(); - String sql = Env.getContext(ctx, DataElementParameters.SQL_STATEMENT); + String sql = Env.getContext(ctx.ctx, DataElementParameters.SQL_STATEMENT); String components[] = null; if (sql.indexOf(";") > 0) { components = sql.split("[;]"); @@ -143,8 +212,8 @@ public class GenericPOElementHandler extends AbstractElementHandler { } else { components = new String[]{sql}; } - int tableId = Env.getContextAsInt(ctx, DataElementParameters.AD_TABLE_ID); - String tableName = MTable.getTableName(ctx, tableId); + int tableId = Env.getContextAsInt(ctx.ctx, DataElementParameters.AD_TABLE_ID); + String tableName = MTable.getTableName(ctx.ctx, tableId); List excludes = defaultExcludeList(tableName); Statement stmt = null; ResultSet rs = null; @@ -153,20 +222,36 @@ public class GenericPOElementHandler extends AbstractElementHandler { stmt = DB.createStatement(); rs = stmt.executeQuery(sql); while (rs.next()) { - GenericPO po = new GenericPO(tableName, ctx, rs); + GenericPO po = new GenericPO(tableName, ctx.ctx, rs, getTrxName(ctx)); int AD_Client_ID = po.getAD_Client_ID(); - if (AD_Client_ID != Env.getAD_Client_ID(ctx)) + if (AD_Client_ID != Env.getAD_Client_ID(ctx.ctx)) continue; - addTypeName(atts, "table"); - document.startElement("","", tableName, atts); - PoExporter filler = new PoExporter(ctx, document, po); - filler.export(excludes, true); + + boolean createElement = true; + if (ctx.packOut.getFromDate() != null) { + if (po.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + createElement = false; + } + } + + if (createElement) { + addTypeName(atts, "table"); + document.startElement("","", tableName, atts); + PoExporter filler = new PoExporter(ctx, document, po); + filler.export(excludes, true); + if (po.get_ID() > 0 && po.get_ID() < 1000000) { + filler.add(tableName+"_ID", new AttributesImpl()); + } + } for (int i = 1; i < components.length; i++) { String tables[] = components[i].split("[>]"); exportDetail(ctx, document, po, 0, tables); } - document.endElement("","",tableName); + + if (createElement) { + document.endElement("","",tableName); + } } } catch (Exception e) { throw new AdempiereException(e); @@ -175,7 +260,7 @@ public class GenericPOElementHandler extends AbstractElementHandler { } } - private void exportDetail(Properties ctx, TransformerHandler document, GenericPO parent, int index, String[] tables) { + private void exportDetail(PIPOContext ctx, TransformerHandler document, GenericPO parent, int index, String[] tables) { AttributesImpl atts = new AttributesImpl(); String sql = "SELECT * FROM " + tables[index] + " WHERE " + parent.get_TableName() + "_ID = ?"; PreparedStatement pstmt = null; @@ -186,18 +271,30 @@ public class GenericPOElementHandler extends AbstractElementHandler { pstmt.setInt(1, parent.get_ID()); rs = pstmt.executeQuery(); while (rs.next()) { - GenericPO po = new GenericPO(tables[index], ctx, rs); + GenericPO po = new GenericPO(tables[index], ctx.ctx, rs, getTrxName(ctx)); int AD_Client_ID = po.getAD_Client_ID(); - if (AD_Client_ID != Env.getAD_Client_ID(ctx)) + if (AD_Client_ID != Env.getAD_Client_ID(ctx.ctx)) continue; - List excludes = defaultExcludeList(tables[index]); - document.startElement("", "", tables[index], atts); - PoExporter filler = new PoExporter(ctx, document, po); - filler.export(excludes, true); + + boolean createElement = true; + if (ctx.packOut.getFromDate() != null) { + if (po.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + createElement = false; + } + } + if (createElement) { + List excludes = defaultExcludeList(tables[index]); + addTypeName(atts, "table"); + document.startElement("", "", tables[index], atts); + PoExporter filler = new PoExporter(ctx, document, po); + filler.export(excludes, true); + } if (index + 1 < tables.length) { exportDetail(ctx, document, po, index+1, tables); } - document.endElement("","",tables[index]); + if (createElement) { + document.endElement("","",tables[index]); + } } } catch (Exception e) { throw new AdempiereException(e); @@ -210,10 +307,22 @@ public class GenericPOElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception { PackoutItem detail = packout.getCurrentPackoutItem(); - Env.setContext(packout.getCtx(), DataElementParameters.AD_TABLE_ID, (Integer)detail.getProperty(DataElementParameters.AD_TABLE_ID)); - Env.setContext(packout.getCtx(), DataElementParameters.SQL_STATEMENT, (String)detail.getProperty(DataElementParameters.SQL_STATEMENT)); + int tableId = 0; + String sql = null; + if (detail.getProperty(DataElementParameters.AD_TABLE_ID) != null) + { + tableId = (Integer)detail.getProperty(DataElementParameters.AD_TABLE_ID); + sql = (String)detail.getProperty(DataElementParameters.SQL_STATEMENT); + } + else + { + tableId = MTable.get(packout.getCtx().ctx, tableName).getAD_Table_ID(); + sql = "SELECT * FROM " + tableName + " WHERE " + tableName + "_ID=" + recordId; + } + packout.getCtx().ctx.put(DataElementParameters.AD_TABLE_ID, tableId); + packout.getCtx().ctx.put(DataElementParameters.SQL_STATEMENT, sql); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(DataElementParameters.AD_TABLE_ID); - packout.getCtx().remove(DataElementParameters.SQL_STATEMENT); + packout.getCtx().ctx.remove(DataElementParameters.AD_TABLE_ID); + packout.getCtx().ctx.remove(DataElementParameters.SQL_STATEMENT); } } \ No newline at end of file diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ImpFormatElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ImpFormatElementHandler.java index 50a5bd205f..dbc9538ea3 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ImpFormatElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ImpFormatElementHandler.java @@ -20,12 +20,12 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import java.util.logging.Level; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -48,7 +48,7 @@ public class ImpFormatElementHandler extends AbstractElementHandler { private List formats = new ArrayList(); - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { List excludes = defaultExcludeList(X_AD_ImpFormat.Table_Name); @@ -57,7 +57,7 @@ public class ImpFormatElementHandler extends AbstractElementHandler { 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, + mImpFormat = new X_AD_ImpFormat(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); } PoFiller filler = new PoFiller(ctx, mImpFormat, element, this); @@ -70,6 +70,7 @@ public class ImpFormatElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -89,27 +90,37 @@ public class ImpFormatElementHandler extends AbstractElementHandler { } else { logImportDetail(ctx, impDetail, 0, mImpFormat.getName(), mImpFormat .get_ID(), action); - throw new POSaveFailedException("Failed to save Import Format."); + throw new POSaveFailedException("Failed to save Import Format " + mImpFormat.getName()); } } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - protected void create(Properties ctx, TransformerHandler document) + protected void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int import_id = Env.getContextAsInt(ctx, + int import_id = Env.getContextAsInt(ctx.ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_ImpFormat_ID); if (formats.contains(import_id)) return; formats.add(import_id); AttributesImpl atts = new AttributesImpl(); - X_AD_ImpFormat m_ImpFormat = new X_AD_ImpFormat(ctx, import_id, null); - addTypeName(atts, "table"); - document.startElement("", "", I_AD_ImpFormat.Table_Name, atts); - createImpFormatBinding(ctx, document, m_ImpFormat); + X_AD_ImpFormat m_ImpFormat = new X_AD_ImpFormat(ctx.ctx, import_id, null); + + boolean createElement = true; + if (ctx.packOut.getFromDate() != null) { + if (m_ImpFormat.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + createElement = false; + } + } + + if (createElement) { + addTypeName(atts, "table"); + document.startElement("", "", I_AD_ImpFormat.Table_Name, atts); + createImpFormatBinding(ctx, document, m_ImpFormat); + } String sql = "SELECT * FROM AD_ImpFormat_Row WHERE AD_ImpFormat_ID= " + import_id; @@ -130,20 +141,23 @@ public class ImpFormatElementHandler extends AbstractElementHandler { } finally { DB.close(rs, pstmt); } - document.endElement("", "", I_AD_ImpFormat.Table_Name); + + if (createElement) { + document.endElement("", "", I_AD_ImpFormat.Table_Name); + } } - private void createImpFormatRow(Properties ctx, + private void createImpFormatRow(PIPOContext ctx, TransformerHandler document, int AD_ImpFormat_Row_ID) throws SAXException { - Env.setContext(ctx, X_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_Row_ID, + Env.setContext(ctx.ctx, X_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_Row_ID, AD_ImpFormat_Row_ID); rowHandler.create(ctx, document); - ctx.remove(X_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_Row_ID); + ctx.ctx.remove(X_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_Row_ID); } - private void createImpFormatBinding(Properties ctx, TransformerHandler document, + private void createImpFormatBinding(PIPOContext ctx, TransformerHandler document, X_AD_ImpFormat m_ImpFormat) { PoExporter filler = new PoExporter(ctx, document, m_ImpFormat); List excludes = defaultExcludeList(X_AD_ImpFormat.Table_Name); @@ -156,8 +170,8 @@ public class ImpFormatElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception { - Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_ImpFormat_ID, recordId); + Env.setContext(packout.getCtx().ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_ImpFormat_ID, recordId); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_ImpFormat_ID); + packout.getCtx().ctx.remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_ImpFormat_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ImpFormatRowElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ImpFormatRowElementHandler.java index 7538aa4932..7f57b62980 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ImpFormatRowElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ImpFormatRowElementHandler.java @@ -17,11 +17,11 @@ package org.adempiere.pipo2.handler; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -39,7 +39,7 @@ import org.xml.sax.helpers.AttributesImpl; public class ImpFormatRowElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) throws SAXException { + public void startElement(PIPOContext ctx, Element element) throws SAXException { String action = null; List excludes = defaultExcludeList(X_AD_ImpFormat_Row.Table_Name); @@ -57,20 +57,21 @@ public class ImpFormatRowElementHandler extends AbstractElementHandler { } 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, getTrxName(ctx)); + impFormatId = ReferenceUtils.resolveReference(ctx.ctx, e, getTrxName(ctx)); else impFormatId = findIdByName(ctx, "AD_ImpFormat", e.contents.toString()); } if (impFormatId <= 0) { element.defer = true; + element.unresolved = "AD_ImpFormat_ID"; return; } Element tableElement = element.properties.get(I_AD_ImpFormat.COLUMNNAME_AD_Table_ID); int tableId = 0; if (ReferenceUtils.isIDLookup(tableElement) || ReferenceUtils.isUUIDLookup(tableElement)) { - tableId = ReferenceUtils.resolveReference(ctx, tableElement, getTrxName(ctx)); + tableId = ReferenceUtils.resolveReference(ctx.ctx, tableElement, getTrxName(ctx)); } else { String tableName = getStringValue(element, I_AD_ImpFormat.COLUMNNAME_AD_Table_ID, excludes); @@ -79,6 +80,7 @@ public class ImpFormatRowElementHandler extends AbstractElementHandler { } if (tableId <= 0) { element.defer = true; + element.unresolved = "AD_Table_ID"; return; } } @@ -86,7 +88,7 @@ public class ImpFormatRowElementHandler extends AbstractElementHandler { 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, getTrxName(ctx)); + columnId = ReferenceUtils.resolveReference(ctx.ctx, columnElement, getTrxName(ctx)); } else { String columnName = getStringValue(element, I_AD_ImpFormat_Row.COLUMNNAME_AD_Column_ID, excludes); @@ -95,13 +97,14 @@ public class ImpFormatRowElementHandler extends AbstractElementHandler { } if (columnId <= 0) { element.defer = true; + element.unresolved = "AD_Column_ID"; 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 = new X_AD_ImpFormat_Row(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); mImpFormatRow.setAD_Column_ID(columnId); mImpFormatRow.setAD_ImpFormat_ID(impFormatId); @@ -115,6 +118,7 @@ public class ImpFormatRowElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -133,18 +137,25 @@ public class ImpFormatRowElementHandler extends AbstractElementHandler { } else{ logImportDetail (ctx, impDetail, 0, mImpFormatRow.getName(), mImpFormatRow.get_ID(),action); - throw new POSaveFailedException("Failed to import Import Format Row."); + throw new POSaveFailedException("Failed to save Import Format Row " + mImpFormatRow.getName()); } } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - 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)); + int AD_ImpFormat_Row_ID = Env.getContextAsInt(ctx.ctx, X_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_Row_ID); + X_AD_ImpFormat_Row m_ImpFormat_Row = new X_AD_ImpFormat_Row (ctx.ctx, AD_ImpFormat_Row_ID, getTrxName(ctx)); + + if (ctx.packOut.getFromDate() != null) { + if (m_ImpFormat_Row.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } + AttributesImpl atts = new AttributesImpl(); addTypeName(atts, "table"); document.startElement("","",I_AD_ImpFormat_Row.Table_Name,atts); @@ -152,12 +163,12 @@ public class ImpFormatRowElementHandler extends AbstractElementHandler { document.endElement("","",I_AD_ImpFormat_Row.Table_Name); } - private void createImpFormatRowBinding(Properties ctx, TransformerHandler document, X_AD_ImpFormat_Row m_ImpFormat_Row) + private void createImpFormatRowBinding(PIPOContext ctx, TransformerHandler document, X_AD_ImpFormat_Row m_ImpFormat_Row) { PoExporter filler = new PoExporter(ctx, document, m_ImpFormat_Row); List excludes = defaultExcludeList(X_AD_ImpFormat_Row.Table_Name); - String sql = null; + String sql = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?"; int tableId = DB.getSQLValue(null, sql,m_ImpFormat_Row.getAD_Column_ID()); filler.addTableReference("AD_Table_ID", "AD_Table", "TableName", tableId, new AttributesImpl()); @@ -174,8 +185,8 @@ public class ImpFormatRowElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler, int recordId) throws Exception { - Env.setContext(packout.getCtx(), I_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_Row_ID, recordId); + Env.setContext(packout.getCtx().ctx, I_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_Row_ID, recordId); create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(I_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_Row_ID); + packout.getCtx().ctx.remove(I_AD_ImpFormat_Row.COLUMNNAME_AD_ImpFormat_Row_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/MenuElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/MenuElementHandler.java index 1d9dd54337..25a64d74ad 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/MenuElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/MenuElementHandler.java @@ -20,7 +20,6 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.util.List; -import java.util.Properties; import java.util.logging.Level; import javax.xml.transform.sax.TransformerHandler; @@ -28,6 +27,7 @@ import javax.xml.transform.sax.TransformerHandler; import org.adempiere.exceptions.DBException; import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.ElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -52,7 +52,7 @@ import org.xml.sax.helpers.AttributesImpl; public class MenuElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { List excludes = defaultExcludeList(X_AD_Menu.Table_Name); @@ -61,7 +61,7 @@ public class MenuElementHandler extends AbstractElementHandler { 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)); + mMenu = new X_AD_Menu(ctx.ctx, menuId > 0 ? menuId : 0, getTrxName(ctx)); } PoFiller filler = new PoFiller(ctx, mMenu, element, this); @@ -73,6 +73,7 @@ public class MenuElementHandler extends AbstractElementHandler { List notFounds = filler.autoFill(excludes); if (notFounds.size() > 0) { element.defer = true; + element.unresolved = notFounds.toString(); return; } @@ -108,7 +109,7 @@ public class MenuElementHandler extends AbstractElementHandler { int parentId = 0; if (parentElement != null) { if (ReferenceUtils.isIDLookup(parentElement) || ReferenceUtils.isUUIDLookup(parentElement)) { - parentId = ReferenceUtils.resolveReference(ctx, parentElement, getTrxName(ctx)); + parentId = ReferenceUtils.resolveReference(ctx.ctx, parentElement, getTrxName(ctx)); } else { String parent = getStringValue(element, "Parent_ID"); parentId = findIdByName(ctx, "AD_Menu", parent); @@ -116,11 +117,12 @@ public class MenuElementHandler extends AbstractElementHandler { } StringBuffer updateSQL = null; - String sql = "SELECT count(Parent_ID) FROM AD_TREENODEMM WHERE AD_Tree_ID = 10" + int AD_Tree_ID = getDefaultMenuTreeId(); + String sql = "SELECT count(Parent_ID) FROM AD_TREENODEMM WHERE AD_Tree_ID = "+AD_Tree_ID + " AND Node_ID = " + mMenu.getAD_Menu_ID(); int countRecords = DB.getSQLValue(getTrxName(ctx), sql); if (countRecords > 0) { - sql = "select * from AD_TREENODEMM where AD_Tree_ID = 10 and " + sql = "select * from AD_TREENODEMM where AD_Tree_ID = "+AD_Tree_ID+" and " + " Node_ID =?"; PreparedStatement pstmt = null; ResultSet rs = null; @@ -154,9 +156,9 @@ public class MenuElementHandler extends AbstractElementHandler { colValue = obj == null ? "" : obj.toString(); } - X_AD_Package_Imp_Backup backup = new X_AD_Package_Imp_Backup(ctx, 0, getTrxName(ctx)); + X_AD_Package_Imp_Backup backup = new X_AD_Package_Imp_Backup(ctx.ctx, 0, getTrxName(ctx)); backup.setAD_Package_Imp_Detail_ID(impDetail.getAD_Package_Imp_Detail_ID()); - backup.setAD_Package_Imp_ID(getPackageImpId(ctx)); + backup.setAD_Package_Imp_ID(getPackageImpId(ctx.ctx)); backup.setAD_Table_ID(tableID); backup.setAD_Column_ID(columnID); backup.setAD_Reference_ID(referenceID); @@ -175,26 +177,30 @@ public class MenuElementHandler extends AbstractElementHandler { updateSQL = new StringBuffer("UPDATE AD_TREENODEMM ").append( "SET Parent_ID = " + parentId).append( " , SeqNo = " + getStringValue(element, "SeqNo")).append( - " WHERE AD_Tree_ID = 10").append( + " WHERE AD_Tree_ID = "+AD_Tree_ID).append( " AND Node_ID = " + mMenu.getAD_Menu_ID()); } else { updateSQL = new StringBuffer("Insert INTO AD_TREENODEMM").append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, ").append( "Parent_ID, SeqNo, AD_Tree_ID, Node_ID)").append( "VALUES(0, 0, 0, 0, ").append( - parentId + "," + getStringValue(element, "SeqNo") + ", 10, " + parentId + "," + getStringValue(element, "SeqNo") + ", "+AD_Tree_ID+", " + mMenu.getAD_Menu_ID() + ")"); } - DB.executeUpdateEx(updateSQL.toString(), getTrxName(ctx)); + DB.executeUpdate(updateSQL.toString(), getTrxName(ctx)); } - public void endElement(Properties ctx, Element element) throws SAXException { + private int getDefaultMenuTreeId() { + return DB.getSQLValue(null, "SELECT MIN(AD_Tree_ID) FROM AD_Tree WHERE IsDefault='Y' AND TreeType='MM' AND AD_Client_ID=0"); } - public void create(Properties ctx, TransformerHandler document) + public void endElement(PIPOContext ctx, Element element) throws SAXException { + } + + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int AD_Menu_ID = Env.getContextAsInt(ctx, "AD_Menu_ID"); - X_AD_Menu m_Menu = new X_AD_Menu(ctx, AD_Menu_ID, null); + int AD_Menu_ID = Env.getContextAsInt(ctx.ctx, "AD_Menu_ID"); + X_AD_Menu m_Menu = new X_AD_Menu(ctx.ctx, AD_Menu_ID, null); if (m_Menu.isSummary() == false) { createApplication(ctx, document, AD_Menu_ID); } else { @@ -207,17 +213,18 @@ public class MenuElementHandler extends AbstractElementHandler { } } - private void createMenuBinding(Properties ctx, TransformerHandler document, + private void createMenuBinding(PIPOContext ctx, TransformerHandler document, X_AD_Menu m_Menu) { PoExporter filler = new PoExporter(ctx, document, m_Menu); List excludes = defaultExcludeList(X_AD_Menu.Table_Name); - String sql = "SELECT Parent_ID FROM AD_TreeNoDemm WHERE AD_Tree_ID = 10 and Node_ID=?"; + int AD_Tree_ID = getDefaultMenuTreeId(); + String sql = "SELECT Parent_ID FROM AD_TreeNoDemm WHERE AD_Tree_ID = "+AD_Tree_ID+" and Node_ID=?"; int id = DB.getSQLValue(null, sql, m_Menu.getAD_Menu_ID()); if (id > 0) { filler.addTableReference("Parent_ID", "AD_Menu", "Name", id, new AttributesImpl()); } - sql = "SELECT SeqNo FROM AD_TreeNoDemm WHERE AD_Tree_ID = 10 and Node_ID=?"; + sql = "SELECT SeqNo FROM AD_TreeNoDemm WHERE AD_Tree_ID = "+AD_Tree_ID+" and Node_ID=?"; int seqNo = DB.getSQLValue(null, sql, m_Menu.getAD_Menu_ID()); filler.addString("SeqNo", Integer.toString(seqNo), new AttributesImpl()); if (m_Menu.getAD_Menu_ID() <= PackOut.MAX_OFFICIAL_ID) @@ -226,16 +233,16 @@ public class MenuElementHandler extends AbstractElementHandler { filler.export(excludes); } - private void createApplication(Properties ctx, TransformerHandler document, + private void createApplication(PIPOContext ctx, TransformerHandler document, int AD_Menu_ID) throws SAXException { - PackOut packOut = (PackOut)ctx.get("PackOutProcess"); + PackOut packOut = ctx.packOut; String sql = null; - // int x = 0; + int AD_Tree_ID = getDefaultMenuTreeId(); sql = "SELECT A.Node_ID, B.AD_Menu_ID, B.Name, B.AD_WINDOW_ID, B.AD_WORKFLOW_ID, B.AD_TASK_ID, " + "B.AD_PROCESS_ID, B.AD_FORM_ID, B.AD_WORKBENCH_ID " - + "FROM AD_TreeNoDemm A, AD_Menu B " + + "FROM AD_TreeNodeMM A, AD_Menu B " + "WHERE A.Node_ID = " - + AD_Menu_ID + " AND A.Node_ID = B.AD_Menu_ID"; + + AD_Menu_ID + " AND A.Node_ID = B.AD_Menu_ID" + " AND A.AD_Tree_ID="+AD_Tree_ID; PreparedStatement pstmt = null; ResultSet rs = null; @@ -244,7 +251,7 @@ public class MenuElementHandler extends AbstractElementHandler { rs = pstmt.executeQuery(); while (rs.next()) { - X_AD_Menu m_Menu = new X_AD_Menu(ctx, rs.getInt("AD_Menu_ID"), + X_AD_Menu m_Menu = new X_AD_Menu(ctx.ctx, rs.getInt("AD_Menu_ID"), null); AttributesImpl atts = new AttributesImpl(); addTypeName(atts, "table"); @@ -294,15 +301,16 @@ public class MenuElementHandler extends AbstractElementHandler { } } - public void createModule(Properties ctx, TransformerHandler document, + public void createModule(PIPOContext ctx, TransformerHandler document, int menu_id) throws SAXException { - PackOut packOut = (PackOut)ctx.get("PackOutProcess"); + PackOut packOut = ctx.packOut; String sql = null; + int AD_Tree_ID = getDefaultMenuTreeId(); sql = "SELECT A.Node_ID, B.AD_Menu_ID, B.Name, B.AD_WINDOW_ID, B.AD_WORKFLOW_ID, B.AD_TASK_ID, " + "B.AD_PROCESS_ID, B.AD_FORM_ID, B.AD_WORKBENCH_ID " - + "FROM AD_TreeNoDemm A, AD_Menu B " + + "FROM AD_TreeNodeMM A, AD_Menu B " + "WHERE A.Parent_ID = " - + menu_id + " AND A.Node_ID = B.AD_Menu_ID"; + + menu_id + " AND A.Node_ID = B.AD_Menu_ID" + " AND A.AD_Tree_ID="+AD_Tree_ID; PreparedStatement pstmt = null; ResultSet rs = null; @@ -311,7 +319,7 @@ public class MenuElementHandler extends AbstractElementHandler { rs = pstmt.executeQuery(); while (rs.next()) { // Menu tag Start. - X_AD_Menu m_Menu = new X_AD_Menu(ctx, rs.getInt("AD_Menu_ID"), + X_AD_Menu m_Menu = new X_AD_Menu(ctx.ctx, rs.getInt("AD_Menu_ID"), null); AttributesImpl atts = new AttributesImpl(); addTypeName(atts, "table"); @@ -364,9 +372,9 @@ public class MenuElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler, int recordId) throws Exception { - Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Menu_ID, recordId); + Env.setContext(packout.getCtx().ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Menu_ID, recordId); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Menu_ID); + packout.getCtx().ctx.remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Menu_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/MessageElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/MessageElementHandler.java index d59fa87a7e..ffdf1b8c07 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/MessageElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/MessageElementHandler.java @@ -18,11 +18,11 @@ package org.adempiere.pipo2.handler; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -41,15 +41,15 @@ public class MessageElementHandler extends AbstractElementHandler { private List messages = new ArrayList(); - public void startElement(Properties ctx, Element element) throws SAXException { + public void startElement(PIPOContext ctx, Element element) throws SAXException { String entitytype = getStringValue(element, "EntityType"); - if (isProcessElement(ctx, entitytype)) { + if (isProcessElement(ctx.ctx, entitytype)) { MMessage mMessage = findPO(ctx, element); if (mMessage == null) { String value = getStringValue(element, "Value"); int id = findIdByColumn(ctx, "AD_Message", "value", value); - mMessage = new MMessage(ctx, id > 0 ? id : 0, getTrxName(ctx)); + mMessage = new MMessage(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); } PoFiller filler = new PoFiller(ctx, mMessage, element, this); List excludes = defaultExcludeList(X_AD_Message.Table_Name); @@ -57,6 +57,7 @@ public class MessageElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -79,7 +80,7 @@ public class MessageElementHandler extends AbstractElementHandler { } else{ logImportDetail (ctx, impDetail, 0, mMessage.getValue(), mMessage.get_ID(),action); - throw new POSaveFailedException("Failed to save message."); + throw new POSaveFailedException("Failed to save message " + mMessage.getValue()); } } } else { @@ -88,24 +89,31 @@ public class MessageElementHandler extends AbstractElementHandler { } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int AD_Message_ID = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Message_ID); + int AD_Message_ID = Env.getContextAsInt(ctx.ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Message_ID); if (messages.contains(AD_Message_ID)) return; messages.add(AD_Message_ID); AttributesImpl atts = new AttributesImpl(); - X_AD_Message m_Message = new X_AD_Message (ctx, AD_Message_ID, null); + X_AD_Message m_Message = new X_AD_Message (ctx.ctx, AD_Message_ID, null); + + if (ctx.packOut.getFromDate() != null) { + if (m_Message.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } + addTypeName(atts, "table"); document.startElement("","",I_AD_Message.Table_Name,atts); createMessageBinding(ctx,document,m_Message); document.endElement("","",I_AD_Message.Table_Name); } - private void createMessageBinding(Properties ctx, TransformerHandler document, X_AD_Message m_Message) + private void createMessageBinding(PIPOContext ctx, TransformerHandler document, X_AD_Message m_Message) { PoExporter filler = new PoExporter(ctx, document, m_Message); if (m_Message.getAD_Message_ID() <= PackOut.MAX_OFFICIAL_ID) @@ -117,8 +125,8 @@ public class MessageElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception { - Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Message_ID, recordId); + Env.setContext(packout.getCtx().ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Message_ID, recordId); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Message_ID); + packout.getCtx().ctx.remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Message_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/OrgRoleElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/OrgRoleElementHandler.java index b947375dd7..bd60879237 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/OrgRoleElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/OrgRoleElementHandler.java @@ -17,12 +17,12 @@ package org.adempiere.pipo2.handler; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.Element; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.PoFiller; @@ -38,7 +38,7 @@ import org.xml.sax.helpers.AttributesImpl; public class OrgRoleElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) throws SAXException { + public void startElement(PIPOContext ctx, Element element) throws SAXException { List excludes = defaultExcludeList(X_AD_Role_OrgAccess.Table_Name); X_AD_Role_OrgAccess po = findPO(ctx, element); @@ -48,19 +48,25 @@ public class OrgRoleElementHandler extends AbstractElementHandler { roleId = getParentId(element, I_AD_Role.Table_Name); } else { Element roleElement = element.properties.get("AD_Role_ID"); - roleId = ReferenceUtils.resolveReference(ctx, roleElement, getTrxName(ctx)); + roleId = ReferenceUtils.resolveReference(ctx.ctx, roleElement, getTrxName(ctx)); + } + + if (roleId <= 0) { + element.defer = true; + element.unresolved = "AD_Role_ID"; + return; } Element orgElement = element.properties.get("AD_Org_ID"); - int orgId = ReferenceUtils.resolveReference(ctx, orgElement, getTrxName(ctx)); + int orgId = ReferenceUtils.resolveReference(ctx.ctx, orgElement, getTrxName(ctx)); - Query query = new Query(ctx, "AD_Role_OrgAccess", "AD_Role_ID=? and AD_Org_ID=?", getTrxName(ctx)); + Query query = new Query(ctx.ctx, "AD_Role_OrgAccess", "AD_Role_ID=? and AD_Org_ID=?", getTrxName(ctx)); po = query.setParameters(new Object[]{roleId, orgId}) .setClient_ID() .first(); if (po == null) { - po = new X_AD_Role_OrgAccess(ctx, 0, getTrxName(ctx)); + po = new X_AD_Role_OrgAccess(ctx.ctx, 0, getTrxName(ctx)); po.setAD_Org_ID(orgId); po.setAD_Role_ID(roleId); } @@ -72,37 +78,46 @@ public class OrgRoleElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } po.saveEx(); } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - 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(); - addTypeName(atts, "table"); - document.startElement("", "", I_AD_Role_OrgAccess.Table_Name, atts); - createOrgAccessBinding(ctx, document, AD_Org_ID, AD_Role_ID); - document.endElement("", "", I_AD_Role_OrgAccess.Table_Name); - + int AD_Org_ID = Env.getContextAsInt(ctx.ctx, "AD_Org_ID"); + int AD_Role_ID = Env.getContextAsInt(ctx.ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); + + Query query = new Query(ctx.ctx, "AD_Role_OrgAccess", "AD_Role_ID=? and AD_Org_ID=?", getTrxName(ctx)); + X_AD_Role_OrgAccess po = query.setParameters(new Object[]{AD_Role_ID, AD_Org_ID}).first(); + if (po != null) { + if (ctx.packOut.getFromDate() != null) { + if (po.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } + + AttributesImpl atts = new AttributesImpl(); + addTypeName(atts, "table"); + document.startElement("", "", I_AD_Role_OrgAccess.Table_Name, atts); + createOrgAccessBinding(ctx, document, po); + document.endElement("", "", I_AD_Role_OrgAccess.Table_Name); + } } - private void createOrgAccessBinding(Properties ctx, TransformerHandler document, - int orgId, int roleId) { - 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}).first(); + private void createOrgAccessBinding(PIPOContext ctx, TransformerHandler document, + X_AD_Role_OrgAccess po) { PoExporter filler = new PoExporter(ctx, document, po); AttributesImpl orgRefAtts = new AttributesImpl(); - String orgReference = ReferenceUtils.getTableReference("AD_Org", "Name", orgId, orgRefAtts); + String orgReference = ReferenceUtils.getTableReference("AD_Org", "Name", po.getAD_Org_ID(), orgRefAtts); filler.addString("AD_Org_ID", orgReference, orgRefAtts); AttributesImpl roleRefAtts = new AttributesImpl(); - String roleReference = ReferenceUtils.getTableReference("AD_Role", "Name", roleId, roleRefAtts); + String roleReference = ReferenceUtils.getTableReference("AD_Role", "Name", po.getAD_Role_ID(), roleRefAtts); filler.addString("AD_Role_ID", roleReference, roleRefAtts); List excludes = defaultExcludeList(X_AD_Role_OrgAccess.Table_Name); diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/PreferenceElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/PreferenceElementHandler.java index 341156315d..296935d75f 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/PreferenceElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/PreferenceElementHandler.java @@ -17,11 +17,11 @@ package org.adempiere.pipo2.handler; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -38,21 +38,22 @@ import org.xml.sax.helpers.AttributesImpl; public class PreferenceElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { List excludes = defaultExcludeList(X_AD_Preference.Table_Name); MPreference mPreference = findPO(ctx, element); if (mPreference == null) { - mPreference = new MPreference(ctx, 0, getTrxName(ctx)); + mPreference = new MPreference(ctx.ctx, 0, getTrxName(ctx)); PoFiller filler = new PoFiller(ctx, mPreference, element, this); List notFounds = filler.autoFill(excludes); if (notFounds.size() > 0) { element.defer = true; + element.unresolved = notFounds.toString(); return; } - Query query = new Query(ctx, "AD_Preference", "Attribute = ? AND coalesce(AD_User_ID,0) = ? AND coalesce(AD_Window_ID,0) = ?", getTrxName(ctx)); + Query query = new Query(ctx.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(); @@ -61,6 +62,7 @@ public class PreferenceElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } mPreference = tmp; @@ -70,6 +72,7 @@ public class PreferenceElementHandler extends AbstractElementHandler { List notFounds = filler.autoFill(excludes); if (notFounds.size() > 0) { element.defer = true; + element.unresolved = notFounds.toString(); return; } } @@ -94,28 +97,35 @@ public class PreferenceElementHandler extends AbstractElementHandler { } else { logImportDetail(ctx, impDetail, 0, mPreference.getAttribute(), mPreference.get_ID(), action); - throw new POSaveFailedException("Failed to save Preference"); + throw new POSaveFailedException("Failed to save Preference " + mPreference.getAttribute()); } } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int AD_Preference_ID = Env.getContextAsInt(ctx, + int AD_Preference_ID = Env.getContextAsInt(ctx.ctx, X_AD_Preference.COLUMNNAME_AD_Preference_ID); - X_AD_Preference m_Preference = new X_AD_Preference(ctx, + X_AD_Preference m_Preference = new X_AD_Preference(ctx.ctx, AD_Preference_ID, getTrxName(ctx)); + + if (ctx.packOut.getFromDate() != null) { + if (m_Preference.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } + AttributesImpl atts = new AttributesImpl(); addTypeName(atts, "table"); - document.startElement("", "", I_AD_Preference.Table_Name, atts); + document.startElement("", "", X_AD_Preference.Table_Name, atts); createPreferenceBinding(ctx, document, m_Preference); document.endElement("", "", I_AD_Preference.Table_Name); } - private void createPreferenceBinding(Properties ctx, TransformerHandler document, + private void createPreferenceBinding(PIPOContext ctx, TransformerHandler document, X_AD_Preference m_Preference) { PoExporter filler = new PoExporter(ctx, document, m_Preference); List excludes = defaultExcludeList(X_AD_Preference.Table_Name); @@ -130,9 +140,9 @@ public class PreferenceElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler, int recordId) throws Exception { - Env.setContext(packout.getCtx(), I_AD_Preference.COLUMNNAME_AD_Preference_ID, recordId); + Env.setContext(packout.getCtx().ctx, I_AD_Preference.COLUMNNAME_AD_Preference_ID, recordId); create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(I_AD_Preference.COLUMNNAME_AD_Preference_ID); + packout.getCtx().ctx.remove(I_AD_Preference.COLUMNNAME_AD_Preference_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/PrintFormatElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/PrintFormatElementHandler.java index be5134684c..d7c6ced3bc 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/PrintFormatElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/PrintFormatElementHandler.java @@ -21,24 +21,26 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.exceptions.DBException; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; 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.I_AD_PrintFormatItem; import org.compiere.model.I_AD_PrintPaper; +import org.compiere.model.I_AD_Table; import org.compiere.model.X_AD_Package_Exp_Detail; import org.compiere.model.X_AD_Package_Imp_Detail; import org.compiere.model.X_AD_PrintFormat; import org.compiere.model.X_AD_PrintFormatItem; +import org.compiere.print.MPrintFormat; +import org.compiere.print.MPrintFormatItem; import org.compiere.util.DB; import org.compiere.util.Env; import org.xml.sax.SAXException; @@ -48,14 +50,14 @@ public class PrintFormatElementHandler extends AbstractElementHandler { private List formats = new ArrayList(); - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { 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)); + mPrintFormat = new X_AD_PrintFormat(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); } PoFiller filler = new PoFiller(ctx, mPrintFormat, element, this); List excludes = defaultExcludeList(X_AD_PrintFormat.Table_Name); @@ -65,6 +67,7 @@ public class PrintFormatElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -85,17 +88,17 @@ public class PrintFormatElementHandler extends AbstractElementHandler { } else { logImportDetail(ctx, impDetail, 0, mPrintFormat.getName(), mPrintFormat.get_ID(), action); - throw new POSaveFailedException("Failed to save Print Format"); + throw new POSaveFailedException("Failed to save Print Format " + mPrintFormat.getName()); } } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int AD_PrintFormat_ID = Env.getContextAsInt(ctx, + int AD_PrintFormat_ID = Env.getContextAsInt(ctx.ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_PrintFormat_ID); if (formats.contains(AD_PrintFormat_ID)) @@ -103,17 +106,48 @@ public class PrintFormatElementHandler extends AbstractElementHandler { formats.add(AD_PrintFormat_ID); AttributesImpl atts = new AttributesImpl(); - X_AD_PrintFormat m_Printformat = new X_AD_PrintFormat(ctx, AD_PrintFormat_ID, null); + MPrintFormat m_Printformat = new MPrintFormat(ctx.ctx, AD_PrintFormat_ID, null); if (m_Printformat.getAD_PrintPaper_ID() > 0) { try { - getPackOut(ctx).getHandler(I_AD_PrintPaper.Table_Name).packOut(getPackOut(ctx), document, getLogDocument(ctx), m_Printformat.getAD_PrintPaper_ID()); + ctx.packOut.getHandler(I_AD_PrintPaper.Table_Name).packOut(ctx.packOut, document, ctx.logDocument, m_Printformat.getAD_PrintPaper_ID()); } catch (Exception e) { throw new SAXException(e); } } - addTypeName(atts, "table"); - document.startElement("", "", I_AD_PrintFormat.Table_Name, atts); - createPrintFormatBinding(ctx, document, m_Printformat); + + if (m_Printformat.getAD_Client_ID() == 0 && m_Printformat.getAD_Table_ID() > 0) { + try { + ctx.packOut.getHandler(I_AD_Table.Table_Name).packOut(ctx.packOut, document, ctx.logDocument, m_Printformat.getAD_Table_ID()); + } catch (Exception e) { + throw new SAXException(e); + } + } + + boolean createElement = true; + if (ctx.packOut.getFromDate() != null) { + if (m_Printformat.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + createElement = false; + } + } + + int size = m_Printformat.getItemCount(); + for(int i = 0; i < size; i++) { + MPrintFormatItem item = m_Printformat.getItem(i); + if (item.getAD_PrintFormatChild_ID() > 0) + { + try { + this.packOut(ctx.packOut, document, null, item.getAD_PrintFormatChild_ID()); + } catch (Exception e) { + throw new SAXException(e); + } + } + } + + if (createElement) { + addTypeName(atts, "table"); + 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= " + m_Printformat.getAD_PrintFormat_ID() @@ -131,21 +165,23 @@ public class PrintFormatElementHandler extends AbstractElementHandler { } finally { DB.close(rs, pstmt); } - document.endElement("", "", I_AD_PrintFormat.Table_Name); + if (createElement) { + document.endElement("", "", X_AD_PrintFormat.Table_Name); + } } - private void createItem(Properties ctx, TransformerHandler document, + private void createItem(PIPOContext ctx, TransformerHandler document, int AD_PrintFormatItem_ID) throws SAXException { try { - getPackOut(ctx).getHandler(I_AD_PrintFormatItem.Table_Name).packOut(getPackOut(ctx), document, getLogDocument(ctx), AD_PrintFormatItem_ID); + ctx.packOut.getHandler(X_AD_PrintFormatItem.Table_Name).packOut(ctx.packOut, document, ctx.logDocument, AD_PrintFormatItem_ID); } catch (Exception e) { throw new SAXException(e); } } - private void createPrintFormatBinding(Properties ctx, TransformerHandler document, - X_AD_PrintFormat m_Printformat) { + private void createPrintFormatBinding(PIPOContext ctx, TransformerHandler document, + MPrintFormat m_Printformat) { PoExporter filler = new PoExporter(ctx, document, m_Printformat); List excludes = defaultExcludeList(X_AD_PrintFormat.Table_Name); @@ -158,9 +194,9 @@ public class PrintFormatElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception { - Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_PrintFormat_ID, recordId); + Env.setContext(packout.getCtx().ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_PrintFormat_ID, recordId); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_PrintFormat_ID); + packout.getCtx().ctx.remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_PrintFormat_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/PrintFormatItemElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/PrintFormatItemElementHandler.java index 3b317d9218..8ab6dd648f 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/PrintFormatItemElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/PrintFormatItemElementHandler.java @@ -18,11 +18,11 @@ package org.adempiere.pipo2.handler; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -39,7 +39,7 @@ import org.xml.sax.helpers.AttributesImpl; public class PrintFormatItemElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { List excludes = defaultExcludeList(X_AD_PrintFormatItem.Table_Name); @@ -56,16 +56,17 @@ public class PrintFormatItemElementHandler extends AbstractElementHandler { 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, getTrxName(ctx)); + parentId = ReferenceUtils.resolveReference(ctx.ctx, pfElement, getTrxName(ctx)); } if (parentId <= 0) { element.defer = true; + element.unresolved = "AD_PrintFormat_ID"; 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 = new X_AD_PrintFormatItem(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); mPrintFormatItem.setAD_PrintFormat_ID(parentId); excludes.add(I_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormat_ID); } @@ -79,10 +80,10 @@ public class PrintFormatItemElementHandler extends AbstractElementHandler { int columnId = 0; Element columnElement = element.properties.get("AD_Column_ID"); if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) { - columnId = ReferenceUtils.resolveReference(ctx, columnElement, getTrxName(ctx)); + columnId = ReferenceUtils.resolveReference(ctx.ctx, columnElement, getTrxName(ctx)); } else { Element tableElement = element.properties.get("AD_Table_ID"); - int tableId = ReferenceUtils.resolveReference(ctx, tableElement, getTrxName(ctx)); + int tableId = ReferenceUtils.resolveReference(ctx.ctx, tableElement, getTrxName(ctx)); String columnName = getStringValue(element, "AD_Column_ID"); columnId = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnName, "AD_Table", tableId); @@ -92,7 +93,7 @@ public class PrintFormatItemElementHandler extends AbstractElementHandler { 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, getTrxName(ctx)); + int AD_PrintFormatChild_ID = ReferenceUtils.resolveReference(ctx.ctx, pfchildElement, getTrxName(ctx)); if (AD_PrintFormatChild_ID > 0) { mPrintFormatItem.setAD_PrintFormatChild_ID(AD_PrintFormatChild_ID); } else if (pfchildElement.contents != null && pfchildElement.contents.length() > 0) { @@ -105,6 +106,7 @@ public class PrintFormatItemElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -124,20 +126,27 @@ public class PrintFormatItemElementHandler extends AbstractElementHandler { } else { logImportDetail(ctx, impDetail, 0, mPrintFormatItem.getName(), mPrintFormatItem.get_ID(), action); - throw new POSaveFailedException("PrintFormatItem"); + throw new POSaveFailedException("Failed to save PrintFormatItem " + mPrintFormatItem.getName()); } } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int AD_PrintFormatItem_ID = Env.getContextAsInt(ctx, + int AD_PrintFormatItem_ID = Env.getContextAsInt(ctx.ctx, X_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormatItem_ID); - X_AD_PrintFormatItem m_PrintFormatItem = new X_AD_PrintFormatItem(ctx, + X_AD_PrintFormatItem m_PrintFormatItem = new X_AD_PrintFormatItem(ctx.ctx, AD_PrintFormatItem_ID, null); + + if (ctx.packOut.getFromDate() != null) { + if (m_PrintFormatItem.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } + AttributesImpl atts = new AttributesImpl(); addTypeName(atts, "table"); document.startElement("", "", I_AD_PrintFormatItem.Table_Name, atts); @@ -145,7 +154,7 @@ public class PrintFormatItemElementHandler extends AbstractElementHandler { document.endElement("", "", I_AD_PrintFormatItem.Table_Name); } - private void createPrintFormatItemBinding(Properties ctx, TransformerHandler document, + private void createPrintFormatItemBinding(PIPOContext ctx, TransformerHandler document, X_AD_PrintFormatItem mPrintformatItem) { PoExporter filler = new PoExporter(ctx, document, mPrintformatItem); @@ -154,12 +163,11 @@ public class PrintFormatItemElementHandler extends AbstractElementHandler { if (mPrintformatItem.getAD_PrintFormatItem_ID() <= PackOut.MAX_OFFICIAL_ID) filler.add("AD_PrintFormatItem_ID", new AttributesImpl()); - if (mPrintformatItem.getAD_Column_ID() > 0) { + if (mPrintformatItem.getAD_Client_ID() == 0 && mPrintformatItem.getAD_Column_ID() > 0) { String sql = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?"; int tableID = DB.getSQLValue(null, sql, mPrintformatItem.getAD_Column_ID()); AttributesImpl referenceAtts = new AttributesImpl(); - String value = ReferenceUtils.getTableReference("AD_Table", "TableName", tableID, referenceAtts); - filler.addString("AD_Table.TableName", value, referenceAtts); + filler.addTableReference("AD_Table_ID", "AD_Table", "TableName", tableID, referenceAtts); } filler.export(excludes); @@ -169,9 +177,9 @@ public class PrintFormatItemElementHandler extends AbstractElementHandler { TransformerHandler docHandler, int recordId) throws Exception { - Env.setContext(packout.getCtx(), X_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormatItem_ID, recordId); + Env.setContext(packout.getCtx().ctx, X_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormatItem_ID, recordId); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(X_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormatItem_ID); + packout.getCtx().ctx.remove(X_AD_PrintFormatItem.COLUMNNAME_AD_PrintFormatItem_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/PrintPaperElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/PrintPaperElementHandler.java index c6ac7876b3..f94b9b6ab2 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/PrintPaperElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/PrintPaperElementHandler.java @@ -18,11 +18,11 @@ package org.adempiere.pipo2.handler; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -37,7 +37,7 @@ import org.xml.sax.helpers.AttributesImpl; public class PrintPaperElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { List excludes = defaultExcludeList(X_AD_PrintPaper.Table_Name); @@ -48,7 +48,7 @@ public class PrintPaperElementHandler extends AbstractElementHandler { 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)); + printPaper = new X_AD_PrintPaper(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); } PoFiller filler = new PoFiller(ctx, printPaper, element, this); @@ -58,6 +58,7 @@ public class PrintPaperElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -76,20 +77,27 @@ public class PrintPaperElementHandler extends AbstractElementHandler { } else { logImportDetail(ctx, impDetail, 0, printPaper.getName(), printPaper.get_ID(), action); - throw new POSaveFailedException("PrintPaper"); + throw new POSaveFailedException("Failed to save PrintPaper " + printPaper.getName()); } } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int AD_PrintPaper_ID = Env.getContextAsInt(ctx, + int AD_PrintPaper_ID = Env.getContextAsInt(ctx.ctx, X_AD_PrintPaper.COLUMNNAME_AD_PrintPaper_ID); - X_AD_PrintPaper printPaper = new X_AD_PrintPaper(ctx, + X_AD_PrintPaper printPaper = new X_AD_PrintPaper(ctx.ctx, AD_PrintPaper_ID, null); + + if (ctx.packOut.getFromDate() != null) { + if (printPaper.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } + AttributesImpl atts = new AttributesImpl(); addTypeName(atts, "table"); document.startElement("", "", I_AD_PrintPaper.Table_Name, atts); @@ -97,7 +105,7 @@ public class PrintPaperElementHandler extends AbstractElementHandler { document.endElement("", "", I_AD_PrintPaper.Table_Name); } - private void createPrintPaperBinding(Properties ctx, TransformerHandler document, + private void createPrintPaperBinding(PIPOContext ctx, TransformerHandler document, X_AD_PrintPaper printPaper) { PoExporter filler = new PoExporter(ctx, document, printPaper); @@ -112,9 +120,9 @@ public class PrintPaperElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler, int recordId) throws Exception { - Env.setContext(packout.getCtx(), X_AD_PrintPaper.COLUMNNAME_AD_PrintPaper_ID, recordId); + Env.setContext(packout.getCtx().ctx, X_AD_PrintPaper.COLUMNNAME_AD_PrintPaper_ID, recordId); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(X_AD_PrintPaper.COLUMNNAME_AD_PrintPaper_ID); + packout.getCtx().ctx.remove(X_AD_PrintPaper.COLUMNNAME_AD_PrintPaper_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ProcessAccessElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ProcessAccessElementHandler.java index 873a8009af..08b0ce4db1 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ProcessAccessElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ProcessAccessElementHandler.java @@ -17,11 +17,11 @@ package org.adempiere.pipo2.handler; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; @@ -39,7 +39,7 @@ import org.xml.sax.helpers.AttributesImpl; public class ProcessAccessElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) throws SAXException { + public void startElement(PIPOContext ctx, Element element) throws SAXException { int roleid =0; int processid =0; List excludes = defaultExcludeList(X_AD_Process_Access.Table_Name); @@ -49,18 +49,29 @@ public class ProcessAccessElementHandler extends AbstractElementHandler { 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, getTrxName(ctx)); + Element roleElement = element.properties.get("AD_Role_ID"); + roleid = ReferenceUtils.resolveReference(ctx.ctx, roleElement, getTrxName(ctx)); + } + + if (roleid <= 0) { + element.defer = true; + element.unresolved = "AD_Role_ID"; + return; } Element processElement = element.properties.get(I_AD_Process_Access.COLUMNNAME_AD_Process_ID); - processid = ReferenceUtils.resolveReference(ctx, processElement, getTrxName(ctx)); + processid = ReferenceUtils.resolveReference(ctx.ctx, processElement, getTrxName(ctx)); + if (processid <= 0) { + element.defer = true; + element.unresolved = "AD_Process_ID " + (processElement.contents != null ? processElement.contents.toString() : ""); + return; + } - Query query = new Query(ctx, "AD_Process_Access", "AD_Role_ID=? and AD_Process_ID=?", getTrxName(ctx)); + Query query = new Query(ctx.ctx, "AD_Process_Access", "AD_Role_ID=? and AD_Process_ID=?", getTrxName(ctx)); po = query.setParameters(new Object[]{roleid, processid}).first(); if (po == null) { - po = new X_AD_Process_Access(ctx, 0, getTrxName(ctx)); + po = new X_AD_Process_Access(ctx.ctx, 0, getTrxName(ctx)); po.setAD_Process_ID(processid); po.setAD_Role_ID(roleid); } @@ -71,37 +82,45 @@ public class ProcessAccessElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } po.saveEx(); } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - 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(); - addTypeName(atts, "table"); - document.startElement("", "", I_AD_Process_Access.Table_Name, atts); - createProcessAccessBinding(ctx, document, AD_Process_ID, AD_Role_ID); - document.endElement("", "", I_AD_Process_Access.Table_Name); + int AD_Process_ID = Env.getContextAsInt(ctx.ctx, X_AD_Process.COLUMNNAME_AD_Process_ID); + int AD_Role_ID = Env.getContextAsInt(ctx.ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); + + X_AD_Process_Access po = null; + Query query = new Query(ctx.ctx, "AD_Process_Access", "AD_Role_ID=? and AD_Process_ID=?", getTrxName(ctx)); + po = query.setParameters(new Object[]{AD_Role_ID, AD_Process_ID}).first(); + + if (po != null) { + + if (ctx.packOut.getFromDate() != null) { + if (po.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } + + AttributesImpl atts = new AttributesImpl(); + addTypeName(atts, "table"); + document.startElement("", "", I_AD_Process_Access.Table_Name, atts); + createProcessAccessBinding(ctx, document, po); + document.endElement("", "", I_AD_Process_Access.Table_Name); + } } - private void createProcessAccessBinding(Properties ctx, TransformerHandler document, - int process_id, int role_id) { - - 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[]{role_id, process_id}).first(); - if (po != null) - { - PoExporter filler = new PoExporter(ctx, document, po); - List excludes = defaultExcludeList(X_AD_Process_Access.Table_Name); - filler.export(excludes); - } + private void createProcessAccessBinding(PIPOContext ctx, TransformerHandler document, + X_AD_Process_Access po) { + PoExporter filler = new PoExporter(ctx, document, po); + List excludes = defaultExcludeList(X_AD_Process_Access.Table_Name); + filler.export(excludes); } @Override diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ProcessElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ProcessElementHandler.java index 9fd7cb9162..d1f2feb539 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ProcessElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ProcessElementHandler.java @@ -18,13 +18,13 @@ package org.adempiere.pipo2.handler; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.exceptions.AdempiereException; import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.ElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -51,17 +51,17 @@ public class ProcessElementHandler extends AbstractElementHandler { private List processes = new ArrayList(); - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { String entitytype = getStringValue(element, "EntityType"); - if (isProcessElement(ctx, entitytype)) { + if (isProcessElement(ctx.ctx, entitytype)) { X_AD_Process mProcess = findPO(ctx, element); if (mProcess == null) { String value = getStringValue(element, "Value"); // Get New process. int id = findIdByColumn(ctx, "AD_Process", "Value", value); - mProcess = new X_AD_Process(ctx, id > 0 ? id : 0, getTrxName(ctx)); + mProcess = new X_AD_Process(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); } if (mProcess.getAD_Process_ID() == 0 && isOfficialId(element, "AD_Process_ID")) @@ -73,6 +73,7 @@ public class ProcessElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -94,7 +95,7 @@ public class ProcessElementHandler extends AbstractElementHandler { } else { logImportDetail(ctx, impDetail, 0, mProcess.getName(), mProcess .get_ID(), action); - throw new POSaveFailedException("Process"); + throw new POSaveFailedException("Failed to save Process " + mProcess.getName()); } } } else { @@ -102,18 +103,18 @@ public class ProcessElementHandler extends AbstractElementHandler { } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int AD_Process_ID = Env.getContextAsInt(ctx, "AD_Process_ID"); + int AD_Process_ID = Env.getContextAsInt(ctx.ctx, "AD_Process_ID"); if (processes.contains(AD_Process_ID)) return; processes.add(AD_Process_ID); - PackOut packOut = getPackOut(ctx); + PackOut packOut = ctx.packOut; - X_AD_Process m_Process = new X_AD_Process(ctx, AD_Process_ID, getTrxName(ctx)); + X_AD_Process m_Process = new X_AD_Process(ctx.ctx, AD_Process_ID, getTrxName(ctx)); AttributesImpl atts = new AttributesImpl(); @@ -132,11 +133,22 @@ public class ProcessElementHandler extends AbstractElementHandler { ElementHandler handler = packOut.getHandler(I_AD_Workflow.Table_Name); handler.packOut(packOut,document,null,m_Process.getAD_Workflow_ID()); } + + boolean createElement = true; + + if (ctx.packOut.getFromDate() != null) { + if (m_Process.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + createElement = false; + } + } + + if (createElement) { addTypeName(atts, "table"); 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)); + Query query = new Query(ctx.ctx, "AD_Process_PARA", "AD_Process_ID = ?", getTrxName(ctx)); List paralist = query.setParameters(new Object[]{AD_Process_ID}).list(); for (X_AD_Process_Para para : paralist) { if (para.getAD_Reference_ID()>0) @@ -160,22 +172,24 @@ public class ProcessElementHandler extends AbstractElementHandler { createProcessPara(ctx, document, para.getAD_Process_Para_ID()); } - document.endElement("", "", I_AD_Process.Table_Name); + if (createElement) { + document.endElement("", "", X_AD_Process.Table_Name); + } } catch (Exception e) { throw new AdempiereException(e); } } - private void createProcessPara(Properties ctx, TransformerHandler document, + private void createProcessPara(PIPOContext ctx, TransformerHandler document, int AD_Process_Para_ID) throws SAXException { - Env.setContext(ctx, X_AD_Process_Para.COLUMNNAME_AD_Process_Para_ID, + Env.setContext(ctx.ctx, X_AD_Process_Para.COLUMNNAME_AD_Process_Para_ID, AD_Process_Para_ID); paraHandler.create(ctx, document); - ctx.remove(X_AD_Process_Para.COLUMNNAME_AD_Process_Para_ID); + ctx.ctx.remove(X_AD_Process_Para.COLUMNNAME_AD_Process_Para_ID); } - private void createProcessBinding(Properties ctx, TransformerHandler document, + private void createProcessBinding(PIPOContext ctx, TransformerHandler document, X_AD_Process m_Process) { PoExporter filler = new PoExporter(ctx, document, m_Process); List excludes = defaultExcludeList(X_AD_Process.Table_Name); @@ -188,8 +202,8 @@ public class ProcessElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception { - Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Process_ID, recordId); + Env.setContext(packout.getCtx().ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Process_ID, recordId); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Process_ID); + packout.getCtx().ctx.remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Process_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ProcessParaElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ProcessParaElementHandler.java index 8cf8e6e074..692c54b3d0 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ProcessParaElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ProcessParaElementHandler.java @@ -17,13 +17,12 @@ package org.adempiere.pipo2.handler; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; -import org.adempiere.exceptions.AdempiereException; import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.ElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -41,12 +40,12 @@ import org.xml.sax.helpers.AttributesImpl; public class ProcessParaElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { List excludes = defaultExcludeList(X_AD_Process_Para.Table_Name); String entitytype = getStringValue(element, "EntityType"); - if (isProcessElement(ctx, entitytype)) { + if (isProcessElement(ctx.ctx, entitytype)) { if (isParentDefer(element, I_AD_Process.Table_Name)) { element.defer = true; return; @@ -54,15 +53,15 @@ public class ProcessParaElementHandler extends AbstractElementHandler { X_AD_Process_Para mProcessPara = findPO(ctx, element); if (mProcessPara == null) { - String name = getStringValue(element, "Name"); + String name = getStringValue(element, "ColumnName"); int id = 0; int masterId = 0; if (getParentId(element, I_AD_Process.Table_Name) > 0) { - masterId = getParentId(element, "process"); + masterId = getParentId(element, I_AD_Process.Table_Name); } else { Element processElement = element.properties.get(I_AD_Process_Para.COLUMNNAME_AD_Process_ID); - masterId = ReferenceUtils.resolveReference(ctx, processElement, getTrxName(ctx)); + masterId = ReferenceUtils.resolveReference(ctx.ctx, processElement, getTrxName(ctx)); } if (masterId <= 0) { element.defer = true; @@ -70,8 +69,8 @@ public class ProcessParaElementHandler extends AbstractElementHandler { 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)); + id = findIdByColumnAndParentId(ctx, "AD_Process_Para", "ColumnName", name, "AD_Process", masterId); + mProcessPara = new X_AD_Process_Para(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); mProcessPara.setAD_Process_ID(masterId); excludes.add(I_AD_Process_Para.COLUMNNAME_AD_Process_ID); } @@ -84,6 +83,7 @@ public class ProcessParaElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -99,12 +99,12 @@ public class ProcessParaElementHandler extends AbstractElementHandler { action = "New"; } if (mProcessPara.save(getTrxName(ctx)) == true) { - logImportDetail(ctx, impDetail, 1, mProcessPara.getName(), + logImportDetail(ctx, impDetail, 1, mProcessPara.getColumnName(), mProcessPara.get_ID(), action); } else { - logImportDetail(ctx, impDetail, 0, mProcessPara.getName(), + logImportDetail(ctx, impDetail, 0, mProcessPara.getColumnName(), mProcessPara.get_ID(), action); - throw new POSaveFailedException("ProcessPara"); + throw new POSaveFailedException("Failed to save ProcessPara " + mProcessPara.getColumnName()); } } } else { @@ -112,23 +112,29 @@ public class ProcessParaElementHandler extends AbstractElementHandler { } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int AD_Process_Para_ID = Env.getContextAsInt(ctx, + int AD_Process_Para_ID = Env.getContextAsInt(ctx.ctx, X_AD_Process_Para.COLUMNNAME_AD_Process_Para_ID); - X_AD_Process_Para m_Processpara = new X_AD_Process_Para(ctx, + X_AD_Process_Para m_Processpara = new X_AD_Process_Para(ctx.ctx, AD_Process_Para_ID, getTrxName(ctx)); if (m_Processpara.getAD_Element_ID() > 0) { - PackOut packOut = getPackOut(ctx); + PackOut packOut = ctx.packOut; ElementHandler handler = packOut.getHandler(I_AD_Element.Table_Name); try { handler.packOut(packOut,document,null,m_Processpara.getAD_Element_ID()); } catch (Exception e) { - throw new AdempiereException(e); + throw new RuntimeException(e); + } + } + + if (ctx.packOut.getFromDate() != null) { + if (m_Processpara.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; } } AttributesImpl atts = new AttributesImpl(); @@ -138,7 +144,7 @@ public class ProcessParaElementHandler extends AbstractElementHandler { document.endElement("", "", I_AD_Process_Para.Table_Name); } - private void createProcessParaBinding(Properties ctx, TransformerHandler document, + private void createProcessParaBinding(PIPOContext ctx, TransformerHandler document, X_AD_Process_Para m_Processpara) { PoExporter filler = new PoExporter(ctx, document, m_Processpara); @@ -153,8 +159,8 @@ public class ProcessParaElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler, int recordId) throws Exception { - Env.setContext(packout.getCtx(), I_AD_Process_Para.COLUMNNAME_AD_Process_Para_ID, recordId); + Env.setContext(packout.getCtx().ctx, I_AD_Process_Para.COLUMNNAME_AD_Process_Para_ID, recordId); create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(I_AD_Process_Para.COLUMNNAME_AD_Process_Para_ID); + packout.getCtx().ctx.remove(I_AD_Process_Para.COLUMNNAME_AD_Process_Para_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ReferenceElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ReferenceElementHandler.java index 82011f0f43..0a7a19fe1a 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ReferenceElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ReferenceElementHandler.java @@ -21,12 +21,12 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import java.util.logging.Level; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -51,17 +51,17 @@ public class ReferenceElementHandler extends AbstractElementHandler { private List references = new ArrayList(); - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { String entitytype = getStringValue(element, "EntityType"); String name = getStringValue(element, "Name"); - if (isProcessElement(ctx, entitytype)) { + if (isProcessElement(ctx.ctx, entitytype)) { 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)); + mReference = new X_AD_Reference(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); } List excludes = defaultExcludeList(X_AD_Reference.Table_Name); if (mReference.getAD_Reference_ID() == 0 && isOfficialId(element, "AD_Reference_ID")) @@ -71,6 +71,7 @@ public class ReferenceElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -96,7 +97,7 @@ public class ReferenceElementHandler extends AbstractElementHandler { } else { logImportDetail(ctx, impDetail, 0, mReference.getName(), mReference.get_ID(), action); - throw new POSaveFailedException("Reference"); + throw new POSaveFailedException("Failed to save Reference " + mReference.getName()); } } } else { @@ -104,12 +105,12 @@ public class ReferenceElementHandler extends AbstractElementHandler { } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int Reference_id = Env.getContextAsInt(ctx, + int Reference_id = Env.getContextAsInt(ctx.ctx, X_AD_Reference.COLUMNNAME_AD_Reference_ID); if (references.contains(Reference_id)) @@ -118,11 +119,20 @@ public class ReferenceElementHandler extends AbstractElementHandler { references.add(Reference_id); AttributesImpl atts = new AttributesImpl(); - X_AD_Reference m_Reference = new X_AD_Reference(ctx, Reference_id, getTrxName(ctx)); + X_AD_Reference m_Reference = new X_AD_Reference(ctx.ctx, Reference_id, getTrxName(ctx)); - addTypeName(atts, "table"); - document.startElement("", "", I_AD_Reference.Table_Name, atts); - createReferenceBinding(ctx, document, m_Reference); + boolean createElement = true; + if (ctx.packOut.getFromDate() != null) { + if (m_Reference.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + createElement = false; + } + } + + if (createElement) { + addTypeName(atts, "table"); + document.startElement("", "", I_AD_Reference.Table_Name, atts); + createReferenceBinding(ctx, document, m_Reference); + } if (m_Reference.getValidationType().compareTo("L") == 0) { String sql1 = "SELECT AD_REF_LIST_ID FROM AD_Ref_List WHERE AD_Reference_ID= " @@ -156,27 +166,29 @@ public class ReferenceElementHandler extends AbstractElementHandler { } else if (m_Reference.getValidationType().compareTo("T") == 0) { createReferenceTable(ctx, document, Reference_id); } - document.endElement("", "", I_AD_Reference.Table_Name); + if (createElement) { + document.endElement("", "", X_AD_Reference.Table_Name); + } } - private void createReferenceTable(Properties ctx, TransformerHandler document, + private void createReferenceTable(PIPOContext ctx, TransformerHandler document, int reference_id) throws SAXException { - Env.setContext(ctx, X_AD_Ref_Table.COLUMNNAME_AD_Reference_ID, reference_id); + Env.setContext(ctx.ctx, X_AD_Ref_Table.COLUMNNAME_AD_Reference_ID, reference_id); tableHandler.create(ctx, document); - ctx.remove(X_AD_Ref_Table.COLUMNNAME_AD_Reference_ID); + ctx.ctx.remove(X_AD_Ref_Table.COLUMNNAME_AD_Reference_ID); } - private void createReferenceList(Properties ctx, + private void createReferenceList(PIPOContext ctx, TransformerHandler document, int AD_Ref_List_ID) throws SAXException { - Env.setContext(ctx, X_AD_Ref_List.COLUMNNAME_AD_Ref_List_ID, + Env.setContext(ctx.ctx, X_AD_Ref_List.COLUMNNAME_AD_Ref_List_ID, AD_Ref_List_ID); listHandler.create(ctx, document); - ctx.remove(X_AD_Ref_List.COLUMNNAME_AD_Ref_List_ID); + ctx.ctx.remove(X_AD_Ref_List.COLUMNNAME_AD_Ref_List_ID); } - private void createReferenceBinding(Properties ctx, TransformerHandler document, + private void createReferenceBinding(PIPOContext ctx, TransformerHandler document, X_AD_Reference m_Reference) { List excludes = defaultExcludeList(X_AD_Reference.Table_Name); PoExporter filler = new PoExporter(ctx, document, m_Reference); @@ -188,8 +200,8 @@ public class ReferenceElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception { - Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Reference_ID, recordId); + Env.setContext(packout.getCtx().ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Reference_ID, recordId); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Reference_ID); + packout.getCtx().ctx.remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Reference_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ReferenceListElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ReferenceListElementHandler.java index c7c1774fb2..0fe4dffd66 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ReferenceListElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ReferenceListElementHandler.java @@ -17,11 +17,11 @@ package org.adempiere.pipo2.handler; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -38,15 +38,15 @@ import org.xml.sax.helpers.AttributesImpl; public class ReferenceListElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { String entitytype = getStringValue(element, "EntityType"); - if (isProcessElement(ctx, entitytype)) { - if (isParentSkip(element, null)) { + if (isProcessElement(ctx.ctx, entitytype)) { + /*if (isParentSkip(element, null)) { element.skip = true; return; - } + }*/ X_AD_Ref_List mRefList = findPO(ctx, element); if (mRefList == null) { @@ -56,11 +56,11 @@ public class ReferenceListElementHandler extends AbstractElementHandler { 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, getTrxName(ctx)); + AD_Reference_ID = ReferenceUtils.resolveReference(ctx.ctx, referenceElement, getTrxName(ctx)); } 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)); + mRefList = new X_AD_Ref_List(ctx.ctx, AD_Ref_List_ID, getTrxName(ctx)); } if (mRefList.getAD_Ref_List_ID() == 0 && isOfficialId(element, "AD_Ref_List_ID")) @@ -71,6 +71,7 @@ public class ReferenceListElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -90,7 +91,7 @@ public class ReferenceListElementHandler extends AbstractElementHandler { } else { logImportDetail(ctx, impDetail, 0, mRefList.getName(), mRefList.get_ID(), action); - throw new POSaveFailedException("ReferenceList"); + throw new POSaveFailedException("Failed to save ReferenceList " + mRefList.getName()); } } } else { @@ -98,15 +99,20 @@ public class ReferenceListElementHandler extends AbstractElementHandler { } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int AD_Ref_List_ID = Env.getContextAsInt(ctx, + int AD_Ref_List_ID = Env.getContextAsInt(ctx.ctx, X_AD_Ref_List.COLUMNNAME_AD_Ref_List_ID); - X_AD_Ref_List m_Ref_List = new X_AD_Ref_List(ctx, AD_Ref_List_ID, + X_AD_Ref_List m_Ref_List = new X_AD_Ref_List(ctx.ctx, AD_Ref_List_ID, getTrxName(ctx)); + if (ctx.packOut.getFromDate() != null) { + if (m_Ref_List.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } AttributesImpl atts = new AttributesImpl(); addTypeName(atts, "table"); document.startElement("", "", I_AD_Ref_List.Table_Name, atts); @@ -114,7 +120,7 @@ public class ReferenceListElementHandler extends AbstractElementHandler { document.endElement("", "", I_AD_Ref_List.Table_Name); } - private void createRefListBinding(Properties ctx, TransformerHandler document, + private void createRefListBinding(PIPOContext ctx, TransformerHandler document, X_AD_Ref_List m_Ref_List) { List excludes = defaultExcludeList(X_AD_Ref_List.Table_Name); PoExporter filler = new PoExporter(ctx, document, m_Ref_List); @@ -128,8 +134,8 @@ public class ReferenceListElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler, int recordId) throws Exception { - Env.setContext(packout.getCtx(), I_AD_Ref_List.COLUMNNAME_AD_Ref_List_ID, recordId); + Env.setContext(packout.getCtx().ctx, I_AD_Ref_List.COLUMNNAME_AD_Ref_List_ID, recordId); create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(I_AD_Ref_List.COLUMNNAME_AD_Ref_List_ID); + packout.getCtx().ctx.remove(I_AD_Ref_List.COLUMNNAME_AD_Ref_List_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ReferenceTableElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ReferenceTableElementHandler.java index 11d72e123a..0563369cf8 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ReferenceTableElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ReferenceTableElementHandler.java @@ -19,12 +19,12 @@ package org.adempiere.pipo2.handler; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.List; -import java.util.Properties; import java.util.logging.Level; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -35,6 +35,7 @@ import org.compiere.model.I_AD_Ref_Table; import org.compiere.model.I_AD_Reference; import org.compiere.model.X_AD_Package_Imp_Detail; import org.compiere.model.X_AD_Ref_Table; +import org.compiere.model.X_AD_Reference; import org.compiere.util.DB; import org.compiere.util.Env; import org.xml.sax.SAXException; @@ -42,13 +43,13 @@ import org.xml.sax.helpers.AttributesImpl; public class ReferenceTableElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { List excludes = defaultExcludeList(X_AD_Ref_Table.Table_Name); String entitytype = getStringValue(element, "EntityType"); - if (isProcessElement(ctx, entitytype)) { + if (isProcessElement(ctx.ctx, entitytype)) { if (isParentSkip(element, null)) { element.skip = true; return; @@ -61,7 +62,7 @@ public class ReferenceTableElementHandler extends AbstractElementHandler { AD_Reference_ID = getParentId(element, I_AD_Reference.Table_Name); } else { Element referenceElement = element.properties.get(I_AD_Ref_Table.COLUMNNAME_AD_Reference_ID); - AD_Reference_ID = ReferenceUtils.resolveReference(ctx, referenceElement, getTrxName(ctx)); + AD_Reference_ID = ReferenceUtils.resolveReference(ctx.ctx, referenceElement, getTrxName(ctx)); } if (AD_Reference_ID <= 0 && isOfficialId(element, "AD_Reference_ID")) AD_Reference_ID = getIntValue(element, "AD_Reference_ID"); @@ -74,9 +75,9 @@ public class ReferenceTableElementHandler extends AbstractElementHandler { pstmt.setInt(1, AD_Reference_ID); rs = pstmt.executeQuery(); if (rs.next()) { - refTable = new X_AD_Ref_Table(ctx, rs, getTrxName(ctx)); + refTable = new X_AD_Ref_Table(ctx.ctx, rs, getTrxName(ctx)); } else { - refTable = new X_AD_Ref_Table(ctx, 0, getTrxName(ctx)); + refTable = new X_AD_Ref_Table(ctx.ctx, 0, getTrxName(ctx)); } } catch (Exception e) { throw new DatabaseAccessException(e.getLocalizedMessage(), e); @@ -89,13 +90,14 @@ public class ReferenceTableElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } int tableId = refTable.getAD_Table_ID(); Element displayElement = element.properties.get("AD_Display"); int displayColumnId = 0; if (ReferenceUtils.isIDLookup(displayElement) || ReferenceUtils.isUUIDLookup(displayElement)) { - displayColumnId = ReferenceUtils.resolveReference(ctx, displayElement, getTrxName(ctx)); + displayColumnId = ReferenceUtils.resolveReference(ctx.ctx, displayElement, getTrxName(ctx)); } else { displayColumnId = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", displayElement.contents.toString(), "AD_Table", tableId); } @@ -105,7 +107,7 @@ public class ReferenceTableElementHandler extends AbstractElementHandler { Element keyElement = element.properties.get("AD_Key"); int keyColumnId = 0; if (ReferenceUtils.isIDLookup(keyElement) || ReferenceUtils.isUUIDLookup(keyElement)) { - keyColumnId = ReferenceUtils.resolveReference(ctx, keyElement, getTrxName(ctx)); + keyColumnId = ReferenceUtils.resolveReference(ctx.ctx, keyElement, getTrxName(ctx)); } else { keyColumnId = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", keyElement.contents.toString(), "AD_Table", tableId); } @@ -117,35 +119,27 @@ public class ReferenceTableElementHandler extends AbstractElementHandler { 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, refTable.getAD_Reference().getName(), refTable.getAD_Reference_ID(), action); + int AD_Reference_ID = refTable.getAD_Reference_ID(); + X_AD_Reference adReference = new X_AD_Reference(ctx.ctx, AD_Reference_ID, getTrxName(ctx)); + logImportDetail(ctx, impDetail, 1, adReference.getName(), refTable.getAD_Reference_ID(), action); } } else { element.skip = true; } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int Reference_id = Env.getContextAsInt(ctx, - X_AD_Ref_Table.COLUMNNAME_AD_Reference_ID); - AttributesImpl atts = new AttributesImpl(); - addTypeName(atts, "table"); - document.startElement("", "", I_AD_Ref_Table.Table_Name, atts); + int Reference_id = Env.getContextAsInt(ctx.ctx, "AD_Reference_ID"); createReferenceTableBinding(ctx, document, Reference_id); - document.endElement("", "", I_AD_Ref_Table.Table_Name); } - private void createReferenceTableBinding(Properties ctx, + private void createReferenceTableBinding(PIPOContext ctx, TransformerHandler document, int reference_ID) { - if (reference_ID <= PackOut.MAX_OFFICIAL_ID) - { - PoExporter filler = new PoExporter(ctx,document,null); - filler.addString("AD_Reference_ID", Integer.toString(reference_ID), new AttributesImpl()); - } String sql = "SELECT * FROM AD_Ref_Table WHERE AD_Reference_ID= " + reference_ID; @@ -155,7 +149,23 @@ public class ReferenceTableElementHandler extends AbstractElementHandler { pstmt = DB.prepareStatement(sql, getTrxName(ctx)); rs = pstmt.executeQuery(); if (rs.next()) { - X_AD_Ref_Table refTable = new X_AD_Ref_Table(ctx, rs, getTrxName(ctx)); + X_AD_Ref_Table refTable = new X_AD_Ref_Table(ctx.ctx, rs, getTrxName(ctx)); + if (ctx.packOut.getFromDate() != null) { + if (refTable.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } + + AttributesImpl atts = new AttributesImpl(); + addTypeName(atts, "table"); + document.startElement("", "", X_AD_Ref_Table.Table_Name, atts); + + if (reference_ID <= PackOut.MAX_OFFICIAL_ID) + { + PoExporter filler = new PoExporter(ctx,document,null); + filler.addString("AD_Reference_ID", Integer.toString(reference_ID), new AttributesImpl()); + } + PoExporter filler = new PoExporter(ctx,document,refTable); List excludes = defaultExcludeList(X_AD_Ref_Table.Table_Name); excludes.add("ad_display"); @@ -163,6 +173,8 @@ public class ReferenceTableElementHandler extends AbstractElementHandler { filler.export(excludes); filler.addTableReference("AD_Display", "AD_Column", "ColumnName", new AttributesImpl()); filler.addTableReference("AD_Key", "AD_Column", "ColumnName", new AttributesImpl()); + + document.endElement("", "", X_AD_Ref_Table.Table_Name); } } catch (Exception e) { log.log(Level.SEVERE, e.getLocalizedMessage(), e); @@ -176,8 +188,8 @@ public class ReferenceTableElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler, int recordId) throws Exception { - Env.setContext(packout.getCtx(), I_AD_Ref_Table.COLUMNNAME_AD_Reference_ID, recordId); + Env.setContext(packout.getCtx().ctx, I_AD_Ref_Table.COLUMNNAME_AD_Reference_ID, recordId); create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(I_AD_Ref_Table.COLUMNNAME_AD_Reference_ID); + packout.getCtx().ctx.remove(I_AD_Ref_Table.COLUMNNAME_AD_Reference_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ReportViewColElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ReportViewColElementHandler.java index 9bf1ec3301..d48260fa19 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ReportViewColElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ReportViewColElementHandler.java @@ -17,11 +17,11 @@ package org.adempiere.pipo2.handler; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -30,6 +30,7 @@ import org.adempiere.pipo2.ReferenceUtils; import org.adempiere.pipo2.exception.POSaveFailedException; import org.compiere.model.I_AD_ReportView; import org.compiere.model.I_AD_ReportView_Col; +import org.compiere.model.MColumn; import org.compiere.model.X_AD_Package_Imp_Detail; import org.compiere.model.X_AD_ReportView_Col; import org.compiere.util.DB; @@ -39,12 +40,12 @@ import org.xml.sax.helpers.AttributesImpl; public class ReportViewColElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { List excludes = defaultExcludeList(X_AD_ReportView_Col.Table_Name); String entitytype = getStringValue(element,"EntityType"); - if (isProcessElement(ctx, entitytype)) { + if (isProcessElement(ctx.ctx, entitytype)) { excludes.add("AD_Table_ID"); X_AD_ReportView_Col mReportviewCol = findPO(ctx, element); if (mReportviewCol == null) { @@ -53,25 +54,27 @@ public class ReportViewColElementHandler extends AbstractElementHandler { 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, getTrxName(ctx)); + AD_ReportView_ID = ReferenceUtils.resolveReference(ctx.ctx, rvElement, getTrxName(ctx)); } if (AD_ReportView_ID <= 0) { element.defer = true; + element.unresolved = "AD_ReportView_ID"; return; } int AD_Column_ID = 0; Element columnElement = element.properties.get(I_AD_ReportView_Col.COLUMNNAME_AD_Column_ID); if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) { - AD_Column_ID = ReferenceUtils.resolveReference(ctx, columnElement, getTrxName(ctx)); + AD_Column_ID = ReferenceUtils.resolveReference(ctx.ctx, columnElement, getTrxName(ctx)); } else { if (columnElement.contents != null && columnElement.contents.length() > 0) { Element tableElement = element.properties.get("AD_Table_ID"); - int AD_Table_ID = ReferenceUtils.resolveReference(ctx, tableElement, getTrxName(ctx)); + int AD_Table_ID = ReferenceUtils.resolveReference(ctx.ctx, tableElement, getTrxName(ctx)); AD_Column_ID = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnElement.contents.toString(), "AD_Table", AD_Table_ID); if (AD_Column_ID <= 0) { element.defer = true; + element.unresolved = "AD_Column_ID"; return; } } @@ -88,10 +91,10 @@ public class ReportViewColElementHandler extends AbstractElementHandler { 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 = new X_AD_ReportView_Col(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); mReportviewCol.setAD_ReportView_ID(AD_ReportView_ID); if (AD_Column_ID > 0) { - mReportviewCol.setAD_Column_ID(id); + mReportviewCol.setAD_Column_ID(AD_Column_ID); } mReportviewCol.setFunctionColumn(functionColumn); excludes.add("FunctionColumn"); @@ -106,6 +109,7 @@ public class ReportViewColElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -126,7 +130,7 @@ public class ReportViewColElementHandler extends AbstractElementHandler { } else { logImportDetail(ctx, impDetail, 0, "" + mReportviewCol.getAD_ReportView_ID(), mReportviewCol.get_ID(),action); - throw new POSaveFailedException("ReportViewCol"); + throw new POSaveFailedException("Failed to save ReportViewCol"); } } } else { @@ -134,23 +138,30 @@ public class ReportViewColElementHandler extends AbstractElementHandler { } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int AD_ReportView_Col_ID = Env.getContextAsInt(ctx, + int AD_ReportView_Col_ID = Env.getContextAsInt(ctx.ctx, X_AD_ReportView_Col.COLUMNNAME_AD_ReportView_Col_ID); - X_AD_ReportView_Col m_Reportview_Col = new X_AD_ReportView_Col(ctx, + X_AD_ReportView_Col m_Reportview_Col = new X_AD_ReportView_Col(ctx.ctx, AD_ReportView_Col_ID, getTrxName(ctx)); + + if (ctx.packOut.getFromDate() != null) { + if (m_Reportview_Col.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } + AttributesImpl atts = new AttributesImpl(); addTypeName(atts, "table"); - document.startElement("", "", I_AD_ReportView_Col.Table_Name, atts); + document.startElement("", "", X_AD_ReportView_Col.Table_Name, atts); createReportViewColBinding(ctx, document, m_Reportview_Col); - document.endElement("", "", I_AD_ReportView_Col.Table_Name); + document.endElement("", "", X_AD_ReportView_Col.Table_Name); } - private void createReportViewColBinding(Properties ctx, TransformerHandler document, + private void createReportViewColBinding(PIPOContext ctx, TransformerHandler document, X_AD_ReportView_Col m_Reportview_Col) { PoExporter filler = new PoExporter(ctx, document, m_Reportview_Col); @@ -159,7 +170,9 @@ public class ReportViewColElementHandler extends AbstractElementHandler { 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(); + int AD_Column_ID = m_Reportview_Col.getAD_Column_ID(); + MColumn mColumn = new MColumn(ctx.ctx, AD_Column_ID, getTrxName(ctx)); + int AD_Table_ID = mColumn.getAD_Table_ID(); AttributesImpl tableAtts = new AttributesImpl(); String value = ReferenceUtils.getTableReference("AD_Table", "TableName", AD_Table_ID, tableAtts); filler.addString("AD_Table_ID", value, tableAtts); @@ -172,8 +185,8 @@ public class ReportViewColElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler, int recordId) throws Exception { - Env.setContext(packout.getCtx(), I_AD_ReportView_Col.COLUMNNAME_AD_ReportView_Col_ID, recordId); + Env.setContext(packout.getCtx().ctx, I_AD_ReportView_Col.COLUMNNAME_AD_ReportView_Col_ID, recordId); create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(I_AD_ReportView_Col.COLUMNNAME_AD_ReportView_Col_ID); + packout.getCtx().ctx.remove(I_AD_ReportView_Col.COLUMNNAME_AD_ReportView_Col_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ReportViewElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ReportViewElementHandler.java index dd685d49ba..701a63edd4 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ReportViewElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ReportViewElementHandler.java @@ -20,13 +20,13 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.exceptions.AdempiereException; import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.ElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -50,7 +50,7 @@ public class ReportViewElementHandler extends AbstractElementHandler { private List views = new ArrayList(); - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { List excludes = defaultExcludeList(X_AD_ReportView.Table_Name); @@ -59,7 +59,7 @@ public class ReportViewElementHandler extends AbstractElementHandler { if (mReportview == null) { String name = getStringValue(element, "Name"); int id = findIdByName(ctx, "AD_ReportView", name); - mReportview = new X_AD_ReportView(ctx, id, getTrxName(ctx)); + mReportview = new X_AD_ReportView(ctx.ctx, id, getTrxName(ctx)); } PoFiller filler = new PoFiller(ctx, mReportview, element, this); if (mReportview.getAD_ReportView_ID() == 0 && isOfficialId(element, "AD_ReportView_ID")) @@ -68,6 +68,7 @@ public class ReportViewElementHandler extends AbstractElementHandler { List notfound = filler.autoFill(excludes); if (notfound.size() > 0) { element.defer = true; + element.unresolved = notfound.toString(); return; } @@ -88,60 +89,50 @@ public class ReportViewElementHandler extends AbstractElementHandler { } else { logImportDetail(ctx, impDetail, 0, mReportview.getName(), mReportview.get_ID(), action); - throw new POSaveFailedException("ReportView"); + throw new POSaveFailedException("Failed to save ReportView " + mReportview.getName()); } } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - PackOut packOut = getPackOut(ctx); - int AD_ReportView_ID = Env.getContextAsInt(ctx, "AD_ReportView_ID"); + PackOut packOut = ctx.packOut; + int AD_ReportView_ID = Env.getContextAsInt(ctx.ctx, "AD_ReportView_ID"); if (views.contains(AD_ReportView_ID)) return; views.add(AD_ReportView_ID); AttributesImpl atts = new AttributesImpl(); - X_AD_ReportView m_Reportview = new X_AD_ReportView(ctx, AD_ReportView_ID, getTrxName(ctx)); + X_AD_ReportView m_Reportview = new X_AD_ReportView(ctx.ctx, AD_ReportView_ID, getTrxName(ctx)); // Export Table if neccessary ElementHandler tableHandler = packOut.getHandler(I_AD_Table.Table_Name); try { tableHandler.packOut(packOut, document, null, m_Reportview.getAD_Table_ID()); } catch (Exception e) { - throw new AdempiereException(e); + throw new RuntimeException(e); } - addTypeName(atts, "table"); - document.startElement("", "", I_AD_ReportView.Table_Name, atts); - createReportViewBinding(ctx, document, m_Reportview); - document.endElement("", "", I_AD_ReportView.Table_Name); + boolean createElement = true; + if (ctx.packOut.getFromDate() != null) { + if (m_Reportview.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + createElement = false; + } + } - String sql = "SELECT AD_PrintFormat_ID FROM AD_PrintFormat WHERE AD_ReportView_ID= " + if (createElement) { + addTypeName(atts, "table"); + document.startElement("", "", I_AD_ReportView.Table_Name, atts); + createReportViewBinding(ctx, document, m_Reportview); + } + + String sql = "SELECT AD_ReportView_Col_ID FROM AD_ReportView_Col WHERE AD_Reportview_ID= " + AD_ReportView_ID; PreparedStatement pstmt = null; ResultSet rs = null; - try { - pstmt = DB.prepareStatement(sql, getTrxName(ctx)); - rs = pstmt.executeQuery(); - while (rs.next()) { - ElementHandler pftHandler = packOut.getHandler(I_AD_PrintFormat.Table_Name); - pftHandler.packOut(packOut, document, null, rs.getInt(1)); - - } - } catch (Exception e) { - throw new AdempiereException(e); - } finally { - DB.close(rs, pstmt); - } - - sql = "SELECT AD_ReportView_Col_ID FROM AD_ReportView_Col WHERE AD_Reportview_ID= " - + AD_ReportView_ID; - pstmt = null; - rs = null; try { pstmt = DB.prepareStatement(sql, getTrxName(ctx)); rs = pstmt.executeQuery(); @@ -153,19 +144,40 @@ public class ReportViewElementHandler extends AbstractElementHandler { } finally { DB.close(rs, pstmt); } + + if (createElement) { + document.endElement("", "", X_AD_ReportView.Table_Name); + } + + sql = "SELECT AD_PrintFormat_ID FROM AD_PrintFormat WHERE AD_ReportView_ID= " + + AD_ReportView_ID; + pstmt = null; + rs = null; + try { + pstmt = DB.prepareStatement(sql, getTrxName(ctx)); + rs = pstmt.executeQuery(); + while (rs.next()) { + ElementHandler pftHandler = packOut.getHandler(I_AD_PrintFormat.Table_Name); + pftHandler.packOut(packOut, document, null, rs.getInt(1)); + } + } catch (Exception e) { + throw new AdempiereException(e); + } finally { + DB.close(rs, pstmt); + } } - private void createReportViewCol(Properties ctx, + private void createReportViewCol(PIPOContext ctx, TransformerHandler document, int AD_ReportView_Col_ID) throws SAXException { - Env.setContext(ctx, + Env.setContext(ctx.ctx, X_AD_ReportView_Col.COLUMNNAME_AD_ReportView_Col_ID, AD_ReportView_Col_ID); columnHandler.create(ctx, document); - ctx.remove(X_AD_ReportView_Col.COLUMNNAME_AD_ReportView_Col_ID); + ctx.ctx.remove(X_AD_ReportView_Col.COLUMNNAME_AD_ReportView_Col_ID); } - private void createReportViewBinding(Properties ctx, TransformerHandler document, + private void createReportViewBinding(PIPOContext ctx, TransformerHandler document, X_AD_ReportView m_Reportview) { PoExporter filler = new PoExporter(ctx, document, m_Reportview); @@ -177,8 +189,8 @@ public class ReportViewElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception { - Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_ReportView_ID, recordId); + Env.setContext(packout.getCtx().ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_ReportView_ID, recordId); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_ReportView_ID); + packout.getCtx().ctx.remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_ReportView_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/RoleElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/RoleElementHandler.java index a9e3ba397d..f9ddbecb66 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/RoleElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/RoleElementHandler.java @@ -20,12 +20,12 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import java.util.logging.Level; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -61,7 +61,7 @@ public class RoleElementHandler extends AbstractElementHandler { private TaskAccessElementHandler taskHandler = new TaskAccessElementHandler(); private WorkflowAccessElementHandler workflowHandler = new WorkflowAccessElementHandler(); - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { List excludes = defaultExcludeList(X_AD_Role.Table_Name); @@ -70,7 +70,7 @@ public class RoleElementHandler extends AbstractElementHandler { 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 = new MRole(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); mRole.setName(name); } @@ -81,6 +81,7 @@ public class RoleElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -101,26 +102,36 @@ public class RoleElementHandler extends AbstractElementHandler { logImportDetail(ctx, impDetail, 0, mRole.getName(), mRole.get_ID(), action); - throw new POSaveFailedException("Role"); + throw new POSaveFailedException("Failed to save Role " + mRole.getName()); } } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int Role_id = Env.getContextAsInt(ctx, + int Role_id = Env.getContextAsInt(ctx.ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Role_ID); if (roles.contains(Role_id)) return; roles.add(Role_id); - X_AD_Role m_Role = new X_AD_Role(ctx, Role_id, null); - AttributesImpl atts = new AttributesImpl(); - addTypeName(atts, "table"); - document.startElement("", "", I_AD_Role.Table_Name, atts); - createRoleBinding(ctx, document, m_Role); + + boolean createElement = true; + X_AD_Role m_Role = new X_AD_Role(ctx.ctx, Role_id, null); + if (ctx.packOut.getFromDate() != null) { + if (m_Role.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + createElement = false; + } + } + + if (createElement) { + AttributesImpl atts = new AttributesImpl(); + addTypeName(atts, "table"); + document.startElement("", "", I_AD_Role.Table_Name, atts); + createRoleBinding(ctx, document, m_Role); + } // Process org access String sql = "SELECT AD_Org_ID, AD_Role_ID FROM AD_Role_OrgAccess WHERE AD_Role_ID= " @@ -141,7 +152,8 @@ public class RoleElementHandler extends AbstractElementHandler { } // Process user assignment access - sql = "SELECT AD_User_ID, AD_Role_ID, AD_Org_ID FROM AD_User_Roles WHERE AD_Role_ID= " + Role_id; + sql = "SELECT AD_User_ID, AD_Role_ID, AD_Org_ID FROM AD_User_Roles WHERE AD_Role_ID= " + Role_id + + " AND AD_User_ID > 0 "; pstmt = null; rs = null; try { @@ -241,75 +253,78 @@ public class RoleElementHandler extends AbstractElementHandler { } finally { DB.close(rs, pstmt); } - document.endElement("", "", I_AD_Role.Table_Name); + + if (createElement) { + document.endElement("", "", X_AD_Role.Table_Name); + } } - private void createTaskAccess(Properties ctx, TransformerHandler document, + private void createTaskAccess(PIPOContext ctx, TransformerHandler document, int AD_Task_ID, int AD_Role_ID) throws SAXException { - Env.setContext(ctx, X_AD_Task.COLUMNNAME_AD_Task_ID, AD_Task_ID); - Env.setContext(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID); + Env.setContext(ctx.ctx, X_AD_Task.COLUMNNAME_AD_Task_ID, AD_Task_ID); + Env.setContext(ctx.ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID); taskHandler.create(ctx, document); - ctx.remove(X_AD_Task.COLUMNNAME_AD_Task_ID); - ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID); + ctx.ctx.remove(X_AD_Task.COLUMNNAME_AD_Task_ID); + ctx.ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID); } - private void createWorkflowAccess(Properties ctx, + private void createWorkflowAccess(PIPOContext ctx, TransformerHandler document, int AD_Workflow_ID, int AD_Role_ID) throws SAXException { - Env.setContext(ctx, X_AD_Workflow.COLUMNNAME_AD_Workflow_ID, AD_Workflow_ID); - Env.setContext(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID); + Env.setContext(ctx.ctx, X_AD_Workflow.COLUMNNAME_AD_Workflow_ID, AD_Workflow_ID); + Env.setContext(ctx.ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID); workflowHandler.create(ctx, document); - ctx.remove(X_AD_Workflow.COLUMNNAME_AD_Workflow_ID); - ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID); + ctx.ctx.remove(X_AD_Workflow.COLUMNNAME_AD_Workflow_ID); + ctx.ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID); } - private void createFormAccess(Properties ctx, TransformerHandler document, + private void createFormAccess(PIPOContext ctx, TransformerHandler document, int AD_Form_ID, int AD_Role_ID) throws SAXException { - Env.setContext(ctx, X_AD_Form.COLUMNNAME_AD_Form_ID, AD_Form_ID); - Env.setContext(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID); + Env.setContext(ctx.ctx, X_AD_Form.COLUMNNAME_AD_Form_ID, AD_Form_ID); + Env.setContext(ctx.ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID); formHandler.create(ctx, document); - ctx.remove(X_AD_Form.COLUMNNAME_AD_Form_ID); - ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID); + ctx.ctx.remove(X_AD_Form.COLUMNNAME_AD_Form_ID); + ctx.ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID); } - private void createProcessAccess(Properties ctx, + private void createProcessAccess(PIPOContext ctx, TransformerHandler document, int AD_Process_ID, int AD_Role_ID) throws SAXException { - Env.setContext(ctx, X_AD_Process.COLUMNNAME_AD_Process_ID, AD_Process_ID); - Env.setContext(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID); + Env.setContext(ctx.ctx, X_AD_Process.COLUMNNAME_AD_Process_ID, AD_Process_ID); + Env.setContext(ctx.ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID); processHandler.create(ctx, document); - ctx.remove(X_AD_Process.COLUMNNAME_AD_Process_ID); - ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID); + ctx.ctx.remove(X_AD_Process.COLUMNNAME_AD_Process_ID); + ctx.ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID); } - private void createWindowAccess(Properties ctx, + private void createWindowAccess(PIPOContext ctx, TransformerHandler document, int AD_Window_ID, int AD_Role_ID) throws SAXException { - Env.setContext(ctx, X_AD_Window.COLUMNNAME_AD_Window_ID, AD_Window_ID); - Env.setContext(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID); + Env.setContext(ctx.ctx, X_AD_Window.COLUMNNAME_AD_Window_ID, AD_Window_ID); + Env.setContext(ctx.ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID); windowHandler.create(ctx, document); - ctx.remove(X_AD_Window.COLUMNNAME_AD_Window_ID); - ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID); + ctx.ctx.remove(X_AD_Window.COLUMNNAME_AD_Window_ID); + ctx.ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID); } - private void createUserRole(Properties ctx, TransformerHandler document, + private void createUserRole(PIPOContext ctx, TransformerHandler document, int AD_User_ID, int AD_Role_ID, int AD_Org_ID) throws SAXException { - Env.setContext(ctx, X_AD_User.COLUMNNAME_AD_User_ID, AD_User_ID); - Env.setContext(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID); - Env.setContext(ctx, "AD_Org_ID", AD_Org_ID); + Env.setContext(ctx.ctx, X_AD_User.COLUMNNAME_AD_User_ID, AD_User_ID); + Env.setContext(ctx.ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID); + Env.setContext(ctx.ctx, "AD_Org_ID", AD_Org_ID); userHandler.create(ctx, document); - ctx.remove(X_AD_User.COLUMNNAME_AD_User_ID); - ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID); - ctx.remove("AD_Org_ID"); + ctx.ctx.remove(X_AD_User.COLUMNNAME_AD_User_ID); + ctx.ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID); + ctx.ctx.remove("AD_Org_ID"); } - private void createOrgAccess(Properties ctx, TransformerHandler document, + private void createOrgAccess(PIPOContext ctx, TransformerHandler document, int AD_Org_ID, int AD_Role_ID) throws SAXException { - Env.setContext(ctx, "AD_Org_ID", AD_Org_ID); - Env.setContext(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID); + Env.setContext(ctx.ctx, "AD_Org_ID", AD_Org_ID); + Env.setContext(ctx.ctx, X_AD_Role.COLUMNNAME_AD_Role_ID, AD_Role_ID); orgHandler.create(ctx, document); - ctx.remove("AD_Org_ID"); - ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID); + ctx.ctx.remove("AD_Org_ID"); + ctx.ctx.remove(X_AD_Role.COLUMNNAME_AD_Role_ID); } - private void createRoleBinding(Properties ctx, TransformerHandler document, + private void createRoleBinding(PIPOContext ctx, TransformerHandler document, X_AD_Role m_Role) { PoExporter filler = new PoExporter(ctx, document, m_Role); List excludes = defaultExcludeList(X_AD_Role.Table_Name); @@ -329,8 +344,8 @@ public class RoleElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception { - Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Role_ID, recordId); + Env.setContext(packout.getCtx().ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Role_ID, recordId); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Role_ID); + packout.getCtx().ctx.remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Role_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/SQLStatementElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/SQLStatementElementHandler.java index db147fe781..815c3e9ab0 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/SQLStatementElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/SQLStatementElementHandler.java @@ -19,16 +19,17 @@ package org.adempiere.pipo2.handler; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.Statement; -import java.util.Properties; import java.util.logging.Level; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.Element; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PackoutItem; import org.adempiere.pipo2.SQLElementParameters; +import org.compiere.model.X_AD_Package_Imp_Detail; import org.compiere.util.DB; import org.compiere.util.Env; import org.xml.sax.SAXException; @@ -36,13 +37,13 @@ import org.xml.sax.helpers.AttributesImpl; public class SQLStatementElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) throws SAXException { + public void startElement(PIPOContext ctx, Element element) throws SAXException { String elementValue = element.getElementValue(); log.info(elementValue); String DBType = getStringValue(element, "DBType"); String sql = getStringValue(element, "statement"); - if (sql.endsWith(";")) + if (sql.endsWith(";") && !(sql.toLowerCase().endsWith("end;"))) sql = sql.substring(0, sql.length() - 1); PreparedStatement pstmt = null; try { @@ -52,8 +53,8 @@ public class SQLStatementElementHandler extends AbstractElementHandler { log.info("Executed SQL Statement: "+ getStringValue(element, "statement") + " ReturnValue="+n); } else if(DB.isOracle() == true && DBType.equals("Oracle")) { - pstmt.executeUpdate(); - log.info("Executed SQL Statement for Oracle: "+ getStringValue(element, "statement")); + int n = pstmt.executeUpdate(); + log.info("Executed SQL Statement for Oracle: "+ getStringValue(element, "statement") + " ReturnValue="+n); } else if ( DB.isPostgreSQL() && ( DBType.equals("Postgres") @@ -78,20 +79,27 @@ public class SQLStatementElementHandler extends AbstractElementHandler { m_con.close(); } } + + X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, "", + 0); + logImportDetail (ctx, impDetail, 1, "SQLStatement",1,"Execute"); } catch (Exception e) { log.log(Level.SEVERE,"SQLSatement", e); + X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, "", + 0); + logImportDetail (ctx, impDetail, 0, "SQLStatement",1,"Execute"); } finally { DB.close(pstmt); } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - String SQLStatement = Env.getContext(ctx, SQLElementParameters.SQL_STATEMENT); - String DBType = Env.getContext(ctx, SQLElementParameters.DB_TYPE); + String SQLStatement = Env.getContext(ctx.ctx, SQLElementParameters.SQL_STATEMENT); + String DBType = Env.getContext(ctx.ctx, SQLElementParameters.DB_TYPE); AttributesImpl atts = new AttributesImpl(); addTypeName(atts, "custom"); document.startElement("","","SQLStatement",atts); @@ -108,7 +116,9 @@ public class SQLStatementElementHandler extends AbstractElementHandler { document.startElement("","","statement", new AttributesImpl()); contents = sqlStatement.toCharArray(); + document.startCDATA(); document.characters(contents,0,contents.length); + document.endCDATA(); document.endElement("","","statement"); } @@ -116,10 +126,10 @@ public class SQLStatementElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int field) throws Exception { PackoutItem detail = packout.getCurrentPackoutItem(); - Env.setContext(packout.getCtx(), SQLElementParameters.SQL_STATEMENT, (String)detail.getProperty(SQLElementParameters.SQL_STATEMENT)); - Env.setContext(packout.getCtx(), SQLElementParameters.DB_TYPE, (String)detail.getProperty(SQLElementParameters.DB_TYPE)); + Env.setContext(packout.getCtx().ctx, SQLElementParameters.SQL_STATEMENT, (String)detail.getProperty(SQLElementParameters.SQL_STATEMENT)); + Env.setContext(packout.getCtx().ctx, SQLElementParameters.DB_TYPE, (String)detail.getProperty(SQLElementParameters.DB_TYPE)); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(SQLElementParameters.SQL_STATEMENT); - packout.getCtx().remove(SQLElementParameters.DB_TYPE); + packout.getCtx().ctx.remove(SQLElementParameters.SQL_STATEMENT); + packout.getCtx().ctx.remove(SQLElementParameters.DB_TYPE); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/TabElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/TabElementHandler.java index 6f73cca2c3..c4e8cffcae 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/TabElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/TabElementHandler.java @@ -19,7 +19,6 @@ package org.adempiere.pipo2.handler; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.List; -import java.util.Properties; import java.util.logging.Level; import javax.xml.transform.sax.TransformerHandler; @@ -27,6 +26,7 @@ import javax.xml.transform.sax.TransformerHandler; import org.adempiere.exceptions.AdempiereException; import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.ElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -50,11 +50,11 @@ public class TabElementHandler extends AbstractElementHandler { private FieldElementHandler fieldHandler = new FieldElementHandler(); - public void startElement(Properties ctx, Element element) throws SAXException { + public void startElement(PIPOContext ctx, Element element) throws SAXException { List excludes = defaultExcludeList(X_AD_Tab.Table_Name); String entitytype = getStringValue(element, "EntityType"); - if (isProcessElement(ctx, entitytype)) { + if (isProcessElement(ctx.ctx, entitytype)) { if (isParentDefer(element, I_AD_Window.Table_Name)) { element.defer = true; return; @@ -69,17 +69,19 @@ public class TabElementHandler extends AbstractElementHandler { 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, getTrxName(ctx)); + windowId = ReferenceUtils.resolveReference(ctx.ctx, windowElement, getTrxName(ctx)); } if (windowId <= 0) { element.defer = true; + element.unresolved = "AD_Window_ID"; return; } Element tableElement = element.properties.get(I_AD_Tab.COLUMNNAME_AD_Table_ID); - int tableId = ReferenceUtils.resolveReference(ctx, tableElement, getTrxName(ctx)); + int tableId = ReferenceUtils.resolveReference(ctx.ctx, tableElement, getTrxName(ctx)); if (tableId <= 0) { element.defer = true; + element.unresolved = "AD_Table_ID"; return; } @@ -88,7 +90,7 @@ public class TabElementHandler extends AbstractElementHandler { + " 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 = new MTab(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); mTab.setAD_Table_ID(tableId); mTab.setName(name); mTab.setAD_Window_ID(windowId); @@ -101,7 +103,7 @@ public class TabElementHandler extends AbstractElementHandler { 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, getTrxName(ctx)); + AD_Column_ID = ReferenceUtils.resolveReference(ctx.ctx, columnElement, getTrxName(ctx)); } else if (columnElement.contents != null && columnElement.contents.length() > 0){ AD_Column_ID = findIdByColumnAndParentId (ctx, "AD_Column","ColumnName", columnElement.contents.toString(), "AD_Table", mTab.getAD_Table_ID()); @@ -111,7 +113,7 @@ public class TabElementHandler extends AbstractElementHandler { 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, getTrxName(ctx)); + AD_Column_ID = ReferenceUtils.resolveReference(ctx.ctx, columnElement, getTrxName(ctx)); } else if (columnElement.contents != null && columnElement.contents.length() > 0){ AD_Column_ID = findIdByColumnAndParentId (ctx, "AD_Column","ColumnName", columnElement.contents.toString(), "AD_Table", mTab.getAD_Table_ID()); @@ -121,7 +123,7 @@ public class TabElementHandler extends AbstractElementHandler { 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, getTrxName(ctx)); + AD_Column_ID = ReferenceUtils.resolveReference(ctx.ctx, columnElement, getTrxName(ctx)); } else if (columnElement.contents != null && columnElement.contents.length() > 0){ AD_Column_ID = findIdByColumnAndParentId (ctx, "AD_Column","ColumnName", columnElement.contents.toString(), "AD_Table", mTab.getAD_Table_ID()); @@ -131,6 +133,7 @@ public class TabElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -150,7 +153,7 @@ public class TabElementHandler extends AbstractElementHandler { element.recordId = mTab.getAD_Tab_ID(); } else { logImportDetail (ctx, impDetail, 0, mTab.getName(), mTab.get_ID(),action); - throw new POSaveFailedException("Tab"); + throw new POSaveFailedException("Failed to save Tab " + mTab.getName()); } } } else { @@ -159,18 +162,28 @@ public class TabElementHandler extends AbstractElementHandler { } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - PackOut packOut = getPackOut(ctx); - 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(); - addTypeName(atts, "table"); - document.startElement("","",I_AD_Tab.Table_Name,atts); - createTabBinding(ctx,document,m_Tab); + PackOut packOut = ctx.packOut; + int AD_Tab_ID = Env.getContextAsInt(ctx.ctx, "AD_Tab_ID"); + + boolean createElement = true; + X_AD_Tab m_Tab = new X_AD_Tab (ctx.ctx, AD_Tab_ID, getTrxName(ctx)); + if (ctx.packOut.getFromDate() != null) { + if (m_Tab.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + createElement = false; + } + } + if (createElement) { + AttributesImpl atts = new AttributesImpl(); + addTypeName(atts, "table"); + 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 + "ORDER BY SEQNO asc"; @@ -193,7 +206,10 @@ public class TabElementHandler extends AbstractElementHandler { { DB.close(rs, pstmt); } - document.endElement("","",I_AD_Tab.Table_Name); + + if (createElement) { + document.endElement("","",X_AD_Tab.Table_Name); + } if(m_Tab.getAD_Process_ID() > 0 ) { @@ -210,14 +226,14 @@ public class TabElementHandler extends AbstractElementHandler { } - private void createField(Properties ctx, TransformerHandler document, + private void createField(PIPOContext ctx, TransformerHandler document, int AD_Field_ID) throws SAXException { - Env.setContext(ctx, X_AD_Field.COLUMNNAME_AD_Field_ID, AD_Field_ID); + Env.setContext(ctx.ctx, X_AD_Field.COLUMNNAME_AD_Field_ID, AD_Field_ID); fieldHandler.create(ctx, document); - ctx.remove(X_AD_Field.COLUMNNAME_AD_Field_ID); + ctx.ctx.remove(X_AD_Field.COLUMNNAME_AD_Field_ID); } - private void createTabBinding(Properties ctx, TransformerHandler document, X_AD_Tab m_Tab) + private void createTabBinding(PIPOContext ctx, TransformerHandler document, X_AD_Tab m_Tab) { PoExporter filler = new PoExporter(ctx, document, m_Tab); List excludes = defaultExcludeList(X_AD_Tab.Table_Name); @@ -232,8 +248,8 @@ public class TabElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler, int recordId) throws Exception { - Env.setContext(packout.getCtx(), I_AD_Tab.COLUMNNAME_AD_Tab_ID, recordId); + Env.setContext(packout.getCtx().ctx, I_AD_Tab.COLUMNNAME_AD_Tab_ID, recordId); create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(I_AD_Tab.COLUMNNAME_AD_Tab_ID); + packout.getCtx().ctx.remove(I_AD_Tab.COLUMNNAME_AD_Tab_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/TableElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/TableElementHandler.java index 2fba140560..7c1bc576ca 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/TableElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/TableElementHandler.java @@ -20,13 +20,13 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.exceptions.AdempiereException; import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.ElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackIn; @@ -49,12 +49,12 @@ public class TableElementHandler extends AbstractElementHandler { private Listtables = new ArrayList(); - public void startElement(Properties ctx, Element element) throws SAXException { - PackIn packIn = getPackIn(ctx); + public void startElement(PIPOContext ctx, Element element) throws SAXException { + PackIn packIn = ctx.packIn; List excludes = defaultExcludeList(X_AD_Table.Table_Name); String entitytype = getStringValue(element, "EntityType"); - if (isProcessElement(ctx, entitytype)) { + if (isProcessElement(ctx.ctx, entitytype)) { MTable mTable = findPO(ctx, element); if (mTable == null) { @@ -70,7 +70,7 @@ public class TableElementHandler extends AbstractElementHandler { return; } - mTable = new MTable(ctx, id > 0 ? id : 0, getTrxName(ctx)); + mTable = new MTable(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); mTable.setTableName(tableName); } @@ -83,6 +83,7 @@ public class TableElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -105,7 +106,7 @@ public class TableElementHandler extends AbstractElementHandler { } else{ logImportDetail (ctx, impDetail, 0, mTable.getName(), mTable.get_ID(),action); - throw new POSaveFailedException("Table"); + throw new POSaveFailedException("Failed to save Table " + mTable.getName()); } } } else { @@ -113,22 +114,30 @@ public class TableElementHandler extends AbstractElementHandler { } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int AD_Table_ID = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID); - PackOut packOut = getPackOut(ctx); + int AD_Table_ID = Env.getContextAsInt(ctx.ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID); + PackOut packOut = ctx.packOut; boolean exported = isTableProcess(ctx, AD_Table_ID); AttributesImpl atts = new AttributesImpl(); //Export table if not already done so if (!exported){ - X_AD_Table m_Table = new X_AD_Table (ctx, AD_Table_ID, null); - addTypeName(atts, "table"); - document.startElement("","",I_AD_Table.Table_Name,atts); - createTableBinding(ctx,document,m_Table); + boolean createElement = true; + X_AD_Table m_Table = new X_AD_Table (ctx.ctx, AD_Table_ID, null); + if (ctx.packOut.getFromDate() != null) { + if (m_Table.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + createElement = false; + } + } + if (createElement) { + addTypeName(atts, "table"); + document.startElement("","",I_AD_Table.Table_Name,atts); + createTableBinding(ctx,document,m_Table); + } String sql = "SELECT * FROM AD_Column WHERE AD_Table_ID = ? " + " ORDER BY IsKey DESC, AD_Column_ID"; // Export key column as the first one @@ -176,18 +185,21 @@ public class TableElementHandler extends AbstractElementHandler { } finally { DB.close(rs, pstmt); } - document.endElement("","",I_AD_Table.Table_Name); + + if (createElement) { + document.endElement("","",X_AD_Table.Table_Name); + } } } - private void createColumn(Properties ctx, TransformerHandler document, int AD_Column_ID) throws SAXException { - Env.setContext(ctx, X_AD_Column.COLUMNNAME_AD_Column_ID, AD_Column_ID); + private void createColumn(PIPOContext ctx, TransformerHandler document, int AD_Column_ID) throws SAXException { + Env.setContext(ctx.ctx, X_AD_Column.COLUMNNAME_AD_Column_ID, AD_Column_ID); columnHandler.create(ctx, document); - ctx.remove(X_AD_Column.COLUMNNAME_AD_Column_ID); + ctx.ctx.remove(X_AD_Column.COLUMNNAME_AD_Column_ID); } - private boolean isTableProcess(Properties ctx, int AD_Table_ID) { + private boolean isTableProcess(PIPOContext ctx, int AD_Table_ID) { if (tables.contains(AD_Table_ID)) return true; else { @@ -196,7 +208,7 @@ public class TableElementHandler extends AbstractElementHandler { } } - private void createTableBinding(Properties ctx, TransformerHandler document, X_AD_Table m_Table) + private void createTableBinding(PIPOContext 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) @@ -210,8 +222,8 @@ public class TableElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception { - Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID, recordId); + Env.setContext(packout.getCtx().ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID, recordId); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID); + packout.getCtx().ctx.remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Table_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/TaskAccessElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/TaskAccessElementHandler.java index d70179aed9..db069d9a6a 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/TaskAccessElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/TaskAccessElementHandler.java @@ -17,11 +17,11 @@ package org.adempiere.pipo2.handler; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; @@ -39,7 +39,7 @@ import org.xml.sax.helpers.AttributesImpl; public class TaskAccessElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) throws SAXException { + public void startElement(PIPOContext ctx, Element element) throws SAXException { int roleid =0; int taskid =0; List excludes = defaultExcludeList(X_AD_Task_Access.Table_Name); @@ -49,17 +49,28 @@ public class TaskAccessElementHandler extends AbstractElementHandler { 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, getTrxName(ctx)); + Element roleElement = element.properties.get("AD_Role_ID"); + roleid = ReferenceUtils.resolveReference(ctx.ctx, roleElement, getTrxName(ctx)); + } + + if (roleid <= 0) { + element.defer = true; + element.unresolved = "AD_Role_ID"; + return; } Element taskElement = element.properties.get(I_AD_Task_Access.COLUMNNAME_AD_Task_ID); - taskid = ReferenceUtils.resolveReference(ctx, taskElement, getTrxName(ctx)); + taskid = ReferenceUtils.resolveReference(ctx.ctx, taskElement, getTrxName(ctx)); + if (taskid <= 0) { + element.defer = true; + element.unresolved = "AD_Task_ID"; + return; + } - Query query = new Query(ctx, "AD_Task_Access", "AD_Role_ID=? and AD_Task_ID=?", getTrxName(ctx)); + Query query = new Query(ctx.ctx, "AD_Task_Access", "AD_Role_ID=? and AD_Task_ID=?", getTrxName(ctx)); po = query.setParameters(new Object[]{roleid, taskid}).first(); if (po == null){ - po = new X_AD_Task_Access(ctx, 0, getTrxName(ctx)); + po = new X_AD_Task_Access(ctx.ctx, 0, getTrxName(ctx)); po.setAD_Role_ID(roleid); po.setAD_Task_ID(taskid); } @@ -70,35 +81,41 @@ public class TaskAccessElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } po.saveEx(); } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - 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(); - addTypeName(atts, "table"); - document.startElement("", "", I_AD_Task_Access.Table_Name, atts); - createTaskAccessBinding(ctx, document, AD_Task_ID, AD_Role_ID); - document.endElement("", "", I_AD_Task_Access.Table_Name); + int AD_Task_ID = Env.getContextAsInt(ctx.ctx, X_AD_Task.COLUMNNAME_AD_Task_ID); + int AD_Role_ID = Env.getContextAsInt(ctx.ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); + Query query = new Query(ctx.ctx, "AD_Task_Access", "AD_Role_ID=? and AD_Task_ID=?", getTrxName(ctx)); + X_AD_Task_Access po = query.setParameters(new Object[]{AD_Role_ID, AD_Task_ID}).first(); + if (po != null) { + if (ctx.packOut.getFromDate() != null) { + if (po.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } + AttributesImpl atts = new AttributesImpl(); + addTypeName(atts, "table"); + document.startElement("", "", I_AD_Task_Access.Table_Name, atts); + createTaskAccessBinding(ctx, document, po); + document.endElement("", "", I_AD_Task_Access.Table_Name); + } } - private void createTaskAccessBinding(Properties ctx, TransformerHandler document, - int taskid, int roleid) { - 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) { + private void createTaskAccessBinding(PIPOContext ctx, TransformerHandler document, + X_AD_Task_Access po) { PoExporter filler = new PoExporter(ctx, document, po); List excludes = defaultExcludeList(X_AD_Task_Access.Table_Name); filler.export(excludes); } - } @Override public void packOut(PackOut packout, TransformerHandler packoutHandler, diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/TaskElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/TaskElementHandler.java index 9037a06148..fdfdbd2325 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/TaskElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/TaskElementHandler.java @@ -19,11 +19,11 @@ package org.adempiere.pipo2.handler; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -41,18 +41,18 @@ public class TaskElementHandler extends AbstractElementHandler { private List tasks = new ArrayList(); - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { List excludes = defaultExcludeList(X_AD_Task.Table_Name); String entitytype = getStringValue(element, "EntityType"); - if (isProcessElement(ctx, entitytype)) { + if (isProcessElement(ctx.ctx, entitytype)) { 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)); + mTask = new MTask(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); } if (mTask.getAD_Task_ID() == 0 && isOfficialId(element, "AD_Task_ID")) @@ -62,6 +62,7 @@ public class TaskElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -81,7 +82,7 @@ public class TaskElementHandler extends AbstractElementHandler { } else { logImportDetail(ctx, impDetail, 0, mTask.getName(), mTask.get_ID(), action); - throw new POSaveFailedException("Task"); + throw new POSaveFailedException("Failed to save Task " + mTask.getName()); } } } else { @@ -89,16 +90,21 @@ public class TaskElementHandler extends AbstractElementHandler { } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int AD_Task_ID = Env.getContextAsInt(ctx, "AD_Task_ID"); + int AD_Task_ID = Env.getContextAsInt(ctx.ctx, "AD_Task_ID"); if (tasks.contains(AD_Task_ID)) return; tasks.add(AD_Task_ID); - X_AD_Task m_Task = new X_AD_Task(ctx, AD_Task_ID, null); + X_AD_Task m_Task = new X_AD_Task(ctx.ctx, AD_Task_ID, null); + if (ctx.packOut.getFromDate() != null) { + if (m_Task.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } AttributesImpl atts = new AttributesImpl(); addTypeName(atts, "table"); document.startElement("", "", I_AD_Task.Table_Name, atts); @@ -107,7 +113,7 @@ public class TaskElementHandler extends AbstractElementHandler { } - private void createTaskBinding(Properties ctx, TransformerHandler document, + private void createTaskBinding(PIPOContext ctx, TransformerHandler document, X_AD_Task m_Task) { PoExporter filler = new PoExporter(ctx, document, m_Task); List excludes = defaultExcludeList(X_AD_Task.Table_Name); @@ -118,9 +124,9 @@ public class TaskElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception { - Env.setContext(packout.getCtx(), X_AD_Task.COLUMNNAME_AD_Task_ID, recordId); + Env.setContext(packout.getCtx().ctx, X_AD_Task.COLUMNNAME_AD_Task_ID, recordId); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(X_AD_Task.COLUMNNAME_AD_Task_ID); + packout.getCtx().ctx.remove(X_AD_Task.COLUMNNAME_AD_Task_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/UserRoleElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/UserRoleElementHandler.java index de676bb06b..9f6cabdc9b 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/UserRoleElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/UserRoleElementHandler.java @@ -17,11 +17,11 @@ package org.adempiere.pipo2.handler; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; @@ -38,7 +38,8 @@ import org.xml.sax.helpers.AttributesImpl; public class UserRoleElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) throws SAXException { + public void startElement(PIPOContext ctx, Element element) + throws SAXException { int roleid =0; int userid =0; int orgid =0; @@ -48,22 +49,34 @@ public class UserRoleElementHandler extends AbstractElementHandler { X_AD_User_Roles po = findPO(ctx, element); if (po == null) { Element userElement = element.properties.get(I_AD_User_Roles.COLUMNNAME_AD_User_ID); - userid = ReferenceUtils.resolveReference(ctx, userElement, getTrxName(ctx)); - - if (getParentId(element, "role") > 0) { - roleid = getParentId(element, "role"); + userid = ReferenceUtils.resolveReference(ctx.ctx, userElement, getTrxName(ctx)); + if (userid <= 0) { + element.defer = true; + element.unresolved = "AD_User_ID " + (userElement.contents != null ? userElement.contents.toString() : ""); + return; + } + if (getParentId(element, X_AD_Role.Table_Name) > 0) { + roleid = getParentId(element, X_AD_Role.Table_Name); } else { - Element roleElement = element.properties.get(I_AD_User_Roles.COLUMNNAME_AD_Role_ID); - roleid = ReferenceUtils.resolveReference(ctx, roleElement, getTrxName(ctx)); + Element roleElement = element.properties.get("AD_Role_ID"); + roleid = ReferenceUtils.resolveReference(ctx.ctx, roleElement, + getTrxName(ctx)); + } + + if (roleid <= 0) + { + element.defer = true; + element.unresolved = "AD_Role_ID"; + return; } Element orgElement = element.properties.get(I_AD_User_Roles.COLUMNNAME_AD_Org_ID); - orgid = ReferenceUtils.resolveReference(ctx, orgElement, getTrxName(ctx)); + orgid = ReferenceUtils.resolveReference(ctx.ctx, orgElement, getTrxName(ctx)); - Query query = new Query(ctx, "AD_User_Roles", "AD_User_ID = ? AND AD_Role_ID = ? AND AD_Org_ID = ?", getTrxName(ctx)); + Query query = new Query(ctx.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 = new X_AD_User_Roles(ctx.ctx, 0, getTrxName(ctx)); po.setAD_Org_ID(orgid); po.setAD_Role_ID(roleid); po.setAD_User_ID(userid); @@ -76,33 +89,49 @@ public class UserRoleElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } po.saveEx(); } - public void endElement(Properties ctx, Element element) throws SAXException { - } - - public void create(Properties ctx, TransformerHandler document) + public void endElement(PIPOContext ctx, Element element) throws SAXException { - int AD_User_ID = Env.getContextAsInt(ctx, X_AD_User.COLUMNNAME_AD_User_ID); - int AD_Role_ID = Env.getContextAsInt(ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); - int AD_Org_ID = Env.getContextAsInt(ctx, "AD_Org_ID"); - AttributesImpl atts = new AttributesImpl(); - addTypeName(atts, "table"); - document.startElement("", "", I_AD_User_Roles.Table_Name, atts); - createUserAssignBinding(ctx, document, AD_User_ID,AD_Role_ID, AD_Org_ID); - document.endElement("", "", I_AD_User_Roles.Table_Name); } - private void createUserAssignBinding(Properties ctx, TransformerHandler document, - int user_id, int role_id, int org_id) { + public void create(PIPOContext ctx, TransformerHandler document) + throws SAXException { + int AD_User_ID = Env.getContextAsInt(ctx.ctx, X_AD_User.COLUMNNAME_AD_User_ID); + int AD_Role_ID = Env.getContextAsInt(ctx.ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); + int AD_Org_ID = Env.getContextAsInt(ctx.ctx, "AD_Org_ID"); + Query query = new Query(ctx.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[] { AD_User_ID, AD_Role_ID, AD_Org_ID }).first(); + if (po != null) { + if (ctx.packOut.getFromDate() != null) { + if (po.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } + AttributesImpl atts = new AttributesImpl(); + addTypeName(atts, "table"); + document.startElement("", "", I_AD_User_Roles.Table_Name, atts); + createUserAssignBinding(ctx, document, po); + document.endElement("", "", I_AD_User_Roles.Table_Name); + } + } - 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[]{user_id, role_id, org_id}).first(); + private void createUserAssignBinding(PIPOContext ctx, + TransformerHandler document, X_AD_User_Roles po) { PoExporter filler = new PoExporter(ctx, document, po); + + AttributesImpl orgRefAtts = new AttributesImpl(); + String orgReference = ReferenceUtils.getTableReference("AD_Org", "Name", po.getAD_Org_ID(), orgRefAtts); + filler.addString("AD_Org_ID", orgReference, orgRefAtts); + List excludes = defaultExcludeList(X_AD_User_Roles.Table_Name); + excludes.add("AD_Org_ID"); filler.export(excludes); } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WindowAccessElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WindowAccessElementHandler.java index 423fefabb4..f4820baeb4 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WindowAccessElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WindowAccessElementHandler.java @@ -17,11 +17,11 @@ package org.adempiere.pipo2.handler; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; @@ -39,7 +39,7 @@ import org.xml.sax.helpers.AttributesImpl; public class WindowAccessElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) throws SAXException { + public void startElement(PIPOContext ctx, Element element) throws SAXException { int roleid =0; int windowid =0; List excludes = defaultExcludeList(X_AD_Window_Access.Table_Name); @@ -50,24 +50,26 @@ public class WindowAccessElementHandler extends AbstractElementHandler { 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, getTrxName(ctx)); + roleid = ReferenceUtils.resolveReference(ctx.ctx, roleElement, getTrxName(ctx)); } if (roleid <= 0) { element.defer = true; + element.unresolved = "AD_Role_ID"; return; } Element windowElement = element.properties.get(I_AD_Window_Access.COLUMNNAME_AD_Window_ID); - windowid = ReferenceUtils.resolveReference(ctx, windowElement, getTrxName(ctx)); + windowid = ReferenceUtils.resolveReference(ctx.ctx, windowElement, getTrxName(ctx)); if (windowid <= 0) { element.defer = true; + element.unresolved = "AD_Window_ID"; return; } - Query query = new Query(ctx, "AD_Window_Access", "AD_Role_ID=? and AD_Window_ID=?", getTrxName(ctx)); + Query query = new Query(ctx.ctx, "AD_Window_Access", "AD_Role_ID=? and AD_Window_ID=?", getTrxName(ctx)); po = query.setParameters(new Object[]{roleid, windowid}).first(); if (po == null) { - po = new X_AD_Window_Access(ctx, 0, getTrxName(ctx)); + po = new X_AD_Window_Access(ctx.ctx, 0, getTrxName(ctx)); po.setAD_Role_ID(roleid); po.setAD_Window_ID(windowid); } @@ -76,30 +78,37 @@ public class WindowAccessElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } po.saveEx(); } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - 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(); - addTypeName(atts, "table"); - document.startElement("", "", I_AD_Window_Access.Table_Name, atts); - createWindowAccessBinding(ctx, document, AD_Window_ID, AD_Role_ID); - document.endElement("", "", I_AD_Window_Access.Table_Name); + int AD_Window_ID = Env.getContextAsInt(ctx.ctx, X_AD_Window.COLUMNNAME_AD_Window_ID); + int AD_Role_ID = Env.getContextAsInt(ctx.ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); + Query query = new Query(ctx.ctx, "AD_Window_Access", "AD_Role_ID=? and AD_Window_ID=?", getTrxName(ctx)); + X_AD_Window_Access po = query.setParameters(new Object[]{AD_Role_ID, AD_Window_ID}).first(); + if (po != null) { + if (ctx.packOut.getFromDate() != null) { + if (po.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } + AttributesImpl atts = new AttributesImpl(); + addTypeName(atts, "table"); + document.startElement("", "", I_AD_Window_Access.Table_Name, atts); + createWindowAccessBinding(ctx, document, po); + document.endElement("", "", I_AD_Window_Access.Table_Name); + } } - private void createWindowAccessBinding(Properties ctx, TransformerHandler document, - int window_id, int role_id) { - - 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[]{role_id, window_id}).first(); + private void createWindowAccessBinding(PIPOContext ctx, TransformerHandler document, + X_AD_Window_Access po) { PoExporter filler = new PoExporter(ctx, document, po); List excludes = defaultExcludeList(X_AD_Window_Access.Table_Name); diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WindowElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WindowElementHandler.java index f3b9730516..a5b9b2b41c 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WindowElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WindowElementHandler.java @@ -21,19 +21,21 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import java.util.logging.Level; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.ElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; 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_Color; +import org.compiere.model.I_AD_Image; import org.compiere.model.I_AD_Window; import org.compiere.model.MWindow; import org.compiere.model.X_AD_Package_Exp_Detail; @@ -53,12 +55,12 @@ public class WindowElementHandler extends AbstractElementHandler { private List windows = new ArrayList(); - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { List excludes = defaultExcludeList(X_AD_Window.Table_Name); String entitytype = getStringValue(element, "EntityType"); - if (isProcessElement(ctx, entitytype)) { + if (isProcessElement(ctx.ctx, entitytype)) { MWindow mWindow = findPO(ctx, element); if (mWindow == null) { String name = getStringValue(element, "Name", excludes); @@ -67,7 +69,7 @@ public class WindowElementHandler extends AbstractElementHandler { return; } - mWindow = new MWindow(ctx, id > 0 ? id : 0, getTrxName(ctx)); + mWindow = new MWindow(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); mWindow.setName(name); } else { if (windows.contains(mWindow.getAD_Window_ID())) { @@ -83,6 +85,7 @@ public class WindowElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -104,7 +107,7 @@ public class WindowElementHandler extends AbstractElementHandler { } else { logImportDetail(ctx, impDetail, 0, mWindow.getName(), mWindow .get_ID(), action); - throw new POSaveFailedException("Window"); + throw new POSaveFailedException("Failed to save Window " + mWindow.getName()); } } } else { @@ -112,19 +115,48 @@ public class WindowElementHandler extends AbstractElementHandler { } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int AD_Window_ID = Env.getContextAsInt(ctx, "AD_Window_ID"); - PackOut packOut = (PackOut) ctx.get("PackOutProcess"); + int AD_Window_ID = Env.getContextAsInt(ctx.ctx, "AD_Window_ID"); + PackOut packOut = ctx.packOut; - X_AD_Window m_Window = new X_AD_Window(ctx, AD_Window_ID, null); - AttributesImpl atts = new AttributesImpl(); - addTypeName(atts, "table"); - document.startElement("", "", I_AD_Window.Table_Name, atts); - createWindowBinding(ctx, document, m_Window); + boolean createElement = true; + X_AD_Window m_Window = new X_AD_Window(ctx.ctx, AD_Window_ID, null); + if (ctx.packOut.getFromDate() != null) { + if (m_Window.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + createElement = false; + } + } + + //export color + if (m_Window.getAD_Color_ID() > 0) { + ElementHandler handler = ctx.packOut.getHandler(I_AD_Color.Table_Name); + try { + handler.packOut(ctx.packOut, document, null, m_Window.getAD_Color_ID()); + } catch (Exception e) { + throw new SAXException(e); + } + } + + //export image + if (m_Window.getAD_Image_ID() > 0) { + ElementHandler handler = ctx.packOut.getHandler(I_AD_Image.Table_Name); + try { + handler.packOut(ctx.packOut, document, null, m_Window.getAD_Image_ID()); + } catch (Exception e) { + throw new SAXException(e); + } + } + + if (createElement) { + AttributesImpl atts = new AttributesImpl(); + addTypeName(atts, "table"); + 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 = " + AD_Window_ID; @@ -153,10 +185,9 @@ public class WindowElementHandler extends AbstractElementHandler { DB.close(rs, pstmt); } - //TODO: export of ad_image and ad_color use - - // Loop tags. - document.endElement("", "", I_AD_Window.Table_Name); + if (createElement) { + document.endElement("", "", X_AD_Window.Table_Name); + } // Preference Tag sql = "SELECT AD_Preference_ID FROM AD_PREFERENCE WHERE AD_WINDOW_ID = ?"; @@ -184,22 +215,22 @@ public class WindowElementHandler extends AbstractElementHandler { } } - private void createPreference(Properties ctx, TransformerHandler document, + private void createPreference(PIPOContext ctx, TransformerHandler document, int AD_Preference_ID) throws SAXException { - Env.setContext(ctx, X_AD_Preference.COLUMNNAME_AD_Preference_ID, + Env.setContext(ctx.ctx, X_AD_Preference.COLUMNNAME_AD_Preference_ID, AD_Preference_ID); preferenceHandler.create(ctx, document); - ctx.remove(X_AD_Preference.COLUMNNAME_AD_Preference_ID); + ctx.ctx.remove(X_AD_Preference.COLUMNNAME_AD_Preference_ID); } - private void createTab(Properties ctx, TransformerHandler document, + private void createTab(PIPOContext ctx, TransformerHandler document, int AD_Tab_ID) throws SAXException { - Env.setContext(ctx, X_AD_Tab.COLUMNNAME_AD_Tab_ID, AD_Tab_ID); + Env.setContext(ctx.ctx, X_AD_Tab.COLUMNNAME_AD_Tab_ID, AD_Tab_ID); tabHandler.create(ctx, document); - ctx.remove(X_AD_Tab.COLUMNNAME_AD_Tab_ID); + ctx.ctx.remove(X_AD_Tab.COLUMNNAME_AD_Tab_ID); } - private void createWindowBinding(Properties ctx, TransformerHandler document, + private void createWindowBinding(PIPOContext ctx, TransformerHandler document, X_AD_Window m_Window) { PoExporter filler = new PoExporter(ctx, document, m_Window); List excludes = defaultExcludeList(X_AD_Window.Table_Name); @@ -212,8 +243,8 @@ public class WindowElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception { - Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Window_ID, recordId); + Env.setContext(packout.getCtx().ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Window_ID, recordId); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Window_ID); + packout.getCtx().ctx.remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Window_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WorkflowAccessElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WorkflowAccessElementHandler.java index 0cfe314acf..0a39808222 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WorkflowAccessElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WorkflowAccessElementHandler.java @@ -17,11 +17,11 @@ package org.adempiere.pipo2.handler; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PackOut; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; @@ -34,32 +34,43 @@ 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.Env; +import org.compiere.wf.MWorkflowAccess; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; public class WorkflowAccessElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) throws SAXException { + public void startElement(PIPOContext ctx, Element element) throws SAXException { int roleid =0; int workflowid =0; List excludes = defaultExcludeList(X_AD_Workflow_Access.Table_Name); - X_AD_Workflow_Access po = findPO(ctx, element); + MWorkflowAccess po = findPO(ctx, element); if (po == null) { if (getParentId(element, I_AD_Role.Table_Name) > 0) { roleid = getParentId(element, I_AD_Role.Table_Name); } else { Element roleElement = element.properties.get(I_AD_Workflow_Access.COLUMNNAME_AD_Role_ID); - roleid = ReferenceUtils.resolveReference(ctx, roleElement, getTrxName(ctx)); + roleid = ReferenceUtils.resolveReference(ctx.ctx, roleElement, getTrxName(ctx)); + } + + if (roleid <= 0) { + element.defer = true; + element.unresolved = "AD_Role_ID"; + return; } Element wfElement = element.properties.get(I_AD_Workflow_Access.COLUMNNAME_AD_Workflow_ID); - workflowid = ReferenceUtils.resolveReference(ctx, wfElement, getTrxName(ctx)); + workflowid = ReferenceUtils.resolveReference(ctx.ctx, wfElement, getTrxName(ctx)); + if (workflowid <= 0) { + element.defer = true; + element.unresolved = "AD_Workflow_ID"; + } - Query query = new Query(ctx, "AD_Workflow_Access", "AD_Role_ID=? and AD_Workflow_ID=?", getTrxName(ctx)); + Query query = new Query(ctx.ctx, "AD_Workflow_Access", "AD_Role_ID=? and AD_Workflow_ID=?", getTrxName(ctx)); po = query.setParameters(new Object[]{roleid, workflowid}).first(); if (po == null) { - po = new X_AD_Workflow_Access(ctx, 0, getTrxName(ctx)); + po = new MWorkflowAccess(ctx.ctx, 0, getTrxName(ctx)); po.setAD_Role_ID(roleid); po.setAD_Workflow_ID(workflowid); } @@ -71,31 +82,38 @@ public class WorkflowAccessElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } po.saveEx(); } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - 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(); - addTypeName(atts, "table"); - document.startElement("", "", I_AD_Workflow_Access.Table_Name, atts); - createWorkflowAccessBinding(ctx, document, AD_Workflow_ID, AD_Role_ID); - document.endElement("", "", I_AD_Workflow_Access.Table_Name); + int AD_Workflow_ID = Env.getContextAsInt(ctx.ctx, X_AD_Workflow.COLUMNNAME_AD_Workflow_ID); + int AD_Role_ID = Env.getContextAsInt(ctx.ctx, X_AD_Role.COLUMNNAME_AD_Role_ID); + MWorkflowAccess po = null; + Query query = new Query(ctx.ctx, "AD_Workflow_Access", "AD_Role_ID=? and AD_Workflow_ID=?", getTrxName(ctx)); + po = query.setParameters(new Object[]{AD_Role_ID, AD_Workflow_ID}).first(); + if (po != null) { + if (ctx.packOut.getFromDate() != null) { + if (po.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } + AttributesImpl atts = new AttributesImpl(); + addTypeName(atts, "table"); + document.startElement("", "", I_AD_Workflow_Access.Table_Name, atts); + createWorkflowAccessBinding(ctx, document, po); + document.endElement("", "", I_AD_Workflow_Access.Table_Name); + } } - - private void createWorkflowAccessBinding(Properties ctx, TransformerHandler document, - int workflow_id, int role_id) { - - 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[]{role_id, workflow_id}).first(); + + private void createWorkflowAccessBinding(PIPOContext ctx, TransformerHandler document, + MWorkflowAccess po) { PoExporter filler = new PoExporter(ctx, document, po); List excludes = defaultExcludeList(X_AD_Workflow_Access.Table_Name); diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WorkflowElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WorkflowElementHandler.java index 22824fba3e..39a2dbec01 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WorkflowElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WorkflowElementHandler.java @@ -20,12 +20,12 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.exceptions.DBException; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -52,12 +52,12 @@ public class WorkflowElementHandler extends AbstractElementHandler { private List workflows = new ArrayList(); - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { List excludes = defaultExcludeList(X_AD_Workflow.Table_Name); String entitytype = getStringValue(element, "EntityType"); - if (isProcessElement(ctx, entitytype)) { + if (isProcessElement(ctx.ctx, entitytype)) { MWorkflow mWorkflow = findPO(ctx, element); if (mWorkflow == null) { @@ -68,7 +68,7 @@ public class WorkflowElementHandler extends AbstractElementHandler { return; } - mWorkflow = new MWorkflow(ctx, id > 0 ? id : 0, getTrxName(ctx)); + mWorkflow = new MWorkflow(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); mWorkflow.setValue(workflowValue); } @@ -78,6 +78,7 @@ public class WorkflowElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -102,7 +103,7 @@ public class WorkflowElementHandler extends AbstractElementHandler { log.info("m_Workflow save failure"); logImportDetail(ctx, impDetail, 0, mWorkflow.getName(), mWorkflow .get_ID(), action); - throw new POSaveFailedException("MWorkflow"); + throw new POSaveFailedException("Failed to save MWorkflow " + mWorkflow.getName()); } } } else { @@ -114,12 +115,12 @@ public class WorkflowElementHandler extends AbstractElementHandler { * @param ctx * @param element */ - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { if (!element.defer && !element.skip && element.recordId > 0) { //set start node String value = getStringValue(element, "AD_WF_Node.Value"); if (value != null && value.trim().length() > 0) { - MWorkflow m_Workflow = new MWorkflow(ctx, element.recordId, getTrxName(ctx)); + MWorkflow m_Workflow = new MWorkflow(ctx.ctx, element.recordId, getTrxName(ctx)); int id = findIdByColumnAndParentId(ctx, "AD_WF_Node", "Value", value, "AD_Workflow", m_Workflow.getAD_Workflow_ID()); if (id <= 0) { log.warning("Failed to resolve start node reference for workflow element. Workflow=" @@ -141,15 +142,15 @@ public class WorkflowElementHandler extends AbstractElementHandler { log.info("m_Workflow update fail"); logImportDetail(ctx, impDetail, 0, m_Workflow.getName(), m_Workflow .get_ID(), "Update"); - throw new POSaveFailedException("MWorkflow"); + throw new POSaveFailedException("Failed to save MWorkflow " + m_Workflow.getName()); } } } } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int AD_Workflow_ID = Env.getContextAsInt(ctx, + int AD_Workflow_ID = Env.getContextAsInt(ctx.ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID); if (workflows.contains(AD_Workflow_ID)) return; @@ -159,18 +160,30 @@ public class WorkflowElementHandler extends AbstractElementHandler { int ad_wf_nodenextcondition_id = 0; AttributesImpl atts = new AttributesImpl(); - X_AD_Workflow m_Workflow = new X_AD_Workflow(ctx, + boolean creatElement = true; + MWorkflow m_Workflow = new MWorkflow(ctx.ctx, AD_Workflow_ID, null); + if (ctx.packOut.getFromDate() != null) { + if (m_Workflow.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + creatElement = false; + } + } + if (creatElement) { + atts.addAttribute("", "", "type", "CDATA", "object"); + atts.addAttribute("", "", "type-name", "CDATA", "ad.workflow"); + document.startElement("", "", I_AD_Workflow.Table_Name, atts); + createWorkflowBinding(ctx, document, m_Workflow); + } - atts.addAttribute("", "", "type", "CDATA", "object"); - atts.addAttribute("", "", "type-name", "CDATA", "ad.workflow"); - 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; PreparedStatement pstmt = null; + PreparedStatement psNodeNext = null; + PreparedStatement psNCondition = null; ResultSet rs = null; + ResultSet nodeNextrs = null; + ResultSet nodeNConditionrs = null; try { pstmt = DB.prepareStatement(sql, getTrxName(ctx)); // Generated workflowNodeNext(s) and @@ -179,20 +192,18 @@ public class WorkflowElementHandler extends AbstractElementHandler { while (rs.next()) { int nodeId = rs.getInt("AD_WF_Node_ID"); createNode(ctx, document, nodeId); - - ad_wf_nodenext_id = 0; - - sql = "SELECT ad_wf_nodenext_id from ad_wf_nodenext WHERE ad_wf_node_id = ?"; - ad_wf_nodenext_id = DB.getSQLValue(null, sql, nodeId); - if (ad_wf_nodenext_id > 0) { + sql = "SELECT ad_wf_nodenext_id from ad_wf_nodenext WHERE ad_wf_node_id =" +nodeId; + psNodeNext = DB.prepareStatement(sql, getTrxName(ctx)); + nodeNextrs = psNodeNext.executeQuery(); + while (nodeNextrs.next()){ + ad_wf_nodenext_id = nodeNextrs.getInt("AD_WF_NodeNext_ID"); createNodeNext(ctx, document, ad_wf_nodenext_id); - - ad_wf_nodenextcondition_id = 0; - sql = "SELECT ad_wf_nextcondition_id from ad_wf_nextcondition WHERE ad_wf_nodenext_id = ?"; - ad_wf_nodenextcondition_id = DB.getSQLValue(null, sql, nodeId); - log.info("ad_wf_nodenextcondition_id: " - + String.valueOf(ad_wf_nodenextcondition_id)); - if (ad_wf_nodenextcondition_id > 0) { + sql = "SELECT ad_wf_nextcondition_id from ad_wf_nextcondition WHERE ad_wf_nodenext_id =" + ad_wf_nodenext_id; + psNCondition = DB.prepareStatement(sql, getTrxName(ctx)); + nodeNConditionrs = psNCondition.executeQuery(); + while (nodeNConditionrs.next()) { + ad_wf_nodenextcondition_id= nodeNConditionrs.getInt("AD_WF_NextCondition_ID"); + log.info("ad_wf_nodenextcondition_id: "+ String.valueOf(ad_wf_nodenextcondition_id)); createNodeNextCondition(ctx, document, ad_wf_nodenextcondition_id); } } @@ -201,37 +212,41 @@ public class WorkflowElementHandler extends AbstractElementHandler { throw new DBException(e); } finally { DB.close(rs, pstmt); - document.endElement("", "", I_AD_Workflow.Table_Name); + DB.close(nodeNextrs, psNodeNext); + DB.close(nodeNConditionrs,psNCondition); + if (creatElement) { + document.endElement("", "", MWorkflow.Table_Name); + } } } - private void createNodeNextCondition(Properties ctx, + private void createNodeNextCondition(PIPOContext ctx, TransformerHandler document, int ad_wf_nodenextcondition_id) throws SAXException { - Env.setContext(ctx, + Env.setContext(ctx.ctx, X_AD_WF_NextCondition.COLUMNNAME_AD_WF_NextCondition_ID, ad_wf_nodenextcondition_id); nextConditionHandler.create(ctx, document); - ctx.remove(X_AD_WF_NextCondition.COLUMNNAME_AD_WF_NextCondition_ID); + ctx.ctx.remove(X_AD_WF_NextCondition.COLUMNNAME_AD_WF_NextCondition_ID); } - private void createNodeNext(Properties ctx, TransformerHandler document, + private void createNodeNext(PIPOContext ctx, TransformerHandler document, int ad_wf_nodenext_id) throws SAXException { - Env.setContext(ctx, X_AD_WF_NodeNext.COLUMNNAME_AD_WF_NodeNext_ID, + Env.setContext(ctx.ctx, X_AD_WF_NodeNext.COLUMNNAME_AD_WF_NodeNext_ID, ad_wf_nodenext_id); nodeNextHandler.create(ctx, document); - ctx.remove(X_AD_WF_NodeNext.COLUMNNAME_AD_WF_NodeNext_ID); + ctx.ctx.remove(X_AD_WF_NodeNext.COLUMNNAME_AD_WF_NodeNext_ID); } - private void createNode(Properties ctx, TransformerHandler document, + private void createNode(PIPOContext ctx, TransformerHandler document, int AD_WF_Node_ID) throws SAXException { - Env.setContext(ctx, X_AD_WF_Node.COLUMNNAME_AD_WF_Node_ID, + Env.setContext(ctx.ctx, X_AD_WF_Node.COLUMNNAME_AD_WF_Node_ID, AD_WF_Node_ID); nodeHandler.create(ctx, document); - ctx.remove(X_AD_WF_Node.COLUMNNAME_AD_WF_Node_ID); + ctx.ctx.remove(X_AD_WF_Node.COLUMNNAME_AD_WF_Node_ID); } - private void createWorkflowBinding(Properties ctx, TransformerHandler document, X_AD_Workflow m_Workflow) { + private void createWorkflowBinding(PIPOContext ctx, TransformerHandler document, MWorkflow m_Workflow) { PoExporter filler = new PoExporter(ctx, document, m_Workflow); List excludes = defaultExcludeList(X_AD_Workflow.Table_Name); @@ -244,8 +259,8 @@ public class WorkflowElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler,int recordId) throws Exception { - Env.setContext(packout.getCtx(), X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID, recordId); + Env.setContext(packout.getCtx().ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID, recordId); this.create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID); + packout.getCtx().ctx.remove(X_AD_Package_Exp_Detail.COLUMNNAME_AD_Workflow_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WorkflowNodeElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WorkflowNodeElementHandler.java index 8fbe739a71..b641aa561f 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WorkflowNodeElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WorkflowNodeElementHandler.java @@ -18,11 +18,11 @@ package org.adempiere.pipo2.handler; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -35,35 +35,37 @@ import org.compiere.model.X_AD_Package_Imp_Detail; import org.compiere.model.X_AD_WF_Node; import org.compiere.util.DB; import org.compiere.util.Env; +import org.compiere.wf.MWFNode; +import org.compiere.wf.MWorkflow; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; public class WorkflowNodeElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { List excludes = defaultExcludeList(X_AD_WF_Node.Table_Name); String entitytype = getStringValue(element, "EntityType"); - if (isProcessElement(ctx, entitytype)) { - if (isParentSkip(element, null)) { + if (isProcessElement(ctx.ctx, entitytype)) { + /*if (isParentSkip(element, null)) { element.skip = true; return; - } - if (isParentDefer(element, I_AD_Workflow.Table_Name)) { + }*/ + if (isParentDefer(element, MWorkflow.Table_Name)) { element.unresolved = "Parent element mark as defer: " + getStringValue(element, "AD_Workflow.Value"); element.defer = true; return; } - X_AD_WF_Node mWFNode = findPO(ctx, element); + MWFNode mWFNode = findPO(ctx, element); if (mWFNode == null) { int workflowId = 0; Element wfElement = element.properties.get(I_AD_WF_Node.COLUMNNAME_AD_Workflow_ID); if (getParentId(element, I_AD_Workflow.Table_Name) > 0) { workflowId = getParentId(element, I_AD_Workflow.Table_Name); } else { - workflowId = ReferenceUtils.resolveReference(ctx, wfElement, getTrxName(ctx)); + workflowId = ReferenceUtils.resolveReference(ctx.ctx, wfElement, getTrxName(ctx)); } if (workflowId <= 0) { element.defer = true; @@ -76,7 +78,7 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler { "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 = new MWFNode(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); mWFNode.setValue(workflowNodeValue); mWFNode.setAD_Workflow_ID(workflowId); excludes.add(I_AD_WF_Node.COLUMNNAME_AD_Workflow_ID); @@ -87,6 +89,7 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -110,7 +113,7 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler { log.info("m_WFNode save failure"); logImportDetail(ctx, impDetail, 0, mWFNode.getName(), mWFNode .get_ID(), action); - throw new POSaveFailedException("WorkflowNode"); + throw new POSaveFailedException("Failed to save WorkflowNode " + mWFNode.getName()); } } } else { @@ -118,25 +121,29 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler { } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int AD_WF_Node_ID = Env.getContextAsInt(ctx, + int AD_WF_Node_ID = Env.getContextAsInt(ctx.ctx, X_AD_WF_Node.COLUMNNAME_AD_WF_Node_ID); AttributesImpl atts = new AttributesImpl(); - X_AD_WF_Node m_WF_Node = new X_AD_WF_Node(ctx, AD_WF_Node_ID, + MWFNode m_WF_Node = new MWFNode(ctx.ctx, AD_WF_Node_ID, getTrxName(ctx)); - + if (ctx.packOut.getFromDate() != null) { + if (m_WF_Node.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } addTypeName(atts, "table"); document.startElement("", "", I_AD_WF_Node.Table_Name, atts); createWorkflowNodeBinding(ctx, document, m_WF_Node); document.endElement("", "", I_AD_WF_Node.Table_Name); } - private void createWorkflowNodeBinding(Properties ctx, TransformerHandler document, - X_AD_WF_Node m_WF_Node) { + private void createWorkflowNodeBinding(PIPOContext ctx, TransformerHandler document, + MWFNode m_WF_Node) { PoExporter filler = new PoExporter(ctx, document, m_WF_Node); List excludes = defaultExcludeList(X_AD_WF_Node.Table_Name); @@ -150,8 +157,8 @@ public class WorkflowNodeElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler, int recordId) throws Exception { - Env.setContext(packout.getCtx(), I_AD_WF_Node.COLUMNNAME_AD_WF_Node_ID, recordId); + Env.setContext(packout.getCtx().ctx, I_AD_WF_Node.COLUMNNAME_AD_WF_Node_ID, recordId); create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(I_AD_WF_Node.COLUMNNAME_AD_WF_Node_ID); + packout.getCtx().ctx.remove(I_AD_WF_Node.COLUMNNAME_AD_WF_Node_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WorkflowNodeNextConditionElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WorkflowNodeNextConditionElementHandler.java index dfb516f451..fd92a9494c 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WorkflowNodeNextConditionElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WorkflowNodeNextConditionElementHandler.java @@ -17,11 +17,11 @@ package org.adempiere.pipo2.handler; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -30,27 +30,30 @@ import org.adempiere.pipo2.ReferenceUtils; import org.adempiere.pipo2.exception.POSaveFailedException; import org.compiere.model.I_AD_WF_NextCondition; import org.compiere.model.I_AD_Workflow; +import org.compiere.model.MColumn; import org.compiere.model.X_AD_Package_Imp_Detail; import org.compiere.model.X_AD_WF_NextCondition; import org.compiere.util.DB; import org.compiere.util.Env; import org.compiere.wf.MWFNextCondition; +import org.compiere.wf.MWFNode; +import org.compiere.wf.MWFNodeNext; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; public class WorkflowNodeNextConditionElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) + public void startElement(PIPOContext ctx, Element element) throws SAXException { List excludes = defaultExcludeList(X_AD_WF_NextCondition.Table_Name); String entitytype = getStringValue(element, "EntityType"); - if (isProcessElement(ctx, entitytype)) { - if (isParentSkip(element, null)) { + if (isProcessElement(ctx.ctx, entitytype)) { + /* if (isParentSkip(element, null)) { element.skip = true; return; - } + }*/ MWFNextCondition mWFNodeNextCondition = findPO(ctx, element); if (mWFNodeNextCondition == null) { @@ -59,7 +62,7 @@ public class WorkflowNodeNextConditionElementHandler extends if (getParentId(element, I_AD_Workflow.Table_Name) > 0) { workflowId = getParentId(element, I_AD_Workflow.Table_Name); } else { - workflowId = ReferenceUtils.resolveReference(ctx, wfElement, getTrxName(ctx)); + workflowId = ReferenceUtils.resolveReference(ctx.ctx, wfElement, getTrxName(ctx)); } if (workflowId <= 0) { element.defer = true; @@ -67,36 +70,20 @@ public class WorkflowNodeNextConditionElementHandler extends 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, getTrxName(ctx)); - } else { - Element wfnElement = element.properties.get("AD_WF_Node_ID"); - int wfNodeId = ReferenceUtils.resolveReference(ctx, wfnElement, getTrxName(ctx)); - 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, getTrxName(ctx)); - 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); + Element nextElement = element.properties.get("AD_WF_NodeNext_ID"); + int wfNodeNextId = ReferenceUtils.resolveReference(ctx.ctx, nextElement, getTrxName(ctx)); + if (wfNodeNextId <= 0) { + element.unresolved = "AD_WF_NodeNext=" + nextElement.contents; + element.defer = true; + return; } - 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); + int seqNo = getIntValue(element, "SeqNo"); + String sql = "SELECT AD_WF_NextCondition_ID FROM AD_WF_NextCondition WHERE AD_WF_NodeNext_ID =? AND SeqNo=?"; + int id = DB.getSQLValue(getTrxName(ctx), sql, new Object[] {wfNodeNextId, seqNo}); - mWFNodeNextCondition = new MWFNextCondition(ctx, id > 0 ? id : 0, getTrxName(ctx)); - mWFNodeNextCondition.setAD_WF_NodeNext_ID(AD_WF_NodeNext_ID); + mWFNodeNextCondition = new MWFNextCondition(ctx.ctx, id > 0 ? id : 0, getTrxName(ctx)); + mWFNodeNextCondition.setAD_WF_NodeNext_ID(wfNodeNextId); } PoFiller filler = new PoFiller(ctx, mWFNodeNextCondition, element, this); @@ -107,9 +94,9 @@ public class WorkflowNodeNextConditionElementHandler extends Element columnElement = element.properties.get("AD_Column_ID"); int columnId = 0; if (ReferenceUtils.isIDLookup(columnElement) || ReferenceUtils.isUUIDLookup(columnElement)) { - columnId = ReferenceUtils.resolveReference(ctx, columnElement, getTrxName(ctx)); + columnId = ReferenceUtils.resolveReference(ctx.ctx, columnElement, getTrxName(ctx)); } else { - int AD_Table_ID = ReferenceUtils.resolveReference(ctx, tableElement, getTrxName(ctx)); + int AD_Table_ID = ReferenceUtils.resolveReference(ctx.ctx, tableElement, getTrxName(ctx)); columnId = findIdByColumnAndParentId(ctx, "AD_Column", "ColumnName", columnElement.contents.toString(), "AD_Table", AD_Table_ID); } mWFNodeNextCondition.setAD_Column_ID(columnId); @@ -117,6 +104,7 @@ public class WorkflowNodeNextConditionElementHandler extends List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -149,7 +137,7 @@ public class WorkflowNodeNextConditionElementHandler extends String.valueOf(mWFNodeNextCondition.get_ID()), mWFNodeNextCondition.get_ID(), action); - throw new POSaveFailedException("WorkflowNodeNextCondition"); + throw new POSaveFailedException("Failed to save WorkflowNodeNextCondition"); } } } else { @@ -157,15 +145,19 @@ public class WorkflowNodeNextConditionElementHandler extends } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int ad_wf_nodenextcondition_id = Env.getContextAsInt(ctx, - X_AD_WF_NextCondition.COLUMNNAME_AD_WF_NextCondition_ID); - X_AD_WF_NextCondition m_WF_NodeNextCondition = new X_AD_WF_NextCondition( - ctx, ad_wf_nodenextcondition_id, null); + int ad_wf_nodenextcondition_id = Env.getContextAsInt(ctx.ctx, "AD_WF_NextCondition_ID"); + MWFNextCondition m_WF_NodeNextCondition = new MWFNextCondition( + ctx.ctx, ad_wf_nodenextcondition_id, null); + if (ctx.packOut.getFromDate() != null) { + if (m_WF_NodeNextCondition.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } AttributesImpl atts = new AttributesImpl(); addTypeName(atts, "table"); document.startElement("", "", I_AD_WF_NextCondition.Table_Name, atts); @@ -173,30 +165,34 @@ public class WorkflowNodeNextConditionElementHandler extends document.endElement("", "", I_AD_WF_NextCondition.Table_Name); } - private void createWorkflowNodeNextConditionBinding(Properties ctx, TransformerHandler document, X_AD_WF_NextCondition mWFNodeNextCondition) { + private void createWorkflowNodeNextConditionBinding(PIPOContext ctx, TransformerHandler document, MWFNextCondition mWFNodeNextCondition) { PoExporter filler = new PoExporter(ctx, document, mWFNodeNextCondition); List excludes = defaultExcludeList(X_AD_WF_NextCondition.Table_Name); if (mWFNodeNextCondition.getAD_WF_NextCondition_ID() <= PackOut.MAX_OFFICIAL_ID) filler.add("AD_WF_NextCondition_ID", new AttributesImpl()); - int AD_workflow_ID = mWFNodeNextCondition.getAD_WF_NodeNext().getAD_WF_Node().getAD_Workflow_ID(); + MWFNodeNext mWFNodeNext = new MWFNodeNext(ctx.ctx, mWFNodeNextCondition.getAD_WF_NodeNext_ID(), getTrxName(ctx)); + MWFNode mWFNode = new MWFNode(ctx.ctx, mWFNodeNext.getAD_WF_Node_ID(), getTrxName(ctx)); + int AD_workflow_ID = mWFNode.getAD_Workflow_ID(); AttributesImpl wfAttributes = new AttributesImpl(); String value = ReferenceUtils.getTableReference("AD_Workflow", "Value", AD_workflow_ID, wfAttributes); filler.addString("AD_Workflow_ID", value, wfAttributes); - int AD_WF_Node_ID = mWFNodeNextCondition.getAD_WF_NodeNext().getAD_WF_Node_ID(); + int AD_WF_Node_ID = mWFNodeNext.getAD_WF_Node_ID(); AttributesImpl wfnAttributes = new AttributesImpl(); value = ReferenceUtils.getTableReference("AD_WF_Node", "Value", AD_WF_Node_ID, wfnAttributes); filler.addString("AD_WF_Node_ID", value, wfnAttributes); - int AD_WF_Next_ID = mWFNodeNextCondition.getAD_WF_NodeNext().getAD_WF_Next_ID(); + int AD_WF_Next_ID = mWFNodeNext.getAD_WF_Next_ID(); AttributesImpl nextAttributes = new AttributesImpl(); value = ReferenceUtils.getTableReference("AD_WF_Node", "Value", AD_WF_Next_ID, nextAttributes); filler.addString("AD_WF_Next_ID", value, nextAttributes); if (mWFNodeNextCondition.getAD_Column_ID() > 0) { - int AD_Table_ID = mWFNodeNextCondition.getAD_Column().getAD_Table_ID(); + int AD_Column_ID = mWFNodeNextCondition.getAD_Column_ID(); + MColumn mColumn = new MColumn(ctx.ctx, AD_Column_ID, getTrxName(ctx)); + int AD_Table_ID = mColumn.getAD_Table_ID(); AttributesImpl tableAttributes = new AttributesImpl(); value = ReferenceUtils.getTableReference("AD_Table", "TableName", AD_Table_ID, tableAttributes); filler.addString("AD_Table_ID", value, tableAttributes); @@ -209,9 +205,9 @@ public class WorkflowNodeNextConditionElementHandler extends public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler, int recordId) throws Exception { - Env.setContext(packout.getCtx(), I_AD_WF_NextCondition.COLUMNNAME_AD_WF_NextCondition_ID, recordId); + Env.setContext(packout.getCtx().ctx, I_AD_WF_NextCondition.COLUMNNAME_AD_WF_NextCondition_ID, recordId); create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(I_AD_WF_NextCondition.COLUMNNAME_AD_WF_NextCondition_ID); + packout.getCtx().ctx.remove(I_AD_WF_NextCondition.COLUMNNAME_AD_WF_NextCondition_ID); } } diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WorkflowNodeNextElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WorkflowNodeNextElementHandler.java index 4ca338d6a6..02e5a90ffa 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WorkflowNodeNextElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/WorkflowNodeNextElementHandler.java @@ -17,11 +17,11 @@ package org.adempiere.pipo2.handler; import java.util.List; -import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.pipo2.AbstractElementHandler; +import org.adempiere.pipo2.PIPOContext; import org.adempiere.pipo2.PoExporter; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PackOut; @@ -41,15 +41,15 @@ import org.xml.sax.helpers.AttributesImpl; public class WorkflowNodeNextElementHandler extends AbstractElementHandler { - public void startElement(Properties ctx, Element element) throws SAXException { - List excludes = defaultExcludeList(X_AD_WF_NodeNext.Table_Name); + public void startElement(PIPOContext ctx, Element element) throws SAXException { + List excludes = defaultExcludeList(MWFNodeNext.Table_Name); String entitytype = getStringValue(element, "EntityType"); - if (isProcessElement(ctx, entitytype)) { - if (isParentSkip(element, null)) { + if (isProcessElement(ctx.ctx, entitytype)) { + /*if (isParentSkip(element, null)) { element.skip = true; return; - } + }*/ MWFNodeNext mWFNodeNext = findPO(ctx, element); if (mWFNodeNext == null) { @@ -58,7 +58,7 @@ public class WorkflowNodeNextElementHandler extends AbstractElementHandler { if (getParentId(element, I_AD_Workflow.Table_Name) > 0) { workflowId = getParentId(element, I_AD_Workflow.Table_Name); } else { - workflowId = ReferenceUtils.resolveReference(ctx, wfElement, getTrxName(ctx)); + workflowId = ReferenceUtils.resolveReference(ctx.ctx, wfElement, getTrxName(ctx)); } if (workflowId <= 0) { element.defer = true; @@ -69,10 +69,10 @@ public class WorkflowNodeNextElementHandler extends AbstractElementHandler { 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, getTrxName(ctx)); + wfNodeId = ReferenceUtils.resolveReference(ctx.ctx, wfnElement, getTrxName(ctx)); } else { wfNodeId = DB.getSQLValue(getTrxName(ctx), "SELECT AD_WF_Node_Id FROM AD_WF_Node WHERE AD_Workflow_ID=? AND Value=? AND AD_Client_ID=?", - workflowId, wfnElement.contents.toString(), Env.getAD_Client_ID(ctx)); + workflowId, wfnElement.contents.toString(), Env.getAD_Client_ID(ctx.ctx)); } if (wfNodeId <= 0) { element.defer = true; @@ -83,10 +83,10 @@ public class WorkflowNodeNextElementHandler extends AbstractElementHandler { 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, getTrxName(ctx)); + AD_WF_Next_ID = ReferenceUtils.resolveReference(ctx.ctx, nextElement, getTrxName(ctx)); } else { AD_WF_Next_ID = DB.getSQLValue(getTrxName(ctx), "SELECT AD_WF_Node_Id FROM AD_WF_Node WHERE AD_Workflow_ID=? AND Value=? AND AD_Client_ID=?", - workflowId, nextElement.contents.toString(), Env.getAD_Client_ID(ctx)); + workflowId, nextElement.contents.toString(), Env.getAD_Client_ID(ctx.ctx)); } if (AD_WF_Next_ID <= 0) { element.defer = true; @@ -96,7 +96,7 @@ public class WorkflowNodeNextElementHandler extends AbstractElementHandler { 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 = new MWFNodeNext(ctx.ctx, AD_WF_NodeNext_ID, getTrxName(ctx)); mWFNodeNext.setAD_WF_Node_ID(wfNodeId); mWFNodeNext.setAD_WF_Next_ID(AD_WF_Next_ID); } @@ -108,6 +108,7 @@ public class WorkflowNodeNextElementHandler extends AbstractElementHandler { List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true; + element.unresolved = notfounds.toString(); return; } @@ -127,7 +128,7 @@ public class WorkflowNodeNextElementHandler extends AbstractElementHandler { } else{ log.info("m_WFNodeNext save failure"); logImportDetail (ctx, impDetail, 0, String.valueOf(mWFNodeNext.get_ID()), mWFNodeNext.get_ID(), action); - throw new POSaveFailedException("WorkflowNodeNext"); + throw new POSaveFailedException("Failed to save WorkflowNodeNext"); } } } else { @@ -135,14 +136,19 @@ public class WorkflowNodeNextElementHandler extends AbstractElementHandler { } } - public void endElement(Properties ctx, Element element) throws SAXException { + public void endElement(PIPOContext ctx, Element element) throws SAXException { } - public void create(Properties ctx, TransformerHandler document) + public void create(PIPOContext ctx, TransformerHandler document) throws SAXException { - int ad_wf_nodenext_id = Env.getContextAsInt(ctx, X_AD_WF_NodeNext.COLUMNNAME_AD_WF_NodeNext_ID); - X_AD_WF_NodeNext m_WF_NodeNext = new X_AD_WF_NodeNext( - ctx, ad_wf_nodenext_id, null); + int ad_wf_nodenext_id = Env.getContextAsInt(ctx.ctx, "AD_WF_NodeNext_ID"); + MWFNodeNext m_WF_NodeNext = new MWFNodeNext( + ctx.ctx, ad_wf_nodenext_id, null); + if (ctx.packOut.getFromDate() != null) { + if (m_WF_NodeNext.getUpdated().compareTo(ctx.packOut.getFromDate()) < 0) { + return; + } + } AttributesImpl atts = new AttributesImpl(); addTypeName(atts, "table"); document.startElement("", "", I_AD_WF_NodeNext.Table_Name, atts); @@ -151,8 +157,8 @@ public class WorkflowNodeNextElementHandler extends AbstractElementHandler { } - private void createWorkflowNodeNextBinding(Properties ctx, TransformerHandler document, - X_AD_WF_NodeNext m_WF_NodeNext) + private void createWorkflowNodeNextBinding(PIPOContext ctx, TransformerHandler document, + MWFNodeNext m_WF_NodeNext) { PoExporter filler = new PoExporter(ctx, document, m_WF_NodeNext); @@ -161,6 +167,9 @@ public class WorkflowNodeNextElementHandler extends AbstractElementHandler { if (m_WF_NodeNext.getAD_WF_NodeNext_ID() <= PackOut.MAX_OFFICIAL_ID) filler.add("AD_WF_NodeNext_ID", new AttributesImpl()); + int AD_Workflow_ID = DB.getSQLValue(getTrxName(ctx), "SELECT AD_Workflow_ID FROM AD_WF_Node WHERE AD_WF_Node_ID=?", m_WF_NodeNext.getAD_WF_Node_ID()); + filler.addTableReference("AD_Workflow_ID", "AD_Workflow", "Value", AD_Workflow_ID, new AttributesImpl()); + filler.export(excludes); } @@ -168,8 +177,8 @@ public class WorkflowNodeNextElementHandler extends AbstractElementHandler { public void packOut(PackOut packout, TransformerHandler packoutHandler, TransformerHandler docHandler, int recordId) throws Exception { - Env.setContext(packout.getCtx(), I_AD_WF_NodeNext.COLUMNNAME_AD_WF_NodeNext_ID, recordId); + Env.setContext(packout.getCtx().ctx, I_AD_WF_NodeNext.COLUMNNAME_AD_WF_NodeNext_ID, recordId); create(packout.getCtx(), packoutHandler); - packout.getCtx().remove(I_AD_WF_NodeNext.COLUMNNAME_AD_WF_NodeNext_ID); + packout.getCtx().ctx.remove(I_AD_WF_NodeNext.COLUMNNAME_AD_WF_NodeNext_ID); } } diff --git a/org.adempiere.pipo/META-INF/MANIFEST.MF b/org.adempiere.pipo/META-INF/MANIFEST.MF index 0771926de6..3987c75f95 100644 --- a/org.adempiere.pipo/META-INF/MANIFEST.MF +++ b/org.adempiere.pipo/META-INF/MANIFEST.MF @@ -4,7 +4,9 @@ Bundle-Name: PiPo Bundle-SymbolicName: org.adempiere.pipo;singleton:=true Bundle-Version: 1.0.0.qualifier Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Import-Package: org.apache.tools.ant, +Import-Package: org.apache.commons.codec;version="1.3.0", + org.apache.commons.codec.binary;version="1.3.0", + org.apache.tools.ant, org.apache.tools.ant.taskdefs, org.apache.xerces.jaxp;version="2.9.0", org.osgi.framework diff --git a/org.adempiere.pipo/src/org/adempiere/pipo2/AbstractElementHandler.java b/org.adempiere.pipo/src/org/adempiere/pipo2/AbstractElementHandler.java index 39280d9f3d..92bee91180 100644 --- a/org.adempiere.pipo/src/org/adempiere/pipo2/AbstractElementHandler.java +++ b/org.adempiere.pipo/src/org/adempiere/pipo2/AbstractElementHandler.java @@ -61,8 +61,8 @@ public abstract class AbstractElementHandler implements ElementHandler { * @param name * */ - public int findIdByName (Properties ctx, String tableName, String name) { - return IDFinder.findIdByName(tableName, name, getClientId(ctx), getTrxName(ctx)); + public int findIdByName (PIPOContext ctx, String tableName, String name) { + return IDFinder.findIdByName(tableName, name, getClientId(ctx.ctx), ctx.trx.getTrxName()); } /** @@ -72,22 +72,25 @@ public abstract class AbstractElementHandler implements ElementHandler { * @param columName * @param name */ - public int findIdByColumn (Properties ctx, String tableName, String columnName, Object value) { + public int findIdByColumn (PIPOContext ctx, String tableName, String columnName, Object value, boolean ignorecase) { int id = 0; if ("AD_Table".equals(tableName) && "TableName".equals(columnName) && value != null) { - id = getPackIn(ctx).getTableId(value.toString()); + id = ctx.packIn.getTableId(value.toString()); if (id <= 0) { - id = IDFinder.findIdByColumn(tableName, columnName, value, getClientId(ctx), getTrxName(ctx)); + id = IDFinder.findIdByColumn(tableName, columnName, value, getClientId(ctx.ctx), ignorecase, ctx.trx.getTrxName()); if (id > 0) { - getPackIn(ctx).addTable(value.toString(), id); + ctx.packIn.addTable(value.toString(), id); } } } else { - id = IDFinder.findIdByColumn(tableName, columnName, value, getClientId(ctx), getTrxName(ctx)); + id = IDFinder.findIdByColumn(tableName, columnName, value, getClientId(ctx.ctx), ignorecase, ctx.trx.getTrxName()); } return id; } + public int findIdByColumn (PIPOContext ctx, String tableName, String columnName, Object value) { + return findIdByColumn (ctx, tableName, columnName, value, false); + } /** * @param ctx * @param type @@ -95,17 +98,17 @@ public abstract class AbstractElementHandler implements ElementHandler { * @param tableId * @return X_AD_Package_Imp_Detail */ - public X_AD_Package_Imp_Detail createImportDetail(Properties ctx, String type, String tableName, int tableId) { - X_AD_Package_Imp_Detail impDetail = new X_AD_Package_Imp_Detail(ctx, 0, getTrxName(ctx)); - impDetail.setAD_Package_Imp_ID(getPackageImpId(ctx)); - impDetail.setAD_Org_ID(Env.getAD_Org_ID(ctx) ); + public X_AD_Package_Imp_Detail createImportDetail(PIPOContext ctx, String type, String tableName, int tableId) { + X_AD_Package_Imp_Detail impDetail = new X_AD_Package_Imp_Detail(ctx.ctx, 0, ctx.trx.getTrxName()); + impDetail.setAD_Package_Imp_ID(getPackageImpId(ctx.ctx)); + impDetail.setAD_Org_ID(Env.getAD_Org_ID(ctx.ctx) ); impDetail.setType(type); impDetail.setName(""); impDetail.setAction(""); impDetail.setAD_Original_ID(1); impDetail.setTableName(tableName); impDetail.setAD_Table_ID(tableId); - impDetail.saveEx(getTrxName(ctx)); + impDetail.saveEx(ctx.trx.getTrxName()); return impDetail; } @@ -122,33 +125,15 @@ public abstract class AbstractElementHandler implements ElementHandler { * @throws SAXException * */ - public void logImportDetail (Properties ctx, X_AD_Package_Imp_Detail detail, int success, String objectName, int objectID, + public void logImportDetail (PIPOContext ctx, X_AD_Package_Imp_Detail detail, int success, String objectName, int objectID, String action) throws SAXException{ - StringBuffer recordLayout = new StringBuffer(); - TransformerHandler hd_document = getLogDocument(ctx); - AttributesImpl attsOut = new AttributesImpl(); String result = success == 1 ? "Success" : "Failure"; - //hd_documemt.startElement("","","Successful",attsOut); - recordLayout.append("Type:") - .append(detail.getType()) - .append(" - Name:") - .append(objectName) - .append(" - ID:") - .append(objectID) - .append(" - Action:") - .append(action) - .append(" - " + result); - - hd_document.startElement("","",result,attsOut); - hd_document.characters(recordLayout.toString().toCharArray(),0,recordLayout.length()); - hd_document.endElement("","",result); - detail.setName(objectName); detail.setAction(action); detail.setSuccess(result); detail.setAD_Original_ID(objectID); - detail.saveEx(getTrxName(ctx)); + ctx.packIn.addImportDetail(detail); } /** @@ -159,8 +144,8 @@ public abstract class AbstractElementHandler implements ElementHandler { * @param tableNameMaster * @param nameMaster */ - public int findIdByNameAndParentName (Properties ctx, String tableName, String name, String tableNameMaster, String nameMaster) { - return IDFinder.findIdByNameAndParentName(tableName, name, tableNameMaster, nameMaster, getTrxName(ctx)); + public int findIdByNameAndParentName (PIPOContext ctx, String tableName, String name, String tableNameMaster, String nameMaster) { + return IDFinder.findIdByNameAndParentName(tableName, name, tableNameMaster, nameMaster, getClientId(ctx.ctx), ctx.trx.getTrxName()); } /** @@ -172,11 +157,25 @@ public abstract class AbstractElementHandler implements ElementHandler { * @param nameMaster */ - public int findIdByColumnAndParentId (Properties ctx, String tableName, String columnName, String name, String tableNameMaster, int masterID) { - return IDFinder.findIdByColumnAndParentId(tableName, columnName, name, tableNameMaster, masterID, - getTrxName(ctx)); + public int findIdByColumnAndParentId (PIPOContext ctx, String tableName, String columnName, String name, String tableNameMaster, int masterID) { + return IDFinder.findIdByColumnAndParentId(tableName, columnName, name, tableNameMaster, masterID, getClientId(ctx.ctx), + ctx.trx.getTrxName()); } + /** + * Get ID from column value for a table with a parent id reference. + * + * @param tableName + * @param name + * @param tableNameMaster + * @param nameMaster + * @param ignoreCase + */ + public int findIdByColumnAndParentId (PIPOContext ctx, String tableName, String columnName, String name, String tableNameMaster, int masterID, boolean ignoreCase) { + return IDFinder.findIdByColumnAndParentId(tableName, columnName, name, tableNameMaster, masterID, getClientId(ctx.ctx), + ignoreCase, ctx.trx.getTrxName()); + } + /** * Get ID from Name for a table with a parent reference ID. * @@ -185,8 +184,8 @@ public abstract class AbstractElementHandler implements ElementHandler { * @param tableNameMaster * @param masterID */ - public int findIdByNameAndParentId (Properties ctx, String tableName, String name, String tableNameMaster, int masterID) { - return IDFinder.findIdByNameAndParentId(tableName, name, tableNameMaster, masterID, getTrxName(ctx)); + public int findIdByNameAndParentId (PIPOContext ctx, String tableName, String name, String tableNameMaster, int masterID) { + return IDFinder.findIdByNameAndParentId(tableName, name, tableNameMaster, masterID, getClientId(ctx.ctx), ctx.trx.getTrxName()); } /** @@ -198,40 +197,42 @@ public abstract class AbstractElementHandler implements ElementHandler { * */ - public void backupRecord(Properties ctx, int AD_Package_Imp_Detail_ID, String tableName,PO from){ + public void backupRecord(PIPOContext ctx, int AD_Package_Imp_Detail_ID, String tableName,PO from){ // Create new record int tableID = findIdByColumn(ctx, "AD_Table", "TableName", tableName); - POInfo poInfo = POInfo.getPOInfo(ctx, tableID, getTrxName(ctx)); + POInfo poInfo = POInfo.getPOInfo(ctx.ctx, tableID); - PreparedStatement pstmtReferenceId = DB.prepareStatement("SELECT AD_Reference_ID FROM AD_COLUMN WHERE AD_Column_ID = ?", getTrxName(ctx)); + PreparedStatement pstmtReferenceId = DB.prepareStatement("SELECT AD_Reference_ID FROM AD_COLUMN WHERE AD_Column_ID = ?", ctx.trx.getTrxName()); ResultSet rs=null; try{ for (int i = 0; i < poInfo.getColumnCount(); i++){ - int columnID =findIdByColumnAndParentId (ctx, "AD_Column", "ColumnName", poInfo.getColumnName(i), "AD_Table", tableID); - - int referenceID=0; - - pstmtReferenceId.setInt(1,columnID); - rs = pstmtReferenceId.executeQuery(); - - if (rs.next()) - referenceID = rs.getInt(1); - - X_AD_Package_Imp_Backup backup = new X_AD_Package_Imp_Backup(ctx, 0, getTrxName(ctx)); - backup.setAD_Org_ID(Env.getAD_Org_ID(ctx)); - backup.setAD_Package_Imp_ID(getPackageImpId(ctx)); - backup.setAD_Package_Imp_Detail_ID(AD_Package_Imp_Detail_ID); - backup.setAD_Table_ID(tableID); - - backup.setAD_Column_ID(columnID); - backup.setAD_Reference_ID(referenceID); - Object value = from.get_ValueOld(i); - backup.setColValue(value != null ? value.toString() : null); - - backup.saveEx(getTrxName(ctx)); + if (from.is_ValueChanged(i)) { + int columnID =findIdByColumnAndParentId (ctx, "AD_Column", "ColumnName", poInfo.getColumnName(i), "AD_Table", tableID); + + int referenceID=0; + + pstmtReferenceId.setInt(1,columnID); + rs = pstmtReferenceId.executeQuery(); + + if (rs.next()) + referenceID = rs.getInt(1); + + X_AD_Package_Imp_Backup backup = new X_AD_Package_Imp_Backup(ctx.ctx, 0, ctx.trx.getTrxName()); + backup.setAD_Org_ID(Env.getAD_Org_ID(ctx.ctx)); + backup.setAD_Package_Imp_ID(getPackageImpId(ctx.ctx)); + backup.setAD_Package_Imp_Detail_ID(AD_Package_Imp_Detail_ID); + backup.setAD_Table_ID(tableID); + + backup.setAD_Column_ID(columnID); + backup.setAD_Reference_ID(referenceID); + Object value = from.get_ValueOld(i); + backup.setColValue(value != null ? value.toString() : null); + + backup.saveEx(); + } } } catch(Exception e) @@ -306,7 +307,7 @@ public abstract class AbstractElementHandler implements ElementHandler { } source.close(); target.close(); - //System.out.println("Successfully copied " + byteCount + " bytes."); + log.finer("Successfully copied " + byteCount + " bytes."); } catch (Exception e) { log.log(Level.SEVERE, e.getLocalizedMessage(), e); @@ -347,21 +348,8 @@ public abstract class AbstractElementHandler implements ElementHandler { * @param ctx * @return transaction name */ - protected String getTrxName(Properties ctx) { - String trxName = Env.getContext(ctx, "TrxName"); - if (trxName != null && trxName.trim().length() > 0) - return trxName; - else - return null; - } - - /** - * Get share document - * @param ctx - * @return TransformerHandler - */ - protected TransformerHandler getLogDocument(Properties ctx) { - return (TransformerHandler)ctx.get("LogDocument"); + protected String getTrxName(PIPOContext ctx) { + return ctx.trx != null ? ctx.trx.getTrxName() : null; } /** @@ -472,24 +460,6 @@ public abstract class AbstractElementHandler implements ElementHandler { return excludes; } - /** - * - * @param ctx - * @return PackIn instance - */ - protected PackIn getPackIn(Properties ctx) { - return (PackIn)ctx.get(PackInHandler.PACK_IN_PROCESS_CTX_KEY); - } - - /** - * - * @param ctx - * @return PackOut instance - */ - protected PackOut getPackOut(Properties ctx) { - return (PackOut) ctx.get(PackOut.PACK_OUT_PROCESS_CTX_KEY); - } - /** * * @param element @@ -582,7 +552,7 @@ public abstract class AbstractElementHandler implements ElementHandler { * @param element * @return T */ - protected T findPO(Properties ctx, Element element) { + protected T findPO(PIPOContext ctx, Element element) { T po = null; String tableName = element.getElementValue(); String uuidColumn = PO.getUUIDColumnName(tableName); @@ -590,13 +560,15 @@ public abstract class AbstractElementHandler implements ElementHandler { 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)); + Query query = new Query(ctx.ctx, tableName, uuidColumn+"=?", ctx.trx.getTrxName()); po = query.setParameters(uuid.trim()).firstOnly(); } - } else if (element.properties.containsKey(idColumn)) { + } + + if (po == null && 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)); + Query query = new Query(ctx.ctx, tableName, idColumn+"=?", ctx.trx.getTrxName()); po = query.setParameters(id.trim()).firstOnly(); } } diff --git a/org.adempiere.pipo/src/org/adempiere/pipo2/ElementHandler.java b/org.adempiere.pipo/src/org/adempiere/pipo2/ElementHandler.java index 8994416ddf..fe9bab225a 100644 --- a/org.adempiere.pipo/src/org/adempiere/pipo2/ElementHandler.java +++ b/org.adempiere.pipo/src/org/adempiere/pipo2/ElementHandler.java @@ -16,8 +16,6 @@ *****************************************************************************/ package org.adempiere.pipo2; -import java.util.Properties; - import javax.xml.transform.sax.TransformerHandler; import org.xml.sax.SAXException; @@ -35,7 +33,7 @@ public interface ElementHandler { * @param element * @throws org.xml.sax.SAXException */ - public void startElement (Properties ctx, Element element) + public void startElement (PIPOContext ctx, Element element) throws org.xml.sax.SAXException; /** @@ -44,8 +42,8 @@ public interface ElementHandler { * @param element * @throws SAXException */ - public void endElement (Properties ctx, Element element) throws SAXException; - + public void endElement (PIPOContext ctx, Element element) throws SAXException; + /** * @param packout * @param packoutHandler diff --git a/org.adempiere.pipo/src/org/adempiere/pipo2/IDFinder.java b/org.adempiere.pipo/src/org/adempiere/pipo2/IDFinder.java index 55864da438..e65dfa11bf 100644 --- a/org.adempiere.pipo/src/org/adempiere/pipo2/IDFinder.java +++ b/org.adempiere.pipo/src/org/adempiere/pipo2/IDFinder.java @@ -16,14 +16,24 @@ *****************************************************************************/ package org.adempiere.pipo2; +import java.io.UnsupportedEncodingException; +import java.math.BigDecimal; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.sql.Timestamp; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.adempiere.pipo2.exception.DatabaseAccessException; +import org.apache.commons.codec.DecoderException; +import org.apache.commons.codec.binary.Hex; +import org.compiere.model.MColumn; +import org.compiere.model.MTable; import org.compiere.util.CLogger; import org.compiere.util.DB; +import org.compiere.util.DisplayType; import org.compiere.util.Env; /** @@ -46,7 +56,7 @@ public class IDFinder { * @param AD_Client_ID * @param trxName */ - public static int findIdByColumn (String tableName, String columnName, Object value, int AD_Client_ID, String trxName) { + public static int findIdByColumn (String tableName, String columnName, Object value, int AD_Client_ID, boolean ignorecase, String trxName) { int id = 0; if (value == null) @@ -70,24 +80,81 @@ public class IDFinder { .append("_ID FROM ") .append(tableName) .append(" WHERE ") - .append(columnName) - .append(" = ?") - .append(" AND AD_Client_ID IN (0, ?)") - .append(" Order By AD_Client_ID Desc, ") + .append(" AD_Client_ID IN (0, ?) AND "); + + Object[] params = null; + String[] columns = null; + if (columnName.indexOf(",") > 0 && value instanceof String) { + columns = columnName.split("[,]"); + String[] values = ((String)value).split("[,]"); + List paramList = new ArrayList(); + for (int i = 0; i < columns.length; i++) { + if (i > 0) + sqlB.append(" AND "); + if (ignorecase) { + sqlB.append("UPPER(").append(columns[i]).append(")=? "); + } else { + sqlB.append(columns[i]).append("=? "); + } + try { + byte[] bytes = Hex.decodeHex(values[i].toCharArray()); + String s = new String(bytes, "UTF-8"); + if (ignorecase) { + paramList.add(s.toUpperCase()); + } else { + paramList.add(s); + } + } catch (DecoderException e) { + throw new RuntimeException(e); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + } + params = paramList.toArray(); + } else { + if (ignorecase && value != null && value instanceof String) { + sqlB.append("UPPER(").append(columnName).append(") =? "); + params = new Object[]{ ((String)value).toUpperCase()}; + } else { + sqlB.append(columnName).append(" =? "); + params = new Object[]{value}; + } + columns = new String[]{columnName}; + } + + sqlB.append(" Order By AD_Client_ID Desc, ") .append(tableName) .append("_ID"); + MTable table = MTable.get(Env.getCtx(), tableName); PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = DB.prepareStatement(sqlB.toString(), trxName); - if (value instanceof String) - pstmt.setString(1, (String)value); - else if (value instanceof Integer) - pstmt.setInt(1, ((Integer)value).intValue()); - else - pstmt.setObject(1, value); - pstmt.setInt(2, AD_Client_ID); + pstmt.setInt(1, AD_Client_ID); + for (int i = 0; i < params.length; i++) { + Object param = params[i]; + if (param instanceof String) { + String s = (String)param; + MColumn column = table.getColumn(columns[i]); + if (column.getAD_Reference_ID() == DisplayType.Amount + || column.getAD_Reference_ID() == DisplayType.Number + || column.getAD_Reference_ID() == DisplayType.CostPrice + || column.getAD_Reference_ID() == DisplayType.Quantity) + pstmt.setBigDecimal(i+2, new BigDecimal(s)); + else if (column.getAD_Reference_ID() == DisplayType.Date + || column.getAD_Reference_ID() == DisplayType.DateTime) + pstmt.setTimestamp(i+2, Timestamp.valueOf(s)); + else if (column.getAD_Reference_ID() == DisplayType.Integer) + pstmt.setInt(i+2, Integer.parseInt(s)); + else + pstmt.setString(i+2, s); + } else if (param instanceof Integer) { + pstmt.setInt(i+2, ((Integer)param).intValue()); + } else { + pstmt.setObject(i+2, param); + } + } rs = pstmt.executeQuery(); if (rs.next()) @@ -106,6 +173,10 @@ public class IDFinder { return id; } + public static int findIdByColumn(String tableName, String columnName, Object value, int clientId, String trxName) { + return findIdByColumn(tableName, columnName, value, clientId, false, trxName); + } + /** * Get ID from Name for a table with a parent name reference. * @@ -115,7 +186,7 @@ public class IDFinder { * @param nameMaster * @param trxName */ - public static int findIdByNameAndParentName (String tableName, String name, String tableNameMaster, String nameMaster, String trxName) { + public static int findIdByNameAndParentName (String tableName, String name, String tableNameMaster, String nameMaster, int AD_Client_ID, String trxName) { int id = 0; //construct cache key StringBuffer key = new StringBuffer(); @@ -179,10 +250,24 @@ public class IDFinder { * @param name * @param tableNameMaster * @param masterID + * @param trx + */ + + public static int findIdByColumnAndParentId (String tableName, String columnName, String name, String tableNameMaster, int masterID, int AD_Client_ID, String trxName) { + return findIdByColumnAndParentId(tableName, columnName, name, tableNameMaster, masterID, AD_Client_ID, false, trxName); + } + + /** + * Get ID from column value for a table with a parent id reference. + * + * @param tableName + * @param name + * @param tableNameMaster + * @param masterID * @param trxName */ - public static int findIdByColumnAndParentId (String tableName, String columnName, String name, String tableNameMaster, int masterID, String trxName) { + public static int findIdByColumnAndParentId (String tableName, String columnName, String name, String tableNameMaster, int masterID, int AD_Client_ID, boolean ignoreCase, String trxName) { int id = 0; //check cache @@ -195,10 +280,16 @@ public class IDFinder { .append(tableName) .append("_ID FROM ") .append(tableName) - .append(" WHERE ") - .append(columnName) - .append(" = ? and ") - .append(tableNameMaster+"_ID = ? AND AD_Client_ID IN (0, ?) ") + .append(" WHERE "); + if (ignoreCase) { + sqlB.append("Upper(") + .append(columnName) + .append(") = ? and "); + } else { + sqlB.append(columnName) + .append(" = ? and "); + } + sqlB.append(tableNameMaster+"_ID = ? AND AD_Client_ID IN (0, ?) ") .append("ORDER BY AD_Client_ID Desc "); log.info(sqlB.toString()); @@ -208,9 +299,13 @@ public class IDFinder { try { pstmt = DB.prepareStatement(sqlB.toString(), trxName); - pstmt.setString(1, name); + if (ignoreCase) { + pstmt.setString(1, name.toUpperCase()); + } else { + pstmt.setString(1, name); + } pstmt.setInt(2, masterID); - pstmt.setInt(3, Env.getAD_Client_ID(Env.getCtx())); + pstmt.setInt(3, AD_Client_ID); rs = pstmt.executeQuery(); if (rs.next()) { @@ -239,7 +334,7 @@ public class IDFinder { * @param masterID * @param trxName */ - public static int findIdByNameAndParentId (String tableName, String name, String tableNameMaster, int masterID, String trxName) { + public static int findIdByNameAndParentId (String tableName, String name, String tableNameMaster, int masterID, int AD_Client_ID, String trxName) { int id = 0; //construct cache key @@ -273,7 +368,7 @@ public class IDFinder { pstmt = DB.prepareStatement(sqlB.toString(), trxName); pstmt.setString(1, name); pstmt.setInt(2, masterID); - pstmt.setInt(3, Env.getAD_Client_ID(Env.getCtx())); + pstmt.setInt(3, AD_Client_ID); rs = pstmt.executeQuery(); if (rs.next()) id = rs.getInt(1); diff --git a/org.adempiere.pipo/src/org/adempiere/pipo2/PIPOContext.java b/org.adempiere.pipo/src/org/adempiere/pipo2/PIPOContext.java new file mode 100644 index 0000000000..63a6dc9869 --- /dev/null +++ b/org.adempiere.pipo/src/org/adempiere/pipo2/PIPOContext.java @@ -0,0 +1,15 @@ +package org.adempiere.pipo2; + +import java.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.compiere.util.Trx; + +public class PIPOContext { + public Properties ctx; + public Trx trx; + public PackIn packIn; + public PackOut packOut; + public TransformerHandler logDocument; +} diff --git a/org.adempiere.pipo/src/org/adempiere/pipo2/PackIn.java b/org.adempiere.pipo/src/org/adempiere/pipo2/PackIn.java index 1357bb11ca..5752a50a26 100644 --- a/org.adempiere.pipo/src/org/adempiere/pipo2/PackIn.java +++ b/org.adempiere.pipo/src/org/adempiere/pipo2/PackIn.java @@ -23,7 +23,9 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Properties; import java.util.logging.Level; @@ -31,7 +33,10 @@ import java.util.logging.Level; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; +import org.compiere.model.PO; +import org.compiere.model.X_AD_Package_Imp_Detail; import org.compiere.util.CLogger; +import org.compiere.util.Trx; /** * IntPackIn Tool. @@ -50,6 +55,8 @@ public class PackIn { private Map columnCache = new HashMap(); private String packageName = null; private String packageVersion = null; + + private List importDetails; public PackIn() { super(); @@ -123,6 +130,10 @@ public class PackIn { } } + public void addImportDetail(X_AD_Package_Imp_Detail importDetail) { + importDetails.add(importDetail); + } + /** * * @param input @@ -135,20 +146,29 @@ public class PackIn { log.info("starting"); // clear cache of previous runs IDFinder.clearIDCache(); + importDetails = new ArrayList(); System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl"); PackInHandler handler = new PackInHandler(); - handler.set_TrxName(trxName); - handler.setCtx(ctx); + PIPOContext context = new PIPOContext(); + context.trx = Trx.get(trxName, true); + context.packIn = this; + context.ctx = ctx; + handler.setCtx(context); handler.setProcess(this); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); String msg = "Start Parser"; log.info(msg); parser.parse(input, handler); + for (PO importDetail : importDetails) { + importDetail.saveEx(); + } msg = "End Parser"; log.info(msg); + if (handler.getUnresolvedCount() > 0) + handler.dumpUnresolvedElements(); return "Processed="+handler.getElementsProcessed()+" Un-Resolved="+handler.getUnresolvedCount(); } catch (Exception e) { log.log(Level.SEVERE, "importXML:", e); @@ -188,6 +208,7 @@ public class PackIn { else baos.write(b); } + data = baos.toByteArray(); } finally { if (fis != null) { try { diff --git a/org.adempiere.pipo/src/org/adempiere/pipo2/PackInHandler.java b/org.adempiere.pipo/src/org/adempiere/pipo2/PackInHandler.java index f8697303dd..d9a69298e6 100644 --- a/org.adempiere.pipo/src/org/adempiere/pipo2/PackInHandler.java +++ b/org.adempiere.pipo/src/org/adempiere/pipo2/PackInHandler.java @@ -19,27 +19,14 @@ package org.adempiere.pipo2; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.OutputStream; import java.sql.PreparedStatement; import java.sql.ResultSet; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Date; import java.util.List; -import java.util.Properties; +import java.util.Set; import java.util.Stack; import java.util.logging.Level; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.sax.SAXTransformerFactory; -import javax.xml.transform.sax.TransformerHandler; -import javax.xml.transform.stream.StreamResult; - import org.adempiere.pipo2.exception.DatabaseAccessException; import org.compiere.model.X_AD_Package_Imp; import org.compiere.model.X_AD_Package_Imp_Inst; @@ -77,17 +64,9 @@ public class PackInHandler extends DefaultHandler { private int AD_Package_Imp_ID=0; private int AD_Package_Imp_Inst_ID=0; private CLogger log = CLogger.getCLogger(PackInHandler.class); - private OutputStream logOutputStream = null; - private TransformerHandler logDocument = null; - private StreamResult loStreamResult = null; - private SAXTransformerFactory transformerFactory = null; - private Transformer logTransformer = null; private boolean isInit = false; - private String logDate = null; private String packageStatus = "Installing"; - // transaction name - private String m_trxName = null; - private Properties m_ctx = null; + private PIPOContext m_ctx = null; private IHandlerRegistry handlerRegistry = null; private List defer = new ArrayList(); @@ -99,41 +78,11 @@ public class PackInHandler extends DefaultHandler { packageDirectory = packIn.getPackageDirectory(); m_updateDictionary = packIn.isUpdateDictionary(); - SimpleDateFormat formatter_file = new SimpleDateFormat("yyMMddHHmmssZ"); - SimpleDateFormat formatter_log = new SimpleDateFormat("MM/dd/yy HH:mm:ss"); - Date today = new Date(); - String fileDate = formatter_file.format(today); - logDate = formatter_log.format(today); - String logFileName = packageDirectory+File.separator+"doc"+File.separator+"Importlog_"+fileDate+".xml"; - log.info("packin log file="+logFileName); - try { - logOutputStream = new FileOutputStream (logFileName, false); - } catch (FileNotFoundException e1) { - log.warning ("Failed to create log file. error="+e1+" file="+logFileName); - } - loStreamResult = new StreamResult(logOutputStream); - transformerFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); - - try { - logDocument = transformerFactory.newTransformerHandler(); - } catch (TransformerConfigurationException e2) { - log.info ("startElement:"+e2); - } - logTransformer = logDocument.getTransformer(); - logTransformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1"); - logTransformer.setOutputProperty(OutputKeys.INDENT,"yes"); - logDocument.setResult(loStreamResult); - logDocument.startDocument(); - logDocument.processingInstruction("xml-stylesheet","type=\"text/css\" href=\"adempiereDocument.css\""); - Properties tmp = new Properties(); - if (m_ctx != null) - tmp.putAll(m_ctx); - else - tmp.putAll(Env.getCtx()); - m_ctx = tmp; - if (m_trxName == null) - m_trxName = Trx.createTrxName("PackIn"); + if (m_ctx == null) + m_ctx = new PIPOContext(); + if (m_ctx.trx == null) + m_ctx.trx = Trx.get("PackIn", true); isInit=true; } @@ -164,10 +113,17 @@ public class PackInHandler extends DefaultHandler { { log.info("adempiereAD updateMode="+m_updateDictionary); - createLogHeader(atts); + //check client + String clientAttribute = atts.getValue("Client"); + String[] clientComponent = clientAttribute.split("[-]"); + int clientId = Integer.parseInt(clientComponent[0]); + if (clientId == 0 && Env.getAD_Client_ID(m_ctx.ctx) > 0) { + throw new RuntimeException("Package is created for System, not Tenant"); + } else if (clientId > 0 && Env.getAD_Client_ID(m_ctx.ctx) == 0) { + throw new RuntimeException("Package is created for Tenant, not System"); + } // Update Summary Package History Table - int PK_preInstalled=0; String packageName = packIn.getPackageName(); @@ -199,8 +155,8 @@ public class PackInHandler extends DefaultHandler { DB.close(rs, pstmt); } - X_AD_Package_Imp packageImp = new X_AD_Package_Imp(m_ctx, 0, null); - packageImp.setAD_Org_ID(Env.getAD_Org_ID(m_ctx)); + X_AD_Package_Imp packageImp = new X_AD_Package_Imp(m_ctx.ctx, 0, null); + packageImp.setAD_Org_ID(Env.getAD_Org_ID(m_ctx.ctx)); packageImp.setReleaseNo(atts.getValue("CompVer")); packageImp.setPK_Version(packageVersion); packageImp.setVersion(atts.getValue("DataBase")); @@ -216,8 +172,8 @@ public class PackInHandler extends DefaultHandler { if ( PK_preInstalled <= 0){ //Insert Package into package install log - X_AD_Package_Imp_Inst packageInst = new X_AD_Package_Imp_Inst(m_ctx, 0, null); - packageInst.setAD_Org_ID(Env.getAD_Org_ID(m_ctx)); + X_AD_Package_Imp_Inst packageInst = new X_AD_Package_Imp_Inst(m_ctx.ctx, 0, null); + packageInst.setAD_Org_ID(Env.getAD_Org_ID(m_ctx.ctx)); packageInst.setReleaseNo(atts.getValue("CompVer")); packageInst.setPK_Version(atts.getValue("Version")); packageInst.setVersion(atts.getValue("DataBase")); @@ -232,17 +188,15 @@ public class PackInHandler extends DefaultHandler { //Update package list with package status AD_Package_Imp_Inst_ID = PK_preInstalled; - X_AD_Package_Imp_Inst packageInst = new X_AD_Package_Imp_Inst(m_ctx, AD_Package_Imp_Inst_ID, null); + X_AD_Package_Imp_Inst packageInst = new X_AD_Package_Imp_Inst(m_ctx.ctx, AD_Package_Imp_Inst_ID, null); packageInst.setPK_Status(packageStatus); packageInst.saveEx(); } - Env.setContext(m_ctx, "AD_Package_Imp_ID", AD_Package_Imp_ID); - Env.setContext(m_ctx, "UpdateMode", m_updateDictionary); - Env.setContext(m_ctx, "TrxName", m_trxName); - Env.setContext(m_ctx, "PackageDirectory", packageDirectory); - m_ctx.put("LogDocument", logDocument); - m_ctx.put(PACK_IN_PROCESS_CTX_KEY, packIn); + m_ctx.ctx.put("AD_Package_Imp_ID", AD_Package_Imp_ID); + m_ctx.ctx.put("UpdateMode", m_updateDictionary); + m_ctx.ctx.put("PackageDirectory", packageDirectory); + m_ctx.packIn = packIn; } else { Element e = new Element(uri, localName, qName, new AttributesImpl(atts)); if (stack.size() > 0) @@ -292,22 +246,6 @@ public class PackInHandler extends DefaultHandler { } } - private void createLogHeader(Attributes atts) throws SAXException { - AttributesImpl attsOut = new AttributesImpl(); - logDocument.startElement("","","adempiereDocument",attsOut); - PackOut.addTextElement(logDocument, "header", atts.getValue("Name")+" Install Log", attsOut); - PackOut.addTextElement(logDocument, "H3", "Package Name:", attsOut); - PackOut.addTextElement(logDocument, "packagename4log", atts.getValue("Name"), attsOut); - PackOut.addTextElement(logDocument, "H3", "Version:", attsOut); - PackOut.addTextElement(logDocument, "Version", atts.getValue("Version"), attsOut); - PackOut.addTextElement(logDocument, "H3", "Package Install Date:", attsOut); - PackOut.addTextElement(logDocument, "installDate", logDate, attsOut); - PackOut.addTextElement(logDocument, "H3", "Min. Version:", attsOut); - PackOut.addTextElement(logDocument, "AdempiereVersion", atts.getValue("AdempiereVersion"), attsOut); - PackOut.addTextElement(logDocument, "H3", "Min. Database Date:", attsOut); - PackOut.addTextElement(logDocument, "Database", atts.getValue("Database"), attsOut); - } - /** * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int) */ @@ -343,30 +281,38 @@ public class PackInHandler extends DefaultHandler { packageStatus = "Completed successfully"; //Update package history log with package status - X_AD_Package_Imp packageImp = new X_AD_Package_Imp(m_ctx, AD_Package_Imp_ID, null); + X_AD_Package_Imp packageImp = new X_AD_Package_Imp(m_ctx.ctx, AD_Package_Imp_ID, null); packageImp.setPK_Status(packageStatus); packageImp.saveEx(); //Update package list with package status - X_AD_Package_Imp_Inst packageInst = new X_AD_Package_Imp_Inst(m_ctx, AD_Package_Imp_Inst_ID, null); + X_AD_Package_Imp_Inst packageInst = new X_AD_Package_Imp_Inst(m_ctx.ctx, AD_Package_Imp_Inst_ID, null); packageInst.setPK_Status(packageStatus); packageInst.saveEx(); - logDocument.endElement("","","adempiereDocument"); - logDocument.endDocument(); - try { - logOutputStream.close(); - } - catch (Exception e) - {} - //reset setupHandlers(); } else { Element e = stack.pop(); if (stack.isEmpty()) { - processElement(e); + try { + processElement(e); + } catch (RuntimeException re) { + packageStatus = "Import Failed"; + //Update package history log with package status + X_AD_Package_Imp packageImp = new X_AD_Package_Imp(m_ctx.ctx, AD_Package_Imp_ID, null); + packageImp.setPK_Status(packageStatus); + packageImp.save(); + throw re; + } catch (SAXException se) { + packageStatus = "Import Failed"; + //Update package history log with package status + X_AD_Package_Imp packageImp = new X_AD_Package_Imp(m_ctx.ctx, AD_Package_Imp_ID, null); + packageImp.setPK_Status(packageStatus); + packageImp.save(); + throw se; + } } } } // endElement @@ -391,7 +337,7 @@ public class PackInHandler extends DefaultHandler { } } if (log.isLoggable(Level.INFO)) { - log.info("Processeing Element: " + d.element.getElementValue() + " - " + log.info("Processing Element: " + d.element.getElementValue() + " - " + d.element.attributes.getValue(0)); } ElementHandler handler = handlerRegistry.getHandler(d.element); @@ -419,13 +365,7 @@ public class PackInHandler extends DefaultHandler { } while (defer.size() > 0); } - // globalqss - add support for trx in 3.1.2 - public void set_TrxName(String trxName) { - m_trxName = trxName; - } - - // globalqss - add support for trx in 3.1.2 - public void setCtx(Properties ctx) { + public void setCtx(PIPOContext ctx) { m_ctx = ctx; } @@ -456,6 +396,35 @@ public class PackInHandler extends DefaultHandler { } return count; } + + public void dumpUnresolvedElements() { + if (defer != null && !defer.isEmpty()) { + for(DeferEntry entry : defer) { + if (!entry.startElement) + { + Element e = entry.element; + StringBuffer s = new StringBuffer(e.qName); + s.append(" ["); + Set keys = e.properties.keySet(); + int i = 0; + for(String key : keys) + { + Element value = e.properties.get(key); + if (i > 0) + s.append(", "); + s.append(key).append("="); + if (value.contents != null) + s.append(value.contents); + i++; + } + s.append("]"); + if (e.unresolved != null && e.unresolved.length() > 0) + s.append(" unresolved ").append(e.unresolved); + log.warning(s.toString()); + } + } + } + } class DeferEntry { Element element; diff --git a/org.adempiere.pipo/src/org/adempiere/pipo2/PackInProcess.java b/org.adempiere.pipo/src/org/adempiere/pipo2/PackInProcess.java index fe5a34429c..f3e56159fa 100644 --- a/org.adempiere.pipo/src/org/adempiere/pipo2/PackInProcess.java +++ b/org.adempiere.pipo/src/org/adempiere/pipo2/PackInProcess.java @@ -18,8 +18,11 @@ package org.adempiere.pipo2; import java.io.File; +import java.sql.Timestamp; import org.compiere.Adempiere; +import org.compiere.model.MAttachment; +import org.compiere.model.MAttachmentEntry; import org.compiere.model.X_AD_Package_Imp_Proc; import org.compiere.process.ProcessInfoParameter; import org.compiere.process.SvrProcess; @@ -70,7 +73,7 @@ public class PackInProcess extends SvrProcess { protected String doIt() throws Exception { X_AD_Package_Imp_Proc adPackageImp = new X_AD_Package_Imp_Proc(getCtx(), - p_PackIn_ID, null); + p_PackIn_ID, get_TrxName()); // Create Target directory if required String packageDirectory = adPackageImp.getAD_Package_Dir(); @@ -78,7 +81,7 @@ public class PackInProcess extends SvrProcess { packageDirectory = Adempiere.getAdempiereHome(); } - String targetDirName = packageDirectory + File.separator + "packages"; + String targetDirName = packageDirectory + File.separator + "packin"; File targetDir = new File(targetDirName); if (!targetDir.exists()) { @@ -88,14 +91,24 @@ public class PackInProcess extends SvrProcess { } } + MAttachment attachment = adPackageImp.getAttachment(); + if (attachment == null) { + return "Please attach the pack out archive before running the process"; + } + + MAttachmentEntry entry = attachment.getEntry(0); + if (entry == null) { + return "Please attach the pack out archive before running the process"; + } + // Unzip package - File zipFilepath = new File(adPackageImp.getAD_Package_Source()); + File zipFilepath = entry.getFile(); log.info("zipFilepath->" + zipFilepath); String parentDir = Zipper.getParentDir(zipFilepath); Zipper.unpackFile(zipFilepath, targetDir); String dict_file = packageDirectory + File.separator - + "packages" + File.separator + parentDir + File.separator + + "packin" + File.separator + parentDir + File.separator + "dict" + File.separator + "PackOut.xml"; log.info("dict file->" + dict_file); @@ -106,16 +119,24 @@ public class PackInProcess extends SvrProcess { m_UpdateDictionary = false; m_packageDirectory = packageDirectory + File.separator - + "packages" + File.separator + parentDir + File.separator; + + "packin" + File.separator + parentDir + File.separator; PackIn packIn = new PackIn(); packIn.setPackageDirectory(m_packageDirectory); packIn.setPackageName(packageName); packIn.setPackageVersion(packageVersion); packIn.setUpdateDictionary(m_UpdateDictionary); + // call XML Handler String msg = packIn.importXML(dict_file, getCtx(), get_TrxName()); - + if (adPackageImp.get_ColumnIndex("DateProcessed") > 0) { + adPackageImp.set_ValueOfColumn("DateProcessed", new Timestamp(System.currentTimeMillis())); + } + if (adPackageImp.get_ColumnIndex("P_Msg") > 0) { + adPackageImp.set_ValueOfColumn("P_Msg", msg); + } + adPackageImp.saveEx(); + return msg; } // doIt } // PackInProcess diff --git a/org.adempiere.pipo/src/org/adempiere/pipo2/PackOut.java b/org.adempiere.pipo/src/org/adempiere/pipo2/PackOut.java index 44d83c71f7..a1f7b35f6c 100644 --- a/org.adempiere.pipo/src/org/adempiere/pipo2/PackOut.java +++ b/org.adempiere.pipo/src/org/adempiere/pipo2/PackOut.java @@ -27,6 +27,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; +import java.sql.Timestamp; import java.util.List; import java.util.Properties; import java.util.logging.Level; @@ -41,7 +42,7 @@ import javax.xml.transform.stream.StreamResult; import org.compiere.model.MClient; import org.compiere.model.MTable; import org.compiere.util.CLogger; -import org.compiere.util.Env; +import org.compiere.util.Trx; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; @@ -66,10 +67,6 @@ public class PackOut public final static String PackOutVersion = "100"; private final static CLogger log = CLogger.getCLogger(PackOut.class); - private static final String TRX_NAME_CTX_KEY = "TrxName"; - public static final String PACK_OUT_PROCESS_CTX_KEY = "PackOutProcess"; - - private Properties localContext = null; private String packageDirectory; private int blobCount = 0; @@ -80,6 +77,8 @@ public class PackOut private int processedCount; private String exportFile; private String packoutDirectory; + private PIPOContext pipoContext; + private Timestamp fromDate; public static final int MAX_OFFICIAL_ID = MTable.MAX_OFFICIAL_ID; @@ -192,26 +191,33 @@ public class PackOut OutputStream packoutStream) throws UnsupportedEncodingException, TransformerConfigurationException, SAXException { StreamResult packoutStreamResult = new StreamResult(new OutputStreamWriter(packoutStream,"UTF-8")); SAXTransformerFactory packoutFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); - packoutFactory.setAttribute("indent-number", new Integer(4)); + //indent-number attribute support is not guarantee + try { + packoutFactory.setAttribute("indent-number", new Integer(4)); + } catch (Exception e) {} TransformerHandler packoutHandler = packoutFactory.newTransformerHandler(); Transformer packoutTransformer = packoutHandler.getTransformer(); packoutTransformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); packoutTransformer.setOutputProperty(OutputKeys.INDENT,"yes"); + //indent-amount property support is not guarantee + try { + packoutTransformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount","4"); + } catch (Exception e) {} packoutHandler.setResult(packoutStreamResult); packoutHandler.startDocument(); AttributesImpl atts = new AttributesImpl(); atts.addAttribute("","","Name","CDATA",packoutDocument.getPackageName()); atts.addAttribute("","","Version","CDATA",packoutDocument.getPackageVersion()); - atts.addAttribute("","","AdempiereVersion","CDATA",packoutDocument.getAdempiereVersion()); - atts.addAttribute("","","DataBaseVersion","CDATA",packoutDocument.getDatabaseVersion()); + atts.addAttribute("","","AdempiereVersion","CDATA",emptyIfNull(packoutDocument.getAdempiereVersion())); + atts.addAttribute("","","DataBaseVersion","CDATA",emptyIfNull(packoutDocument.getDatabaseVersion())); atts.addAttribute("","","Description","CDATA",emptyIfNull(packoutDocument.getDescription())); - atts.addAttribute("","","Author","CDATA",packoutDocument.getAuthor()); + atts.addAttribute("","","Author","CDATA",emptyIfNull(packoutDocument.getAuthor())); atts.addAttribute("","","AuthorEmail","CDATA",emptyIfNull(packoutDocument.getAuthorEmail())); atts.addAttribute("","","CreatedDate","CDATA",packoutDocument.getCreated().toString()); atts.addAttribute("","","UpdatedDate","CDATA",packoutDocument.getUpdated().toString()); atts.addAttribute("","","PackOutVersion","CDATA",PackOutVersion); - MClient client = MClient.get(localContext); + MClient client = MClient.get(pipoContext.ctx); StringBuffer sb = new StringBuffer () .append(client.get_ID()) .append("-") @@ -231,11 +237,18 @@ public class PackOut private TransformerHandler createDocHandler(OutputStream docStream) throws UnsupportedEncodingException, TransformerConfigurationException, SAXException { StreamResult docStreamResult = new StreamResult(new OutputStreamWriter(docStream,"UTF-8")); SAXTransformerFactory transformerFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); - transformerFactory.setAttribute("indent-number", new Integer(4)); + //indent-number attribute support is not guarantee + try { + transformerFactory.setAttribute("indent-number", new Integer(4)); + } catch (Exception e) {} TransformerHandler docHandler = transformerFactory.newTransformerHandler(); Transformer transformer = docHandler.getTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING,"UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); + //indent-amount property support is not guarantee + try { + transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount","4"); + } catch (Exception e) {} docHandler.setResult(docStreamResult); docHandler.startDocument(); docHandler.processingInstruction("xml-stylesheet","type=\"text/css\" href=\"adempiereDocument.css\""); @@ -261,7 +274,7 @@ public class PackOut addTextElement(docHandler, "filedirectory", "Directory: \\dict\\", atts); addTextElement(docHandler, "filenotes", "Notes: Contains all application/object settings for package", atts); - MClient client = MClient.get(localContext); + MClient client = MClient.get(pipoContext.ctx); StringBuffer sb = new StringBuffer () .append(client.get_ID()) .append("-") @@ -281,13 +294,7 @@ public class PackOut } private void initContext() { - Properties tmp = new Properties(); - if (getCtx() != null) - tmp.putAll(getCtx()); - if (trxName != null) - tmp.put(TRX_NAME_CTX_KEY, trxName); - tmp.put(PACK_OUT_PROCESS_CTX_KEY, this); - localContext = tmp; + pipoContext.trx = Trx.get(trxName, true); } /** @@ -352,8 +359,8 @@ public class PackOut } } - public Properties getCtx() { - return localContext != null ? localContext : Env.getCtx(); + public PIPOContext getCtx() { + return pipoContext; } /** @@ -422,4 +429,25 @@ public class PackOut public String getExportFile() { return exportFile; } + + /** + * @param fromDate + */ + public void setFromDate(Timestamp fromDate) { + this.fromDate = fromDate; + } + + /** + * @return from date + */ + public Timestamp getFromDate() { + return fromDate; + } + + /** + * @param ctx + */ + public void setCtx(Properties ctx) { + pipoContext.ctx = ctx; + } } // PackOut diff --git a/org.adempiere.pipo/src/org/adempiere/pipo2/PackOutProcess.java b/org.adempiere.pipo/src/org/adempiere/pipo2/PackOutProcess.java index f7c5a137a9..953a34a8b3 100644 --- a/org.adempiere.pipo/src/org/adempiere/pipo2/PackOutProcess.java +++ b/org.adempiere.pipo/src/org/adempiere/pipo2/PackOutProcess.java @@ -19,12 +19,14 @@ package org.adempiere.pipo2; import java.io.File; +import java.sql.Timestamp; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Level; +import org.compiere.Adempiere; import org.compiere.model.I_AD_Form; import org.compiere.model.I_AD_ImpFormat; import org.compiere.model.I_AD_Menu; @@ -95,9 +97,27 @@ public class PackOutProcess extends SvrProcess if (packageExp.getAD_Package_Exp_ID() == p_PackOut_ID){ //Create the package documentation - packoutDirectory = packageExp.getFile_Directory().trim(); - if (!packoutDirectory.endsWith("/") && !packoutDirectory.endsWith("\\")) - packoutDirectory+= File.separator; + packoutDirectory = packageExp.getFile_Directory(); + if (packoutDirectory == null || packoutDirectory.trim().length() == 0) { + packoutDirectory = Adempiere.getAdempiereHome().trim(); + if (!packoutDirectory.endsWith("/") && !packoutDirectory.endsWith("\\")) + packoutDirectory+= File.separator; + packoutDirectory = packoutDirectory + "packout" + File.separator; + } else { + packoutDirectory = packoutDirectory.trim(); + if (!packoutDirectory.endsWith("/") && !packoutDirectory.endsWith("\\")) + packoutDirectory+= File.separator; + } + + //create packout folder if needed + File packoutDirectoryFile = new File(packoutDirectory); + if (!packoutDirectoryFile.exists()) { + boolean success = packoutDirectoryFile.mkdirs(); + if (!success) { + log.warning("Failed to create target directory. " + packoutDirectory); + } + } + PackoutDocument packoutDocument = new PackoutDocument(packageExp.getName(), packageExp.getPK_Version(), packageExp.getReleaseNo(), packageExp.getVersion(), packageExp.getDescription(), packageExp.getInstructions(), packageExp.getUserName(), packageExp.getEMail(), packageExp.getCreated(), packageExp.getUpdated()); @@ -115,6 +135,12 @@ public class PackOutProcess extends SvrProcess } PackOut packOut = new PackOut(); + packOut.setCtx(getCtx()); + Object dateFromValue = packageExp.get_Value("DateFrom"); + if (dateFromValue != null && dateFromValue instanceof Timestamp) { + packOut.setFromDate((Timestamp) dateFromValue); + } + packOut.export(packoutDirectory, null, packoutDocument, packoutItems, get_TrxName()); processedCount = packOut.getExportCount(); exportFile = packOut.getExportFile(); diff --git a/org.adempiere.pipo/src/org/adempiere/pipo2/PoExporter.java b/org.adempiere.pipo/src/org/adempiere/pipo2/PoExporter.java index 0e7e0ef0bb..7c116a39b8 100644 --- a/org.adempiere.pipo/src/org/adempiere/pipo2/PoExporter.java +++ b/org.adempiere.pipo/src/org/adempiere/pipo2/PoExporter.java @@ -2,18 +2,17 @@ package org.adempiere.pipo2; import java.math.BigDecimal; import java.util.List; -import java.util.Properties; -import java.util.UUID; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.exceptions.AdempiereException; -import org.compiere.model.I_AD_Client; -import org.compiere.model.I_AD_Org; import org.compiere.model.MTable; import org.compiere.model.PO; import org.compiere.model.POInfo; +import org.compiere.model.X_AD_Client; +import org.compiere.model.X_AD_Org; import org.compiere.util.CLogger; +import org.compiere.util.DB; import org.compiere.util.DisplayType; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; @@ -24,7 +23,7 @@ public class PoExporter { @SuppressWarnings("unused") private CLogger log = CLogger.getCLogger(getClass()); - private Properties ctx; + private PIPOContext ctx; private TransformerHandler transformerHandler; @@ -48,7 +47,7 @@ public class PoExporter { * @param ctx * @param po */ - public PoExporter(Properties ctx, TransformerHandler handler, PO po){ + public PoExporter(PIPOContext ctx, TransformerHandler handler, PO po){ this.ctx = ctx; this.po = po; transformerHandler = handler; @@ -180,22 +179,27 @@ public class PoExporter { int AD_Client_ID = po.getAD_Client_ID(); if (AD_Client_ID == 0) { - addString("AD_Org_ID", "0", new AttributesImpl()); + addString("AD_Client_ID", "0", new AttributesImpl()); + if (excludes == null || !excludes.contains("AD_Org_ID")) + addString("AD_Org_ID", "0", new AttributesImpl()); } else { - int AD_Org_ID = po.getAD_Org_ID(); - if (AD_Org_ID == 0) + if (excludes == null || !excludes.contains("AD_Org_ID")) { - addString("AD_Org_ID", "0", new AttributesImpl()); - } - else - { - if (!preservedOrg) - addString("AD_Org_ID", "@AD_Org_ID@", new AttributesImpl()); - else { - addTableReference(I_AD_Client.Table_Name, I_AD_Client.COLUMNNAME_Value, new AttributesImpl()); - addTableReference(I_AD_Org.Table_Name, I_AD_Org.COLUMNNAME_Value, new AttributesImpl()); + int AD_Org_ID = po.getAD_Org_ID(); + if (AD_Org_ID == 0) + { + addString("AD_Org_ID", "0", new AttributesImpl()); + } + else + { + if (!preservedOrg) + addString("AD_Org_ID", "@AD_Org_ID@", new AttributesImpl()); + else { + addTableReference(X_AD_Client.Table_Name, "Value", new AttributesImpl()); + addTableReference(X_AD_Org.Table_Name, "Value", new AttributesImpl()); + } } } } @@ -225,8 +229,18 @@ public class PoExporter { if ("Record_ID".equalsIgnoreCase(columnName) && po.get_ColumnIndex("AD_Table_ID") >= 0) { int AD_Table_ID = po.get_Value(po.get_ColumnIndex("AD_Table_ID")) != null ? (Integer)po.get_Value(po.get_ColumnIndex("AD_Table_ID")) : 0; - tableName = MTable.getTableName(ctx, AD_Table_ID); + tableName = MTable.getTableName(ctx.ctx, AD_Table_ID); searchColumn = tableName + "_ID"; + } else if (po.get_TableName().equals("AD_TreeNode") && columnName.equals("Parent_ID")) { + int AD_Tree_ID = po.get_ValueAsInt("AD_Tree_ID"); + int AD_Table_ID = DB.getSQLValue(po.get_TrxName(), "SELECT AD_Table_ID From AD_Tree WHERE AD_Tree_ID="+AD_Tree_ID); + tableName = MTable.getTableName(po.getCtx(), AD_Table_ID); + searchColumn = tableName+"_ID"; + } else if (po.get_TableName().equals("AD_TreeNode") && columnName.equals("Node_ID")) { + int AD_Tree_ID = po.get_ValueAsInt("AD_Tree_ID"); + int AD_Table_ID = DB.getSQLValue(po.get_TrxName(), "SELECT AD_Table_ID From AD_Tree WHERE AD_Tree_ID="+AD_Tree_ID); + tableName = MTable.getTableName(po.getCtx(), AD_Table_ID); + searchColumn = tableName+"_ID"; } else { //remove _ID searchColumn = columnName; @@ -257,7 +271,7 @@ public class PoExporter { if ("Record_ID".equalsIgnoreCase(columnName) && po.get_ColumnIndex("AD_Table_ID") >= 0) { int AD_Table_ID = po.get_Value(po.get_ColumnIndex("AD_Table_ID")) != null ? (Integer)po.get_Value(po.get_ColumnIndex("AD_Table_ID")) : 0; - tableName = MTable.getTableName(ctx, AD_Table_ID); + tableName = MTable.getTableName(ctx.ctx, AD_Table_ID); searchColumn = tableName + "_ID"; } else if (info.getColumnLookup(i) != null){ searchColumn = info.getColumnLookup(i).getColumnName(); @@ -286,6 +300,8 @@ public class PoExporter { addTableReference(columnName, tableName, searchColumn, new AttributesImpl()); } else if (DisplayType.isLOB(displayType)) { addBlob(columnName); + } else if (columnName.equals(po.getUUIDColumnName()) && po.get_Value(columnName) == null) { + continue; } else { add(columnName, "", new AttributesImpl()); } @@ -299,7 +315,7 @@ public class PoExporter { return; } - PackOut packOut = (PackOut) ctx.get(PackOut.PACK_OUT_PROCESS_CTX_KEY); + PackOut packOut = ctx.packOut; byte[] data = null; String dataType = null; String fileName = null; diff --git a/org.adempiere.pipo/src/org/adempiere/pipo2/PoFiller.java b/org.adempiere.pipo/src/org/adempiere/pipo2/PoFiller.java index 30c29b10f8..7e23e4b39b 100644 --- a/org.adempiere.pipo/src/org/adempiere/pipo2/PoFiller.java +++ b/org.adempiere.pipo/src/org/adempiere/pipo2/PoFiller.java @@ -5,7 +5,6 @@ import java.math.BigDecimal; import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import org.adempiere.exceptions.AdempiereException; import org.compiere.model.PO; @@ -16,8 +15,9 @@ import org.compiere.util.Env; public class PoFiller{ PO po = null; + @SuppressWarnings("unused") private AbstractElementHandler handler; - private Properties ctx; + private PIPOContext ctx; private Element element; /** @@ -26,7 +26,7 @@ public class PoFiller{ * @param atts * @param handler */ - public PoFiller(Properties ctx, PO po, Element element, AbstractElementHandler handler){ + public PoFiller(PIPOContext ctx, PO po, Element element, AbstractElementHandler handler){ this.ctx = ctx; this.po = po; @@ -51,7 +51,7 @@ public class PoFiller{ else if (oldValue != null && oldValue.toString().equals(value)) return; else - po.set_ValueOfColumn(columnName, value); + po.set_ValueNoCheck(columnName, value); } /** @@ -68,7 +68,7 @@ public class PoFiller{ if (po.get_Value(columnName) != null && po.get_ValueAsBoolean(columnName) == bool) return; else - po.set_ValueOfColumn(columnName, bool); + po.set_ValueNoCheck(columnName, bool); } /** @@ -89,7 +89,7 @@ public class PoFiller{ else if (oldValue != null && oldValue.equals(ts)) return; else - po.set_ValueOfColumn(qName, ts); + po.set_ValueNoCheck(qName, ts); } /** @@ -110,7 +110,7 @@ public class PoFiller{ else if (oldValue != null && oldValue.equals(i)) return; else - po.set_ValueOfColumn(qName, i); + po.set_ValueNoCheck(qName, i); } /** @@ -131,10 +131,10 @@ public class PoFiller{ else if (oldValue != null && oldValue.equals(bd)) return; else - po.set_ValueOfColumn(qName, bd); + po.set_ValueNoCheck(qName, bd); } - public static int findTableReference(Properties ctx, AbstractElementHandler handler, Element element, String qName) { + public static int findTableReference(PIPOContext ctx, AbstractElementHandler handler, Element element, String qName) { Element propertyElement = element.properties.get(qName); if (propertyElement == null) return 0; @@ -169,16 +169,16 @@ public class PoFiller{ String value = e.contents.toString(); String columnName = qName; if (value != null && value.trim().length() > 0) { - int id = ReferenceUtils.resolveReference(ctx, e, po.get_TrxName()); + int id = ReferenceUtils.resolveReference(ctx.ctx, e, po.get_TrxName()); if (columnName.equals("AD_Client_ID") && id > 0) { - if (id != Env.getAD_Client_ID(ctx)) { + if (id != Env.getAD_Client_ID(ctx.ctx)) { return -1; } } if (po.get_ColumnIndex(columnName) >= 0) { if (id > 0) { if (po.get_ValueAsInt(columnName) != id) { - po.set_ValueOfColumn(columnName, id); + po.set_ValueNoCheck(columnName, id); } return id; } @@ -199,16 +199,26 @@ public class PoFiller{ POInfo info = POInfo.getPOInfo(po.getCtx(), po.get_Table_ID()); ListnotFounds = new ArrayList(); - //special treatment for ad_org_id - Element orgElement = element.properties.get("AD_Org_ID"); - String sAD_Org_ID = orgElement != null ? orgElement.contents.toString() : null; - if (sAD_Org_ID != null && sAD_Org_ID.equals("0")) + //special treatment for ad_client_id and ad_org_id + Element clientElement = element.properties.get("AD_Client_ID"); + String sAD_Client_ID = clientElement != null ? clientElement.contents.toString() : null; + if (sAD_Client_ID != null && sAD_Client_ID.equals("0")) + { + po.set_ValueNoCheck("AD_Client_ID", 0); po.setAD_Org_ID(0); - else if (sAD_Org_ID != null && sAD_Org_ID.equals("@AD_Org_ID@")) - po.setAD_Org_ID(Env.getAD_Org_ID(ctx)); - else { - if (setTableReference("AD_Client_ID") >= 0) - setTableReference("AD_Org_ID"); + } + else + { + Element orgElement = element.properties.get("AD_Org_ID"); + String sAD_Org_ID = orgElement != null ? orgElement.contents.toString() : null; + if (sAD_Org_ID != null && sAD_Org_ID.equals("0")) + po.setAD_Org_ID(0); + else if (sAD_Org_ID != null && sAD_Org_ID.equals("@AD_Org_ID@")) + po.setAD_Org_ID(Env.getAD_Org_ID(ctx.ctx)); + else { + if (setTableReference("AD_Client_ID") >= 0) + setTableReference("AD_Org_ID"); + } } for(String qName : element.properties.keySet()) { @@ -262,7 +272,7 @@ public class PoFiller{ if (component.length == 2) { String fileName = component[0]; String dataType = component[1]; - PackIn packIn = handler.getPackIn(ctx); + PackIn packIn = ctx.packIn; try { byte[] bytes = packIn.readBlob(fileName); if ("byte[]".equals(dataType)) { @@ -275,6 +285,6 @@ public class PoFiller{ } } } - po.set_ValueOfColumn(qName, data); + po.set_ValueNoCheck(qName, data); } } diff --git a/org.adempiere.pipo/src/org/adempiere/pipo2/ReferenceUtils.java b/org.adempiere.pipo/src/org/adempiere/pipo2/ReferenceUtils.java index 1226738d14..5740c51411 100644 --- a/org.adempiere.pipo/src/org/adempiere/pipo2/ReferenceUtils.java +++ b/org.adempiere.pipo/src/org/adempiere/pipo2/ReferenceUtils.java @@ -1,7 +1,13 @@ package org.adempiere.pipo2; +import java.io.UnsupportedEncodingException; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.Properties; +import org.adempiere.exceptions.DBException; +import org.apache.commons.codec.binary.Hex; import org.compiere.model.MTable; import org.compiere.model.PO; import org.compiere.util.DB; @@ -79,25 +85,29 @@ public class ReferenceUtils { 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) { + //official id atts.addAttribute("", "", "reference", "CDATA", "id"); String value = Integer.toString(id); return value; } else if (id == 0) { + //no id, should never happen atts.addAttribute("", "", "reference", "CDATA", "id"); return ""; } else { MTable table = MTable.get(Env.getCtx(), tableName); - if (table.getColumn(PO.getUUIDColumnName(tableName)) != null) + if (table == null) + throw new RuntimeException("Table Not Found. TableName="+tableName); + String uuidColumnName = PO.getUUIDColumnName(tableName); + if (table.getColumn(uuidColumnName) != null) { - sql = "SELECT " + PO.getUUIDColumnName(tableName) + " FROM " + //uuid + String sql = "SELECT " + uuidColumnName + " FROM " + tableName + " WHERE " + keyColumn + " = ?"; String value = DB.getSQLValueString(null, sql, id); if (value != null && value.trim().length() > 0) @@ -108,12 +118,53 @@ public class ReferenceUtils { } } - 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; + //search column + if (searchColumn.indexOf(",") > 0) { + //composite search column + String value = ""; + String[] columns = searchColumn.split("[,]"); + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = DB.prepareStatement("SELECT " + searchColumn + " FROM " + tableName, null); + rs = stmt.executeQuery(); + if (rs.next()) { + for(int i = 0; i < columns.length; i++) { + Object o = rs.getObject(i+1); + String s = o != null ? o.toString() : ""; + if (s.length() > 0) { + char[] chars = Hex.encodeHex(s.getBytes("UTF-8")); + s = new String(chars); + } + if (i == 0) { + value = s; + } else { + value = value+","+s; + } + } + } + } catch (SQLException e) { + throw new DBException(e); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } finally { + DB.close(rs, stmt); + } + StringBuffer buffer = new StringBuffer(); + buffer.append(tableName).append(".").append(searchColumn); + atts.addAttribute("", "", "reference", "CDATA", "table"); + atts.addAttribute("", "", "reference-key", "CDATA", buffer.toString()); + return value; + } else { + String sql = "SELECT " + searchColumn + " FROM " + + tableName + " WHERE " + keyColumn + " = ?"; + String value = DB.getSQLValueString(null, sql, id); + StringBuffer buffer = new StringBuffer(); + buffer.append(tableName).append(".").append(searchColumn); + atts.addAttribute("", "", "reference", "CDATA", "table"); + atts.addAttribute("", "", "reference-key", "CDATA", buffer.toString()); + return value; + } } } }