diff --git a/base/src/org/adempiere/pipo/AbstractElementHandler.java b/base/src/org/adempiere/pipo/AbstractElementHandler.java index 057d593a89..e24fadb22d 100644 --- a/base/src/org/adempiere/pipo/AbstractElementHandler.java +++ b/base/src/org/adempiere/pipo/AbstractElementHandler.java @@ -1,452 +1,456 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 Adempiere, Inc. All Rights Reserved. * - * 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.pipo; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Properties; -import java.util.logging.Level; - -import javax.xml.transform.sax.TransformerHandler; - -import org.compiere.model.PO; -import org.compiere.model.POInfo; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.AttributesImpl; - -public abstract class AbstractElementHandler implements ElementHandler { - - protected CLogger log = CLogger.getCLogger("PackIn"); - - /** - * Get ID from Name for a table. - * TODO: substitute with PO.getAllIDs - * - * @param tableName - * @param name - * - */ - public int get_ID (Properties ctx, String tableName, String name) { - return IDFinder.get_ID(tableName, name, getClientId(ctx), getTrxName(ctx)); - } - - /** - * Get ID from column value for a table. - * - * @param tableName - * @param columName - * @param name - */ - public int get_IDWithColumn (Properties ctx, String tableName, String columnName, Object value) { - return IDFinder.get_IDWithColumn(tableName, columnName, value, getClientId(ctx), getTrxName(ctx)); - } - - /** - * Write results to log and records in history table - * - * @param success - * @param tableName - * @param objectType - * @param objectID - * @param objectStatus - * @throws SAXException - * - */ - public int record_log (Properties ctx, int success, String objectName,String objectType, int objectID, - int objectIDBackup, String objectStatus, String tableName, int AD_Table_ID) throws SAXException{ - StringBuffer recordLayout = new StringBuffer(); - int id = 0; - TransformerHandler hd_document = getLogDocument(ctx); - AttributesImpl attsOut = new AttributesImpl(); - if (success == 1){ - //hd_documemt.startElement("","","Successfull",attsOut); - recordLayout.append("Type:") - .append(objectType) - .append(" - Name:") - .append(objectName) - .append(" - ID:") - .append(objectID) - .append(" - Action:") - .append(objectStatus) - .append(" - Success"); - - hd_document.startElement("","","Success",attsOut); - hd_document.characters(recordLayout.toString().toCharArray(),0,recordLayout.length()); - hd_document.endElement("","","Success"); - //hd_documemt.endElement("","","Successfull"); - - //String sql2 = "SELECT MAX(AD_PACKAGE_IMP_DETAIL_ID) FROM AD_PACKAGE_IMP_DETAIL"; - //int id = DB.getSQLValue(m_trxName, sql2)+1; - - id = DB.getNextID (Env.getAD_Client_ID(ctx), "AD_Package_Imp_Detail", getTrxName(ctx)); - - StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Detail") - .append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " ) - .append( "AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID, TYPE, NAME," ) - .append( " ACTION, SUCCESS, AD_ORIGINAL_ID, AD_BACKUP_ID, TABLENAME, AD_TABLE_ID)" ) - .append( "VALUES(" ) - .append( " "+ Env.getAD_Client_ID(ctx) ) - .append( ", "+ Env.getAD_Org_ID(ctx) ) - .append( ", "+ Env.getAD_User_ID(ctx) ) - .append( ", "+ Env.getAD_User_ID(ctx) ) - .append( ", " + id ) - .append( ", " + getPackageImpId(ctx) ) - .append( ", '" + objectType ) - .append( "', '" + objectName ) - .append( "', '" + objectStatus ) - .append( "', 'Success'" ) - .append( ", "+objectID ) - .append( ", "+objectIDBackup ) - .append( ", '"+tableName ) - .append( "', "+AD_Table_ID ) - .append(")"); - int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); - if (no == -1) - log.info("Insert to import detail failed"); - - } - else{ - String PK_Status = "Completed with errors"; - hd_document.startElement("","","Failure",attsOut); - recordLayout.append("Type:") - .append(objectType) - .append(" - Name:") - .append(tableName) - .append(" - ID:") - .append(objectID) - .append(" - Action:") - .append(objectStatus) - .append(" - Failure"); - //hd_documemt.startElement("","","Success",attsOut); - hd_document.characters(recordLayout.toString().toCharArray(),0,recordLayout.length()); - //hd_documemt.endElement("","","Success"); - hd_document.endElement("","","Failure"); - - //String sql2 = "SELECT MAX(AD_PACKAGE_IMP_DETAIL_ID) FROM AD_PACKAGE_IMP_DETAIL"; - //int id = DB.getSQLValue(m_trxName,sql2)+1; - - id = DB.getNextID (Env.getAD_Client_ID(ctx), "AD_Package_Imp_Detail", getTrxName(ctx)); - - StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Detail") - .append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " ) - .append( "AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID, TYPE, NAME," ) - .append( " ACTION, SUCCESS, AD_ORIGINAL_ID, AD_BACKUP_ID, TABLENAME, AD_TABLE_ID)" ) - .append( "VALUES(" ) - .append( " "+ Env.getAD_Client_ID(ctx) ) - .append( ", "+ Env.getAD_Org_ID(ctx) ) - .append( ", "+ Env.getAD_User_ID(ctx) ) - .append( ", "+ Env.getAD_User_ID(ctx) ) - .append( ", " + id ) - .append( ", " + getPackageImpId(ctx) ) - .append( ", '" + objectType ) - .append( "', '" + objectName ) - .append( "', '" + objectStatus ) - .append( "', 'Failure'" ) - .append( ", "+objectID ) - .append( ", "+objectIDBackup ) - .append( ", '"+tableName ) - .append( "', "+AD_Table_ID ) - .append( ")"); - int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); - if (no == -1) - log.info("Insert to import detail failed"); - } - - String Object_Status = "Status not set"; - return id; - } - - /** - * Get ID from Name for a table with a Master reference. - * - * @param tableName - * @param name - * @param tableNameMaster - * @param nameMaster - */ - public int get_IDWithMaster (Properties ctx, String tableName, String name, String tableNameMaster, String nameMaster) { - return IDFinder.get_IDWithMaster(tableName, name, tableNameMaster, nameMaster, getTrxName(ctx)); - } - - /** - * Get ID from Name for a table with a Master reference. - * - * @param tableName - * @param name - * @param tableNameMaster - * @param nameMaster - */ - - public int get_IDWithMasterAndColumn (Properties ctx, String tableName, String columnName, String name, String tableNameMaster, int masterID) { - return IDFinder.get_IDWithMasterAndColumn(tableName, columnName, name, tableNameMaster, masterID, - getTrxName(ctx)); - } - - /** - * Get ID from Name for a table with a Master reference ID. - * - * @param tableName - * @param name - * @param tableNameMaster - * @param masterID - */ - public int get_IDWithMaster (Properties ctx, String tableName, String name, String tableNameMaster, int masterID) { - return IDFinder.get_IDWithMaster(tableName, name, tableNameMaster, masterID, getTrxName(ctx)); - } - - /** - * Get ID from Name for a table. - * TODO: substitute with PO.getAllIDs - * - * @param tableName - * @param name - */ - public int getIDbyName (Properties ctx, String tableName, String name) { - return IDFinder.getIDbyName(tableName, name, getClientId(ctx), getTrxName(ctx)); - } - - /** - * Make backup copy of record. - * - * @param tablename - * - * - * - */ - public int copyRecord(Properties ctx, String tableName,PO from){ - // Create new record - int idBackup = 0; - String colValue=null; - int tableID = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName); - POInfo poInfo = POInfo.getPOInfo(ctx, tableID, getTrxName(ctx)); - for (int i = 0; i < poInfo.getColumnCount(); i++){ - String colName = poInfo.getColumnName(i); - colValue=null; - - int columnID =get_IDWithMasterAndColumn (ctx, "AD_Column", "ColumnName", poInfo.getColumnName(i), "AD_Table", tableID); - StringBuffer sqlD = new StringBuffer("SELECT AD_Reference_ID FROM AD_COLUMN WHERE AD_Column_ID = '"+columnID+"'"); - int referenceID = DB.getSQLValue(getTrxName(ctx),sqlD.toString()); - - idBackup = DB.getNextID (getClientId(ctx), "AD_Package_Imp_Backup", getTrxName(ctx)); - - sqlD = new StringBuffer("SELECT MAX(AD_PACKAGE_IMP_DETAIL_ID) FROM AD_PACKAGE_IMP_DETAIL"); - int idDetail = DB.getSQLValue(getTrxName(ctx),sqlD.toString())+1; - - if (referenceID == 10 || referenceID == 14 || referenceID == 34 || referenceID == 17) - if (from.get_Value(i)!= null) - colValue = from.get_Value(i).toString().replaceAll("'","''"); - else if (referenceID == 20|| referenceID == 28) - if (from.get_Value(i)!= null) - colValue = from.get_Value(i).toString().replaceAll("'","''"); - else - ;//Ignore - - StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Backup") - .append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " ) - .append( "AD_PACKAGE_IMP_BACKUP_ID, AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID," ) - .append( " AD_TABLE_ID, AD_COLUMN_ID, AD_REFERENCE_ID, COLVALUE)" ) - .append( "VALUES(" ) - .append( " "+ Env.getAD_Client_ID(ctx) ) - .append( ", "+ Env.getAD_Org_ID(ctx) ) - .append( ", "+ Env.getAD_User_ID(ctx) ) - .append( ", "+ Env.getAD_User_ID(ctx) ) - .append( ", " + idBackup ) - .append( ", " + idDetail ) - .append( ", " + getPackageImpId(ctx) ) - .append( ", " + tableID ) - .append( ", " + (columnID == -1 ? "null" : columnID) ) - .append( ", " + (referenceID == -1 ? "null" : referenceID) ) - .append( ", '" + (colValue != null ? colValue : from.get_Value(i)) ) - .append( "')"); - - int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); - if (no == -1) - log.info("Insert to import backup failed"); - //} - } - return idBackup; - } - - /** - * Open input file for processing - * - * @param String file with path - * - */ - public FileInputStream OpenInputfile (String filePath) { - - FileInputStream fileTarget = null; - - try { - fileTarget = new FileInputStream(filePath); - } - catch (FileNotFoundException e ) { - System.out.println("File not found: " + filePath); - - return null; - } - return fileTarget; - } - - /** - * Open output file for processing - * - * @param String file with path - * - */ - public OutputStream OpenOutputfile (String filePath) { - - OutputStream fileTarget = null; - - try { - fileTarget = new FileOutputStream(filePath); - } - catch (FileNotFoundException e ) { - System.out.println("File not found: " + filePath); - - return null; - } - return fileTarget; - } - - /** - * Copyfile - * - * @param String file with path - * - */ - public int copyFile (InputStream source,OutputStream target) { - - int byteCount = 0; - int success = 0; - try { - while (true) { - int data = source.read(); - if (data < 0) - break; - target.write(data); - byteCount++; - } - source.close(); - target.close(); - //System.out.println("Successfully copied " + byteCount + " bytes."); - } - catch (Exception e) { - System.out.println("Error occurred while copying. "+ byteCount + " bytes copied."); - log.log(Level.SEVERE, e.getLocalizedMessage(), e); - - success = -1; - } - return success; - } - - /** - * Get client id - * @param ctx - * @return int - */ - protected int getClientId(Properties ctx) { - return Env.getContextAsInt(ctx, "AD_Client_ID"); - } - - /** - * Get AD_Package_Imp_ID - * @param ctx - * @return int - */ - protected int getPackageImpId(Properties ctx) { - return Env.getContextAsInt(ctx, "AD_Package_Imp_ID"); - } - - /** - * Get update system maintained dictionary flag - * @param ctx - * @return update mode - */ - protected String getUpdateMode(Properties ctx) { - return Env.getContext(ctx, "UpdateMode"); - } - - /** - * Get current transaction name - * @param ctx - * @return transaction name - */ - protected String getTrxName(Properties ctx) { - return Env.getContext(ctx, "TrxName"); - } - - /** - * Get share document - * @param ctx - * @return TransformerHandler - */ - protected TransformerHandler getLogDocument(Properties ctx) { - return (TransformerHandler)ctx.get("LogDocument"); - } - - /** - * @param ctx - * @return package directory - */ - protected String getPackageDirectory(Properties ctx) { - return Env.getContext(ctx, "PackageDirectory"); - } - - /** - * Process element by entity type and user setting. - * @param ctx - * @param entityType - * @return boolean - */ - protected boolean isProcessElement(Properties ctx, String entityType) { - if ("D".equals(entityType) || "C".equals(entityType)) { - return "true".equalsIgnoreCase(getUpdateMode(ctx)); - } else { - return true; - } - } - - /** - * return null for empty string (""). - * @param atts - * @param qName - * @return string value - */ - protected String getStringValue(Attributes atts, String qName) { - String s = atts.getValue(qName); - return ("".equals(s) ? null : s); - } - - /** - * Returns option - Is export-import of AD translations is needed - * @param ctx - * @param entityType - * @return boolean - */ - protected boolean isHandleTranslations(Properties ctx) { - - return "true".equalsIgnoreCase(Env.getContext(ctx, "isHandleTranslations")); - } -} +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * Copyright (C) 1999-2006 Adempiere, Inc. All Rights Reserved. * + * 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.pipo; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Properties; +import java.util.logging.Level; + +import javax.xml.transform.sax.TransformerHandler; + +import org.compiere.model.PO; +import org.compiere.model.POInfo; +import org.compiere.util.CLogger; +import org.compiere.util.DB; +import org.compiere.util.Env; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +public abstract class AbstractElementHandler implements ElementHandler { + + protected CLogger log = CLogger.getCLogger("PackIn"); + + /** + * Get ID from Name for a table. + * TODO: substitute with PO.getAllIDs + * + * @param tableName + * @param name + * + */ + public int get_ID (Properties ctx, String tableName, String name) { + return IDFinder.get_ID(tableName, name, getClientId(ctx), getTrxName(ctx)); + } + + /** + * Get ID from column value for a table. + * + * @param tableName + * @param columName + * @param name + */ + public int get_IDWithColumn (Properties ctx, String tableName, String columnName, Object value) { + return IDFinder.get_IDWithColumn(tableName, columnName, value, getClientId(ctx), getTrxName(ctx)); + } + + /** + * Write results to log and records in history table + * + * @param success + * @param tableName + * @param objectType + * @param objectID + * @param objectStatus + * @throws SAXException + * + */ + public int record_log (Properties ctx, int success, String objectName,String objectType, int objectID, + int objectIDBackup, String objectStatus, String tableName, int AD_Table_ID) throws SAXException{ + StringBuffer recordLayout = new StringBuffer(); + int id = 0; + TransformerHandler hd_document = getLogDocument(ctx); + AttributesImpl attsOut = new AttributesImpl(); + if (success == 1){ + //hd_documemt.startElement("","","Successfull",attsOut); + recordLayout.append("Type:") + .append(objectType) + .append(" - Name:") + .append(objectName) + .append(" - ID:") + .append(objectID) + .append(" - Action:") + .append(objectStatus) + .append(" - Success"); + + hd_document.startElement("","","Success",attsOut); + hd_document.characters(recordLayout.toString().toCharArray(),0,recordLayout.length()); + hd_document.endElement("","","Success"); + //hd_documemt.endElement("","","Successfull"); + + //String sql2 = "SELECT MAX(AD_PACKAGE_IMP_DETAIL_ID) FROM AD_PACKAGE_IMP_DETAIL"; + //int id = DB.getSQLValue(m_trxName, sql2)+1; + + id = DB.getNextID (Env.getAD_Client_ID(ctx), "AD_Package_Imp_Detail", getTrxName(ctx)); + + StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Detail") + .append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " ) + .append( "AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID, TYPE, NAME," ) + .append( " ACTION, SUCCESS, AD_ORIGINAL_ID, AD_BACKUP_ID, TABLENAME, AD_TABLE_ID)" ) + .append( "VALUES(" ) + .append( " ?") + .append( ", ?" ) + .append( ", ?" ) + .append( ", ?" ) + .append( ", ?" ) + .append( ", ?" ) + .append( ", ?" ) + .append( ", ?" ) + .append( ", ?" ) + .append( ", ?" ) + .append( ", ?" ) + .append( ", ?" ) + .append( ", ?" ) + .append( ", ?") + .append(")"); + Object[] param = new Object[] { Env.getAD_Client_ID(ctx), Env.getAD_Org_ID(ctx), Env.getAD_User_ID(ctx), Env.getAD_User_ID(ctx), + id, getPackageImpId(ctx) , objectType, objectName, objectStatus, "Success", objectID, objectIDBackup, tableName, + AD_Table_ID + }; + int no = DB.executeUpdate (sqlB.toString(), param, true, getTrxName(ctx)); + if (no == -1) + log.info("Insert to import detail failed"); + + } + else{ + String PK_Status = "Completed with errors"; + hd_document.startElement("","","Failure",attsOut); + recordLayout.append("Type:") + .append(objectType) + .append(" - Name:") + .append(tableName) + .append(" - ID:") + .append(objectID) + .append(" - Action:") + .append(objectStatus) + .append(" - Failure"); + //hd_documemt.startElement("","","Success",attsOut); + hd_document.characters(recordLayout.toString().toCharArray(),0,recordLayout.length()); + //hd_documemt.endElement("","","Success"); + hd_document.endElement("","","Failure"); + + //String sql2 = "SELECT MAX(AD_PACKAGE_IMP_DETAIL_ID) FROM AD_PACKAGE_IMP_DETAIL"; + //int id = DB.getSQLValue(m_trxName,sql2)+1; + + id = DB.getNextID (Env.getAD_Client_ID(ctx), "AD_Package_Imp_Detail", getTrxName(ctx)); + + StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Detail") + .append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " ) + .append( "AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID, TYPE, NAME," ) + .append( " ACTION, SUCCESS, AD_ORIGINAL_ID, AD_BACKUP_ID, TABLENAME, AD_TABLE_ID)" ) + .append( "VALUES(" ) + .append( " "+ Env.getAD_Client_ID(ctx) ) + .append( ", "+ Env.getAD_Org_ID(ctx) ) + .append( ", "+ Env.getAD_User_ID(ctx) ) + .append( ", "+ Env.getAD_User_ID(ctx) ) + .append( ", " + id ) + .append( ", " + getPackageImpId(ctx) ) + .append( ", '" + objectType ) + .append( "', '" + objectName ) + .append( "', '" + objectStatus ) + .append( "', 'Failure'" ) + .append( ", "+objectID ) + .append( ", "+objectIDBackup ) + .append( ", '"+tableName ) + .append( "', "+AD_Table_ID ) + .append( ")"); + int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); + if (no == -1) + log.info("Insert to import detail failed"); + } + + String Object_Status = "Status not set"; + return id; + } + + /** + * Get ID from Name for a table with a Master reference. + * + * @param tableName + * @param name + * @param tableNameMaster + * @param nameMaster + */ + public int get_IDWithMaster (Properties ctx, String tableName, String name, String tableNameMaster, String nameMaster) { + return IDFinder.get_IDWithMaster(tableName, name, tableNameMaster, nameMaster, getTrxName(ctx)); + } + + /** + * Get ID from Name for a table with a Master reference. + * + * @param tableName + * @param name + * @param tableNameMaster + * @param nameMaster + */ + + public int get_IDWithMasterAndColumn (Properties ctx, String tableName, String columnName, String name, String tableNameMaster, int masterID) { + return IDFinder.get_IDWithMasterAndColumn(tableName, columnName, name, tableNameMaster, masterID, + getTrxName(ctx)); + } + + /** + * Get ID from Name for a table with a Master reference ID. + * + * @param tableName + * @param name + * @param tableNameMaster + * @param masterID + */ + public int get_IDWithMaster (Properties ctx, String tableName, String name, String tableNameMaster, int masterID) { + return IDFinder.get_IDWithMaster(tableName, name, tableNameMaster, masterID, getTrxName(ctx)); + } + + /** + * Get ID from Name for a table. + * TODO: substitute with PO.getAllIDs + * + * @param tableName + * @param name + */ + public int getIDbyName (Properties ctx, String tableName, String name) { + return IDFinder.getIDbyName(tableName, name, getClientId(ctx), getTrxName(ctx)); + } + + /** + * Make backup copy of record. + * + * @param tablename + * + * + * + */ + public int copyRecord(Properties ctx, String tableName,PO from){ + // Create new record + int idBackup = 0; + String colValue=null; + int tableID = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName); + POInfo poInfo = POInfo.getPOInfo(ctx, tableID, getTrxName(ctx)); + for (int i = 0; i < poInfo.getColumnCount(); i++){ + String colName = poInfo.getColumnName(i); + colValue=null; + + int columnID =get_IDWithMasterAndColumn (ctx, "AD_Column", "ColumnName", poInfo.getColumnName(i), "AD_Table", tableID); + StringBuffer sqlD = new StringBuffer("SELECT AD_Reference_ID FROM AD_COLUMN WHERE AD_Column_ID = '"+columnID+"'"); + int referenceID = DB.getSQLValue(getTrxName(ctx),sqlD.toString()); + + idBackup = DB.getNextID (getClientId(ctx), "AD_Package_Imp_Backup", getTrxName(ctx)); + + sqlD = new StringBuffer("SELECT MAX(AD_PACKAGE_IMP_DETAIL_ID) FROM AD_PACKAGE_IMP_DETAIL"); + int idDetail = DB.getSQLValue(getTrxName(ctx),sqlD.toString())+1; + + if (referenceID == 10 || referenceID == 14 || referenceID == 34 || referenceID == 17) + if (from.get_Value(i)!= null) + colValue = from.get_Value(i).toString().replaceAll("'","''"); + else if (referenceID == 20|| referenceID == 28) + if (from.get_Value(i)!= null) + colValue = from.get_Value(i).toString().replaceAll("'","''"); + else + ;//Ignore + + StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Backup") + .append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " ) + .append( "AD_PACKAGE_IMP_BACKUP_ID, AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID," ) + .append( " AD_TABLE_ID, AD_COLUMN_ID, AD_REFERENCE_ID, COLVALUE)" ) + .append( "VALUES(" ) + .append( " "+ Env.getAD_Client_ID(ctx) ) + .append( ", "+ Env.getAD_Org_ID(ctx) ) + .append( ", "+ Env.getAD_User_ID(ctx) ) + .append( ", "+ Env.getAD_User_ID(ctx) ) + .append( ", " + idBackup ) + .append( ", " + idDetail ) + .append( ", " + getPackageImpId(ctx) ) + .append( ", " + tableID ) + .append( ", " + (columnID == -1 ? "null" : columnID) ) + .append( ", " + (referenceID == -1 ? "null" : referenceID) ) + .append( ", '" + (colValue != null ? colValue : from.get_Value(i)) ) + .append( "')"); + + int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx)); + if (no == -1) + log.info("Insert to import backup failed"); + //} + } + return idBackup; + } + + /** + * Open input file for processing + * + * @param String file with path + * + */ + public FileInputStream OpenInputfile (String filePath) { + + FileInputStream fileTarget = null; + + try { + fileTarget = new FileInputStream(filePath); + } + catch (FileNotFoundException e ) { + System.out.println("File not found: " + filePath); + + return null; + } + return fileTarget; + } + + /** + * Open output file for processing + * + * @param String file with path + * + */ + public OutputStream OpenOutputfile (String filePath) { + + OutputStream fileTarget = null; + + try { + fileTarget = new FileOutputStream(filePath); + } + catch (FileNotFoundException e ) { + System.out.println("File not found: " + filePath); + + return null; + } + return fileTarget; + } + + /** + * Copyfile + * + * @param String file with path + * + */ + public int copyFile (InputStream source,OutputStream target) { + + int byteCount = 0; + int success = 0; + try { + while (true) { + int data = source.read(); + if (data < 0) + break; + target.write(data); + byteCount++; + } + source.close(); + target.close(); + //System.out.println("Successfully copied " + byteCount + " bytes."); + } + catch (Exception e) { + System.out.println("Error occurred while copying. "+ byteCount + " bytes copied."); + log.log(Level.SEVERE, e.getLocalizedMessage(), e); + + success = -1; + } + return success; + } + + /** + * Get client id + * @param ctx + * @return int + */ + protected int getClientId(Properties ctx) { + return Env.getContextAsInt(ctx, "AD_Client_ID"); + } + + /** + * Get AD_Package_Imp_ID + * @param ctx + * @return int + */ + protected int getPackageImpId(Properties ctx) { + return Env.getContextAsInt(ctx, "AD_Package_Imp_ID"); + } + + /** + * Get update system maintained dictionary flag + * @param ctx + * @return update mode + */ + protected String getUpdateMode(Properties ctx) { + return Env.getContext(ctx, "UpdateMode"); + } + + /** + * Get current transaction name + * @param ctx + * @return transaction name + */ + protected String getTrxName(Properties ctx) { + return Env.getContext(ctx, "TrxName"); + } + + /** + * Get share document + * @param ctx + * @return TransformerHandler + */ + protected TransformerHandler getLogDocument(Properties ctx) { + return (TransformerHandler)ctx.get("LogDocument"); + } + + /** + * @param ctx + * @return package directory + */ + protected String getPackageDirectory(Properties ctx) { + return Env.getContext(ctx, "PackageDirectory"); + } + + /** + * Process element by entity type and user setting. + * @param ctx + * @param entityType + * @return boolean + */ + protected boolean isProcessElement(Properties ctx, String entityType) { + if ("D".equals(entityType) || "C".equals(entityType)) { + return "true".equalsIgnoreCase(getUpdateMode(ctx)); + } else { + return true; + } + } + + /** + * return null for empty string (""). + * @param atts + * @param qName + * @return string value + */ + protected String getStringValue(Attributes atts, String qName) { + String s = atts.getValue(qName); + return ("".equals(s) ? null : s); + } + + /** + * Returns option - Is export-import of AD translations is needed + * @param ctx + * @param entityType + * @return boolean + */ + protected boolean isHandleTranslations(Properties ctx) { + + return "true".equalsIgnoreCase(Env.getContext(ctx, "isHandleTranslations")); + } +} diff --git a/base/src/org/adempiere/pipo/PackInHandler.java b/base/src/org/adempiere/pipo/PackInHandler.java index 6b5e707517..dc7cf59577 100644 --- a/base/src/org/adempiere/pipo/PackInHandler.java +++ b/base/src/org/adempiere/pipo/PackInHandler.java @@ -1,850 +1,850 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 Adempiere, Inc. All Rights Reserved. * - * 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) 2004 Marco LOMBARDO. lombardo@mayking.com * - * Contributor: Robert KLEIN. robeklein@hotmail.com * - * Contributor: Tim Heath * - * Contributor: Low Heng Sin hengsin@avantz.com * - *****************************************************************************/ - -package org.adempiere.pipo; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.OutputStream; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -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.pipo.handler.AdElementHandler; -import org.adempiere.pipo.handler.CodeSnipitElementHandler; -import org.adempiere.pipo.handler.ColumnElementHandler; -import org.adempiere.pipo.handler.CommonTranslationHandler; -import org.adempiere.pipo.handler.DataElementHandler; -import org.adempiere.pipo.handler.DistFileElementHandler; -import org.adempiere.pipo.handler.DynValRuleElementHandler; -import org.adempiere.pipo.handler.FieldElementHandler; -import org.adempiere.pipo.handler.FieldGroupElementHandler; -import org.adempiere.pipo.handler.FormAccessElementHandler; -import org.adempiere.pipo.handler.FormElementHandler; -import org.adempiere.pipo.handler.ImpFormatElementHandler; -import org.adempiere.pipo.handler.ImpFormatRowElementHandler; -import org.adempiere.pipo.handler.MenuElementHandler; -import org.adempiere.pipo.handler.MessageElementHandler; -import org.adempiere.pipo.handler.OrgRoleElementHandler; -import org.adempiere.pipo.handler.PreferenceElementHandler; -import org.adempiere.pipo.handler.PrintFormatElementHandler; -import org.adempiere.pipo.handler.PrintFormatItemElementHandler; -import org.adempiere.pipo.handler.ProcessAccessElementHandler; -import org.adempiere.pipo.handler.ProcessElementHandler; -import org.adempiere.pipo.handler.ProcessParaElementHandler; -import org.adempiere.pipo.handler.ReferenceElementHandler; -import org.adempiere.pipo.handler.ReferenceListElementHandler; -import org.adempiere.pipo.handler.ReferenceTableElementHandler; -import org.adempiere.pipo.handler.ReportViewColElementHandler; -import org.adempiere.pipo.handler.ReportViewElementHandler; -import org.adempiere.pipo.handler.RoleElementHandler; -import org.adempiere.pipo.handler.SQLStatementElementHandler; -import org.adempiere.pipo.handler.TabElementHandler; -import org.adempiere.pipo.handler.TableElementHandler; -import org.adempiere.pipo.handler.TaskAccessElementHandler; -import org.adempiere.pipo.handler.TaskElementHandler; -import org.adempiere.pipo.handler.UserRoleElementHandler; -import org.adempiere.pipo.handler.WindowAccessElementHandler; -import org.adempiere.pipo.handler.WindowElementHandler; -import org.adempiere.pipo.handler.WorkflowAccessElementHandler; -import org.adempiere.pipo.handler.WorkflowElementHandler; -import org.adempiere.pipo.handler.WorkflowNodeElementHandler; -import org.adempiere.pipo.handler.WorkflowNodeNextConditionElementHandler; -import org.adempiere.pipo.handler.WorkflowNodeNextElementHandler; -import org.compiere.model.MSequence; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.Trx; -import org.compiere.wf.MWFNode; -import org.compiere.wf.MWorkflow; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.AttributesImpl; -import org.xml.sax.helpers.DefaultHandler; - -/** - * SAX Handler for parsing XML description of the GUI. - * - * @author Marco LOMBARDO, lombardo@mayking.com - * @author Robert KLEIN, robeklein@hotmail - * - * Contributor: William G. Heath - Import of workflows and dynamic validations - */ -public class PackInHandler extends DefaultHandler { - - /** - * PackInHandler Handler - */ - public PackInHandler () { - setupHandlers(); - } // PackInHandler - - /** Set this if you want to update Dictionary */ - private String m_UpdateMode = "true"; - private String packageDirectory = null; - private String m_DatabaseType = "Oracle"; - private int m_AD_Client_ID = 0; - private int AD_Package_Imp_ID=0; - private int AD_Package_Imp_Inst_ID=0; - private CLogger log = CLogger.getCLogger(PackInHandler.class); - private OutputStream fw_document = null; - private TransformerHandler logDocument = null; - private StreamResult streamResult_document = null; - private SAXTransformerFactory tf_document = null; - private Transformer serializer_document = null; - private int Start_Doc = 0; - private String logDate = null; - private String PK_Status = "Installing"; - // transaction name - private String m_trxName = null; - private Properties m_ctx = null; - - private Maphandlers = null; - private List menus = new ArrayList(); - private List workflow = new ArrayList(); - private List nodes = new ArrayList(); - private List defer = new ArrayList(); - private Stack stack = new Stack(); - private PackIn packIn; - - private void init() throws SAXException { - if (packIn == null) - packIn = new PackIn(); - packageDirectory = PackIn.m_Package_Dir; - m_UpdateMode = PackIn.m_UpdateMode; - m_DatabaseType = PackIn.m_Database; - 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 file_document = packageDirectory+File.separator+"doc"+File.separator+"Importlog_"+fileDate+".xml"; - log.info("file_document="+file_document); - try { - fw_document = new FileOutputStream (file_document, false); - } catch (FileNotFoundException e1) { - log.warning ("Failed to create log file:"+e1); - } - streamResult_document = new StreamResult(fw_document); - tf_document = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); - - try { - logDocument = tf_document.newTransformerHandler(); - } catch (TransformerConfigurationException e2) { - log.info ("startElement:"+e2); - } - serializer_document = logDocument.getTransformer(); - serializer_document.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1"); - serializer_document.setOutputProperty(OutputKeys.INDENT,"yes"); - logDocument.setResult(streamResult_document); - 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"); - - m_AD_Client_ID = Env.getContextAsInt(m_ctx, "AD_Client_ID"); - - Start_Doc=1; - } - - private void setupHandlers() { - DataElementHandler dataHandler = new DataElementHandler(); - handlers = new HashMap(); - handlers.put("menu", new MenuElementHandler()); - handlers.put("adempieredata", dataHandler); - handlers.put("data", dataHandler); - handlers.put("dtable", dataHandler); - handlers.put("drow", dataHandler); - handlers.put("dcolumn", dataHandler); - handlers.put("window", new WindowElementHandler()); - handlers.put("windowaccess", new WindowAccessElementHandler()); - handlers.put("preference", new PreferenceElementHandler()); - handlers.put("tab", new TabElementHandler()); - handlers.put("field", new FieldElementHandler()); - handlers.put("process", new ProcessElementHandler()); - handlers.put("processpara", new ProcessParaElementHandler()); - handlers.put("processaccess", new ProcessAccessElementHandler()); - handlers.put("message", new MessageElementHandler()); - handlers.put("dynvalrule", new DynValRuleElementHandler()); - handlers.put("workflow", new WorkflowElementHandler()); - handlers.put("workflowNode", new WorkflowNodeElementHandler()); - handlers.put("workflowNodeNext", new WorkflowNodeNextElementHandler()); - handlers.put("workflowNodeNextCondition", new WorkflowNodeNextConditionElementHandler()); - handlers.put("workflowaccess", new WorkflowAccessElementHandler()); - handlers.put("table", new TableElementHandler()); - handlers.put("column", new ColumnElementHandler()); - handlers.put("role", new RoleElementHandler()); - handlers.put("userrole", new UserRoleElementHandler()); - handlers.put("orgrole", new OrgRoleElementHandler()); - handlers.put("form", new FormElementHandler()); - handlers.put("formaccess", new FormAccessElementHandler()); - handlers.put("task", new TaskElementHandler()); - handlers.put("taskaccess", new TaskAccessElementHandler()); - handlers.put("impformat", new ImpFormatElementHandler()); - handlers.put("impformatrow", new ImpFormatRowElementHandler()); - handlers.put("codesnipit", new CodeSnipitElementHandler()); - handlers.put("distfile", new DistFileElementHandler()); - handlers.put("reportview", new ReportViewElementHandler()); - handlers.put("reportviewcol", new ReportViewColElementHandler()); - handlers.put("printformat", new PrintFormatElementHandler()); - handlers.put("printformatitem", new PrintFormatItemElementHandler()); - handlers.put("SQLStatement", new SQLStatementElementHandler()); - handlers.put("reference", new ReferenceElementHandler()); - handlers.put("referencelist", new ReferenceListElementHandler()); - handlers.put("referencetable", new ReferenceTableElementHandler()); - handlers.put("fieldgroup", new FieldGroupElementHandler()); - handlers.put("element", new AdElementHandler()); - handlers.put("trl", new CommonTranslationHandler()); - } - - /** - * Receive notification of the start of an element. - * - * @param uri namespace - * @param localName simple name - * @param qName qualified name - * @param atts attributes - * @throws org.xml.sax.SAXException - */ - public void startElement (String uri, String localName, String qName, Attributes atts) - throws org.xml.sax.SAXException { - - // Create the package log - if (Start_Doc==0){ - init(); - } - // Check namespace. - String elementValue = null; - if ("".equals (uri)) - elementValue = qName; - else - elementValue = uri + localName; - - // adempiereAD. - if (elementValue.equals("adempiereAD")) { - log.info("adempiereAD updateMode="+m_UpdateMode); - //Start package log - AttributesImpl attsOut = new AttributesImpl(); - logDocument.startElement("","","adempiereDocument",attsOut); - logDocument.startElement("","","header",attsOut); - logDocument.characters((atts.getValue("Name")+" Install Log").toCharArray(),0,(atts.getValue("Name")+" Install Log").length()); - logDocument.endElement("","","header"); - logDocument.startElement("","","H3",attsOut); - logDocument.characters(("Package Name:" ).toCharArray(),0,("Package Name:" ).length()); - logDocument.endElement("","","H3"); - logDocument.startElement("","","packagename4log",attsOut); - logDocument.characters(atts.getValue("Name").toCharArray(),0,atts.getValue("Name").length()); - logDocument.endElement("","","packagename4log"); - logDocument.startElement("","","H3",attsOut); - logDocument.characters(("Version:" ).toCharArray(),0,("Version:" ).length()); - logDocument.endElement("","","H3"); - logDocument.startElement("","","Version",attsOut); - logDocument.characters(atts.getValue("Version").toCharArray(),0,atts.getValue("Version").length()); - logDocument.endElement("","","Version"); - logDocument.startElement("","","H3",attsOut); - logDocument.characters(("Package Install Date:" ).toCharArray(),0,("Package Install Date:" ).length()); - logDocument.endElement("","","H3"); - logDocument.startElement("","","installDate",attsOut); - logDocument.characters(logDate.toCharArray(),0,logDate.length()); - logDocument.endElement("","","installDate"); - logDocument.startElement("","","H3",attsOut); - logDocument.characters(("Min. Compiere Version:" ).toCharArray(),0,("Min. Compiere Version:" ).length()); - logDocument.endElement("","","H3"); - logDocument.startElement("","","CompVer",attsOut); - logDocument.characters(atts.getValue("CompVer").toCharArray(),0,atts.getValue("CompVer").length()); - logDocument.endElement("","","CompVer"); - logDocument.startElement("","","H3",attsOut); - logDocument.characters(("Min. Database Date:" ).toCharArray(),0,("Min. Database Date:" ).length()); - logDocument.endElement("","","H3"); - logDocument.startElement("","","DataBase",attsOut); - logDocument.characters(atts.getValue("DataBase").toCharArray(),0,atts.getValue("DataBase").length()); - logDocument.endElement("","","DataBase"); - - createImp_Sum_table ("AD_Package_Imp_Backup"); - createImp_Sum_table ("AD_Package_Imp"); - createImp_Sum_table ("AD_Package_Imp_Inst"); - createImp_Sum_table ("AD_Package_Imp_Detail"); - - // Update Summary Package History Table - String sql2 = "SELECT AD_PACKAGE_IMP_INST_ID FROM AD_PACKAGE_IMP_INST WHERE NAME =" - + "'" + atts.getValue("Name") - + "' AND PK_VERSION ='" + atts.getValue("Version") + "'"; - int PK_preInstalled = DB.getSQLValue(m_trxName,sql2); - - AD_Package_Imp_ID = DB.getNextID (Env.getAD_Client_ID(m_ctx), "AD_Package_Imp", null); - - StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp") - .append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " ) - .append( "AD_PACKAGE_IMP_ID, RELEASENO, PK_VERSION, VERSION " ) - .append( ", DESCRIPTION, NAME, CREATOR" ) - .append( ", CREATORCONTACT, CREATEDDATE,UPDATEDDATE,PK_STATUS)" ) - .append( "VALUES(" ) - .append( " "+ Env.getAD_Client_ID(m_ctx) ) - .append( ", "+ Env.getAD_Org_ID(m_ctx) ) - .append( ", "+ Env.getAD_User_ID(m_ctx) ) - .append( ", "+ Env.getAD_User_ID(m_ctx) ) - .append( ", " + AD_Package_Imp_ID ) - .append( ", '" + atts.getValue("CompVer") ) - .append( "', '" + atts.getValue("Version") ) - .append( "', '" + atts.getValue("DataBase") ) - .append( "', '" + atts.getValue("Description").replaceAll("'","''")) - .append( "', '" + atts.getValue("Name") ) - .append( "', '" + atts.getValue("creator") ) - .append( "', '" + atts.getValue("creatorcontact") ) - .append( "', '" + atts.getValue("createddate") ) - .append( "', '" + atts.getValue("updateddate") ) - .append( "', '" + PK_Status ) - .append( "')" ); - Env.getAD_User_ID(m_ctx); - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Insert to Package import failed"); - - if ( PK_preInstalled == -1){ - AD_Package_Imp_Inst_ID = DB.getNextID (Env.getAD_Client_ID(m_ctx), "AD_Package_Imp_Inst", null); - - //Insert Package into package install log - sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Inst") - .append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " ) - .append( "AD_PACKAGE_IMP_INST_ID, RELEASENO, PK_VERSION, VERSION " ) - .append( ", DESCRIPTION, NAME, CREATOR" ) - .append( ", CREATORCONTACT, CREATEDDATE,UPDATEDDATE,PK_STATUS)" ) - .append( "VALUES(" ) - .append( " "+ Env.getAD_Client_ID(m_ctx) ) - .append( ", "+ Env.getAD_Org_ID(m_ctx) ) - .append( ", "+ Env.getAD_User_ID(m_ctx) ) - .append( ", "+ Env.getAD_User_ID(m_ctx) ) - .append( ", " + AD_Package_Imp_Inst_ID ) - .append( ", '" + atts.getValue("CompVer") ) - .append( "', '" + atts.getValue("Version") ) - .append( "', '" + atts.getValue("DataBase") ) - .append( "', '" + atts.getValue("Description").replaceAll("'","''")) - .append( "', '" + atts.getValue("Name") ) - .append( "', '" + atts.getValue("creator") ) - .append( "', '" + atts.getValue("creatorcontact") ) - .append( "', '" + atts.getValue("createddate") ) - .append( "', '" + atts.getValue("updateddate") ) - .append( "', '" + PK_Status ) - .append( "')" ); - - Env.getAD_User_ID(m_ctx); - no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Insert to Package List import failed"); - } - else{ - //Update package list with package status - AD_Package_Imp_Inst_ID = PK_preInstalled; - sqlB = new StringBuffer ("UPDATE AD_Package_Imp_Inst " - + "SET PK_Status = '" + PK_Status - + "' WHERE AD_Package_Imp_Inst_ID = "+AD_Package_Imp_Inst_ID); - no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Update to package summary failed"); - } - Env.setContext(m_ctx, "AD_Package_Imp_ID", AD_Package_Imp_ID); - Env.setContext(m_ctx, "UpdateMode", m_UpdateMode); - Env.setContext(m_ctx, "TrxName", m_trxName); - Env.setContext(m_ctx, "PackageDirectory", packageDirectory); - m_ctx.put("LogDocument", logDocument); - m_ctx.put("PackInProcess", packIn); - } - else if (elementValue.equals("menu")) { - //defer - Element e = new Element(uri, localName, qName, new AttributesImpl(atts)); - if (stack.size() > 0) - e.parent = stack.peek(); - stack.push(e); - menus.add(e); - } - else { - Element e = new Element(uri, localName, qName, new AttributesImpl(atts)); - if (stack.size() > 0) - e.parent = stack.peek(); - stack.push(e); - if (elementValue.equals("workflow")) - { - workflow.add(e); - } - - if (elementValue.equals("workflowNode")) - { - nodes.add(e); - } - - - ElementHandler handler = handlers.get(elementValue); - if (handler != null) - handler.startElement(m_ctx, e); - if (e.defer) { - defer.add(new DeferEntry(e, true)); - } - } - } // startElement - - /** - * Check if Package History Table exists in database. If not create - * - * @param tablename - * - */ - public void createImp_Sum_table (String tablename){ - // Check if table exists. - - Connection conn = DB.getConnectionRW(); - DatabaseMetaData dbm; - try { - dbm = conn.getMetaData(); - // check if table is there - ResultSet tables = null; - if (m_DatabaseType.equals("Oracle")) - tables = dbm.getTables(null, null, tablename.toUpperCase(), null ); - else if (m_DatabaseType.equals("PostgreSQL")) - tables = dbm.getTables(null, null, tablename.toLowerCase(), null ); - - if (tables.next()) { - log.info ("Table Found"); - } - else { - if (tablename.equals("AD_Package_Imp")){ - StringBuffer sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( ") - .append( tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " ) - .append( "AD_CLIENT_ID NUMBER(10) NOT NULL, " ) - .append( "AD_ORG_ID NUMBER(10) NOT NULL, " ) - .append( "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " ) - .append( "CREATED DATE DEFAULT SYSDATE NOT NULL, " ) - .append( "CREATEDBY NUMBER(10) NOT NULL, " ) - .append( "UPDATED DATE DEFAULT SYSDATE NOT NULL, " ) - .append( "UPDATEDBY NUMBER(10) NOT NULL, " ) - .append( "NAME NVARCHAR2(60) NOT NULL, " ) - .append( "PK_STATUS NVARCHAR2(22), " ) - .append( "RELEASENO NVARCHAR2(20), " ) - .append( "PK_VERSION NVARCHAR2(20), " ) - .append( "VERSION NVARCHAR2(20), " ) - .append( "DESCRIPTION NVARCHAR2(1000) NOT NULL, " ) - .append( "EMAIL NVARCHAR2(60), " ) - .append( "PROCESSED CHAR(1) DEFAULT 'N', " ) - .append( "PROCESSING CHAR(1) DEFAULT 'N', " ) - .append( "CREATOR VARCHAR2(60 ), " ) - .append( "CREATORCONTACT VARCHAR2(255), " ) - .append( " CREATEDDATE VARCHAR2(25), " ) - .append( "UPDATEDDATE VARCHAR2(25), " ) - .append( "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" ); - - try { - PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(),ResultSet.TYPE_FORWARD_ONLY, - ResultSet.CONCUR_UPDATABLE, null); - pstmt.executeUpdate(); - MSequence.createTableSequence (m_ctx, "AD_Package_Imp", m_trxName); - pstmt.close(); - pstmt = null; - } - catch (Exception e) { - log.info ("createImp_Sum_table:"+e); - } - } - if (tablename.equals("AD_Package_Imp_Inst")){ - StringBuffer sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( ") - .append( tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " ) - .append( "AD_CLIENT_ID NUMBER(10) NOT NULL, " ) - .append( "AD_ORG_ID NUMBER(10) NOT NULL, " ) - .append( "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " ) - .append( "CREATED DATE DEFAULT SYSDATE NOT NULL, " ) - .append( "CREATEDBY NUMBER(10) NOT NULL, " ) - .append( "UPDATED DATE DEFAULT SYSDATE NOT NULL, " ) - .append( "UPDATEDBY NUMBER(10) NOT NULL, " ) - .append( "NAME NVARCHAR2(60) NOT NULL, " ) - .append( "PK_STATUS NVARCHAR2(22), " ) - .append( "RELEASENO NVARCHAR2(20), " ) - .append( "PK_VERSION NVARCHAR2(20), " ) - .append( "VERSION NVARCHAR2(20), " ) - .append( "DESCRIPTION NVARCHAR2(1000) NOT NULL, " ) - .append( "EMAIL NVARCHAR2(60), " ) - .append( "PROCESSED CHAR(1) DEFAULT 'N', " ) - .append( "PROCESSING CHAR(1) DEFAULT 'N', " ) - .append( "CREATOR VARCHAR2(60 ), " ) - .append( "CREATORCONTACT VARCHAR2(255), " ) - .append( " CREATEDDATE VARCHAR2(25), " ) - .append( "UPDATEDDATE VARCHAR2(25), " ) - .append( "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" ); - - try { - PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(),ResultSet.TYPE_FORWARD_ONLY, - ResultSet.CONCUR_UPDATABLE, null); - pstmt.executeUpdate(); - MSequence.createTableSequence (m_ctx, "AD_Package_Imp_Inst", m_trxName); - pstmt.close(); - pstmt = null; - } - catch (Exception e) { - log.info ("createImp_Sum_table:"+e); - } - } - if (tablename.equals("AD_Package_Imp_Detail")){ - StringBuffer sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( ") - .append( tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " ) - .append( "AD_CLIENT_ID NUMBER(10) NOT NULL, " ) - .append( "AD_ORG_ID NUMBER(10) NOT NULL, " ) - .append( "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " ) - .append( "CREATED DATE DEFAULT SYSDATE NOT NULL, " ) - .append( "CREATEDBY NUMBER(10) NOT NULL, " ) - .append( "UPDATED DATE DEFAULT SYSDATE NOT NULL, " ) - .append( "UPDATEDBY NUMBER(10) NOT NULL, " ) - .append( "NAME NVARCHAR2(60), " ) - .append( "AD_PACKAGE_IMP_ID Number(10) NOT NULL, " ) - .append( "AD_ORIGINAL_ID Number(10) NOT NULL, " ) - .append( "AD_BACKUP_ID Number(10), " ) - .append( "ACTION NVARCHAR2(20), " ) - .append( "SUCCESS NVARCHAR2(20), " ) - .append( "TYPE NVARCHAR2(60), " ) - .append( "TABLENAME NVARCHAR2(60), " ) - .append( "AD_TABLE_ID NUMBER(10), " ) - .append( "UNINSTALL CHAR(1), " ) - .append( "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" ); - - try { - PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(),ResultSet.TYPE_FORWARD_ONLY, - ResultSet.CONCUR_UPDATABLE, null); - pstmt.executeUpdate(); - MSequence.createTableSequence (m_ctx, "AD_Package_Imp_Detail", m_trxName); - pstmt.close(); - pstmt = null; - } - catch (Exception e) { - log.info ("createImp_Sum_table:"+e); - } - } - if (tablename.equals("AD_Package_Imp_Backup")){ - StringBuffer sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( ") - .append( tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " ) - .append( "AD_CLIENT_ID NUMBER(10) NOT NULL, " ) - .append( "AD_ORG_ID NUMBER(10) NOT NULL, " ) - .append( "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " ) - .append( "CREATED DATE DEFAULT SYSDATE NOT NULL, " ) - .append( "CREATEDBY NUMBER(10) NOT NULL, " ) - .append( "UPDATED DATE DEFAULT SYSDATE NOT NULL, " ) - .append( "UPDATEDBY NUMBER(10) NOT NULL, " ) - .append( "AD_PACKAGE_IMP_ID Number(10) NOT NULL, " ) - .append( "AD_PACKAGE_IMP_DETAIL_ID Number(10) NOT NULL, " ) - .append( "AD_TABLE_ID NUMBER(10), " ) - .append( "AD_COLUMN_ID NUMBER(10), " ) - .append( "AD_REFERENCE_ID NUMBER(10), " ) - .append( "AD_PACKAGE_IMP_BCK_DIR NVARCHAR2(255), " ) - .append( "AD_PACKAGE_IMP_ORG_DIR NVARCHAR2(255), " ) - .append( "COLVALUE NVARCHAR2(2000), " ) - .append( "UNINSTALL CHAR(1), " ) - .append( "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" ); - - try { - PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(),ResultSet.TYPE_FORWARD_ONLY, - ResultSet.CONCUR_UPDATABLE, null); - pstmt.executeUpdate(); - MSequence.createTableSequence (m_ctx, "AD_Package_Imp_Backup", m_trxName); - pstmt.close(); - pstmt = null; - } - catch (Exception e) { - log.info ("createImp_Sum_table:"+e); - } - } - } - - tables.close(); - } - - catch (SQLException e) { - log.info ("createImp_Sum_table:"+e); - } - - finally - { - if( conn != null ) - { - try - { - conn.close(); - } - catch( Exception e ){} - } - } - } - - /** - * Receive notification of the end of an element. - * @param uri namespace - * @param localName simple name - * @param qName qualified name - * @throws SAXException - */ - public void endElement (String uri, String localName, String qName) throws SAXException { - // Check namespace. - String elementValue = null; - if ("".equals (uri)) - elementValue = qName; - else - elementValue = uri + localName; - - if (elementValue.equals("adempiereAD")){ - processDeferElements(); - processMenuElements(); - if (!PK_Status.equals("Completed with errors")) - PK_Status = "Completed successfully"; - - //Update package history log with package status - StringBuffer sqlB = new StringBuffer ("UPDATE AD_Package_Imp " - + "SET PK_Status = '" + PK_Status - + "' WHERE AD_Package_Imp_ID = " + AD_Package_Imp_ID); - int no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Update to package summary failed"); - - //Update package list with package status - sqlB = new StringBuffer ("UPDATE AD_Package_Imp_Inst " - + "SET PK_Status = '" + PK_Status - + "' WHERE AD_Package_Imp_Inst_ID = " + AD_Package_Imp_Inst_ID); - no = DB.executeUpdate (sqlB.toString(), m_trxName); - if (no == -1) - log.info("Update to package list failed"); - - if(workflow.size() > 0) - { - for (Element e : workflow) - { - Attributes atts = e.attributes; - String workflowName = atts.getValue("Name"); - MWorkflow wf = null; - - int workflow_id = IDFinder.get_IDWithColumn("AD_Workflow", "Name", workflowName ,m_AD_Client_ID , m_trxName); - if(workflow_id > 0) - { - wf = new MWorkflow(m_ctx, workflow_id , m_trxName); - int node_id = 0; - - String name = atts.getValue("ADWorkflowNodeNameID"); - if (name != null && name.trim().length() > 0) - { - MWFNode[] nodes = wf.getNodes(false, m_AD_Client_ID); - - for (MWFNode node : nodes) - { - if (node.getName().trim().equals(name.trim())) - { - node_id = node.getAD_WF_Node_ID(); - wf.setAD_WF_Node_ID(node_id); - if (!wf.save()) - System.out.println("Can not save Start Node "+ name +"to Workflow " + workflowName + " do not exist "); - break; - } - } - - if(node_id == 0) - System.out.println("Unresolved: Start Node to Workflow " + workflowName + " do not exist "); - else - break; - } - - } - } - } - - if(nodes.size() > 0) - { - for (Element e : nodes) - { - Attributes atts = e.attributes; - String nodeName = atts.getValue("Name"); - MWFNode node = null; - int id = IDFinder.get_IDWithColumn("AD_WF_Node", "Name", nodeName , m_AD_Client_ID , m_trxName); - if(id > 0) - { - node = new MWFNode(m_ctx, id , m_trxName); - String workflowNodeName = atts.getValue("WorkflowNameID").trim(); - if (workflowNodeName != null && workflowNodeName.trim().length() > 0) - { - int workflow_id = IDFinder.get_IDWithColumn("AD_Workflow", "Name",workflowNodeName, m_AD_Client_ID, m_trxName); - if (workflow_id > 0) - { - node.setWorkflow_ID(workflow_id); - if(!node.save()) - { - System.out.println("can not save Workflow " + workflowNodeName ); - } - } - else - System.out.println("Unresolved: Workflow " + workflowNodeName + " do not exist "); - } - - } - } - } - - logDocument.endElement("","","adempiereDocument"); - logDocument.endDocument(); - try { - fw_document.close(); - } - catch (Exception e) - {} - - //reset - setupHandlers(); - } else { - Element e = stack.pop(); - if (e.defer) { - defer.add(new DeferEntry(e, false)); - } else { - ElementHandler handler = handlers.get(elementValue); - if (handler != null) - handler.endElement(m_ctx, e); - if (e.defer || e.deferEnd) - defer.add(new DeferEntry(e, false)); - else if (!e.skip) { - if (log.isLoggable(Level.INFO)) - log.info("Processed: " + e.getElementValue() + " - " + e.attributes.getValue(0)); - } - } - } - - - - } // endElement - - private void processMenuElements() throws SAXException { - ElementHandler handler = handlers.get("menu"); - if (menus.size() > 0 && handler != null) { - for (Element e : menus) { - handler.startElement(m_ctx, e); - handler.endElement(m_ctx, e); - } - } - } - - private void processDeferElements() throws SAXException { - if (defer.isEmpty()) return; - - do { - int startSize = defer.size(); - List tmp = new ArrayList(defer); - defer.clear(); - for (DeferEntry d : tmp) { - if (d.startElement) { - d.element.defer = false; - d.element.unresolved = ""; - d.element.pass++; - } else { - if (d.element.deferEnd) { - d.element.deferEnd = false; - d.element.unresolved = ""; - } - } - if (log.isLoggable(Level.INFO)) { - log.info("Processeing Defer Element: " + d.element.getElementValue() + " - " - + d.element.attributes.getValue(0)); - } - ElementHandler handler = handlers.get(d.element.getElementValue()); - if (handler != null) { - if (d.startElement) - handler.startElement(m_ctx, d.element); - else - handler.endElement(m_ctx, d.element); - } - if (d.element.defer) - defer.add(d); - else if (!d.startElement) { - if (d.element.deferEnd) - defer.add(d); - else { - if (log.isLoggable(Level.INFO)) - log.info("Imported Defer Element: " + d.element.getElementValue() + " - " - + d.element.attributes.getValue(0)); - } - } - } - int endSize = defer.size(); - if (startSize == endSize) break; - } while (defer.size() > 0); - - if (defer.size() > 0) { - int count = 0; - for (DeferEntry d : defer) { - if (!d.startElement) { - count++; - if (log.isLoggable(Level.SEVERE)) - log.severe("Unresolved: " + d.element.getElementValue() + " - " + d.element.attributes.getValue(0) + ", " + d.element.unresolved); - } - } - throw new RuntimeException("Failed to resolve dependency for " + count + " elements."); - //System.err.println("Failed to resolve dependency for " + count + " elements."); - } - } - - // 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) { - m_ctx = ctx; - } - - class DeferEntry { - Element element; - boolean startElement = false; - - DeferEntry(Element e, boolean b) { - element = e; - startElement = b; - } - } - - /** - * @param packIn - */ - public void setProcess(PackIn packIn) { - this.packIn = packIn; - } -} // PackInHandler +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * Copyright (C) 1999-2006 Adempiere, Inc. All Rights Reserved. * + * 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) 2004 Marco LOMBARDO. lombardo@mayking.com * + * Contributor: Robert KLEIN. robeklein@hotmail.com * + * Contributor: Tim Heath * + * Contributor: Low Heng Sin hengsin@avantz.com * + *****************************************************************************/ + +package org.adempiere.pipo; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +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.pipo.handler.AdElementHandler; +import org.adempiere.pipo.handler.CodeSnipitElementHandler; +import org.adempiere.pipo.handler.ColumnElementHandler; +import org.adempiere.pipo.handler.CommonTranslationHandler; +import org.adempiere.pipo.handler.DataElementHandler; +import org.adempiere.pipo.handler.DistFileElementHandler; +import org.adempiere.pipo.handler.DynValRuleElementHandler; +import org.adempiere.pipo.handler.FieldElementHandler; +import org.adempiere.pipo.handler.FieldGroupElementHandler; +import org.adempiere.pipo.handler.FormAccessElementHandler; +import org.adempiere.pipo.handler.FormElementHandler; +import org.adempiere.pipo.handler.ImpFormatElementHandler; +import org.adempiere.pipo.handler.ImpFormatRowElementHandler; +import org.adempiere.pipo.handler.MenuElementHandler; +import org.adempiere.pipo.handler.MessageElementHandler; +import org.adempiere.pipo.handler.OrgRoleElementHandler; +import org.adempiere.pipo.handler.PreferenceElementHandler; +import org.adempiere.pipo.handler.PrintFormatElementHandler; +import org.adempiere.pipo.handler.PrintFormatItemElementHandler; +import org.adempiere.pipo.handler.ProcessAccessElementHandler; +import org.adempiere.pipo.handler.ProcessElementHandler; +import org.adempiere.pipo.handler.ProcessParaElementHandler; +import org.adempiere.pipo.handler.ReferenceElementHandler; +import org.adempiere.pipo.handler.ReferenceListElementHandler; +import org.adempiere.pipo.handler.ReferenceTableElementHandler; +import org.adempiere.pipo.handler.ReportViewColElementHandler; +import org.adempiere.pipo.handler.ReportViewElementHandler; +import org.adempiere.pipo.handler.RoleElementHandler; +import org.adempiere.pipo.handler.SQLStatementElementHandler; +import org.adempiere.pipo.handler.TabElementHandler; +import org.adempiere.pipo.handler.TableElementHandler; +import org.adempiere.pipo.handler.TaskAccessElementHandler; +import org.adempiere.pipo.handler.TaskElementHandler; +import org.adempiere.pipo.handler.UserRoleElementHandler; +import org.adempiere.pipo.handler.WindowAccessElementHandler; +import org.adempiere.pipo.handler.WindowElementHandler; +import org.adempiere.pipo.handler.WorkflowAccessElementHandler; +import org.adempiere.pipo.handler.WorkflowElementHandler; +import org.adempiere.pipo.handler.WorkflowNodeElementHandler; +import org.adempiere.pipo.handler.WorkflowNodeNextConditionElementHandler; +import org.adempiere.pipo.handler.WorkflowNodeNextElementHandler; +import org.compiere.model.MSequence; +import org.compiere.util.CLogger; +import org.compiere.util.DB; +import org.compiere.util.Env; +import org.compiere.util.Trx; +import org.compiere.wf.MWFNode; +import org.compiere.wf.MWorkflow; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; +import org.xml.sax.helpers.DefaultHandler; + +/** + * SAX Handler for parsing XML description of the GUI. + * + * @author Marco LOMBARDO, lombardo@mayking.com + * @author Robert KLEIN, robeklein@hotmail + * + * Contributor: William G. Heath - Import of workflows and dynamic validations + */ +public class PackInHandler extends DefaultHandler { + + /** + * PackInHandler Handler + */ + public PackInHandler () { + setupHandlers(); + } // PackInHandler + + /** Set this if you want to update Dictionary */ + private String m_UpdateMode = "true"; + private String packageDirectory = null; + private String m_DatabaseType = "Oracle"; + private int m_AD_Client_ID = 0; + private int AD_Package_Imp_ID=0; + private int AD_Package_Imp_Inst_ID=0; + private CLogger log = CLogger.getCLogger(PackInHandler.class); + private OutputStream fw_document = null; + private TransformerHandler logDocument = null; + private StreamResult streamResult_document = null; + private SAXTransformerFactory tf_document = null; + private Transformer serializer_document = null; + private int Start_Doc = 0; + private String logDate = null; + private String PK_Status = "Installing"; + // transaction name + private String m_trxName = null; + private Properties m_ctx = null; + + private Maphandlers = null; + private List menus = new ArrayList(); + private List workflow = new ArrayList(); + private List nodes = new ArrayList(); + private List defer = new ArrayList(); + private Stack stack = new Stack(); + private PackIn packIn; + + private void init() throws SAXException { + if (packIn == null) + packIn = new PackIn(); + packageDirectory = PackIn.m_Package_Dir; + m_UpdateMode = PackIn.m_UpdateMode; + m_DatabaseType = PackIn.m_Database; + 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 file_document = packageDirectory+File.separator+"doc"+File.separator+"Importlog_"+fileDate+".xml"; + log.info("file_document="+file_document); + try { + fw_document = new FileOutputStream (file_document, false); + } catch (FileNotFoundException e1) { + log.warning ("Failed to create log file:"+e1); + } + streamResult_document = new StreamResult(fw_document); + tf_document = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); + + try { + logDocument = tf_document.newTransformerHandler(); + } catch (TransformerConfigurationException e2) { + log.info ("startElement:"+e2); + } + serializer_document = logDocument.getTransformer(); + serializer_document.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1"); + serializer_document.setOutputProperty(OutputKeys.INDENT,"yes"); + logDocument.setResult(streamResult_document); + 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"); + + m_AD_Client_ID = Env.getContextAsInt(m_ctx, "AD_Client_ID"); + + Start_Doc=1; + } + + private void setupHandlers() { + DataElementHandler dataHandler = new DataElementHandler(); + handlers = new HashMap(); + handlers.put("menu", new MenuElementHandler()); + handlers.put("adempieredata", dataHandler); + handlers.put("data", dataHandler); + handlers.put("dtable", dataHandler); + handlers.put("drow", dataHandler); + handlers.put("dcolumn", dataHandler); + handlers.put("window", new WindowElementHandler()); + handlers.put("windowaccess", new WindowAccessElementHandler()); + handlers.put("preference", new PreferenceElementHandler()); + handlers.put("tab", new TabElementHandler()); + handlers.put("field", new FieldElementHandler()); + handlers.put("process", new ProcessElementHandler()); + handlers.put("processpara", new ProcessParaElementHandler()); + handlers.put("processaccess", new ProcessAccessElementHandler()); + handlers.put("message", new MessageElementHandler()); + handlers.put("dynvalrule", new DynValRuleElementHandler()); + handlers.put("workflow", new WorkflowElementHandler()); + handlers.put("workflowNode", new WorkflowNodeElementHandler()); + handlers.put("workflowNodeNext", new WorkflowNodeNextElementHandler()); + handlers.put("workflowNodeNextCondition", new WorkflowNodeNextConditionElementHandler()); + handlers.put("workflowaccess", new WorkflowAccessElementHandler()); + handlers.put("table", new TableElementHandler()); + handlers.put("column", new ColumnElementHandler()); + handlers.put("role", new RoleElementHandler()); + handlers.put("userrole", new UserRoleElementHandler()); + handlers.put("orgrole", new OrgRoleElementHandler()); + handlers.put("form", new FormElementHandler()); + handlers.put("formaccess", new FormAccessElementHandler()); + handlers.put("task", new TaskElementHandler()); + handlers.put("taskaccess", new TaskAccessElementHandler()); + handlers.put("impformat", new ImpFormatElementHandler()); + handlers.put("impformatrow", new ImpFormatRowElementHandler()); + handlers.put("codesnipit", new CodeSnipitElementHandler()); + handlers.put("distfile", new DistFileElementHandler()); + handlers.put("reportview", new ReportViewElementHandler()); + handlers.put("reportviewcol", new ReportViewColElementHandler()); + handlers.put("printformat", new PrintFormatElementHandler()); + handlers.put("printformatitem", new PrintFormatItemElementHandler()); + handlers.put("SQLStatement", new SQLStatementElementHandler()); + handlers.put("reference", new ReferenceElementHandler()); + handlers.put("referencelist", new ReferenceListElementHandler()); + handlers.put("referencetable", new ReferenceTableElementHandler()); + handlers.put("fieldgroup", new FieldGroupElementHandler()); + handlers.put("element", new AdElementHandler()); + handlers.put("trl", new CommonTranslationHandler()); + } + + /** + * Receive notification of the start of an element. + * + * @param uri namespace + * @param localName simple name + * @param qName qualified name + * @param atts attributes + * @throws org.xml.sax.SAXException + */ + public void startElement (String uri, String localName, String qName, Attributes atts) + throws org.xml.sax.SAXException { + + // Create the package log + if (Start_Doc==0){ + init(); + } + // Check namespace. + String elementValue = null; + if ("".equals (uri)) + elementValue = qName; + else + elementValue = uri + localName; + + // adempiereAD. + if (elementValue.equals("adempiereAD")) { + log.info("adempiereAD updateMode="+m_UpdateMode); + //Start package log + AttributesImpl attsOut = new AttributesImpl(); + logDocument.startElement("","","adempiereDocument",attsOut); + logDocument.startElement("","","header",attsOut); + logDocument.characters((atts.getValue("Name")+" Install Log").toCharArray(),0,(atts.getValue("Name")+" Install Log").length()); + logDocument.endElement("","","header"); + logDocument.startElement("","","H3",attsOut); + logDocument.characters(("Package Name:" ).toCharArray(),0,("Package Name:" ).length()); + logDocument.endElement("","","H3"); + logDocument.startElement("","","packagename4log",attsOut); + logDocument.characters(atts.getValue("Name").toCharArray(),0,atts.getValue("Name").length()); + logDocument.endElement("","","packagename4log"); + logDocument.startElement("","","H3",attsOut); + logDocument.characters(("Version:" ).toCharArray(),0,("Version:" ).length()); + logDocument.endElement("","","H3"); + logDocument.startElement("","","Version",attsOut); + logDocument.characters(atts.getValue("Version").toCharArray(),0,atts.getValue("Version").length()); + logDocument.endElement("","","Version"); + logDocument.startElement("","","H3",attsOut); + logDocument.characters(("Package Install Date:" ).toCharArray(),0,("Package Install Date:" ).length()); + logDocument.endElement("","","H3"); + logDocument.startElement("","","installDate",attsOut); + logDocument.characters(logDate.toCharArray(),0,logDate.length()); + logDocument.endElement("","","installDate"); + logDocument.startElement("","","H3",attsOut); + logDocument.characters(("Min. Compiere Version:" ).toCharArray(),0,("Min. Compiere Version:" ).length()); + logDocument.endElement("","","H3"); + logDocument.startElement("","","CompVer",attsOut); + logDocument.characters(atts.getValue("CompVer").toCharArray(),0,atts.getValue("CompVer").length()); + logDocument.endElement("","","CompVer"); + logDocument.startElement("","","H3",attsOut); + logDocument.characters(("Min. Database Date:" ).toCharArray(),0,("Min. Database Date:" ).length()); + logDocument.endElement("","","H3"); + logDocument.startElement("","","DataBase",attsOut); + logDocument.characters(atts.getValue("DataBase").toCharArray(),0,atts.getValue("DataBase").length()); + logDocument.endElement("","","DataBase"); + + createImp_Sum_table ("AD_Package_Imp_Backup"); + createImp_Sum_table ("AD_Package_Imp"); + createImp_Sum_table ("AD_Package_Imp_Inst"); + createImp_Sum_table ("AD_Package_Imp_Detail"); + + // Update Summary Package History Table + String sql2 = "SELECT AD_PACKAGE_IMP_INST_ID FROM AD_PACKAGE_IMP_INST WHERE NAME =" + + "'" + atts.getValue("Name") + + "' AND PK_VERSION ='" + atts.getValue("Version") + "'"; + int PK_preInstalled = DB.getSQLValue(m_trxName,sql2); + + AD_Package_Imp_ID = DB.getNextID (Env.getAD_Client_ID(m_ctx), "AD_Package_Imp", null); + + StringBuffer sqlB = new StringBuffer ("Insert INTO AD_Package_Imp") + .append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " ) + .append( "AD_PACKAGE_IMP_ID, RELEASENO, PK_VERSION, VERSION " ) + .append( ", DESCRIPTION, NAME, CREATOR" ) + .append( ", CREATORCONTACT, CREATEDDATE,UPDATEDDATE,PK_STATUS)" ) + .append( "VALUES(" ) + .append( " "+ Env.getAD_Client_ID(m_ctx) ) + .append( ", "+ Env.getAD_Org_ID(m_ctx) ) + .append( ", "+ Env.getAD_User_ID(m_ctx) ) + .append( ", "+ Env.getAD_User_ID(m_ctx) ) + .append( ", " + AD_Package_Imp_ID ) + .append( ", '" + atts.getValue("CompVer") ) + .append( "', '" + atts.getValue("Version") ) + .append( "', '" + atts.getValue("DataBase") ) + .append( "', '" + atts.getValue("Description").replaceAll("'","''")) + .append( "', '" + atts.getValue("Name") ) + .append( "', '" + atts.getValue("creator") ) + .append( "', '" + atts.getValue("creatorcontact") ) + .append( "', '" + atts.getValue("createddate") ) + .append( "', '" + atts.getValue("updateddate") ) + .append( "', '" + PK_Status ) + .append( "')" ); + Env.getAD_User_ID(m_ctx); + int no = DB.executeUpdate (sqlB.toString(), m_trxName); + if (no == -1) + log.info("Insert to Package import failed"); + + if ( PK_preInstalled == -1){ + AD_Package_Imp_Inst_ID = DB.getNextID (Env.getAD_Client_ID(m_ctx), "AD_Package_Imp_Inst", null); + + //Insert Package into package install log + sqlB = new StringBuffer ("Insert INTO AD_Package_Imp_Inst") + .append( "(AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy, " ) + .append( "AD_PACKAGE_IMP_INST_ID, RELEASENO, PK_VERSION, VERSION " ) + .append( ", DESCRIPTION, NAME, CREATOR" ) + .append( ", CREATORCONTACT, CREATEDDATE,UPDATEDDATE,PK_STATUS)" ) + .append( "VALUES(" ) + .append( " "+ Env.getAD_Client_ID(m_ctx) ) + .append( ", "+ Env.getAD_Org_ID(m_ctx) ) + .append( ", "+ Env.getAD_User_ID(m_ctx) ) + .append( ", "+ Env.getAD_User_ID(m_ctx) ) + .append( ", " + AD_Package_Imp_Inst_ID ) + .append( ", '" + atts.getValue("CompVer") ) + .append( "', '" + atts.getValue("Version") ) + .append( "', '" + atts.getValue("DataBase") ) + .append( "', '" + atts.getValue("Description").replaceAll("'","''")) + .append( "', '" + atts.getValue("Name") ) + .append( "', '" + atts.getValue("creator") ) + .append( "', '" + atts.getValue("creatorcontact") ) + .append( "', '" + atts.getValue("createddate") ) + .append( "', '" + atts.getValue("updateddate") ) + .append( "', '" + PK_Status ) + .append( "')" ); + + Env.getAD_User_ID(m_ctx); + no = DB.executeUpdate (sqlB.toString(), m_trxName); + if (no == -1) + log.info("Insert to Package List import failed"); + } + else{ + //Update package list with package status + AD_Package_Imp_Inst_ID = PK_preInstalled; + sqlB = new StringBuffer ("UPDATE AD_Package_Imp_Inst " + + "SET PK_Status = '" + PK_Status + + "' WHERE AD_Package_Imp_Inst_ID = "+AD_Package_Imp_Inst_ID); + no = DB.executeUpdate (sqlB.toString(), m_trxName); + if (no == -1) + log.info("Update to package summary failed"); + } + Env.setContext(m_ctx, "AD_Package_Imp_ID", AD_Package_Imp_ID); + Env.setContext(m_ctx, "UpdateMode", m_UpdateMode); + Env.setContext(m_ctx, "TrxName", m_trxName); + Env.setContext(m_ctx, "PackageDirectory", packageDirectory); + m_ctx.put("LogDocument", logDocument); + m_ctx.put("PackInProcess", packIn); + } + else if (elementValue.equals("menu")) { + //defer + Element e = new Element(uri, localName, qName, new AttributesImpl(atts)); + if (stack.size() > 0) + e.parent = stack.peek(); + stack.push(e); + menus.add(e); + } + else { + Element e = new Element(uri, localName, qName, new AttributesImpl(atts)); + if (stack.size() > 0) + e.parent = stack.peek(); + stack.push(e); + if (elementValue.equals("workflow")) + { + workflow.add(e); + } + + if (elementValue.equals("workflowNode")) + { + nodes.add(e); + } + + + ElementHandler handler = handlers.get(elementValue); + if (handler != null) + handler.startElement(m_ctx, e); + if (e.defer) { + defer.add(new DeferEntry(e, true)); + } + } + } // startElement + + /** + * Check if Package History Table exists in database. If not create + * + * @param tablename + * + */ + public void createImp_Sum_table (String tablename){ + // Check if table exists. + + Connection conn = DB.getConnectionRW(); + DatabaseMetaData dbm; + try { + dbm = conn.getMetaData(); + // check if table is there + ResultSet tables = null; + if (m_DatabaseType.equals("Oracle")) + tables = dbm.getTables(null, null, tablename.toUpperCase(), null ); + else if (m_DatabaseType.equals("PostgreSQL")) + tables = dbm.getTables(null, null, tablename.toLowerCase(), null ); + + if (tables.next()) { + log.info ("Table Found"); + } + else { + if (tablename.equals("AD_Package_Imp")){ + StringBuffer sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( ") + .append( tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " ) + .append( "AD_CLIENT_ID NUMBER(10) NOT NULL, " ) + .append( "AD_ORG_ID NUMBER(10) NOT NULL, " ) + .append( "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " ) + .append( "CREATED DATE DEFAULT SYSDATE NOT NULL, " ) + .append( "CREATEDBY NUMBER(10) NOT NULL, " ) + .append( "UPDATED DATE DEFAULT SYSDATE NOT NULL, " ) + .append( "UPDATEDBY NUMBER(10) NOT NULL, " ) + .append( "NAME NVARCHAR2(60) NOT NULL, " ) + .append( "PK_STATUS NVARCHAR2(22), " ) + .append( "RELEASENO NVARCHAR2(20), " ) + .append( "PK_VERSION NVARCHAR2(20), " ) + .append( "VERSION NVARCHAR2(20), " ) + .append( "DESCRIPTION NVARCHAR2(1000) NOT NULL, " ) + .append( "EMAIL NVARCHAR2(60), " ) + .append( "PROCESSED CHAR(1) DEFAULT 'N', " ) + .append( "PROCESSING CHAR(1) DEFAULT 'N', " ) + .append( "CREATOR VARCHAR2(60 ), " ) + .append( "CREATORCONTACT VARCHAR2(255), " ) + .append( " CREATEDDATE VARCHAR2(25), " ) + .append( "UPDATEDDATE VARCHAR2(25), " ) + .append( "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" ); + + try { + PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(),ResultSet.TYPE_FORWARD_ONLY, + ResultSet.CONCUR_UPDATABLE, null); + pstmt.executeUpdate(); + MSequence.createTableSequence (m_ctx, "AD_Package_Imp", m_trxName); + pstmt.close(); + pstmt = null; + } + catch (Exception e) { + log.info ("createImp_Sum_table:"+e); + } + } + if (tablename.equals("AD_Package_Imp_Inst")){ + StringBuffer sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( ") + .append( tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " ) + .append( "AD_CLIENT_ID NUMBER(10) NOT NULL, " ) + .append( "AD_ORG_ID NUMBER(10) NOT NULL, " ) + .append( "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " ) + .append( "CREATED DATE DEFAULT SYSDATE NOT NULL, " ) + .append( "CREATEDBY NUMBER(10) NOT NULL, " ) + .append( "UPDATED DATE DEFAULT SYSDATE NOT NULL, " ) + .append( "UPDATEDBY NUMBER(10) NOT NULL, " ) + .append( "NAME NVARCHAR2(60) NOT NULL, " ) + .append( "PK_STATUS NVARCHAR2(22), " ) + .append( "RELEASENO NVARCHAR2(20), " ) + .append( "PK_VERSION NVARCHAR2(20), " ) + .append( "VERSION NVARCHAR2(20), " ) + .append( "DESCRIPTION NVARCHAR2(1000) NOT NULL, " ) + .append( "EMAIL NVARCHAR2(60), " ) + .append( "PROCESSED CHAR(1) DEFAULT 'N', " ) + .append( "PROCESSING CHAR(1) DEFAULT 'N', " ) + .append( "CREATOR VARCHAR2(60 ), " ) + .append( "CREATORCONTACT VARCHAR2(255), " ) + .append( " CREATEDDATE VARCHAR2(25), " ) + .append( "UPDATEDDATE VARCHAR2(25), " ) + .append( "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" ); + + try { + PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(),ResultSet.TYPE_FORWARD_ONLY, + ResultSet.CONCUR_UPDATABLE, null); + pstmt.executeUpdate(); + MSequence.createTableSequence (m_ctx, "AD_Package_Imp_Inst", m_trxName); + pstmt.close(); + pstmt = null; + } + catch (Exception e) { + log.info ("createImp_Sum_table:"+e); + } + } + if (tablename.equals("AD_Package_Imp_Detail")){ + StringBuffer sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( ") + .append( tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " ) + .append( "AD_CLIENT_ID NUMBER(10) NOT NULL, " ) + .append( "AD_ORG_ID NUMBER(10) NOT NULL, " ) + .append( "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " ) + .append( "CREATED DATE DEFAULT SYSDATE NOT NULL, " ) + .append( "CREATEDBY NUMBER(10) NOT NULL, " ) + .append( "UPDATED DATE DEFAULT SYSDATE NOT NULL, " ) + .append( "UPDATEDBY NUMBER(10) NOT NULL, " ) + .append( "NAME NVARCHAR2(60), " ) + .append( "AD_PACKAGE_IMP_ID Number(10) NOT NULL, " ) + .append( "AD_ORIGINAL_ID Number(10) NOT NULL, " ) + .append( "AD_BACKUP_ID Number(10), " ) + .append( "ACTION NVARCHAR2(20), " ) + .append( "SUCCESS NVARCHAR2(20), " ) + .append( "TYPE NVARCHAR2(60), " ) + .append( "TABLENAME NVARCHAR2(60), " ) + .append( "AD_TABLE_ID NUMBER(10), " ) + .append( "UNINSTALL CHAR(1), " ) + .append( "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" ); + + try { + PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(),ResultSet.TYPE_FORWARD_ONLY, + ResultSet.CONCUR_UPDATABLE, null); + pstmt.executeUpdate(); + MSequence.createTableSequence (m_ctx, "AD_Package_Imp_Detail", m_trxName); + pstmt.close(); + pstmt = null; + } + catch (Exception e) { + log.info ("createImp_Sum_table:"+e); + } + } + if (tablename.equals("AD_Package_Imp_Backup")){ + StringBuffer sqlB = new StringBuffer ("CREATE TABLE "+ tablename.toUpperCase() + "( ") + .append( tablename.toUpperCase()+"_ID NUMBER(10) NOT NULL, " ) + .append( "AD_CLIENT_ID NUMBER(10) NOT NULL, " ) + .append( "AD_ORG_ID NUMBER(10) NOT NULL, " ) + .append( "ISACTIVE CHAR(1) DEFAULT 'Y' NOT NULL, " ) + .append( "CREATED DATE DEFAULT SYSDATE NOT NULL, " ) + .append( "CREATEDBY NUMBER(10) NOT NULL, " ) + .append( "UPDATED DATE DEFAULT SYSDATE NOT NULL, " ) + .append( "UPDATEDBY NUMBER(10) NOT NULL, " ) + .append( "AD_PACKAGE_IMP_ID Number(10) NOT NULL, " ) + .append( "AD_PACKAGE_IMP_DETAIL_ID Number(10) NOT NULL, " ) + .append( "AD_TABLE_ID NUMBER(10), " ) + .append( "AD_COLUMN_ID NUMBER(10), " ) + .append( "AD_REFERENCE_ID NUMBER(10), " ) + .append( "AD_PACKAGE_IMP_BCK_DIR NVARCHAR2(255), " ) + .append( "AD_PACKAGE_IMP_ORG_DIR NVARCHAR2(255), " ) + .append( "COLVALUE NVARCHAR2(2000), " ) + .append( "UNINSTALL CHAR(1), " ) + .append( "PRIMARY KEY( "+tablename.toUpperCase() +"_ID)"+")" ); + + try { + PreparedStatement pstmt = DB.prepareStatement(sqlB.toString(),ResultSet.TYPE_FORWARD_ONLY, + ResultSet.CONCUR_UPDATABLE, null); + pstmt.executeUpdate(); + MSequence.createTableSequence (m_ctx, "AD_Package_Imp_Backup", m_trxName); + pstmt.close(); + pstmt = null; + } + catch (Exception e) { + log.info ("createImp_Sum_table:"+e); + } + } + } + + tables.close(); + } + + catch (SQLException e) { + log.info ("createImp_Sum_table:"+e); + } + + finally + { + if( conn != null ) + { + try + { + conn.close(); + } + catch( Exception e ){} + } + } + } + + /** + * Receive notification of the end of an element. + * @param uri namespace + * @param localName simple name + * @param qName qualified name + * @throws SAXException + */ + public void endElement (String uri, String localName, String qName) throws SAXException { + // Check namespace. + String elementValue = null; + if ("".equals (uri)) + elementValue = qName; + else + elementValue = uri + localName; + + if (elementValue.equals("adempiereAD")){ + processDeferElements(); + processMenuElements(); + if (!PK_Status.equals("Completed with errors")) + PK_Status = "Completed successfully"; + + //Update package history log with package status + StringBuffer sqlB = new StringBuffer ("UPDATE AD_Package_Imp " + + "SET PK_Status = '" + PK_Status + + "' WHERE AD_Package_Imp_ID = " + AD_Package_Imp_ID); + int no = DB.executeUpdate (sqlB.toString(), m_trxName); + if (no == -1) + log.info("Update to package summary failed"); + + //Update package list with package status + sqlB = new StringBuffer ("UPDATE AD_Package_Imp_Inst " + + "SET PK_Status = '" + PK_Status + + "' WHERE AD_Package_Imp_Inst_ID = " + AD_Package_Imp_Inst_ID); + no = DB.executeUpdate (sqlB.toString(), m_trxName); + if (no == -1) + log.info("Update to package list failed"); + + if(workflow.size() > 0) + { + for (Element e : workflow) + { + Attributes atts = e.attributes; + String workflowName = atts.getValue("Name"); + MWorkflow wf = null; + + int workflow_id = IDFinder.get_IDWithColumn("AD_Workflow", "Name", workflowName ,m_AD_Client_ID , m_trxName); + if(workflow_id > 0) + { + wf = new MWorkflow(m_ctx, workflow_id , m_trxName); + int node_id = 0; + + String name = atts.getValue("ADWorkflowNodeNameID"); + if (name != null && name.trim().length() > 0) + { + MWFNode[] nodes = wf.getNodes(false, m_AD_Client_ID); + + for (MWFNode node : nodes) + { + if (node.getName().trim().equals(name.trim())) + { + node_id = node.getAD_WF_Node_ID(); + wf.setAD_WF_Node_ID(node_id); + if (!wf.save()) + System.out.println("Can not save Start Node "+ name +"to Workflow " + workflowName + " do not exist "); + break; + } + } + + if(node_id == 0) + System.out.println("Unresolved: Start Node to Workflow " + workflowName + " do not exist "); + else + break; + } + + } + } + } + + if(nodes.size() > 0) + { + for (Element e : nodes) + { + Attributes atts = e.attributes; + String nodeName = atts.getValue("Name"); + MWFNode node = null; + int id = IDFinder.get_IDWithColumn("AD_WF_Node", "Name", nodeName , m_AD_Client_ID , m_trxName); + if(id > 0) + { + node = new MWFNode(m_ctx, id , m_trxName); + String workflowNodeName = atts.getValue("WorkflowNameID").trim(); + if (workflowNodeName != null && workflowNodeName.trim().length() > 0) + { + int workflow_id = IDFinder.get_IDWithColumn("AD_Workflow", "Name",workflowNodeName, m_AD_Client_ID, m_trxName); + if (workflow_id > 0) + { + node.setWorkflow_ID(workflow_id); + if(!node.save()) + { + System.out.println("can not save Workflow " + workflowNodeName ); + } + } + else + System.out.println("Unresolved: Workflow " + workflowNodeName + " do not exist "); + } + + } + } + } + + logDocument.endElement("","","adempiereDocument"); + logDocument.endDocument(); + try { + fw_document.close(); + } + catch (Exception e) + {} + + //reset + setupHandlers(); + } else { + Element e = stack.pop(); + if (e.defer) { + defer.add(new DeferEntry(e, false)); + } else { + ElementHandler handler = handlers.get(elementValue); + if (handler != null) + handler.endElement(m_ctx, e); + if (e.defer || e.deferEnd) + defer.add(new DeferEntry(e, false)); + else if (!e.skip) { + if (log.isLoggable(Level.INFO)) + log.info("Processed: " + e.getElementValue() + " - " + e.attributes.getValue(0)); + } + } + } + + + + } // endElement + + private void processMenuElements() throws SAXException { + ElementHandler handler = handlers.get("menu"); + if (menus.size() > 0 && handler != null) { + for (Element e : menus) { + handler.startElement(m_ctx, e); + handler.endElement(m_ctx, e); + } + } + } + + private void processDeferElements() throws SAXException { + if (defer.isEmpty()) return; + + do { + int startSize = defer.size(); + List tmp = new ArrayList(defer); + defer.clear(); + for (DeferEntry d : tmp) { + if (d.startElement) { + d.element.defer = false; + d.element.unresolved = ""; + d.element.pass++; + } else { + if (d.element.deferEnd) { + d.element.deferEnd = false; + d.element.unresolved = ""; + } + } + if (log.isLoggable(Level.INFO)) { + log.info("Processeing Defer Element: " + d.element.getElementValue() + " - " + + d.element.attributes.getValue(0)); + } + ElementHandler handler = handlers.get(d.element.getElementValue()); + if (handler != null) { + if (d.startElement) + handler.startElement(m_ctx, d.element); + else + handler.endElement(m_ctx, d.element); + } + if (d.element.defer) + defer.add(d); + else if (!d.startElement) { + if (d.element.deferEnd) + defer.add(d); + else { + if (log.isLoggable(Level.INFO)) + log.info("Imported Defer Element: " + d.element.getElementValue() + " - " + + d.element.attributes.getValue(0)); + } + } + } + int endSize = defer.size(); + if (startSize == endSize) break; + } while (defer.size() > 0); + + if (defer.size() > 0) { + int count = 0; + for (DeferEntry d : defer) { + if (!d.startElement) { + count++; + if (log.isLoggable(Level.SEVERE)) + log.severe("Unresolved: " + d.element.getElementValue() + " - " + d.element.attributes.getValue(0) + ", " + d.element.unresolved); + } + } + //throw new RuntimeException("Failed to resolve dependency for " + count + " elements."); //commented by Joyce (12 Nov 2008) + //System.err.println("Failed to resolve dependency for " + count + " elements."); + } + } + + // 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) { + m_ctx = ctx; + } + + class DeferEntry { + Element element; + boolean startElement = false; + + DeferEntry(Element e, boolean b) { + element = e; + startElement = b; + } + } + + /** + * @param packIn + */ + public void setProcess(PackIn packIn) { + this.packIn = packIn; + } +} // PackInHandler diff --git a/base/src/org/adempiere/pipo/handler/DataElementHandler.java b/base/src/org/adempiere/pipo/handler/DataElementHandler.java index d628691f40..ff9ca61bca 100644 --- a/base/src/org/adempiere/pipo/handler/DataElementHandler.java +++ b/base/src/org/adempiere/pipo/handler/DataElementHandler.java @@ -23,8 +23,7 @@ import java.sql.ResultSetMetaData; import java.sql.Statement; import java.sql.Timestamp; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; +import java.util.List; import java.util.Properties; import java.util.logging.Level; @@ -38,11 +37,18 @@ import org.adempiere.pipo.exception.POSaveFailedException; import org.compiere.model.POInfo; import org.compiere.model.X_AD_Package_Exp_Detail; import org.compiere.util.DB; +import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; +/** + * + * @author Robert Klein. + * @author Low Heng Sin + * + */ public class DataElementHandler extends AbstractElementHandler { private GenericPO genericPO = null; @@ -93,41 +99,41 @@ public class DataElementHandler extends AbstractElementHandler { public void startElement(Properties ctx, Element element) throws SAXException { String elementValue = element.getElementValue(); Attributes atts = element.attributes; - log.info(elementValue+" "+atts.getValue("name")); - String d_rowname = atts.getValue("name"); - - // name can be null if there are keyXname attributes. - if (!d_rowname.equals("")){ - int id = get_ID(ctx, d_tablename, d_rowname); - genericPO = new GenericPO(d_tablename, ctx, id, getTrxName(ctx)); - if (id > 0){ - AD_Backup_ID = copyRecord(ctx,d_tablename,genericPO); - objectStatus = "Update"; - } - else{ - objectStatus = "New"; - AD_Backup_ID =0; - } - } - // keyXname and lookupkeyXname. - else { + log.info(elementValue+" "+atts.getValue("name")); + + // use keyXname and lookupkeyXname if available + if (atts.getValue("key1name") != null && atts.getValue("key1name").trim().length() > 0) + { String sql = "select * from "+d_tablename; String whereand = " where"; - String CURRENT_KEY = "key1name"; - if (atts.getValue(CURRENT_KEY) != null && !atts.getValue(CURRENT_KEY).equals("")) { - sql = sql+whereand+" "+atts.getValue(CURRENT_KEY)+"="+atts.getValue("lookup"+CURRENT_KEY); - whereand = " and"; + + Listparams = new ArrayList(); + int keyIndex = 1; + while (true) { + String currentKey = "key" + keyIndex + "name"; + if (atts.getValue(currentKey) != null && !atts.getValue(currentKey).equals("")) { + params.add(atts.getValue("lookup"+currentKey)); + sql = sql+whereand+" "+atts.getValue(currentKey)+"=?"; + whereand = " and"; + keyIndex++; + } else { + break; + } } - CURRENT_KEY = "key2name"; - if (atts.getValue(CURRENT_KEY) != null && !atts.getValue(CURRENT_KEY).equals("")) { - sql = sql+whereand+" "+atts.getValue(CURRENT_KEY)+"="+atts.getValue("lookup"+CURRENT_KEY); - whereand = " and"; + + if (getClientId(ctx) > 0) { + sql = sql + whereand + " " + d_tablename + ".AD_Client_ID in (0, " + getClientId(ctx) + ")"; + sql = sql + " Order by " + d_tablename + ".AD_Client_ID Desc"; + } else { + sql = sql + whereand + " " + d_tablename + ".AD_Client_ID = 0"; } - if (whereand.equals(" where")) - log.warning("no name or keyXname attribute defined."); + // Load GenericPO from rs, in fact ID could not exist e.g. Attribute Value try { PreparedStatement pstmt = DB.prepareStatement(sql, getTrxName(ctx)); + for (int i = 0; i < params.size(); i++) { + pstmt.setString(i+1, params.get(i)); + } ResultSet rs = pstmt.executeQuery(); if (rs.next()) { @@ -143,20 +149,23 @@ public class DataElementHandler extends AbstractElementHandler { pstmt.close(); pstmt = null; objectStatus = "New"; - // set keyXname. - CURRENT_KEY = "key1name"; - if (!atts.getValue(CURRENT_KEY).equals("")) { - genericPO.set_ValueOfColumn(atts.getValue(CURRENT_KEY), atts.getValue("lookup"+CURRENT_KEY)); - } - CURRENT_KEY = "key2name"; - if (!atts.getValue(CURRENT_KEY).equals("")) { - genericPO.set_ValueOfColumn(atts.getValue(CURRENT_KEY), atts.getValue("lookup"+CURRENT_KEY)); - } - } - + } } catch (Exception e) { - log.warning ("keyXname attribute. init from rs error."+e); + log.log(Level.SEVERE, e.getLocalizedMessage(), e); + } + } else { + //fallback to name attribute + String nameAttribute = atts.getValue("name"); + int id = get_ID(ctx, d_tablename, nameAttribute); + genericPO = new GenericPO(d_tablename, ctx, id, getTrxName(ctx)); + if (id > 0){ + AD_Backup_ID = copyRecord(ctx,d_tablename,genericPO); + objectStatus = "Update"; + } + else{ + objectStatus = "New"; + AD_Backup_ID =0; } } @@ -171,29 +180,7 @@ public class DataElementHandler extends AbstractElementHandler { } // globalqss: set AD_Client_ID to the client setted in adempieredata if (getClientId(ctx) > 0 && genericPO.getAD_Client_ID() != getClientId(ctx)) - genericPO.set_ValueOfColumn("AD_Client_ID", getClientId(ctx)); - // if new. TODO: no defaults for keyXname. - if (!d_rowname.equals("") && ((Integer)(genericPO.get_Value(d_tablename+"_ID"))).intValue() == 0) { - log.info("new genericPO, table: "+d_tablename+" name:"+d_rowname); - genericPO.set_ValueOfColumn("Name", d_rowname); - // Set defaults. - //TODO: get defaults from configuration - HashMap defaults = new HashMap(); - HashMap thisDefault = (HashMap)defaults.get(d_tablename); - if (thisDefault != null) { - Iterator iter = thisDefault.values().iterator(); - ArrayList thisValue = null; - while (iter.hasNext()) { - thisValue = (ArrayList)iter.next(); - if (((String)(thisValue.get(2))).equals("String")) - genericPO.set_ValueOfColumn((String)thisValue.get(0), (String)thisValue.get(1)); - else if (((String)(thisValue.get(2))).equals("Integer")) - genericPO.set_ValueOfColumn((String)thisValue.get(0), Integer.valueOf((String)thisValue.get(1))); - else if (((String)(thisValue.get(2))).equals("Boolean")) - genericPO.set_ValueOfColumn((String)thisValue.get(0), new Boolean(((String)thisValue.get(1)).equals("true") ? true : false)); - } - } - } + genericPO.set_ValueOfColumn("AD_Client_ID", getClientId(ctx)); } public void endElement(Properties ctx, Element element) throws SAXException { @@ -224,6 +211,10 @@ public class DataElementHandler extends AbstractElementHandler { String columnName = atts.getValue("name"); int tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", d_tablename); int id =get_IDWithMasterAndColumn (ctx,"AD_Column", "ColumnName", columnName, "AD_Table", tableid); + if (id <= 0) { + log.log(Level.WARNING, "Column not found in AD_Column, TableName=" + d_tablename + " ColumnName=" + columnName); + return; + } StringBuffer sql = new StringBuffer ("SELECT IsUpdateable FROM AD_column WHERE AD_Column_ID = ?"); String isUpdateable = DB.getSQLValueString(getTrxName(ctx), sql.toString(),id); sql = new StringBuffer ("SELECT IsKey FROM AD_column WHERE AD_Column_ID = ?"); @@ -231,36 +222,43 @@ public class DataElementHandler extends AbstractElementHandler { if (("New".equals(objectStatus)) || (isKey.equals("N") && isUpdateable.equals("Y") && (!atts.getValue("name").equals("CreatedBy")||!atts.getValue("name").equals("UpdatedBy")))) { - if (atts.getValue("value") != null && !atts.getValue("value").equals("null")) { + String value = atts.getValue("value"); + if (value != null && !value.equals("null") && value.trim().length() > 0) { if (atts.getValue("class").equals("String") || atts.getValue("class").equals("Text") || atts.getValue("class").equals("List")|| atts.getValue("class").equals("Yes-No") || atts.getValue("class").equals("Button") || atts.getValue("class").equals("Memo")|| atts.getValue("class").equals("Text Long")) { - genericPO.set_ValueOfColumn(atts.getValue("name").toString(), atts.getValue("value").toString()); + genericPO.set_ValueOfColumn(atts.getValue("name"), value); } else if (atts.getValue("class").equals("Number") || atts.getValue("class").equals("Amount") || atts.getValue("class").equals("Quantity")|| atts.getValue("class").equals("Costs+Prices")){ - genericPO.set_ValueOfColumn(atts.getValue("name").toString(), new BigDecimal(atts.getValue("value"))); + genericPO.set_ValueOfColumn(atts.getValue("name"), new BigDecimal(value)); } else if (atts.getValue("class").equals("Integer") || atts.getValue("class").equals("ID") || atts.getValue("class").equals("Table Direct")|| atts.getValue("class").equals("Table") || atts.getValue("class").equals("Location (Address)")|| atts.getValue("class").equals("Account") || atts.getValue("class").equals("Color)")|| atts.getValue("class").equals("Search") || atts.getValue("class").equals("Locator (WH)")|| atts.getValue("class").equals("Product Attribute")) { - genericPO.set_ValueOfColumn(atts.getValue("name").toString(), Integer.valueOf(atts.getValue("value"))); + genericPO.set_ValueOfColumn(atts.getValue("name"), Integer.valueOf(value)); } else if (atts.getValue("class").equals("Boolean")) { - genericPO.set_ValueOfColumn(atts.getValue("name"), new Boolean(atts.getValue("value").equals("true") ? true : false)); + genericPO.set_ValueOfColumn(atts.getValue("name"), new Boolean(value.equals("true") ? true : false)); } else if (atts.getValue("class").equals("Date") || atts.getValue("class").equals("Date+Time") || atts.getValue("class").equals("Time")) { - genericPO.set_ValueOfColumn(atts.getValue("name").toString(), Timestamp.valueOf(atts.getValue("value"))); + genericPO.set_ValueOfColumn(atts.getValue("name"), Timestamp.valueOf(value)); }//Binary, Radio, RowID, Image not supported } else { // value is null if (atts.getValue("lookupname") != null && !"".equals(atts.getValue("lookupname"))) { // globalqss - bring support from XML2AD to lookupname String m_tablename = atts.getValue("name").substring(0, atts.getValue("name").length()-3); genericPO.set_ValueOfColumn(atts.getValue("name"), new Integer(getIDbyName(ctx, m_tablename, atts.getValue("lookupname")))); + } else if ( atts.getValue("sql") != null && atts.getValue("sql").trim().length() > 0) { + String idSql = atts.getValue("sql"); + idSql = idSql.replace("@AD_Client_ID@", Integer.toString(getClientId(ctx))); + int result = DB.getSQLValue(getTrxName(ctx), idSql); + if (result >= 0) + genericPO.set_ValueOfColumn(atts.getValue("name"), result); } } } @@ -275,6 +273,10 @@ public class DataElementHandler extends AbstractElementHandler { } + /** + * @param ctx + * @param document + */ public void create(Properties ctx, TransformerHandler document) throws SAXException { String sql = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement); @@ -295,37 +297,53 @@ public class DataElementHandler extends AbstractElementHandler { document.startElement("","","dtable",atts); while (rs.next()){ atts.clear(); - int key1 = 0; + int keyIndex = 0; String nameatts = ""; for (i=1 ;i <= columns;i++){ col_Name = meta.getColumnName(i).toUpperCase(); if (col_Name.equals("NAME") && rs.getObject("name") != null) nameatts = ""+rs.getObject("name"); String sql2 = "SELECT ColumnName FROM AD_Column " - + "WHERE isKey = 'Y' AND " + + "WHERE isIdentifier = 'Y' AND " + "AD_Table_ID = ? AND " + "Upper(ColumnName)= '"+col_Name+"'"; String cName = DB.getSQLValueString(null,sql2,table_id); if (cName != null){ - if (cName.toUpperCase().equals(col_Name) && key1 == 0 ){ - atts.addAttribute("","","key1name","CDATA",cName); - atts.addAttribute("","","lookupkey1name","CDATA",""+rs.getObject(col_Name)); - key1 = 1; + if (cName.toUpperCase().equals(col_Name)){ + keyIndex++; + atts.addAttribute("","","key" + keyIndex + "name","CDATA",cName); + atts.addAttribute("","","lookupkey" + keyIndex + "name","CDATA",""+rs.getObject(col_Name)); } - else if (cName.toUpperCase().equals(col_Name) && key1 == 1 ){ - atts.addAttribute("","","key2name","CDATA",cName); - atts.addAttribute("","","lookupkey2name","CDATA",""+rs.getObject(col_Name)); - key1 = 2; + } + } + + //fall back to Id + if (keyIndex == 0) { + for (i=1 ;i <= columns;i++){ + col_Name = meta.getColumnName(i).toUpperCase(); + if (col_Name.equals("NAME") && rs.getObject("name") != null) + nameatts = ""+rs.getObject("name"); + String sql2 = "SELECT ColumnName FROM AD_Column " + + "WHERE isKey = 'Y' AND " + + "AD_Table_ID = ? AND " + + "Upper(ColumnName)= '"+col_Name+"'"; + String cName = DB.getSQLValueString(null,sql2,table_id); + if (cName != null){ + if (cName.toUpperCase().equals(col_Name)){ + keyIndex++; + atts.addAttribute("","","key" + keyIndex + "name","CDATA",cName); + atts.addAttribute("","","lookupkey" + keyIndex + "name","CDATA",""+rs.getObject(col_Name)); + } } } } atts.addAttribute("","","name","CDATA",nameatts); - if ( key1 == 0 ){ + if ( keyIndex == 0 ){ atts.addAttribute("","","key1name","CDATA",""); atts.addAttribute("","","lookupkey1name","CDATA",""); - key1 = 1; + keyIndex++; } - if ( key1 == 1 ){ + if ( keyIndex == 1 ){ atts.addAttribute("","","key2name","CDATA",""); atts.addAttribute("","","lookupkey2name","CDATA",""); } @@ -333,11 +351,12 @@ public class DataElementHandler extends AbstractElementHandler { for (i=1 ;i <= columns;i++){ atts.clear(); col_Name = meta.getColumnName(i).toUpperCase(); - String sql2 = "Select A.ColumnName, B.Name " + String sql2 = "Select A.ColumnName, B.Name, A.AD_Reference_ID, A.AD_Reference_Value_ID " + "From AD_Column A, AD_Reference B " + "Where Upper(A.columnname) = ? and " + "A.AD_TABLE_ID = ? and " - + "A.AD_Reference_ID = B.AD_Reference_ID"; + + "A.AD_Reference_ID = B.AD_Reference_ID " + + "AND A.ColumnName != 'AD_Client_ID' "; PreparedStatement pstmt = null; try { @@ -350,11 +369,50 @@ public class DataElementHandler extends AbstractElementHandler { atts.clear(); atts.addAttribute("","","name","CDATA", rs1.getString("ColumnName")); atts.addAttribute("","","class","CDATA", rs1.getString("Name")); - if (rs1.getString("Name").equals("Date")||rs1.getString("Name").equals("Date+Time")||rs1.getString("Name").equals("Time")) - atts.addAttribute("","","value","CDATA", "" + rs.getTimestamp(i)); - else - atts.addAttribute("","","value","CDATA", "" + rs.getObject(i)); + //rs1.getString("ColumnName") : NAME / VALUE + //rs1.getString("Name") : STRING + //rs1.getString("AD_Reference_ID") : number (table/table direct/ search) + //rs1.getString("AD_Reference_Value_ID") : number (null when type is table direct) + + if (rs1.getInt("AD_Reference_ID") == DisplayType.Table || rs1.getInt("AD_Reference_ID") == DisplayType.Search + || rs1.getInt("AD_Reference_ID") == DisplayType.TableDir ){ + String tableName = ""; + + if (rs1.getInt("AD_Reference_ID") == DisplayType.TableDir){ + //if rs1.getString("ColumnName") = C_EDIFORMAT_ID, tablename = C_EDIFORMAT + tableName = rs1.getString("ColumnName").substring(0,rs1.getString("ColumnName").length()-3); + }else{ + //ad_ref_table.ad_reference_id = ad_reference_value_id + int referenceId = rs1.getInt("AD_Reference_Value_ID"); + + if (referenceId != 0) + tableName = getTableNameFromReferenceId(referenceId); + else + tableName = rs1.getString("ColumnName").substring(0,rs1.getString("ColumnName").length()-3); + } + + if (rs.getObject(i) == null) + atts.addAttribute("","","value","CDATA", ""); + else{ + String insertSql = getSqlFromTableName(tableName,Integer.parseInt(rs.getObject(i).toString()),ctx); + + String parentSql = getParentSql(tableName,ctx,Integer.parseInt(rs.getObject(i).toString())); + if (!parentSql.equals("")) + insertSql = insertSql + parentSql; + + insertSql = insertSql + " Order By " + tableName + ".AD_Client_ID Desc "; + + atts.addAttribute("","","value","CDATA", ""); + atts.addAttribute("", "", "sql", "CDATA", insertSql); + } + + } else { + if (rs1.getString("Name").equals("Date")||rs1.getString("Name").equals("Date+Time")||rs1.getString("Name").equals("Time")) + atts.addAttribute("","","value","CDATA", "" + rs.getTimestamp(i)); + else + atts.addAttribute("","","value","CDATA", "" + rs.getObject(i)); + } if (!rs1.getString("ColumnName").equals("Created")&&!rs1.getString("ColumnName").equals("CreatedBy")&& !rs1.getString("ColumnName").equals("Updated")&&!rs1.getString("ColumnName").equals("UpdatedBy")){ document.startElement("","","dcolumn",atts); @@ -384,5 +442,95 @@ public class DataElementHandler extends AbstractElementHandler { document.endElement("","","data"); } - + + private String getTableNameFromReferenceId(int referenceId){ + String tableName = ""; + String sql = " SELECT t.TableName FROM AD_Table T, AD_Ref_Table R " + +" WHERE T.AD_Table_ID=R.AD_Table_ID AND R.AD_Reference_ID=? "; + tableName= DB.getSQLValueString(null,sql,referenceId); + + return tableName; + } + + private String getSqlFromTableName(String tableName, int id, Properties ctx) throws Exception{ + String result = null; + + String sql = "SELECT count(a.ad_table_id) FROM ad_table a INNER JOIN ad_column b ON (a.ad_table_id = b.ad_table_id) " + + "AND a.tablename = '" + tableName + "' AND UPPER(b.columnname) = 'VALUE'"; + int count = DB.getSQLValue(null, sql); + + String insertSqlValue = count <= 0 + ? ( "SELECT Name FROM "+tableName+" WHERE "+tableName+"_ID=?" ) + : ( "SELECT Value FROM "+tableName+" WHERE "+tableName+"_ID=?" ); + PreparedStatement pstmt = null; + ResultSet rs = null; + + try{ + pstmt = DB.prepareStatement(insertSqlValue, getTrxName(ctx)); + pstmt.setInt(1, id); + rs = pstmt.executeQuery(); + if (rs.next()){ + + if (count <= 0) + result = "SELECT " +tableName+"_ID FROM "+tableName+" WHERE Name='"+rs.getString(1)+"'"; + else + result = "SELECT " +tableName+"_ID FROM "+tableName+" WHERE Value='"+rs.getString(1)+"'"; + result = result + " AND " + tableName + ".AD_Client_ID IN ( @AD_Client_ID@ , 0 )"; + } + + } catch (Exception e) { + log.log(Level.SEVERE, e.getLocalizedMessage(), e); + } finally { + DB.close(rs, pstmt); + } + + return result; + } + + private String getParentSql(String tableName, Properties ctx, int recordId) throws Exception{ + String parentSql = ""; + PreparedStatement pstmt = null; + ResultSet rs = null; + + try{ + String sql = "SELECT A.ColumnName, A.AD_Reference_ID, A.AD_Reference_Value_ID " + + "FROM AD_Column A, AD_Table T " + + "Where A.AD_TABLE_ID = T.AD_Table_ID AND A.IsParent = 'Y' " + + "AND UPPER(T.TableName)=? " + + "AND A.ColumnName != 'AD_Client_ID' "; + + pstmt = DB.prepareStatement(sql, getTrxName(ctx)); + pstmt.setString(1,tableName.toUpperCase()); + rs = pstmt.executeQuery(); + + while(rs.next()){ + if (rs.getInt("AD_Reference_ID") == DisplayType.Table || rs.getInt("AD_Reference_ID") == DisplayType.Search || rs.getInt("AD_Reference_ID") == DisplayType.TableDir){ + String parentTableName = ""; + + if (rs.getInt("AD_Reference_ID") == DisplayType.TableDir){ + //if rs1.getString("ColumnName") = C_EDIFORMAT_ID, tablename = C_EDIFORMAT + parentTableName = rs.getString("ColumnName").substring(0,rs.getString("ColumnName").length()-3); + }else{ + //ad_ref_table.ad_reference_id = ad_reference_value_id + int referenceId = rs.getInt("AD_Reference_Value_ID"); + parentTableName = getTableNameFromReferenceId(referenceId); + } + + String parentIdSql = "SELECT "+parentTableName+"_ID FROM "+tableName+" WHERE "+tableName+"_ID = "+recordId; + int parentRecordId = DB.getSQLValue(null, parentIdSql); + + parentSql = " AND "+rs.getString("ColumnName")+ " IN (" +getParentSql(parentTableName, ctx, parentRecordId)+")"; + parentSql = parentSql + " AND " + tableName + ".AD_Client_ID IN ( @AD_Client_ID@ , 0 )"; + } + } + } catch (Exception e) { + log.log(Level.SEVERE, e.getLocalizedMessage(), e); + } finally{ + DB.close(rs, pstmt); + } + + return parentSql; + } } + + diff --git a/base/src/org/adempiere/pipo/handler/FieldElementHandler.java b/base/src/org/adempiere/pipo/handler/FieldElementHandler.java index 6aa9ba653c..157948d8df 100644 --- a/base/src/org/adempiere/pipo/handler/FieldElementHandler.java +++ b/base/src/org/adempiere/pipo/handler/FieldElementHandler.java @@ -1,325 +1,330 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 Adempiere, Inc. All Rights Reserved. * - * 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.pipo.handler; - -import java.math.BigDecimal; -import java.util.Properties; - -import javax.xml.transform.sax.TransformerHandler; - -import org.adempiere.pipo.AbstractElementHandler; -import org.adempiere.pipo.Element; -import org.adempiere.pipo.PackIn; -import org.adempiere.pipo.PackOut; -import org.adempiere.pipo.exception.POSaveFailedException; -import org.compiere.model.MField; -import org.compiere.model.X_AD_Field; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.AttributesImpl; - -public class FieldElementHandler extends AbstractElementHandler { - - public void startElement(Properties ctx, Element element) - throws SAXException { - PackIn packIn = (PackIn)ctx.get("PackInProcess"); - String elementValue = element.getElementValue(); - Attributes atts = element.attributes; - log.info(elementValue + " " + atts.getValue("Name")); - String entitytype = atts.getValue("EntityType"); - if (isProcessElement(ctx, entitytype)) { - if (element.parent != null && element.parent.getElementValue().equals("tab") && - element.parent.defer) { - element.defer = true; - return; - } - String name = atts.getValue("Name"); - String tabname = atts.getValue("ADTabNameID"); - String colname = atts.getValue("ADColumnNameID"); - String tableName = atts.getValue("ADTableNameID"); - int tableid = packIn.getTableId(tableName); - if (tableid <= 0) { - tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName); - if (tableid > 0) - packIn.addTable(tableName, tableid); - } - if (tableid <= 0) { - element.defer = true; - return; - } - int windowid = get_ID(ctx, "AD_Window", atts - .getValue("ADWindowNameID")); - if (windowid <= 0) { - element.defer = true; - return; - } - int columnid = packIn.getColumnId(tableName, colname); - if (columnid <= 0) { - columnid = get_IDWithMasterAndColumn(ctx, "AD_Column", - "ColumnName", colname, "AD_Table", tableid); - if (columnid > 0) - packIn.addColumn(tableName, colname, columnid); - } - if (columnid <= 0) { - element.defer = true; - return; - } - int tabid = 0; - if (element.parent != null && element.parent.getElementValue().equals("tab") && - element.parent.recordId > 0) { - tabid = element.parent.recordId; - } else { - StringBuffer sqlB = new StringBuffer( - "select AD_Tab_ID from AD_Tab where AD_Window_ID = " - + windowid).append(" and Name = '" + tabname + "'") - .append(" and AD_Table_ID = ?"); - tabid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), - tableid); - if (element.parent != null && element.parent.getElementValue().equals("tab") && tabid > 0) { - element.parent.recordId = tabid; - } - } - if (tabid > 0) { - StringBuffer sqlB = new StringBuffer( - "select AD_Field_ID from AD_Field where AD_Column_ID = ") - .append(columnid) - .append(" and AD_Tab_ID = ?"); - int id = DB - .getSQLValue(getTrxName(ctx), sqlB.toString(), tabid); - MField m_Field = new MField(ctx, id, getTrxName(ctx)); - int AD_Backup_ID = -1; - String Object_Status = null; - if (id > 0) { - AD_Backup_ID = copyRecord(ctx, "AD_Field", m_Field); - Object_Status = "Update"; - } else { - Object_Status = "New"; - AD_Backup_ID = 0; - } - m_Field.setName(atts.getValue("Name")); - m_Field.setAD_Column_ID(columnid); - name = atts.getValue("ADFieldGroupNameID"); - id = get_IDWithColumn(ctx, "AD_FieldGroup", "Name", name); - m_Field.setAD_FieldGroup_ID(id); - m_Field.setAD_Tab_ID(tabid); - m_Field.setEntityType(atts.getValue("EntityType")); - m_Field.setIsSameLine(Boolean - .valueOf(atts.getValue("SameLine")).booleanValue()); - m_Field.setIsCentrallyMaintained(Boolean.valueOf( - atts.getValue("isCentrallyMaintained")).booleanValue()); - m_Field.setIsDisplayed(Boolean.valueOf( - atts.getValue("Displayed")).booleanValue()); - // m_Field.setIsEncrypted(Boolean.valueOf(atts.getValue("isEncrypted")).booleanValue()); - m_Field.setIsFieldOnly(Boolean.valueOf( - atts.getValue("isFieldOnly")).booleanValue()); - m_Field.setIsHeading(Boolean - .valueOf(atts.getValue("isHeading")).booleanValue()); - m_Field.setIsReadOnly(Boolean.valueOf( - atts.getValue("isReadOnly")).booleanValue()); - m_Field.setSeqNo(Integer.parseInt(atts.getValue("SeqNo"))); - m_Field.setDisplayLength(Integer.parseInt(atts - .getValue("DisplayLength"))); - m_Field.setDescription(getStringValue(atts, "Description")); - m_Field.setHelp(getStringValue(atts, "Help")); - m_Field.setIsActive(atts.getValue("isActive") != null ? Boolean - .valueOf(atts.getValue("isActive")).booleanValue() - : true); - String sortNo = getStringValue(atts, "SortNo"); - if (sortNo != null) - m_Field.setSortNo(new BigDecimal(sortNo)); - m_Field.setDisplayLogic(getStringValue(atts, "DisplayLogic")); - - String Name = atts.getValue("ADReferenceNameID"); - id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name); - m_Field.setAD_Reference_ID(id); - - Name = atts.getValue("ADValRuleNameID"); - id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", Name); - m_Field.setAD_Val_Rule_ID(id); - Name = atts.getValue("ADReferenceNameValueID"); - id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name); - m_Field.setAD_Reference_Value_ID(id); - m_Field.setInfoFactoryClass(getStringValue(atts, "InfoFactoryClass")); - - if (m_Field.save(getTrxName(ctx)) == true) { - record_log(ctx, 1, m_Field.getName(), "Field", m_Field - .get_ID(), AD_Backup_ID, Object_Status, "AD_Field", - get_IDWithColumn(ctx, "AD_Table", "TableName", - "AD_Field")); - element.recordId = m_Field.getAD_Field_ID(); - } else { - record_log(ctx, 0, m_Field.getName(), "Field", m_Field - .get_ID(), AD_Backup_ID, Object_Status, "AD_Field", - get_IDWithColumn(ctx, "AD_Table", "TableName", - "AD_Field")); - throw new POSaveFailedException("Failed to save field definition."); - } - } else { - element.defer = true; - return; - } - } else { - element.skip = true; - } - } - - public void endElement(Properties ctx, Element element) throws SAXException { - } - - public void create(Properties ctx, TransformerHandler document) - throws SAXException { - int AD_Field_ID = Env.getContextAsInt(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(); - createFieldBinding(atts, m_Field); - - PackOut packOut = (PackOut)ctx.get("PackOutProcess"); - - if(m_Field.getAD_FieldGroup_ID() > 0){ - packOut.createFieldGroupElement(m_Field.getAD_FieldGroup_ID(), document); - } - - if(m_Field.getAD_Reference_ID() > 0) { - packOut.createReference(m_Field.getAD_Reference_ID(), document); - } - - if (m_Field.getAD_Reference_Value_ID() > 0) { - packOut.createReference(m_Field.getAD_Reference_Value_ID(), document); - } - - if (m_Field.getAD_Val_Rule_ID() > 0) { - packOut.createDynamicRuleValidation(m_Field.getAD_Val_Rule_ID(), document); - } - - document.startElement("", "", "field", atts); - document.endElement("", "", "field"); - } - - private AttributesImpl createFieldBinding(AttributesImpl atts, - X_AD_Field m_Field) { - String sql = null; - String name = null; - atts.clear(); - if (m_Field.getAD_Column_ID() > 0) { - sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; - name = DB.getSQLValueString(null, sql, m_Field.getAD_Column_ID()); - atts.addAttribute("", "", "ADColumnNameID", "CDATA", name); - } else - atts.addAttribute("", "", "ADColumnNameID", "CDATA", ""); - - if (m_Field.getAD_Column_ID() > 0) { - sql = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?"; - int idTable = DB.getSQLValue(null, sql, m_Field.getAD_Column_ID()); - sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; - name = DB.getSQLValueString(null, sql, idTable); - atts.addAttribute("", "", "ADTableNameID", "CDATA", name); - } else - atts.addAttribute("", "", "ADTableNameID", "CDATA", ""); - if (m_Field.getAD_FieldGroup_ID() > 0) { - sql = "SELECT Name FROM AD_FieldGroup WHERE AD_FieldGroup_ID=?"; - name = DB.getSQLValueString(null, sql, m_Field - .getAD_FieldGroup_ID()); - atts.addAttribute("", "", "ADFieldGroupNameID", "CDATA", name); - } else - atts.addAttribute("", "", "ADFieldGroupNameID", "CDATA", ""); - - if (m_Field.getAD_Field_ID() > 0) { - sql = "SELECT Name FROM AD_Field WHERE AD_Field_ID=?"; - name = DB.getSQLValueString(null, sql, m_Field.getAD_Field_ID()); - atts.addAttribute("", "", "ADFieldNameID", "CDATA", name); - } else - atts.addAttribute("", "", "ADFieldNameID", "CDATA", ""); - - if (m_Field.getAD_Tab_ID() > 0) { - sql = "SELECT Name FROM AD_Tab WHERE AD_Tab_ID=?"; - name = DB.getSQLValueString(null, sql, m_Field.getAD_Tab_ID()); - atts.addAttribute("", "", "ADTabNameID", "CDATA", name); - sql = "SELECT AD_Window_ID FROM AD_Tab WHERE AD_Tab_ID=?"; - int windowid = DB.getSQLValue(null, sql, m_Field.getAD_Tab_ID()); - sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?"; - name = DB.getSQLValueString(null, sql, windowid); - atts.addAttribute("", "", "ADWindowNameID", "CDATA", name); - } else - atts.addAttribute("", "", "ADTabNameID", "CDATA", ""); - - atts.addAttribute("", "", "EntityType", "CDATA", (m_Field - .getEntityType() != null ? m_Field.getEntityType() : "")); - atts.addAttribute("", "", "Name", "CDATA", - (m_Field.getName() != null ? m_Field.getName() : "")); - atts.addAttribute("", "", "SameLine", "CDATA", - (m_Field.isSameLine() == true ? "true" : "false")); - atts.addAttribute("", "", "isCentrallyMaintained", "CDATA", (m_Field - .isCentrallyMaintained() == true ? "true" : "false")); - atts.addAttribute("", "", "Displayed", "CDATA", - (m_Field.isDisplayed() == true ? "true" : "false")); - atts.addAttribute("", "", "isActive", "CDATA", - (m_Field.isActive() == true ? "true" : "false")); - atts.addAttribute("", "", "isEncrypted", "CDATA", (m_Field - .isEncrypted() == true ? "true" : "false")); - atts.addAttribute("", "", "isFieldOnly", "CDATA", (m_Field - .isFieldOnly() == true ? "true" : "false")); - atts.addAttribute("", "", "isHeading", "CDATA", - (m_Field.isHeading() == true ? "true" : "false")); - atts.addAttribute("", "", "isReadOnly", "CDATA", - (m_Field.isReadOnly() == true ? "true" : "false")); - atts.addAttribute("", "", "SeqNo", "CDATA", "" + (m_Field.getSeqNo())); - atts.addAttribute("", "", "DisplayLength", "CDATA", - (m_Field.getDisplayLength() > 0 ? "" - + m_Field.getDisplayLength() : "0")); - atts.addAttribute("", "", "Description", "CDATA", (m_Field - .getDescription() != null ? m_Field.getDescription() : "")); - atts.addAttribute("", "", "Help", "CDATA", - (m_Field.getHelp() != null ? m_Field.getHelp() : "")); - atts.addAttribute("", "", "SortNo", "CDATA", - (m_Field.getSortNo() != null ? m_Field.getSortNo().toString() - : "")); - atts.addAttribute("", "", "DisplayLogic", "CDATA", (m_Field - .getDisplayLogic() != null ? m_Field.getDisplayLogic() : "")); - atts.addAttribute("", "", "ObscureType", "CDATA", (m_Field - .getObscureType() != null ? m_Field.getObscureType() : "")); - - atts.addAttribute("", "", "InfoFactoryClass", "CDATA", (m_Field.getInfoFactoryClass() != null - ? m_Field.getInfoFactoryClass() : "")); - - if (m_Field.getAD_Reference_ID() > 0) { - sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?"; - name = DB.getSQLValueString(null, sql, m_Field - .getAD_Reference_ID()); - atts.addAttribute("", "", "ADReferenceNameID", "CDATA", name); - } else - atts.addAttribute("", "", "ADReferenceNameID", "CDATA", ""); - if (m_Field.getAD_Reference_Value_ID() > 0) { - sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?"; - name = DB.getSQLValueString(null, sql, m_Field - .getAD_Reference_Value_ID()); - atts.addAttribute("", "", "ADReferenceNameValueID", "CDATA", name); - } else - atts.addAttribute("", "", "ADReferenceNameValueID", "CDATA", ""); - if (m_Field.getAD_Val_Rule_ID() > 0) { - sql = "SELECT Name FROM AD_Val_Rule WHERE AD_Val_Rule_ID=?"; - name = DB - .getSQLValueString(null, sql, m_Field.getAD_Val_Rule_ID()); - atts.addAttribute("", "", "ADValRuleNameID", "CDATA", name); - } else - atts.addAttribute("", "", "ADValRuleNameID", "CDATA", ""); - - return atts; - } -} +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * Copyright (C) 1999-2006 Adempiere, Inc. All Rights Reserved. * + * 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.pipo.handler; + +import java.math.BigDecimal; +import java.util.Properties; + +import javax.xml.transform.sax.TransformerHandler; + +import org.adempiere.pipo.AbstractElementHandler; +import org.adempiere.pipo.Element; +import org.adempiere.pipo.PackIn; +import org.adempiere.pipo.PackOut; +import org.adempiere.pipo.exception.POSaveFailedException; +import org.compiere.model.MField; +import org.compiere.model.X_AD_Field; +import org.compiere.util.DB; +import org.compiere.util.Env; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +public class FieldElementHandler extends AbstractElementHandler { + + public void startElement(Properties ctx, Element element) + throws SAXException { + PackIn packIn = (PackIn)ctx.get("PackInProcess"); + String elementValue = element.getElementValue(); + Attributes atts = element.attributes; + log.info(elementValue + " " + atts.getValue("Name")); + String entitytype = atts.getValue("EntityType"); + if (isProcessElement(ctx, entitytype)) { + if (element.parent != null && element.parent.getElementValue().equals("tab") && + element.parent.defer) { + element.defer = true; + element.unresolved = element.parent.unresolved; + return; + } + String name = atts.getValue("Name"); + String tabname = atts.getValue("ADTabNameID"); + String colname = atts.getValue("ADColumnNameID"); + String tableName = atts.getValue("ADTableNameID"); + int tableid = packIn.getTableId(tableName); + if (tableid <= 0) { + tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", tableName); + if (tableid > 0) + packIn.addTable(tableName, tableid); + } + if (tableid <= 0) { + element.unresolved = "AD_Table=" + tableName; + element.defer = true; + return; + } + int windowid = get_ID(ctx, "AD_Window", atts + .getValue("ADWindowNameID")); + if (windowid <= 0) { + element.defer = true; + element.unresolved = "AD_Window=" + atts.getValue("ADWindowNameID"); + return; + } + int columnid = packIn.getColumnId(tableName, colname); + if (columnid <= 0) { + columnid = get_IDWithMasterAndColumn(ctx, "AD_Column", + "ColumnName", colname, "AD_Table", tableid); + if (columnid > 0) + packIn.addColumn(tableName, colname, columnid); + } + if (columnid <= 0) { + element.defer = true; + element.unresolved = "AD_Column"+ colname; + return; + } + int tabid = 0; + if (element.parent != null && element.parent.getElementValue().equals("tab") && + element.parent.recordId > 0) { + tabid = element.parent.recordId; + } else { + StringBuffer sqlB = new StringBuffer( + "select AD_Tab_ID from AD_Tab where AD_Window_ID = " + + windowid).append(" and Name = '" + tabname + "'") + .append(" and AD_Table_ID = ?"); + tabid = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), + tableid); + if (element.parent != null && element.parent.getElementValue().equals("tab") && tabid > 0) { + element.parent.recordId = tabid; + } + } + if (tabid > 0) { + StringBuffer sqlB = new StringBuffer( + "select AD_Field_ID from AD_Field where AD_Column_ID = ") + .append(columnid) + .append(" and AD_Tab_ID = ?"); + int id = DB + .getSQLValue(getTrxName(ctx), sqlB.toString(), tabid); + MField m_Field = new MField(ctx, id, getTrxName(ctx)); + int AD_Backup_ID = -1; + String Object_Status = null; + if (id > 0) { + AD_Backup_ID = copyRecord(ctx, "AD_Field", m_Field); + Object_Status = "Update"; + } else { + Object_Status = "New"; + AD_Backup_ID = 0; + } + m_Field.setName(atts.getValue("Name")); + m_Field.setAD_Column_ID(columnid); + name = atts.getValue("ADFieldGroupNameID"); + id = get_IDWithColumn(ctx, "AD_FieldGroup", "Name", name); + m_Field.setAD_FieldGroup_ID(id); + m_Field.setAD_Tab_ID(tabid); + m_Field.setEntityType(atts.getValue("EntityType")); + m_Field.setIsSameLine(Boolean + .valueOf(atts.getValue("SameLine")).booleanValue()); + m_Field.setIsCentrallyMaintained(Boolean.valueOf( + atts.getValue("isCentrallyMaintained")).booleanValue()); + m_Field.setIsDisplayed(Boolean.valueOf( + atts.getValue("Displayed")).booleanValue()); + // m_Field.setIsEncrypted(Boolean.valueOf(atts.getValue("isEncrypted")).booleanValue()); + m_Field.setIsFieldOnly(Boolean.valueOf( + atts.getValue("isFieldOnly")).booleanValue()); + m_Field.setIsHeading(Boolean + .valueOf(atts.getValue("isHeading")).booleanValue()); + m_Field.setIsReadOnly(Boolean.valueOf( + atts.getValue("isReadOnly")).booleanValue()); + m_Field.setSeqNo(Integer.parseInt(atts.getValue("SeqNo"))); + m_Field.setDisplayLength(Integer.parseInt(atts + .getValue("DisplayLength"))); + m_Field.setDescription(getStringValue(atts, "Description")); + m_Field.setHelp(getStringValue(atts, "Help")); + m_Field.setIsActive(atts.getValue("isActive") != null ? Boolean + .valueOf(atts.getValue("isActive")).booleanValue() + : true); + String sortNo = getStringValue(atts, "SortNo"); + if (sortNo != null) + m_Field.setSortNo(new BigDecimal(sortNo)); + m_Field.setDisplayLogic(getStringValue(atts, "DisplayLogic")); + + String Name = atts.getValue("ADReferenceNameID"); + id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name); + m_Field.setAD_Reference_ID(id); + + Name = atts.getValue("ADValRuleNameID"); + id = get_IDWithColumn(ctx, "AD_Val_Rule", "Name", Name); + m_Field.setAD_Val_Rule_ID(id); + Name = atts.getValue("ADReferenceNameValueID"); + id = get_IDWithColumn(ctx, "AD_Reference", "Name", Name); + m_Field.setAD_Reference_Value_ID(id); + m_Field.setInfoFactoryClass(getStringValue(atts, "InfoFactoryClass")); + + if (m_Field.save(getTrxName(ctx)) == true) { + record_log(ctx, 1, m_Field.getName(), "Field", m_Field + .get_ID(), AD_Backup_ID, Object_Status, "AD_Field", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Field")); + element.recordId = m_Field.getAD_Field_ID(); + } else { + record_log(ctx, 0, m_Field.getName(), "Field", m_Field + .get_ID(), AD_Backup_ID, Object_Status, "AD_Field", + get_IDWithColumn(ctx, "AD_Table", "TableName", + "AD_Field")); + throw new POSaveFailedException("Failed to save field definition."); + } + } else { + element.defer = true; + element.unresolved = "AD_Tab=" + tabname; + return; + } + } else { + element.skip = true; + } + } + + public void endElement(Properties ctx, Element element) throws SAXException { + } + + public void create(Properties ctx, TransformerHandler document) + throws SAXException { + int AD_Field_ID = Env.getContextAsInt(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(); + createFieldBinding(atts, m_Field); + + PackOut packOut = (PackOut)ctx.get("PackOutProcess"); + + if(m_Field.getAD_FieldGroup_ID() > 0){ + packOut.createFieldGroupElement(m_Field.getAD_FieldGroup_ID(), document); + } + + if(m_Field.getAD_Reference_ID() > 0) { + packOut.createReference(m_Field.getAD_Reference_ID(), document); + } + + if (m_Field.getAD_Reference_Value_ID() > 0) { + packOut.createReference(m_Field.getAD_Reference_Value_ID(), document); + } + + if (m_Field.getAD_Val_Rule_ID() > 0) { + packOut.createDynamicRuleValidation(m_Field.getAD_Val_Rule_ID(), document); + } + + document.startElement("", "", "field", atts); + document.endElement("", "", "field"); + } + + private AttributesImpl createFieldBinding(AttributesImpl atts, + X_AD_Field m_Field) { + String sql = null; + String name = null; + atts.clear(); + if (m_Field.getAD_Column_ID() > 0) { + sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; + name = DB.getSQLValueString(null, sql, m_Field.getAD_Column_ID()); + atts.addAttribute("", "", "ADColumnNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADColumnNameID", "CDATA", ""); + + if (m_Field.getAD_Column_ID() > 0) { + sql = "SELECT AD_Table_ID FROM AD_Column WHERE AD_Column_ID=?"; + int idTable = DB.getSQLValue(null, sql, m_Field.getAD_Column_ID()); + sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; + name = DB.getSQLValueString(null, sql, idTable); + atts.addAttribute("", "", "ADTableNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADTableNameID", "CDATA", ""); + if (m_Field.getAD_FieldGroup_ID() > 0) { + sql = "SELECT Name FROM AD_FieldGroup WHERE AD_FieldGroup_ID=?"; + name = DB.getSQLValueString(null, sql, m_Field + .getAD_FieldGroup_ID()); + atts.addAttribute("", "", "ADFieldGroupNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADFieldGroupNameID", "CDATA", ""); + + if (m_Field.getAD_Field_ID() > 0) { + sql = "SELECT Name FROM AD_Field WHERE AD_Field_ID=?"; + name = DB.getSQLValueString(null, sql, m_Field.getAD_Field_ID()); + atts.addAttribute("", "", "ADFieldNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADFieldNameID", "CDATA", ""); + + if (m_Field.getAD_Tab_ID() > 0) { + sql = "SELECT Name FROM AD_Tab WHERE AD_Tab_ID=?"; + name = DB.getSQLValueString(null, sql, m_Field.getAD_Tab_ID()); + atts.addAttribute("", "", "ADTabNameID", "CDATA", name); + sql = "SELECT AD_Window_ID FROM AD_Tab WHERE AD_Tab_ID=?"; + int windowid = DB.getSQLValue(null, sql, m_Field.getAD_Tab_ID()); + sql = "SELECT Name FROM AD_Window WHERE AD_Window_ID=?"; + name = DB.getSQLValueString(null, sql, windowid); + atts.addAttribute("", "", "ADWindowNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADTabNameID", "CDATA", ""); + + atts.addAttribute("", "", "EntityType", "CDATA", (m_Field + .getEntityType() != null ? m_Field.getEntityType() : "")); + atts.addAttribute("", "", "Name", "CDATA", + (m_Field.getName() != null ? m_Field.getName() : "")); + atts.addAttribute("", "", "SameLine", "CDATA", + (m_Field.isSameLine() == true ? "true" : "false")); + atts.addAttribute("", "", "isCentrallyMaintained", "CDATA", (m_Field + .isCentrallyMaintained() == true ? "true" : "false")); + atts.addAttribute("", "", "Displayed", "CDATA", + (m_Field.isDisplayed() == true ? "true" : "false")); + atts.addAttribute("", "", "isActive", "CDATA", + (m_Field.isActive() == true ? "true" : "false")); + atts.addAttribute("", "", "isEncrypted", "CDATA", (m_Field + .isEncrypted() == true ? "true" : "false")); + atts.addAttribute("", "", "isFieldOnly", "CDATA", (m_Field + .isFieldOnly() == true ? "true" : "false")); + atts.addAttribute("", "", "isHeading", "CDATA", + (m_Field.isHeading() == true ? "true" : "false")); + atts.addAttribute("", "", "isReadOnly", "CDATA", + (m_Field.isReadOnly() == true ? "true" : "false")); + atts.addAttribute("", "", "SeqNo", "CDATA", "" + (m_Field.getSeqNo())); + atts.addAttribute("", "", "DisplayLength", "CDATA", + (m_Field.getDisplayLength() > 0 ? "" + + m_Field.getDisplayLength() : "0")); + atts.addAttribute("", "", "Description", "CDATA", (m_Field + .getDescription() != null ? m_Field.getDescription() : "")); + atts.addAttribute("", "", "Help", "CDATA", + (m_Field.getHelp() != null ? m_Field.getHelp() : "")); + atts.addAttribute("", "", "SortNo", "CDATA", + (m_Field.getSortNo() != null ? m_Field.getSortNo().toString() + : "")); + atts.addAttribute("", "", "DisplayLogic", "CDATA", (m_Field + .getDisplayLogic() != null ? m_Field.getDisplayLogic() : "")); + atts.addAttribute("", "", "ObscureType", "CDATA", (m_Field + .getObscureType() != null ? m_Field.getObscureType() : "")); + + atts.addAttribute("", "", "InfoFactoryClass", "CDATA", (m_Field.getInfoFactoryClass() != null + ? m_Field.getInfoFactoryClass() : "")); + + if (m_Field.getAD_Reference_ID() > 0) { + sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?"; + name = DB.getSQLValueString(null, sql, m_Field + .getAD_Reference_ID()); + atts.addAttribute("", "", "ADReferenceNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADReferenceNameID", "CDATA", ""); + if (m_Field.getAD_Reference_Value_ID() > 0) { + sql = "SELECT Name FROM AD_Reference WHERE AD_Reference_ID=?"; + name = DB.getSQLValueString(null, sql, m_Field + .getAD_Reference_Value_ID()); + atts.addAttribute("", "", "ADReferenceNameValueID", "CDATA", name); + } else + atts.addAttribute("", "", "ADReferenceNameValueID", "CDATA", ""); + if (m_Field.getAD_Val_Rule_ID() > 0) { + sql = "SELECT Name FROM AD_Val_Rule WHERE AD_Val_Rule_ID=?"; + name = DB + .getSQLValueString(null, sql, m_Field.getAD_Val_Rule_ID()); + atts.addAttribute("", "", "ADValRuleNameID", "CDATA", name); + } else + atts.addAttribute("", "", "ADValRuleNameID", "CDATA", ""); + + return atts; + } +} diff --git a/migration/353a-trunk/oracle/411-2Pack_1976008.sql b/migration/353a-trunk/oracle/411-2Pack_1976008.sql new file mode 100644 index 0000000000..86887af649 --- /dev/null +++ b/migration/353a-trunk/oracle/411-2Pack_1976008.sql @@ -0,0 +1,30 @@ +-- Aug 6, 2008 10:39:44 AM SGT +-- Packin to any client +UPDATE AD_Table SET AccessLevel='6',Updated=TO_DATE('2008-08-06 10:39:44','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Table_ID=50008 +; + +-- Aug 6, 2008 10:39:57 AM SGT +-- Packin to any client +UPDATE AD_Table SET AccessLevel='6',Updated=TO_DATE('2008-08-06 10:39:57','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Table_ID=50003 +; + +-- Aug 6, 2008 10:40:31 AM SGT +-- Packin to any client +DELETE FROM AD_Window_Access WHERE AD_Role_ID=102 +; + +-- Aug 6, 2008 10:40:32 AM SGT +-- Packin to any client +INSERT INTO AD_Window_Access (AD_Window_ID, AD_Role_ID, AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadWrite) SELECT DISTINCT w.AD_Window_ID, 102,11,0,'Y', SysDate,100, SysDate,100,'Y' FROM AD_Window w INNER JOIN AD_Tab t ON (w.AD_Window_ID=t.AD_Window_ID) INNER JOIN AD_Table tt ON (t.AD_Table_ID=tt.AD_Table_ID) WHERE t.SeqNo=(SELECT MIN(SeqNo) FROM AD_Tab xt WHERE xt.AD_Window_ID=w.AD_Window_ID)AND tt.AccessLevel IN ('7','6','3','2','1') +; + +-- Aug 6, 2008 10:40:32 AM SGT +-- Packin to any client +DELETE FROM AD_Process_Access WHERE AD_Role_ID=102 +; + +-- Aug 6, 2008 10:40:32 AM SGT +-- Packin to any client +INSERT INTO AD_Process_Access (AD_Process_ID, AD_Role_ID, AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadWrite) SELECT DISTINCT p.AD_Process_ID, 102,11,0,'Y', SysDate,100, SysDate,100,'Y' FROM AD_Process p WHERE AccessLevel IN ('7','6','3','2','1') +; + diff --git a/migration/353a-trunk/postgresql/411-2Pack_1976008.sql b/migration/353a-trunk/postgresql/411-2Pack_1976008.sql new file mode 100644 index 0000000000..169a59058c --- /dev/null +++ b/migration/353a-trunk/postgresql/411-2Pack_1976008.sql @@ -0,0 +1,30 @@ +-- Aug 6, 2008 10:39:44 AM SGT +-- Packin to any client +UPDATE AD_Table SET AccessLevel='6',Updated=TO_TIMESTAMP('2008-08-06 10:39:44','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Table_ID=50008 +; + +-- Aug 6, 2008 10:39:57 AM SGT +-- Packin to any client +UPDATE AD_Table SET AccessLevel='6',Updated=TO_TIMESTAMP('2008-08-06 10:39:57','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Table_ID=50003 +; + +-- Aug 6, 2008 10:40:32 AM SGT +-- Packin to any client +DELETE FROM AD_Window_Access WHERE AD_Role_ID=102 +; + +-- Aug 6, 2008 10:40:32 AM SGT +-- Packin to any client +INSERT INTO AD_Window_Access (AD_Window_ID, AD_Role_ID, AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadWrite) SELECT DISTINCT w.AD_Window_ID, 102,11,0,'Y', CURRENT_TIMESTAMP,100, CURRENT_TIMESTAMP,100,'Y' FROM AD_Window w INNER JOIN AD_Tab t ON (w.AD_Window_ID=t.AD_Window_ID) INNER JOIN AD_Table tt ON (t.AD_Table_ID=tt.AD_Table_ID) WHERE t.SeqNo=(SELECT MIN(SeqNo) FROM AD_Tab xt WHERE xt.AD_Window_ID=w.AD_Window_ID)AND tt.AccessLevel IN ('7','6','3','2','1') +; + +-- Aug 6, 2008 10:40:32 AM SGT +-- Packin to any client +DELETE FROM AD_Process_Access WHERE AD_Role_ID=102 +; + +-- Aug 6, 2008 10:40:32 AM SGT +-- Packin to any client +INSERT INTO AD_Process_Access (AD_Process_ID, AD_Role_ID, AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadWrite) SELECT DISTINCT p.AD_Process_ID, 102,11,0,'Y', CURRENT_TIMESTAMP,100, CURRENT_TIMESTAMP,100,'Y' FROM AD_Process p WHERE AccessLevel IN ('7','6','3','2','1') +; +