From 4481f00b5dd2121e0f3bfe4bb4d6425deede2b6c Mon Sep 17 00:00:00 2001 From: vpj-cd Date: Mon, 7 Dec 2009 21:27:03 +0000 Subject: [PATCH] Test Export Model in Export Format do not work https://sourceforge.net/tracker/?func=detail&atid=879332&aid=2910176&group_id=176962 Test Import Model do not work ADempiere Client https://sourceforge.net/tracker/?func=detail&atid=879332&aid=2910169&group_id=176962 finish the implementation of Export Format Generator https://sourceforge.net/tracker/?func=detail&atid=879332&aid=2910179&group_id=176962 --- base/src/org/adempiere/process/Export.java | 35 +-- .../org/adempiere/process}/rpl/XMLHelper.java | 2 +- .../process/rpl/exp/ExportHelper.java | 68 ++--- .../process/rpl/exp/ModelExporter.java | 165 ++++++++++++ .../process}/rpl/imp/ImportHelper.java | 49 ++-- .../process}/rpl/imp/ModelImporter.java | 4 +- base/src/org/compiere/model/MEXPFormat.java | 102 ++------ .../process/ExportFormatGenerator.java | 240 +++++++++++------- .../oracle/622_BF2910176TestExportModel.sql | 60 +++++ .../622_BF2910176TestExportModel.sql | 60 +++++ .../server/rpl/imp/FileImportProcessor.java | 3 +- .../server/rpl/imp/TopicListener.java | 3 +- 12 files changed, 550 insertions(+), 241 deletions(-) rename {serverRoot/src/main/server/org/adempiere/server => base/src/org/adempiere/process}/rpl/XMLHelper.java (99%) mode change 100644 => 100755 create mode 100644 base/src/org/adempiere/process/rpl/exp/ModelExporter.java rename {serverRoot/src/main/server/org/adempiere/server => base/src/org/adempiere/process}/rpl/imp/ImportHelper.java (91%) mode change 100644 => 100755 rename {serverRoot/src/main/server/org/adempiere/server => base/src/org/adempiere/process}/rpl/imp/ModelImporter.java (98%) mode change 100644 => 100755 create mode 100644 migration/354a-trunk/oracle/622_BF2910176TestExportModel.sql create mode 100644 migration/354a-trunk/postgresql/622_BF2910176TestExportModel.sql diff --git a/base/src/org/adempiere/process/Export.java b/base/src/org/adempiere/process/Export.java index 48ce4ae933..232ff8cd5d 100644 --- a/base/src/org/adempiere/process/Export.java +++ b/base/src/org/adempiere/process/Export.java @@ -32,6 +32,7 @@ package org.adempiere.process; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.Collection; import java.util.HashMap; import java.util.logging.Level; @@ -55,6 +56,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Text; + /** * * @author Trifon Trifonov @@ -214,20 +216,21 @@ public class Export extends SvrProcess */ private void generateExportFormat(Element rootElement, MEXPFormat exportFormat, ResultSet rs, PO masterPO, int masterID, HashMap variableMap) throws SQLException, Exception { - MEXPFormatLine[] formatLines = (MEXPFormatLine[]) exportFormat.getFormatLines(); + Collection formatLines = exportFormat.getFormatLines(); @SuppressWarnings("unused") boolean elementHasValue = false; - for (int i = 0; i < formatLines.length; i++) { - if ( formatLines[i].getType().equals(X_EXP_FormatLine.TYPE_XMLElement) ) { + for (MEXPFormatLine formatLine : formatLines) + { + if ( formatLine.getType().equals(X_EXP_FormatLine.TYPE_XMLElement) ) { // process single XML Attribute // Create new element - Element newElement = outDocument.createElement(formatLines[i].getValue()); + Element newElement = outDocument.createElement(formatLine.getValue()); - if (formatLines[i].getAD_Column_ID() == 0) { + if (formatLine.getAD_Column_ID() == 0) { throw new Exception(Msg.getMsg (getCtx(), "EXPColumnMandatory")); } - MColumn column = MColumn.get(getCtx(), formatLines[i].getAD_Column_ID()); + MColumn column = MColumn.get(getCtx(), formatLine.getAD_Column_ID()); if (column == null) { throw new Exception(Msg.getMsg (getCtx(), "EXPColumnMandatory")); } @@ -241,7 +244,7 @@ public class Export extends SvrProcess if (value != null) { valueString = value.toString(); } else { - if (formatLines[i].isMandatory()) { + if (formatLine.isMandatory()) { throw new Exception(Msg.getMsg (getCtx(), "EXPFieldMandatory")); } } @@ -278,17 +281,17 @@ public class Export extends SvrProcess } else { // Empty field. } - } else if ( formatLines[i].getType().equals(X_EXP_FormatLine.TYPE_XMLAttribute) ) { + } else if ( formatLine.getType().equals(X_EXP_FormatLine.TYPE_XMLAttribute) ) { // process single XML Attribute /* // Create new element Element newElement = outDocument.createElement(formatLines[i].getValue()); if (hasContent) { rootElement.appendChild(newElement); }*/ - if (formatLines[i].getAD_Column_ID() == 0) { + if (formatLine.getAD_Column_ID() == 0) { throw new Exception(Msg.getMsg (getCtx(), "EXPColumnMandatory")); } - MColumn column = MColumn.get(getCtx(), formatLines[i].getAD_Column_ID()); + MColumn column = MColumn.get(getCtx(), formatLine.getAD_Column_ID()); if (column == null) { throw new Exception(Msg.getMsg (getCtx(), "EXPColumnMandatory")); } @@ -302,7 +305,7 @@ public class Export extends SvrProcess if (value != null) { valueString = value.toString(); } else { - if (formatLines[i].isMandatory()) { + if (formatLine.isMandatory()) { throw new Exception(Msg.getMsg (getCtx(), "EXPFieldMandatory")); } } @@ -330,17 +333,17 @@ public class Export extends SvrProcess }*/ log.info("EXP Field - column=["+column.getColumnName()+"]; value=" + value); if (valueString != null && !"".equals(valueString) && !"null".equals(valueString)) { - rootElement.setAttribute(formatLines[i].getValue(), valueString); + rootElement.setAttribute(formatLine.getValue(), valueString); elementHasValue = true; //increaseVariable(variableMap, formatLines[i].getVariableName()); // Increase value of Variable if any Variable //increaseVariable(variableMap, TOTAL_SEGMENTS); } else { // Empty field. } - } else if ( formatLines[i].getType().equals(X_EXP_FormatLine.TYPE_EmbeddedEXPFormat) ) { + } else if ( formatLine.getType().equals(X_EXP_FormatLine.TYPE_EmbeddedEXPFormat) ) { // process Embedded Export Format - int embeddedFormat_ID = formatLines[i].getEXP_EmbeddedFormat_ID(); + int embeddedFormat_ID = formatLine.getEXP_EmbeddedFormat_ID(); MEXPFormat embeddedFormat = new MEXPFormat(getCtx(), embeddedFormat_ID, get_TrxName()); MTable tableEmbedded = MTable.get(getCtx(), embeddedFormat.getAD_Table_ID()); @@ -366,8 +369,8 @@ public class Export extends SvrProcess int embeddedID = rsEmbedded.getInt(tableEmbedded.getTableName() + "_ID"); PO poEmbedded = tableEmbedded.getPO (embeddedID, get_TrxName()); - Element embeddedElement = outDocument.createElement(formatLines[i].getValue()); - embeddedElement.appendChild(outDocument.createComment(formatLines[i].getDescription())); + Element embeddedElement = outDocument.createElement(formatLine.getValue()); + embeddedElement.appendChild(outDocument.createComment(formatLine.getDescription())); generateExportFormat(embeddedElement, embeddedFormat, rsEmbedded, poEmbedded, embeddedID, variableMap); rootElement.appendChild(embeddedElement); } diff --git a/serverRoot/src/main/server/org/adempiere/server/rpl/XMLHelper.java b/base/src/org/adempiere/process/rpl/XMLHelper.java old mode 100644 new mode 100755 similarity index 99% rename from serverRoot/src/main/server/org/adempiere/server/rpl/XMLHelper.java rename to base/src/org/adempiere/process/rpl/XMLHelper.java index 2299e694ca..1d4f77eb1e --- a/serverRoot/src/main/server/org/adempiere/server/rpl/XMLHelper.java +++ b/base/src/org/adempiere/process/rpl/XMLHelper.java @@ -26,7 +26,7 @@ * Sponsors: * * - E-evolution (http://www.e-evolution.com) * **********************************************************************/ -package org.adempiere.server.rpl; +package org.adempiere.process.rpl; import java.io.File; import java.io.IOException; diff --git a/base/src/org/adempiere/process/rpl/exp/ExportHelper.java b/base/src/org/adempiere/process/rpl/exp/ExportHelper.java index b82d476b3a..f1724d98fb 100644 --- a/base/src/org/adempiere/process/rpl/exp/ExportHelper.java +++ b/base/src/org/adempiere/process/rpl/exp/ExportHelper.java @@ -34,6 +34,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; import java.text.SimpleDateFormat; +import java.util.Collection; import java.util.HashMap; import java.util.Properties; @@ -63,6 +64,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Text; + /** * @author Trifon N. Trifonov * @author Antonio CaƱaveral, e-Evolution @@ -232,7 +234,7 @@ public class ExportHelper { for (int id : ids) { - PO po = table.getPO(id, null); + PO po = table.getPO(id, exportFormat.get_TrxName()); log.info("Client = " + client.toString()); log.finest("po.getAD_Org_ID() = " + po.getAD_Org_ID()); log.finest("po.get_TrxName() = " + po.get_TrxName()); @@ -302,20 +304,22 @@ public class ExportHelper { */ private void generateExportFormat(Element rootElement, MEXPFormat exportFormat, ResultSet rs, PO masterPO, int masterID, HashMap variableMap) throws SQLException, Exception { - MEXPFormatLine[] formatLines = (MEXPFormatLine[]) exportFormat.getFormatLines(); + Collection formatLines = exportFormat.getFormatLines(); @SuppressWarnings("unused") boolean elementHasValue = false; - for (int i = 0; i < formatLines.length; i++) { - if ( formatLines[i].getType().equals(X_EXP_FormatLine.TYPE_XMLElement) ) { + //for (int i = 0; i < formatLines.length; i++) { + for (MEXPFormatLine formatLine : formatLines) + { + if ( formatLine.getType().equals(X_EXP_FormatLine.TYPE_XMLElement) ) { // process single XML Attribute // Create new element - Element newElement = outDocument.createElement(formatLines[i].getValue()); + Element newElement = outDocument.createElement(formatLine.getValue()); - if (formatLines[i].getAD_Column_ID() == 0) { + if (formatLine.getAD_Column_ID() == 0) { throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPColumnMandatory")); } - MColumn column = MColumn.get(masterPO.getCtx(), formatLines[i].getAD_Column_ID()); + MColumn column = MColumn.get(masterPO.getCtx(), formatLine.getAD_Column_ID()); if (column == null) { throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPColumnMandatory")); } @@ -330,14 +334,14 @@ public class ExportHelper { valueString = value.toString(); } else { // Could remove this exception and create empty XML Element when column do not have value. - if (formatLines[i].isMandatory()) { + if (formatLine.isMandatory()) { //throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPFieldMandatory")); } } if (column.getAD_Reference_ID() == DisplayType.Date) { if (valueString != null) { - if (formatLines[i].getDateFormat() != null && !"".equals(formatLines[i].getDateFormat())) { - m_customDateFormat = new SimpleDateFormat( formatLines[i].getDateFormat() ); // "MM/dd/yyyy" + if (formatLine.getDateFormat() != null && !"".equals(formatLine.getDateFormat())) { + m_customDateFormat = new SimpleDateFormat( formatLine.getDateFormat() ); // "MM/dd/yyyy" //Date date = m_customDateFormat.parse ( valueString ); valueString = m_customDateFormat.format(Timestamp.valueOf (valueString)); newElement.setAttribute("DateFormat", m_customDateFormat.toPattern()); // Add "DateForamt attribute" @@ -351,8 +355,8 @@ public class ExportHelper { } } else if (column.getAD_Reference_ID() == DisplayType.DateTime) { if (valueString != null) { - if (formatLines[i].getDateFormat() != null && !"".equals(formatLines[i].getDateFormat())) { - m_customDateFormat = new SimpleDateFormat( formatLines[i].getDateFormat() ); // "MM/dd/yyyy" + if (formatLine.getDateFormat() != null && !"".equals(formatLine.getDateFormat())) { + m_customDateFormat = new SimpleDateFormat( formatLine.getDateFormat() ); // "MM/dd/yyyy" //Date date = m_customDateFormat.parse ( valueString ); valueString = m_customDateFormat.format(Timestamp.valueOf (valueString)); newElement.setAttribute("DateFormat", m_customDateFormat.toPattern()); // Add "DateForamt attribute" @@ -374,19 +378,19 @@ public class ExportHelper { //increaseVariable(variableMap, TOTAL_SEGMENTS); } else { // Empty field. - if (formatLines[i].isMandatory()) { + if (formatLine.isMandatory()) { Text newText = outDocument.createTextNode(""); newElement.appendChild(newText); rootElement.appendChild(newElement); elementHasValue = true; } } - } else if ( formatLines[i].getType().equals(X_EXP_FormatLine.TYPE_XMLAttribute) ) { + } else if ( formatLine.getType().equals(X_EXP_FormatLine.TYPE_XMLAttribute) ) { // process single XML Attribute - if (formatLines[i].getAD_Column_ID() == 0) { + if (formatLine.getAD_Column_ID() == 0) { throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPColumnMandatory")); } - MColumn column = MColumn.get(masterPO.getCtx(), formatLines[i].getAD_Column_ID()); + MColumn column = MColumn.get(masterPO.getCtx(), formatLine.getAD_Column_ID()); if (column == null) { throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPColumnMandatory")); } @@ -400,7 +404,7 @@ public class ExportHelper { if (value != null) { valueString = value.toString(); } else { - if (formatLines[i].isMandatory()) { + if (formatLine.isMandatory()) { throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPFieldMandatory")); } } @@ -428,17 +432,19 @@ public class ExportHelper { }*/ log.info("EXP Field - column=["+column.getColumnName()+"]; value=" + value); if (valueString != null && !"".equals(valueString) && !"null".equals(valueString)) { - rootElement.setAttribute(formatLines[i].getValue(), valueString); + rootElement.setAttribute(formatLine.getValue(), valueString); elementHasValue = true; //increaseVariable(variableMap, formatLines[i].getVariableName()); // Increase value of Variable if any Variable //increaseVariable(variableMap, TOTAL_SEGMENTS); } else { // Empty field. } - } else if ( formatLines[i].getType().equals(X_EXP_FormatLine.TYPE_EmbeddedEXPFormat) ) { + } + else if ( formatLine.getType().equals(X_EXP_FormatLine.TYPE_EmbeddedEXPFormat) ) + { // process Embedded Export Format - int embeddedFormat_ID = formatLines[i].getEXP_EmbeddedFormat_ID(); + int embeddedFormat_ID = formatLine.getEXP_EmbeddedFormat_ID(); MEXPFormat embeddedFormat = new MEXPFormat(masterPO.getCtx(), embeddedFormat_ID, masterPO.get_TrxName()); MTable tableEmbedded = MTable.get(masterPO.getCtx(), embeddedFormat.getAD_Table_ID()); @@ -465,9 +471,9 @@ public class ExportHelper { int embeddedID = rsEmbedded.getInt(tableEmbedded.getTableName() + "_ID"); PO poEmbedded = tableEmbedded.getPO (embeddedID, masterPO.get_TrxName()); - Element embeddedElement = outDocument.createElement(formatLines[i].getValue()); - if (formatLines[i].getDescription() != null && !"".equals(formatLines[i].getDescription())) { - embeddedElement.appendChild(outDocument.createComment(formatLines[i].getDescription())); + Element embeddedElement = outDocument.createElement(formatLine.getValue()); + if (formatLine.getDescription() != null && !"".equals(formatLine.getDescription())) { + embeddedElement.appendChild(outDocument.createComment(formatLine.getDescription())); } generateExportFormat(embeddedElement, embeddedFormat, rsEmbedded, poEmbedded, embeddedID, variableMap); rootElement.appendChild(embeddedElement); @@ -482,10 +488,12 @@ public class ExportHelper { pstmt = null; } - } else if ( formatLines[i].getType().equals(X_EXP_FormatLine.TYPE_ReferencedEXPFormat) ) { + } + else if ( formatLine.getType().equals(X_EXP_FormatLine.TYPE_ReferencedEXPFormat) ) + { // process Referenced Export Format - int embeddedFormat_ID = formatLines[i].getEXP_EmbeddedFormat_ID(); + int embeddedFormat_ID = formatLine.getEXP_EmbeddedFormat_ID(); MEXPFormat embeddedFormat = new MEXPFormat(masterPO.getCtx(), embeddedFormat_ID, masterPO.get_TrxName()); MTable tableEmbedded = MTable.get(masterPO.getCtx(), embeddedFormat.getAD_Table_ID()); @@ -499,10 +507,10 @@ public class ExportHelper { sql.append(" AND ").append(embeddedFormat.getWhereClause()); } log.info(sql.toString()); - if (formatLines[i].getAD_Column_ID() == 0) { + if (formatLine.getAD_Column_ID() == 0) { throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPColumnMandatory")); } - MColumn column = MColumn.get(masterPO.getCtx(), formatLines[i].getAD_Column_ID()); + MColumn column = MColumn.get(masterPO.getCtx(), formatLine.getAD_Column_ID()); if (column == null) { throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPColumnMandatory")); } @@ -532,9 +540,9 @@ public class ExportHelper { int embeddedID = rsEmbedded.getInt(tableEmbedded.getTableName() + "_ID"); PO poEmbedded = tableEmbedded.getPO (embeddedID, masterPO.get_TrxName()); - Element embeddedElement = outDocument.createElement(formatLines[i].getValue()); - if (formatLines[i].getDescription() != null && !"".equals(formatLines[i].getDescription())) { - embeddedElement.appendChild(outDocument.createComment(formatLines[i].getDescription())); + Element embeddedElement = outDocument.createElement(formatLine.getValue()); + if (formatLine.getDescription() != null && !"".equals(formatLine.getDescription())) { + embeddedElement.appendChild(outDocument.createComment(formatLine.getDescription())); } generateExportFormat(embeddedElement, embeddedFormat, rsEmbedded, poEmbedded, embeddedID, variableMap); rootElement.appendChild(embeddedElement); diff --git a/base/src/org/adempiere/process/rpl/exp/ModelExporter.java b/base/src/org/adempiere/process/rpl/exp/ModelExporter.java new file mode 100644 index 0000000000..f3ec462b0b --- /dev/null +++ b/base/src/org/adempiere/process/rpl/exp/ModelExporter.java @@ -0,0 +1,165 @@ +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * 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. * + * For the text or an alternative of this public license, you may reach us * + * Contributor(s): Victor Perez www.e-evolution.com * + * Copyright (C) 2003-2007 e-Evolution,SC. All Rights Reserved. * + *****************************************************************************/ +package org.adempiere.process.rpl.exp; + +import java.io.File; +import java.io.StringWriter; +import java.io.Writer; +import java.util.logging.Level; + +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.compiere.Adempiere; +import org.compiere.model.MEXPFormat; +import org.compiere.model.MReplicationStrategy; +import org.compiere.model.ModelValidator; +import org.compiere.model.X_AD_ReplicationTable; +import org.compiere.process.ProcessInfo; +import org.compiere.process.ProcessInfoParameter; +import org.compiere.process.SvrProcess; +import org.compiere.util.CLogMgt; +import org.compiere.util.Env; +import org.w3c.dom.Document; + +/** + * + * @author victor.perez@e-evolution.com + * FB [1963487 ] Is necessary new process to export and import with an Export + * @see http://sourceforge.net/tracker/?func=detail&atid=879335&aid=1963487&group_id=176962 + * @version $Id:$ + */ +public class ModelExporter extends SvrProcess { + + /** Client Parameter */ + protected int p_AD_Client_ID = 0; + + /** Document Type Parameter */ + protected int p_C_DocType_ID = 0; + + /** Record ID */ + protected int p_Record_ID = 0; + /** EXP_Format_ID */ + protected int p_EXP_Format_ID = 0; + /** File Name **/ + protected String p_FileName = ""; + + /** Table ID */ + int AD_Table_ID = 0; + + + /** + * Get Parameters + */ + protected void prepare() { + + p_Record_ID = getRecord_ID(); + if (p_AD_Client_ID == 0) + p_AD_Client_ID = Env.getAD_Client_ID(getCtx()); + AD_Table_ID = getTable_ID(); + + StringBuffer sb = new StringBuffer("AD_Table_ID=").append(AD_Table_ID); + sb.append("; Record_ID=").append(getRecord_ID()); + // Parameter + ProcessInfoParameter[] paras = getParameter(); + for (ProcessInfoParameter para : paras) + { + String name = para.getParameterName(); + if (para.getParameter() == null) + ; + else if (name.equals("EXP_Format_ID")) + p_EXP_Format_ID = para.getParameterAsInt(); + else if (name.equals("FileName")) + p_FileName = (String)para.getParameter(); + else + log.log(Level.SEVERE, "Unknown Parameter: " + name); + } + + if(p_EXP_Format_ID == 0) + p_EXP_Format_ID = p_Record_ID; + if(p_FileName == null) + { + // Load XML file and parse it + String fileNameOr = org.compiere.util.Ini.findAdempiereHome() + + System.getProperty("file.separator") + + "data" + + System.getProperty("file.separator") + + "ExportFile.xml"; + p_FileName = fileNameOr; + } + log.info(sb.toString()); + } + + /** + * Process + * + * @return info + */ + protected String doIt() throws Exception + { + ExportHelper expHelper = new ExportHelper(getCtx(),p_AD_Client_ID); + MEXPFormat exportFormat = new MEXPFormat (getCtx(), p_EXP_Format_ID, get_TrxName() ); + File file = new File(p_FileName); + Document doc = expHelper.exportRecord(exportFormat,"", MReplicationStrategy.REPLICATION_TABLE, X_AD_ReplicationTable.REPLICATIONTYPE_Merge,ModelValidator.TYPE_AFTER_CHANGE); + // Save the document to the disk file + TransformerFactory tranFactory = TransformerFactory.newInstance(); + + tranFactory.setAttribute("indent-number", 4); + + Transformer aTransformer = tranFactory.newTransformer(); + aTransformer.setOutputProperty(OutputKeys.METHOD, "xml"); + aTransformer.setOutputProperty(OutputKeys.INDENT, "yes"); + Source src = new DOMSource(doc); + + // =================================== Write to String + Writer writer = new StringWriter(); + Result dest2 = new StreamResult(writer); + aTransformer.transform(src, dest2); + // =================================== Write to Disk + try { + Result dest = new StreamResult(file); + aTransformer.transform(src, dest); + writer.flush(); + writer.close(); + + } catch (TransformerException ex) { + ex.printStackTrace(); + throw ex; + } + return "Exported"; + } + + public static void main(String[] args) + { + CLogMgt.setLoggerLevel(Level.INFO, null); + CLogMgt.setLevel(Level.INFO); + + Adempiere.startupEnvironment(true); + ProcessInfo pi = new ProcessInfo("Test Import Model", 1000000); + pi.setAD_Client_ID(11); + pi.setAD_User_ID(100); + + ModelExporter modelExporter = new ModelExporter(); + modelExporter.startProcess(Env.getCtx(), pi, null); + } + +} \ No newline at end of file diff --git a/serverRoot/src/main/server/org/adempiere/server/rpl/imp/ImportHelper.java b/base/src/org/adempiere/process/rpl/imp/ImportHelper.java old mode 100644 new mode 100755 similarity index 91% rename from serverRoot/src/main/server/org/adempiere/server/rpl/imp/ImportHelper.java rename to base/src/org/adempiere/process/rpl/imp/ImportHelper.java index a56cbe3b40..4dee08b95e --- a/serverRoot/src/main/server/org/adempiere/server/rpl/imp/ImportHelper.java +++ b/base/src/org/adempiere/process/rpl/imp/ImportHelper.java @@ -26,20 +26,22 @@ * Sponsors: * * - E-evolution (http://www.e-evolution.com/) * **********************************************************************/ -package org.adempiere.server.rpl.imp; +package org.adempiere.process.rpl.imp; import java.math.BigDecimal; import java.sql.SQLException; import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Collection; import java.util.List; import java.util.Properties; import javax.xml.xpath.XPathExpressionException; +import org.adempiere.exceptions.AdempiereException; import org.adempiere.process.rpl.exp.ExportHelper; -import org.adempiere.server.rpl.XMLHelper; +import org.adempiere.process.rpl.XMLHelper; import org.compiere.model.I_AD_Client; import org.compiere.model.MClient; import org.compiere.model.MColumn; @@ -266,8 +268,8 @@ public class ImportHelper { StringBuffer orderBy = new StringBuffer(MEXPFormatLine.COLUMNNAME_IsMandatory).append(" DESC ") .append(", ").append(MEXPFormatLine.COLUMNNAME_Position); - MEXPFormatLine[] formatLines = expFormat.getFormatLinesOrderedBy(orderBy.toString()); - if (formatLines == null || formatLines.length < 1) + Collection formatLines = expFormat.getFormatLinesOrderedBy(orderBy.toString()); + if (formatLines == null || formatLines.size() < 1) { throw new Exception(Msg.getMsg(ctx, "EXPFormatNoLines")); } @@ -472,8 +474,7 @@ public class ImportHelper { // if (!Util.isEmpty(value.toString())) { - double doubleValue = Double.parseDouble(value.toString()); - value = new BigDecimal(doubleValue); + value = new Integer(value.toString()); } else { @@ -567,22 +568,25 @@ public class ImportHelper { } // Get list with all Unique columns! - MEXPFormatLine[] uniqueFormatLines = expFormat.getUniqueColumns(); - if (uniqueFormatLines == null || uniqueFormatLines.length < 1) + Collection uniqueFormatLines = expFormat.getUniqueColumns(); + if (uniqueFormatLines == null || uniqueFormatLines.size() < 1) { - throw new Exception(Msg.getMsg(ctx, "EXPFormatLineNoUniqueColumns")); + throw new AdempiereException(Msg.getMsg(ctx, "EXPFormatLineNoUniqueColumns")); } - Object[] cols = new Object[uniqueFormatLines.length]; - Object[] params = new Object[uniqueFormatLines.length]; + Object[] cols = new Object[uniqueFormatLines.size()]; + Object[] params = new Object[uniqueFormatLines.size()]; StringBuffer whereClause= new StringBuffer(""); int col = 0; + String formatLines = ""; for (MEXPFormatLine uniqueFormatLine : uniqueFormatLines) { MColumn column = MColumn.get(ctx, uniqueFormatLine.getAD_Column_ID()); log.info("column = ["+column+"]"); String valuecol=column.getColumnName(); + formatLines = formatLines + "|"+ valuecol; + if (MEXPFormatLine.TYPE_XMLElement.equals(uniqueFormatLine.getType())) { // XML Element @@ -626,10 +630,23 @@ public class ImportHelper { { params[col] = (String)cols[col]; } - else if( DisplayType.Amount == column.getAD_Reference_ID() - || DisplayType.Number == column.getAD_Reference_ID() - || DisplayType.CostPrice == column.getAD_Reference_ID() - || DisplayType.Quantity == column.getAD_Reference_ID()) + else if ( DisplayType.isID(column.getAD_Reference_ID()) + || DisplayType.Integer == column.getAD_Reference_ID()) + { + Object value = cols[col]; + if (!Util.isEmpty(value.toString())) + { + //double doubleValue = Double.parseDouble(value.toString()); + value = new Integer(value.toString()); + } + else + { + value=null; + } + + params[col] = value; + } + else if( DisplayType.isNumeric(column.getAD_Reference_ID())) { valuecol="Round("+valuecol+",2)"; params[col] = new BigDecimal((String)cols[col]).setScale(2, BigDecimal.ROUND_HALF_UP); @@ -653,7 +670,7 @@ public class ImportHelper { if(values.size()>1)//The Return Object must be always one { - throw new Exception(Msg.getMsg(ctx, "EXPFormatIncorrectFormatDefinition")); + throw new AdempiereException(Msg.getMsg(ctx, "EXPFormatLineNoUniqueColumns") + " : " +expFormat.getName() + "(" +formatLines+")"); } if(values.size()<=0)//Means that is a new record diff --git a/serverRoot/src/main/server/org/adempiere/server/rpl/imp/ModelImporter.java b/base/src/org/adempiere/process/rpl/imp/ModelImporter.java old mode 100644 new mode 100755 similarity index 98% rename from serverRoot/src/main/server/org/adempiere/server/rpl/imp/ModelImporter.java rename to base/src/org/adempiere/process/rpl/imp/ModelImporter.java index aba442b57d..e03c5ed0b5 --- a/serverRoot/src/main/server/org/adempiere/server/rpl/imp/ModelImporter.java +++ b/base/src/org/adempiere/process/rpl/imp/ModelImporter.java @@ -26,11 +26,11 @@ * Sponsors: * * - E-evolution (http://www.e-evolution.com/) * **********************************************************************/ -package org.adempiere.server.rpl.imp; +package org.adempiere.process.rpl.imp; import java.util.logging.Level; -import org.adempiere.server.rpl.XMLHelper; +import org.adempiere.process.rpl.XMLHelper; import org.compiere.Adempiere; import org.compiere.process.ProcessInfo; import org.compiere.process.ProcessInfoParameter; diff --git a/base/src/org/compiere/model/MEXPFormat.java b/base/src/org/compiere/model/MEXPFormat.java index 5ce329a8bd..e5a67f6082 100644 --- a/base/src/org/compiere/model/MEXPFormat.java +++ b/base/src/org/compiere/model/MEXPFormat.java @@ -30,19 +30,13 @@ package org.compiere.model; -import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; +import java.util.Collection; import java.util.Properties; -import java.util.logging.Level; -import org.compiere.model.MTable; -import org.compiere.model.Query; import org.compiere.util.CCache; import org.compiere.util.CLogger; -import org.compiere.util.DB; /** * @author Trifon N. Trifonov @@ -51,10 +45,11 @@ import org.compiere.util.DB; *
  • http://sourceforge.net/tracker/index.php?func=detail&aid=2195090&group_id=176962&atid=879335 */ public class MEXPFormat extends X_EXP_Format { + /** * */ - private static final long serialVersionUID = 1070027055056912752L; + private static final long serialVersionUID = 1455411275338766608L; /** Static Logger */ private static CLogger s_log = CLogger.getCLogger (MEXPFormat.class); @@ -69,86 +64,29 @@ public class MEXPFormat extends X_EXP_Format { super (ctx, rs, trxName); } - public MEXPFormatLine[] getFormatLines() { + public Collection getFormatLines() { return getFormatLinesOrderedBy(X_EXP_FormatLine.COLUMNNAME_Position); } - public MEXPFormatLine[] getFormatLinesOrderedBy(String orderBy) { - List resultList = new ArrayList(); - - StringBuffer sql = new StringBuffer("SELECT * ") - .append(" FROM ").append(X_EXP_FormatLine.Table_Name) - .append(" WHERE ").append(X_EXP_FormatLine.COLUMNNAME_EXP_Format_ID).append("=?") - .append(" AND IsActive = ?") - .append(" ORDER BY ").append(orderBy); - PreparedStatement pstmt = null; - MEXPFormatLine exportLine = null; - try { - pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); - pstmt.setInt(1, getEXP_Format_ID()); - pstmt.setString(2, "Y"); - ResultSet rs = pstmt.executeQuery (); - while ( rs.next() ) { - exportLine = new MEXPFormatLine (getCtx(), rs, get_TrxName()); - resultList.add(exportLine); - } - rs.close (); - pstmt.close (); - pstmt = null; - } catch (SQLException e) { - s_log.log(Level.SEVERE, sql.toString(), e); - } finally { - try { - if (pstmt != null) pstmt.close (); - pstmt = null; - } catch (Exception e) { pstmt = null; } - } - - MEXPFormatLine[] result = (MEXPFormatLine[])resultList.toArray( new MEXPFormatLine[0]); - return result; + public Collection getFormatLinesOrderedBy(String orderBy) + { + final String clauseWhere = X_EXP_FormatLine.COLUMNNAME_EXP_Format_ID + "=?"; + return new Query(getCtx() , I_EXP_FormatLine.Table_Name, clauseWhere , get_TrxName()) + .setOnlyActiveRecords(true) + .setParameters(new Object[]{getEXP_Format_ID()}) + .setOrderBy(orderBy) + .list(); } - public MEXPFormatLine[] getUniqueColumns() throws SQLException { - List resultList = new ArrayList(); - - StringBuffer sql = new StringBuffer("SELECT * ") - .append(" FROM ").append(X_EXP_FormatLine.Table_Name) - .append(" WHERE ").append(X_EXP_FormatLine.COLUMNNAME_EXP_Format_ID).append("= ?") - .append(" AND IsActive = ?") - .append(" AND ").append(X_EXP_FormatLine.COLUMNNAME_IsPartUniqueIndex).append("= ?") - .append(" ORDER BY ").append(X_EXP_FormatLine.COLUMNNAME_Position); - PreparedStatement pstmt = null; - MEXPFormatLine exportLine = null; - log.info(sql.toString()); - - log.info("pstmt.setInt(1, getEXP_Format_ID() = " + getEXP_Format_ID()); - try { - pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); - pstmt.setInt(1, getEXP_Format_ID()); - pstmt.setString(2, "Y"); - pstmt.setString(3, "Y"); - ResultSet rs = pstmt.executeQuery (); - while ( rs.next() ) { - exportLine = new MEXPFormatLine (getCtx(), rs, get_TrxName()); - resultList.add(exportLine); - } - rs.close (); - pstmt.close (); - pstmt = null; - } catch (SQLException e) { - s_log.log(Level.SEVERE, sql.toString(), e); - throw e; - } finally { - try { - if (pstmt != null) pstmt.close (); - pstmt = null; - } catch (Exception e) { pstmt = null; } - } - - MEXPFormatLine[] result = (MEXPFormatLine[])resultList.toArray( new MEXPFormatLine[0]); - return result; + public Collection getUniqueColumns() throws SQLException { + final String clauseWhere = X_EXP_FormatLine.COLUMNNAME_EXP_Format_ID+"= ?" + + " AND " + X_EXP_FormatLine.COLUMNNAME_IsPartUniqueIndex +"= ?"; + return new Query(getCtx(), I_EXP_FormatLine.Table_Name, clauseWhere, get_TrxName()) + .setOnlyActiveRecords(true) + .setParameters(new Object[]{getEXP_Format_ID(), "Y"}) + .setOrderBy(X_EXP_FormatLine.COLUMNNAME_Position) + .list(); } - public static MEXPFormat getFormatByValueAD_Client_IDAndVersion(Properties ctx, String value, int AD_Client_ID, String version, String trxName) throws SQLException diff --git a/base/src/org/eevolution/process/ExportFormatGenerator.java b/base/src/org/eevolution/process/ExportFormatGenerator.java index e400ce9abe..e5fecf9be2 100644 --- a/base/src/org/eevolution/process/ExportFormatGenerator.java +++ b/base/src/org/eevolution/process/ExportFormatGenerator.java @@ -15,9 +15,11 @@ *****************************************************************************/ package org.eevolution.process; +import java.sql.SQLException; import java.util.Hashtable; import java.util.logging.Level; +import org.adempiere.exceptions.AdempiereException; import org.compiere.model.MColumn; import org.compiere.model.MEXPFormat; import org.compiere.model.MEXPFormatLine; @@ -45,30 +47,33 @@ public class ExportFormatGenerator extends SvrProcess private boolean p_IsMandatory = false; private boolean p_IsInsertRecord= false; private Hashtable m_formats = new Hashtable(); + private String version = "3.2.0"; private String m_parent_table = null; private String m_format_value = null; private int m_level = -1; + private MTab currentTab = null; + private MWindow window = null; /** * Prepare - e.g., get Parameters. */ protected void prepare() { - ProcessInfoParameter[] para = getParameter(); - for (int i = 0; i < para.length; i++) + ProcessInfoParameter[] paras = getParameter(); + for (ProcessInfoParameter para : paras) { - String name = para[i].getParameterName(); - if (para[i].getParameter() == null) + String name = para.getParameterName(); + if (para.getParameter() == null) ; else if (name.equals("AD_Window_ID")) - p_AD_Window_ID = para[i].getParameterAsInt(); + p_AD_Window_ID = para.getParameterAsInt(); else if (name.equals("IsMandatory")) { - p_IsMandatory = "Y".equals(para[i].getParameter()); + p_IsMandatory = "Y".equals(para.getParameter()); } else if (name.equals("IsInsertRecord")) { - p_IsInsertRecord = "Y".equals(para[i].getParameter()); + p_IsInsertRecord = "Y".equals(para.getParameter()); } else log.log(Level.SEVERE, "Unknown Parameter: " + name); @@ -82,7 +87,7 @@ public class ExportFormatGenerator extends SvrProcess */ protected String doIt () throws Exception { - MWindow window = new MWindow(getCtx(),p_AD_Window_ID, get_TrxName()); + window = new MWindow(getCtx(),p_AD_Window_ID, get_TrxName()); MTab[] tabs = window.getTabs(true, get_TrxName()); @@ -113,7 +118,7 @@ public class ExportFormatGenerator extends SvrProcess } return "ok"; } // doIt - + private String createFormat(MTable table) throws Exception { log.info("Table Name:"+table.getTableName()); @@ -144,7 +149,7 @@ public class ExportFormatGenerator extends SvrProcess return format.getValue(); String where=" value = ? "; - Query sql = new Query(getCtx(),MEXPFormat.Table_Name,where,null).setParameters(new Object[]{formatValue}); + Query sql = new Query(getCtx(),MEXPFormat.Table_Name,where,get_TrxName()).setParameters(new Object[]{formatValue}); if(sql.match()) { format = (MEXPFormat) sql.first(); @@ -152,17 +157,17 @@ public class ExportFormatGenerator extends SvrProcess return format.getValue(); } - format = MEXPFormat.getFormatByValueAD_Client_IDAndVersion(getCtx(), formatValue, getAD_Client_ID(), "1", get_TrxName()); + format = MEXPFormat.getFormatByValueAD_Client_IDAndVersion(getCtx(), formatValue, getAD_Client_ID(), version, get_TrxName()); if(format == null) format = new MEXPFormat(getCtx(), 0 , get_TrxName()); - + format.setAD_Org_ID(0); format.setValue(formatValue); format.setName(table.getName()); format.setAD_Table_ID(table.getAD_Table_ID()); format.setDescription(table.getDescription()); format.setHelp(table.getHelp()); - format.setVersion("1"); - format.save(); + format.setVersion(version); + format.saveEx(); if (format != null) m_formats.put(format.getValue(), format); @@ -184,41 +189,54 @@ public class ExportFormatGenerator extends SvrProcess private int createFormatLine(MEXPFormat format, MTable table, MColumn col, int position,boolean force) throws Exception { - MEXPFormatLine format_line =null; + MEXPFormatLine formatLine =null; String formatlinevalue= col.getColumnName(); - format_line = MEXPFormatLine.getFormatLineByValue(getCtx(),formatlinevalue ,format.getEXP_Format_ID(),get_TrxName()); - if(format_line==null) - format_line = new MEXPFormatLine(getCtx(),0,get_TrxName()); + formatLine = MEXPFormatLine.getFormatLineByValue(getCtx(),formatlinevalue ,format.getEXP_Format_ID(),get_TrxName()); + if(formatLine==null) + formatLine = new MEXPFormatLine(getCtx(),0,get_TrxName()); + - format_line.setEXP_Format_ID(format.getEXP_Format_ID()); - format_line.setValue(formatlinevalue); - format_line.setName(col.getName()); - format_line.setDescription(col.getDescription()); - format_line.setHelp(col.getHelp()); - format_line.setPosition(position); - format_line.setIsMandatory(col.isMandatory()); - if(force||col.isIdentifier()) + formatLine.setAD_Org_ID(0); + formatLine.setEXP_Format_ID(format.getEXP_Format_ID()); + formatLine.setValue(formatlinevalue); + formatLine.setName(col.getName()); + formatLine.setDescription(col.getDescription()); + formatLine.setHelp(col.getHelp()); + formatLine.setPosition(position); + formatLine.setIsMandatory(col.isMandatory()); + if(force + || (col.isIdentifier() + && !col.isKey())) { - format_line.setIsPartUniqueIndex(true); - format_line.setIsActive(true); + formatLine.setIsPartUniqueIndex(true); + formatLine.setIsActive(true); } else - format_line.setIsActive(false); + { + formatLine.setIsActive(false); + } + MTable tabledir = null; - if(col.getColumnName().equals(m_parent_table+"_ID")&(col.getAD_Reference_ID()==DisplayType.Search|col.getAD_Reference_ID()==DisplayType.TableDir)) + if(col.getColumnName().equals(m_parent_table+"_ID") + && DisplayType.isID(col.getAD_Reference_ID())) { MEXPFormat referenceFormat = null; - referenceFormat = MEXPFormat.getFormatByValueAD_Client_IDAndVersion(getCtx(), m_parent_table+"_Key", getAD_Client_ID(), "1", get_TrxName()); + referenceFormat = MEXPFormat.getFormatByValueAD_Client_IDAndVersion(getCtx(), m_parent_table+"_Key", getAD_Client_ID(), version, get_TrxName()); + if(referenceFormat == null) + { referenceFormat = new MEXPFormat(getCtx(), 0 , get_TrxName()); + } + + referenceFormat.setAD_Org_ID(0); referenceFormat.setValue(m_parent_table+"_Key"); referenceFormat.setName(m_parent_table+"_Key"); - referenceFormat.setAD_Table_ID(table.getAD_Table_ID()); + referenceFormat.setAD_Table_ID(MTable.getTable_ID(m_parent_table)); referenceFormat.setDescription(table.getDescription()); referenceFormat.setHelp(table.getHelp()); - referenceFormat.setVersion("1"); - referenceFormat.save(); + referenceFormat.setVersion(version); + referenceFormat.saveEx(); int AD_Column_ID=DB.getSQLValue(get_TrxName(), "SELECT AD_Column_ID FROM AD_Column WHERE AD_Table_ID=(SELECT AD_Table_ID FROM AD_Table WHERE TableName=?) AND UPPER(ColumnName)='DOCUMENTNO'",m_parent_table); if(AD_Column_ID>0) @@ -229,57 +247,86 @@ public class ExportFormatGenerator extends SvrProcess AD_Column_ID=DB.getSQLValue(get_TrxName(), "SELECT AD_Column_ID FROM AD_Column WHERE AD_Table_ID=(SELECT AD_Table_ID FROM AD_Table WHERE TableName=?) AND UPPER(ColumnName)='C_DOCTYPE_ID'",m_parent_table); if(AD_Column_ID>0) createFormatLine(referenceFormat, table, new MColumn(getCtx(),AD_Column_ID,get_TrxName()), 20,true); + formatLine.setValue(m_parent_table+"_Key"); + formatLine.setName("Key DocumentNo_C_DocType"); + formatLine.setAD_Column_ID(col.getAD_Column_ID()); + formatLine.setType(MEXPFormatLine.TYPE_ReferencedEXPFormat); + formatLine.setEXP_EmbeddedFormat_ID(referenceFormat.getEXP_Format_ID()); + formatLine.saveEx(); - format_line.setValue(m_parent_table+"_DocumentNo_C_DocType_Key"); - format_line.setName("Key DocumentNo_C_DocType"); - format_line.setAD_Column_ID(col.getAD_Column_ID()); - format_line.setType(MEXPFormatLine.TYPE_ReferencedEXPFormat); - format_line.setEXP_EmbeddedFormat_ID(referenceFormat.getEXP_Format_ID()); - format_line.save(); - return format_line.getEXP_FormatLine_ID(); - }else + if(m_parent_table != null) + { + if (col.isParent() && col.getColumnName().contains(m_parent_table)) + { + + int reference = ((MEXPFormat)m_formats.get(m_format_value)).getEXP_Format_ID(); + MEXPFormatLine embededformatLine = new MEXPFormatLine(getCtx(), 0 , get_TrxName()); + embededformatLine.setAD_Org_ID(0); + embededformatLine.setValue(format.getValue()+"_Embedded"); + embededformatLine.setName("Embedded "+ format.getName()); + embededformatLine.setEXP_EmbeddedFormat_ID(formatLine.getEXP_Format_ID()); + embededformatLine.setEXP_Format_ID(reference); + embededformatLine.setType(MEXPFormatLine.TYPE_EmbeddedEXPFormat); + embededformatLine.setAD_Column_ID(col.getAD_Column_ID()); + embededformatLine.saveEx(); + } + } + log.info("Export Format Line:"+formatLine.getName()); + return formatLine.getEXP_FormatLine_ID(); + } + else { AD_Column_ID=DB.getSQLValue(get_TrxName(), "SELECT AD_Column_ID FROM AD_Column WHERE AD_Table_ID=(SELECT AD_Table_ID FROM AD_Table WHERE TableName=?) AND UPPER(ColumnName)='NAME'",m_parent_table); if(AD_Column_ID>0) + { createFormatLine(referenceFormat, table, new MColumn(getCtx(),AD_Column_ID,get_TrxName()), 10,true); + } else { AD_Column_ID=DB.getSQLValue(get_TrxName(), "SELECT AD_Column_ID FROM AD_Column WHERE AD_Table_ID=(SELECT AD_Table_ID FROM AD_Table WHERE TableName=?) AND UPPER(ColumnName)='VALUE'",m_parent_table); if(AD_Column_ID>0) + { createFormatLine(referenceFormat, table, new MColumn(getCtx(),AD_Column_ID,get_TrxName()), 10,true); + } else - throw new Exception("Table without name or value column"); + { + throw new AdempiereException("Table without name or value column"); + } } - format_line.setValue(m_parent_table+"_Key"); - format_line.setName("Key "+ col.getColumnName()); - format_line.setAD_Column_ID(col.getAD_Column_ID()); - format_line.setType(MEXPFormatLine.TYPE_ReferencedEXPFormat); - format_line.setEXP_EmbeddedFormat_ID(referenceFormat.getEXP_Format_ID()); - format_line.save(); - return format_line.getEXP_FormatLine_ID(); + formatLine.setValue(m_parent_table+"_Key"); + formatLine.setName("Key "+ col.getColumnName()); + formatLine.setAD_Column_ID(col.getAD_Column_ID()); + formatLine.setType(MEXPFormatLine.TYPE_ReferencedEXPFormat); + formatLine.setEXP_EmbeddedFormat_ID(referenceFormat.getEXP_Format_ID()); + formatLine.saveEx(); + return formatLine.getEXP_FormatLine_ID(); } } - if((col.getAD_Reference_ID()==DisplayType.Table||col.getAD_Reference_ID()==DisplayType.Search)&col.getAD_Reference_Value_ID()>0) + if(DisplayType.isID(col.getAD_Reference_ID()) && col.getAD_Reference_Value_ID()>0) { int AD_Table_ID = DB.getSQLValue(get_TrxName(), "SELECT rt.AD_Table_ID FROM AD_Reference r INNER JOIN AD_Ref_Table rt ON (r.AD_Reference_ID=rt.AD_Reference_ID) WHERE r.AD_Reference_ID=?", col.getAD_Reference_Value_ID()); if (AD_Table_ID > 0) { tabledir = MTable.get(getCtx(), AD_Table_ID); - format_line.setValue(col.getColumnName()+"_Reference"); - format_line.setName("Referenced "+ tabledir.getTableName()); - format_line.setAD_Column_ID(col.getAD_Column_ID()); + formatLine.setValue(col.getColumnName()+"_Reference"); + formatLine.setName("Referenced "+ tabledir.getTableName()); + formatLine.setAD_Column_ID(col.getAD_Column_ID()); String format_value = createFormat(tabledir); int embedded = ((MEXPFormat)m_formats.get(format_value)).getEXP_Format_ID(); - format_line.setType(MEXPFormatLine.TYPE_ReferencedEXPFormat); - format_line.setEXP_EmbeddedFormat_ID(embedded); - format_line.save(); - return format_line.getEXP_FormatLine_ID(); + formatLine.setType(MEXPFormatLine.TYPE_ReferencedEXPFormat); + formatLine.setEXP_EmbeddedFormat_ID(embedded); + formatLine.saveEx(); + return formatLine.getEXP_FormatLine_ID(); } } - - if((col.getAD_Reference_ID()==DisplayType.TableDir & col.isKey()== false) || (col.getAD_Reference_ID()==DisplayType.TableDir & col.isParent() == true)) + if(DisplayType.isID(col.getAD_Reference_ID()) + && col.isKey() == false + && DisplayType.ID + != col.getAD_Reference_ID() + && DisplayType.Image + != col.getAD_Reference_ID()) { String tableName = col.getColumnName().substring(0, col.getColumnName().lastIndexOf("_ID")); @@ -292,42 +339,51 @@ public class ExportFormatGenerator extends SvrProcess if(tabledir==null) throw new Exception ("Ilegal Table Name"); - format_line.setValue(tabledir.getTableName()+"_Reference"); - format_line.setName("Referenced "+ tabledir.getTableName()); + formatLine.setValue(tabledir.getTableName()+"_Reference"); + formatLine.setName("Referenced "+ tabledir.getTableName()); + //formatLine.setType(MEXPFormatLine.TYPE_XMLElement); if (tabledir!=null) - { - if(m_parent_table != null) - { - if (col.isParent() && col.getColumnName().contains(m_parent_table)) - { - - int embedded = ((MEXPFormat)m_formats.get(m_format_value)).getEXP_Format_ID(); - format_line.setValue(format.getValue()+"_Embedded"); - format_line.setName("Embedded "+ format.getName()); - format_line.setEXP_EmbeddedFormat_ID(format_line.getEXP_Format_ID()); - format_line.setEXP_Format_ID(embedded); - format_line.setType(MEXPFormatLine.TYPE_EmbeddedEXPFormat); - format_line.setAD_Column_ID(col.getAD_Column_ID()); - format_line.save(); - log.info("Export Format Line:"+format_line.getName()); - return format_line.getEXP_FormatLine_ID(); - - } - } - String format_value = createFormat(tabledir); - int embedded = ((MEXPFormat)m_formats.get(format_value)).getEXP_Format_ID(); - format_line.setType(MEXPFormatLine.TYPE_ReferencedEXPFormat); - format_line.setEXP_EmbeddedFormat_ID(embedded); + { + String format_value = createFormat(tabledir); + int embedded = ((MEXPFormat)m_formats.get(format_value)).getEXP_Format_ID(); + formatLine.setType(MEXPFormatLine.TYPE_ReferencedEXPFormat); + formatLine.setEXP_EmbeddedFormat_ID(embedded); } else - format_line.setType(MEXPFormatLine.TYPE_XMLElement); + formatLine.setType(MEXPFormatLine.TYPE_XMLElement); } - - format_line.setAD_Column_ID(col.getAD_Column_ID()); - format_line.save(); - log.info("Export Format Line:"+format_line.getName()); - return format_line.getEXP_FormatLine_ID(); - + formatLine.setAD_Column_ID(col.getAD_Column_ID()); + formatLine.saveEx(); + log.info("Export Format Line:"+formatLine.getName()); + return formatLine.getEXP_FormatLine_ID(); } + private void createEmbededFormat(MTable table, MColumn col,boolean force) throws Exception + { + if(col.isParent() && getTab().getTabLevel() > 0) + { + String tableName = col.getColumnName().substring(0, col.getColumnName().lastIndexOf("_ID")); + + MEXPFormat format = MEXPFormat.getFormatByValueAD_Client_IDAndVersion(getCtx(), tableName, getAD_Client_ID(), version, get_TrxName()); + if (format != null) + { + createFormatLine(format, MTable.get(col.getCtx(), tableName), col, 0 , force); + return; + } + } + } + + private MTab getTab() + { + return currentTab; + } + + private MWindow getWindow() + { + return window; + } + private void setTab(MTab tab) + { + currentTab = tab; + } } // Generate Export Format diff --git a/migration/354a-trunk/oracle/622_BF2910176TestExportModel.sql b/migration/354a-trunk/oracle/622_BF2910176TestExportModel.sql new file mode 100644 index 0000000000..3a7deeada7 --- /dev/null +++ b/migration/354a-trunk/oracle/622_BF2910176TestExportModel.sql @@ -0,0 +1,60 @@ +-- Dec 1, 2009 10:41:32 PM CST +-- Replication Stabilization +UPDATE AD_Process SET IsActive='Y', IsBetaFunctionality='N',Updated=TO_DATE('2009-12-01 22:41:32','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_ID=53085 +; + +-- Dec 1, 2009 10:41:33 PM CST +-- Replication Stabilization +UPDATE AD_Menu SET Description='Create multiple Export Format based in a Window', IsActive='Y', Name='Export Format Generator',Updated=TO_DATE('2009-12-01 22:41:33','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Menu_ID=53125 +; + +-- Dec 1, 2009 10:42:43 PM CST +-- Replication Stabilization +UPDATE AD_Menu SET IsActive='Y',Updated=TO_DATE('2009-12-01 22:42:43','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Menu_ID=53130 +; + +-- Dec 1, 2009 10:43:39 PM CST +-- Replication Stabilization +UPDATE AD_Process SET IsActive='Y',Updated=TO_DATE('2009-12-01 22:43:39','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_ID=53089 +; + +-- Dec 1, 2009 10:44:32 PM CST +-- Replication Stabilization +UPDATE AD_Process SET Classname='org.adempiere.process.rpl.imp.ModelImporter',Updated=TO_DATE('2009-12-01 22:44:32','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_ID=53074 +; + +-- Dec 1, 2009 10:44:50 PM CST +-- Replication Stabilization +UPDATE AD_Window SET IsBetaFunctionality='N',Updated=TO_DATE('2009-12-01 22:44:50','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Window_ID=53025 +; + +-- Dec 1, 2009 10:44:58 PM CST +-- Replication Stabilization +UPDATE AD_Window SET IsSOTrx='N',Updated=TO_DATE('2009-12-01 22:44:58','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Window_ID=53025 +; + +-- Dec 1, 2009 10:45:26 PM CST +-- Replication Stabilization +UPDATE AD_Field SET IsActive='Y',Updated=TO_DATE('2009-12-01 22:45:26','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Field_ID=55417 +; + +-- Dec 1, 2009 10:58:44 PM CST +-- Replication Stabilization +UPDATE AD_Field SET SeqNo=120,IsDisplayed='Y' WHERE AD_Field_ID=55417 +; + +-- Dec 1, 2009 10:58:44 PM CST +-- Replication Stabilization +UPDATE AD_Field SET SeqNo=130,IsDisplayed='Y' WHERE AD_Field_ID=54570 +; + +-- Dec 1, 2009 10:58:51 PM CST +-- Replication Stabilization +UPDATE AD_Field SET Included_Tab_ID=53086,Updated=TO_DATE('2009-12-01 22:58:51','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Field_ID=54570 +; + +-- Dec 1, 2009 10:59:21 PM CST +-- Replication Stabilization +UPDATE AD_Tab SET IsSingleRow='N',Updated=TO_DATE('2009-12-01 22:59:21','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Tab_ID=53086 +; + diff --git a/migration/354a-trunk/postgresql/622_BF2910176TestExportModel.sql b/migration/354a-trunk/postgresql/622_BF2910176TestExportModel.sql new file mode 100644 index 0000000000..bcfada4539 --- /dev/null +++ b/migration/354a-trunk/postgresql/622_BF2910176TestExportModel.sql @@ -0,0 +1,60 @@ +-- Dec 1, 2009 10:41:32 PM CST +-- Replication Stabilization +UPDATE AD_Process SET IsActive='Y', IsBetaFunctionality='N',Updated=TO_TIMESTAMP('2009-12-01 22:41:32','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_ID=53085 +; + +-- Dec 1, 2009 10:41:33 PM CST +-- Replication Stabilization +UPDATE AD_Menu SET Description='Create multiple Export Format based in a Window', IsActive='Y', Name='Export Format Generator',Updated=TO_TIMESTAMP('2009-12-01 22:41:33','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Menu_ID=53125 +; + +-- Dec 1, 2009 10:42:43 PM CST +-- Replication Stabilization +UPDATE AD_Menu SET IsActive='Y',Updated=TO_TIMESTAMP('2009-12-01 22:42:43','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Menu_ID=53130 +; + +-- Dec 1, 2009 10:43:39 PM CST +-- Replication Stabilization +UPDATE AD_Process SET IsActive='Y',Updated=TO_TIMESTAMP('2009-12-01 22:43:39','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_ID=53089 +; + +-- Dec 1, 2009 10:44:32 PM CST +-- Replication Stabilization +UPDATE AD_Process SET Classname='org.adempiere.process.rpl.imp.ModelImporter',Updated=TO_TIMESTAMP('2009-12-01 22:44:32','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_ID=53074 +; + +-- Dec 1, 2009 10:44:50 PM CST +-- Replication Stabilization +UPDATE AD_Window SET IsBetaFunctionality='N',Updated=TO_TIMESTAMP('2009-12-01 22:44:50','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Window_ID=53025 +; + +-- Dec 1, 2009 10:44:58 PM CST +-- Replication Stabilization +UPDATE AD_Window SET IsSOTrx='N',Updated=TO_TIMESTAMP('2009-12-01 22:44:58','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Window_ID=53025 +; + +-- Dec 1, 2009 10:45:26 PM CST +-- Replication Stabilization +UPDATE AD_Field SET IsActive='Y',Updated=TO_TIMESTAMP('2009-12-01 22:45:26','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Field_ID=55417 +; + +-- Dec 1, 2009 10:58:44 PM CST +-- Replication Stabilization +UPDATE AD_Field SET SeqNo=120,IsDisplayed='Y' WHERE AD_Field_ID=55417 +; + +-- Dec 1, 2009 10:58:44 PM CST +-- Replication Stabilization +UPDATE AD_Field SET SeqNo=130,IsDisplayed='Y' WHERE AD_Field_ID=54570 +; + +-- Dec 1, 2009 10:58:51 PM CST +-- Replication Stabilization +UPDATE AD_Field SET Included_Tab_ID=53086,Updated=TO_TIMESTAMP('2009-12-01 22:58:51','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Field_ID=54570 +; + +-- Dec 1, 2009 10:59:21 PM CST +-- Replication Stabilization +UPDATE AD_Tab SET IsSingleRow='N',Updated=TO_TIMESTAMP('2009-12-01 22:59:21','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Tab_ID=53086 +; + diff --git a/serverRoot/src/main/server/org/adempiere/server/rpl/imp/FileImportProcessor.java b/serverRoot/src/main/server/org/adempiere/server/rpl/imp/FileImportProcessor.java index a3184b6f6e..ca9b5bfdf8 100644 --- a/serverRoot/src/main/server/org/adempiere/server/rpl/imp/FileImportProcessor.java +++ b/serverRoot/src/main/server/org/adempiere/server/rpl/imp/FileImportProcessor.java @@ -30,8 +30,9 @@ package org.adempiere.server.rpl.imp; import java.util.Properties; +import org.adempiere.process.rpl.imp.ImportHelper; +import org.adempiere.process.rpl.XMLHelper; import org.adempiere.server.rpl.IImportProcessor; -import org.adempiere.server.rpl.XMLHelper; import org.compiere.model.MIMPProcessor; import org.compiere.model.X_IMP_ProcessorParameter; import org.compiere.server.ReplicationProcessor; diff --git a/serverRoot/src/main/server/org/adempiere/server/rpl/imp/TopicListener.java b/serverRoot/src/main/server/org/adempiere/server/rpl/imp/TopicListener.java index e4d006153a..dbf1e8d703 100644 --- a/serverRoot/src/main/server/org/adempiere/server/rpl/imp/TopicListener.java +++ b/serverRoot/src/main/server/org/adempiere/server/rpl/imp/TopicListener.java @@ -41,7 +41,8 @@ import javax.jms.Session; import javax.jms.TextMessage; import javax.jms.Topic; -import org.adempiere.server.rpl.XMLHelper; +import org.adempiere.process.rpl.imp.ImportHelper; +import org.adempiere.process.rpl.XMLHelper; import org.apache.activemq.ActiveMQConnectionFactory; import org.compiere.server.ReplicationProcessor; import org.compiere.util.CLogger;